Index: /branches/2017/dev_merge_2017/DOC/Namelists/nam_tide
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/nam_tide	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/nam_tide	(revision 9019)
@@ -2,8 +2,8 @@
 &nam_tide      !   tide parameters
 !-----------------------------------------------------------------------
-   ln_tide       = .true.   !  Activate tide module
-   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
+   ln_tide     = .false.
+   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
 /
Index: /branches/2017/dev_merge_2017/DOC/Namelists/nam_vvl
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/nam_vvl	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/nam_vvl	(revision 9019)
@@ -1,14 +1,14 @@
 !-----------------------------------------------------------------------
-&nam_vvl    !   vertical coordinate options                             (default: zstar)
+&nam_vvl       !   vertical coordinate options                             (default: z-star)
 !-----------------------------------------------------------------------
-   ln_vvl_zstar  = .true.           !  zstar vertical coordinate
-   ln_vvl_ztilde = .false.          !  ztilde vertical coordinate: only high frequency variations
+   ln_vvl_zstar  = .true.           !  z-star vertical coordinate
+   ln_vvl_ztilde = .false.          !  z-tilde 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
+   rn_ahe3       =  0.0             !  thickness diffusion coefficient
+   rn_rst_e3t    = 30.0             !  ztilde to zstar restoration timescale [days]
+   rn_lf_cutoff  =  5.0             !  cutoff frequency for low-pass filter  [days]
+   rn_zdef_max   =  0.9             !  maximum fractional e3t deformation
    ln_vvl_dbg    = .true.           !  debug prints    (T/F)
 /
Index: /branches/2017/dev_merge_2017/DOC/Namelists/nambbl
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/nambbl	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/nambbl	(revision 9019)
@@ -1,5 +1,6 @@
 !-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
+&nambbl        !   bottom boundary layer scheme                         (default: NO)
 !-----------------------------------------------------------------------
+   ln_trabbl   = .false.   !  Bottom Boundary Layer parameterisation flag
    nn_bbl_ldf  =  1        !  diffusive bbl (=1)   or not (=0)
    nn_bbl_adv  =  0        !  advective bbl (=1/2) or not (=0)
Index: /branches/2017/dev_merge_2017/DOC/Namelists/nambdy
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/nambdy	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/nambdy	(revision 9019)
@@ -1,6 +1,6 @@
 !-----------------------------------------------------------------------
-&nambdy        !  unstructured open boundaries
+&nambdy        !  unstructured open boundaries                          
 !-----------------------------------------------------------------------
-    ln_bdy         = .true.               !  Activate BDY module
+    ln_bdy         = .false.              !  Use unstructured open boundaries
     nb_bdy         = 0                    !  number of open boundary sets
     ln_coords_file = .true.               !  =T : read bdy coordinates from file
@@ -33,3 +33,4 @@
     ln_vol        = .false.               !  total volume correction (see nn_volctl parameter)
     nn_volctl     = 1                     !  = 0, the total water flux across open boundaries is zero
+    nb_jpk_bdy    = -1                    ! number of levels in the bdy data (set < 0 if consistent with planned run)
 /
Index: /branches/2017/dev_merge_2017/DOC/Namelists/nambdy_dta
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/nambdy_dta	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/nambdy_dta	(revision 9019)
@@ -1,4 +1,4 @@
 !-----------------------------------------------------------------------
-&nambdy_dta    !  open boundaries - external data
+&nambdy_dta    !  open boundaries - external data                       
 !-----------------------------------------------------------------------
 !              !  file name      ! frequency (hours) ! variable  ! time interp.!  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
@@ -11,12 +11,8 @@
    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'  ,    ''    ,   ''     ,     ''
+!   bn_h_i     = 'amm12_bdyT_ice',         24        , 'iicethic',    .true.   , .false. ,  'daily'  ,    ''    ,   ''     ,     ''
+!   bn_h_s     = 'amm12_bdyT_ice',         24        , 'isnowthi',    .true.   , .false. ,  'daily'  ,    ''    ,   ''     ,     ''
 
    cn_dir      = 'bdydta/' !  root directory for the location of the bulk files
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namberg
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namberg	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namberg	(revision 9019)
@@ -2,33 +2,33 @@
 &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
+   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'  ,    ''    ,    ''    ,     ''
+!         ! 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 = './'
+   cn_dir = './'
 /
Index: anches/2017/dev_merge_2017/DOC/Namelists/nambfr
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/nambfr	(revision 9018)
+++ 	(revision )
@@ -1,23 +1,0 @@
-!-----------------------------------------------------------------------
-&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)
-/
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namcfg
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namcfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namcfg	(revision 9019)
@@ -1,4 +1,4 @@
 !-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
+&namcfg        !   parameters of the configuration                     !   (default: user defined GYRE)
 !-----------------------------------------------------------------------
    ln_read_cfg = .false.   !  (=T) read the domain configuration file
Index: anches/2017/dev_merge_2017/DOC/Namelists/namcfg_orca1
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namcfg_orca1	(revision 9018)
+++ 	(revision )
@@ -1,12 +1,0 @@
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-   cp_cfg      =  "orca"               !  name of the configuration
-   jp_cfg      =       1               !  resolution of the configuration
-   jpidta      =     362               !  1st lateral dimension ( >= jpi )
-   jpjdta      =     292               !  2nd    "         "    ( >= jpj )
-   jpkdta      =      75               !  number of levels      ( >= jpk )
-   jpiglo      =     362               !  1st dimension of global domain --> i =jpidta
-   jpjglo      =     292               !  2nd    -                  -    --> j  =jpjdta
-   jperio      =       6               !  lateral cond. type (between 0 and 6)
-   ln_use_jattr = .true.               !  use (T) the file attribute: open_ocean_jstart if present
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namcrs
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namcrs	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namcrs	(revision 9019)
@@ -1,4 +1,4 @@
 !-----------------------------------------------------------------------
-&namcrs        !   coarsened grid (for outputs and/or TOP)              ("key_crs")
+&namcrs        !   coarsened grid (for outputs and/or TOP)              (ln_crs =T)
 !-----------------------------------------------------------------------
    nn_factx    = 3         !  Reduction factor of x-direction
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namctl
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namctl	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namctl	(revision 9019)
@@ -1,4 +1,4 @@
 !-----------------------------------------------------------------------
-&namctl        !   Control prints & Benchmark
+&namctl        !   Control prints 
 !-----------------------------------------------------------------------
    ln_ctl      = .false.   !  trends control print (expensive!)
@@ -10,7 +10,5 @@
    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)
+   ln_timing   = .false.   !  timing by routine write out in timing.output file
+   ln_diacfl   = .false.   !  CFL diagnostics write out in cfl_diagnostics.ascii
 /
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namdiu
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namdiu	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namdiu	(revision 9019)
@@ -2,5 +2,5 @@
 &namdiu        !   Cool skin and warm layer models                       (default F)
 !-----------------------------------------------------------------------
-   ln_diurnal      = .false.   ! 
+   ln_diurnal      = .false.   !
    ln_diurnal_only = .false.   !
 /
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namdom
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namdom	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namdom	(revision 9019)
@@ -1,39 +1,14 @@
 !-----------------------------------------------------------------------
-&namdom        !   space and time domain (bathymetry, mesh, timestep)
+&namdom        !   time and space domain
 !-----------------------------------------------------------------------
-   nn_bathy    =    1      !  compute (=0) or read (=1) the bathymetry file
-   rn_bathy    =    0.     !  value of the bathymetry. if (=0) bottom flat at jpkm1
+   ln_linssh   = .false.   !  =T  linear free surface  ==>>  model level are fixed in time
    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)
+   !
+   nn_msh      =    0      !  create (>0) a mesh file or not (=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_rdt      = 5760.     !  time step for the dynamics and tracer
    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 !
+   !
+   ln_crs      = .false.   !  Logical switch for coarsening module      (T => fill namcrs)
 /
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namdrg
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namdrg	(revision 9019)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namdrg	(revision 9019)
@@ -0,0 +1,10 @@
+!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .false.    !  free-slip       : Cd = 0                  (F => fill namdrg_bot
+   ln_lin     = .false.    !      linear  drag: Cd = Cd0 Uc0                   &   namdrg_top)
+   ln_non_lin = .false.    !  non-linear  drag: Cd = Cd0 |U|
+   ln_loglayer= .false.    !  logarithmic drag: Cd = vkarmn/log(z/z0) |U|
+   !
+   ln_drgimp  = .true.     !  implicit top/bottom friction flag
+/
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namdrg_bot
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namdrg_bot	(revision 9019)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namdrg_bot	(revision 9019)
@@ -0,0 +1,11 @@
+!-----------------------------------------------------------------------
+&namdrg_bot        !   BOTTOM friction                                  
+!-----------------------------------------------------------------------
+   rn_Cd0     =  1.e-3    !  drag coefficient [-]
+   rn_Uc0     =  0.4      !  ref. velocity [m/s] (linear drag=Cd0*Uc0) 
+   rn_Cdmax   =  0.1      !  drag value maximum [-] (logarithmic drag)
+   rn_ke0     =  2.5e-3   !  background kinetic energy  [m2/s2] (non-linear cases)
+   rn_z0      =  3.e-3    !  roughness [m] (ln_loglayer=T)
+   ln_boost   = .false.   !  =T regional boost of Cd0 ; =F constant
+      rn_boost=  50.         !  local boost factor  [-]
+/
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namdrg_top
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namdrg_top	(revision 9019)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namdrg_top	(revision 9019)
@@ -0,0 +1,11 @@
+!-----------------------------------------------------------------------
+&namdrg_top        !   TOP friction                                     (ln_isfcav=T)
+!-----------------------------------------------------------------------
+   rn_Cd0     =  1.e-3     !  drag coefficient [-]
+   rn_Uc0     =  0.4       !  ref. velocity [m/s] (linear drag=Cd0*Uc0) 
+   rn_Cdmax   =  0.1       !  drag value maximum [-] (logarithmic drag)
+   rn_ke0     =  2.5e-3    !  background kinetic energy  [m2/s2] (non-linear cases)
+   rn_z0      =  3.0e-3    !  roughness [m] (ln_loglayer=T)
+   ln_boost   = .false.    !  =T regional boost of Cd0 ; =F constant
+      rn_boost=  50.          !  local boost factor  [-]
+/
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namdyn_adv
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namdyn_adv	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namdyn_adv	(revision 9019)
@@ -1,9 +1,9 @@
 !-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection                (default: vector form)
+&namdyn_adv    !   formulation of the momentum advection                (default: NO selection)
 !-----------------------------------------------------------------------
-   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_NONE= .false. !  linear dynamics (no momentum advection)
+   ln_dynadv_vec = .false. !  vector form - 2nd centered scheme
+     nn_dynkeg     = 0        ! grad(KE) scheme: =0   C2  ;  =1   Hollingsworth correction
    ln_dynadv_cen2= .false. !  flux form - 2nd order centered scheme
    ln_dynadv_ubs = .false. !  flux form - 3rd order UBS      scheme
-   ln_dynzad_zts = .false. !  Use (T) sub timestepping for vertical momentum advection
 /
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namdyn_hpg
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namdyn_hpg	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namdyn_hpg	(revision 9019)
@@ -1,7 +1,7 @@
 !-----------------------------------------------------------------------
-&namdyn_hpg    !   Hydrostatic pressure gradient option                 (default: zps)
+&namdyn_hpg    !   Hydrostatic pressure gradient option                 (default: NO selection)
 !-----------------------------------------------------------------------
    ln_hpg_zco  = .false.   !  z-coordinate - full steps
-   ln_hpg_zps  = .true.    !  z-coordinate - partial steps (interpolation)
+   ln_hpg_zps  = .false.   !  z-coordinate - partial steps (interpolation)
    ln_hpg_sco  = .false.   !  s-coordinate (standard jacobian formulation)
    ln_hpg_isf  = .false.   !  s-coordinate (sco ) adapted to isf
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namdyn_ldf
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namdyn_ldf	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namdyn_ldf	(revision 9019)
@@ -1,7 +1,7 @@
 !-----------------------------------------------------------------------
-&namdyn_ldf    !   lateral diffusion on momentum                        (default: NO)
+&namdyn_ldf    !   lateral diffusion on momentum                        (default: NO selection)
 !-----------------------------------------------------------------------
    !                       !  Type of the operator :
-   !                           !  no diffusion: set ln_dynldf_lap=..._blp=F 
+   ln_dynldf_NONE=  .false.    !  No operator (i.e. no explicit diffusion)
    ln_dynldf_lap =  .false.    !    laplacian operator
    ln_dynldf_blp =  .false.    !  bilaplacian operator
@@ -19,8 +19,12 @@
    !                                !  = 30  F(i,j,k)=c2d*c1d
    !                                !  = 31  F(i,j,k)=F(grid spacing and local velocity)
+   !                                !  = 32  F(i,j,k)=F(local gridscale and deformation rate)
+   ! Caution in 20 and 30 cases the coefficient have to be given for a 1 degree grid (~111km)
    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)
+   !                       !  Smagorinsky settings (nn_ahm_ijk_t  = 32) :
+   rn_csmc       = 3.5         !  Smagorinsky constant of proportionality
+   rn_minfac     = 1.0         !  multiplier of theorectical lower limit
+   rn_maxfac     = 1.0         !  multiplier of theorectical upper limit
 /
Index: anches/2017/dev_merge_2017/DOC/Namelists/namelist_dmp
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namelist_dmp	(revision 9018)
+++ 	(revision )
@@ -1,24 +1,0 @@
-&nam_dmp_create
-    cp_cfg = 'orca'            ! Name of model grid (orca and C1D have special options - otherwise ignored)
-    cp_cfz = 'antarctic'       ! Name of zoom configuration (arctic and antarctic have some special treatment if lzoom=.true.)
-    jp_cfg = 2                 ! Resolution of the model (used for med_red_seas damping)
-    lzoom = .false.            ! Zoom configuration or not
-    ln_full_field = .false.    ! Calculate coefficient over whole of domain 
-    ln_med_red_seas = .true.   ! Damping in Med/Red Seas (or local modifications here if ln_full_field=.true.)
-    ln_old_31_lev_code = .true.   ! Replicate behaviour of old online code for 31 level model (Med/Red seas damping based on level number instead of depth)
-    ln_coast = .true.          ! Reduce near to coastlines 
-    ln_zero_top_layer = .true. ! No damping in top layer
-    ln_custom = .false.        ! Call "custom" module to apply user modifications to the damping coefficient field
-    nn_hdmp = 10               ! Damp poleward of this latitude (smooth transition up to maximum damping)
-    pn_surf = 0.25             ! Surface Relaxation timescale (days) 
-    pn_bot = 0.25              ! Bottom relaxation timescale (days)
-    pn_dep = 1000              ! Transition depth from upper to deep ocean
-    jperio = 2                 ! Lateral boundary condition (as specified in namelist_cfg for model run).
-/
-
-&nam_zoom_dmp
-    lzoom_n = .false.     ! Open boundary had northern edge?
-    lzoom_e = .false.     ! Open boundary at eastern edge?
-    lzoom_w = .false.     ! Open boundary at western edge?
-    lzoom_s = .false.     ! Open boundary at southern edge?
-/
Index: /branches/2017/dev_merge_2017/DOC/Namelists/nameos
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/nameos	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/nameos	(revision 9019)
@@ -1,13 +1,13 @@
 !-----------------------------------------------------------------------
-&nameos        !   ocean physical parameters
+&nameos        !   ocean Equation Of Seawater                           (default: NO)
 !-----------------------------------------------------------------------
-   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)
+   ln_teos10   = .false.         !  = Use TEOS-10
+   ln_eos80    = .false.         !  = Use EOS80
+   ln_seos     = .false.         !  = Use S-EOS (simplified Eq.)
                                  !
    !                     ! 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_a0       =  1.6550e-1      !  thermal expension coefficient
+   rn_b0       =  7.6554e-1      !  saline  expension coefficient
    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)
Index: /branches/2017/dev_merge_2017/DOC/Namelists/nammpp
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/nammpp	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/nammpp	(revision 9019)
@@ -1,7 +1,7 @@
 !-----------------------------------------------------------------------
-&nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi)
+&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.
+   !                       !  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
Index: anches/2017/dev_merge_2017/DOC/Namelists/namobs_example
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namobs_example	(revision 9018)
+++ 	(revision )
@@ -1,34 +1,0 @@
-!-----------------------------------------------------------------------
-&namobs       !  observation usage switch
-!-----------------------------------------------------------------------
-   ln_diaobs  = .true.                 ! Logical switch for the observation operator
-   ln_t3d     = .true.                 ! Logical switch for T profile observations
-   ln_s3d     = .true.                 ! 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
-   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
-/
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namsbc
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namsbc	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namsbc	(revision 9019)
@@ -5,30 +5,23 @@
                            !     (also = the frequency of sea-ice & iceberg model call)
                      ! Type of air-sea fluxes 
-   ln_ana      = .false.   !  analytical formulation                    (T => fill namsbc_ana )
+   ln_usr      = .false.   !  user defined formulation                  (T => check usrdef_sbc)
    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 )
+   ln_blk      = .false.    !  Bulk formulation                          (T => fill namsbc_blk )
                      ! 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)
+                           !  =0 no opa-sas OASIS coupling: default single executable config.
+                           !  =1 opa-sas OASIS coupling: multi executable config., OPA component
+                           !  =2 opa-sas OASIS coupling: multi executable config., SAS component 
                      ! Sea-ice :
-   nn_ice      = 2         !  =0 no ice boundary condition   ,
+   nn_ice      = 0         !  =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)
+                           !  =2 or 3 automatically for LIM3 or CICE    ("key_lim3" or "key_cice")
+                           !          except in AGRIF zoom where it has to be specified
+   ln_ice_embd = .false.   !  =T embedded sea-ice (pressure + mass and salt exchanges)
+                           !  =F levitating ice (no pressure, mass and salt exchanges)
                      ! Misc. options of sbc : 
-   ln_traqsr   = .true.    !  Light penetration in the ocean            (T => fill namtra_qsr )
+   ln_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)
@@ -39,5 +32,9 @@
    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)
+   ln_wave     = .false.   !  Activate coupling with wave  (T => fill namsbc_wave)
+   ln_cdgw     = .false.   !  Neutral drag coefficient read from wave model (T => ln_wave=.true. & fill namsbc_wave)
+   ln_sdw      = .false.   !  Read 2D Surf Stokes Drift & Computation of 3D stokes drift (T => ln_wave=.true. & fill namsbc_wave) 
+   ln_tauoc    = .false.   !  Activate ocean stress modified by external wave induced stress (T => ln_wave=.true. & fill namsbc_wave)
+   ln_stcor    = .false.   !  Activate Stokes Coriolis term (T => ln_wave=.true. & ln_sdw=.true. & fill namsbc_wave)
    nn_lsm      = 0         !  =0 land/sea mask for input fields is not applied (keep empty land/sea mask filename field) ,
                            !  =1:n number of iterations of land/sea mask application for input fields (fill land/sea mask filename field)
Index: anches/2017/dev_merge_2017/DOC/Namelists/namsbc_alb
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_alb	(revision 9018)
+++ 	(revision )
@@ -1,11 +1,0 @@
-!-----------------------------------------------------------------------
-&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
-/
Index: anches/2017/dev_merge_2017/DOC/Namelists/namsbc_ana
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_ana	(revision 9018)
+++ 	(revision )
@@ -1,10 +1,0 @@
-!-----------------------------------------------------------------------
-&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)
-/
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_apr
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_apr	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_apr	(revision 9019)
@@ -1,4 +1,4 @@
 !-----------------------------------------------------------------------
-&namsbc_apr    !   Atmospheric pressure used as ocean forcing or in bulk
+&namsbc_apr    !   Atmospheric pressure used as ocean forcing           (ln_apr_dyn =T)
 !-----------------------------------------------------------------------
 !              ! file name ! frequency (hours) ! variable ! time interp.!  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_blk
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_blk	(revision 9019)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_blk	(revision 9019)
@@ -0,0 +1,32 @@
+!-----------------------------------------------------------------------
+&namsbc_blk   !   namsbc_blk  generic Bulk formula                      (ln_blk =T)
+!-----------------------------------------------------------------------
+!              !  file name                   ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights                              ! rotation ! land/sea mask !
+!              !                              !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename                             ! pairing  ! filename      !
+   sn_wndi     = 'u_10.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_slp      = 'slp.15JUNE2009_fill'        ,         6         , 'SLP'     ,   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_tdif     = 'taudif_core'                ,        24         , 'taudif'  ,   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   !                    !  bulk algorithm :
+   ln_NCAR     = .false.   ! "NCAR"      algorithm   (Large and Yeager 2008)
+   ln_COARE_3p0= .false.   ! "COARE 3.0" algorithm   (Fairall et al. 2003)
+   ln_COARE_3p5= .false.   ! "COARE 3.5" algorithm   (Edson et al. 2013)
+   ln_ECMWF    = .false.   ! "ECMWF"     algorithm   (IFS cycle 31)
+   !
+   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 used to
+   !                       !  calculate the wind stress (0.=absolute or 1.=relative winds)
+   ln_Cd_L12   = .false.   !  air-ice drags = F(ice concentration) (Lupkes et al. 2012)
+   ln_Cd_L15   = .false.   !  air-ice drags = F(ice concentration) (Lupkes et al. 2015)
+/
Index: anches/2017/dev_merge_2017/DOC/Namelists/namsbc_clio
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_clio	(revision 9018)
+++ 	(revision )
@@ -1,15 +1,0 @@
-!-----------------------------------------------------------------------
-&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
-/
Index: anches/2017/dev_merge_2017/DOC/Namelists/namsbc_core
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_core	(revision 9018)
+++ 	(revision )
@@ -1,24 +1,0 @@
-!-----------------------------------------------------------------------
-&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)
-/
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_cpl
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_cpl	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_cpl	(revision 9019)
@@ -10,4 +10,7 @@
    sn_snd_crt    =   'none'                 ,    'no'    , 'spherical' , 'eastward-northward' ,  'T'
    sn_snd_co2    =   'coupled'              ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_crtw   =       'none'                 ,    'no'    ,     ''      ,         ''           , 'U,V'
+   sn_snd_ifrac  =       'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_wlev   =       'coupled'              ,    'no'    ,     ''      ,         ''           ,   ''
 ! receive
    sn_rcv_w10m   =   'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
@@ -21,4 +24,14 @@
    sn_rcv_cal    =   'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
    sn_rcv_co2    =   'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_hsig   =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_iceflx =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_mslp   =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_phioc  =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_sdrfx  =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_sdrfy  =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_wper   =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_wnum   =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_wstrf  =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_wdrag  =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
 !
    nn_cplmodel   =     1   !  Maximum number of models to/from which NEMO is potentialy sending/receiving data
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_flx
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_flx	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_flx	(revision 9019)
@@ -9,5 +9,5 @@
    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
 /
Index: anches/2017/dev_merge_2017/DOC/Namelists/namsbc_mfs
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_mfs	(revision 9018)
+++ 	(revision )
@@ -1,15 +1,0 @@
-!-----------------------------------------------------------------------
-&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
-/
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_rnf
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_rnf	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_rnf	(revision 9019)
@@ -1,4 +1,4 @@
 !-----------------------------------------------------------------------
-&namsbc_rnf    !   runoffs namelist surface boundary condition          (ln_rnf=T)
+&namsbc_rnf    !   runoffs namelist surface boundary condition          (ln_rnf =T)
 !-----------------------------------------------------------------------
 !              !  file name           ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_sas
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_sas	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_sas	(revision 9019)
@@ -1,9 +1,9 @@
 !-----------------------------------------------------------------------
-&namsbc_sas    !   analytical surface boundary condition
+&namsbc_sas    !   Stand-Alone 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_usp      = 'sas_grid_U',     120           , 'uos'     ,   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_vsp      = 'sas_grid_V',     120           , 'vos'     ,   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
    sn_tem      = 'sas_grid_T',     120           , 'sosstsst',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
    sn_sal      = 'sas_grid_T',     120           , 'sosaline',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
@@ -12,5 +12,6 @@
    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
+   l_sasread   = .true.    !  =T Read the above fields in a file, =F initialize to 0. in sbcssm.F90
+   ln_3d_uve   = .false.   !  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
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_ssr
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_ssr	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_ssr	(revision 9019)
@@ -1,4 +1,4 @@
 !-----------------------------------------------------------------------
-&namsbc_ssr    !   surface boundary condition : sea surface restoring   (ln_ssr=T)
+&namsbc_ssr    !   surface boundary condition : sea surface restoring   (ln_ssr =T)
 !-----------------------------------------------------------------------
 !              ! file name ! frequency (hours) ! variable ! time interp.!  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
@@ -10,5 +10,5 @@
    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)
+   !                       !  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]
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_wave
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_wave	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namsbc_wave	(revision 9019)
@@ -2,13 +2,14 @@
 &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'   ,    ''      , ''       , ''
+!              !  file name  ! frequency (hours) ! variable     ! time interp. !  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !             !  (if <0  months)  !   name       !   (logical)  !  (T/F)  ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_cdg      =  'sdw_wave' ,        1          , 'drag_coeff' ,     .true.   , .false. , 'daily'   ,  ''      , ''       , ''
+   sn_usd      =  'sdw_wave' ,        1          , 'u_sd2d'     ,     .true.   , .false. , 'daily'   ,  ''      , ''       , ''
+   sn_vsd      =  'sdw_wave' ,        1          , 'v_sd2d'     ,     .true.   , .false. , 'daily'   ,  ''      , ''       , ''
+   sn_hsw      =  'sdw_wave' ,        1          , 'hs'         ,     .true.   , .false. , 'daily'   ,  ''      , ''       , ''
+   sn_wmp      =  'sdw_wave' ,        1          , 'wmp'        ,     .true.   , .false. , 'daily'   ,  ''      , ''       , ''
+   sn_wnum     =  'sdw_wave' ,        1          , 'wave_num'   ,     .true.   , .false. , 'daily'   ,  ''      , ''       , ''
+   sn_tauoc    =  'sdw_wave' ,        1          , 'wave_stress',     .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               
+   cn_dir  = './'  !  root directory for the location of drag coefficient files
 /
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namtra_adv
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namtra_adv	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namtra_adv	(revision 9019)
@@ -1,5 +1,6 @@
 !-----------------------------------------------------------------------
-&namtra_adv    !   advection scheme for tracer                          (default: NO advection)
+&namtra_adv    !   advection scheme for tracer                          (default: NO selection)
 !-----------------------------------------------------------------------
+   ln_traadv_NONE= .false. !  No tracer advection
    ln_traadv_cen = .false. !  2nd order centered scheme
       nn_cen_h   =  4            !  =2/4, horizontal 2nd order CEN / 4th order CEN
@@ -8,6 +9,4 @@
       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
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namtra_dmp
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namtra_dmp	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namtra_dmp	(revision 9019)
@@ -2,8 +2,8 @@
 &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)
+   ln_tradmp   =  .true.   !  add a damping term
+      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)
 /
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namtra_ldf
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namtra_ldf	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namtra_ldf	(revision 9019)
@@ -1,7 +1,7 @@
 !-----------------------------------------------------------------------
-&namtra_ldf    !   lateral diffusion scheme for tracers                 (default: NO diffusion)
+&namtra_ldf    !   lateral diffusion scheme for tracers                 (default: NO selection)
 !-----------------------------------------------------------------------
    !                       !  Operator type:
-   !                           !  no diffusion: set ln_traldf_lap=..._blp=F 
+   ln_traldf_NONE  =  .false.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namtra_ldfeiv
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namtra_ldfeiv	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namtra_ldfeiv	(revision 9019)
@@ -2,13 +2,13 @@
 &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
+   ln_ldfeiv     = .false. ! use eddy induced velocity parameterization
+      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
+      ln_ldfeiv_dia =.false.  ! diagnose eiv stream function and velocities
 /
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namtra_qsr
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namtra_qsr	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namtra_qsr	(revision 9019)
@@ -1,4 +1,4 @@
 !-----------------------------------------------------------------------
-&namtra_qsr    !   penetrative solar radiation                          (ln_traqsr=T)
+&namtra_qsr    !   penetrative solar radiation                          (ln_traqsr =T)
 !-----------------------------------------------------------------------
 !              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
@@ -14,4 +14,3 @@
    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
 /
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namzdf
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namzdf	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namzdf	(revision 9019)
@@ -1,16 +1,32 @@
 !-----------------------------------------------------------------------
-&namzdf        !   vertical physics
+&namzdf        !   vertical physics                                     (default: NO selection)
 !-----------------------------------------------------------------------
-   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
+   !                       ! type of vertical closure (required)
+   ln_zdfcst   = .false.      !  constant mixing
+   ln_zdfric   = .false.      !  local Richardson dependent formulation (T =>   fill namzdf_ric)
+   ln_zdftke   = .false.      !  Turbulent Kinetic Energy closure       (T =>   fill namzdf_tke)
+   ln_zdfgls   = .false.      !  Generic Length Scale closure           (T =>   fill namzdf_gls)
+   ln_zdfosm   = .false.      !  OSMOSIS BL closure                     (T =>   fill namzdf_osm)
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+      nn_evdm     =    0         ! apply on tracer (=0) or on tracer and momentum (=1)
+      rn_evd      =  100.        ! mixing coefficient [m2/s]
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+      nn_npc      =    1         ! frequency of application of npc
+      nn_npcp     =  365         ! npc control print frequency
+   !
+   ln_zdfddm   = .false.   ! double diffusive mixing
+      rn_avts  =    1.e-4     !  maximum avs (vertical mixing on salinity)
+      rn_hsbfr =    1.6       !  heat/salt buoyancy flux ratio
+   !
+   !                       ! gravity wave-driven vertical mixing
+   ln_zdfiwm   = .false.      ! internal wave-induced mixing            (T =>   fill namzdf_iwm)
+   ln_zdfswm   = .false.      ! surface  wave-induced mixing            (T => ln_wave=ln_sdw=T )
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.2e-4     !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   1.2e-5     !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
 /
Index: anches/2017/dev_merge_2017/DOC/Namelists/namzdf_ddm
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_ddm	(revision 9018)
+++ 	(revision )
@@ -1,6 +1,0 @@
-!-----------------------------------------------------------------------
-&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
-/
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_gls
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_gls	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_gls	(revision 9019)
@@ -1,4 +1,4 @@
 !-----------------------------------------------------------------------
-&namzdf_gls    !   GLS vertical diffusion                               ("key_zdfgls")
+&namzdf_gls    !   GLS vertical diffusion                               (ln_zdfgls =T)
 !-----------------------------------------------------------------------
    rn_emin       = 1.e-7   !  minimum value of e   [m2/s2]
@@ -10,6 +10,7 @@
    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)
+   rn_frac_hs    =   1.3   !  Fraction of wave height as roughness (if nn_z0_met>1)
+   nn_z0_met     =     2   !  Method for surface roughness computation (0/1/2/3)
+   !                             ! =3 requires ln_wave=T
    nn_bc_surf    =     1   !  surface condition (0/1=Dir/Neum)
    nn_bc_bot     =     1   !  bottom condition (0/1=Dir/Neum)
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_iwm
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_iwm	(revision 9019)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_iwm	(revision 9019)
@@ -0,0 +1,7 @@
+!-----------------------------------------------------------------------
+&namzdf_iwm    !    internal wave-driven mixing parameterization        (ln_zdfiwm =T)
+!-----------------------------------------------------------------------
+   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)
+/
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_osm
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_osm	(revision 9019)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_osm	(revision 9019)
@@ -0,0 +1,19 @@
+!-----------------------------------------------------------------------
+&namzdf_osm                !   OSM vertical diffusion                   ("key_zdfosm")
+!-----------------------------------------------------------------------
+   ln_use_osm_la = .false.     ! Use namelist  rn_osm_la
+   rn_osm_la     = 0.3         ! Turbulent Langmuir number
+   rn_osm_dstokes     = 5.     ! Depth scale of Stokes drift (m)
+   nn_ave = 0                  ! choice of horizontal averaging on avt, avmu, avmv
+   ln_dia_osm = .true.         ! output OSMOSIS-OBL variables
+   rn_osm_hbl0 = 10.           ! initial hbl value
+   ln_kpprimix = .true.        ! Use KPP-style Ri# mixing below BL
+   rn_riinfty  = 0.7           ! Highest local Ri_g permitting shear instability
+   rn_difri  =  0.005          ! max Ri# diffusivity at Ri_g = 0 (m^2/s)
+   ln_convmix  = .true.        ! Use convective instability mixing below BL
+   rn_difconv = 1.             ! diffusivity when unstable below BL  (m2/s)
+   nn_osm_wave = 0             ! Method used to calculate Stokes drift
+                               !  = 2: Use ECMWF wave fields
+                               !  = 1: Pierson Moskowitz wave spectrum
+                               !  = 0: Constant La# = 0.3
+/
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_ric
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_ric	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_ric	(revision 9019)
@@ -1,13 +1,13 @@
 !-----------------------------------------------------------------------
-&namzdf_ric    !   richardson number dependent vertical diffusion       ("key_zdfric" )
+&namzdf_ric    !   richardson number dependent vertical diffusion       (ln_zdfric =T)
 !-----------------------------------------------------------------------
    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.
+   ln_mldw     =  .false.  !  enhanced mixing in the Ekman layer
+      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
 /
Index: /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_tke
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_tke	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_tke	(revision 9019)
@@ -1,4 +1,4 @@
 !-----------------------------------------------------------------------
-&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  ("key_zdftke")
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  (ln_zdftke =T)
 !-----------------------------------------------------------------------
    rn_ediff    =   0.1     !  coef. for vertical eddy coef. (avt=rn_ediff*mxl*sqrt(e) )
@@ -8,21 +8,21 @@
    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_pdl      =   1       !  Prandtl number function of richarson number (=1, avt=pdl(Ri)*avm) or not (=0, avt=avm)
    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)
+   !                       !                 = 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
    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_drg      = .false.   !  top/bottom friction added as boundary condition of TKE
    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
+      rn_lc       =   0.15    !  coef. associated to Langmuir cells
+   nn_etau     =   1       !  penetration of tke below the mixed layer (ML) due to NIWs
+                              !        = 0 none ; = 1 add a tke source below the ML
+                              !        = 2 add a tke source just at the base of the ML
+                              !        = 3 as = 1 applied on HF part of the stress           (ln_cpl=T)
+      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
 /
Index: anches/2017/dev_merge_2017/DOC/Namelists/namzdf_tmx
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_tmx	(revision 9018)
+++ 	(revision )
@@ -1,10 +1,0 @@
-!-----------------------------------------------------------------------
-&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
-/
Index: anches/2017/dev_merge_2017/DOC/Namelists/namzdf_tmx_new
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namzdf_tmx_new	(revision 9018)
+++ 	(revision )
@@ -1,7 +1,0 @@
-!-----------------------------------------------------------------------
-&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)
-/
Index: anches/2017/dev_merge_2017/DOC/Namelists/namzgr
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namzgr	(revision 9018)
+++ 	(revision )
@@ -1,9 +1,0 @@
-!-----------------------------------------------------------------------
-&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
-/
Index: anches/2017/dev_merge_2017/DOC/Namelists/namzgr_sco
===================================================================
--- /branches/2017/dev_merge_2017/DOC/Namelists/namzgr_sco	(revision 9018)
+++ 	(revision )
@@ -1,25 +1,0 @@
-!-----------------------------------------------------------------------
-&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)
-/
Index: /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Chap_CFG.tex
===================================================================
--- /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Chap_CFG.tex	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Chap_CFG.tex	(revision 9019)
@@ -25,7 +25,4 @@
 in the code, though by no means are all options exercised in the reference configurations.
 
-Configuration is defined mainly through the \ngn{namcfg}  namelist variables:
-\sfcomment {Here change namcfg part of namelist. Configuration is defined throughout domain\_cfg.nc file now}  
-
 %------------------------------------------namcfg----------------------------------------------------
 \namdisplay{namcfg}
@@ -37,4 +34,8 @@
 \section{Water column model: 1D model (C1D) (\key{c1d}) }
 \label{CFG_c1d}
+
+$\ $\newline
+BE careful: to be re-written according to suppression of jpizoom and jpjzoom !!!!
+$\ $\newline
 
 The 1D model option simulates a stand alone water column within the 3D \NEMO system. 
@@ -85,8 +86,9 @@
 the LIM sea-ice model (ORCA-LIM) and possibly with PISCES biogeochemical model 
 (ORCA-LIM-PISCES), using various resolutions.
-The appropriate namelist is available in \textit{CONFIG/ORCA2\_LIM3\_PISCES/EXP00/namelist\_cfg} 
-for ORCA2 and in \textit{CONFIG/SHARED/README\_configs\_namcfg\_namdom}  \sfcomment {not really true, they are obsolete namelists, where find these informations?}  
-for other resolutions
-
+An appropriate namelist is available in \textit{CONFIG/ORCA2\_LIM3\_PISCES/EXP00/namelist\_cfg} 
+for ORCA2.
+The domain of ORCA2 configuration is defined in ORCA\_R2\_zps\_domcfg.nc file, this file is available in tar file in the wiki of NEMO : \\
+https://forge.ipsl.jussieu.fr/nemo/wiki/Users/ReferenceConfigurations/ORCA2\_LIM3\_PISCES \\
+In this namelist\_cfg the name of domain input file is set in \ngn{namcfg} block of namelist. 
 
 %>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -140,6 +142,6 @@
 than the smallest one in the southern hemisphere.
 The resulting mesh is shown in Fig.~\ref{Fig_MISC_ORCA_msh} and \ref{Fig_MISC_ORCA_e1e2} 
-for a half a degree grid (ORCA\_R05). The smallest ocean scale factor is found in along  
-Antarctica, while the ratio of anisotropy remains close to one except near the Victoria Island 
+for a half a degree grid (ORCA\_R05).
+The smallest ocean scale factor is found in along  Antarctica, while the ratio of anisotropy remains close to one except near the Victoria Island 
 in the Canadian Archipelago. 
 
@@ -153,7 +155,6 @@
 The NEMO system is provided with five built-in ORCA configurations which differ in the 
 horizontal resolution. The value of the resolution is given by the resolution at the Equator 
-expressed in degrees. Each of configuration is set through the \textit{domain\_cfg} file, 
-which sets the grid size and configuration name parameters \sfcomment {I would like to change tab_ORCA but I can not find it, wrong jp_cfg}  
- (Tab. \ref{Tab_ORCA}).
+expressed in degrees. Each of configuration is set through the \textit{domain\_cfg} domain configuration file, 
+which sets the grid size and configuration name parameters. The NEMO System Team provides only ORCA2 domain input file "ORCA\_R2\_zps\_domcfg.nc" file  (Tab. \ref{Tab_ORCA}).
 
 
@@ -175,6 +176,6 @@
 \end{tabular}
 \caption{ \label{Tab_ORCA}   
-Set of predefined parameters for ORCA family configurations.
-In all cases, the flag for configurations of ORCA family is set to 1 in \textit{domain\_cfg}  }
+Domain size of ORCA family configurations.
+The flag for configurations of ORCA family need to be set in \textit{domain\_cfg} file. }
 \end{center}
 \end{table}
Index: /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Chap_DOM.tex
===================================================================
--- /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Chap_DOM.tex	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Chap_DOM.tex	(revision 9019)
@@ -268,6 +268,5 @@
 
 The total size of the computational domain is set by the parameters \np{jpiglo}, 
-\np{jpjglo} and \np{jpkglo} in the $i$, $j$ and $k$ directions respectively. They are 
-given as namelist variables in the \ngn{namcfg} namelist. 
+\np{jpjglo} and \np{jpkglo} in the $i$, $j$ and $k$ directions respectively. 
 %%%
 %%%
@@ -278,18 +277,4 @@
 
 $\ $\newline    % force a new line
-
-%%%
-\sfcomment {Hereafter I want to create new subsection 4.2: "fields needed by opa engine or something like this"
-and add list of fields :
-case 1: read in domain.nc
-case 2: defined in userdef\_hrg\/zgr.F90
-longitude, latitude, domaine size 
-number of points
-factor scales (e1, e2, e3)
-coriolis
-k\_top, k\_bottom (first and last ocean level)
-periodicity
-}
-%%%
 
 % ================================================================
@@ -303,55 +288,29 @@
 The grid-points are located at integer or integer and a half values of as indicated 
 in Table~\ref{Tab_cell}. The associated scale factors are defined using the  
-analytical first derivative of the transformation \eqref{Eq_scale_factors}. These 
-definitions are done in two modules given by example, \mdl{userdef\_hgr} and \mdl{userdef\_zgr}, which 
-provide the horizontal and vertical meshes, respectively. Otherwise all needed fields can be read in file \np{cn\_domcfg} specified in \ngn{namcfg}.
+analytical first derivative of the transformation \eqref{Eq_scale_factors}. 
+Necessary fields for configuration definition are: \\
+Geographic position :
+
+longitude : glamt , glamu , glamv and glamf  (at T, U, V and F point)
+
+latitude : gphit , gphiu , gphiv and gphif (at T, U, V and F point)\\
+Coriolis parameter (if domain not on the sphere): 
+
+ ff\_f  and  ff\_t (at T and F point)\\
+Scale factors : 
  
-The needed fields for domain are: 
-
-geographic position :
-
-longitude : glamt , glamu , glamv and glamf  (at T, U, V and F point)
-
-latitude : gphit , gphiu , gphiv and gphif (at T, U, V and F point)
-
-Coriolis parameter (if domain not on the sphere):  ff\_f  and  ff\_t (at T and F point)
-
-Scale factors : e1t, e1u, e1v and e1f (on i direction),
-
-   e2t, e2u, e2v and e2f (on j direction)
-
-   and ie1e2u\_v, e1e2u , e1e2v   
-
-%%%
-\sfcomment {
-say something about ie1e2u\_v, e1e2u , e1e2v
-
-and add list of fields :
-case 1: read in domain.nc
-case 2: defined in userdef\_hrg\/zgr.F90
-longitude, latitude, domaine size
-number of points
-factor scales (e1, e2, e3)
-coriolis
-k\_top, k\_bottom (first and last ocean level)
-periodicity
-----
-        int ORCA ;
-   int ORCA\_index ;
-   int jpiglo ; j, k
-   int jperio ;
-   int ln_zco ; zps, sco
-   int ln_isfcav ;
-   double glamt(t, y, x) ; u,v,f
-   double gphit(t, y, x) ; u,v,f
-   double e1t(t, y, x) ; u,v,w,
-   double e2t(t, y, x) ; u,v,w
-   double ff\_f(t, y, x) ;  double ff\_t(t, y, x) ;
-   double e3t\_1d(t, z) ;
-   double e3w\_1d(t, z) ;
-   double e3t\_0(t, z, y, x) ; u0, v0 , w0
-----
-}
-
+ e1t, e1u, e1v and e1f (on i direction),
+
+ e2t, e2u, e2v and e2f (on j direction)
+
+ and ie1e2u\_v, e1e2u , e1e2v   
+ 
+e1e2u , e1e2v are u and v surfaces (if gridsize reduction in some straits)\\
+ie1e2u\_v is a flag to flag set u and  v surfaces are neither read nor computed.\\
+ 
+These fields can be read in an domain input file which name is setted in \np{cn\_domcfg} parameter specified in \ngn{namcfg}.
+\namdisplay{namcfg}
+or they can be defined in an analytical way in MY\_SRC directory of the configuration.
+For Reference Configurations of NEMO input domain files are supplied by NEMO System Team. For analytical definition of input fields two routines are supplied: \mdl{userdef\_hgr} and \mdl{userdef\_zgr}. They are an example of GYRE configuration parameters, and they are available in NEMO/OPA\_SRC/USR directory, they provide the horizontal and vertical mesh. 
 % -------------------------------------------------------------------------------------------------------------
 %        Needed fields 
@@ -446,54 +405,4 @@
 \label{DOM_hgr_msh_choice}
 
-The user has three options available in defining a horizontal grid, which involve 
-the namelist variable \np{jphgr\_mesh} of the \ngn{namcfg} namelist. 
-\begin{description}
-\item[\np{jphgr\_mesh}=0]  The most general curvilinear orthogonal grids.
-The coordinates and their first derivatives with respect to $i$ and $j$ are provided
-in a input file (\ifile{coordinates}), read in \rou{hgr\_read} subroutine of the domhgr module.
-\item[\np{jphgr\_mesh}=1 to 5] A few simple analytical grids are provided (see below). 
-For other analytical grids, the \mdl{domhgr} module must be modified by the user. 
-\end{description}
-
-There are two simple cases of geographical grids on the sphere. With 
-\np{jphgr\_mesh}=1, the grid (expressed in degrees) is regular in space, 
-with grid sizes specified by parameters \np{ppe1\_deg} and \np{ppe2\_deg}, 
-respectively. Such a geographical grid can be very anisotropic at high latitudes 
-because of the convergence of meridians (the zonal scale factors $e_1$ 
-become much smaller than the meridional scale factors $e_2$). The Mercator 
-grid (\np{jphgr\_mesh}=4) avoids this anisotropy by refining the meridional scale 
-factors in the same way as the zonal ones. In this case, meridional scale factors 
-and latitudes are calculated analytically using the formulae appropriate for 
-a Mercator projection, based on \np{ppe1\_deg} which is a reference grid spacing 
-at the equator (this applies even when the geographical equator is situated outside 
-the model domain). 
-%%%
-\gmcomment{ give here the analytical expression of the Mercator mesh}
-%%%
-In these two cases (\np{jphgr\_mesh}=1 or 4), the grid position is defined by the 
-longitude and latitude of the south-westernmost point (\np{ppglamt0} 
-and \np{ppgphi0}). Note that for the Mercator grid the user need only provide 
-an approximate starting latitude: the real latitude will be recalculated analytically, 
-in order to ensure that the equator corresponds to line passing through $t$- 
-and $u$-points.  
-
-Rectangular grids ignoring the spherical geometry are defined with 
-\np{jphgr\_mesh} = 2, 3, 5. The domain is either an $f$-plane (\np{jphgr\_mesh} = 2, 
-Coriolis factor is constant) or a beta-plane (\np{jphgr\_mesh} = 3, the Coriolis factor 
-is linear in the $j$-direction). The grid size is uniform in meter in each direction, 
-and given by the parameters \np{ppe1\_m} and \np{ppe2\_m} respectively. 
-The zonal grid coordinate (\textit{glam} arrays) is in kilometers, starting at zero 
-with the first $t$-point. The meridional coordinate (gphi. arrays) is in kilometers, 
-and the second $t$-point corresponds to coordinate $gphit=0$. The input 
-variable \np{ppglam0} is ignored. \np{ppgphi0} is used to set the reference 
-latitude for computation of the Coriolis parameter. In the case of the beta plane, 
-\np{ppgphi0} corresponds to the center of the domain. Finally, the special case 
-\np{jphgr\_mesh}=5 corresponds to a beta plane in a rotated domain for the 
-GYRE configuration, representing a classical mid-latitude double gyre system. 
-The rotation allows us to maximize the jet length relative to the gyre areas 
-(and the number of grid points). 
-
-The choice of the grid must be consistent with the boundary conditions specified 
-by \np{jperio}, a parameter found in \ngn{namcfg} namelist (see {\S\ref{LBC}).
 
 % -------------------------------------------------------------------------------------------------------------
@@ -684,5 +593,5 @@
 (Fig.~\ref{Fig_zgr}).
 
-If the ice shelf cavities are opened (\np{ln\_isfcav}=~true~}), the definition of $z_0$ is the same. 
+If the ice shelf cavities are opened (\np{ln\_isfcav}=~true~), the definition of $z_0$ is the same. 
 However, definition of $e_3^0$ at $t$- and $w$-points is respectively changed to:
 \begin{equation} \label{DOM_zgr_ana}
@@ -737,5 +646,5 @@
 \begin{table}     \begin{center} \begin{tabular}{c||r|r|r|r}
 \hline
-\textbf{LEVEL}& \textbf{gdept}& \textbf{gdepw}& \textbf{e3t }& \textbf{e3w  } \\ \hline
+\textbf{LEVEL}& \textbf{gdept\_1d}& \textbf{gdepw\_1d}& \textbf{e3t\_1d }& \textbf{e3w\_1d  } \\ \hline
 1	&	\textbf{  5.00}	&       0.00 &	\textbf{ 10.00} &	 10.00 \\	\hline
 2	&	\textbf{15.00}	& 	  10.00 &	\textbf{ 10.00} &	 10.00 \\	\hline
Index: /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Chap_MISC.tex
===================================================================
--- /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Chap_MISC.tex	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Chap_MISC.tex	(revision 9019)
@@ -2,5 +2,5 @@
 \begin{document}
 % ================================================================
-% Chapter ——— Miscellaneous Topics
+% Chapter --- Miscellaneous Topics
 % ================================================================
 \chapter{Miscellaneous Topics}
@@ -87,41 +87,8 @@
 
 % ================================================================
-% Sub-Domain Functionality (\textit{nizoom, njzoom}, namelist parameters)
-% ================================================================
-\section{Sub-Domain Functionality (\np{jpizoom}, \np{jpjzoom})}
+% Sub-Domain Functionality 
+% ================================================================
+\section{Sub-Domain Functionality}
 \label{MISC_zoom}
-
-The sub-domain functionality, also improperly called the zoom option 
-(improperly because it is not associated with a change in model resolution) 
-is a quite simple function that allows a simulation over a sub-domain of an 
-already defined configuration ($i.e.$ without defining a new mesh, initial 
-state and forcings). This option can be useful for testing the user settings 
-of surface boundary conditions, or the initial ocean state of a huge ocean 
-model configuration while having a small computer memory requirement. 
-It can also be used to easily test specific physics in a sub-domain (for example, 
-see \citep{Madec_al_JPO96} for a test of the coupling used in the global ocean 
-version of OPA between sea-ice and ocean model over the Arctic or Antarctic 
-ocean, using a sub-domain). In the standard model, this option does not 
-include any specific treatment for the ocean boundaries of the sub-domain: 
-they are considered as artificial vertical walls. Nevertheless, it is quite easy 
-to add a restoring term toward a climatology in the vicinity of such boundaries 
-(see \S\ref{TRA_dmp}).
-
-In order to easily define a sub-domain over which the computation can be 
-performed, the dimension of all input arrays (ocean mesh, bathymetry, 
-forcing, initial state, ...) are defined as \np{jpidta}, \np{jpjdta} and \np{jpkdta} 
-( in \ngn{namcfg} namelist), while the computational domain is defined through 
-\np{jpiglo}, \np{jpjglo} and \jp{jpk} (\ngn{namcfg} namelist). When running the 
-model over the whole domain, the user sets \np{jpiglo}=\np{jpidta} \np{jpjglo}=\np{jpjdta} 
-and \jp{jpk}=\jp{jpkdta}. When running the model over a sub-domain, the user 
-has to provide the size of the sub-domain, (\np{jpiglo}, \np{jpjglo}, \np{jpkglo}), 
-and the indices of the south western corner as \np{jpizoom} and \np{jpjzoom} in 
-the  \ngn{namcfg} namelist (Fig.~\ref{Fig_LBC_zoom}). 
-
-Note that a third set of dimensions exist, \jp{jpi}, \jp{jpj} and \jp{jpk} which is 
-actually used to perform the computation. It is set by default to \jp{jpi}=\np{jpjglo} 
-and \jp{jpj}=\np{jpjglo}, except for massively parallel computing where the 
-computational domain is laid out on local processor memories following a 2D 
-horizontal splitting. % (see {\S}IV.2-c) ref to the section to be updated
 
 \subsection{Simple subsetting of input files via netCDF attributes}
@@ -165,5 +132,5 @@
 \noindent Add the logical switch to \ngn{namcfg} in the configuration namelist and set true:
 %--------------------------------------------namcfg--------------------------------------------------------
-\namdisplay{namcfg_orca1}
+\namdisplay{namcfg}
 %--------------------------------------------------------------------------------------------------------------
 
Index: /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Chap_SBC.tex
===================================================================
--- /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Chap_SBC.tex	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Chap_SBC.tex	(revision 9019)
@@ -1266,7 +1266,7 @@
 ice-ocean fluxes, that are combined with the air-sea fluxes using the ice fraction of 
 each model cell to provide the surface ocean fluxes. Note that the activation of a 
-sea-ice model is is done by defining a CPP key (\key{lim2}, \key{lim3} or \key{cice}). 
+sea-ice model is is done by defining a CPP key (\key{lim3} or \key{cice}). 
 The activation automatically overwrites the read value of nn{\_}ice to its appropriate 
-value ($i.e.$ $2$ for LIM-2, $3$ for LIM-3 or $4$ for CICE).
+value ($i.e.$ $2$ for LIM-3 or $3$ for CICE).
 \end{description}
 
Index: /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Chap_ZDF.tex
===================================================================
--- /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Chap_ZDF.tex	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Chap_ZDF.tex	(revision 9019)
@@ -612,4 +612,15 @@
 Examples of performance of the 4 turbulent closure scheme can be found in \citet{Warner_al_OM05}.
 
+% -------------------------------------------------------------------------------------------------------------
+%        OSM OSMOSIS BL Scheme 
+% -------------------------------------------------------------------------------------------------------------
+\subsection{OSM OSMOSIS Boundary Layer scheme (\key{zdfosm})}
+\label{ZDF_osm}
+
+%--------------------------------------------namzdf_osm---------------------------------------------------------
+\namdisplay{namzdf_osm}
+%--------------------------------------------------------------------------------------------------------------
+
+The OSMOSIS turbulent closure scheme is based on......   TBC
 
 % ================================================================
@@ -734,5 +745,5 @@
 %       Turbulent Closure Scheme 
 % -------------------------------------------------------------------------------------------------------------
-\subsection{Turbulent Closure Scheme (\key{zdftke} or \key{zdfgls})}
+\subsection{Turbulent Closure Scheme (\key{zdftke}, \key{zdfgls} or \key{zdfosm})}
 \label{ZDF_tcs}
 
Index: /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Introduction.tex
===================================================================
--- /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Introduction.tex	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/TexFiles/Chapters/Introduction.tex	(revision 9019)
@@ -255,16 +255,16 @@
 $\bullet$ The main modifications from NEMO/OPA v3.4 and  v3.6 are :\\
 \begin{enumerate}
+ \item ... ; 
+\end{enumerate}
+
+
+ \vspace{1cm}
+$\bullet$ The main modifications from NEMO/OPA v3.6 and  v4.0 are :\\
+\begin{enumerate}
+\item new definition of configurations ;
+\item bulk formulation ;
 \item ... ; 
 \end{enumerate}
 
 
- \vspace{1cm}
-$\bullet$ The main modifications from NEMO/OPA v3.6 and  v4.0 are :\\
-\begin{enumerate}
-\item ... ; 
-
-
-\end{enumerate}
-
-
 \end{document}
Index: /branches/2017/dev_merge_2017/DOC/TexFiles/Top_Matter.tex
===================================================================
--- /branches/2017/dev_merge_2017/DOC/TexFiles/Top_Matter.tex	(revision 9018)
+++ /branches/2017/dev_merge_2017/DOC/TexFiles/Top_Matter.tex	(revision 9019)
@@ -17,5 +17,5 @@
 %\date{\today}
 \date{
-January 2017  \\
+Decembre 2017  \\
 {\small  -- version 4.0 alpha --} \\
 ~  \\
Index: /branches/2017/dev_merge_2017/NEMOGCM/ARCH/arch-X64_ADA.fcm
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/ARCH/arch-X64_ADA.fcm	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/ARCH/arch-X64_ADA.fcm	(revision 9019)
@@ -33,5 +33,5 @@
 %NCDF_HOME           /smplocal/pub/NetCDF/4.1.3/mpi
 %HDF5_HOME           /smplocal/pub/HDF5/1.8.9/par
-%XIOS_HOME           $WORKDIR/XIOS2
+%XIOS_HOME           $WORKDIR/XIOS
 ####%OASIS_HOME          $WORKDIR/oasis3-mct/BLD
 %OASIS_HOME          /not/defined
@@ -46,5 +46,5 @@
 %CPP	             cpp
 %FC                  mpiifort -c -cpp
-%FCFLAGS             -DCPP_PARA -i4 -r8 -O3 -xAVX -fp-model precise
+%FCFLAGS             -DCPP_PARA -i4 -r8 -O3 -axAVX,SSE4.2 -fp-model precise
 %FFLAGS              %FCFLAGS
 %LD                  mpiifort
Index: /branches/2017/dev_merge_2017/NEMOGCM/ARCH/arch-X64_ADA_DEBUG.fcm
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/ARCH/arch-X64_ADA_DEBUG.fcm	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/ARCH/arch-X64_ADA_DEBUG.fcm	(revision 9019)
@@ -33,5 +33,5 @@
 %NCDF_HOME           /smplocal/pub/NetCDF/4.1.3/mpi
 %HDF5_HOME           /smplocal/pub/HDF5/1.8.9/par
-%XIOS_HOME           $WORKDIR/XIOS2
+%XIOS_HOME           $WORKDIR/XIOS
 %OASIS_HOME          /not/yet/defined
 
@@ -45,5 +45,9 @@
 %CPP	             cpp
 %FC                  mpiifort -c -cpp
-%FCFLAGS             -DCPP_PARA -i4 -r8 -g -O0 -debug all -traceback -xAVX -fp-model precise -check all -ftrapuv -fpe0   
+## if no agrif
+%FCFLAGS             -DCPP_PARA -i4 -r8 -g -O0 -debug all -traceback -axAVX,SSE4.2 -fp-model precise -check all -ftrapuv -fpe0   
+## if agrif
+#%FCFLAGS             -DCPP_PARA -i4 -r8 -g -O0 -traceback -list -check bounds -check pointers
+##
 %FFLAGS              %FCFLAGS
 %LD                  mpiifort
Index: /branches/2017/dev_merge_2017/NEMOGCM/ARCH/arch-macport_osx_debug.fcm
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/ARCH/arch-macport_osx_debug.fcm	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/ARCH/arch-macport_osx_debug.fcm	(revision 9019)
@@ -42,5 +42,5 @@
 %NCDF_HOME           /opt/local
 %HDF5_HOME           /opt/local
-%XIOS_HOME           /Users/sflod/XIOS
+%XIOS_HOME           /Users/$( whoami )/xios-2.0
 %OASIS_HOME          /not/defined
 
@@ -52,5 +52,5 @@
 %OASIS_LIB           -L%OASIS_HOME/lib -lpsmile.MPI1 -lmct -lmpeu -lscrip
 
-%CPP	             cpp-mp-4.9
+%CPP	             cpp-mp-4.8
 %FC	             mpif90 
 #%FCFLAGS             -fdefault-real-8 -O3 -funroll-all-loops -fcray-pointer -ffree-line-length-none -fbounds-check
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/AMM12/EXP00/namelist_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/AMM12/EXP00/namelist_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/AMM12/EXP00/namelist_cfg	(revision 9019)
@@ -13,5 +13,5 @@
    nn_euler    =       1   !  = 0 : start with forward time step if ln_rstart=.true.
    cn_ocerst_in   = "amm12_restart_oce"   !  suffix of ocean restart name (input)
-   cn_ocerst_out  = "restart_oce_out"   !  suffix of ocean restart name (input)
+   cn_ocerst_out  = "restart"             !  suffix of ocean restart name (input)
    nn_stock    =    1296   !  frequency of creation of a restart file (modulo referenced to 1)
    nn_write    =     144   !  frequency of write in the output file   (modulo referenced to nit000) 
@@ -29,9 +29,4 @@
 !-----------------------------------------------------------------------
    rn_rdt      =   600.    !  time step for the dynamics (and tracer if nn_acc=0)
-/
-!-----------------------------------------------------------------------
-&namcrs        !   Grid coarsening for dynamics output and/or
-!              !   passive tracer coarsened online simulations
-!-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
@@ -179,13 +174,25 @@
    filtide      = 'bdydta/amm12_bdytide_'         !  file name root of tidal forcing files
 /
-!-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    2      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-   rn_bfri2    =    2.5e-3 !  bottom drag coefficient (non linear case)
-   rn_bfeb2    =    0.0e0  !  bottom turbulent kinetic energy background  (m2/s2)
-   ln_loglayer =    .true. !  loglayer bottom friction (only effect when nn_bfr = 2)
-   rn_bfrz0    =    0.003  !  bottom roughness (only effect when ln_loglayer = .true.)
+
+!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .false.    !  free-slip       : Cd = 0                  (F => fill namdrg_bot
+   ln_lin     = .false.    !      linear  drag: Cd = Cd0 Uc0                   &   namdrg_top)
+   ln_non_lin = .false.    !  non-linear  drag: Cd = Cd0 |U|
+   ln_loglayer= .true.     !  logarithmic drag: Cd = vkarmn/log(z/z0) |U|
+   !
+   ln_drgimp  = .true.     !  implicit top/bottom friction flag
+/
+!-----------------------------------------------------------------------
+&namdrg_bot        !   BOTTOM friction                                  
+!-----------------------------------------------------------------------
+   rn_Cd0     =  2.5e-3   !  drag coefficient [-]
+   rn_Uc0     =  0.4      !  ref. velocity [m/s] (linear drag=Cd0*Uc0) 
+   rn_Cdmax   =  0.1      !  drag value maximum [-] (logarithmic drag)
+   rn_ke0     =  0.0e0    !  background kinetic energy  [m2/s2] (non-linear cases)
+   rn_z0      =  0.003    !  roughness [m]  (ln_loglayer=T)
+   ln_boost   = .false.   !  =T regional boost of Cd0 ; =F constant
+      rn_boost=  50.         !  local boost factor  [-]
 /
 !-----------------------------------------------------------------------
@@ -194,7 +201,6 @@
 /
 !-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme
-!-----------------------------------------------------------------------
-   nn_bbl_ldf  =  0      !  diffusive bbl (=1)   or not (=0)
+&nambbl        !   bottom boundary layer scheme                         (default: NO)
+!-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
@@ -204,11 +210,9 @@
 /
 !-----------------------------------------------------------------------
-&namtra_adv    !   advection scheme for tracer
+&namtra_adv    !   advection scheme for tracer                          (default: NO advection)
 !-----------------------------------------------------------------------
    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)
 /
 !-----------------------------------------------------------------------
@@ -220,4 +224,5 @@
 !----------------------------------------------------------------------------------
    !                       !  Operator type:
+   ln_traldf_NONE  = .false.   !           No operator (no explicit diffusion)
    ln_traldf_lap   =  .true.   !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -258,6 +263,8 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection
-!-----------------------------------------------------------------------
+&namdyn_adv    !   formulation of the momentum advection                (default: None)
+!-----------------------------------------------------------------------
+   ln_dynadv_vec = .true.  !  vector form - 2nd centered scheme
+     nn_dynkeg     = 0        ! grad(KE) scheme: =0   C2  ;  =1   Hollingsworth correction
 /
 !-----------------------------------------------------------------------
@@ -287,5 +294,5 @@
 !-----------------------------------------------------------------------
    !                       !  Type of the operator :
-   !                           !  no diffusion: set ln_dynldf_lap=..._blp=F 
+   ln_dynldf_NONE=  .false.    !           No operator (no explicit diffusion)
    ln_dynldf_lap =  .false.    !    laplacian operator
    ln_dynldf_blp =  .true.     !  bilaplacian operator
@@ -310,21 +317,45 @@
 /
 !-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   0.1e-6  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.1e-6  !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.   !  enhanced vertical diffusion (evd) (T) or not (F)
-   nn_evdm     =    1      !  evd apply on tracer (=0) or on tracer and momentum (=1)
-/
-!-----------------------------------------------------------------------
-&namzdf_ric    !   richardson number dependent vertical diffusion       ("key_zdfric" )
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  ("key_zdftke")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_gls                !   GLS vertical diffusion                   ("key_zdfgls")
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .false.      !  constant mixing
+   ln_zdfric   = .false.      !  local Richardson dependent formulation (T =>   fill namzdf_ric)
+   ln_zdftke   = .false.      !  Turbulent Kinetic Energy closure       (T =>   fill namzdf_tke)
+   ln_zdfgls   = .true.       !  Generic Length Scale closure           (T =>   fill namzdf_gls)
+   ln_zdfosm   = .false.      !  OSMOSIS BL closure                     (T =>   fill namzdf_osm)
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+      nn_evdm     =    0         ! apply on tracer (=0) or on tracer and momentum (=1)
+      rn_evd      =  100.        ! mixing coefficient [m2/s]
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+      nn_npc      =    1         ! frequency of application of npc
+      nn_npcp     =  365         ! npc control print frequency
+   !
+   ln_zdfddm   = .false.   ! double diffusive mixing
+      rn_avts  =    1.e-4     !  maximum avs (vertical mixing on salinity)
+      rn_hsbfr =    1.6       !  heat/salt buoyancy flux ratio
+   !
+   !                       ! gravity wave-driven vertical mixing
+   ln_zdfiwm   = .false.      ! internal wave-induced mixing            (T =>   fill namzdf_iwm)
+   ln_zdfswm   = .false.      ! surface  wave-induced mixing            (T => ln_wave=ln_sdw=T )
+   !
+   !                       ! coefficients
+   rn_avm0     =   0.1e-6     !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   0.1e-6     !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
+/
+!-----------------------------------------------------------------------
+&namzdf_ric    !   richardson number dependent vertical diffusion       (ln_zdfric =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  (ln_zdftke =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_gls                !   GLS vertical diffusion                   (ln_zdfgls =T)
 !-----------------------------------------------------------------------
    rn_charn =  100000.     !  Charnock constant for wb induced roughness length
@@ -332,11 +363,10 @@
 /
 !-----------------------------------------------------------------------
-&namzdf_ddm    !   double diffusive mixing parameterization             ("key_zdfddm")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_tmx    !   tidal mixing parameterization                        ("key_zdftmx")
-!-----------------------------------------------------------------------
-   ln_tmx_itf  = .FALSE.   !  ITF specific parameterisation
+&namzdf_osm                !   OSM vertical diffusion                   (ln_zdfosm =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_iwm    !   internal wave-driven mixing parameterization         (ln_zdfiwm =T)
+!-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/AMM12/cpp_AMM12.fcm
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/AMM12/cpp_AMM12.fcm	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/AMM12/cpp_AMM12.fcm	(revision 9019)
@@ -1,1 +1,1 @@
- bld::tool::fppkeys key_zdfgls key_diainstant key_mpp_mpi key_iomput
+ bld::tool::fppkeys   key_diainstant key_mpp_mpi key_iomput
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/C1D_PAPA/EXP00/namelist_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/C1D_PAPA/EXP00/namelist_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/C1D_PAPA/EXP00/namelist_cfg	(revision 9019)
@@ -60,9 +60,4 @@
 /
 !-----------------------------------------------------------------------
-&namcrs        !   Grid coarsening for dynamics output and/or
-               !   passive tracer coarsened online simulations
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
 &namc1d        !   1D configuration options                             ("key_c1d")
 !-----------------------------------------------------------------------
@@ -110,9 +105,9 @@
    sn_slp      = 'slp.15JUNE2009_fill'        ,         6         , 'SLP',        .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
 
-   nn_bulk_algo = 1        !  Bulk algorithm to use to compute bulk transfer coefficients Cd, Ce and Ch
-                           !  1 => "NCAR" algorithm        (Large and Yeager, 2008)
-                           !  2 => "COARE 3.0" algorithm   (Fairall et al 2003)
-                           !  3 => "ECMWF" algorithm       (IFS cycle 31)
-                           !  4 => "COARE 3.5" algorithm   (Edson et al 2013)
+   !                    !  bulk algorithm :
+   ln_NCAR     = .true.    ! "NCAR"      algorithm   (Large and Yeager 2008)
+   ln_COARE_3p0= .false.   ! "COARE 3.0" algorithm   (Fairall et al. 2003)
+   ln_COARE_3p5= .false.   ! "COARE 3.5" algorithm   (Edson et al. 2013)
+   ln_ECMWF    = .false.   ! "ECMWF"     algorithm   (IFS cycle 31)
 
    rn_zqt      =  2.       !  Air temperature and humidity reference height (m)
@@ -123,9 +118,5 @@
 /
 !-----------------------------------------------------------------------
-&namsbc_sas    !   analytical surface boundary condition
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namtra_qsr    !   penetrative solar radiation
+&namtra_qsr    !   penetrative solar radiation                          (ln_traqsr =T)
 !-----------------------------------------------------------------------
 !              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
@@ -134,9 +125,4 @@
 /
 !-----------------------------------------------------------------------
-&namsbc_rnf    !   runoffs namelist surface boundary condition
-!-----------------------------------------------------------------------
-   ln_rnf_mouth = .false.   !  specific treatment at rivers mouths
-/
-!-----------------------------------------------------------------------
 &namsbc_apr    !   Atmospheric pressure used as ocean forcing or in bulk
 !-----------------------------------------------------------------------
@@ -154,36 +140,7 @@
 /
 !-----------------------------------------------------------------------
-&namberg       !   iceberg parameters
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namlbc        !   lateral momentum boundary condition
-!-----------------------------------------------------------------------
-   rn_shlat    =    0.     !  shlat = 0  !  0 < shlat < 2  !  shlat = 2  !  2 < shlat
-/
-!-----------------------------------------------------------------------
-&namagrif      !  AGRIF zoom                                            ("key_agrif")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nam_tide      !    tide parameters
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy        !  unstructured open boundaries                          
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy_dta      !  open boundaries - external data           
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy_tide     ! tidal forcing at open boundaries
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    2      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_non_lin = .true.     !  non-linear  drag: Cd = Cd0 |U|
 /
 !-----------------------------------------------------------------------
@@ -192,8 +149,4 @@
 /
 !-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
 &nameos        !   ocean physical parameters
 !-----------------------------------------------------------------------
@@ -203,8 +156,8 @@
 &namtra_adv    !   advection scheme for tracer
 !-----------------------------------------------------------------------
-! C1D : no advection scheme 
-/
-!-----------------------------------------------------------------------
-&namtra_adv_mle !  mixed layer eddy parametrisation (Fox-Kemper param)
+   ln_traadv_NONE= .true.  !  No tracer advection
+/
+!-----------------------------------------------------------------------
+&namtra_adv_mle !  mixed layer eddy parametrisation (Fox-Kemper param)  (default: NO)
 !-----------------------------------------------------------------------
 /
@@ -212,10 +165,9 @@
 &namtra_ldf    !   lateral diffusion scheme for tracers
 !-----------------------------------------------------------------------
-! C1D : no lateral diffusion  
-/
-!-----------------------------------------------------------------------
-&namtra_ldfeiv !   eddy induced velocity param.
-!-----------------------------------------------------------------------
-! C1D : no eiv  
+   ln_traldf_NONE= .true.  ! No operator (no explicit diffusion)
+/
+!-----------------------------------------------------------------------
+&namtra_ldfeiv !   eddy induced velocity param.                         (default: NO)
+!-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
@@ -225,7 +177,7 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection
-!-----------------------------------------------------------------------
-! C1D : no advection scheme 
+&namdyn_adv    !   formulation of the momentum advection                (default: None)
+!-----------------------------------------------------------------------
+   ln_dynadv_NONE= .true.  !  linear dynamics (no momentum advection)
 /
 !-----------------------------------------------------------------------
@@ -252,42 +204,60 @@
 &namdyn_ldf    !   lateral diffusion on momentum
 !-----------------------------------------------------------------------
-   ln_dynldf_lap    =  .false.  !  laplacian operator
-/
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   ln_zdfevd   = .false.        !  enhanced vertical diffusion (evd) (T) or not (F)
-/
-!-----------------------------------------------------------------------
-&namzdf_ric    !   richardson number dependent vertical diffusion       ("key_zdfric" )
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  ("key_zdftke")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_gls                !   GLS vertical diffusion                   ("key_zdfgls")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_ddm    !   double diffusive mixing parameterization             ("key_zdfddm")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_tmx    !   tidal mixing parameterization                        ("key_zdftmx")
-!-----------------------------------------------------------------------
-   ln_tmx_itf  = .false.   !  ITF specific parameterisation
-/
-!-----------------------------------------------------------------------
-&nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi)
+   ln_dynldf_NONE= .true.     ! No operator (no explicit diffusion)
+/
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .false.      !  constant mixing
+   ln_zdfric   = .false.      !  local Richardson dependent formulation (T =>   fill namzdf_ric)
+   ln_zdftke   = .false.      !  Turbulent Kinetic Energy closure       (T =>   fill namzdf_tke)
+   ln_zdfgls   = .true.       !  Generic Length Scale closure           (T =>   fill namzdf_gls)
+   ln_zdfosm   = .false.      !  OSMOSIS BL closure                     (T =>   fill namzdf_osm)
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+      nn_evdm     =    0         ! apply on tracer (=0) or on tracer and momentum (=1)
+      rn_evd      =  100.        ! mixing coefficient [m2/s]
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+      nn_npc      =    1         ! frequency of application of npc
+      nn_npcp     =  365         ! npc control print frequency
+   !
+   ln_zdfddm   = .false.   ! double diffusive mixing
+      rn_avts  =    1.e-4     !  maximum avs (vertical mixing on salinity)
+      rn_hsbfr =    1.6       !  heat/salt buoyancy flux ratio
+   !
+   !                       ! gravity wave-driven vertical mixing
+   ln_zdfiwm   = .false.      ! internal wave-induced mixing            (T =>   fill namzdf_iwm)
+   ln_zdfswm   = .false.      ! surface  wave-induced mixing            (T => ln_wave=ln_sdw=T )
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.2e-4     !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   1.2e-5     !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
+/
+!-----------------------------------------------------------------------
+&namzdf_ric    !   richardson number dependent vertical diffusion       (ln_zdfric =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  (ln_zdftke =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_gls                !   GLS vertical diffusion                   (ln_zdfgls =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_osm                !   OSM vertical diffusion                   (ln_zdfosm =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_iwm    !    internal wave-driven mixing parameterization        (ln_zdfiwm =T)
 !-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
 &namctl        !   Control prints & Benchmark
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namnc4        !   netcdf4 chunking and compression settings            ("key_netcdf4")
 !-----------------------------------------------------------------------
 /
@@ -298,32 +268,9 @@
 /
 !-----------------------------------------------------------------------
-&namflo       !   float parameters                                      ("key_float")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namptr       !   Poleward Transport Diagnostic
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
 &namhsb       !  Heat and salt budgets
 !-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
-&namdct        ! transports through sections
-!-----------------------------------------------------------------------
-    nn_dct      = 60       !  time step frequency for transports computing
-    nn_dctwri   = 60       !  time step frequency for transports writing
-    nn_secdebug = 0        !      0 : no section to debug
-/
-!-----------------------------------------------------------------------
 &namobs       !  observation usage switch                               ('key_diaobs')
 !-----------------------------------------------------------------------
 /
-!-----------------------------------------------------------------------
-&nam_asminc   !   assimilation increments                               ('key_asminc')
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namsbc_wave   ! External fields from wave model
-!-----------------------------------------------------------------------
-/
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/C1D_PAPA/cpp_C1D_PAPA.fcm
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/C1D_PAPA/cpp_C1D_PAPA.fcm	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/C1D_PAPA/cpp_C1D_PAPA.fcm	(revision 9019)
@@ -1,1 +1,1 @@
- bld::tool::fppkeys key_c1d key_zdfgls
+ bld::tool::fppkeys   key_c1d key_zdfgls
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_cfg	(revision 9019)
@@ -43,6 +43,5 @@
 /
 !-----------------------------------------------------------------------
-&namcrs        !   Grid coarsening for dynamics output and/or
-!              !   passive tracer coarsened online simulations
+&namcrs        !   coarsened grid (for outputs and/or TOP)              (ln_crs =T)
 !-----------------------------------------------------------------------
 /
@@ -122,7 +121,7 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    2      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_non_lin = .true.     !  non-linear  drag: Cd = Cd0 |U|
 /
 !-----------------------------------------------------------------------
@@ -140,20 +139,19 @@
 /
 !-----------------------------------------------------------------------
-&namtra_adv    !   advection scheme for tracer
+&namtra_adv    !   advection scheme for tracer                          (default: No selection)
 !-----------------------------------------------------------------------
    ln_traadv_fct =  .true.   !  FCT scheme
       nn_fct_h   =  2               !  =2/4, horizontal 2nd / 4th order 
       nn_fct_v   =  2               !  =2/4, vertical   2nd / COMPACT 4th order 
-      nn_fct_zts =  0               !  >=1,  2nd order FCT scheme with vertical sub-timestepping
-      !                             !        (number of sub-timestep = nn_fct_zts)
-/
-!-----------------------------------------------------------------------
-&namtra_adv_mle !  mixed layer eddy parametrisation (Fox-Kemper param)
-!-----------------------------------------------------------------------
-/
-!----------------------------------------------------------------------------------
-&namtra_ldf    !   lateral diffusion scheme for tracers
-!----------------------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtra_adv_mle !  mixed layer eddy parametrisation (Fox-Kemper param)  (default: NO)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtra_ldf    !   lateral diffusion scheme for tracers                 (default: No selection)
+!-----------------------------------------------------------------------
    !                       !  Operator type:
+   ln_traldf_NONE  = .false.   !           No operator (no explicit advection)
    ln_traldf_lap   =  .true.   !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -183,7 +181,7 @@
    rn_bht_0        = 1.e+12    !  lateral eddy diffusivity (bilap. operator) [m4/s]
 /
-!----------------------------------------------------------------------------------
-&namtra_ldfeiv !   eddy induced velocity param.
-!----------------------------------------------------------------------------------
+!-----------------------------------------------------------------------
+&namtra_ldfeiv !   eddy induced velocity param.                         (default: NO)
+!-----------------------------------------------------------------------
    ln_ldfeiv     =.false.   ! use eddy induced velocity parameterization
 /
@@ -194,6 +192,8 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection
-!-----------------------------------------------------------------------
+&namdyn_adv    !   formulation of the momentum advection                (default: No selection)
+!-----------------------------------------------------------------------
+   ln_dynadv_vec = .true.  !  vector form - 2nd centered scheme
+     nn_dynkeg     = 0        ! grad(KE) scheme: =0   C2  ;  =1   Hollingsworth correction
 /
 !-----------------------------------------------------------------------
@@ -221,5 +221,5 @@
 !-----------------------------------------------------------------------
    !                       !  Type of the operator :
-   !                           !  no diffusion: set ln_dynldf_lap=..._blp=F 
+   ln_dynldf_NONE=  .false.    !           No operator (no explicit diffusion)
    ln_dynldf_lap =  .true.     !    laplacian operator
    ln_dynldf_blp =  .false.    !  bilaplacian operator
@@ -242,29 +242,55 @@
 /
 !-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   nn_evdm     =    1      !  evd apply on tracer (=0) or on tracer and momentum (=1)
-/
-!-----------------------------------------------------------------------
-&namzdf_ric    !   richardson number dependent vertical diffusion       ("key_zdfric" )
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  ("key_zdftke")
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .false.      !  constant mixing
+   ln_zdfric   = .false.      !  local Richardson dependent formulation (T =>   fill namzdf_ric)
+   ln_zdftke   = .true.       !  Turbulent Kinetic Energy closure       (T =>   fill namzdf_tke)
+   ln_zdfgls   = .false.      !  Generic Length Scale closure           (T =>   fill namzdf_gls)
+   ln_zdfosm   = .false.      !  OSMOSIS BL closure                     (T =>   fill namzdf_osm)
+   !
+   !                       ! convection
+   ln_zdfevd   = .true.       !  enhanced vertical diffusion
+      nn_evdm     =    1         ! apply on tracer (=0) or on tracer and momentum (=1)
+      rn_evd      =  100.        ! mixing coefficient [m2/s]
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+      nn_npc      =    1         ! frequency of application of npc
+      nn_npcp     =  365         ! npc control print frequency
+   !
+   ln_zdfddm   = .false.   ! double diffusive mixing
+      rn_avts  =    1.e-4     !  maximum avs (vertical mixing on salinity)
+      rn_hsbfr =    1.6       !  heat/salt buoyancy flux ratio
+   !
+   !                       ! gravity wave-driven vertical mixing
+   ln_zdfiwm   = .false.      ! internal wave-induced mixing            (T =>   fill namzdf_iwm)
+   ln_zdfswm   = .false.      ! surface  wave-induced mixing            (T => ln_wave=ln_sdw=T )
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.2e-4     !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   1.2e-5     !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
+/
+!-----------------------------------------------------------------------
+&namzdf_ric    !   richardson number dependent vertical diffusion       (ln_zdfric =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  (ln_zdftke")
 !-----------------------------------------------------------------------
    nn_etau     =   0       !  penetration of tke below the mixed layer (ML) due to internal & intertial waves
 /
 !-----------------------------------------------------------------------
-&namzdf_gls                !   GLS vertical diffusion                   ("key_zdfgls")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_ddm    !   double diffusive mixing parameterization             ("key_zdfddm")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_tmx    !   tidal mixing parameterization                        ("key_zdftmx")
-!-----------------------------------------------------------------------
-   ln_tmx_itf  = .false.   !  ITF specific parameterisation
+&namzdf_gls                !   GLS vertical diffusion                   (ln_zdfgls =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_osm                !   OSM vertical diffusion                   (ln_zdfosm =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_iwm    !    internal wave-driven mixing parameterization        (ln_zdfiwm =T)
+!-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_top_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_top_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_top_cfg	(revision 9019)
@@ -22,11 +22,9 @@
 /
 !-----------------------------------------------------------------------
-&namtrc_adv    !   advection scheme for passive tracer 
+&namtrc_adv    !   advection scheme for passive tracer                  (default: NO selection)
 !-----------------------------------------------------------------------
    ln_trcadv_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)
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_BFM/cpp_GYRE_BFM.fcm
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_BFM/cpp_GYRE_BFM.fcm	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_BFM/cpp_GYRE_BFM.fcm	(revision 9019)
@@ -1,2 +1,2 @@
-bld::tool::fppkeys key_zdftke key_top key_my_trc key_mpp_mpi key_iomput
+bld::tool::fppkeys   key_top key_my_trc key_mpp_mpi key_iomput
 inc $BFMDIR/src/nemo/bfm.fcm
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_PISCES/EXP00/namelist_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_PISCES/EXP00/namelist_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_PISCES/EXP00/namelist_cfg	(revision 9019)
@@ -12,7 +12,4 @@
 !!                   ***  Run management namelists  ***
 !!======================================================================
-!!   namrun        parameters of the run
-!!======================================================================
-!
 !-----------------------------------------------------------------------
 &namrun        !   parameters of the run
@@ -25,4 +22,7 @@
    nn_write    =      60   !  frequency of write in the output file   (modulo referenced to nn_it000)
 /
+!!======================================================================
+!!                      ***  Domain namelists  ***
+!!======================================================================
 !-----------------------------------------------------------------------
 &namcfg     !   parameters of the configuration   
@@ -37,13 +37,6 @@
 !-----------------------------------------------------------------------
    ln_linssh   = .true.    !  =T  linear free surface  ==>>  model level are fixed in time
-   !
    nn_msh      =    0      !  create (>0) a mesh file or not (=0)
-   !
    rn_rdt      = 7200.     !  time step for the dynamics (and tracer if nn_acc=0)
-/
-!-----------------------------------------------------------------------
-&namcrs        !   Grid coarsening for dynamics output and/or
-!              !   passive tracer coarsened online simulations
-!-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
@@ -56,4 +49,8 @@
    ln_tsd_tradmp = .false.   !  damping of ocean T & S toward T &S input data (T) or not (F)
 /
+
+!!======================================================================
+!!            ***  Surface Boundary Condition namelists  ***
+!!======================================================================
 !-----------------------------------------------------------------------
 &namsbc        !   Surface Boundary Condition (surface module)
@@ -76,25 +73,4 @@
 /
 !-----------------------------------------------------------------------
-&namsbc_rnf    !   runoffs namelist surface boundary condition
-!-----------------------------------------------------------------------
-   ln_rnf_mouth = .false.   !  specific treatment at rivers mouths
-/
-!-----------------------------------------------------------------------
-&namsbc_apr    !   Atmospheric pressure used as ocean forcing or in bulk
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namsbc_ssr    !   surface boundary condition : sea surface restoring
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namsbc_alb    !   albedo parameters
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namberg       !   iceberg parameters
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
 &namlbc        !   lateral momentum boundary condition
 !-----------------------------------------------------------------------
@@ -102,34 +78,10 @@
 /
 !-----------------------------------------------------------------------
-&namagrif      !  AGRIF zoom                                            ("key_agrif")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nam_tide      !    tide parameters
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy        !  unstructured open boundaries                          
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy_dta      !  open boundaries - external data           
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambdy_tide     ! tidal forcing at open boundaries
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    2      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme
+&namdrg        !   top/bottom friction
+!-----------------------------------------------------------------------
+   ln_non_lin = .true.     !  non-linear  drag: Cd = Cd0 |U|
+/
+!-----------------------------------------------------------------------
+&nambbl        !   bottom boundary layer scheme                         (default: NO)
 !-----------------------------------------------------------------------
 /
@@ -140,20 +92,19 @@
 /
 !-----------------------------------------------------------------------
-&namtra_adv    !   advection scheme for tracer
+&namtra_adv    !   advection scheme for tracer                          (default: No selection)
 !-----------------------------------------------------------------------
    ln_traadv_fct =  .true.   !  FCT scheme
       nn_fct_h   =  2               !  =2/4, horizontal 2nd / 4th order 
       nn_fct_v   =  2               !  =2/4, vertical   2nd / COMPACT 4th order 
-      nn_fct_zts =  0               !  >=1,  2nd order FCT scheme with vertical sub-timestepping
-      !                             !        (number of sub-timestep = nn_fct_zts)
-/
-!-----------------------------------------------------------------------
-&namtra_adv_mle !  mixed layer eddy parametrisation (Fox-Kemper param)
-!-----------------------------------------------------------------------
-/
-!----------------------------------------------------------------------------------
-&namtra_ldf    !   lateral diffusion scheme for tracers
-!----------------------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtra_adv_mle !  mixed layer eddy parametrisation (Fox-Kemper param)  (default: NO)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtra_ldf    !   lateral diffusion scheme for tracers                 (default: No selection)
+!-----------------------------------------------------------------------
    !                       !  Operator type:
+   ln_traldf_NONE  =  .false.  !           No operator (no explicit advection)
    ln_traldf_lap   =  .true.   !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -194,9 +145,11 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namdyn_vor    !   option of physics/algorithm (not control by CPP keys)
+&namdyn_adv    !   formulation of the momentum advection                (default: No selection)
+!-----------------------------------------------------------------------
+   ln_dynadv_vec = .true.  !  vector form - 2nd centered scheme
+     nn_dynkeg     = 0        ! grad(KE) scheme: =0   C2  ;  =1   Hollingsworth correction
+/
+!-----------------------------------------------------------------------
+&namdyn_vor    !   option of physics/algorithm                          (default: No selection)
 !-----------------------------------------------------------------------
    ln_dynvor_ene = .true.  !  enstrophy conserving scheme
@@ -218,8 +171,8 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_ldf    !   lateral diffusion on momentum
+&namdyn_ldf    !   lateral diffusion on momentum                        (default: No selection)
 !-----------------------------------------------------------------------
    !                       !  Type of the operator :
-   !                           !  no diffusion: set ln_dynldf_lap=..._blp=F 
+   ln_dynldf_NONE=  .false.    !           No operator (no explicit diffusion)
    ln_dynldf_lap =  .true.     !    laplacian operator
    ln_dynldf_blp =  .false.    !  bilaplacian operator
@@ -241,30 +194,58 @@
    rn_bhm_0      =      0.     !  horizontal bilaplacian eddy viscosity [m4/s]
 /
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   nn_evdm     =    1      !  evd apply on tracer (=0) or on tracer and momentum (=1)
-/
-!-----------------------------------------------------------------------
-&namzdf_ric    !   richardson number dependent vertical diffusion       ("key_zdfric" )
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  ("key_zdftke")
+
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .false.      !  constant mixing
+   ln_zdfric   = .false.      !  local Richardson dependent formulation (T =>   fill namzdf_ric)
+   ln_zdftke   = .true.       !  Turbulent Kinetic Energy closure       (T =>   fill namzdf_tke)
+   ln_zdfgls   = .false.      !  Generic Length Scale closure           (T =>   fill namzdf_gls)
+   ln_zdfosm   = .false.      !  OSMOSIS BL closure                     (T =>   fill namzdf_osm)
+   !
+   !                       ! convection
+   ln_zdfevd   = .true.       !  Enhanced Vertical Diffusion scheme
+      nn_evdm  =    1            !  evd apply on tracer (=0) or on tracer and momentum (=1)
+      rn_evd   =  100.           !  evd mixing coefficient [m2/s]
+   !
+   ln_zdfddm   = .false.   ! double diffusive mixing
+      rn_avts  =    1.e-4     !  maximum avs (vertical mixing on salinity)
+      rn_hsbfr =    1.6       !  heat/salt buoyancy flux ratio
+   !
+   !                       ! gravity wave-driven vertical mixing
+   ln_zdfiwm   = .false.      ! internal wave-induced mixing            (T =>   fill namzdf_iwm)
+   ln_zdfswm   = .false.      ! surface  wave-induced mixing            (T => ln_wave=ln_sdw=T )
+   !
+   !                       !  Coefficients
+   rn_avm0     =   1.2e-4     !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   1.2e-5     !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
+   !
+/
+!-----------------------------------------------------------------------
+&namzdf_ric    !   richardson number dependent vertical diffusion       (ln_zdfric=T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  (ln_zdftke=T)
 !-----------------------------------------------------------------------
    nn_etau     =   0       !  penetration of tke below the mixed layer (ML) due to internal & intertial waves
 /
 !-----------------------------------------------------------------------
-&namzdf_gls                !   GLS vertical diffusion                   ("key_zdfgls")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_ddm    !   double diffusive mixing parameterization             ("key_zdfddm")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_tmx    !   tidal mixing parameterization                        ("key_zdftmx")
-!-----------------------------------------------------------------------
-   ln_tmx_itf  = .false.   !  ITF specific parameterisation
+&namzdf_gls                !   GLS vertical diffusion                   (ln_zdfgls=T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_osm                !   OSM vertical diffusion                   (ln_zdfosm =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_ddm    !   double diffusive mixing parameterization             (ln_zdfddm=T)
+!-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_PISCES/EXP00/namelist_top_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_PISCES/EXP00/namelist_top_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_PISCES/EXP00/namelist_top_cfg	(revision 9019)
@@ -29,11 +29,9 @@
 /
 !-----------------------------------------------------------------------
-&namtrc_adv    !   advection scheme for passive tracer
+&namtrc_adv    !   advection scheme for passive tracer                  (default: NO selection)
 !-----------------------------------------------------------------------
    ln_trcadv_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)
 /
 !-----------------------------------------------------------------------
@@ -41,8 +39,4 @@
 !-----------------------------------------------------------------------
    rn_ahtrc_0       =  1000.    !  horizontal eddy diffusivity for tracers [m2/s]
-/
-!-----------------------------------------------------------------------
-&namtrc_zdf        !   vertical physics
-!-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_PISCES/cpp_GYRE_PISCES.fcm
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_PISCES/cpp_GYRE_PISCES.fcm	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/GYRE_PISCES/cpp_GYRE_PISCES.fcm	(revision 9019)
@@ -1,1 +1,1 @@
-bld::tool::fppkeys key_zdftke key_top key_mpp_mpi key_iomput
+bld::tool::fppkeys   key_top key_mpp_mpi key_iomput
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/1_context_nemo.xml
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/1_context_nemo.xml	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/1_context_nemo.xml	(revision 9019)
@@ -0,0 +1,120 @@
+<!--
+ ============================================================================================== 
+    NEMO context
+============================================================================================== 
+-->
+<context id="1_nemo">
+<!-- $id$ -->
+<!-- Fields definition -->
+    <field_definition src="./field_def_nemo-opa.xml"/>   <!--  NEMO ocean dynamics                     -->
+
+<!-- Files definition -->
+    <file_definition src="./file_def_nemo-opa.xml"/>     <!--  NEMO ocean dynamics                     -->
+    <!-- 
+============================================================================================================
+= grid definition = = DO NOT CHANGE =
+============================================================================================================
+    -->
+    
+    <axis_definition>
+      <axis id="deptht" long_name="Vertical T levels" unit="m" positive="down" />
+      <axis id="depthu" long_name="Vertical U levels" unit="m" positive="down" />
+      <axis id="depthv" long_name="Vertical V levels" unit="m" positive="down" />
+      <axis id="depthw" long_name="Vertical W levels" unit="m" positive="down" />
+      <axis id="nfloat" long_name="Float number"      unit="-"                 />
+      <axis id="icbcla"  long_name="Iceberg class"      unit="1"               />
+      <axis id="ncatice" long_name="Ice category"       unit="1"               />
+      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"            />
+      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"            />
+    </axis_definition>
+ 
+    <domain_definition src="./domain_def_nemo.xml"/>
+  
+    <grid_definition>    
+
+        <!--  -->
+       <grid id="grid_T_2D" >
+         <domain id="grid_T" />
+       </grid>
+        <!--  -->
+       <grid id="grid_T_3D_ncatice" >
+         <domain id="grid_T" />
+         <axis id="ncatice" />
+       </grid>
+        <!--  -->
+       <grid id="grid_T_3D" >
+         <domain id="grid_T" />
+         <axis id="deptht" />
+       </grid>
+        <!--  -->
+       <grid id="grid_U_2D" >
+         <domain id="grid_U" />
+       </grid>
+        <!--  -->
+       <grid id="grid_U_3D" >
+         <domain id="grid_U" />
+         <axis id="depthu" />
+       </grid>
+        <!--  -->
+       <grid id="grid_V_2D" >
+         <domain id="grid_V" />
+       </grid>
+        <!--  -->
+       <grid id="grid_V_3D" >
+         <domain id="grid_V" />
+         <axis id="depthv" />
+       </grid>
+        <!--  -->
+       <grid id="grid_W_2D" >
+         <domain id="grid_W" />
+       </grid>
+        <!--  -->
+       <grid id="grid_W_3D" >
+         <domain id="grid_W" />
+         <axis id="depthw" />
+       </grid>
+        <!--  -->
+       <grid id="grid_1point" >
+         <domain domain_ref="1point"/>
+       </grid>
+        <!--  -->
+       <grid id="grid_T_nfloat" >
+         <domain id="grid_T" />
+         <axis id="nfloat" />
+       </grid>
+        <!--  -->
+       <grid id="grid_EqT" >
+         <domain domain_ref="EqT" />
+       </grid>
+        <!--  -->
+       <grid id="grid_znl_T_2D">
+         <domain id="gznl" />
+       </grid>
+        <!--  -->
+       <grid id="grid_znl_T_3D">
+         <domain id="gznl" />
+         <axis id="deptht" />
+       </grid>
+        <!--  -->
+       <grid id="grid_znl_W_3D">
+         <domain id="gznl" />
+         <axis id="depthw" />
+       </grid>
+
+      <grid id="grid_ptr_T_2D">
+       <domain id="ptr" />
+      </grid>
+
+      <grid id="grid_ptr_T_3D">
+       <domain id="ptr" />
+         <axis id="deptht" />
+       </grid>
+
+      <grid id="grid_ptr_W_3D">
+       <domain id="ptr" />
+         <axis id="depthw" />
+      </grid>
+
+    </grid_definition>   
+
+</context>
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/1_namelist_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/1_namelist_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/1_namelist_cfg	(revision 9019)
@@ -13,5 +13,5 @@
 /
 !-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
+&namcfg     !   parameters of the configuration
 !-----------------------------------------------------------------------
    ln_read_cfg = .true.    !  (=T) read the domain configuration file
@@ -21,6 +21,6 @@
 !-----------------------------------------------------------------------
 &namdom        !   space and time domain (bathymetry, mesh, timestep)
-!-----------------------------------------------------------------------  
-   ln_linssh   = .true.   !  =T  linear free surface  ==>>  model level are fixed in time
+!-----------------------------------------------------------------------
+   ln_linssh   = .true.    !  =T  linear free surface  ==>>  model level are fixed in time
    nn_closea   =    0      !  remove (=0) or keep (=1) closed seas and lakes (ORCA)
    !
@@ -29,6 +29,5 @@
 /
 !-----------------------------------------------------------------------
-&namcrs        !   Grid coarsening for dynamics output and/or
-!              !   passive tracer coarsened online simulations
+&namcrs        !   coarsened grid (for outputs and/or TOP)              (ln_crs =T)
 !-----------------------------------------------------------------------
 /
@@ -40,17 +39,17 @@
 &namsbc        !   Surface Boundary Condition (surface module)
 !-----------------------------------------------------------------------
-   ln_blk      = .true.    !  CORE bulk formulation                     (T => fill namsbc_core)
-   nn_ice      = 3         !  =0 no ice boundary condition   ,
+   nn_fsbc     = 1         !  frequency of surface boundary condition computation
+   ln_blk      = .true.    !  Bulk formulation                          (T => fill namsbc_blk )
+   nn_ice      = 0         !  =0 no ice boundary condition   ,
                            !  =1 use observed ice-cover      ,
-                           !  =2 ice-model used                         ("key_lim3" or "key_lim2)
-   ln_rnf      = .false.   !  runoffs                                   (T => fill namsbc_rnf)
-   ln_ssr      = .false.   !  Sea Surface Restoring on T and/or S       (T => fill namsbc_ssr)
-   nn_fwb      = 0         !  FreshWater Budget: =0 unchecked 
-                           !     =1 global mean of e-p-r set to zero at each time step 
+                           !  =2 or 3 automatically for LIM3 or CICE    ("key_lim3" or "key_cice")
+   ln_rnf      = .false.    !  runoffs                                   (T => fill namsbc_rnf)
+   ln_ssr      = .false.    !  Sea Surface Restoring on T and/or S       (T => fill namsbc_ssr)
+   nn_fwb      = 0         !  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
-                           !     =3 global emp set to zero and spread out over erp area
-/
-!-----------------------------------------------------------------------
-&namsbc_blk   !   namsbc_blk  generic Bulk formula                      (ln_blk = T)
+/
+!-----------------------------------------------------------------------
+&namsbc_blk   !   namsbc_blk  Bulk formulae
 !-----------------------------------------------------------------------
 !              !  file name                   ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights                              ! rotation ! land/sea mask !
@@ -69,5 +68,4 @@
    !                    !  bulk algorithm :
    ln_NCAR     = .true.   ! "NCAR"      algorithm   (Large and Yeager 2008)
-   !
 /
 !-----------------------------------------------------------------------
@@ -79,8 +77,30 @@
 /
 !-----------------------------------------------------------------------
+&namsbc_rnf    !   runoffs namelist surface boundary condition
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_ssr    !   surface boundary condition : sea surface restoring
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_alb    !   albedo parameters
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namberg       !   iceberg parameters
+!-----------------------------------------------------------------------
+      ln_icebergs              = .false.               ! iceberg floats or not
+/
+!-----------------------------------------------------------------------
 &namlbc        !   lateral momentum boundary condition
 !-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
+&namdrg        !   top/bottom friction
+!-----------------------------------------------------------------------
+   ln_lin = .true.         !     linear  drag: Cd = Cd0 Uc0
+/
+!-----------------------------------------------------------------------
 &namagrif      !  AGRIF zoom                                            ("key_agrif")
 !-----------------------------------------------------------------------
@@ -88,39 +108,40 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition
+&nambbc        !   bottom temperature boundary condition                (default: NO)
 !-----------------------------------------------------------------------
    ln_trabbc   = .true.    !  Apply a geothermal heating at the ocean bottom
 /
 !-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme
-!-----------------------------------------------------------------------
+&nambbl        !   bottom boundary layer scheme                         (default: NO)
+!-----------------------------------------------------------------------
+   ln_trabbl   = .true.    !  Bottom Boundary Layer parameterisation flag
+   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]
 /
 !-----------------------------------------------------------------------
 &nameos        !   ocean physical parameters
 !-----------------------------------------------------------------------
-  ln_teos10   = .true.         !  = Use TEOS-10 equation of state
-/
-!-----------------------------------------------------------------------
-&namtra_dmp    !   tracer: T & S newtonian damping
-!-----------------------------------------------------------------------
-   ln_tradmp   =  .false.   !  add a damping termn (T) or not (F)
-/
-!-----------------------------------------------------------------------
-&namtra_adv    !   advection scheme for tracer
-!-----------------------------------------------------------------------
-   ln_traadv_fct =  .true.    !  FCT scheme
+   ln_teos10   = .false.         !  = Use TEOS-10 equation of state
+   ln_eos80    = .true.          !  = Use EOS80
+   ln_seos     = .false.         !  = Use S-EOS (simplified Eq.)
+/
+!-----------------------------------------------------------------------
+&namtra_adv    !   advection scheme for tracer                          (default: NO advection)
+!-----------------------------------------------------------------------
+   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)
-/
-!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtra_adv_mle !   mixed layer eddy parametrisation (Fox-Kemper param)
+!-----------------------------------------------------------------------
+/
+!----------------------------------------------------------------------------------
 &namtra_ldf    !   lateral diffusion scheme for tracers
 !----------------------------------------------------------------------------------
    !                       !  Operator type:
+   ln_traldf_NONE  =  .false.  !           No operator (no explicit advection)
    ln_traldf_lap   =  .true.   !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -156,7 +177,17 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection
-!-----------------------------------------------------------------------
-/  
+&namtra_dmp    !   tracer: T & S newtonian damping                      (default: NO)
+!-----------------------------------------------------------------------
+   ln_tradmp   =  .false.   !  add a damping termn (T) or not (F)
+/
+!-----------------------------------------------------------------------
+&namdyn_adv    !   formulation of the momentum advection                (default: No selection)
+!-----------------------------------------------------------------------
+   ln_dynadv_NONE= .false. !  linear dynamics (no momentum advection)
+   ln_dynadv_vec = .true.  !  vector form - 2nd centered scheme
+     nn_dynkeg     = 0        ! grad(KE) scheme: =0   C2  ;  =1   Hollingsworth correction
+   ln_dynadv_cen2= .false. !  flux form - 2nd order centered scheme
+   ln_dynadv_ubs = .false. !  flux form - 3rd order UBS      scheme
+/
 !-----------------------------------------------------------------------
 &namdyn_vor    !   option of physics/algorithm (not control by CPP keys)
@@ -171,4 +202,5 @@
 &namdyn_hpg    !   Hydrostatic pressure gradient option
 !-----------------------------------------------------------------------
+   ln_hpg_sco  = .true.   !  s-coordinate (standard jacobian formulation)
 /
 !-----------------------------------------------------------------------
@@ -201,20 +233,42 @@
    rn_bhm_0      = 8.5e+11     !  horizontal bilaplacian eddy viscosity [m4/s]
 /
-!-----------------------------------------------------------------------
-&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")
-!-----------------------------------------------------------------------
-   ln_tmx_itf  = .false.   !  ITF specific parameterisation
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .false.      !  constant mixing
+   ln_zdfric   = .false.      !  local Richardson dependent formulation (T =>   fill namzdf_ric)
+   ln_zdftke   = .true.       !  Turbulent Kinetic Energy closure       (T =>   fill namzdf_tke)
+   ln_zdfgls   = .false.      !  Generic Length Scale closure           (T =>   fill namzdf_gls)
+   !
+   !                       ! convection
+   ln_zdfevd   = .true.       !  Enhanced Vertical Diffusion scheme
+      nn_evdm  =    0            !  evd apply on tracer (=0) or on tracer and momentum (=1)
+      rn_evd   =  100.           !  evd mixing coefficient [m2/s]
+   !
+   ln_zdfddm   = .true.    ! double diffusive mixing
+      rn_avts  =    1.e-4     !  maximum avs (vertical mixing on salinity)
+      rn_hsbfr =    1.6       !  heat/salt buoyancy flux ratio
+   !
+   !                       ! gravity wave-driven vertical mixing
+   ln_zdfiwm   = .false.      ! internal wave-induced mixing            (T =>   fill namzdf_iwm)
+   ln_zdfswm   = .false.      ! surface  wave-induced mixing            (T => ln_wave=ln_sdw=T )
+   !
+   !                       !  Coefficients
+   rn_avm0     =   1.2e-4     !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   1.2e-5     !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    1         !  horizontal shape for avtb (=1) or not (=0)
+/
+!-----------------------------------------------------------------------
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion 
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_iwm    !   tidal mixing parameterization                        (ln_zdfiwm =T)
+!-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
@@ -223,8 +277,4 @@
 /
 !-----------------------------------------------------------------------
-&nammpp_dyndist !   Massively Parallel Distribution for AGRIF zoom      ("key_agrif" && "key_mpp_dyndist")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
 &namctl        !   Control prints & Benchmark
 !-----------------------------------------------------------------------
@@ -235,5 +285,5 @@
 /
 !-----------------------------------------------------------------------
-&namhsb       !  Heat and salt budgets 
+&namhsb       !  Heat and salt budgets                                  (default F)
 !-----------------------------------------------------------------------
 /
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/context_nemo.xml
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/context_nemo.xml	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/context_nemo.xml	(revision 9019)
@@ -7,10 +7,12 @@
 <!-- $id$ -->
 <!-- Fields definition -->
-    <field_definition src="./field_def_nemo-opa.xml"/>   <!--  NEMO ocean dynamics                     -->
-    <field_definition src="./field_def_nemo-lim.xml"/>   <!--  LIM ice model                     -->
-    <field_definition src="./field_def_nemo-pisces.xml"/>   <!--  Ocean biology                     -->
+    <field_definition src="./field_def_nemo-opa.xml"/>    <!--  NEMO ocean dynamics               -->
+    <field_definition src="./field_def_nemo-lim.xml"/>    <!--  LIM ice model                     -->
+    <field_definition src="./field_def_nemo-pisces.xml"/> <!--  Ocean biology                     -->
 
 <!-- Files definition -->
-    <file_definition src="./file_def_nemo.xml"/>     <!--  NEMO ocean dynamics                     -->
+    <file_definition src="./file_def_nemo-opa.xml"/>     <!--  NEMO ocean dynamics                -->
+    <file_definition src="./file_def_nemo-lim.xml"/>     <!--  NEMO ocean dynamics                -->
+    <file_definition src="./file_def_nemo-pisces.xml"/>  <!--  NEMO ocean dynamics                -->
     <!-- 
 ============================================================================================================
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/file_def_nemo-lim.xml
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/file_def_nemo-lim.xml	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/file_def_nemo-lim.xml	(revision 9019)
@@ -0,0 +1,67 @@
+<?xml version="1.0"?>
+    <!-- $id$ -->
+    
+ <!--
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files for lim3                                =
+=                                         put the variables you want...                                    =
+============================================================================================================
+ -->
+    
+ <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1mo" min_digits="4">
+   
+   <file_group id="5d" output_freq="5d"  output_level="10" enabled=".TRUE.">  <!-- 5d files -->   	
+     <file id="file21" name_suffix="_icemod" description="ice variables" enabled=".true." >
+       <field field_ref="snwthic"         name="snthic" />
+       <field field_ref="icethic"         name="sithic" />
+       <field field_ref="icevolu"         name="sivolu" />
+       <field field_ref="snwvolu"         name="snvolu" />
+       <field field_ref="iceconc"         name="siconc" />
+     </file>
+     
+     <file id="file22" name_suffix="_SBC_scalar" description="scalar variables" enabled=".true." >
+       <!-- global contents -->
+       <field field_ref="ibgvol_tot"    name="ibgvol_tot"   />
+       <field field_ref="sbgvol_tot"    name="sbgvol_tot"   />
+       <field field_ref="ibgarea_tot"   name="ibgarea_tot"  />
+       <field field_ref="ibgsalt_tot"   name="ibgsalt_tot"  />
+       <field field_ref="ibgheat_tot"   name="ibgheat_tot"  />
+       <field field_ref="sbgheat_tot"   name="sbgheat_tot"  />
+       
+       <!-- global drifts (conservation checks) -->
+       <field field_ref="ibgvolume"     name="ibgvolume"    />
+       <field field_ref="ibgsaltco"     name="ibgsaltco"    />
+       <field field_ref="ibgheatco"     name="ibgheatco"    />
+       <field field_ref="ibgheatfx"     name="ibgheatfx"    />
+       
+       <!-- global forcings  -->
+       <field field_ref="ibgfrcvoltop"  name="ibgfrcvoltop" />
+       <field field_ref="ibgfrcvolbot"  name="ibgfrcvolbot" />
+       <field field_ref="ibgfrctemtop"  name="ibgfrctemtop" />
+       <field field_ref="ibgfrctembot"  name="ibgfrctembot" />
+       <field field_ref="ibgfrcsal"     name="ibgfrcsal"    />
+       <field field_ref="ibgfrchfxtop"  name="ibgfrchfxtop" />
+       <field field_ref="ibgfrchfxbot"  name="ibgfrchfxbot" />
+     </file>
+     
+   </file_group>
+   
+   <file_group id="1ts" output_freq="1ts" output_level="10" enabled=".TRUE."/> <!-- 1 time step files -->
+   <file_group id="1h"  output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+   <file_group id="2h"  output_freq="2h"  output_level="10" enabled=".TRUE."/> <!-- 2h files -->
+   <file_group id="3h"  output_freq="3h"  output_level="10" enabled=".TRUE."/> <!-- 3h files -->     
+   <file_group id="4h"  output_freq="4h"  output_level="10" enabled=".TRUE."/> <!-- 4h files -->
+   <file_group id="6h"  output_freq="6h"  output_level="10" enabled=".TRUE."/> <!-- 6h files -->        
+   <file_group id="1m"  output_freq="1mo" output_level="10" enabled=".TRUE."/> <!-- real monthly files -->
+   <file_group id="2m"  output_freq="2mo" output_level="10" enabled=".TRUE."/> <!-- real 2m files -->
+   <file_group id="3m"  output_freq="3mo" output_level="10" enabled=".TRUE."/> <!-- real 3m files -->
+   <file_group id="4m"  output_freq="4mo" output_level="10" enabled=".TRUE."/> <!-- real 4m files -->
+   <file_group id="6m"  output_freq="6mo" output_level="10" enabled=".TRUE."/> <!-- real 6m files -->
+   <file_group id="1y"  output_freq="1y"  output_level="10" enabled=".TRUE."/> <!-- real yearly files -->
+   <file_group id="2y"  output_freq="2y"  output_level="10" enabled=".TRUE."/> <!-- real 2y files -->
+   <file_group id="5y"  output_freq="5y"  output_level="10" enabled=".TRUE."/> <!-- real 5y files -->
+   <file_group id="10y" output_freq="10y" output_level="10" enabled=".TRUE."/> <!-- real 10y files -->
+   
+ </file_definition>
+ 
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/file_def_nemo-opa.xml
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/file_def_nemo-opa.xml	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/file_def_nemo-opa.xml	(revision 9019)
@@ -0,0 +1,128 @@
+<?xml version="1.0"?>
+
+<!--
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own filesfor ocean dynamics context               =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+   
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1mo" min_digits="4">
+    
+      <file_group id="5d" output_freq="5d"  output_level="10" enabled=".TRUE.">  <!-- 5d files -->   
+        <file id="file11" name_suffix="_grid_T" description="ocean T grid variables" >
+          <field field_ref="e3t"      />
+          <field field_ref="toce"         name="thetao"                                                                      operation="instant" freq_op="5d" > @toce_e3t / @e3t </field>
+          <field field_ref="soce"         name="so"                                                                          operation="instant" freq_op="5d" > @soce_e3t / @e3t </field>
+          <field field_ref="sst"          name="tos"   />
+          <field field_ref="sss"          name="sos"   />
+          <field field_ref="ssh"          name="zos"   />
+          <field field_ref="sst"          name="tosstd"       long_name="sea surface temperature standard deviation"         operation="instant" freq_op="5d" > sqrt( @sst2 - @sst * @sst ) </field>
+          <field field_ref="ssh"          name="zosstd"       long_name="sea surface height above geoid standard deviation"  operation="instant" freq_op="5d" > sqrt( @ssh2 - @ssh * @ssh ) </field>
+          <field field_ref="sst"          name="sstdcy"       long_name="amplitude of sst diurnal cycle"                     operation="average" freq_op="1d" > @sstmax - @sstmin </field>
+          <field field_ref="mldkz5"   />
+          <field field_ref="mldr10_1" />
+          <field field_ref="mldr10_1"     name="mldr10_1dcy"  long_name="amplitude of mldr10_1 diurnal cycle"                operation="average" freq_op="1d" > @mldr10_1max - @mldr10_1min </field>
+          <field field_ref="sbt"      />
+          <field field_ref="heatc"        name="heatc" />
+          <field field_ref="saltc"        name="saltc" />
+
+	  <field field_ref="empmr"        name="wfo"      />
+	  <field field_ref="qsr_oce"      name="qsr_oce"  />
+	  <field field_ref="qns_oce"      name="qns_oce"  />
+	  <field field_ref="qt_oce"       name="qt_oce"   />
+	  <field field_ref="saltflx"      name="sfx"      />
+	  <field field_ref="taum"         name="taum"     />
+	  <field field_ref="wspd"         name="windsp"   />
+	  <field field_ref="precip"       name="precip"   />
+	  <!-- ice and snow -->
+	  <field field_ref="snowpre" />
+	</file>
+
+	<file id="file12" name_suffix="_grid_U" description="ocean U grid variables" >
+	  <field field_ref="e3u" />
+	  <field field_ref="ssu"          name="uos"      />
+	  <field field_ref="uoce"         name="uo"       operation="instant" freq_op="5d" > @uoce_e3u / @e3u </field>
+	  <field field_ref="utau"         name="tauuo"    />
+          <field field_ref="uocetr_eff"   name="uocetr_eff"  />
+          <!-- available with diaar5 -->
+	  <field field_ref="u_masstr"     name="vozomatr" />
+	  <field field_ref="u_heattr"     name="sozohetr" />
+	  <field field_ref="u_salttr"     name="sozosatr" />
+	</file>
+	
+	<file id="file13" name_suffix="_grid_V" description="ocean V grid variables" >
+	  <field field_ref="e3v" />
+	  <field field_ref="ssv"          name="vos"      />
+	  <field field_ref="voce"         name="vo"       operation="instant" freq_op="5d" > @voce_e3v / @e3v </field>
+	  <field field_ref="vtau"         name="tauvo"    />
+          <field field_ref="vocetr_eff"   name="vocetr_eff"  />
+          <!-- available with diaar5 -->
+	  <field field_ref="v_masstr"     name="vomematr" />
+	  <field field_ref="v_heattr"     name="somehetr" />
+          <field field_ref="v_salttr"     name="somesatr" />
+	</file>
+	
+	<file id="file14" name_suffix="_grid_W" description="ocean W grid variables" >
+	  <field field_ref="e3w" />
+	  <field field_ref="woce"         name="wo"       />
+	  <field field_ref="avt"          name="difvho"   />
+	  <field field_ref="w_masstr"     name="vovematr" />
+         <!-- variables available with ln_zdfiwm =T -->
+          <field field_ref="av_wave"      name="av_wave"    />
+          <field field_ref="bn2"          name="bn2"        />
+          <field field_ref="bflx_iwm"     name="bflx_iwm"   />
+          <field field_ref="pcmap_iwm"    name="pcmap_iwm"  />
+          <field field_ref="emix_iwm"     name="emix_iwm"   />
+          <field field_ref="av_ratio"     name="av_ratio"   />
+	</file>
+
+        <file id="file15" name_suffix="_scalar" description="scalar variables" enabled=".true." >
+          <field field_ref="voltot"       name="scvoltot"   />
+          <field field_ref="sshtot"       name="scsshtot"   />
+          <field field_ref="sshsteric"    name="scsshste"   />
+          <field field_ref="sshthster"    name="scsshtst"   />
+          <field field_ref="masstot"      name="scmastot"   />
+          <field field_ref="temptot"      name="sctemtot"   />
+          <field field_ref="saltot"       name="scsaltot"   />
+
+          <field field_ref="bgtemper"     name="bgtemper"   />
+          <field field_ref="bgsaline"     name="bgsaline"   />
+          <field field_ref="bgheatco"     name="bgheatco"   />
+          <field field_ref="bgsaltco"     name="bgsaltco"   />
+          <field field_ref="bgvolssh"     name="bgvolssh"   />
+          <field field_ref="bgvole3t"     name="bgvole3t"   />
+          <field field_ref="bgfrcvol"     name="bgfrcvol"   />
+          <field field_ref="bgfrctem"     name="bgfrctem"   />
+          <field field_ref="bgfrcsal"     name="bgfrcsal"   />
+        </file>
+
+      </file_group> 
+
+
+      <file_group id="1m" output_freq="1mo" output_level="10" enabled=".TRUE."> <!-- real monthly files -->
+      </file_group>
+
+      <file_group id="1y"  output_freq="1y" output_level="10" enabled=".TRUE."> <!-- real yearly files -->
+      </file_group>
+	
+      
+      <file_group id="1ts" output_freq="1ts" output_level="10" enabled=".TRUE."/> <!-- 1 time step files -->
+      <file_group id="2h"  output_freq="2h"  output_level="10" enabled=".TRUE."/> <!-- 2h files -->
+      <file_group id="3h"  output_freq="3h"  output_level="10" enabled=".TRUE."/> <!-- 3h files -->     
+      <file_group id="4h"  output_freq="4h"  output_level="10" enabled=".TRUE."/> <!-- 4h files -->
+      <file_group id="6h"  output_freq="6h"  output_level="10" enabled=".TRUE."/> <!-- 6h files -->     
+      <file_group id="2m"  output_freq="2mo" output_level="10" enabled=".TRUE."/> <!-- real 2m files -->
+      <file_group id="3m"  output_freq="3mo" output_level="10" enabled=".TRUE."/> <!-- real 3m files -->
+      <file_group id="4m"  output_freq="4mo" output_level="10" enabled=".TRUE."/> <!-- real 4m files -->
+      <file_group id="6m"  output_freq="6mo" output_level="10" enabled=".TRUE."/> <!-- real 6m files -->
+      <file_group id="2y"  output_freq="2y"  output_level="10" enabled=".TRUE."/> <!-- real 2y files -->
+      <file_group id="5y"  output_freq="5y"  output_level="10" enabled=".TRUE."/> <!-- real 5y files -->
+      <file_group id="10y" output_freq="10y" output_level="10" enabled=".TRUE."/> <!-- real 10y files -->
+
+   </file_definition>
+    
+
+
+
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/file_def_nemo-pisces.xml
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/file_def_nemo-pisces.xml	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/file_def_nemo-pisces.xml	(revision 9019)
@@ -0,0 +1,128 @@
+<?xml version="1.0"?>
+
+<!--
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own filesfor ocean dynamics context               =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+   
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1mo" min_digits="4">
+    
+      <file_group id="5d" output_freq="5d"  output_level="10" enabled=".TRUE.">  <!-- 5d files -->   
+
+        <file id="file31" name_suffix="_bioscalar" description="pisces sms variables" >
+          <field field_ref="tdenit"   name="tdenit"   unit="TgN/yr" operation="instant" > tdenit * 14. * 86400. * 365. / 1e12 </field>
+          <field field_ref="tnfix"    name="tnfix"    unit="TgN/yr" operation="instant" > tnfix * 14. * 86400. * 365. / 1e12 </field>
+          <field field_ref="tcflx"    name="tcflx"    unit="PgC/yr" operation="instant" > tcflx * -1. * 12. * 86400. * 365. / 1e15 </field>
+          <field field_ref="tcflxcum" name="tcflxcum" unit="PgC"    operation="instant" > tcflxcum * -1. * 12. / 1e15 </field>
+          <field field_ref="tcexp"    name="tcexp"    unit="PgC/yr" operation="instant" > tcexp * 12. * 86400. * 365. / 1e15 </field>
+          <field field_ref="tintpp"   name="tintpp"   unit="PgC/yr" operation="instant" > tintpp * 12. * 86400. * 365. / 1e15 </field>
+          <field field_ref="pno3tot"  name="pno3tot"  unit="umolN"  > pno3tot * 16. / 122. * 1e6 </field>
+          <field field_ref="ppo4tot"  name="ppo4tot"  unit="umolP"  > ppo4tot * 1. / 122. * 1e6 </field>
+          <field field_ref="psiltot"  name="psiltot"  unit="umolC"  > psiltot * 1e6  </field>
+          <field field_ref="palktot"  name="palktot"  unit="umolC"  > palktot * 1e6  </field>
+          <field field_ref="pfertot"  name="pfertot"  unit="nmolFe" > pfertot * 1e9  </field>
+        </file>
+
+      </file_group> 
+
+
+      <file_group id="1m" output_freq="1mo" output_level="10" enabled=".TRUE."> <!-- real monthly files -->
+
+        <file id="file32" name_suffix="_ptrc_T" description="pisces sms variables" >
+          <field field_ref="DIC"      />
+          <field field_ref="Alkalini" />
+          <field field_ref="O2"       />
+          <field field_ref="PO4"      />
+          <field field_ref="Si"       />
+          <field field_ref="Fer"      />
+          <field field_ref="NCHL"     />
+          <field field_ref="DCHL"     />
+          <field field_ref="NO3"      />
+        </file>
+
+        <file id="file33" name_suffix="_diad_T" description="additional pisces diagnostics" >
+          <field field_ref="Cflx"     />
+          <field field_ref="Dpco2"    />
+        </file>
+
+      </file_group>
+
+      <file_group id="1y"  output_freq="1y" output_level="10" enabled=".TRUE."> <!-- real yearly files -->
+
+        <file id="file34" name_suffix="_ptrc_T" description="pisces sms variables" >
+          <field field_ref="DIC"      />
+          <field field_ref="Alkalini" />
+          <field field_ref="O2"       />
+          <field field_ref="CaCO3"    />
+          <field field_ref="PO4"      />
+          <field field_ref="POC"      />
+          <field field_ref="Si"       />
+          <field field_ref="PHY"      />
+          <field field_ref="ZOO"      />
+          <field field_ref="DOC"      />
+          <field field_ref="PHY2"     />
+          <field field_ref="ZOO2"     />
+          <field field_ref="DSi"      />
+          <field field_ref="Fer"      />
+          <field field_ref="BFe"      />
+          <field field_ref="GOC"      />
+          <field field_ref="SFe"      />
+          <field field_ref="DFe"      />
+          <field field_ref="GSi"      />
+          <field field_ref="NFe"      />
+          <field field_ref="NCHL"     />
+          <field field_ref="DCHL"     />
+          <field field_ref="NO3"      />
+          <field field_ref="NH4"      />
+        </file>
+
+        <file id="file35" name_suffix="_diad_T" description="additional pisces diagnostics" >
+          <field field_ref="PH"       />
+          <field field_ref="PAR"      />
+          <field field_ref="PPPHYN"    />
+          <field field_ref="PPPHYD"   />
+          <field field_ref="PPPHYP"   />
+          <field field_ref="PPNEWN"   />
+          <field field_ref="PPNEWD"   />
+          <field field_ref="PPNEWP"   />
+          <field field_ref="PBSi"     />
+          <field field_ref="PFeN"     />
+          <field field_ref="PFeD"     />
+          <field field_ref="PCAL"     />
+          <field field_ref="DCAL"     />
+          <field field_ref="GRAZ1"    />
+          <field field_ref="GRAZ2"    />
+          <field field_ref="EPC100"   />
+          <field field_ref="EPFE100"  />
+          <field field_ref="EPSI100"  />
+          <field field_ref="EPCAL100" />
+          <field field_ref="Cflx"     />
+          <field field_ref="Dpco2"    />
+          <field field_ref="Heup"     />
+          <field field_ref="Nfix"     />
+        </file>
+     </file_group>
+	
+	
+      
+      <file_group id="1ts" output_freq="1ts" output_level="10" enabled=".TRUE."/> <!-- 1 time step files -->
+      <file_group id="2h"  output_freq="2h"  output_level="10" enabled=".TRUE."/> <!-- 2h files -->
+      <file_group id="3h"  output_freq="3h"  output_level="10" enabled=".TRUE."/> <!-- 3h files -->     
+      <file_group id="4h"  output_freq="4h"  output_level="10" enabled=".TRUE."/> <!-- 4h files -->
+      <file_group id="6h"  output_freq="6h"  output_level="10" enabled=".TRUE."/> <!-- 6h files -->     
+      <file_group id="2m"  output_freq="2mo" output_level="10" enabled=".TRUE."/> <!-- real 2m files -->
+      <file_group id="3m"  output_freq="3mo" output_level="10" enabled=".TRUE."/> <!-- real 3m files -->
+      <file_group id="4m"  output_freq="4mo" output_level="10" enabled=".TRUE."/> <!-- real 4m files -->
+      <file_group id="6m"  output_freq="6mo" output_level="10" enabled=".TRUE."/> <!-- real 6m files -->
+      <file_group id="2y"  output_freq="2y"  output_level="10" enabled=".TRUE."/> <!-- real 2y files -->
+      <file_group id="5y"  output_freq="5y"  output_level="10" enabled=".TRUE."/> <!-- real 5y files -->
+      <file_group id="10y" output_freq="10y" output_level="10" enabled=".TRUE."/> <!-- real 10y files -->
+
+   </file_definition>
+    
+
+
+
Index: anches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/file_def_nemo.xml
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/file_def_nemo.xml	(revision 9018)
+++ 	(revision )
@@ -1,351 +1,0 @@
-<?xml version="1.0"?>
-
-    <!-- 
-============================================================================================================
-=                                           output files definition                                        =
-=                                            Define your own files                                         =
-=                                         put the variables you want...                                    =
-============================================================================================================
-    -->
-    
-    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="10d" min_digits="4">
-    
-      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."/> <!-- 1 time step files -->
-
-      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
-
-      <file_group id="2h" output_freq="2h"  output_level="10" enabled=".TRUE."/> <!-- 2h files -->
-
-      <file_group id="3h" output_freq="3h"  output_level="10" enabled=".TRUE."/> <!-- 3h files -->     
-
-      <file_group id="4h" output_freq="4h"  output_level="10" enabled=".TRUE."/> <!-- 4h files -->
-
-      <file_group id="6h" output_freq="6h"  output_level="10" enabled=".TRUE."/> <!-- 6h files -->     
-
-      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 1d files -->
-      
-      <file_group id="3d" output_freq="3d"  output_level="10" enabled=".TRUE."/> <!-- 3d files -->
-      
-      <file_group id="5d" output_freq="5d"  output_level="10" enabled=".TRUE.">  <!-- 5d files -->   
-	
-	<file id="file1" name_suffix="_grid_T" description="ocean T grid variables" >
-	  <field field_ref="e3t"      />
-	  <field field_ref="toce"         name="thetao"                                                                      operation="instant" freq_op="5d" > @toce_e3t / @e3t </field>
-	  <field field_ref="soce"         name="so"                                                                          operation="instant" freq_op="5d" > @soce_e3t / @e3t </field>
-	  <field field_ref="sst"          name="tos"   />
-	  <field field_ref="sss"          name="sos"   />
-	  <field field_ref="ssh"          name="zos"   />
-	  <field field_ref="sst"          name="tosstd"       long_name="sea surface temperature standard deviation"         operation="instant" freq_op="5d" > sqrt( @sst2 - @sst * @sst ) </field>
-	  <field field_ref="ssh"          name="zosstd"       long_name="sea surface height above geoid standard deviation"  operation="instant" freq_op="5d" > sqrt( @ssh2 - @ssh * @ssh ) </field>
-	  <field field_ref="sst"          name="sstdcy"       long_name="amplitude of sst diurnal cycle"                     operation="average" freq_op="1d" > @sstmax - @sstmin </field>
-	  <field field_ref="mldkz5"   />
-	  <field field_ref="mldr10_1" />
-	  <field field_ref="mldr10_1"     name="mldr10_1dcy"  long_name="amplitude of mldr10_1 diurnal cycle"                operation="average" freq_op="1d" > @mldr10_1max - @mldr10_1min </field>
-	  <field field_ref="sbt"      />
-	  <field field_ref="heatc"        name="heatc" />
-	  <field field_ref="saltc"        name="saltc" />
-	</file>
-
-	<file id="file2" name_suffix="_SBC" description="surface fluxes variables" > <!-- time step automaticaly defined based on nn_fsbc -->
-	  <field field_ref="empmr"        name="wfo"      />
-	  <field field_ref="qsr_oce"      name="qsr_oce"  />
-	  <field field_ref="qns_oce"      name="qns_oce"  />
-	  <field field_ref="qt_oce"       name="qt_oce"   />
-	  <field field_ref="qsr_ice"      name="qsr_ice"  />
-	  <field field_ref="qns_ice"      name="qns_ice"  />
-	  <field field_ref="qtr_ice"      name="qtr_ice"  />
-	  <field field_ref="qt_ice"       name="qt_ice"   />
-	  <field field_ref="saltflx"      name="sfx"      />
-	  <field field_ref="taum"         name="taum"     />
-	  <field field_ref="wspd"         name="windsp"   />
-	  <field field_ref="precip"       name="precip"   />
-	  <!-- ice and snow -->
-	  <field field_ref="snowpre" />
-	  <field field_ref="utau_ice"     name="utau_ice" />
-	  <field field_ref="vtau_ice"     name="vtau_ice" />
-	</file>
-
-	<file id="file3" name_suffix="_grid_U" description="ocean U grid variables" >
-	  <field field_ref="e3u" />
-	  <field field_ref="ssu"          name="uos"      />
-	  <field field_ref="uoce"         name="uo"       operation="instant" freq_op="5d" > @uoce_e3u / @e3u </field>
-	  <field field_ref="utau"         name="tauuo"    />
-          <field field_ref="uocetr_eff"   name="uocetr_eff"  />
-          <!-- available with diaar5 -->
-	  <field field_ref="u_masstr"     name="vozomatr" />
-	  <field field_ref="u_heattr"     name="sozohetr" />
-      <field field_ref="u_salttr"     name="sozosatr" />
-	</file>
-	
-	<file id="file4" name_suffix="_grid_V" description="ocean V grid variables" >
-	  <field field_ref="e3v" />
-	  <field field_ref="ssv"          name="vos"      />
-	  <field field_ref="voce"         name="vo"       operation="instant" freq_op="5d" > @voce_e3v / @e3v </field>
-	  <field field_ref="vtau"         name="tauvo"    />
-          <field field_ref="vocetr_eff"   name="vocetr_eff"  />
-          <!-- available with diaar5 -->
-	  <field field_ref="v_masstr"     name="vomematr" />
-	  <field field_ref="v_heattr"     name="somehetr" />
-          <field field_ref="v_salttr"     name="somesatr" />
-	</file>
-	
-	<file id="file5" name_suffix="_grid_W" description="ocean W grid variables" >
-	  <field field_ref="e3w" />
-	  <field field_ref="woce"         name="wo"       />
-	  <field field_ref="avt"          name="difvho"   />
-	  <field field_ref="w_masstr"     name="vovematr" />
-     <!-- variables available with key_zdftmx_new -->
-     <field field_ref="av_wave"      name="av_wave"    />
-     <field field_ref="bn2"          name="bn2"        />
-     <field field_ref="bflx_tmx"     name="bflx_tmx"   />
-     <field field_ref="pcmap_tmx"    name="pcmap_tmx"  />
-     <field field_ref="emix_tmx"     name="emix_tmx"   />
-     <field field_ref="av_ratio"     name="av_ratio"   />
-	</file>
-
-	<file id="file6" name_suffix="_icemod" description="ice variables" enabled=".true." >
-          <field field_ref="snowthic_cea"    name="snthic" />
-          <field field_ref="icethic_cea"     name="sithic" />
-          <field field_ref="icevolu"         name="sivolu" />
-          <field field_ref="snowvol"         name="snvolu" />
-          <field field_ref="iceconc"         name="siconc" />
-
-          <field field_ref="vfxbog"          name="vfxbog" />
-          <field field_ref="vfxdyn"          name="vfxdyn" />
-          <field field_ref="vfxopw"          name="vfxopw" />
-          <field field_ref="vfxsni"          name="vfxsni" />
-          <field field_ref="vfxsum"          name="vfxsum" />
-          <field field_ref="vfxbom"          name="vfxbom" />
-          <field field_ref="vfxres"          name="vfxres" />
-          <field field_ref="vfxice"          name="vfxice" />
-          <field field_ref="vfxsnw"          name="vfxsnw" />
-          <field field_ref="vfxsub"          name="vfxsub" />
-          <field field_ref="vfxspr"          name="vfxspr" />
-
-          <field field_ref="icetrp"          name="sivtrp" />
-          <field field_ref="snwtrp"          name="snvtrp" />
-          <field field_ref="saltrp"          name="saltrp" />
-          <field field_ref="deitrp"          name="deitrp" />
-          <field field_ref="destrp"          name="destrp" />
-
-          <field field_ref="sfxbri"          name="sfxbri" />
-          <field field_ref="sfxdyn"          name="sfxdyn" />
-          <field field_ref="sfxres"          name="sfxres" />
-          <field field_ref="sfxbog"          name="sfxbog" />
-          <field field_ref="sfxbom"          name="sfxbom" />
-          <field field_ref="sfxsum"          name="sfxsum" />
-          <field field_ref="sfxsni"          name="sfxsni" />
-          <field field_ref="sfxopw"          name="sfxopw" />
-          <field field_ref="sfx"             name="sfx"    />
-
-          <field field_ref="hfxsum"          name="hfxsum"     />
-          <field field_ref="hfxbom"          name="hfxbom"     />
-          <field field_ref="hfxbog"          name="hfxbog"     />
-          <field field_ref="hfxdif"          name="hfxdif"     />
-          <field field_ref="hfxopw"          name="hfxopw"     />
-          <field field_ref="hfxout"          name="hfxout"     />
-          <field field_ref="hfxin"           name="hfxin"      />
-          <field field_ref="hfxsnw"          name="hfxsnw"     />
-          <field field_ref="hfxerr"          name="hfxerr"     />
-          <field field_ref="hfxerr_rem"      name="hfxerr_rem" />
-
-	  <!-- ice-ocean heat flux from mass exchange -->
-          <field field_ref="hfxdyn"          name="hfxdyn" />
-          <field field_ref="hfxres"          name="hfxres" />
-          <field field_ref="hfxthd"          name="hfxthd" />
-	  <!-- ice-atm. heat flux from mass exchange -->
-          <field field_ref="hfxsub"          name="hfxsub" />
-          <field field_ref="hfxspr"          name="hfxspr" />
-
-	  <!-- diags -->
-          <field field_ref="hfxdhc"          name="hfxdhc" />
-          <field field_ref="hfxtur"          name="hfxtur" />
-
-          <field field_ref="isst"            name="sst"    />
-          <field field_ref="isss"            name="sss"    />
-          <field field_ref="micesalt"        name="sisali" />
-          <field field_ref="micet"           name="sitemp" />
-          <field field_ref="icest"           name="sistem" />
-          <field field_ref="icehc"           name="siheco" />
-          <field field_ref="isnowhc"         name="snheco" />
-          <field field_ref="miceage"         name="siages" />
-
-          <field field_ref="uice_ipa"        name="sivelu" />
-          <field field_ref="vice_ipa"        name="sivelv" />
-          <field field_ref="icevel"          name="sivelo" />
-          <field field_ref="idive"           name="sidive" />
-          <field field_ref="ishear"          name="sishea" />
-          <field field_ref="icestr"          name="sistre" />
-
-          <field field_ref="ibrinv"          name="sibrin" />
-          <field field_ref="icecolf"         name="sicolf" />
-
-          <field field_ref="iceage_cat"      name="siagecat" />
-          <field field_ref="iceconc_cat"     name="siconcat" />
-          <field field_ref="icethic_cat"     name="sithicat" />
-          <field field_ref="snowthic_cat"    name="snthicat" />
-          <field field_ref="salinity_cat"    name="salincat" />
-          <field field_ref="brinevol_cat"    name="sibricat" />
-	  <field field_ref="icetemp_cat"     name="sitemcat" />
-	  <field field_ref="snwtemp_cat"     name="sntemcat" />
-
-	</file>
-
-        <file id="file7" name_suffix="_scalar" description="scalar variables" enabled=".true." >
-          <field field_ref="voltot"       name="scvoltot"   />
-          <field field_ref="sshtot"       name="scsshtot"   />
-          <field field_ref="sshsteric"    name="scsshste"   />
-          <field field_ref="sshthster"    name="scsshtst"   />
-          <field field_ref="masstot"      name="scmastot"   />
-          <field field_ref="temptot"      name="sctemtot"   />
-          <field field_ref="saltot"       name="scsaltot"   />
-
-          <field field_ref="bgtemper"     name="bgtemper"   />
-          <field field_ref="bgsaline"     name="bgsaline"   />
-          <field field_ref="bgheatco"     name="bgheatco"   />
-          <field field_ref="bgsaltco"     name="bgsaltco"   />
-          <field field_ref="bgvolssh"     name="bgvolssh"   /> 
-          <field field_ref="bgvole3t"     name="bgvole3t"   />
-          <field field_ref="bgfrcvol"     name="bgfrcvol"   />
-          <field field_ref="bgfrctem"     name="bgfrctem"   />
-          <field field_ref="bgfrcsal"     name="bgfrcsal"   />
-        </file>
-
-        <file id="file8" name_suffix="_SBC_scalar" description="scalar variables" enabled=".true." >
-          <!-- global contents -->
-	  <field field_ref="ibgvol_tot"    name="ibgvol_tot"   />
-	  <field field_ref="sbgvol_tot"    name="sbgvol_tot"   />
-	  <field field_ref="ibgarea_tot"   name="ibgarea_tot"  />
-	  <field field_ref="ibgsalt_tot"   name="ibgsalt_tot"  />
-	  <field field_ref="ibgheat_tot"   name="ibgheat_tot"  />
-	  <field field_ref="sbgheat_tot"   name="sbgheat_tot"  />
-	  
-	  <!-- global drifts (conservation checks) -->
-	  <field field_ref="ibgvolume"     name="ibgvolume"    />
-	  <field field_ref="ibgsaltco"     name="ibgsaltco"    />
-	  <field field_ref="ibgheatco"     name="ibgheatco"    />
-	  <field field_ref="ibgheatfx"     name="ibgheatfx"    />
-	  
-	  <!-- global forcings  -->
-	  <field field_ref="ibgfrcvoltop"  name="ibgfrcvoltop" />
-	  <field field_ref="ibgfrcvolbot"  name="ibgfrcvolbot" />
-	  <field field_ref="ibgfrctemtop"  name="ibgfrctemtop" />
-	  <field field_ref="ibgfrctembot"  name="ibgfrctembot" />
-	  <field field_ref="ibgfrcsal"     name="ibgfrcsal"    />
-	  <field field_ref="ibgfrchfxtop"  name="ibgfrchfxtop" />
-	  <field field_ref="ibgfrchfxbot"  name="ibgfrchfxbot" />
-        </file>
-
-        <file id="file9" name_suffix="_bioscalar" description="pisces sms variables" >
-          <field field_ref="tdenit"   name="tdenit"   unit="TgN/yr" operation="instant" > tdenit * 14. * 86400. * 365. / 1e12 </field>
-          <field field_ref="tnfix"    name="tnfix"    unit="TgN/yr" operation="instant" > tnfix * 14. * 86400. * 365. / 1e12 </field>
-          <field field_ref="tcflx"    name="tcflx"    unit="PgC/yr" operation="instant" > tcflx * -1. * 12. * 86400. * 365. / 1e15 </field>
-          <field field_ref="tcflxcum" name="tcflxcum" unit="PgC"    operation="instant" > tcflxcum * -1. * 12. / 1e15 </field>
-          <field field_ref="tcexp"    name="tcexp"    unit="PgC/yr" operation="instant" > tcexp * 12. * 86400. * 365. / 1e15 </field>
-          <field field_ref="tintpp"   name="tintpp"   unit="PgC/yr" operation="instant" > tintpp * 12. * 86400. * 365. / 1e15 </field>
-          <field field_ref="pno3tot"  name="pno3tot"  unit="umolN"  > pno3tot * 16. / 122. * 1e6 </field>
-          <field field_ref="ppo4tot"  name="ppo4tot"  unit="umolP"  > ppo4tot * 1. / 122. * 1e6 </field>
-          <field field_ref="psiltot"  name="psiltot"  unit="umolC"  > psiltot * 1e6  </field>
-          <field field_ref="palktot"  name="palktot"  unit="umolC"  > palktot * 1e6  </field>
-        <field field_ref="pfertot"  name="pfertot"  unit="nmolFe" > pfertot * 1e9  </field>
-        </file>
-	<!--
-	<file id="file20" name_suffix="_Tides" description="tidal harmonics" >
-	  <field field_ref="M2x"          name="M2x"      long_name="M2 Elevation harmonic real part"                       />
-	  <field field_ref="M2y"          name="M2y"      long_name="M2 Elevation harmonic imaginary part"                  />
-	  <field field_ref="M2x_u"        name="M2x_u"    long_name="M2 current barotrope along i-axis harmonic real part "       />
-	  <field field_ref="M2y_u"        name="M2y_u"    long_name="M2 current barotrope along i-axis harmonic imaginary part "  />
-	  <field field_ref="M2x_v"        name="M2x_v"    long_name="M2 current barotrope along j-axis harmonic real part "       />
-	  <field field_ref="M2y_v"        name="M2y_v"    long_name="M2 current barotrope along j-axis harmonic imaginary part "  />
-	</file>
-	-->
-
-      </file_group>
-
-      <file_group id="1m" output_freq="1mo" output_level="10" enabled=".TRUE."> <!-- real monthly files -->
-
-	<file id="file10" name_suffix="_ptrc_T" description="pisces sms variables" >
-          <field field_ref="DIC"      />
-          <field field_ref="Alkalini" />
-          <field field_ref="O2"       />
-          <field field_ref="PO4"      />
-          <field field_ref="Si"       />
-          <field field_ref="Fer"      />
-          <field field_ref="NCHL"     />
-          <field field_ref="DCHL"     />
-          <field field_ref="NO3"      />
-	</file>
-	
-	<file id="file11" name_suffix="_diad_T" description="additional pisces diagnostics" >
-          <field field_ref="Cflx"     />
-          <field field_ref="Dpco2"    />
-	</file>
-
-      </file_group>
-      <file_group id="2m" output_freq="2mo" output_level="10" enabled=".TRUE."/> <!-- real 2m files -->
-      <file_group id="3m" output_freq="3mo" output_level="10" enabled=".TRUE."/> <!-- real 3m files -->
-      <file_group id="4m" output_freq="4mo" output_level="10" enabled=".TRUE."/> <!-- real 4m files -->
-      <file_group id="6m" output_freq="6mo" output_level="10" enabled=".TRUE."/> <!-- real 6m files -->
-
-      <file_group id="1y"  output_freq="1y" output_level="10" enabled=".TRUE."> <!-- real yearly files -->
-
-	<file id="file12" name_suffix="_ptrc_T" description="pisces sms variables" >
-          <field field_ref="DIC"      />
-          <field field_ref="Alkalini" />
-          <field field_ref="O2"       />
-          <field field_ref="CaCO3"    />
-          <field field_ref="PO4"      />
-          <field field_ref="POC"      />
-          <field field_ref="Si"       />
-          <field field_ref="PHY"      />
-          <field field_ref="ZOO"      />
-          <field field_ref="DOC"      />
-          <field field_ref="PHY2"     />
-          <field field_ref="ZOO2"     />
-          <field field_ref="DSi"      />
-          <field field_ref="Fer"      />
-          <field field_ref="BFe"      />
-          <field field_ref="GOC"      />
-          <field field_ref="SFe"      />
-          <field field_ref="DFe"      />
-          <field field_ref="GSi"      />
-          <field field_ref="NFe"      />
-          <field field_ref="NCHL"     />
-          <field field_ref="DCHL"     />
-          <field field_ref="NO3"      />
-          <field field_ref="NH4"      />
-	</file>
-
-	<file id="file13" name_suffix="_diad_T" description="additional pisces diagnostics" >
-          <field field_ref="PH"       />
-          <field field_ref="PAR"      />
-          <field field_ref="PPPHYN"    />
-          <field field_ref="PPPHYD"   />
-          <field field_ref="PPPHYP"   />
-          <field field_ref="PPNEWN"   />
-          <field field_ref="PPNEWD"   />
-          <field field_ref="PPNEWP"   />
-          <field field_ref="PBSi"     />
-          <field field_ref="PFeN"     />
-          <field field_ref="PFeD"     />
-          <field field_ref="PCAL"     />
-          <field field_ref="DCAL"     />
-          <field field_ref="GRAZ1"    />
-          <field field_ref="GRAZ2"    />
-          <field field_ref="EPC100"   />
-          <field field_ref="EPFE100"  />
-          <field field_ref="EPSI100"  />
-          <field field_ref="EPCAL100" />
-          <field field_ref="Cflx"     />
-          <field field_ref="Dpco2"    />
-          <field field_ref="Heup"     />
-          <field field_ref="Nfix"     />
-	</file>
-     </file_group>  
-
-      <file_group id="2y"  output_freq="2y" output_level="10" enabled=".TRUE."/> <!-- real 2y files -->
-      <file_group id="5y"  output_freq="5y" output_level="10" enabled=".TRUE."/> <!-- real 5y files -->
-      <file_group id="10y" output_freq="10y" output_level="10" enabled=".TRUE."/> <!-- real 10y files -->
-
-   </file_definition>
-    
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/iodef.xml
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/iodef.xml	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/iodef.xml	(revision 9019)
@@ -11,5 +11,5 @@
 
           <variable id="info_level"                type="int">10</variable>
-          <variable id="using_server"              type="bool">true</variable>
+          <variable id="using_server"              type="bool">false</variable>
           <variable id="using_oasis"               type="bool">false</variable>
           <variable id="oasis_codes_id"            type="string" >oceanx</variable>
@@ -23,4 +23,5 @@
 
   <context id="nemo" src="./context_nemo.xml"/>       <!--  NEMO       -->
+  <context id="1_nemo" src="./1_context_nemo.xml"/>       <!--  NEMO       -->
 
 </simulation>
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/namelist_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/namelist_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/namelist_cfg	(revision 9019)
@@ -2,5 +2,4 @@
 !! NEMO/OPA  Configuration namelist : used to overwrite defaults values defined in SHARED/namelist_ref
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-!
 !-----------------------------------------------------------------------
 &namrun        !   parameters of the run
@@ -27,6 +26,5 @@
 /
 !-----------------------------------------------------------------------
-&namcrs        !   Grid coarsening for dynamics output and/or
-               !   passive tracer coarsened online simulations
+&namcrs        !   coarsened grid (for outputs and/or TOP)              (ln_crs =T)
 !-----------------------------------------------------------------------
 /
@@ -47,4 +45,8 @@
 !-----------------------------------------------------------------------
 &namtra_qsr    !   penetrative solar radiation
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_cpl
 !-----------------------------------------------------------------------
 /
@@ -100,4 +102,9 @@
 /
 !-----------------------------------------------------------------------
+&namdrg        !   top/bottom friction
+!-----------------------------------------------------------------------
+   ln_lin = .true.         !     linear  drag: Cd = Cd0 Uc0
+/
+!-----------------------------------------------------------------------
 &namagrif      !  AGRIF zoom                                            ("key_agrif")
 !-----------------------------------------------------------------------
@@ -105,8 +112,4 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
 &nambbc        !   bottom temperature boundary condition                (default: NO)
 !-----------------------------------------------------------------------
@@ -114,23 +117,28 @@
 /
 !-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme
-!-----------------------------------------------------------------------
+&nambbl        !   bottom boundary layer scheme                         (default: NO)
+!-----------------------------------------------------------------------
+   ln_trabbl   = .true.    !  Bottom Boundary Layer parameterisation flag
+   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]
 /
 !-----------------------------------------------------------------------
 &nameos        !   ocean physical parameters
 !-----------------------------------------------------------------------
-   ln_teos10    = .true.         !  = Use TEOS-10 equation of state
-/
-!-----------------------------------------------------------------------
-&namtra_adv    !   advection scheme for tracer
-!-----------------------------------------------------------------------
-   ln_traadv_fct =  .true.    !  FCT scheme
+   ln_teos10   = .false.         !  = Use TEOS-10 equation of state
+   ln_eos80    = .true.          !  = Use EOS80
+   ln_seos     = .false.         !  = Use S-EOS (simplified Eq.)
+/
+!-----------------------------------------------------------------------
+&namtra_adv    !   advection scheme for tracer                          (default: NO advection)
+!-----------------------------------------------------------------------
+   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)
-/
-!-----------------------------------------------------------------------
-&namtra_adv_mle !  mixed layer eddy parametrisation (Fox-Kemper param)
+/
+!-----------------------------------------------------------------------
+&namtra_adv_mle !   mixed layer eddy parametrisation (Fox-Kemper param)
 !-----------------------------------------------------------------------
    ln_mle      = .true.   ! (T) use the Mixed Layer Eddy (MLE) parameterisation
@@ -140,4 +148,5 @@
 !----------------------------------------------------------------------------------
    !                       !  Operator type:
+   ln_traldf_NONE  =  .false.  !           No operator (no explicit advection)
    ln_traldf_lap   =  .true.   !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -186,6 +195,11 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection
-!-----------------------------------------------------------------------
+&namdyn_adv    !   formulation of the momentum advection                (default: No selection)
+!-----------------------------------------------------------------------
+   ln_dynadv_NONE= .false. !  linear dynamics (no momentum advection)
+   ln_dynadv_vec = .true.  !  vector form - 2nd centered scheme
+     nn_dynkeg     = 0        ! grad(KE) scheme: =0   C2  ;  =1   Hollingsworth correction
+   ln_dynadv_cen2= .false. !  flux form - 2nd order centered scheme
+   ln_dynadv_ubs = .false. !  flux form - 3rd order UBS      scheme
 /
 !-----------------------------------------------------------------------
@@ -212,5 +226,5 @@
 !-----------------------------------------------------------------------
    !                       !  Type of the operator :
-   !                           !  no diffusion: set ln_dynldf_lap=..._blp=F 
+   ln_dynldf_NONE=  .false.    !           No operator (no explicit diffusion)
    ln_dynldf_lap =  .true.     !    laplacian operator
    ln_dynldf_blp =  .false.    !  bilaplacian operator
@@ -234,22 +248,42 @@
    ! Caution in 20 and 30 cases the coefficient have to be given for a 1 degree grid (~111km)
 /
-!-----------------------------------------------------------------------
-&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")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_tmx_new !   internal wave-driven mixing parameterization        ("key_zdftmx_new" & "key_zdfddm")
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .false.      !  constant mixing
+   ln_zdfric   = .false.      !  local Richardson dependent formulation (T =>   fill namzdf_ric)
+   ln_zdftke   = .true.       !  Turbulent Kinetic Energy closure       (T =>   fill namzdf_tke)
+   ln_zdfgls   = .false.      !  Generic Length Scale closure           (T =>   fill namzdf_gls)
+   ln_zdfosm   = .false.      !  OSMOSIS BL closure                     (T =>   fill namzdf_osm)
+   !
+   !                       ! convection
+   ln_zdfevd   = .true.       !  Enhanced Vertical Diffusion scheme
+      nn_evdm  =    0            !  evd apply on tracer (=0) or on tracer and momentum (=1)
+      rn_evd   =  100.           !  evd mixing coefficient [m2/s]
+   !
+   ln_zdfddm   = .true.    ! double diffusive mixing
+      rn_avts  =    1.e-4     !  maximum avs (vertical mixing on salinity)
+      rn_hsbfr =    1.6       !  heat/salt buoyancy flux ratio
+   !
+   !                       ! gravity wave-driven vertical mixing
+   ln_zdfiwm   = .false.      ! internal wave-induced mixing            (T =>   fill namzdf_iwm)
+   ln_zdfswm   = .false.      ! surface  wave-induced mixing            (T => ln_wave=ln_sdw=T )
+   !
+   !                       !  Coefficients
+   rn_avm0     =   1.2e-4     !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   1.2e-5     !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    1         !  horizontal shape for avtb (=1) or not (=0)
+/
+!-----------------------------------------------------------------------
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion 
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_iwm    !   tidal mixing parameterization                        (ln_zdfiwm =T)
 !-----------------------------------------------------------------------
    nn_zpyc     = 2         !  pycnocline-intensified dissipation scales as N (=1) or N^2 (=2)
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/namelist_ice_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/namelist_ice_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/namelist_ice_cfg	(revision 9019)
@@ -1,48 +1,84 @@
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-!! LIM3 configuration namelist: Overwrites SHARED/namelist_ice_lim3_ref
-!!              1 - Generic parameters                 (namicerun)
-!!              2 - Diagnostics                        (namicediag)
-!!              3 - Ice initialization                 (namiceini)
-!!              4 - Ice discretization                 (namiceitd)
-!!              5 - Ice dynamics and transport         (namicedyn)
-!!              6 - Ice diffusion                      (namicehdf)
-!!              7 - Ice thermodynamics                 (namicethd)
-!!              8 - Ice salinity                       (namicesal)
-!!              9 - Ice mechanical redistribution      (namiceitdme)
-!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!! ESIM configuration namelist: Overwrites SHARED/namelist_ice_lim3_ref
+!!              1 - Generic parameters                 (nampar)
+!!              2 - Ice thickness discretization       (namitd)
+!!              3 - Ice dynamics                       (namdyn)
+!!              4 - Ice ridging/rafting                (namdyn_rdgrft)
+!!              5 - Ice rheology                       (namdyn_rhg)
+!!              6 - Ice advection                      (namdyn_adv)
+!!              7 - Ice surface forcing                (namforcing)
+!!              8 - Ice thermodynamics                 (namthd)
+!!              9 - Ice heat diffusion                 (namthd_zdf)
+!!             10 - Ice lateral melting                (namthd_da)
+!!             11 - Ice growth in open water           (namthd_do)
+!!             12 - Ice salinity                       (namthd_sal)
+!!             13 - Ice melt ponds                     (namthd_pnd)
+!!             14 - Ice initialization                 (namini)
+!!             15 - Ice/snow albedos                   (namalb)
+!!             16 - Ice diagnostics                    (namdia)
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!
 !------------------------------------------------------------------------------
-&namicerun     !   Generic parameters
+&nampar         !   Generic parameters
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namicediag    !   Diagnostics
+&namitd         !   Ice discretization
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namiceini     !   Ice initialization
+&namdyn         !   Ice dynamics
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namiceitd     !   Ice discretization
+&namdyn_rdgrft  !   Ice ridging/rafting
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namicedyn     !   Ice dynamics and transport
+&namdyn_rhg     !   Ice rheology
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namicehdf     !   Ice horizontal diffusion
+&namdyn_adv     !   Ice advection
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namicethd     !   Ice thermodynamics
+&namforcing     !   Ice surface forcing
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namicesal     !   Ice salinity
+&namthd         !   Ice thermodynamics
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namiceitdme   !   Ice mechanical redistribution (ridging and rafting)
+&namthd_zdf     !   Ice heat diffusion
 !------------------------------------------------------------------------------
 /
+!------------------------------------------------------------------------------
+&namthd_da      !   Ice lateral melting
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namthd_do      !   Ice growth in open water
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namthd_sal     !   Ice salinity
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namthd_pnd     !   Melt ponds
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namini         !   Ice initialization
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namalb         !   albedo parameters
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namdia         !   Diagnostics
+!------------------------------------------------------------------------------
+/
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/namelist_top_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/namelist_top_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/namelist_top_cfg	(revision 9019)
@@ -71,5 +71,5 @@
 /
 !-----------------------------------------------------------------------
-&namtrc_adv    !   advection scheme for passive tracer 
+&namtrc_adv    !   advection scheme for passive tracer                  (default: NO selection)
 !-----------------------------------------------------------------------
    ln_trcadv_mus =  .true.  !  MUSCL scheme
@@ -78,8 +78,4 @@
 !-----------------------------------------------------------------------
 &namtrc_ldf    !   lateral diffusion scheme for passive tracer 
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namtrc_zdf        !   vertical physics
 !-----------------------------------------------------------------------
 /
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/cpp_ORCA2_LIM3_PISCES.fcm
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/cpp_ORCA2_LIM3_PISCES.fcm	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/cpp_ORCA2_LIM3_PISCES.fcm	(revision 9019)
@@ -1,1 +1,1 @@
-bld::tool::fppkeys key_trabbl key_lim3 key_zdftke key_zdfddm key_zdftmx_new key_iomput key_mpp_mpi key_top key_nosignedzero
+bld::tool::fppkeys   key_lim3 key_top key_iomput key_mpp_mpi key_nosignedzero
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist_cfg	(revision 9019)
@@ -37,13 +37,4 @@
 /
 !-----------------------------------------------------------------------
-&namsplit      !   time splitting parameters                            ("key_dynspg_ts")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namcrs        !   Grid coarsening for dynamics output and/or
-               !   passive tracer coarsened online simulations
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
 &namsbc        !   Surface Boundary Condition (surface module)
 !-----------------------------------------------------------------------
@@ -69,9 +60,17 @@
 &nambbl        !   bottom boundary layer scheme
 !-----------------------------------------------------------------------
+   ln_trabbl   = .true.    !  Bottom Boundary Layer parameterisation flag
+   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]
+/
 /
 !-----------------------------------------------------------------------
 &nameos        !   ocean physical parameters
 !-----------------------------------------------------------------------
-   ln_teos10    = .true.         !  = Use TEOS-10 equation of state
+   ln_teos10   = .false.        !  = Use TEOS-10 equation of state
+   ln_eos80    = .true.         !  = Use EOS80
+   ln_seos     = .false.        !  = Use S-EOS (simplified Eq.)
 /
 !----------------------------------------------------------------------------------
@@ -79,4 +78,5 @@
 !----------------------------------------------------------------------------------
    !                       !  Operator type:
+   ln_traldf_NONE  =  .false.  !           No operator (no explicit advection)
    ln_traldf_lap   =  .true.   !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist_top_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist_top_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/EXP00/namelist_top_cfg	(revision 9019)
@@ -71,5 +71,5 @@
 /
 !-----------------------------------------------------------------------
-&namtrc_adv    !   advection scheme for passive tracer 
+&namtrc_adv    !   advection scheme for passive tracer                  (default: No selection)
 !-----------------------------------------------------------------------
    ln_trcadv_mus =  .true.  !  MUSCL scheme
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/cpp_ORCA2_OFF_PISCES.fcm
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/cpp_ORCA2_OFF_PISCES.fcm	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_OFF_PISCES/cpp_ORCA2_OFF_PISCES.fcm	(revision 9019)
@@ -1,1 +1,1 @@
-bld::tool::fppkeys key_trabbl key_top key_iomput key_mpp_mpi
+bld::tool::fppkeys   key_top key_iomput key_mpp_mpi
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_OFF_TRC/EXP00/namelist_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_OFF_TRC/EXP00/namelist_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_OFF_TRC/EXP00/namelist_cfg	(revision 9019)
@@ -39,13 +39,4 @@
 /
 !-----------------------------------------------------------------------
-&namsplit      !   time splitting parameters                            ("key_dynspg_ts")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namcrs        !   Grid coarsening for dynamics output and/or
-               !   passive tracer coarsened online simulations
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
 &namsbc        !   Surface Boundary Condition (surface module)
 !-----------------------------------------------------------------------
@@ -71,4 +62,9 @@
 &nambbl        !   bottom boundary layer scheme
 !-----------------------------------------------------------------------
+   ln_trabbl   = .true.    !  Bottom Boundary Layer parameterisation flag
+   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]
 /
 !-----------------------------------------------------------------------
@@ -81,4 +77,5 @@
 !----------------------------------------------------------------------------------
    !                       !  Operator type:
+   ln_traldf_NONE  =  .false.  ! No explicit diffusion
    ln_traldf_lap   =  .true.   !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_OFF_TRC/cpp_ORCA2_OFF_TRC.fcm
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_OFF_TRC/cpp_ORCA2_OFF_TRC.fcm	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_OFF_TRC/cpp_ORCA2_OFF_TRC.fcm	(revision 9019)
@@ -1,1 +1,1 @@
-bld::tool::fppkeys key_trabbl key_top key_iomput key_mpp_mpi
+bld::tool::fppkeys   key_top key_iomput key_mpp_mpi
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_SAS_LIM3/EXP00/file_def_nemo.xml
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_SAS_LIM3/EXP00/file_def_nemo.xml	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_SAS_LIM3/EXP00/file_def_nemo.xml	(revision 9019)
@@ -21,7 +21,7 @@
     -->
     
-    <file_definition type="multiple_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="10d" min_digits="4">
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="10d" min_digits="4">
     
-      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."/> <!-- 1 time step files -->
+      <file_group id="2ts" output_freq="2ts"  output_level="10" enabled=".TRUE."/> <!-- 1 time step files -->
 
       <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
@@ -39,5 +39,5 @@
       <file_group id="3d" output_freq="3d"  output_level="10" enabled=".TRUE."/> <!-- 3d files -->
       
-      <file_group id="5d" output_freq="5d"  output_level="10" enabled=".TRUE.">  <!-- 5d files -->   
+      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE.">  <!-- 5d files -->   
 	
 	<file id="file1" name_suffix="_grid_T" description="ocean T grid variables" >
@@ -110,162 +110,7 @@
 
 	<file id="file6" name_suffix="_icemod" description="ice variables" enabled=".true." >
-          <field field_ref="snowthic_cea"    name="snthic" />
-          <field field_ref="icethic_cea"     name="sithic" />
           <field field_ref="icevolu"         name="sivolu" />
-          <field field_ref="snowvol"         name="snvolu" />
-          <field field_ref="iceconc"         name="siconc" />
-
-          <field field_ref="vfxbog"          name="vfxbog" />
-          <field field_ref="vfxdyn"          name="vfxdyn" />
-          <field field_ref="vfxopw"          name="vfxopw" />
-          <field field_ref="vfxsni"          name="vfxsni" />
-          <field field_ref="vfxsum"          name="vfxsum" />
-          <field field_ref="vfxbom"          name="vfxbom" />
-          <field field_ref="vfxres"          name="vfxres" />
-          <field field_ref="vfxice"          name="vfxice" />
-          <field field_ref="vfxsnw"          name="vfxsnw" />
-          <field field_ref="vfxsub"          name="vfxsub" />
-          <field field_ref="vfxspr"          name="vfxspr" />
-
-          <field field_ref="icetrp"          name="sivtrp" />
-          <field field_ref="snwtrp"          name="snvtrp" />
-          <field field_ref="saltrp"          name="saltrp" />
-          <field field_ref="deitrp"          name="deitrp" />
-          <field field_ref="destrp"          name="destrp" />
-
-          <field field_ref="sfxbri"          name="sfxbri" />
-          <field field_ref="sfxdyn"          name="sfxdyn" />
-          <field field_ref="sfxres"          name="sfxres" />
-          <field field_ref="sfxbog"          name="sfxbog" />
-          <field field_ref="sfxbom"          name="sfxbom" />
-          <field field_ref="sfxsum"          name="sfxsum" />
-          <field field_ref="sfxsni"          name="sfxsni" />
-          <field field_ref="sfxopw"          name="sfxopw" />
-          <field field_ref="sfx"             name="sfx"    />
-
-          <field field_ref="hfxsum"          name="hfxsum"     />
-          <field field_ref="hfxbom"          name="hfxbom"     />
-          <field field_ref="hfxbog"          name="hfxbog"     />
-          <field field_ref="hfxdif"          name="hfxdif"     />
-          <field field_ref="hfxopw"          name="hfxopw"     />
-          <field field_ref="hfxout"          name="hfxout"     />
-          <field field_ref="hfxin"           name="hfxin"      />
-          <field field_ref="hfxsnw"          name="hfxsnw"     />
-          <field field_ref="hfxerr"          name="hfxerr"     />
-          <field field_ref="hfxerr_rem"      name="hfxerr_rem" />
-
-	  <!-- ice-ocean heat flux from mass exchange -->
-          <field field_ref="hfxdyn"          name="hfxdyn" />
-          <field field_ref="hfxres"          name="hfxres" />
-          <field field_ref="hfxthd"          name="hfxthd" />
-	  <!-- ice-atm. heat flux from mass exchange -->
-          <field field_ref="hfxsub"          name="hfxsub" />
-          <field field_ref="hfxspr"          name="hfxspr" />
-
-	  <!-- diags -->
-          <field field_ref="hfxdhc"          name="hfxdhc" />
-          <field field_ref="hfxtur"          name="hfxtur" />
-
-          <field field_ref="isst"            name="sst"    />
-          <field field_ref="isss"            name="sss"    />
-          <field field_ref="micesalt"        name="sisali" />
-          <field field_ref="micet"           name="sitemp" />
-          <field field_ref="icest"           name="sistem" />
-          <field field_ref="icehc"           name="siheco" />
-          <field field_ref="isnowhc"         name="snheco" />
-          <field field_ref="miceage"         name="siages" />
-
-          <field field_ref="uice_ipa"        name="sivelu" />
-          <field field_ref="vice_ipa"        name="sivelv" />
-          <field field_ref="icevel"          name="sivelo" />
-          <field field_ref="idive"           name="sidive" />
-          <field field_ref="ishear"          name="sishea" />
-          <field field_ref="icestr"          name="sistre" />
-
-          <field field_ref="ibrinv"          name="sibrin" />
-          <field field_ref="icecolf"         name="sicolf" />
-
-          <field field_ref="iceage_cat"      name="siagecat" />
-          <field field_ref="iceconc_cat"     name="siconcat" />
-          <field field_ref="icethic_cat"     name="sithicat" />
-          <field field_ref="snowthic_cat"    name="snthicat" />
-          <field field_ref="salinity_cat"    name="salincat" />
-          <field field_ref="brinevol_cat"    name="sibricat" />
-	  <field field_ref="icetemp_cat"     name="sitemcat" />
-	  <field field_ref="snwtemp_cat"     name="sntemcat" />
 
 	</file>
-
-        <file id="file7" name_suffix="_scalar" description="scalar variables" enabled=".true." >
-          <field field_ref="voltot"       name="scvoltot"   />
-          <field field_ref="sshtot"       name="scsshtot"   />
-          <field field_ref="sshsteric"    name="scsshste"   />
-          <field field_ref="sshthster"    name="scsshtst"   />
-          <field field_ref="masstot"      name="scmastot"   />
-          <field field_ref="temptot"      name="sctemtot"   />
-          <field field_ref="saltot"       name="scsaltot"   />
-
-          <field field_ref="bgtemper"     name="bgtemper"   />
-          <field field_ref="bgsaline"     name="bgsaline"   />
-          <field field_ref="bgheatco"     name="bgheatco"   />
-          <field field_ref="bgsaltco"     name="bgsaltco"   />
-          <field field_ref="bgvolssh"     name="bgvolssh"   /> 
-          <field field_ref="bgvole3t"     name="bgvole3t"   />
-          <field field_ref="bgfrcvol"     name="bgfrcvol"   />
-          <field field_ref="bgfrctem"     name="bgfrctem"   />
-          <field field_ref="bgfrcsal"     name="bgfrcsal"   />
-
-          <field field_ref="ibgvoltot"    name="ibgvoltot"  />
-          <field field_ref="sbgvoltot"    name="sbgvoltot"  />
-          <field field_ref="ibgarea"      name="ibgarea"    />
-          <field field_ref="ibgsaline"    name="ibgsaline"  />
-          <field field_ref="ibgtemper"    name="ibgtemper"  />
-          <field field_ref="ibgheatco"    name="ibgheatco"  />
-          <field field_ref="sbgheatco"    name="sbgheatco"  />
-          <field field_ref="ibgsaltco"    name="ibgsaltco"  />
-
-          <field field_ref="ibgvfx"       name="ibgvfx"     />
-          <field field_ref="ibgvfxbog"    name="ibgvfxbog"  />
-          <field field_ref="ibgvfxopw"    name="ibgvfxopw"  />
-          <field field_ref="ibgvfxsni"    name="ibgvfxsni"  />
-          <field field_ref="ibgvfxdyn"    name="ibgvfxdyn"  />
-          <field field_ref="ibgvfxbom"    name="ibgvfxbom"  />
-          <field field_ref="ibgvfxsum"    name="ibgvfxsum"  />
-          <field field_ref="ibgvfxres"    name="ibgvfxres"  />
-          <field field_ref="ibgvfxspr"    name="ibgvfxspr"  />
-          <field field_ref="ibgvfxsnw"    name="ibgvfxsnw"  />
-          <field field_ref="ibgvfxsub"    name="ibgvfxsub"  />
-
-          <field field_ref="ibgsfx"       name="ibgsfx"     />
-          <field field_ref="ibgsfxbri"    name="ibgsfxbri"  />
-          <field field_ref="ibgsfxdyn"    name="ibgsfxdyn"  />
-          <field field_ref="ibgsfxres"    name="ibgsfxres"  />
-          <field field_ref="ibgsfxbog"    name="ibgsfxbog"  />
-          <field field_ref="ibgsfxopw"    name="ibgsfxopw"  />
-          <field field_ref="ibgsfxsni"    name="ibgsfxsni"  />
-          <field field_ref="ibgsfxbom"    name="ibgsfxbom"  />
-          <field field_ref="ibgsfxsum"    name="ibgsfxsum"  />
-
-          <field field_ref="ibghfxdhc"    name="ibghfxdhc"  />
-          <field field_ref="ibghfxspr"    name="ibghfxspr"  />
-
-          <field field_ref="ibghfxres"    name="ibghfxres"  />
-          <field field_ref="ibghfxsub"    name="ibghfxsub"  />
-          <field field_ref="ibghfxdyn"    name="ibghfxdyn"  />
-          <field field_ref="ibghfxthd"    name="ibghfxthd"  />
-          <field field_ref="ibghfxsum"    name="ibghfxsum"  />
-          <field field_ref="ibghfxbom"    name="ibghfxbom"  />
-          <field field_ref="ibghfxbog"    name="ibghfxbog"  />
-          <field field_ref="ibghfxdif"    name="ibghfxdif"  />
-          <field field_ref="ibghfxopw"    name="ibghfxopw"  />
-          <field field_ref="ibghfxout"    name="ibghfxout"  />
-          <field field_ref="ibghfxin"     name="ibghfxin"   />
-          <field field_ref="ibghfxsnw"    name="ibghfxsnw"  />
-
-          <field field_ref="ibgfrcvol"    name="ibgfrcvol"  />
-          <field field_ref="ibgfrcsfx"    name="ibgfrcsfx"  />
-          <field field_ref="ibgvolgrm"    name="ibgvolgrm"  />
-
-        </file>
 
 	<!--
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_SAS_LIM3/EXP00/namelist_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_SAS_LIM3/EXP00/namelist_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_SAS_LIM3/EXP00/namelist_cfg	(revision 9019)
@@ -19,9 +19,4 @@
 /
 !-----------------------------------------------------------------------
-&namzgr        !   vertical coordinate
-!-----------------------------------------------------------------------
-   ln_zps      = .true.    !  z-coordinate - partial steps
-/
-!-----------------------------------------------------------------------
 &namdom        !   space and time domain (bathymetry, mesh, timestep)
 !-----------------------------------------------------------------------
@@ -32,6 +27,5 @@
 /
 !-----------------------------------------------------------------------
-&namcrs        !   Grid coarsening for dynamics output and/or
-               !   passive tracer coarsened online simulations
+&namcrs        !   coarsened grid (for outputs and/or TOP)              (ln_crs =T)
 !-----------------------------------------------------------------------
 /
@@ -75,17 +69,4 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-   ln_trabbc   = .true.    !  Apply a geothermal heating at the ocean bottom
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
 &nameos        !   ocean physical parameters
 !-----------------------------------------------------------------------
@@ -93,127 +74,17 @@
 /
 !-----------------------------------------------------------------------
-&namtra_adv    !   advection scheme for tracer
+&namtra_adv    !   advection scheme for tracer                          (default: NO selection)
 !-----------------------------------------------------------------------
-   ln_traadv_fct =  .true.    !  FCT scheme
-      nn_fct_h   =  2               !  =2/4, horizontal 2nd / 4th order 
-      nn_fct_v   =  2               !  =2/4, vertical   2nd / COMPACT 4th order 
-      nn_fct_zts =  0               !  > 1 , 2nd order FCT scheme with vertical sub-timestepping
-      !                             !        (number of sub-timestep = nn_fct_zts)
-/
-!-----------------------------------------------------------------------
-&namtra_adv_mle !  mixed layer eddy parametrisation (Fox-Kemper param)
-!-----------------------------------------------------------------------
+   ln_traadv_NONE =  .true.    !  No advection
 /
 !----------------------------------------------------------------------------------
 &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 (Triads   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]
+   ln_traldf_lap  =  .NONE.   ! No explicit diffusion
 /
-!----------------------------------------------------------------------------------
-&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
-/
-!-----------------------------------------------------------------------
-&namtra_dmp    !   tracer: T & S newtonian damping                      (default: NO)
-!-----------------------------------------------------------------------
 !-----------------------------------------------------------------------
 &namdyn_adv    !   formulation of the momentum advection
 !-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&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)
-/
-!-----------------------------------------------------------------------
-&namdyn_hpg    !   Hydrostatic pressure gradient option
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&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]
-   !
-   ! Caution in 20 and 30 cases the coefficient have to be given for a 1 degree grid (~111km)
-/
-!-----------------------------------------------------------------------
-&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")
-!-----------------------------------------------------------------------
+   ln_dynadv_NONE =  .true.    !  No advection
 /
 !-----------------------------------------------------------------------
@@ -225,18 +96,2 @@
 !-----------------------------------------------------------------------
 /
-!-----------------------------------------------------------------------
-&namptr       !   Poleward Transport Diagnostic
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namhsb       !  Heat and salt budgets                                  (default F)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namobs       !  observation usage                                      ('key_diaobs')
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nam_asminc   !   assimilation increments                               ('key_asminc')
-!-----------------------------------------------------------------------
-/
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_SAS_LIM3/EXP00/namelist_ice_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_SAS_LIM3/EXP00/namelist_ice_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_SAS_LIM3/EXP00/namelist_ice_cfg	(revision 9019)
@@ -1,48 +1,84 @@
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-!! LIM3 configuration namelist: Overwrites SHARED/namelist_ice_lim3_ref
-!!              1 - Generic parameters                 (namicerun)
-!!              2 - Diagnostics                        (namicediag)
-!!              3 - Ice initialization                 (namiceini)
-!!              4 - Ice discretization                 (namiceitd)
-!!              5 - Ice dynamics and transport         (namicedyn)
-!!              6 - Ice diffusion                      (namicehdf)
-!!              7 - Ice thermodynamics                 (namicethd)
-!!              8 - Ice salinity                       (namicesal)
-!!              9 - Ice mechanical redistribution      (namiceitdme)
-!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!! ESIM configuration namelist: Overwrites SHARED/namelist_ice_lim3_ref
+!!              1 - Generic parameters                 (nampar)
+!!              2 - Ice thickness discretization       (namitd)
+!!              3 - Ice dynamics                       (namdyn)
+!!              4 - Ice ridging/rafting                (namdyn_rdgrft)
+!!              5 - Ice rheology                       (namdyn_rhg)
+!!              6 - Ice advection                      (namdyn_adv)
+!!              7 - Ice surface forcing                (namforcing)
+!!              8 - Ice thermodynamics                 (namthd)
+!!              9 - Ice heat diffusion                 (namthd_zdf)
+!!             10 - Ice lateral melting                (namthd_da)
+!!             11 - Ice growth in open water           (namthd_do)
+!!             12 - Ice salinity                       (namthd_sal)
+!!             13 - Ice melt ponds                     (namthd_pnd)
+!!             14 - Ice initialization                 (namini)
+!!             15 - Ice/snow albedos                   (namalb)
+!!             16 - Ice diagnostics                    (namdia)
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!
 !------------------------------------------------------------------------------
-&namicerun     !   Generic parameters
+&nampar         !   Generic parameters
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namicediag    !   Diagnostics
+&namitd         !   Ice discretization
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namiceini     !   Ice initialization
+&namdyn         !   Ice dynamics
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namiceitd     !   Ice discretization
+&namdyn_rdgrft  !   Ice ridging/rafting
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namicedyn     !   Ice dynamics and transport
+&namdyn_rhg     !   Ice rheology
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namicehdf     !   Ice horizontal diffusion
+&namdyn_adv     !   Ice advection
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namicethd     !   Ice thermodynamics
+&namforcing     !   Ice surface forcing
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namicesal     !   Ice salinity
+&namthd         !   Ice thermodynamics
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namiceitdme   !   Ice mechanical redistribution (ridging and rafting)
+&namthd_zdf     !   Ice heat diffusion
 !------------------------------------------------------------------------------
 /
+!------------------------------------------------------------------------------
+&namthd_da      !   Ice lateral melting
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namthd_do      !   Ice growth in open water
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namthd_sal     !   Ice salinity
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namthd_pnd     !   Melt ponds
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namini         !   Ice initialization
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namalb         !   albedo parameters
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namdia         !   Diagnostics
+!------------------------------------------------------------------------------
+/
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_SAS_LIM3/cpp_ORCA2_SAS_LIM3.fcm
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_SAS_LIM3/cpp_ORCA2_SAS_LIM3.fcm	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/ORCA2_SAS_LIM3/cpp_ORCA2_SAS_LIM3.fcm	(revision 9019)
@@ -1,1 +1,1 @@
- bld::tool::fppkeys key_trabbl key_lim3  key_zdftke key_zdfddm key_zdftmx key_iomput key_mpp_mpi
+ bld::tool::fppkeys   key_lim3 key_iomput key_mpp_mpi
Index: anches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/README_configs_namcfg_namdom
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/README_configs_namcfg_namdom	(revision 9018)
+++ 	(revision )
@@ -1,609 +1,0 @@
-
-
-This README file contains the informations for the &namcfg namelist for some configurations whic are not one of the reference configurations.
-These informations wher previoulsy in NEMO/OPA_SRC_par_*.h90 files. The full test with these configurations has not been done.
-
-
-ORCA_R4
-=======
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-   cp_cfg      =  "orca"               !  name of the configuration
-   jp_cfg      =       4               !  resolution of the configuration
-   jpidta      =      92               !  1st lateral dimension ( >= jpi )
-   jpjdta      =      76               !  2nd    "         "    ( >= jpj )
-   jpkdta      =      31               !  number of levels      ( >= jpk )
-   jpiglo      =      92               !  1st dimension of global domain --> i =jpidta
-   jpjglo      =      76               !  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)
-/
-!-----------------------------------------------------------------------
-&namdom        !  
-!-----------------------------------------------------------------------
-   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.0             !  Minimum vertical spacing
-   pphmax      =  999999.0             !  Maximum depth
-   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
-   ppa2        =  999999.0             !  Double tanh function parameters
-   ppkth2      =  999999.0             !
-   ppacr2      =  999999.0             !
-/
-
-ORCA_R1 75 vertical levels
-=======
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-   cp_cfg      =  "orca"               !  name of the configuration
-   jp_cfg      =       1               !  resolution of the configuration
-   jpidta      =     362               !  1st lateral dimension ( >= jpi )
-   jpjdta      =     292               !  2nd    "         "    ( >= jpj )
-   jpkdta      =      75               !  number of levels      ( >= jpk )
-   jpiglo      =     362               !  1st dimension of global domain --> i =jpidta
-   jpjglo      =     292               !  2nd    -                  -    --> j  =jpjdta
-   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
-   jpjzoom     =       1               !  in data domain indices
-   jperio      =       6               !  lateral cond. type (between 0 and 6)
-/
-!-----------------------------------------------------------------------
-&namdom        !  
-!-----------------------------------------------------------------------
-   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       =   -3958.951371276829  !  ORCA r4, r2 and r05 coefficients
-   ppa0        =     103.9530096000000 ! (default coefficients)
-   ppa1        =       2.415951269000000   !
-   ppkth       =      15.35101370000000    !
-   ppacr       =       7.0             !
-   ppdzmin     =  999999.0             !  Minimum vertical spacing
-   pphmax      =  999999.0             !  Maximum depth
-   ldbletanh   =   .TRUE.              !  Use/do not use double tanf function for vertical coordinates
-   ppa2        =     100.7609285000000 !  Double tanh function parameters
-   ppkth2      =      48.02989372000000    !
-   ppacr2      =      13.00000000000   !
-/
-
-
-ORCA_R1 46 vertical levels
-=======
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-   cp_cfg      =  "orca"               !  name of the configuration
-   jp_cfg      =       1               !  resolution of the configuration
-   jpidta      =     362               !  1st lateral dimension ( >= jpi )
-   jpjdta      =     292               !  2nd    "         "    ( >= jpj )
-   jpkdta      =      46               !  number of levels      ( >= jpk )
-   jpiglo      =     362               !  1st dimension of global domain --> i =jpidta
-   jpjglo      =     292               !  2nd    -                  -    --> j  =jpjdta
-   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
-   jpjzoom     =       1               !  in data domain indices
-   jperio      =       6               !  lateral cond. type (between 0 and 6)
-/
-!-----------------------------------------------------------------------
-&namdom        !  
-!-----------------------------------------------------------------------
-   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       =  999998.0             !  ORCA r4, r2 and r05 coefficients
-   ppa0        =  999998.0             ! (default coefficients)
-   ppa1        =  999998.0             !
-   ppkth       =      23.563           !
-   ppacr       =       9.0             !
-   ppdzmin     =       6.0             !  Minimum vertical spacing
-   pphmax      =    5750.              !  Maximum depth
-   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
-   ppa2        =  999999.0             !  Double tanh function parameters
-   ppkth2      =  999999.0             !
-   ppacr2      =  999999.0             !
-/
-ORCA_R05 
-========
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-   cp_cfg      =  "orca"               !  name of the configuration
-   jp_cfg      =      05               !  resolution of the configuration
-   jpidta      =     722               !  1st lateral dimension ( >= jpi )
-   jpjdta      =     511               !  2nd    "         "    ( >= jpj )
-   jpkdta      =      31               !  number of levels      ( >= jpk )
-   jpiglo      =     722               !  1st dimension of global domain --> i =jpidta
-   jpjglo      =     511               !  2nd    -                  -    --> j  =jpjdta
-   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
-   jpjzoom     =       1               !  in data domain indices
-   jperio      =       6               !  lateral cond. type (between 0 and 6)
-/
-!-----------------------------------------------------------------------
-&namdom        !  
-!-----------------------------------------------------------------------
-   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.0             !  Minimum vertical spacing
-   pphmax      =  999999.0             !  Maximum depth
-   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
-   ppa2        =  999999.0             !  Double tanh function parameters
-   ppkth2      =  999999.0             !
-   ppacr2      =  999999.0             !
-/
-
-
-ORCA_R05 Antarctic zoom
-========
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-   cp_cfg      =  "orca"               !  name of the configuration
-   cp_cfz      =  "antarctic"          !  name of the zoom of configuration
-   jp_cfg      =      05               !  resolution of the configuration
-   jpidta      =     722               !  1st lateral dimension ( >= jpi )
-   jpjdta      =     511               !  2nd    "         "    ( >= jpj )
-   jpkdta      =      31               !  number of levels      ( >= jpk )
-   jpiglo      =     722               !  1st dimension of global domain --> i =jpidta
-   jpjglo      =     187               !  2nd    -                  -    --> j  =jpjdta
-   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
-   jpjzoom     =       1               !  in data domain indices
-   jperio      =       1               !  lateral cond. type (between 0 and 6)
-/
-!-----------------------------------------------------------------------
-&namdom        !  
-!-----------------------------------------------------------------------
-   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.0             !  Minimum vertical spacing
-   pphmax      =  999999.0             !  Maximum depth
-   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
-   ppa2        =  999999.0             !  Double tanh function parameters
-   ppkth2      =  999999.0             !
-   ppacr2      =  999999.0             !
-/
-
-
-ORCA_R05 Arctic zoom
-========
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-   cp_cfg      =  "orca"               !  name of the configuration
-   cp_cfz      =  "arctic"             !  name of the zoom of configuration
-   jp_cfg      =      05               !  resolution of the configuration
-   jpidta      =     722               !  1st lateral dimension ( >= jpi )
-   jpjdta      =     511               !  2nd    "         "    ( >= jpj )
-   jpkdta      =      31               !  number of levels      ( >= jpk )
-   jpiglo      =     562               !  1st dimension of global domain --> i =jpidta
-   jpjglo      =     211               !  2nd    -                  -    --> j  =jpjdta
-   jpizoom     =      81               !  left bottom (i,j) indices of the zoom
-   jpjzoom     =     301               !  in data domain indices
-   jperio      =       5               !  lateral cond. type (between 0 and 6)
-/
-!-----------------------------------------------------------------------
-&namdom        !  
-!-----------------------------------------------------------------------
-   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.0             !  Minimum vertical spacing
-   pphmax      =  999999.0             !  Maximum depth
-   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
-   ppa2        =  999999.0             !  Double tanh function parameters
-   ppkth2      =  999999.0             !
-   ppacr2      =  999999.0             !
-/
-
-ORCA2 - Antarctic zoom
-======================
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-   cp_cfg      =  "orca"               !  name of the configuration
-   cp_cfz      =  "antarctic"          !  name of the zoom of 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      =      50               !  2nd    -                  -    --> j  =jpjdta
-   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
-   jpjzoom     =       1               !  in data domain indices
-   jperio      =       1               !  lateral cond. type (between 0 and 6)
-/
-!-----------------------------------------------------------------------
-&namdom        !  
-!-----------------------------------------------------------------------
-   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.              !
-/
-
-
-ORCA2 - Arctic zoom
-=================== 
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-   cp_cfg      =  "orca"               !  name of the configuration
-   cp_cfz      =  "arctic"             !  name of the zoom of 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      =     142               !  1st dimension of global domain --> i =jpidta
-   jpjglo      =      53               !  2nd    -                  -    --> j  =jpjdta
-   jpizoom     =      21               !  left bottom (i,j) indices of the zoom
-   jpjzoom     =      97               !  in data domain indices
-   jperio      =       3               !  lateral cond. type (between 0 and 6)
-/
-!-----------------------------------------------------------------------
-&namdom        !  
-!-----------------------------------------------------------------------
-   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.              !
-/
-
-
-ORCA025 - 75 vertical levels
-=======
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-   cp_cfg      =  "orca"               !  name of the configuration
-   jp_cfg      =     025               !  resolution of the configuration
-   jpidta      =    1442               !  1st lateral dimension ( >= jpi )
-   jpjdta      =    1021               !  2nd    "         "    ( >= jpj )
-   jpkdta      =      75               !  number of levels      ( >= jpk )
-   jpiglo      =    1442               !  1st dimension of global domain --> i =jpidta
-   jpjglo      =    1021               !  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)
-/
-!-----------------------------------------------------------------------
-&namdom        !  
-!-----------------------------------------------------------------------
-   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       =   -3958.951371276829  !  ORCA r4, r2 and r05 coefficients
-   ppa0        =    103.9530096000000  ! (default coefficients)
-   ppa1        =      2.415951269000000  !
-   ppkth       =     15.35101370000000 !
-   ppacr       =       7.0             !
-   ppdzmin     =  999999.0             !  Minimum vertical spacing
-   pphmax      =  999999.0             !  Maximum depth
-   ldbletanh   =   .TRUE.              !  Use/do not use double tanf function for vertical coordinates
-   ppa2        =     100.7609285000000 !  Double tanh function parameters
-   ppkth2      =      48.02989372000000  !
-   ppacr2      =      13.              !
-/
-
-
-ORCA025 - 46 vertical levels
-=======
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-   cp_cfg      =  "orca"               !  name of the configuration
-   jp_cfg      =    1442               !  resolution of the configuration
-   jpidta      =    1021               !  1st lateral dimension ( >= jpi )
-   jpjdta      =     511               !  2nd    "         "    ( >= jpj )
-   jpkdta      =      46               !  number of levels      ( >= jpk )
-   jpiglo      =    1442               !  1st dimension of global domain --> i =jpidta
-   jpjglo      =    1021               !  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)
-/
-!-----------------------------------------------------------------------
-&namdom        !  
-!-----------------------------------------------------------------------
-   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       =  999998.0             !  ORCA r4, r2 and r05 coefficients
-   ppa0        =  999998.0             ! (default coefficients)
-   ppa1        =  999998.0             !
-   ppkth       =      23.563           !
-   ppacr       =       9.0             !
-   ppdzmin     =       6.0             !  Minimum vertical spacing
-   pphmax      =    5750.0             !  Maximum depth
-   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
-   ppa2        =  999999.0             !  Double tanh function parameters
-   ppkth2      =  999999.0             !
-   ppacr2      =  999999.0             !
-/
-EEL R2: channel
-======
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-   cp_cfg      =   "eel"               !  name of the configuration
-   jp_cfg      =       2               !  resolution of the configuration
-   jpidta      =      83               !  1st lateral dimension ( >= jpi )
-   jpjdta      =     242               !  2nd    "         "    ( >= jpj )
-   jpkdta      =      30               !  number of levels      ( >= jpk )
-   jpiglo      =      83               !  1st dimension of global domain --> i =jpidta
-   jpjglo      =     242               !  2nd    -                  -    --> j  =jpjdta
-   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
-   jpjzoom     =       1               !  in data domain indices
-   jperio      =       1               !  lateral cond. type (between 0 and 6)
-/
-!-----------------------------------------------------------------------
-&namdom        !  
-!-----------------------------------------------------------------------
-   jphgr_msh   =       3               !  type of horizontal mesh
-   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    =  999999.0             !  zonal      grid-spacing (degrees)
-   ppe2_deg    =  999999.0             !  meridional grid-spacing (degrees)
-   ppe1_m      =    2000.0             !  zonal      grid-spacing (degrees)
-   ppe2_m      =    2000.0             !  meridional grid-spacing (degrees)
-   ppsur       =   -2033.194295283385  !  ORCA r4, r2 and r05 coefficients
-   ppa0        =     155.8325369664153 ! (default coefficients)
-   ppa1        =     146.3615918601890 !
-   ppkth       =      17.28520372419791  !
-   ppacr       =       5.0             !
-   ppdzmin     =  999999.0             !  Minimum vertical spacing
-   pphmax      =  999999.0             !  Maximum depth
-   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
-   ppa2        =  999999.0             !  Double tanh function parameters
-   ppkth2      =  999999.0             !
-   ppacr2      =  999999.0             !
-/
-
-
-EEL R5: channel
-======
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-   cp_cfg      =   "eel"               !  name of the configuration
-   jp_cfg      =       5               !  resolution of the configuration
-   jpidta      =      66               !  1st lateral dimension ( >= jpi )
-   jpjdta      =      66               !  2nd    "         "    ( >= jpj )
-   jpkdta      =      31               !  number of levels      ( >= jpk )
-   jpiglo      =      66               !  1st dimension of global domain --> i =jpidta
-   jpjglo      =      66               !  2nd    -                  -    --> j  =jpjdta
-   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
-   jpjzoom     =       1               !  in data domain indices
-   jperio      =       1               !  lateral cond. type (between 0 and 6)
-/
-!-----------------------------------------------------------------------
-&namdom        !  
-!-----------------------------------------------------------------------
-   jphgr_msh   =       2               !  type of horizontal mesh
-   ppglam0     =       0.0             !  longitude of first raw and column T-point (jphgr_msh = 1)
-   ppgphi0     =      43.436430714     ! 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      =    8000.0             !  zonal      grid-spacing (degrees)
-   ppe2_m      =    8000.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.0             !  Minimum vertical spacing
-   pphmax      =  999999.0             !  Maximum depth
-   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
-   ppa2        =  999999.0             !  Double tanh function parameters
-   ppkth2      =  999999.0             !
-   ppacr2      =  999999.0             !
-/
-
-
-EEL R6: 6 km resolution channel
-======
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-   cp_cfg      =   "eel"               !  name of the configuration
-   jp_cfg      =       6               !  resolution of the configuration
-   jpidta      =      29               !  1st lateral dimension ( >= jpi )
-   jpjdta      =      83               !  2nd    "         "    ( >= jpj )
-   jpkdta      =      30               !  number of levels      ( >= jpk )
-   jpiglo      =      29               !  1st dimension of global domain --> i =jpidta
-   jpjglo      =      83               !  2nd    -                  -    --> j  =jpjdta
-   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
-   jpjzoom     =       1               !  in data domain indices
-   jperio      =       1               !  lateral cond. type (between 0 and 6)
-/
-!-----------------------------------------------------------------------
-&namdom        !  
-!-----------------------------------------------------------------------
-   jphgr_msh   =       3               !  type of horizontal mesh
-   ppglam0     =       0.0             !  longitude of first raw and column T-point (jphgr_msh = 1)
-   ppgphi0     =      35.              ! 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      =    6000.0             !  zonal      grid-spacing (degrees)
-   ppe2_m      =    6000.0             !  meridional grid-spacing (degrees)
-   ppsur       =   -2033.194295283385  !  ORCA r4, r2 and r05 coefficients
-   ppa0        =     155.8325369664153 ! (default coefficients)
-   ppa1        =     146.3615918601890 !
-   ppkth       =      17.28520372419791   !
-   ppacr       =       5.0             !
-   ppdzmin     =  999999.0             !  Minimum vertical spacing
-   pphmax      =  999999.0             !  Maximum depth
-   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
-   ppa2        =  999999.0             !  Double tanh function parameters
-   ppkth2      =  999999.0             !
-   ppacr2      =  999999.0             !
-/
-
-
-POMME: 025
-======
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-   cp_cfg      =   "pomme"             !  name of the configuration
-   jp_cfg      =     025               !  resolution of the configuration
-   jpidta      =      30               !  1st lateral dimension ( >= jpi )
-   jpjdta      =      40               !  2nd    "         "    ( >= jpj )
-   jpkdta      =      46               !  number of levels      ( >= jpk )
-   jpiglo      =      30               !  1st dimension of global domain --> i =jpidta
-   jpjglo      =      40               !  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)
-/
-!-----------------------------------------------------------------------
-&namdom        !  
-!-----------------------------------------------------------------------
-   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       =  999998.0             !  ORCA r4, r2 and r05 coefficients
-   ppa0        =  999998.0             ! (default coefficients)
-   ppa1        =  999998.0             !
-   ppkth       =      23.563           !
-   ppacr       =       9.0             !
-   ppdzmin     =       6.0             !  Minimum vertical spacing
-   pphmax      =    5750.0             !  Maximum depth
-   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
-   ppa2        =  999999.0             !  Double tanh function parameters
-   ppkth2      =  999999.0             !
-   ppacr2      =  999999.0             !
-/
-
-C1D - 1D configuration. Add key_c1d in active cpp keys
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-   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      =       3               !  1st dimension of global domain --> i =jpidta
-   jpjglo      =       3               !  2nd    -                  -    --> j  =jpjdta
-! Choose postion of the 1D column: 
-!            jpizoom =   61, jpjzoom =   133  (160W,75N)
-!            jpizoom =   61, jpjzoom =   110  (160W,50N)
-!            jpizoom =   61, jpjzoom =   97   (160W,30N)
-!            jpizoom =   61, jpjzoom =   86   (160W,10N)
-!            jpizoom =   61, jpjzoom =   49   (160W,30S)
-!            jpizoom =   61, jpjzoom =   27   (160W,60S)
-!            jpizoom =   61, jpjzoom =    7   (160W,75S)
-!            jpizoom =   110,jpjzoom =   97   (64W,31.5N) BATS site
-   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)
-/
-!-----------------------------------------------------------------------
-&namdom        !  
-!-----------------------------------------------------------------------
-   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.              !
-/
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/field_def_nemo-lim.xml
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/field_def_nemo-lim.xml	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/field_def_nemo-lim.xml	(revision 9019)
@@ -4,5 +4,5 @@
     <!-- 
 ============================================================================================================
-=                                  definition of all existing variables                                    =
+=                                  definition of all existing ice variables                                =
 =                                            DO NOT CHANGE                                                 =
 ============================================================================================================
@@ -12,126 +12,140 @@
       <field_group id="SBC" grid_ref="grid_T_2D" > <!-- time step automaticaly defined based on nn_fsbc -->
 
-         <!-- LIM2(only) fields -->
-         <field id="qsr_ai_cea"   long_name="Air-Ice downward solar heat flux (cell average)"              standard_name="surface_downwelling_shortwave_flux_in_air"          unit="W/m2"         />
-         <field id="qns_ai_cea"   long_name="Air-Ice downward non-solar heat flux (cell average)"                                                                             unit="W/m2"         />
-         <field id="qla_ai_cea"   long_name="Air-Ice downward Latent heat flux (cell average)"             standard_name="surface_downward_latent_heat_flux"                  unit="W/m2"         />         
-         <field id="qsr_io_cea"   long_name="Ice-Oce downward solar heat flux (cell average)"              standard_name="net_downward_shortwave_flux_at_sea_water_surface"   unit="W/m2"         />
-         <field id="qns_io_cea"   long_name="Ice-Oce downward non-solar heat flux (cell average)"                                                                             unit="W/m2"         />
-         <field id="iceprod_cea"  long_name="Ice production (cell average)"                                                                                                   unit="m/s"          />
-         <field id="iiceconc"     long_name="Ice concentration"                                            standard_name="sea_ice_area_fraction"                              unit="1"            />
-         <field id="ice_pres"     long_name="Ice presence"                                                                                                                    unit=""             />
-         <field id="ist_cea"      long_name="Ice surface temperature (cell average)"                       standard_name="surface_temperature"                                unit="degC"         />
-         <field id="ist_ipa"      long_name="Ice surface temperature (ice presence average)"               standard_name="surface_temperature"                                unit="degC"         />
-         <field id="u_imasstr"    long_name="Sea-ice mass transport along i-axis"                          standard_name="sea_ice_x_transport"                                unit="kg/s"         />
-         <field id="v_imasstr"    long_name="Sea-ice mass transport along j-axis"                          standard_name="sea_ice_y_transport"                                unit="kg/s"         />
-
-         <!-- LIM3 fields -->  
-         <field id="ice_cover"    long_name="Ice fraction"                                                 standard_name="sea_ice_area_fraction"                              unit="1"            />
- 
-         <field id="snowthic_cea" long_name="Snow thickness (cell average)"                                standard_name="surface_snow_thickness"                             unit="m"            />
-         <field id="icethic_cea"  long_name="Ice thickness (cell average)"                                 standard_name="sea_ice_thickness"                                  unit="m"            />
-
-         <field id="uice_ipa"     long_name="Ice velocity along i-axis at I-point (ice presence average)"  standard_name="sea_ice_x_velocity"                                 unit="m/s"          />      
-         <field id="vice_ipa"     long_name="Ice velocity along j-axis at I-point (ice presence average)"  standard_name="sea_ice_y_velocity"                                 unit="m/s"          />               
-         <field id="utau_ice"     long_name="Wind stress along i-axis over the ice at i-point"             standard_name="surface_downward_x_stress"                          unit="N/m2"         />
-         <field id="vtau_ice"     long_name="Wind stress along j-axis over the ice at i-point"             standard_name="surface_downward_y_stress"                          unit="N/m2"         />
-         
-         <field id="iceconc"      long_name="ice concentration"                                            standard_name="sea_ice_area_fraction"                              unit="%"            />
-       	 <field id="isst"         long_name="sea surface temperature"                                      standard_name="sea_surface_temperature"                            unit="degC"         />
-         <field id="isss"         long_name="sea surface salinity"                                         standard_name="sea_surface_salinity"                               unit="1e-3"         /> 
-         <field id="qt_oce"       long_name="total flux at ocean surface"                                  standard_name="surface_downward_heat_flux_in_sea_water"            unit="W/m2"         />
-         <field id="qsr_oce"      long_name="solar heat flux at ocean surface"                             standard_name="net_downward_shortwave_flux_at_sea_water_surface"   unit="W/m2"         />
-         <field id="qns_oce"      long_name="non-solar heat flux at ocean surface"                                                                                            unit="W/m2"         />
-         <field id="qt_ice"       long_name="total heat flux at ice surface: sum over categories"          standard_name="surface_downward_heat_flux_in_air"                  unit="W/m2"         />
-         <field id="qsr_ice"      long_name="solar heat flux at ice surface: sum over categories"          standard_name="surface_downwelling_shortwave_flux_in_air"          unit="W/m2"         />
-         <field id="qns_ice"      long_name="non-solar heat flux at ice surface: sum over categories"                                                                         unit="W/m2"         />
-         <field id="qtr_ice"      long_name="solar heat flux transmitted through ice: sum over categories"                                                                    unit="W/m2"         />
-         <field id="qemp_ice"     long_name="Downward Heat Flux from E-P over ice"                                                                                            unit="W/m2"         />
-         <field id="micesalt"     long_name="Mean ice salinity"                                                                                                               unit="1e-3"         />
-         <field id="miceage"      long_name="Mean ice age"                                                                                                                    unit="years"        />
-         <field id="alb_ice"      long_name="Mean albedo over sea ice"                                                                                                        unit=""             />
-         <field id="albedo"       long_name="Mean albedo over sea ice and ocean"                                                                                              unit=""             />
-
-         <field id="iceage_cat"   long_name="Ice age for categories"                                       unit="days"   grid_ref="grid_T_3D_ncatice" />
-         <field id="iceconc_cat"  long_name="Ice concentration for categories"                             unit="%"      grid_ref="grid_T_3D_ncatice" />
-         <field id="icethic_cat"  long_name="Ice thickness for categories"                                 unit="m"      grid_ref="grid_T_3D_ncatice" />
-         <field id="snowthic_cat" long_name="Snow thicknessi for categories"                               unit="m"      grid_ref="grid_T_3D_ncatice" />
-         <field id="salinity_cat" long_name="Sea-Ice Bulk salinity for categories"                         unit="g/kg"   grid_ref="grid_T_3D_ncatice" />
-         <field id="brinevol_cat" long_name="Brine volume for categories"                                  unit="%"      grid_ref="grid_T_3D_ncatice" />
-         <field id="icetemp_cat"  long_name="Ice temperature for categories"                               unit="degC"   grid_ref="grid_T_3D_ncatice" />
-         <field id="snwtemp_cat"  long_name="Snow temperature for categories"                              unit="degC"   grid_ref="grid_T_3D_ncatice" />
-
-         <field id="micet"        long_name="Mean ice temperature"                                         unit="degC"     />
-         <field id="icehc"        long_name="ice total heat content"                                       unit="10^9J"    /> 
-         <field id="isnowhc"      long_name="snow total heat content"                                      unit="10^9J"    />
-         <field id="icest"        long_name="ice surface temperature"                                      unit="degC"     />
-         <field id="ibrinv"       long_name="brine volume"                                                 unit="%"        />
-         <field id="icecolf"      long_name="frazil ice collection thickness"                              unit="m"        />
-         <field id="icestr"       long_name="ice strength"                                                 unit="N/m"      />
-         <field id="icevel"       long_name="ice velocity"                                                 unit="m/s"      />
-         <field id="idive"        long_name="divergence"                                                   unit="1e-8s-1"  />
-         <field id="ishear"       long_name="shear"                                                        unit="1e-8s-1"  />
-         <field id="icevolu"      long_name="ice volume"                                                   unit="m"        />
-         <field id="snowvol"      long_name="snow volume"                                                  unit="m"        />
-         <field id="tau_icebfr"   long_name="ice friction on ocean bottom for landfast ice"                unit="N/2"      />
-
-         <field id="icetrp"       long_name="ice volume transport"                                         unit="m/day"          />
-         <field id="snwtrp"       long_name="snw volume transport"                                         unit="m/day"          />
-         <field id="saltrp"       long_name="salt content transport"                                       unit="1e-3*kg/m2/day" />
-         <field id="deitrp"       long_name="advected ice enthalpy"                                        unit="W/m2"           />
-         <field id="destrp"       long_name="advected snw enthalpy"                                        unit="W/m2"           />
-
-         <field id="sfxbri"       long_name="brine salt flux"                                              unit="1e-3*kg/m2/day" />
-         <field id="sfxdyn"       long_name="salt flux from ridging rafting"                               unit="1e-3*kg/m2/day" />
-         <field id="sfxres"       long_name="salt flux from lipupdate (resultant)"                         unit="1e-3*kg/m2/day" />
-         <field id="sfxbog"       long_name="salt flux from bot growth"                                    unit="1e-3*kg/m2/day" />
-         <field id="sfxbom"       long_name="salt flux from bot melt"                                      unit="1e-3*kg/m2/day" />
-         <field id="sfxsum"       long_name="salt flux from surf melt"                                     unit="1e-3*kg/m2/day" />
-         <field id="sfxlam"       long_name="salt flux from lateral melt"                                  unit="1e-3*kg/m2/day" />
-         <field id="sfxsni"       long_name="salt flux from snow-ice formation"                            unit="1e-3*kg/m2/day" />
-         <field id="sfxopw"       long_name="salt flux from open water ice formation"                      unit="1e-3*kg/m2/day" />
-         <field id="sfxsub"       long_name="salt flux from sublimation"                                   unit="1e-3*kg/m2/day" />
-         <field id="sfx"          long_name="salt flux total"                                              unit="1e-3*kg/m2/day" />
-
-         <field id="vfxbog"       long_name="daily bottom thermo ice prod."                                unit="m/day"   />
-         <field id="vfxdyn"       long_name="daily  dynamic ice prod."                                     unit="m/day"   />
-         <field id="vfxopw"       long_name="daily lateral thermo ice prod."                               unit="m/day"   />
-         <field id="vfxsni"       long_name="daily snowice ice prod."                                      unit="m/day"   />
-         <field id="vfxsum"       long_name="surface melt"                                                 unit="m/day"   />
-         <field id="vfxlam"       long_name="lateral melt"                                                 unit="m/day"   />
-         <field id="vfxbom"       long_name="bottom melt"                                                  unit="m/day"   />
-         <field id="vfxres"       long_name="daily resultant ice prod./melting from limupdate"             unit="m/day"   />
-         <field id="vfxice"       long_name="ice melt/growth"                                              unit="m/day"   />
-         <field id="vfxsnw"       long_name="snw melt/growth"                                              unit="m/day"   />
-         <field id="vfxsub"       long_name="snw sublimation"                                              unit="m/day"   />
-         <field id="vfxsub_err"   long_name="excess of snw sublimation sent to ocean"                      unit="m/day"   />
-         <field id="vfxspr"       long_name="snw precipitation on ice"                                     unit="m/day"   />
-         <field id="vfxthin"      long_name="daily thermo ice prod. for thin ice(20cm) + open water"      unit="m/day"   />
-
-         <field id="afxtot"       long_name="area tendency (total)"                                        unit="day-1"   />
-         <field id="afxdyn"       long_name="area tendency (dynamics)"                                     unit="day-1"   />
-         <field id="afxthd"       long_name="area tendency (thermo)"                                       unit="day-1"   />
-
-         <field id="hfxsum"       long_name="heat fluxes causing surface ice melt"                         unit="W/m2"  />
-         <field id="hfxbom"       long_name="heat fluxes causing bottom ice melt"                          unit="W/m2"  />
-         <field id="hfxbog"       long_name="heat fluxes causing bottom ice growth"                        unit="W/m2"  />
-         <field id="hfxdif"       long_name="heat fluxes causing ice temperature change"                   unit="W/m2"  />
-         <field id="hfxopw"       long_name="heat fluxes causing open water ice formation"                 unit="W/m2"  />
-         <field id="hfxsnw"       long_name="heat fluxes causing snow melt"                                unit="W/m2"  />
-         <field id="hfxerr"       long_name="heat fluxes error after heat diffusion"                       unit="W/m2"  />
-         <field id="hfxerr_rem"   long_name="heat fluxes error after remapping"                            unit="W/m2"  />
-         <field id="hfxout"       long_name="total heat fluxes received by the ocean"                      unit="W/m2"  />
-         <field id="hfxin"        long_name="total heat fluxes at the ice/ocean surface"                   unit="W/m2"  />
-
-         <!-- heat flux associated with mass exchange -->
-         <field id="hfxthd"       long_name="heat fluxes from ice-ocean mass exchange during thermo"       unit="W/m2"  />
-         <field id="hfxdyn"       long_name="heat fluxes from ice-ocean mass exchange during dynamic"      unit="W/m2"  />
-         <field id="hfxres"       long_name="heat fluxes from ice-ocean mass exchange during resultant"    unit="W/m2"  />
-         <field id="hfxsub"       long_name="heat fluxes from ice-atm. mass exchange during sublimation"   unit="W/m2"  />
-         <field id="hfxspr"       long_name="heat fluxes from ice-atm. mass exchange during snow precip"   unit="W/m2"  />
+         <!-- =================== -->
+         <!-- standard ice fields -->  
+         <!-- =================== -->
+	 <!-- ice presence masks -->
+         <field id="icemask"      long_name="Fraction of time steps with sea ice"                     standard_name="sea_ice_mask"                              unit="" />
+         <field id="icemask05"    long_name="Ice mask (0 if ice conc. lower than  5%, 1 otherwise)"   standard_name="sea_ice_mask05"                            unit="" />
+         <field id="icemask15"    long_name="Ice mask (0 if ice conc. lower than 15%, 1 otherwise)"   standard_name="sea_ice_mask15"                            unit="" />
+	 <field id="icepres"      long_name="Fraction of time steps with sea ice"                     standard_name="sea_ice_time_fraction"                     unit="" />
+	 
+	 <!-- general fields -->
+         <field id="icemass"      long_name="Sea-ice mass per area"                                   standard_name="sea_ice_amount"                            unit="kg/m2"/>
+         <field id="snwmass"      long_name="Snow mass per area"                                      standard_name="liquid_water_content_of_surface_snow"      unit="kg/m2"/>
+         <field id="iceconc"      long_name="Sea-ice area fraction"                                   standard_name="sea_ice_area_fraction"                     unit=""    />
+         <field id="icevolu"      long_name="Sea-ice volume per area"                                 standard_name="sea_ice_thickness"                         unit="m"   />
+         <field id="icethic"      long_name="Sea-ice thickness per area"                              standard_name="sea_ice_thickness"                         unit="m"   />
+         <field id="snwthic"      long_name="Snow thickness per area"                                 standard_name="snow_thickness"                            unit="m"   />
+         <field id="icebrv"       long_name="brine volume"                                                                                                      unit="%"   />
+         <field id="iceage"       long_name="ice age"                                                                                                           unit="days"/>
+         <field id="icehnew"      long_name="frazil ice collection thickness"                                                                                   unit="m"   />
+         <field id="snwvolu"      long_name="snow volume"                                                                                                       unit="m"   />
+         <field id="icefrb"       long_name="Sea-ice freeboard"                                       standard_name="sea_ice_freeboard"                         unit="m"   />
+         <field id="icealb"       long_name="Sea-ice or snow albedo"                                  standard_name="sea_ice_albedo"                            unit=""    />
+         <field id="tau_icebfr"   long_name="ice friction on ocean bottom for landfast ice"                                                                     unit="N/2" />
+
+	 <!-- melt ponds -->
+	 <field id="iceapnd"      long_name="melt pond fraction"                                      standard_name="sea_ice_meltpond_fraction"                 unit="%" /> 
+         <field id="icevpnd"      long_name="melt pond volume"                                        standard_name="sea_ice_meltpond_volume"                   unit="m" /> 
+	 
+	 <!-- heat -->
+         <field id="icetemp"      long_name="Mean ice temperature"                                                                                              unit="degC" />
+         <field id="icettop"      long_name="temperature at the ice surface"                                                                                    unit="degC" />
+         <field id="icetbot"      long_name="temperature at the ice bottom"                                                                                     unit="degC" />
+         <field id="icetsni"      long_name="temperature at the snow-ice interface"                                                                             unit="degC" />
+         <field id="icehc"        long_name="ice heat content"                                                                                                  unit="J/m2" /> 
+         <field id="snwhc"        long_name="snow heat content"                                                                                                 unit="J/m2" />
+
+	 <!-- salt -->
+         <field id="icesalt"      long_name="Sea ice salinity"                                                                                                  unit="g/kg"  />
+         <field id="icesalm"      long_name="Mass of salt in sea ice per area"                        standard_name="sea_ice_salt_mass"                         unit="kg/m2" />
+	 
+	 <!-- momentum (rheology) -->
+         <field id="uice"         long_name="X-component of sea ice velocity"                         standard_name="sea_ice_x_velocity"                        unit="m/s"  /> 
+         <field id="vice"         long_name="Y-component of sea ice velocity"                         standard_name="sea_ice_y_velocity"                        unit="m/s"  />      
+         <field id="icevel"       long_name="Sea-ice speed"                                           standard_name="sea_ice_speed"                             unit="m/s"  />
+         <field id="utau_ai"      long_name="X-component of atmospheric stress on sea ice"            standard_name="surface_downward_x_stress"                 unit="N/m2" />
+         <field id="vtau_ai"      long_name="Y-component of atmospheric stress on sea ice"            standard_name="surface_downward_y_stress"                 unit="N/m2" />
+         <field id="utau_oi"      long_name="X-component of ocean stress on sea ice"                  standard_name="sea_ice_base_upward_x_stress"              unit="N/m2" />
+         <field id="vtau_oi"      long_name="Y-component of ocean stress on sea ice"                  standard_name="sea_ice_base_upward_y_stress"              unit="N/m2" />
+         <field id="isig1"        long_name="1st principal stress component for EVP rhg"                                                                        unit=""     />
+         <field id="isig2"        long_name="2nd principal stress component for EVP rhg"                                                                        unit=""     />
+         <field id="isig3"        long_name="convergence measure for EVP rheology (must be around 1)"                                                           unit=""     />
+         <field id="normstr"      long_name="Average normal stress in sea ice"                        standard_name="average_normal_stress"                     unit="N/m"  />
+         <field id="sheastr"      long_name="Maximum shear stress in sea ice"                         standard_name="maximum_shear_stress"                      unit="N/m"  />
+         <field id="icestr"       long_name="Compressive sea ice strength"                            standard_name="compressive_strength_of_sea_ice"           unit="N/m"  />
+         <field id="icediv"       long_name="Divergence of the sea-ice velocity field"                standard_name="divergence_of_sea_ice_velocity"            unit="s-1"  />
+         <field id="iceshe"       long_name="Maximum shear of sea-ice velocity field"                 standard_name="maximum_shear_of_sea_ice_velocity"         unit="s-1"  />
+
+	 <!-- surface heat fluxes -->
+         <field id="qt_ice"       long_name="total heat flux at ice surface"                          standard_name="surface_downward_heat_flux_in_air"         unit="W/m2" />
+         <field id="qsr_ice"      long_name="solar heat flux at ice surface"                          standard_name="surface_downwelling_shortwave_flux_in_air" unit="W/m2" />
+         <field id="qns_ice"      long_name="non-solar heat flux at ice surface (including E-P)"                                                                unit="W/m2" />
+         <field id="qtr_ice_bot"  long_name="solar heat flux transmitted through the ice (to the ocean)"                                                        unit="W/m2" />
+         <field id="qtr_ice_top"  long_name="solar heat flux transmitted through the ice surface"                                                               unit="W/m2" />
+         <field id="qt_oce_ai"    long_name="total heat flux at the ocean   surface: interface oce-(ice+atm)"                                                   unit="W/m2" />
+         <field id="qt_atm_oi"    long_name="total heat flux at the oce-ice surface: interface atm-(ice+oce)"                                                   unit="W/m2" />
+         <field id="qemp_ice"     long_name="Downward Heat Flux from E-P over ice"                                                                              unit="W/m2" />
+         <field id="albedo"       long_name="Mean albedo over sea ice and ocean"                                                                                unit=""     />
+
+	 <!-- trends -->
+         <field id="afxthd"       long_name="sea-ice area fraction change from thermodynamics"  standard_name="tendency_of_sea_ice_area_fraction_due_to_dynamics" unit="s-1" />
+         <field id="afxdyn"       long_name="sea-ice area fraction change from dynamics"        standard_name="tendency_of_sea_ice_area_fraction_due_to_dynamics" unit="s-1" />
+	 <field id="afxtot"       long_name="area tendency (total)"                                                                                               unit="s-1" />
+
+	 <!-- momentum (advection) -->
+         <field id="icemtrp"      long_name="ice  mass transport"                                          unit="kg/m2/s" />
+         <field id="snwmtrp"      long_name="snw  mass transport"                                          unit="kg/m2/s" />
+         <field id="salmtrp"      long_name="salt mass transport"                                          unit="kg/m2/s" />
+         <field id="dihctrp"      long_name="ice heat content transport"                                   unit="W/m2"    />
+         <field id="dshctrp"      long_name="snw heat content transport"                                   unit="W/m2"    />
+
+	 <!-- salt fluxes -->
+         <field id="sfxice"       long_name="ice-ocean salt flux from ice growth/melt (neg = growth)"      unit="kg/m2/s" />
+         <field id="sfxbog"       long_name="ice-ocean salt flux from ice bottom growth"                   unit="kg/m2/s" />
+         <field id="sfxbom"       long_name="ice-ocean salt flux from ice bottom melt"                     unit="kg/m2/s" />
+         <field id="sfxsum"       long_name="ice-ocean salt flux from ice surface melt"                    unit="kg/m2/s" />
+         <field id="sfxlam"       long_name="ice-ocean salt flux from ice lateral melt"                    unit="kg/m2/s" />
+         <field id="sfxsni"       long_name="ice-ocean salt flux from snow-ice formation"                  unit="kg/m2/s" />
+         <field id="sfxopw"       long_name="ice-ocean salt flux from ice formation in open water"         unit="kg/m2/s" />
+         <field id="sfxdyn"       long_name="ice-ocean salt flux from ice dynamics (ridging)"              unit="kg/m2/s" />
+         <field id="sfxbri"       long_name="ice-ocean salt flux from brines"                              unit="kg/m2/s" />
+         <field id="sfxres"       long_name="ice-ocean salt flux from undiagnosed processes"               unit="kg/m2/s" />
+         <field id="sfxsub"       long_name="ice-ocean salt flux from ice sublimation"                     unit="kg/m2/s" />
+
+	 <!-- mass fluxes -->
+         <field id="vfxice"       long_name="ice-ocean mass flux from ice melt/growth (neg = growth)"      unit="kg/m2/s" />
+         <field id="vfxbog"       long_name="ice-ocean mass flux from ice bottom growth"                   unit="kg/m2/s" />
+         <field id="vfxbom"       long_name="ice-ocean mass flux from ice bottom melt"                     unit="kg/m2/s" />
+         <field id="vfxsum"       long_name="ice-ocean mass flux from ice surface melt"                    unit="kg/m2/s" />
+         <field id="vfxlam"       long_name="ice-ocean mass flux from ice lateral melt"                    unit="kg/m2/s" />
+         <field id="vfxsni"       long_name="ice-ocean mass flux from snow-ice formation"                  unit="kg/m2/s" />
+         <field id="vfxopw"       long_name="ice-ocean mass flux from ice growth in open water"            unit="kg/m2/s" />
+         <field id="vfxdyn"       long_name="ice-ocean mass flux from ice dynamics (ridging)"              unit="kg/m2/s" />
+         <field id="vfxres"       long_name="ice-ocean mass flux from undiagnosed processes"               unit="kg/m2/s" />
+         <field id="vfxpnd"       long_name="ice-ocean mass flux from ice melt ponds"                      unit="kg/m2/s" />
+         <field id="vfxsub"       long_name="ice-atm.  mass flux from ice sublimation"                     unit="kg/m2/s" />
+         <field id="vfxsub_err"   long_name="ice-ocean mass flux from unbalance in sublimation (incl. in qt_oce_ai)" unit="kg/m2/s" />
+         <field id="vfxthin"      long_name="ice-ocean mass flux from ice growth in open water + thin ice(20cm)" unit="kg/m2/s" />
+
+         <field id="vfxsnw"       long_name="ice-ocean mass flux from snw melt/growth (neg = growth)"      unit="kg/m2/s" />
+         <field id="vfxsnw_sum"   long_name="ice-ocean mass flux from snw surface melt"                    unit="kg/m2/s" />
+         <field id="vfxsnw_sni"   long_name="ice-ocean mass flux from snow-ice formation"                  unit="kg/m2/s" />
+         <field id="vfxsnw_dyn"   long_name="ice-ocean mass flux from dynamics (ridging)"                  unit="kg/m2/s" />
+         <field id="vfxsnw_sub"   long_name="ice-atm.  mass flux from snw sublimation"                     unit="kg/m2/s" />
+         <field id="vfxsnw_pre"   long_name="snw precipitation on ice"                                     unit="kg/m2/s" />
+
+	 <!-- heat fluxes -->
+         <field id="hfxbog"       long_name="heat flux used for bottom ice growth (neg.)"                  unit="W/m2" />
+         <field id="hfxbom"       long_name="heat flux used for bottom ice melt (pos.)"                    unit="W/m2" />
+         <field id="hfxsum"       long_name="heat flux used for surface ice melt"                          unit="W/m2" />
+         <field id="hfxopw"       long_name="heat flux used for open water ice formation"                  unit="W/m2" />
+         <field id="hfxdif"       long_name="heat flux used for ice temperature change"                    unit="W/m2" />
+         <field id="hfxsnw"       long_name="heat flux used for snow melt"                                 unit="W/m2" />
+         <field id="hfxerr"       long_name="heat flux error after heat diffusion"                         unit="W/m2" />
+         <!-- heat fluxes associated with mass exchange -->
+         <field id="hfxthd"       long_name="heat fluxes from ice-ocean mass exchange during thermo"       unit="W/m2" />
+         <field id="hfxdyn"       long_name="heat fluxes from ice-ocean mass exchange during dynamic"      unit="W/m2" />
+         <field id="hfxres"       long_name="heat fluxes from ice-ocean mass exchange during resultant"    unit="W/m2" />
+         <field id="hfxsub"       long_name="heat fluxes from ice-atm. mass exchange during sublimation"   unit="W/m2" />
+         <field id="hfxspr"       long_name="heat fluxes from ice-atm. mass exchange during snow precip"   unit="W/m2" />
+
+         <field id="hfxsensib"    long_name="Net sensible heat flux under sea ice (neg = ice cooling)"         standard_name="ice_ocean_heat_flux"                        unit="W/m2" />
+         <field id="hfxcndtop"    long_name="Net conductive heat flux at the ice surface (neg = ice cooling)"  standard_name="conductive_heat_flux_at_sea_ice_surface"    unit="W/m2" /> 
+         <field id="hfxcndbot"    long_name="Net conductive heat flux at the ice bottom (neg = ice cooling)"   standard_name="conductive_heat_flux_at_sea_ice_bottom"     unit="W/m2" />
 
          <!-- diags -->
-         <field id="hfxdhc"       long_name="Heat content variation in snow and ice"                       unit="W/m2" />
-         <field id="hfxtur"       long_name="turbulent heat flux at the ice base"                          unit="W/m2" />
+         <field id="hfxdhc"       long_name="Heat content variation in snow and ice (neg = ice cooling)"   unit="W/m2" />
 
 	 <!-- sbcssm variables -->
@@ -144,28 +158,126 @@
          <field id="frq_m"    unit="-"    />
 
-      </field_group>
-
-      <!-- LIM3 scalar variables -->
+	 <!-- categories -->
+	 <field id="iceconc_cat"  long_name="Sea-ice concentration per category"                unit=""       grid_ref="grid_T_3D_ncatice" />
+         <field id="icethic_cat"  long_name="Sea-ice thickness per category"                    unit="m"      grid_ref="grid_T_3D_ncatice" />
+         <field id="snwthic_cat"  long_name="Snow thickness per category"                       unit="m"      grid_ref="grid_T_3D_ncatice" />
+         <field id="icesalt_cat"  long_name="Sea-Ice Bulk salinity per category"                unit="g/kg"   grid_ref="grid_T_3D_ncatice" />
+         <field id="icetemp_cat"  long_name="Ice temperature per category"                      unit="degC"   grid_ref="grid_T_3D_ncatice" />
+         <field id="snwtemp_cat"  long_name="Snow temperature per category"                     unit="degC"   grid_ref="grid_T_3D_ncatice" />
+         <field id="iceapnd_cat"  long_name="Ice melt pond concentration per category"          unit="%"      grid_ref="grid_T_3D_ncatice" /> 
+         <field id="icehpnd_cat"  long_name="Ice melt pond thickness per category"              unit="m"      grid_ref="grid_T_3D_ncatice" /> 
+         <field id="iceafpnd_cat" long_name="Ice melt pond fraction per category"               unit="m"      grid_ref="grid_T_3D_ncatice" /> 
+         <field id="icemask_cat"  long_name="Ice mask (0 if no ice, 1 otherwise) per category"  unit=""       grid_ref="grid_T_3D_ncatice" />
+         <field id="iceage_cat"   long_name="Ice age per category"                              unit="days"   grid_ref="grid_T_3D_ncatice" />
+         <field id="icebrv_cat"   long_name="Brine volume per category"                         unit="%"      grid_ref="grid_T_3D_ncatice" />
+
+	 <!-- ================= -->
+         <!-- Add-ons for SIMIP -->
+         <!-- ================= -->
+         <field id="icemass_cmip" long_name="Sea-ice mass per area"                                   standard_name="sea_ice_amount"                             unit="kg/m2"  > icemass * icemask   + 1.e20 * (1.-icemask  ) </field>
+         <field id="icethic_cmip" long_name="Sea-ice thickness"                                       standard_name="sea_ice_thickness"                          unit="m"      > icethic * icemask05 + 1.e20 * (1.-icemask05) </field>
+         <field id="snwmass_cmip" long_name="Snow mass per area"                                      standard_name="liquid_water_content_of_surface_snow"       unit="kg/m2"  > snwmass * icemask   + 1.e20 * (1.-icemask  ) </field>
+         <field id="snwthic_cmip" long_name="Snow thickness"                                          standard_name="surface_snow_thickness"                     unit="m"      > snwthic * icemask05 + 1.e20 * (1.-icemask05) </field>
+         <field id="iceconc_pct"  long_name="Sea-ice area fraction in percent"                        standard_name="sea_ice_area_fraction_in_percent"           unit="%"      > iceconc * 100.                                </field>
+         <field id="iceage_cmip"  long_name="Age of sea ice"                                          standard_name="age_of_sea_ice"                             unit="days"   > iceage  * icemask15 + 1.e20 * (1.-icemask15) </field>
+         <field id="icesalt_cmip" long_name="Sea ice salinity"                                        standard_name="sea_ice_salinity"                           unit="g/kg"   > icesalt * icemask   + 1.e20 * (1.-icemask)   </field>
+         <field id="icefrb_cmip"  long_name="Sea-ice freeboard"                                       standard_name="sea_ice_freeboard"                          unit="m"      > icefrb  * icemask   + 1.e20 * (1.-icemask)   </field>
+
+	 <!-- heat -->
+         <field id="icettop_cmip" long_name="Surface temperature of sea ice"                          standard_name="sea_ice_surface_temperature"                unit="K"  > (icettop+273.15) * icemask + 1.e20 * (1.-icemask) </field>
+         <field id="icetsni_cmip" long_name="Temperature at snow-ice interface"                       standard_name="sea_ice_snow_interface_temperature"         unit="K"  > (icetsni+273.15) * icemask + 1.e20 * (1.-icemask) </field>
+         <field id="icetbot_cmip" long_name="Temperature at ice-ocean interface"                      standard_name="sea_ice_bottom_temperature"                 unit="K"  > (icetbot+273.15) * icemask + 1.e20 * (1.-icemask) </field>
+         <field id="icehc_cmip"   long_name="Sea-ice heat content per unit area"                      standard_name="integral_of_sea_ice_temperature_wrt_depth_expressed_as_heat_content" unit="J/m2" > icehc * icemask + 1.e20 * (1.-icemask) </field>
+         <field id="snwhc_cmip"   long_name="Snow-heat content per unit area"                         standard_name="thermal_energy_content_of_surface_snow"                              unit="J/m2" > snwhc * icemask + 1.e20 * (1.-icemask) </field>
+
+	 <!-- fluxes (mass, heat, salt) -->
+         <field id="vfxsum_cmip"    long_name="Freshwater flux from sea-ice surface"                  standard_name="freshwater_flux_from_ice_surface"           unit="kg/m2/s"  > vfxsum    * icemask + 1.e20 * (1.-icemask) </field>
+         <field id="vfxice_cmip"    long_name="Freshwater flux from sea ice"                          standard_name="freshwater_flux_from_ice"                   unit="kg/m2/s"  > vfxice    * icemask + 1.e20 * (1.-icemask) </field>
+         <field id="hfxsensib_cmip" long_name="Net sensible heat flux under sea ice"                  standard_name="ice_ocean_heat_flux"                        unit="W/m2"     > hfxsensib * icemask + 1.e20 * (1.-icemask) </field> 
+         <field id="hfxcndtop_cmip" long_name="Net conductive heat flux at the ice surface"           standard_name="conductive_heat_flux_at_sea_ice_surface"    unit="W/m2"     > hfxcndtop * icemask + 1.e20 * (1.-icemask) </field> 
+         <field id="hfxcndbot_cmip" long_name="Net conductive heat flux at the ice bottom"            standard_name="conductive_heat_flux_at_sea_ice_bottom"     unit="W/m2"     > hfxcndbot * icemask + 1.e20 * (1.-icemask) </field>
+         <field id="sfxice_cmip"    long_name="Salt flux from sea ice"                                standard_name="salt_flux_from_ice"                         unit="kg/m2/s"  > sfxice    * icemask + 1.e20 * (1.-icemask) </field>
+
+	 <!-- trends -->
+         <field id="dmithd"       long_name="sea-ice mass change from thermodynamics"                 standard_name="tendency_of_sea_ice_amount_due_to_thermodynamics"                        unit="kg/m2/s" />
+         <field id="dmidyn"       long_name="sea-ice mass change from dynamics"                       standard_name="tendency_of_sea_ice_amount_due_to_dynamics"                              unit="kg/m2/s" />
+         <field id="dmiopw"       long_name="sea-ice mass change through growth in supercooled open water (frazil)" standard_name="tendency_of_sea_ice_amount_due_to_freezing_in_open_water"  unit="kg/m2/s" />
+         <field id="dmibog"       long_name="sea-ice mass change through basal growth"                standard_name="tendency_of_sea_ice_amount_due_to_congelation_ice_accumulation"          unit="kg/m2/s" />
+         <field id="dmisni"       long_name="sea-ice mass change through snow-to-ice conversion"      standard_name="tendency_of_sea_ice_amount_due_to_snow_conversion"                       unit="kg/m2/s" />
+         <field id="dmtsub"       long_name="snow and sea ice mass change through sublimation"        standard_name="tendency_of_snow_and_ice_amount_due_to_sublimation"                      unit="kg/m2/s" />
+         <field id="dmssub"       long_name="sea-ice mass change through evaporation and sublimation" standard_name="water_evaporation_flux"                                                  unit="kg/m2/s" />
+         <field id="dmisub"       long_name="snow mass change through evaporation or sublimation"     standard_name="surface_snow_sublimation_flux"                                           unit="kg/m2/s" />
+         <field id="dmisum"       long_name="sea-ice mass change through surface melting"             standard_name="tendency_of_sea_ice_amount_due_to_surface_melting"                       unit="kg/m2/s" />
+         <field id="dmibom"       long_name="sea-ice mass change through bottom melting"              standard_name="tendency_of_sea_ice_amount_due_to_basal_melting"                         unit="kg/m2/s" />
+         <field id="dmsspr"       long_name="snow mass change through snow fall"                      standard_name="snowfall_flux"                                                           unit="kg/m2/s" />
+         <field id="dmsmel"       long_name="snow mass change through melt"                           standard_name="surface_snow_melt_flux"                                                  unit="kg/m2/s" />
+         <field id="dmsdyn"       long_name="snow mass change through advection by sea-ice dynamics"  standard_name="tendency_of_snow_mass_due_to_sea_ice_dynamics"                           unit="kg/m2/s" />
+         <field id="dmsssi"       long_name="snow mass change through snow-to-ice conversion"         standard_name="tendency_of_snow_mass_due_to_snow_to_ice_conversion"                     unit="kg/m2/s" />
+
+	 <!-- momentum (rheology) -->
+         <field id="uice_cmip"    long_name="X-component of sea ice velocity"                         standard_name="sea_ice_x_velocity"                    unit="m/s"   > uice    * icemask + 1.e20 * (1.-icemask) </field>
+         <field id="vice_cmip"    long_name="Y-component of sea ice velocity"                         standard_name="sea_ice_y_velocity"                    unit="m/s"   > vice    * icemask + 1.e20 * (1.-icemask) </field>     
+         <field id="icevel_cmip"  long_name="Sea-ice speed"                                           standard_name="sea_ice_speed"                         unit="m/s"   > icevel  * icemask + 1.e20 * (1.-icemask) </field> 
+         <field id="utau_ai_cmip" long_name="X-component of atmospheric stress on sea ice"            standard_name="surface_downward_x_stress"             unit="N/m2"  > utau_ai * icemask + 1.e20 * (1.-icemask) </field>
+         <field id="vtau_ai_cmip" long_name="Y-component of atmospheric stress on sea ice"            standard_name="surface_downward_y_stress"             unit="N/m2"  > vtau_ai * icemask + 1.e20 * (1.-icemask) </field>
+         <field id="dssh_dx"      long_name="Sea-surface tilt term in force balance (x-component)"    standard_name="sea_surface_tilt_force_on_sea_ice_x"   unit="N/m2" />
+         <field id="dssh_dy"      long_name="Sea-surface tilt term in force balance (y-component)"    standard_name="sea_surface_tilt_force_on_sea_ice_y"   unit="N/m2" />
+         <field id="corstrx"      long_name="Coriolis force term in force balance (x-component)"      standard_name="coriolis_force_on_sea_ice_x"           unit="N/m2" />
+         <field id="corstry"      long_name="Coriolis force term in force balance (y-component)"      standard_name="coriolis_force_on_sea_ice_y"           unit="N/m2" />
+         <field id="intstrx"      long_name="Internal stress term in force balance (x-component)"     standard_name="internal_stress_in_sea_ice_x"          unit="N/m2" />
+         <field id="intstry"      long_name="Internal stress term in force balance (y-component)"     standard_name="internal_stress_in_sea_ice_y"          unit="N/m2" />
+
+	 <!-- momentum (advection) -->
+	 <field id="xmtrpice"     long_name="X-component of ice mass transport"                       standard_name="ice_x_transport"                       unit="kg/s" />
+         <field id="ymtrpice"     long_name="Y-component of ice mass transport"                       standard_name="ice_y_transport"                       unit="kg/s" />
+         <field id="xmtrpsnw"     long_name="X-component of snw mass transport"                       standard_name="snw_x_transport"                       unit="kg/s" />
+         <field id="ymtrpsnw"     long_name="Y-component of snw mass transport"                       standard_name="snw_y_transport"                       unit="kg/s" />
+         <field id="xatrp"        long_name="X-component of ice area transport"                       standard_name="area_x_transport"                      unit="m2/s" />
+         <field id="yatrp"        long_name="Y-component of ice area transport"                       standard_name="area_y_transport"                      unit="m2/s" />
+         <field id="xmtrptot"     long_name="X-component of sea-ice mass transport"                   standard_name="sea_ice_x_transport"                   unit="kg/s" > xmtrpice + xmtrpsnw </field>
+         <field id="ymtrptot"     long_name="Y-component of sea-ice mass transport"                   standard_name="sea_ice_y_transport"                   unit="kg/s" > ymtrpice + ymtrpsnw </field>
+
+	 <!-- categories -->
+         <field id="iceconc_cat_cmip"     long_name="Sea-ice area fractions in thickness categories"  standard_name="sea_ice_area_fraction_over_categories" unit=""   grid_ref="grid_T_3D_ncatice" > iceconc_cat * icemask_cat + 1.e20 * (1.-icemask_cat) </field>
+         <field id="icethic_cat_cmip"     long_name="Sea-ice thickness in thickness categories"       standard_name="sea_ice_thickness_over_categories"     unit="m"  grid_ref="grid_T_3D_ncatice" > icethic_cat * icemask_cat + 1.e20 * (1.-icemask_cat) </field>
+         <field id="snwthic_cat_cmip"     long_name="Snow thickness in thickness categories"          standard_name="snow_thickness_over_categories"        unit="m"  grid_ref="grid_T_3D_ncatice" > snwthic_cat * icemask_cat + 1.e20 * (1.-icemask_cat) </field>
+         <field id="iceconc_cat_pct_cmip" long_name="Sea-ice area fractions in thickness categories"  standard_name="sea_ice_area_fraction_over_categories" unit="%"  grid_ref="grid_T_3D_ncatice" > iceconc_cat*100. * icemask_cat + 1.e20 * (1.-icemask_cat) </field>
+	 
+      </field_group>
+
+      <!-- scalar variables -->
       <field_group id="SBC_scalar"  grid_ref="grid_T_2D" >
-         <!-- available with ln_limdiaout -->
-         <field id="ibgfrcvoltop"    long_name="global mean ice/snow forcing at interface ice/snow-atm (volume equivalent ocean volume)"   unit="km3"       />
-         <field id="ibgfrcvolbot"    long_name="global mean ice/snow forcing at interface ice/snow-ocean (volume equivalent ocean volume)" unit="km3"       />
-         <field id="ibgfrctemtop"    long_name="global mean heat on top of ice/snw/ocean-atm "                                             unit="1e20J"     />
-         <field id="ibgfrctembot"    long_name="global mean heat below ice (on top of ocean) "                                             unit="1e20J"     />
-         <field id="ibgfrcsal"       long_name="global mean ice/snow forcing (salt equivalent ocean volume)"                               unit="pss*km3"   />
-         <field id="ibgfrchfxtop"    long_name="global mean heat flux on top of ice/snw/ocean-atm "                                        unit="W/m2"      />
-         <field id="ibgfrchfxbot"    long_name="global mean heat flux below ice (on top of ocean) "                                        unit="W/m2"      />
+         <!-- available with ln_icediaout -->
+         <field id="ibgfrcvoltop"    long_name="global mean ice/snow forcing at interface ice/snow-atm (volume equivalent ocean volume)"   unit="km3"      />
+         <field id="ibgfrcvolbot"    long_name="global mean ice/snow forcing at interface ice/snow-ocean (volume equivalent ocean volume)" unit="km3"      />
+         <field id="ibgfrctemtop"    long_name="global mean heat on top of ice/snw/ocean-atm "                                             unit="1e20J"    />
+         <field id="ibgfrctembot"    long_name="global mean heat below ice (on top of ocean) "                                             unit="1e20J"    />
+         <field id="ibgfrcsal"       long_name="global mean ice/snow forcing (salt equivalent ocean volume)"                               unit="pss*km3"  />
+         <field id="ibgfrchfxtop"    long_name="global mean heat flux on top of ice/snw/ocean-atm "                                        unit="W/m2"     />
+         <field id="ibgfrchfxbot"    long_name="global mean heat flux below ice (on top of ocean) "                                        unit="W/m2"     />
  
-         <field id="ibgvolume"       long_name="drift in ice/snow volume (equivalent ocean volume)"            unit="km3"        />
-         <field id="ibgsaltco"       long_name="drift in ice salt content (equivalent ocean volume)"           unit="pss*km3"    />
-         <field id="ibgheatco"       long_name="drift in ice/snow heat content"                                unit="1e20J"      />
-         <field id="ibgheatfx"       long_name="drift in ice/snow heat flux"                                   unit="W/m2"       />
-
-         <field id="ibgvol_tot"      long_name="global mean ice volume"                                        unit="km3"        />
-         <field id="sbgvol_tot"      long_name="global mean snow volume"                                       unit="km3"        />
-         <field id="ibgarea_tot"     long_name="global mean ice area"                                          unit="km2"        />
-         <field id="ibgsalt_tot"     long_name="global mean ice salt content"                                  unit="1e-3*km3"   />
-         <field id="ibgheat_tot"     long_name="global mean ice heat content"                                  unit="1e20J"      />
-         <field id="sbgheat_tot"     long_name="global mean snow heat content"                                 unit="1e20J"      />
+         <field id="ibgvolume"       long_name="drift in ice/snow volume (equivalent ocean volume)"                                        unit="km3"      />
+         <field id="ibgsaltco"       long_name="drift in ice salt content (equivalent ocean volume)"                                       unit="pss*km3"  />
+         <field id="ibgheatco"       long_name="drift in ice/snow heat content"                                                            unit="1e20J"    />
+         <field id="ibgheatfx"       long_name="drift in ice/snow heat flux"                                                               unit="W/m2"     />
+
+         <field id="ibgvol_tot"      long_name="global mean ice volume"                                                                    unit="km3"      />
+         <field id="sbgvol_tot"      long_name="global mean snow volume"                                                                   unit="km3"      />
+         <field id="ibgarea_tot"     long_name="global mean ice area"                                                                      unit="km2"      />
+         <field id="ibgsalt_tot"     long_name="global mean ice salt content"                                                              unit="1e-3*km3" />
+         <field id="ibgheat_tot"     long_name="global mean ice heat content"                                                              unit="1e20J"    />
+         <field id="sbgheat_tot"     long_name="global mean snow heat content"                                                             unit="1e20J"    />
+
+         <field id="NH_iceextt"      long_name="Sea ice extent North"                   standard_name="sea_ice_extent_n"                   unit="1e6_km2"  />
+         <field id="SH_iceextt"      long_name="Sea ice extent South"                   standard_name="sea_ice_extent_s"                   unit="1e6_km2"  />
+         <field id="NH_icevolu"      long_name="Sea ice volume North"                   standard_name="sea_ice_volume_n"                   unit="1e3_km3"  />
+         <field id="SH_icevolu"      long_name="Sea ice volume South"                   standard_name="sea_ice_volume_s"                   unit="1e3_km3"  />
+         <field id="NH_icearea"      long_name="Sea ice area North"                     standard_name="sea_ice_area_n"                     unit="1e6_km2"  />
+         <field id="SH_icearea"      long_name="Sea ice area South"                     standard_name="sea_ice_area_s"                     unit="1e6_km2"  />
+
+         <field id="strait_mifl"     long_name="Sea ice mass flux through straits"      standard_name="sea_ice_mass_transport_across_line" unit="kg/s"  grid_ref="grid_4strait" />
+         <field id="strait_arfl"     long_name="Sea ice area flux through straits"      standard_name="sea_ice_area_transport_across_line" unit="m2/s"  grid_ref="grid_4strait" />  
+         <field id="strait_msfl"     long_name="Sea ice snow flux through straits"      standard_name="snow_mass_transport_across_line"    unit="kg/s"  grid_ref="grid_4strait" />
+
       </field_group>
   
@@ -176,8 +288,151 @@
       
       <field_group id="myvarICE" >
-         <field field_ref="icethic_cea"      name="sithic"     long_name="sea_ice_thickness"        />
+         <field field_ref="icethic"          name="sithic"  />
          <field field_ref="icevolu"          name="sivolu"  />
          <field field_ref="iceconc"          name="siconc"  />
       </field_group>    
-      
+
+      <field_group id="ICE_globalbudget">
+
+    	<field field_ref="ibgvol_tot"     grid_ref="grid_1point"  name="ibgvol_tot"   />
+	<field field_ref="sbgvol_tot"     grid_ref="grid_1point"  name="sbgvol_tot"   />
+    	<field field_ref="ibgarea_tot"    grid_ref="grid_1point"  name="ibgarea_tot"  />
+    	<field field_ref="ibgsalt_tot"    grid_ref="grid_1point"  name="ibgsalt_tot"  />
+    	<field field_ref="ibgheat_tot"    grid_ref="grid_1point"  name="ibgheat_tot"  />
+    	<field field_ref="sbgheat_tot"    grid_ref="grid_1point"  name="sbgheat_tot"  />
+
+     	<field field_ref="ibgvolume"      grid_ref="grid_1point"  name="ibgvolume"    />
+    	<field field_ref="ibgsaltco"      grid_ref="grid_1point"  name="ibgsaltco"    />
+    	<field field_ref="ibgheatco"      grid_ref="grid_1point"  name="ibgheatco"    />
+        <field field_ref="ibgheatfx"      grid_ref="grid_1point"  name="ibgheatfx"    />
+
+    	<field field_ref="ibgfrcvoltop"   grid_ref="grid_1point"  name="ibgfrcvoltop" />
+    	<field field_ref="ibgfrcvolbot"   grid_ref="grid_1point"  name="ibgfrcvolbot" />
+    	<field field_ref="ibgfrctemtop"   grid_ref="grid_1point"  name="ibgfrctemtop" />
+    	<field field_ref="ibgfrctembot"   grid_ref="grid_1point"  name="ibgfrctembot" />
+    	<field field_ref="ibgfrcsal"      grid_ref="grid_1point"  name="ibgfrcsal"    />
+        <field field_ref="ibgfrchfxtop"   grid_ref="grid_1point"  name="ibgfrchfxtop" />
+        <field field_ref="ibgfrchfxbot"   grid_ref="grid_1point"  name="ibgfrchfxbot" />
+
+      </field_group>
+
+
+      <!--============================-->
+      <!-- SIMIP sea ice field groups -->
+      <!--     Notz et al 2016        -->
+      <!--============================-->
+
+      <!-- SIMIP monthly scalar variables -->
+      <field_group id="SImon_scalars">
+        <!-- Integrated quantities -->
+        <field field_ref="NH_iceextt"     grid_ref="grid_1point"  name="siextentn"    />
+        <field field_ref="SH_iceextt"     grid_ref="grid_1point"  name="siextents"    />
+        <field field_ref="NH_icevolu"     grid_ref="grid_1point"  name="sivoln"       />
+        <field field_ref="SH_icevolu"     grid_ref="grid_1point"  name="sivols"       />
+        <field field_ref="NH_icearea"     grid_ref="grid_1point"  name="siarean"      />
+        <field field_ref="SH_icearea"     grid_ref="grid_1point"  name="siareas"      />
+      </field_group>
+
+      <!-- SIMIP daily fields -->
+      <field_group id="SIday_fields"> 
+          <field field_ref="icepres"          name="sitimefrac"   /> 
+          <field field_ref="iceconc_pct"      name="siconc"       /> 
+          <field field_ref="icethic_cmip"     name="sithick"      default_value="1.0e20" detect_missing_value="true" operation="average" /> 
+          <field field_ref="snwthic_cmip"     name="sisnthick"    default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="icettop_cmip"     name="sitemptop"    default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="uice_cmip"        name="siu"          default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="vice_cmip"        name="siv"          default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="icevel_cmip"      name="sispeed"      default_value="1.0e20" detect_missing_value="true" operation="average" />
+      </field_group>
+
+      <!-- SIMIP monthly fields -->
+      <field_group id="SImon_fields">
+          <!-- Sea-ice state variables -->
+          <field field_ref="icepres"          name="sitimefrac"   />
+          <field field_ref="iceconc_pct"      name="siconc"       />
+          <field field_ref="icemass_cmip"     name="simass"       default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="icethic_cmip"     name="sithick"      default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="icevolu"          name="sivol"        />
+          <field field_ref="snwmass_cmip"     name="sisnmass"     default_value="1.0e20" detect_missing_value="true" operation="average" /> 
+          <field field_ref="snwthic_cmip"     name="sisnthick"    default_value="1.0e20" detect_missing_value="true" operation="average" />
+   
+          <!-- category-dependent fields -->
+          <field field_ref="iceconc_cat_pct_cmip" name="siitdconc"    default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="icethic_cat_cmip"     name="siitdthick"   default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="snwthic_cat_cmip"     name="siitdsnthick" default_value="1.0e20" detect_missing_value="true" operation="average" />
+
+          <!-- additional state variables-->
+          <field field_ref="icettop_cmip"     name="sitemptop"    default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="icetsni_cmip"     name="sitempsnic"   default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="icetbot_cmip"     name="sitempbot"    default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="iceage_cmip"      name="siage"        default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="icesalm"          name="sisaltmass"   />
+          <field field_ref="icesalt_cmip"     name="sisali"       default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="icefrb_cmip"      name="sifb"         default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="icehc_cmip"       name="sihc"         default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="snwhc_cmip"       name="sisnhc"       default_value="1.0e20" detect_missing_value="true" operation="average" />
+
+          <!-- freshwater fluxes -->
+          <field field_ref="vfxice_cmip"      name="siflfwbot"    default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="vfxsum_cmip"      name="siflfwdrain"  default_value="1.0e20" detect_missing_value="true" operation="average" />
+
+          <!-- area balance -->
+          <field field_ref="afxthd"           name="sidconcth"    />
+          <field field_ref="afxdyn"           name="sidconcdyn"   />
+
+          <!-- mass balance -->
+          <field field_ref="dmithd"           name="sidmassth"        />
+          <field field_ref="dmidyn"           name="sidmassdyn"       />
+          <field field_ref="dmiopw"           name="sidmassgrowthwat" />
+          <field field_ref="dmibog"           name="sidmassgrowthbot" />
+          <field field_ref="dmisni"           name="sidmasssi"        />
+          <field field_ref="dmisub"           name="sidmassevapsubl"  />
+          <field field_ref="dmisum"           name="sidmassmelttop"   />
+          <field field_ref="dmibom"           name="sidmassmeltbot"   />
+          <field field_ref="dmsspr"           name="sndmasssnf"       />
+          <field field_ref="dmsmel"           name="sndmassmelt"      />
+          <field field_ref="dmssub"           name="sndmasssubl"      />
+          <field field_ref="dmsdyn"           name="sndmassdyn"       />
+          <field field_ref="dmsssi"           name="sndmasssi"        />
+
+          <!-- heat balance -->
+          <field field_ref="hfxsensib"        name="siflsensupbot"    default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="hfxcndtop"        name="siflcondtop"      default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="hfxcndbot"        name="siflcondbot"      default_value="1.0e20" detect_missing_value="true" operation="average" />
+
+          <!-- salt balance -->
+          <field field_ref="sfxice_cmip"      name="siflsaltbot"      default_value="1.0e20" detect_missing_value="true" operation="average" />
+
+          <!-- sea-ice dynamics -->
+          <field field_ref="uice_cmip"        name="siu"              default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="vice_cmip"        name="siv"              default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="icevel_cmip"      name="sispeed"          default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="utau_ai_cmip"     name="sistrxdtop"       default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="vtau_ai_cmip"     name="sistrydtop"       default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="utau_oi"          name="sistrxubot"       default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="vtau_oi"          name="sistryubot"       default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="icestr"           name="sicompstren"      default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="dssh_dx"          name="siforcetiltx"     default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="dssh_dy"          name="siforcetilty"     default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="corstrx"          name="siforcecoriolx"   default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="corstry"          name="siforcecorioly"   default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="intstrx"          name="siforceintstrx"   default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="intstry"          name="siforceintstry"   default_value="1.0e20" detect_missing_value="true" operation="average" />
+          <field field_ref="xmtrptot"         name="sidmasstranx"     />
+          <field field_ref="ymtrptot"         name="sidmasstrany"     />
+          <field field_ref="normstr"          name="sistresave"       default_value="1.0e20" detect_missing_value="true" operation="instant" />
+          <field field_ref="sheastr"          name="sistremax"        default_value="1.0e20" detect_missing_value="true" operation="instant" />
+          <field field_ref="icediv"           name="sidivvel"         default_value="1.0e20" detect_missing_value="true" operation="instant" />
+          <field field_ref="iceshe"           name="sishevel"         default_value="1.0e20" detect_missing_value="true" operation="instant" />
+
+          <!-- sea ice fluxes across straits: 2D arrays to be post-processed  -->
+          <field field_ref="xmtrpice"         name="simassacrossline_x" />
+          <field field_ref="ymtrpice"         name="simassacrossline_y" />
+          <field field_ref="xmtrpsnw"         name="snmassacrossline_x" />
+          <field field_ref="ymtrpsnw"         name="snmassacrossline_y" />
+          <field field_ref="xatrp"            name="siareaacrossline_x" />
+          <field field_ref="yatrp"            name="siareaacrossline_y" />
+
+      </field_group>
+
    </field_definition>
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/field_def_nemo-opa.xml
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/field_def_nemo-opa.xml	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/field_def_nemo-opa.xml	(revision 9019)
@@ -182,6 +182,48 @@
       </field_group>
 
+      <!-- OSMOSIS variables (available with ln_zdfosm=.true.) -->
+
+      <field_group id="OSMOSIS_T" grid_ref="grid_T_2D">
+         <field id="zwth0"               long_name="surface non-local temperature flux"       unit="deg m/s" />
+         <field id="zws0"                long_name="surface non-local salinity flux"          unit="psu m/s" />
+         <field id="hbl"                 long_name="boundary layer depth"                     unit="m"       />
+         <field id="hbli"                long_name="initial boundary layer depth"             unit="m"       />
+         <field id="dstokes"             long_name="stokes drift  depth scale"                unit="m"       />
+         <field id="zustke"              long_name="magnitude of stokes drift  at T-points"   unit="m/s"     />
+         <field id="zwstrc"              long_name="convective velocity scale"                unit="m/s"     />
+         <field id="zwstrl"              long_name="langmuir velocity scale"                  unit="m/s"     />
+         <field id="zustar"              long_name="friction velocity"                        unit="m/s"     />
+         <field id="zhbl"                long_name="boundary layer depth"                     unit="m"       />
+         <field id="zhml"                long_name="mixed layer depth"                        unit="m"       />
+         <field id="wind_wave_abs_power" long_name="\rho |U_s| x u*^2"                        unit="mW"      />
+         <field id="wind_wave_power"     long_name="U_s \dot  tau"                            unit="mW"      />
+         <field id="wind_power"          long_name="\rho  u*^3"                               unit="mW"      />
+
+         <!-- extra OSMOSIS diagnostics -->
+         <field id="zwthav"              long_name="av turb flux of T in ml"                  unit="deg m/s" />
+         <field id="zt_ml"               long_name="av T in ml"                               unit="deg"     />
+         <field id="zwth_ent"            long_name="entrainment turb flux of T"               unit="deg m/s" />
+         <field id="zhol"                long_name="Hoenekker number"                         unit="#"       />
+         <field id="zdh"                 long_name="Pycnocline  depth - grid"                 unit=" m"      />
+      </field_group>
+
+      <field_group id="OSMOSIS_W" grid_ref="grid_W_3D" operation="instant" >
+         <field id="ghamt"       long_name="non-local temperature flux"                       unit="deg m/s" />
+         <field id="ghams"       long_name="non-local salinity flux"                          unit="psu m/s" />
+         <field id="zdtdz_pyc"   long_name="Pycnocline temperature gradient"                  unit=" deg/m"  />
+      </field_group>
+
+      <field_group id="OSMOSIS_U" grid_ref="grid_U_2D" >
+         <field id="ghamu"       long_name="non-local u-momentum flux"   grid_ref="grid_U_3D" unit="m^2/s^2" />
+         <field id="us_x"        long_name="i component of Stokes drift"                      unit="m/s"     />
+      </field_group>
+
+      <field_group id="OSMOSIS_V" grid_ref="grid_V_2D" >
+         <field id="ghamv"       long_name="non-local v-momentum flux"   grid_ref="grid_V_3D" unit="m^2/s^2" />
+         <field id="us_y"        long_name="j component of Stokes drift"                      unit="m/s"     />
+      </field_group>
+      
       <!-- SBC -->
-      
+
       <field_group id="SBC" grid_ref="grid_T_2D" > <!-- time step automaticaly defined based on nn_fsbc -->
          <field id="empmr"        long_name="Net Upward Water Flux"                standard_name="water_flux_out_of_sea_ice_and_sea_water"                              unit="kg/m2/s"   />
@@ -226,9 +268,12 @@
 
          <!-- *_oce variables available with ln_blk_clio or ln_blk_core -->
-         <field id="qlw_oce"      long_name="Longwave Downward Heat Flux over open ocean"  standard_name="surface_net_downward_longwave_flux"   unit="W/m2"  />
-         <field id="qsb_oce"      long_name="Sensible Downward Heat Flux over open ocean"  standard_name="surface_downward_sensible_heat_flux"  unit="W/m2"  />
-         <field id="qla_oce"      long_name="Latent Downward Heat Flux over open ocean"    standard_name="surface_downward_latent_heat_flux"    unit="W/m2"  />
-         <field id="qemp_oce"     long_name="Downward Heat Flux from E-P over open ocean"                                                       unit="W/m2"  />
-         <field id="taum_oce"     long_name="wind stress module over open ocean"           standard_name="magnitude_of_surface_downward_stress" unit="N/m2"  />
+         <field id="qlw_oce"      long_name="Longwave Downward Heat Flux over open ocean"  standard_name="surface_net_downward_longwave_flux"                 unit="W/m2"  />
+         <field id="qsb_oce"      long_name="Sensible Downward Heat Flux over open ocean"  standard_name="surface_downward_sensible_heat_flux"                unit="W/m2"  />
+         <field id="qla_oce"      long_name="Latent Downward Heat Flux over open ocean"    standard_name="surface_downward_latent_heat_flux"                  unit="W/m2"  />
+         <field id="qt_oce"       long_name="total flux at ocean surface"                  standard_name="surface_downward_heat_flux_in_sea_water"            unit="W/m2"  />
+         <field id="qsr_oce"      long_name="solar heat flux at ocean surface"             standard_name="net_downward_shortwave_flux_at_sea_water_surface"   unit="W/m2"  />
+         <field id="qns_oce"      long_name="non-solar heat flux at ocean surface (including E-P)"                                                            unit="W/m2"  />
+         <field id="qemp_oce"     long_name="Downward Heat Flux from E-P over open ocean"                                                                     unit="W/m2"  />
+         <field id="taum_oce"     long_name="wind stress module over open ocean"           standard_name="magnitude_of_surface_downward_stress"               unit="N/m2"  />
 
          <!-- available key_oasis3 -->
@@ -299,18 +344,20 @@
          <field id="uoces"        long_name="ocean transport along i-axis times salinity (CRS)"                                                  unit="1e-3*m/s"   grid_ref="grid_U_3D" />
 
-         <!-- u-eddy coefficients (ldftra) -->
+         <!-- u-eddy diffusivity coefficients (available if ln_traldf_NONE=F) -->
          <field id="ahtu_2d"      long_name=" surface u-eddy diffusivity coefficient"   unit="m2/s or m4/s" />
          <field id="ahtu_3d"      long_name=" 3D u-EIV coefficient"                     unit="m2/s or m4/s"      grid_ref="grid_U_3D"/>
+         <!-- u-eiv diffusivity coefficients (available if ln_ldfeiv=F) -->
          <field id="aeiu_2d"      long_name=" surface u-EIV coefficient"                unit="m2/s" />
          <field id="aeiu_3d"      long_name=" 3D u-EIV coefficient"                     unit="m2/s"              grid_ref="grid_U_3D"/>
 
-         <!-- variables available with MLE -->
+         <!-- variables available with MLE (ln_mle=T) -->
          <field id="psiu_mle"     long_name="MLE streamfunction along i-axis"   unit="m3/s"   grid_ref="grid_U_3D" />
 
-         <!-- uoce_eiv: available EIV -->
+         <!-- uoce_eiv: available EIV (ln_ldfeiv=T and ln_ldfeiv_dia=T) -->
          <field id="uoce_eiv"     long_name="EIV ocean current along i-axis"   standard_name="bolus_sea_water_x_velocity"   unit="m/s"   grid_ref="grid_U_3D" />
 
-         <!-- uoce_eiv: available with key_trabbl -->
+         <!-- uoce_bbl: available with ln_trabbl=T and nn_bbl_adv=1 -->
          <field id="uoce_bbl"     long_name="BBL ocean current along i-axis"    unit="m/s"  />
+         <!-- ahu_bbl : available with ln_trabbl=T and nn_bbl_ldf=1 -->
          <field id="ahu_bbl"      long_name="BBL diffusive flux along i-axis"   unit="m3/s" />
 
@@ -347,18 +394,20 @@
          <field id="voces"        long_name="ocean transport along j-axis times salinity (CRS)"                                                  unit="1e-3*m/s"   grid_ref="grid_V_3D" />
 
-         <!-- v-eddy coefficients (ldftra, ldfdyn) -->
+         <!-- v-eddy diffusivity coefficients (available if ln_traldf_NONE=F) -->
          <field id="ahtv_2d"      long_name=" surface v-eddy diffusivity coefficient"     unit="m2/s or (m4/s)^1/2" />
          <field id="ahtv_3d"      long_name=" 3D v-eddy diffusivity coefficient"          unit="m2/s or (m4/s)^1/2"           grid_ref="grid_V_3D"/>
+         <!-- v-eiv diffusivity coefficients (available if ln_ldfeiv=F) -->
          <field id="aeiv_2d"      long_name=" surface v-EIV coefficient"                  unit="m2/s" />
          <field id="aeiv_3d"      long_name=" 3D v-EIV coefficient"                       unit="m2/s"                         grid_ref="grid_V_3D" />
 
-         <!-- variables available with MLE -->
+         <!-- variables available with MLE (ln_mle=T) -->
          <field id="psiv_mle"     long_name="MLE streamfunction along j-axis"   unit="m3/s"   grid_ref="grid_V_3D" />
 
-         <!-- voce_eiv: available with EIV -->
+         <!-- voce_eiv: available EIV (ln_ldfeiv=T and ln_ldfeiv_dia=T)  -->
          <field id="voce_eiv"     long_name="EIV ocean current along j-axis"   standard_name="bolus_sea_water_y_velocity"   unit="m/s"   grid_ref="grid_V_3D" />
 
-         <!-- voce_eiv: available with key_trabbl -->
+         <!-- voce_bbl: available with ln_trabbl=T and nn_bbl_adv=1 -->
          <field id="voce_bbl"     long_name="BBL ocean current along j-axis"    unit="m/s"  />
+         <!-- ahu_bbl : available with ln_trabbl=T and nn_bbl_ldf=1 -->
          <field id="ahv_bbl"      long_name="BBL diffusive flux along j-axis"   unit="m3/s" />
 
@@ -387,5 +436,5 @@
          <field id="wocetr_eff"   long_name="effective ocean vertical transport"                                               unit="m3/s" />
 
-         <!-- woce_eiv: available with EIV -->
+         <!-- woce_eiv: available with EIV  (ln_ldfeiv=T and ln_ldfeiv_dia=T)  -->
          <field id="woce_eiv"     long_name="EIV ocean vertical velocity"   standard_name="bolus_upward_sea_water_velocity"   unit="m/s" />
 
@@ -394,5 +443,5 @@
          <field id="avm"          long_name="vertical eddy viscosity"     standard_name="ocean_vertical_momentum_diffusivity"   unit="m2/s" />
 
-         <!-- avs: available with key_zdfddm -->
+         <!-- avs: /= avt with ln_zdfddm=T -->
          <field id="avs"          long_name="salt vertical eddy diffusivity"   standard_name="ocean_vertical_salt_diffusivity"   unit="m2/s" />
          <field id="logavs"       long_name="logarithm of salt vertical eddy diffusivity"   standard_name="ocean_vertical_heat_diffusivity"       unit="m2/s" />
@@ -402,13 +451,10 @@
          <field id="avm_evd"      long_name="convective enhancement of vertical viscosity"     standard_name="ocean_vertical_momentum_diffusivity_due_to_convection"   unit="m2/s" />
 
-         <!-- avt_tide: available with key_zdftmx -->
-         <field id="av_tide"      long_name="tidal vertical diffusivity"   standard_name="ocean_vertical_tracer_diffusivity_due_to_tides"   unit="m2/s" />
-
-         <!-- variables available with key_zdftmx_new -->
-         <field id="av_ratio"     long_name="S over T diffusivity ratio"            standard_name="salinity_over_temperature_diffusivity_ratio"                     unit="1"    />
-         <field id="av_wave"      long_name="wave-induced vertical diffusivity"     standard_name="ocean_vertical_tracer_diffusivity_due_to_internal_waves"         unit="m2/s" />
-         <field id="bflx_tmx"     long_name="wave-induced buoyancy flux"            standard_name="buoyancy_flux_due_to_internal_waves"                             unit="W/kg" />
-         <field id="pcmap_tmx"    long_name="power consumed by wave-driven mixing"  standard_name="vertically_integrated_power_consumption_by_wave_driven_mixing"   unit="W/m2"      grid_ref="grid_W_2D" />
-         <field id="emix_tmx"     long_name="power density available for mixing"    standard_name="power_available_for_mixing_from_breaking_internal_waves"         unit="W/kg" />
+         <!-- avt_tide: available with ln_zdfiwm=T -->
+         <field id="av_ratio"     long_name="S over T diffusivity ratio"                     standard_name="salinity_over_temperature_diffusivity_ratio"                     unit="1"    />
+         <field id="av_wave"      long_name="internal wave-induced vertical diffusivity"     standard_name="ocean_vertical_tracer_diffusivity_due_to_internal_waves"         unit="m2/s" />
+         <field id="bflx_iwm"     long_name="internal wave-induced buoyancy flux"            standard_name="buoyancy_flux_due_to_internal_waves"                             unit="W/kg" />
+         <field id="pcmap_iwm"    long_name="power consumed by wave-driven mixing"           standard_name="vertically_integrated_power_consumption_by_wave_driven_mixing"   unit="W/m2"      grid_ref="grid_W_2D" />
+         <field id="emix_iwm"     long_name="power density available for mixing"             standard_name="power_available_for_mixing_from_breaking_internal_waves"         unit="W/kg" />
 
          <!-- variables available with diaar5 -->   
@@ -704,9 +750,15 @@
        <field id="KE"            long_name="kinetic energy: u(n)*u(n+1)/2"                    unit="W/s^2"                        />   
 
+      <!-- variables available when explicit lateral mixing is used (ln_dynldf_NONE=F) -->
+      <field id="dispkexyfo"    long_name="KE-trend: lateral  mixing induced dissipation"   standard_name="ocean_kinetic_energy_dissipation_per_unit_area_due_to_xy_friction"                   unit="W/m^2" grid_ref="grid_T_2D" />   
+      <field id="dispkevfo"     long_name="KE-trend: vertical mixing induced dissipation"   standard_name="ocean_kinetic_energy_dissipation_per_unit_area_due_to_vertical_friction"             unit="W/m^2" grid_ref="grid_T_2D" />   
+      <!-- variables available with ln_traadv_eiv=T and ln_diaeiv=T -->
+      <field id="eketrd_eiv"    long_name="EKE-trend due to parameterized eddy advection"   standard_name="tendency_of_ocean_eddy_kinetic_energy_content_due_to_parameterized_eddy_advection"   unit="W/m^2" grid_ref="grid_T_2D" />   
+
        <!-- variables available with ln_PE_trd -->
        <field id="petrd_xad"     long_name="pe-trend: i-advection"                unit="W/m^3"                        />
        <field id="petrd_yad"     long_name="pe-trend: j-advection"                unit="W/m^3"                        />
        <field id="petrd_zad"     long_name="pe-trend: k-advection"                unit="W/m^3"                        />
-       <field id="petrd_sad"     long_name="pe-trend: surface adv. (linssh true)"      unit="W/m^3"   grid_ref="grid_T_2D" />
+       <field id="petrd_sad"     long_name="pe-trend: surface adv. (linssh true)" unit="W/m^3"   grid_ref="grid_T_2D" />
        <field id="petrd_ldf"     long_name="pe-trend: lateral  diffusion"         unit="W/m^3"                        />
        <field id="petrd_zdf"     long_name="pe-trend: vertical diffusion"         unit="W/m^3"                        />
Index: anches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/namelist_ice_lim2_ref
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/namelist_ice_lim2_ref	(revision 9018)
+++ 	(revision )
@@ -1,131 +1,0 @@
-!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-!! NEMO/LIM-2 : 1 - dynamics/advection/thermo          (namicerun)
-!! namelists    2 - ice intialisation                  (namiceini)
-!!              3 - ice dynamic                        (namicedyn)
-!!              4 - ice advection                      (namicetrp)
-!!              5 - thermodynamic                      (namicethd)
-!!              6 - ice damping                        (namice_dmp)
-!!              7 - ice diagnostics                    (namicedia)
-!!              8 - ice outputs                        (namiceout)
-!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-
-!-----------------------------------------------------------------------
-&namicerun     !   Share parameters for dynamics/advection/thermo
-!-----------------------------------------------------------------------
-   cn_icerst_in  = "restart_ice_in"   !  suffix of ice restart name (input)
-   cn_icerst_indir = "."              !  directory from which to read input ice restarts
-   cn_icerst_out = "restart_ice"      !  suffix of ice restart name (output)
-   cn_icerst_outdir = "."             !  directory in which to write output ice restarts
-   ln_limdyn     = .true.             !  ice dynamics (T) or thermodynamics only (F)
-   ln_limdmp     = .false.            !  restoring ice thickness and fraction leads   (T => fill  namice_dmp)
-   acrit         = 1.0e-06 , 1.0e-06  !  minimum lead fraction in the Northern & Southern Hemispheres
-   hsndif        =  0.e0              !  computation of temperature in snow (=0.0) or not
-   hicdif        =  0.e0              !  computation of temperature in ice  (=0.0) or not (=9999.0)
-/
-!-----------------------------------------------------------------------
-&namiceini     !   ice initialisation
-!-----------------------------------------------------------------------
-   ln_limini   = .false.   !  read the initial state in 'Ice_initialization.nc' (T) or not (F)
-   ttest       =  2.0      !  threshold water temperature for initial sea ice
-   hninn       =  0.5      !  initial snow thickness in the north
-   hginn       =  3.0      !  initial ice  thickness in the north
-   alinn       =  0.05     !  initial leads area     in the north
-   hnins       =  0.1      !  same  three parameter  in the south
-   hgins       =  1.0      !        "                 "     south   
-   alins       =  0.1      !        "                 "     south
-/
-!-----------------------------------------------------------------------
-&namicedyn     !   ice dynamic
-!-----------------------------------------------------------------------
-   epsd        =   1.0e-20 !  tolerance parameter
-   alpha       =   0.5     !  coefficient for semi-implicit coriolis
-   dm          =   0.6e+03 !  diffusion constant for dynamics
-   nbiter      =   1       !  number of sub-time steps for relaxation
-   nbitdr      = 100       !  maximum number of iterations for relaxation
-   om          =   0.5     !  relaxation constant 
-   resl        =   5.0e-05 !  maximum value for the residual of relaxation
-   cw          =   5.0e-03 !  drag coefficient for oceanic stress
-   angvg       =   0.0     !  turning angle for oceanic stress
-   pstar       =   1.0e+04 !  1st bulk-rheology parameter
-   c_rhg       =  20.0     !  2nd bulk-rhelogy parameter
-   etamn       =   0.0e+07 !  minimun value for viscosity
-   rn_creepl   =   1.0e-08 !  creep limit
-   rn_ecc      =   2.0     !  eccentricity of the elliptical yield curve
-   ahi0        = 350.e0    !  horizontal eddy diffusivity coefficient for sea-ice [m2/s]
-   nn_nevp     =   120     !  number of EVP subcycling iterations
-   telast      =   9600    !  timescale for EVP elastic waves
-   alphaevp    =   1.0     !  coefficient for the solution of EVP int. stresses
-/
-!-----------------------------------------------------------------------
-&namicetrp     !   ice transport
-!-----------------------------------------------------------------------
-   bound       =   0.0     !  boundary conditions (=0. no-slip, =1. free-slip)
-/
-!-----------------------------------------------------------------------
-&namicethd     !   ice thermodynamic
-!-----------------------------------------------------------------------
-   hmelt       = -0.15     !  maximum melting at the bottom
-   hiccrit     = 0.3 , 0.3 !  ice thickness for lateral accretion in the Northern (Southern) Hemisphere
-   !                       !  (caution 1.0, 1.0 best value to be used!!! (gilles G.))
-   hicmin      = 0.2       !  ice thickness corr. to max. energy stored in brine pocket
-   hiclim      = 0.05      !  minimum ice thickness
-   amax        = 0.999     !  maximum lead fraction
-   swiqst      = 1.        !  energy stored in brine pocket (=1) or not (=0)	
-   sbeta       = 1.        !  numerical caracteritic of the scheme for diffusion in ice
-                           !        Cranck-Nicholson (=0.5), implicit (=1), explicit (=0)
-   parlat      = 0.0       !  percentage of energy used for lateral ablation
-   hakspl      = 0.5       !  slope of distr. for Hakkinen-Mellor's lateral melting
-   hibspl      = 0.5       !  slope of distribution for Hibler's lateral melting
-   exld        = 2.0       !  exponent for leads-closure rate
-   hakdif      = 1.0       !  coefficient for diffusions of ice and snow
-   thth        = 0.2       !  threshold thickness for comp. of eq. thermal conductivity
-   hnzst       = 0.1       !  thickness of the surf. layer in temp. computation
-   parsub      = 1.0       !  switch for snow sublimation or not
-   alphs       = 1.0       !  coefficient for snow density when snow ice formation
-/
-!-----------------------------------------------------------------------
-&namice_dmp    !   damping of sea ice alone open boundaries
-!              !   (hard coded damping area: check if it fit your config)
-!-----------------------------------------------------------------------
-!              !  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_hicif    = 'ice_damping'  ,  -1.              , 'hicif'  ,   .true.     , .true. , 'yearly'  , ''       , ''       ,    ''
-   sn_frld     = 'ice_damping'  ,  -1.              , 'frld'   ,   .true.     , .true. , 'yearly'  , ''       , ''       ,    ''
-!
-   cn_dir      = './'      !  root directory for the location of the runoff files
-/
-!-----------------------------------------------------------------------
-&namicedia     !   ice diagnostics
-!-----------------------------------------------------------------------
-   fmtinf      = '1PE13.5' !  format of the output values
-   nfrinf      =  4        !  number of variables written in one line
-   ntmoy       =  1        !  instantaneous values of ice evolution or averaging
-   ninfo       =  1        !  frequency of ouputs on file ice_evolu in case of averaging
-/
-!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
-&namiceout     !   parameters for outputs
-!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
-!              !         title of the field           !  name     !   units   !  save  ! multipl. ! additive !
-!              !                                      !           !           ! or not !  factor  !  factor  !
-   field_1     = 'Snow thickness                     ', 'isnowthi', 'm       ',    1   ,  1.0     ,    0.0
-   field_2     = 'Ice thickness                      ', 'iicethic', 'm       ',    1   ,  1.0     ,    0.0
-   field_3     = 'Ice produced                       ', 'iiceprod', 'm/kt    ',    1   ,  1.0     ,    0.0
-   field_4     = 'Ice concentration                  ', 'ileadfra', '%       ',    1   , -1.0     ,    1.0
-   field_5     = 'Ice temperature                    ', 'iicetemp', 'C       ',    1   ,  1.0     , -273.15
-   field_6     = 'Oceanic flux at the ice base       ', 'ioceflxb', 'w/m2    ',    1   ,  1.0     ,    0.0
-   field_7     = 'Ice velocity u                     ', 'iicevelu', 'm/s     ',    1   ,  1.0     ,    0.0
-   field_8     = 'Ice velocity v                     ', 'iicevelv', 'm/s     ',    1   ,  1.0     ,    0.0
-   field_9     = 'Sea surface temperature            ', 'isstempe', 'C       ',    1   ,  1.0     , -273.15
-   field_10    = 'Sea surface salinity               ', 'isssalin', 'PSU     ',    1   ,  1.0     ,    0.0
-   field_11    = 'Total flux at ocean surface        ', 'iocetflx', 'w/m2    ',    1   ,  1.0     ,    0.0
-   field_12    = 'Solar flux at ocean surface        ', 'iocesflx', 'w/m2    ',    1   ,  1.0     ,    0.0
-   field_13    = 'Non-solar flux at ocean surface    ', 'iocwnsfl', 'w/m2    ',    1   ,  1.0     ,    0.0
-   field_14    = 'Salt flux at ocean surface         ', 'iocesafl', 'kg/m2/kt',    1   ,  1.0     ,    0.0
-   field_15    = 'Wind stress u                      ', 'iocestru', 'Pa      ',    1   ,  1.0     ,    0.0
-   field_16    = 'Wind stress v                      ', 'iocestrv', 'Pa      ',    1   ,  1.0     ,    0.0 
-   field_17    = 'Solar flux at ice/ocean surface    ', 'iicesflx', 'w/m2    ',    1   ,  1.0     ,    0.0
-   field_18    = 'Non-solar flux at ice/ocean surface', 'iicenflx', 'w/m2    ',    1   ,  1.0     ,    0.0
-   field_19    = 'Snow precipitation                 ', 'isnowpre', 'kg/day  ',    1   ,  1.0     ,    0.0
-!
-   noumef      =   19      !  number of fields
-/      
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/namelist_ice_lim3_ref
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/namelist_ice_lim3_ref	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/namelist_ice_lim3_ref	(revision 9019)
@@ -1,187 +1,228 @@
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-!! LIM3 namelist:  
-!!              1 - Generic parameters                 (namicerun)
-!!              2 - Diagnostics                        (namicediag)
-!!              3 - Ice initialization                 (namiceini)
-!!              4 - Ice discretization                 (namiceitd)
-!!              5 - Ice dynamics and transport         (namicedyn)
-!!              6 - Ice diffusion                      (namicehdf)
-!!              7 - Ice thermodynamics                 (namicethd)
-!!              8 - Ice salinity                       (namicesal)
-!!              9 - Ice mechanical redistribution      (namiceitdme)
+!! ESIM namelist:  
+!!              1 - Generic parameters                 (nampar)
+!!              2 - Ice thickness discretization       (namitd)
+!!              3 - Ice dynamics                       (namdyn)
+!!              4 - Ice ridging/rafting                (namdyn_rdgrft)
+!!              5 - Ice rheology                       (namdyn_rhg)
+!!              6 - Ice advection                      (namdyn_adv)
+!!              7 - Ice surface forcing                (namforcing)
+!!              8 - Ice thermodynamics                 (namthd)
+!!              9 - Ice heat diffusion                 (namthd_zdf)
+!!             10 - Ice lateral melting                (namthd_da)
+!!             11 - Ice growth in open water           (namthd_do)
+!!             12 - Ice salinity                       (namthd_sal)
+!!             13 - Ice melt ponds                     (namthd_pnd)
+!!             14 - Ice initialization                 (namini)
+!!             15 - Ice/snow albedos                   (namalb)
+!!             16 - Ice diagnostics                    (namdia)
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 !
 !------------------------------------------------------------------------------
-&namicerun     !   Generic parameters
-!------------------------------------------------------------------------------
-   jpl              =    5          !  number of ice  categories
-   nlay_i           =    2          !  number of ice  layers
-   nlay_s           =    1          !  number of snow layers (only 1 is working)
-   rn_amax_n        =   0.997       !  maximum tolerated ice concentration NH
-   rn_amax_s        =   0.997       !  maximum tolerated ice concentration SH
-   cn_icerst_in     = "restart_ice" !  suffix of ice restart name (input)
-   cn_icerst_out    = "restart_ice" !  suffix of ice restart name (output)
-   cn_icerst_indir  = "."           !  directory to read   input ice restarts
-   cn_icerst_outdir = "."           !  directory to write output ice restarts
-   ln_limthd        =  .true.       !  ice thermo   (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-   ln_limdyn        =  .true.       !  ice dynamics (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-   nn_limdyn        =   2           !     (ln_limdyn=T) switch for ice dynamics   
-                                    !      2: total
-                                    !      1: advection only (no diffusion, no ridging/rafting)
-                                    !      0: advection only (as 1 but with prescribed velocity, bypass rheology)
-   rn_uice          =   0.00001     !     (nn_limdyn=0) ice u-velocity
-   rn_vice          =  -0.00001     !     (nn_limdyn=0) ice v-velocity
-/
-!------------------------------------------------------------------------------
-&namicediag    !   Diagnostics
-!------------------------------------------------------------------------------
-   ln_limdiachk   =  .false.        !  check online the heat, mass & salt budgets (T) or not (F)
-   ln_limdiahsb   =  .false.        !  output the heat, mass & salt budgets (T) or not (F)
-   ln_limctl      =  .false.        !  ice points output for debug (T or F)
-   iiceprt        =    10           !  i-index for debug
-   jiceprt        =    10           !  j-index for debug
-/
-!------------------------------------------------------------------------------
-&namiceini     !   Ice initialization
-!------------------------------------------------------------------------------
-                  ! -- limistate -- !
-   ln_limini      = .true.          !  activate ice initialization (T) or not (F)
-   ln_limini_file = .false.         !  netcdf file provided for initialization (T) or not (F)
-   rn_thres_sst   =  2.0            !  maximum water temperature with initial ice (degC)
-   rn_hts_ini_n   =  0.3            !  initial real snow thickness (m), North
-   rn_hts_ini_s   =  0.3            !        "            "             South
-   rn_hti_ini_n   =  3.0            !  initial real ice thickness  (m), North
-   rn_hti_ini_s   =  1.0            !        "            "             South
-   rn_ati_ini_n   =  0.9            !  initial ice concentration   (-), North
-   rn_ati_ini_s   =  0.9            !        "            "             South
-   rn_smi_ini_n   =  6.3            !  initial ice salinity     (g/kg), North
-   rn_smi_ini_s   =  6.3            !        "            "             South
-   rn_tmi_ini_n   =  270.           !  initial ice/snw temperature (K), North
-   rn_tmi_ini_s   =  270.           !        "            "             South
-/
-!------------------------------------------------------------------------------
-&namiceitd     !   Ice discretization
-!------------------------------------------------------------------------------
-   nn_catbnd      =    2           !  computation of ice category boundaries based on
-                                   !      1: tanh function
-                                   !      2: h^(-alpha), function of rn_himean
-   rn_himean      =    2.0         !  expected domain-average ice thickness (m), nn_catbnd = 2 only
-/
-!------------------------------------------------------------------------------
-&namicedyn     !   Ice dynamics and transport
-!------------------------------------------------------------------------------
-                  ! -- limtrp & limadv -- !
-   nn_limadv      =    0            !  choose the advection scheme (-1=Prather ; 0=Ultimate-Macho)
-   nn_limadv_ord  =    5            !  choose the order of the advection scheme (if nn_limadv=0)
-                  ! -- limitd_me -- !
-   nn_icestr      =    0            !  ice strength parameteriztaion                      
-                                    !     0: Hibler_79     P = pstar*<h>*exp(-c_rhg*A)
-                                    !     1: Rothrock_75   P = Cf*coeff*integral(wr.h^2)    
-   rn_pe_rdg      =   17.0          !     (nn_icestr=1) ridging work divided by pot. energy change in ridging
-   rn_pstar       =    2.0e+04      !     (nn_icestr=0) ice strength thickness parameter (N/m2) 
-   rn_crhg        =   20.0          !     (nn_icestr=0) ice strength conc. parameter (-)
-   ln_icestr_bvf  =    .false.      !     ice strength function brine volume (T) or not (F)
-                                    !
-            ! -- limdyn & limrhg -- !
-   rn_cio         =    5.0e-03      !  ice-ocean drag coefficient (-)
-   rn_creepl      =    1.0e-12      !  creep limit (s-1)
-   rn_ecc         =    2.0          !  eccentricity of the elliptical yield curve          
-   nn_nevp        =  120            !  number of EVP subcycles                             
-   rn_relast      =    0.333        !  ratio of elastic timescale to ice time step: Telast = dt_ice * rn_relast 
-                                    !     advised value: 1/3 (rn_nevp=120) or 1/9 (rn_nevp=300)
-   ln_landfast    =  .false.        !  landfast ice parameterization (T or F)                           
-   rn_gamma       =    0.15         !     (ln_landfast=T)  fraction of ocean depth that ice must reach to initiate landfast
-                                    !                      recommended range: [0.1 ; 0.25]
-   rn_icebfr      =    10.          !     (ln_landfast=T)  maximum bottom stress per unit area of contact (N/m2)                 
-                                    !                      a very large value ensures ice velocity=0 even with a small contact area
-                                    !                      recommended range: ?? (should be greater than atm-ice stress => >0.1 N/m2)
-   rn_lfrelax     =    1.e-5        !     (ln_landfast=T)  relaxation time scale to reach static friction (s-1)                 
-/
-!------------------------------------------------------------------------------
-&namicehdf     !   Ice horizontal diffusion
-!------------------------------------------------------------------------------
-                     ! -- limhdf -- !
-   nn_ahi0        =    -1           !  horizontal diffusivity computation
-                                    !    -1: no diffusion (bypass limhdf)
-                                    !     0: use rn_ahi0_ref
-                                    !     1: use rn_ahi0_ref x mean grid cell length / ( 2deg mean grid cell length )
-                                    !     2: use rn_ahi0_ref x grid cell length      / ( 2deg mean grid cell length )
-   rn_ahi0_ref    = 350.0           !  horizontal sea ice diffusivity (m2/s) 
-                                    !     if nn_ahi0 > 0, rn_ahi0_ref is the reference value at a nominal 2 deg resolution
-/
-!------------------------------------------------------------------------------
-&namicethd     !   Ice thermodynamics
-!------------------------------------------------------------------------------
-                 ! -- limthd_dif -- !
-   rn_kappa_i     = 1.0             !  radiation attenuation coefficient in sea ice (m-1)
-   nn_conv_dif    = 50              !  maximal number of iterations for heat diffusion computation
-   rn_terr_dif    = 1.0e-04         !  maximum temperature after heat diffusion (degC)
-   nn_ice_thcon   = 1               !  sea ice thermal conductivity
-                                    !     0: k = k0 + beta.S/T            (Untersteiner, 1964)
-                                    !     1: k = k0 + beta1.S/T - beta2.T (Pringle et al., 2007)
-   ln_it_qnsice   = .true.          !  iterate the surface non-solar flux with surface temperature (T) or not (F)
-   nn_monocat     = 0               !  virtual ITD mono-category parameterizations (1, jpl = 1 only) or not (0)
-                                    !     2: simple piling instead of ridging    --- temporary option
-                                    !     3: activate G(he) only                 --- temporary option
-                                    !     4: activate extra lateral melting only --- temporary option
-   rn_cdsn     = 0.31              !  thermal conductivity of the snow (0.31 W/m/K, Maykut and Untersteiner, 1971)
-                                   !  Obs: 0.1-0.5 (Lecomte et al, JAMES 2013)
-                  ! -- limthd_dh -- !
-   ln_limdH       = .true.          !  activate ice thickness change from growing/melting (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-   rn_betas       = 0.66            !  exponent in lead-ice repratition of snow precipitation
-                                    !     betas = 1 -> equipartition, betas < 1 -> more on leads
-                  ! -- limthd_da -- !
-   ln_limdA       = .true.          !  activate lateral melting param. (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-   rn_beta        = 1.0             !     (ln_latmelt=T) coef. beta for lateral melting param. Recommended range=[0.8-1.2]
-                                    !      => decrease = more melt and melt peaks toward higher concentration (A~0.5 for beta=1 ; A~0.8 for beta=0.2)
-                                    !         0.3 = best fit for western Fram Strait and Antarctica
-                                    !         1.4 = best fit for eastern Fram Strait      
-   rn_dmin        = 8.              !     (ln_latmelt=T) minimum floe diameter for lateral melting param. Recommended range=[6-10]
-                                    !      => 6  vs 8m = +40% melting at the peak (A~0.5)
-                                    !         10 vs 8m = -20% melting
-                 ! -- limthd_lac -- !
-   ln_limdO       = .true.          !  activate ice growth in open-water (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-   rn_hnewice     = 0.1             !  thickness for new ice formation in open water (m)
-   ln_frazil      = .false.         !  Frazil ice parameterization (ice collection as a function of wind)
-   rn_maxfrazb    = 1.0             !     (ln_frazil=T) maximum fraction of frazil ice collecting at the ice base
-   rn_vfrazb      = 0.417           !     (ln_frazil=T) thresold drift speed for frazil ice collecting at the ice bottom (m/s)
-   rn_Cfrazb      = 5.0             !     (ln_frazil=T) squeezing coefficient for frazil ice collecting at the ice bottom
-                  ! -- limitd_th -- !
-   rn_himin       = 0.1             !  minimum ice thickness (m) used in remapping, must be smaller than rn_hnewice
-/
-!------------------------------------------------------------------------------
-&namicesal     !   Ice salinity
-!------------------------------------------------------------------------------
-                 ! -- limthd_sal -- !
-   ln_limdS       = .true.          !  activate gravity drainage and flushing (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-   nn_icesal      =  2              !  ice salinity option
-                                    !     1: constant ice salinity (S=rn_icesal)
-                                    !     2: varying salinity parameterization S(z,t)
-                                    !     3: prescribed salinity profile S(z), Schwarzacher, 1959
-   rn_icesal      =  4.             !    (nn_icesal=1) ice salinity (g/kg)
-   rn_sal_gd      =  5.             !  restoring ice salinity, gravity drainage (g/kg)
-   rn_time_gd     =  1.73e+6        !  restoring time scale, gravity drainage  (s)
-   rn_sal_fl      =  2.             !  restoring ice salinity, flushing (g/kg)
-   rn_time_fl     =  8.64e+5        !  restoring time scale, flushing (s)
-   rn_simax       = 20.             !  maximum tolerated ice salinity (g/kg)
-   rn_simin       =  0.1            !  minimum tolerated ice salinity (g/kg)
-/
-!------------------------------------------------------------------------------
-&namiceitdme   !   Ice mechanical redistribution (ridging and rafting)
-!------------------------------------------------------------------------------
-                  ! -- limitd_me -- !
-   rn_cs          =   0.5           !  fraction of shearing energy contributing to ridging
-   nn_partfun     =   1             !  type of ridging participation function
-                                    !     0: linear      (Thorndike et al, 1975)
-                                    !     1: exponential (Lipscomb, 2007)
-   rn_gstar       =   0.15          !     (nn_partfun = 0) fractional area of thin ice being ridged 
-   rn_astar       =   0.03          !     (nn_partfun = 1) exponential measure of ridging ice fraction [set to 0.05 if hstar=100]
-   ln_ridging     =   .true.        !  ridging activated (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-   rn_hstar       =  25.0           !     (ln_ridging = T) determines the maximum thickness of ridged ice (m) (Hibler, 1980)
-   rn_por_rdg     =   0.3           !     (ln_ridging = T) porosity of newly ridged ice (Lepparanta et al., 1995)
-   rn_fsnowrdg    =   0.5           !     (ln_ridging = T) snow volume fraction that survives in ridging
-   ln_rafting     =   .true.        !  rafting activated (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-   rn_hraft       =   0.75          !     (ln_rafting = T) threshold thickness for rafting (m)
-   rn_craft       =   5.0           !     (ln_rafting = T) squeezing coefficient used in the rafting function
-   rn_fsnowrft    =   0.5           !     (ln_rafting = T) snow volume fraction that survives in rafting
-/
+&nampar         !   Generic parameters
+!------------------------------------------------------------------------------
+   jpl              =   5             !  number of ice  categories
+   nlay_i           =   2             !  number of ice  layers
+   nlay_s           =   1             !  number of snow layers (only 1 is working)
+   nn_monocat       =   0             !  virtual ITD mono-category parameterizations (1-4 => jpl = 1 only) or not (0)
+                                      !     2: simple piling instead of ridging    --- temporary option
+                                      !     3: activate G(he) only                 --- temporary option
+                                      !     4: activate extra lateral melting only --- temporary option
+   ln_icedyn        = .true.          !  ice dynamics (T) or not (F)
+   ln_icethd        = .true.          !  ice thermo   (T) or not (F)
+   rn_amax_n        =   0.997         !  maximum tolerated ice concentration NH
+   rn_amax_s        =   0.997         !  maximum tolerated ice concentration SH
+   cn_icerst_in     = "restart_ice"   !  suffix of ice restart name (input)
+   cn_icerst_out    = "restart_ice"   !  suffix of ice restart name (output)
+   cn_icerst_indir  = "."             !  directory to read   input ice restarts
+   cn_icerst_outdir = "."             !  directory to write output ice restarts
+/
+!------------------------------------------------------------------------------
+&namitd         !   Ice discretization
+!------------------------------------------------------------------------------
+   ln_cat_hfn       = .true.          !  ice categories are defined by a function following rn_himean**(-0.05)
+      rn_himean     =   2.0           !  expected domain-average ice thickness (m)
+   ln_cat_usr       = .false.         !  ice categories are defined by rn_catbnd below (m)
+      rn_catbnd     =   0.,0.45,1.1,2.1,3.7,6.0  
+   rn_himin         =   0.1           !  minimum ice thickness (m) used in remapping
+/
+!------------------------------------------------------------------------------
+&namdyn         !   Ice dynamics
+!------------------------------------------------------------------------------
+   ln_dynFULL       = .true.          !  dyn.: full ice dynamics               (rheology + advection + ridging/rafting + correction)
+   ln_dynRHGADV     = .false.         !  dyn.: no ridge/raft & no corrections  (rheology + advection)
+   ln_dynADV        = .false.         !  dyn.: only advection w prescribed vel.(rn_uvice + advection)
+      rn_uice       =   0.00001       !        prescribed ice u-velocity
+      rn_vice       =   0.            !        prescribed ice v-velocity
+   rn_ishlat        =   2.            !  free slip (0) ; partial slip (0-2) ; no slip (2) ; strong slip (>2)
+   ln_landfast      = .false.         !  landfast ice parameterization (T or F)                           
+      rn_gamma      =   0.15          !     fraction of ocean depth that ice must reach to initiate landfast
+                                      !        recommended range: [0.1 ; 0.25]
+      rn_icebfr     =  10.            !     maximum bottom stress per unit area of contact [N/m2]                 
+                                      !        a very large value ensures ice velocity=0 even with a small contact area
+                                      !        recommended range: ?? (should be greater than atm-ice stress => >0.1 N/m2)
+      rn_lfrelax    =   1.e-5         !     relaxation time scale to reach static friction [s-1]
+/
+!------------------------------------------------------------------------------
+&namdyn_rdgrft  !   Ice ridging/rafting
+!------------------------------------------------------------------------------
+          ! -- ice_rdgrft_strength -- !
+   ln_str_H79       = .true.          !  ice strength param.: Hibler_79   => P = pstar*<h>*exp(-c_rhg*A)                      
+      rn_pstar      =   2.0e+04       !     ice strength thickness parameter [N/m2]
+      rn_crhg       =   20.0          !     ice strength conc. parameter (-)
+                   ! -- ice_rdgrft -- !
+   rn_csrdg         =   0.5           !  fraction of shearing energy contributing to ridging
+              ! -- ice_rdgrft_prep -- !
+   ln_partf_lin     = .false.         !  Linear ridging participation function (Thorndike et al, 1975)
+      rn_gstar      =   0.15          !     fractional area of thin ice being ridged 
+   ln_partf_exp     = .true.          !  Exponential ridging participation function (Lipscomb, 2007)
+      rn_astar      =   0.03          !     exponential measure of ridging ice fraction [set to 0.05 if hstar=100]
+   ln_ridging       = .true.          !  ridging activated (T) or not (F)
+      rn_hstar      =  25.0           !     determines the maximum thickness of ridged ice [m] (Hibler, 1980)
+      rn_porordg    =   0.3           !     porosity of newly ridged ice (Lepparanta et al., 1995)
+      rn_fsnwrdg    =   0.5           !     snow volume fraction that survives in ridging
+      rn_fpndrdg    =   1.0           !     pond fraction that survives in ridging (small a priori)
+   ln_rafting       = .true.          !  rafting activated (T) or not (F)
+      rn_hraft      =   0.75          !     threshold thickness for rafting [m]
+      rn_craft      =   5.0           !     squeezing coefficient used in the rafting function
+      rn_fsnwrft    =   0.5           !     snow volume fraction that survives in rafting
+      rn_fpndrft    =   1.0           !     pond fraction that survives in rafting (0.5 a priori)
+/
+!------------------------------------------------------------------------------
+&namdyn_rhg     !   Ice rheology
+!------------------------------------------------------------------------------
+   ln_rhg_EVP       = .true.          !  EVP rheology
+      ln_aEVP       = .false.         !     adaptive rheology (Kimmritz et al. 2016 & 2017)
+      rn_creepl     =   2.0e-9        !     creep limit [1/s]
+      rn_ecc        =   2.0           !     eccentricity of the elliptical yield curve          
+      nn_nevp       = 120             !     number of EVP subcycles                             
+      rn_relast     =   0.333         !     ratio of elastic timescale to ice time step: Telast = dt_ice * rn_relast 
+                                      !        advised value: 1/3 (rn_nevp=120) or 1/9 (rn_nevp=300)
+/
+!------------------------------------------------------------------------------
+&namdyn_adv     !   Ice advection
+!------------------------------------------------------------------------------
+   ln_adv_Pra       = .false.         !  Advection scheme (Prather)
+   ln_adv_UMx       = .true.          !  Advection scheme (Ultimate-Macho)
+      nn_UMx        =   5             !     order of the scheme for UMx (1-5 ; 20=centered 2nd order)
+/
+!------------------------------------------------------------------------------
+&namforcing     !   Ice surface forcing
+!------------------------------------------------------------------------------
+   rn_cio           =   5.0e-03       !  ice-ocean drag coefficient (-)
+   rn_blow_s        =   0.66          !  mesure of snow blowing into the leads
+                                      !     = 1 => no snow blowing, < 1 => some snow blowing
+   nn_flxdist       =  -1             !  Redistribute heat flux over ice categories
+                                      !     =-1  Do nothing (needs N(cat) fluxes)
+                                      !     = 0  Average N(cat) fluxes then apply the average over the N(cat) ice
+                                      !     = 1  Average N(cat) fluxes then redistribute over the N(cat) ice using T-ice and albedo sensitivity
+                                      !     = 2  Redistribute a single flux over categories
+   nice_jules       = 0               !  Jules coupling (0=OFF, 1=EMULATED, 2=ACTIVE)
+/
+!------------------------------------------------------------------------------
+&namthd         !   Ice thermodynamics
+!------------------------------------------------------------------------------
+   ln_icedH         = .true.          !  activate ice thickness change from growing/melting (T) or not (F)
+   ln_icedA         = .true.          !  activate lateral melting param. (T) or not (F)
+   ln_icedO         = .true.          !  activate ice growth in open-water (T) or not (F)
+   ln_icedS         = .true.          !  activate brine drainage (T) or not (F)
+/
+!------------------------------------------------------------------------------
+&namthd_zdf     !   Ice heat diffusion
+!------------------------------------------------------------------------------
+   ln_zdf_BL99      = .true.          !  Heat diffusion follows Bitz and Lipscomb 1999
+   ln_cndi_U64      = .false.         !  sea ice thermal conductivity: k = k0 + beta.S/T            (Untersteiner, 1964)
+   ln_cndi_P07      = .true.          !  sea ice thermal conductivity: k = k0 + beta1.S/T - beta2.T (Pringle et al., 2007)
+   rn_cnd_s         =   0.31          !  thermal conductivity of the snow (0.31 W/m/K, Maykut and Untersteiner, 1971)
+                                      !     Obs: 0.1-0.5 (Lecomte et al, JAMES 2013)
+   rn_kappa_i       =   1.0           !  radiation attenuation coefficient in sea ice [1/m]
+/
+!------------------------------------------------------------------------------
+&namthd_da     !   Ice lateral melting
+!------------------------------------------------------------------------------
+   rn_beta          =   1.0           !  coef. beta for lateral melting param. Recommended range=[0.8-1.2]
+                                      !   => decrease = more melt and melt peaks toward higher concentration (A~0.5 for beta=1 ; A~0.8 for beta=0.2)
+                                      !      0.3 = best fit for western Fram Strait and Antarctica
+                                      !      1.4 = best fit for eastern Fram Strait      
+   rn_dmin          =   8.            !  minimum floe diameter for lateral melting param. Recommended range=[6-10]
+                                      !   => 6  vs 8m = +40% melting at the peak (A~0.5)
+                                      !      10 vs 8m = -20% melting
+/
+!------------------------------------------------------------------------------
+&namthd_do      !   Ice growth in open water
+!------------------------------------------------------------------------------
+   rn_hinew         =   0.1           !  thickness for new ice formation in open water (m), must be larger than rn_hnewice
+   ln_frazil        = .false.         !  Frazil ice parameterization (ice collection as a function of wind)
+      rn_maxfraz    =   1.0           !     maximum fraction of frazil ice collecting at the ice base
+      rn_vfraz      =   0.417         !     thresold drift speed for frazil ice collecting at the ice bottom (m/s)
+      rn_Cfraz      =   5.0           !     squeezing coefficient for frazil ice collecting at the ice bottom
+/
+!------------------------------------------------------------------------------
+&namthd_sal     !   Ice salinity
+!------------------------------------------------------------------------------
+   nn_icesal        =   2             !  ice salinity option
+                                      !     1: constant ice salinity (S=rn_icesal)
+                                      !     2: varying salinity parameterization S(z,t)
+                                      !     3: prescribed salinity profile S(z), Schwarzacher, 1959
+   rn_icesal        =   4.            !    (nn_icesal=1) ice salinity (g/kg)
+   rn_sal_gd        =   5.            !  restoring ice salinity, gravity drainage (g/kg)
+   rn_time_gd       =   1.73e+6       !  restoring time scale, gravity drainage  (s)
+   rn_sal_fl        =   2.            !  restoring ice salinity, flushing (g/kg)
+   rn_time_fl       =   8.64e+5       !  restoring time scale, flushing (s)
+   rn_simax         =  20.            !  maximum tolerated ice salinity (g/kg)
+   rn_simin         =   0.1           !  minimum tolerated ice salinity (g/kg)
+/
+!------------------------------------------------------------------------------
+&namthd_pnd     !   Melt ponds
+!------------------------------------------------------------------------------
+   ln_pnd_H12       = .false.         !  activate evolutive melt ponds (from Holland et al 2012)
+      ln_pnd_fwb    = .false.         !     melt ponds store freshwater or not
+   ln_pnd_CST       = .false.         !  activate constant melt ponds
+      rn_apnd       =   0.2           !     prescribed pond fraction, at Tsu=0
+      rn_hpnd       =   0.05          !     prescribed pond depth, at Tsu=0
+   ln_pnd_alb       = .false.         !  melt ponds affect albedo or not
+/
+!------------------------------------------------------------------------------
+&namini         !   Ice initialization
+!------------------------------------------------------------------------------
+   ln_iceini        = .true.          !  activate ice initialization (T) or not (F)
+   ln_iceini_file   = .false.         !  netcdf file provided for initialization (T) or not (F)
+   rn_thres_sst     =   2.0           !  max delta temp. above Tfreeze with initial ice = (sst - tfreeze)
+   rn_hts_ini_n     =   0.3           !  initial real snow thickness (m), North
+   rn_hts_ini_s     =   0.3           !        "            "             South
+   rn_hti_ini_n     =   3.0           !  initial real ice thickness  (m), North
+   rn_hti_ini_s     =   1.0           !        "            "             South
+   rn_ati_ini_n     =   0.9           !  initial ice concentration   (-), North
+   rn_ati_ini_s     =   0.9           !        "            "             South
+   rn_smi_ini_n     =   6.3           !  initial ice salinity     (g/kg), North
+   rn_smi_ini_s     =   6.3           !        "            "             South
+   rn_tmi_ini_n     = 270.            !  initial ice/snw temperature (K), North
+   rn_tmi_ini_s     = 270.            !        "            "             South
+
+   sn_hti = 'Ice_initialization'    , -12 ,'hti'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_hts = 'Ice_initialization'    , -12 ,'hts'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_ati = 'Ice_initialization'    , -12 ,'ati'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_tsu = 'Ice_initialization'    , -12 ,'tsu'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_tmi = 'Ice_initialization'    , -12 ,'tmi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_smi = 'Ice_initialization'    , -12 ,'smi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   cn_dir='./'
+/
+!------------------------------------------------------------------------------
+&namalb         !   albedo parameters
+!------------------------------------------------------------------------------
+   !                                  !                          !  obs range (cloud-sky)
+   rn_alb_sdry      =   0.85          !  dry snow albedo         :  0.85 -- 0.87
+   rn_alb_smlt      =   0.75          !  melting snow albedo     :  0.72 -- 0.82
+   rn_alb_idry      =   0.60          !  dry ice albedo          :  0.54 -- 0.65
+   rn_alb_imlt      =   0.50          !  bare puddled ice albedo :  0.49 -- 0.58
+   rn_alb_dpnd      =   0.27          !  ponded ice albedo       :  0.10 -- 0.30 
+/
+!------------------------------------------------------------------------------
+&namdia         !   Diagnostics
+!------------------------------------------------------------------------------
+   ln_icediachk     = .false.         !  check online the heat, mass & salt budgets (T) or not (F)
+   ln_icediahsb     = .false.         !  output the heat, mass & salt budgets (T) or not (F)
+   ln_icectl        = .false.         !  ice points output for debug (T or F)
+   iiceprt          =  10             !  i-index for debug
+   jiceprt          =  10             !  j-index for debug
+/
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/namelist_ref
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 9019)
@@ -1,22 +1,23 @@
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-!!                            namelist_ref
+!!                            namelist_ref                            !!
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 !! NEMO/OPA  :  1 - run manager      (namrun)
-!! namelists    2 - Domain           (namcfg, namzgr, namdom, namtsd, namcrs, namc1d, namc1d_uvd)
-!!              3 - Surface boundary (namsbc, namsbc_flx, namsbc_blk, namsbc_sas)
-!!                                    namsbc_cpl, namtra_qsr, namsbc_rnf,
-!!                                    namsbc_apr, namsbc_ssr, namsbc_alb, namsbc_wave)
+!! namelists    2 - Domain           (namcfg, namdom, namtsd, namcrs, namc1d, namc1d_uvd)
+!!              3 - Surface boundary (namsbc, namsbc_flx, namsbc_blk, namsbc_cpl,
+!!                                    namsbc_sas, namtra_qsr, namsbc_rnf,
+!!                                    namberg, namsbc_isf, namsbc_iscpl, 
+!!                                    namsbc_apr, namsbc_ssr, namsbc_wave)
 !!              4 - lateral boundary (namlbc, namagrif, nambdy, nambdy_tide)
-!!              5 - bottom  boundary (nambfr, nambbc, nambbl)
+!!              5 - bottom  boundary (namdrg, namdrg_top, namdrg_bot, 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, namzdf_tmx_new)
-!!              9 - diagnostics      (namnc4, namtrd, namspr, namflo, namhsb, namsto)
-!!             10 - miscellaneous    (nammpp, namctl)
+!!              8 - Verical physics  (namzdf, namzdf_ric, namzdf_tke, namzdf_gls, namzdf_iwm)
+!!              9 - miscellaneous    (nammpp, namctl)
+!!             10 - diagnostics      (namnc4, namtrd, namspr, namflo, namhsb, namsto)
 !!             11 - Obs & Assim      (namobs, nam_asminc)
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 
 !!======================================================================
-!!                   ***  Run management namelists  ***
+!!                   ***  Run management namelists  ***               !!
 !!======================================================================
 !!   namrun       parameters of the run
@@ -62,5 +63,5 @@
 !!   namwad       Wetting and drying                                    (default F)
 !!   namtsd       data: temperature & salinity
-!!   namcrs       coarsened grid (for outputs and/or TOP)               ("key_crs")
+!!   namcrs       coarsened grid (for outputs and/or TOP)               (ln_crs =T)
 !!   namc1d       1D configuration options                              ("key_c1d")
 !!   namc1d_dyndmp 1D newtonian damping applied on currents             ("key_c1d")
@@ -69,5 +70,5 @@
 !
 !-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
+&namcfg        !   parameters of the configuration                     !   (default: user defined GYRE)
 !-----------------------------------------------------------------------
    ln_read_cfg = .false.   !  (=T) read the domain configuration file
@@ -82,5 +83,5 @@
 /
 !-----------------------------------------------------------------------
-&namdom        !   space and time domain (bathymetry, mesh, timestep)
+&namdom        !   time and space domain
 !-----------------------------------------------------------------------
    ln_linssh   = .false.   !  =T  linear free surface  ==>>  model level are fixed in time
@@ -90,8 +91,8 @@
    rn_isfhmin  =    1.00   !  treshold (m) to discriminate grounding ice to floating ice
    !
-   rn_rdt      = 5760.     !  time step for the dynamics (and tracer if nn_acc=0)
+   rn_rdt      = 5760.     !  time step for the dynamics and tracer
    rn_atfp     =    0.1    !  asselin time filter parameter
    !
-   ln_crs      = .false.   !  Logical switch for coarsening module
+   ln_crs      = .false.   !  Logical switch for coarsening module      (T => fill namcrs)
 /
 !-----------------------------------------------------------------------
@@ -117,5 +118,5 @@
 /
 !-----------------------------------------------------------------------
-&namcrs        !   coarsened grid (for outputs and/or TOP)              ("key_crs")
+&namcrs        !   coarsened grid (for outputs and/or TOP)              (ln_crs =T)
 !-----------------------------------------------------------------------
    nn_factx    = 3         !  Reduction factor of x-direction
@@ -170,5 +171,4 @@
 !!   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)
@@ -183,24 +183,19 @@
    ln_usr      = .false.   !  user defined formulation                  (T => check usrdef_sbc)
    ln_flx      = .false.   !  flux formulation                          (T => fill namsbc_flx )
-   ln_blk      = .true.    !  Bulk formulation                          (T => fill namsbc_blk )
+   ln_blk      = .false.    !  Bulk formulation                          (T => fill namsbc_blk )
                      ! 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)
+                           !  =0 no opa-sas OASIS coupling: default single executable config.
+                           !  =1 opa-sas OASIS coupling: multi executable config., OPA component
+                           !  =2 opa-sas OASIS coupling: multi executable config., SAS component 
                      ! Sea-ice :
-   nn_ice      = 3         !  =0 no ice boundary condition   ,
+   nn_ice      = 2         !  =0 no ice boundary condition   ,
                            !  =1 use observed ice-cover      ,
-                           !  =2 to 4 :  ice-model used (LIM2, LIM3 or CICE)                         ("key_lim3", "key_lim2", or "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)
+                           !  =2 or 3 automatically for LIM3 or CICE    ("key_lim3" or "key_cice")
+                           !          except in AGRIF zoom where it has to be specified
+   ln_ice_embd = .false.   !  =T embedded sea-ice (pressure + mass and salt exchanges)
+                           !  =F levitating ice (no pressure, mass and salt exchanges)
                      ! Misc. options of sbc : 
    ln_traqsr   = .true.    !  Light penetration in the ocean            (T => fill namtra_qsr)
@@ -231,9 +226,9 @@
    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_blk   !   namsbc_blk  generic Bulk formula                      (ln_blk = T)
+&namsbc_blk   !   namsbc_blk  generic Bulk formula                      (ln_blk =T)
 !-----------------------------------------------------------------------
 !              !  file name                   ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights                              ! rotation ! land/sea mask !
@@ -261,8 +256,8 @@
    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)
-   ln_Cd_L12   = .false.   !  Modify the drag ice-atm and oce-atm depending on ice concentration
-                           !  This parameterization is from Lupkes et al. (JGR 2012)
+   rn_vfac     = 0.        !  multiplicative factor for ocean & ice velocity used to
+   !                       !  calculate the wind stress (0.=absolute or 1.=relative winds)
+   ln_Cd_L12   = .false.   !  air-ice drags = F(ice concentration) (Lupkes et al. 2012)
+   ln_Cd_L15   = .false.   !  air-ice drags = F(ice concentration) (Lupkes et al. 2015)
 /
 !-----------------------------------------------------------------------
@@ -277,41 +272,49 @@
    sn_snd_crt    =   'none'                 ,    'no'    , 'spherical' , 'eastward-northward' ,  'T'
    sn_snd_co2    =   'coupled'              ,    'no'    ,     ''      ,         ''           ,   ''
-   sn_snd_crtw   =       'none'                 ,    'no'    ,     ''      ,         ''           , 'U,V'
-   sn_snd_ifrac  =       'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
-   sn_snd_wlev   =       'coupled'              ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_crtw   =   'none'                 ,    'no'    ,     ''      ,         ''           , 'U,V'
+   sn_snd_ifrac  =   'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_wlev   =   'coupled'              ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_cond   =   'weighted ice'         ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_thick1 =   'ice and snow'         ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_mpnd   =   'weighted ice'         ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_sstfrz =   'coupled'              ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_ttilyr =   'weighted ice'         ,    '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'    ,     ''      ,         ''          ,   ''
-   sn_rcv_hsig   =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
-   sn_rcv_iceflx =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
-   sn_rcv_mslp   =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
-   sn_rcv_phioc  =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
-   sn_rcv_sdrfx  =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
-   sn_rcv_sdrfy  =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
-   sn_rcv_wper   =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
-   sn_rcv_wnum   =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
-   sn_rcv_wstrf  =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
-   sn_rcv_wdrag  =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
+   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'    ,     ''      ,         ''           ,   ''
+   sn_rcv_hsig   =   'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_rcv_iceflx =   'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_rcv_mslp   =   'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_rcv_phioc  =   'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_rcv_sdrfx  =   'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_rcv_sdrfy  =   'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_rcv_wper   =   'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_rcv_wnum   =   'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_rcv_wstrf  =   'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_rcv_wdrag  =   'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_rcv_ts_ice =   'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_rcv_isf    =   'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_rcv_icb    =   'none'                 ,    '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    !   Stand Alone Surface boundary condition
+   nn_cats_cpl   =     5   !  Number of sea ice categories over which coupling is to be carried out (if not 1)
+/
+!-----------------------------------------------------------------------
+&namsbc_sas    !   Stand-Alone 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      !
-   l_sasread   = .TRUE.   ! Read fields in a file if .TRUE. , or initialize to 0. in sbcssm.F90 if .FALSE.
-   sn_usp      = 'sas_grid_U',     120           , 'vozocrtx',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
-   sn_vsp      = 'sas_grid_V',     120           , 'vomecrty',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_usp      = 'sas_grid_U',     120           , 'uos'     ,   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_vsp      = 'sas_grid_V',     120           , 'vos'     ,   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
    sn_tem      = 'sas_grid_T',     120           , 'sosstsst',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
    sn_sal      = 'sas_grid_T',     120           , 'sosaline',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
@@ -320,10 +323,11 @@
    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
+   l_sasread   = .true.    !  =T Read the above fields in a file, =F initialize to 0. in sbcssm.F90
+   ln_3d_uve   = .false.   !  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)
+&namtra_qsr    !   penetrative solar radiation                          (ln_traqsr =T)
 !-----------------------------------------------------------------------
 !              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
@@ -339,8 +343,7 @@
    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)
+/
+!-----------------------------------------------------------------------
+&namsbc_rnf    !   runoffs namelist surface boundary condition          (ln_rnf =T)
 !-----------------------------------------------------------------------
 !              !  file name           ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
@@ -418,5 +421,5 @@
 /
 !-----------------------------------------------------------------------
-&namsbc_ssr    !   surface boundary condition : sea surface restoring   (ln_ssr=T)
+&namsbc_ssr    !   surface boundary condition : sea surface restoring   (ln_ssr =T)
 !-----------------------------------------------------------------------
 !              ! file name ! frequency (hours) ! variable ! time interp.!  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
@@ -428,21 +431,9 @@
    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)
+   !                       !  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   =    1   !  parameterization of ice/snow albedo
-                         !     0: Shine & Henderson-Sellers (JGR 1985), giving clear-sky albedo
-                         !     1: "home made" based on Brandt et al. (JClim 2005) and Grenfell & Perovich (JGR 2004),
-                         !        giving cloud-sky albedo
-   rn_alb_sdry  =  0.85  !  dry snow albedo         : 0.80 (nn_ice_alb = 0); 0.85 (nn_ice_alb = 1); obs 0.85-0.87 (cloud-sky)
-   rn_alb_smlt  =  0.75  !  melting snow albedo     : 0.65 ( '' )          ; 0.75 ( '' )          ; obs 0.72-0.82 ( '' )
-   rn_alb_idry  =  0.60  !  dry ice albedo          : 0.72 ( '' )          ; 0.60 ( '' )          ; obs 0.54-0.65 ( '' )
-   rn_alb_imlt  =  0.50  !  bare puddled ice albedo : 0.53 ( '' )          ; 0.50 ( '' )          ; obs 0.49-0.58 ( '' )
 /
 !-----------------------------------------------------------------------
@@ -497,5 +488,5 @@
 
 !!======================================================================
-!!               ***  Lateral boundary condition  ***
+!!               ***  Lateral boundary condition  ***                 !!
 !!======================================================================
 !!   namlbc        lateral momentum boundary condition
@@ -580,12 +571,8 @@
    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'  ,    ''    ,   ''     ,     ''
+!   bn_h_i     = 'amm12_bdyT_ice',         24        , 'iicethic',    .true.   , .false. ,  'daily'  ,    ''    ,   ''     ,     ''
+!   bn_h_s     = 'amm12_bdyT_ice',         24        , 'isnowthi',    .true.   , .false. ,  'daily'  ,    ''    ,   ''     ,     ''
 
    cn_dir      = 'bdydta/' !  root directory for the location of the bulk files
@@ -601,33 +588,44 @@
 
 !!======================================================================
-!!                 ***  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)
+!!                ***  Top/Bottom boundary condition  ***             !!
+!!======================================================================
+!!   namdrg        top/bottom drag coefficient                          (default: NO selection)
+!!   namdrg_top    top    friction                                      (ln_isfcav=T)
+!!   namdrg_bot    bottom friction                                      
+!!   nambbc        bottom temperature boundary condition                (default: NO)
+!!   nambbl        bottom boundary layer scheme                         (default: NO)
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .false.    !  free-slip       : Cd = 0                  (F => fill namdrg_bot
+   ln_lin     = .false.    !      linear  drag: Cd = Cd0 Uc0                   &   namdrg_top)
+   ln_non_lin = .false.    !  non-linear  drag: Cd = Cd0 |U|
+   ln_loglayer= .false.    !  logarithmic drag: Cd = vkarmn/log(z/z0) |U|
+   !
+   ln_drgimp  = .true.     !  implicit top/bottom friction flag
+/
+!-----------------------------------------------------------------------
+&namdrg_top        !   TOP friction                                     (ln_isfcav=T)
+!-----------------------------------------------------------------------
+   rn_Cd0     =  1.e-3     !  drag coefficient [-]
+   rn_Uc0     =  0.4       !  ref. velocity [m/s] (linear drag=Cd0*Uc0) 
+   rn_Cdmax   =  0.1       !  drag value maximum [-] (logarithmic drag)
+   rn_ke0     =  2.5e-3    !  background kinetic energy  [m2/s2] (non-linear cases)
+   rn_z0      =  3.0e-3    !  roughness [m] (ln_loglayer=T)
+   ln_boost   = .false.    !  =T regional boost of Cd0 ; =F constant
+      rn_boost=  50.          !  local boost factor  [-]
+/
+!-----------------------------------------------------------------------
+&namdrg_bot        !   BOTTOM friction                                  
+!-----------------------------------------------------------------------
+   rn_Cd0     =  1.e-3    !  drag coefficient [-]
+   rn_Uc0     =  0.4      !  ref. velocity [m/s] (linear drag=Cd0*Uc0) 
+   rn_Cdmax   =  0.1      !  drag value maximum [-] (logarithmic drag)
+   rn_ke0     =  2.5e-3   !  background kinetic energy  [m2/s2] (non-linear cases)
+   rn_z0      =  3.e-3    !  roughness [m] (ln_loglayer=T)
+   ln_boost   = .false.   !  =T regional boost of Cd0 ; =F constant
+      rn_boost=  50.         !  local boost factor  [-]
 /
 !-----------------------------------------------------------------------
@@ -646,6 +644,7 @@
 /
 !-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
+&nambbl        !   bottom boundary layer scheme                         (default: NO)
+!-----------------------------------------------------------------------
+   ln_trabbl   = .false.   !  Bottom Boundary Layer parameterisation flag
    nn_bbl_ldf  =  1        !  diffusive bbl (=1)   or not (=0)
    nn_bbl_adv  =  0        !  advective bbl (=1/2) or not (=0)
@@ -655,5 +654,5 @@
 
 !!======================================================================
-!!                        Tracer (T & S ) namelists
+!!                        Tracer (T & S) namelists
 !!======================================================================
 !!   nameos           equation of state
@@ -666,9 +665,9 @@
 !
 !-----------------------------------------------------------------------
-&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)
+&nameos        !   ocean Equation Of Seawater                           (default: NO)
+!-----------------------------------------------------------------------
+   ln_teos10   = .false.         !  = Use TEOS-10
+   ln_eos80    = .false.         !  = Use EOS80
+   ln_seos     = .false.         !  = Use S-EOS (simplified Eq.)
                                  !
    !                     ! S-EOS coefficients (ln_seos=T):
@@ -683,6 +682,7 @@
 /
 !-----------------------------------------------------------------------
-&namtra_adv    !   advection scheme for tracer                          (default: NO advection)
-!-----------------------------------------------------------------------
+&namtra_adv    !   advection scheme for tracer                          (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_traadv_NONE= .false. !  No tracer advection
    ln_traadv_cen = .false. !  2nd order centered scheme
       nn_cen_h   =  4            !  =2/4, horizontal 2nd order CEN / 4th order CEN
@@ -691,6 +691,4 @@
       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
@@ -713,8 +711,8 @@
 /
 !-----------------------------------------------------------------------
-&namtra_ldf    !   lateral diffusion scheme for tracers                 (default: NO diffusion)
+&namtra_ldf    !   lateral diffusion scheme for tracers                 (default: NO selection)
 !-----------------------------------------------------------------------
    !                       !  Operator type:
-   !                           !  no diffusion: set ln_traldf_lap=..._blp=F 
+   ln_traldf_NONE  =  .false.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -748,28 +746,29 @@
 &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
+   ln_ldfeiv     = .false. ! use eddy induced velocity parameterization
+      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
+      ln_ldfeiv_dia =.false.  ! diagnose eiv stream function and velocities
 /
 !-----------------------------------------------------------------------
 &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  ***
-!!======================================================================
+   ln_tradmp   =  .true.   !  add a damping term
+      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  ***                  !!
+!!======================================================================
+!!   nam_vvl       vertical coordinate options
 !!   namdyn_adv    formulation of the momentum advection
 !!   namdyn_vor    advection scheme
@@ -780,25 +779,25 @@
 !
 !-----------------------------------------------------------------------
-&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
+&nam_vvl       !   vertical coordinate options                             (default: z-star)
+!-----------------------------------------------------------------------
+   ln_vvl_zstar  = .true.           !  z-star vertical coordinate
+   ln_vvl_ztilde = .false.          !  z-tilde 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
+   rn_ahe3       =  0.0             !  thickness diffusion coefficient
+   rn_rst_e3t    = 30.0             !  ztilde to zstar restoration timescale [days]
+   rn_lf_cutoff  =  5.0             !  cutoff frequency for low-pass filter  [days]
+   rn_zdef_max   =  0.9             !  maximum fractional e3t deformation
    ln_vvl_dbg    = .true.           !  debug prints    (T/F)
+/
+!-----------------------------------------------------------------------
+&namdyn_adv    !   formulation of the momentum advection                (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_dynadv_NONE= .false. !  linear dynamics (no momentum advection)
+   ln_dynadv_vec = .false. !  vector form - 2nd centered scheme
+     nn_dynkeg     = 0        ! grad(KE) scheme: =0   C2  ;  =1   Hollingsworth correction
+   ln_dynadv_cen2= .false. !  flux form - 2nd order centered scheme
+   ln_dynadv_ubs = .false. !  flux form - 3rd order UBS      scheme
 /
 !-----------------------------------------------------------------------
@@ -813,5 +812,5 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_hpg    !   Hydrostatic pressure gradient option                 (default: zps)
+&namdyn_hpg    !   Hydrostatic pressure gradient option                 (default: NO selection)
 !-----------------------------------------------------------------------
    ln_hpg_zco  = .false.   !  z-coordinate - full steps
@@ -837,8 +836,8 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_ldf    !   lateral diffusion on momentum                        (default: NO)
+&namdyn_ldf    !   lateral diffusion on momentum                        (default: NO selection)
 !-----------------------------------------------------------------------
    !                       !  Type of the operator :
-   !                           !  no diffusion: set ln_dynldf_lap=..._blp=F 
+   ln_dynldf_NONE=  .false.    !  No operator (i.e. no explicit diffusion)
    ln_dynldf_lap =  .false.    !    laplacian operator
    ln_dynldf_blp =  .false.    !  bilaplacian operator
@@ -866,48 +865,62 @@
    rn_maxfac     = 1.0         !  multiplier of theorectical upper limit
 /
-
-!!======================================================================
-!!             Tracers & Dynamics vertical physics namelists
+!
+!!======================================================================
+!!                     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
-   ln_zdfqiao  = .false.   !  Enhanced wave vertical mixing Qiao (2010) (T => ln_wave=.true. & ln_sdw=.true. & fill namsbc_wave)
-/
-!-----------------------------------------------------------------------
-&namzdf_ric    !   richardson number dependent vertical diffusion       ("key_zdfric" )
+!!    namzdf_ric    richardson number vertical mixing                   (ln_zdfric=T)
+!!    namzdf_tke    TKE vertical mixing                                 (ln_zdftke=T)
+!!    namzdf_gls    GLS vertical mixing                                 (ln_zdfgls=T)
+!!    namzdf_iwm    tidal mixing parameterization                       (ln_zdfiwm=T)
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure (required)
+   ln_zdfcst   = .false.      !  constant mixing
+   ln_zdfric   = .false.      !  local Richardson dependent formulation (T =>   fill namzdf_ric)
+   ln_zdftke   = .false.      !  Turbulent Kinetic Energy closure       (T =>   fill namzdf_tke)
+   ln_zdfgls   = .false.      !  Generic Length Scale closure           (T =>   fill namzdf_gls)
+   ln_zdfosm   = .false.      !  OSMOSIS BL closure                     (T =>   fill namzdf_osm)
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+      nn_evdm     =    0         ! apply on tracer (=0) or on tracer and momentum (=1)
+      rn_evd      =  100.        ! mixing coefficient [m2/s]
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+      nn_npc      =    1         ! frequency of application of npc
+      nn_npcp     =  365         ! npc control print frequency
+   !
+   ln_zdfddm   = .false.   ! double diffusive mixing
+      rn_avts  =    1.e-4     !  maximum avs (vertical mixing on salinity)
+      rn_hsbfr =    1.6       !  heat/salt buoyancy flux ratio
+   !
+   !                       ! gravity wave-driven vertical mixing
+   ln_zdfiwm   = .false.      ! internal wave-induced mixing            (T =>   fill namzdf_iwm)
+   ln_zdfswm   = .false.      ! surface  wave-induced mixing            (T => ln_wave=ln_sdw=T )
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.2e-4     !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   1.2e-5     !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
+/
+!-----------------------------------------------------------------------
+&namzdf_ric    !   richardson number dependent vertical diffusion       (ln_zdfric =T)
 !-----------------------------------------------------------------------
    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")
+   ln_mldw     =  .false.  !  enhanced mixing in the Ekman layer
+      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
+/
+!-----------------------------------------------------------------------
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  (ln_zdftke =T)
 !-----------------------------------------------------------------------
    rn_ediff    =   0.1     !  coef. for vertical eddy coef. (avt=rn_ediff*mxl*sqrt(e) )
@@ -917,25 +930,25 @@
    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_pdl      =   1       !  Prandtl number function of richarson number (=1, avt=pdl(Ri)*avm) or not (=0, avt=avm)
    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)
+   !                       !                 = 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
    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_drg      = .false.   !  top/bottom friction added as boundary condition of TKE
    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_lc       =   0.15    !  coef. associated to Langmuir cells
+   nn_etau     =   1       !  penetration of tke below the mixed layer (ML) due to NIWs
+                              !        = 0 none ; = 1 add a tke source below the ML
+                              !        = 2 add a tke source just at the base of the ML
+                              !        = 3 as = 1 applied on HF part of the stress           (ln_cpl=T)
+      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                               (ln_zdfgls =T)
 !-----------------------------------------------------------------------
    rn_emin       = 1.e-7   !  minimum value of e   [m2/s2]
@@ -947,5 +960,5 @@
    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)
+   rn_frac_hs    =   1.3   !  Fraction of wave height as roughness (if nn_z0_met>1)
    nn_z0_met     =     2   !  Method for surface roughness computation (0/1/2/3)
    !                             ! =3 requires ln_wave=T
@@ -956,21 +969,24 @@
 /
 !-----------------------------------------------------------------------
-&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")
+&namzdf_osm                !   OSM vertical diffusion                   (ln_zdfosm =T)
+!-----------------------------------------------------------------------
+   ln_use_osm_la = .false.      !  Use namelist  rn_osm_la
+   rn_osm_la     = 0.3         !  Turbulent Langmuir number
+   rn_osm_dstokes     = 5.     !  Depth scale of Stokes drift (m)
+   nn_ave = 0                  ! choice of horizontal averaging on avt, avmu, avmv
+   ln_dia_osm = .true.         ! output OSMOSIS-OBL variables
+   rn_osm_hbl0 = 10.           ! initial hbl value
+   ln_kpprimix = .true.        ! Use KPP-style Ri# mixing below BL
+   rn_riinfty  = 0.7           ! Highest local Ri_g permitting shear instability
+   rn_difri  =  0.005          ! max Ri# diffusivity at Ri_g = 0 (m^2/s)
+   ln_convmix  = .true.        ! Use convective instability mixing below BL
+   rn_difconv = 1.             ! diffusivity when unstable below BL  (m2/s)
+   nn_osm_wave = 0             ! Method used to calculate Stokes drift
+                               !  = 2: Use ECMWF wave fields
+                               !  = 1: Pierson Moskowitz wave spectrum
+                               !  = 0: Constant La# = 0.3
+/
+!-----------------------------------------------------------------------
+&namzdf_iwm    !    internal wave-driven mixing parameterization        (ln_zdfiwm =T)
 !-----------------------------------------------------------------------
    nn_zpyc     = 1         !  pycnocline-intensified dissipation scales as N (=1) or N^2 (=2)
@@ -981,5 +997,5 @@
 !!                  ***  Miscellaneous namelists  ***
 !!======================================================================
-!!   nammpp            Massively Parallel Processing                    ("key_mpp_mpi)
+!!   nammpp            Massively Parallel Processing                    ("key_mpp_mpi")
 !!   namctl            Control prints 
 !!   namsto            Stochastic parametrization of EOS
@@ -987,8 +1003,8 @@
 !
 !-----------------------------------------------------------------------
-&nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi)
+&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.
+   !                       !  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
@@ -1008,6 +1024,6 @@
    nn_isplt    =    1      !  number of processors in i-direction
    nn_jsplt    =    1      !  number of processors in j-direction
-   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)
+   ln_timing   = .false.   !  timing by routine write out in timing.output file
+   ln_diacfl   = .false.   !  CFL diagnostics write out in cfl_diagnostics.ascii
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/namelist_top_ref
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/namelist_top_ref	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/SHARED/namelist_top_ref	(revision 9019)
@@ -61,6 +61,7 @@
 /
 !-----------------------------------------------------------------------
-&namtrc_adv      !   advection scheme for passive tracer 
+&namtrc_adv      !   advection scheme for passive tracer                (default: NO selection)
 !-----------------------------------------------------------------------
+   ln_trcadv_NONE=  .false.  !  No passive tracer advection
    ln_trcadv_cen =  .false.  !  2nd order centered scheme
       nn_cen_h   =  4               !  =2/4, horizontal 2nd order CEN / 4th order CEN
@@ -69,6 +70,4 @@
       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_trcadv_mus =  .false.  !  MUSCL scheme
       ln_mus_ups =  .false.         !  use upstream scheme near river mouths
@@ -93,10 +92,4 @@
    !
    rn_fact_lap      =     1.     !     enhanced zonal eddy diffusivity
-/
-!-----------------------------------------------------------------------
-&namtrc_zdf      !   vertical physics
-!-----------------------------------------------------------------------
-   ln_trczdf_exp =  .false.  !  split explicit (T) or implicit (F) time stepping
-   nn_trczdf_exp =   3       !  number of sub-timestep for ln_trczdfexp=T
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/EXP00/namelist_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/EXP00/namelist_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/EXP00/namelist_cfg	(revision 9019)
@@ -2,14 +2,4 @@
 !! NEMO/OPA  : ISOMIP Configuration namelist to overwrite reference dynamical namelist
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-!-----------------------------------------------------------------------
-&namusr_def    !   ISOMIP user defined namelist  
-!-----------------------------------------------------------------------
-   ln_zps      = .true.       ! z-partial-step coordinate
-   rn_lam0     =   0.0        !  longitude of first raw and column T-point (jphgr_msh = 1)
-   rn_phi0     = -80.0        ! latitude  of first raw and column T-point (jphgr_msh = 1)
-   rn_e1deg    =   0.3        !  zonal      grid-spacing (degrees)
-   rn_e2deg    =   0.1        !  meridional grid-spacing (degrees)
-   rn_e3       =   30.        !  vertical resolution
-/
 !-----------------------------------------------------------------------
 &namrun        !   parameters of the run
@@ -29,7 +19,4 @@
    ln_read_cfg = .false.   !  (=T) read the domain configuration file
       !                    !  (=F) user defined configuration  ==>>>  see usrdef(_...) modules
-      !
-   ln_write_cfg= .true.    !  (=T) create the domain configuration file
-   cn_domcfg_out = "ISOMIP_cfg_out" ! newly created domain configuration filename
 /
 !-----------------------------------------------------------------------
@@ -38,5 +25,5 @@
    ln_linssh   = .false.    !  =T  linear free surface  ==>>  model level are fixed in time
    !
-   nn_msh      =    1      !  create (>0) a mesh file or not (=0)
+   nn_msh      =    0      !  create (>0) a mesh file or not (=0)
    !
    rn_rdt      = 1800.     !  time step for the dynamics (and tracer if nn_acc=0)
@@ -64,7 +51,7 @@
                            !  =1 use observed ice-cover      , 
                            !  =2 ice-model used                
-   nn_ice_embd = 0         !  =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)
+   ln_ice_embd = .false.   !  =F levitating ice with mass and salt exchange but no presure effect
+                           !  =T embedded sea-ice (full salt and mass exchanges and pressure)
+                     ! Misc. options of sbc :
    ln_traqsr   = .false.   !  Light penetration (T) or not (F)
    ln_rnf      = .false.   !  runoffs                                   (T => fill namsbc_rnf)
@@ -179,25 +166,29 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    2      !  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)
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_non_lin = .true.    !  non-linear  drag: Cd = Cd0 |U|
+/
+!-----------------------------------------------------------------------
+&namdrg_top        !   TOP friction                                     (ln_isfcav=T)
+!-----------------------------------------------------------------------
+   rn_Cd0     =  2.5e-3    !  drag coefficient [-]
+   rn_Uc0     =  0.16      !  ref. velocity [m/s] (linear drag=Cd0*Uc0) 
+   rn_Cdmax   =  0.1       !  drag value maximum [-] (logarithmic drag)
+   rn_ke0     =  0.0e-0    !  background kinetic energy  [m2/s2] (non-linear cases)
+   rn_z0      =  3.0e-3    !  roughness [m] (ln_loglayer=T)
+   ln_boost   = .false.    !  =T regional boost of Cd0 ; =F constant
+      rn_boost=  50.          !  local boost factor  [-]
+/
+!-----------------------------------------------------------------------
+&namdrg_bot        !   BOTTOM friction                                  
+!-----------------------------------------------------------------------
+   rn_Cd0     =  1.e-3    !  drag coefficient [-]
+   rn_Uc0     =  0.4      !  ref. velocity [m/s] (linear drag=Cd0*Uc0) 
+   rn_Cdmax   =  0.1      !  drag value maximum [-] (logarithmic drag)
+   rn_ke0     =  2.5e-3   !  background kinetic energy  [m2/s2] (non-linear cases)
+   rn_z0      =  3.e-3    !  roughness [m] (ln_loglayer=T)
+   ln_boost   = .false.   !  =T regional boost of Cd0 ; =F constant
+      rn_boost=  50.         !  local boost factor  [-]
 /
 !-----------------------------------------------------------------------
@@ -217,5 +208,4 @@
    ln_teos10   = .false.         !  = Use TEOS-10 equation of state
    ln_eos80    = .true.          !  = Use EOS80 equation of state
-   !                             !  rd(T,S,Z)*rau0 = -a0*(1+.5*lambda*dT+mu*Z+nu*dS)*dT+b0*dS
 /
 !-----------------------------------------------------------------------
@@ -225,6 +215,4 @@
       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)
 /
 !-----------------------------------------------------------------------
@@ -275,4 +263,10 @@
 !-----------------------------------------------------------------------
 &namdyn_adv    !   formulation of the momentum advection
+!-----------------------------------------------------------------------
+   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
+/
 !-----------------------------------------------------------------------
 /
@@ -324,39 +318,32 @@
 /
 !-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.0e-3  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   5.0e-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     =    1      !  evd apply on tracer (=0) or on tracer and momentum (=1)
-   rn_avevd    =   0.1     !  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" )
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  ("key_zdftke")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_gls                !   GLS vertical diffusion                   ("key_zdfgls")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_ddm    !   double diffusive mixing parameterization             ("key_zdfddm")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_tmx    !   tidal mixing parameterization                        ("key_zdftmx")
-!-----------------------------------------------------------------------
-   ln_tmx_itf  = .false.   !  ITF specific parameterisation
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .true.       !  constant mixing
+   ln_zdfric   = .false.      !  local Richardson dependent formulation (T =>   fill namzdf_ric)
+   ln_zdftke   = .false.      !  Turbulent Kinetic Energy closure       (T =>   fill namzdf_tke)
+   ln_zdfgls   = .false.      !  Generic Length Scale closure           (T =>   fill namzdf_gls)
+   ln_zdfosm   = .false.      !  OSMOSIS BL closure                     (T =>   fill namzdf_osm)
+   !
+   !                       ! convection
+   ln_zdfevd   = .true.       !  enhanced vertical diffusion
+      nn_evdm     =    1         ! apply on tracer (=0) or on tracer and momentum (=1)
+      rn_evd      =   0.1        ! mixing coefficient [m2/s]
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+      nn_npc      =    1         ! frequency of application of npc
+      nn_npcp     =  365         ! npc control print frequency
+   !
+   ln_zdfddm   = .false.   ! double diffusive mixing
+   !
+   !                       ! gravity wave-driven vertical mixing
+   ln_zdfiwm   = .false.      ! internal wave-induced mixing            (T =>   fill namzdf_iwm)
+   ln_zdfswm   = .false.      ! surface  wave-induced mixing            (T => ln_wave=ln_sdw=T )
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.e-3     !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   5.e-5     !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
@@ -378,21 +365,9 @@
 /
 !-----------------------------------------------------------------------
-&namflo       !   float parameters                                      ("key_float")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namptr       !   Poleward Transport Diagnostic
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
 &namhsb       !  Heat and salt budgets
 !-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
-&namdct        ! transports through sections
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namobs       !  observation usage switch                               ('key_diaobs')
+&namobs       !  observation usage switch                               (ln_diaobs =T)
 !-----------------------------------------------------------------------
 /
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/MY_SRC/usrdef_hgr.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/MY_SRC/usrdef_hgr.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/MY_SRC/usrdef_hgr.F90	(revision 9019)
@@ -68,14 +68,14 @@
       IF( nn_timing == 1 )  CALL timing_start('usr_def_hgr')
       !
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'usr_def_hgr : ISOMIP configuration'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'usr_def_hgr : ISOMIP configuration'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*)
+         WRITE(numout,*) '   ===>>  geographical mesh on the sphere with regular grid-spacing'
+         WRITE(numout,*) '          given by rn_e1deg and rn_e2deg'
+      ENDIF
       !
-      !                       !==  grid point position  ==!   (in kilometers)
-
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) '          geographical mesh on the sphere with regular grid-spacing'
-      IF(lwp) WRITE(numout,*) '          given by rn_e1deg and rn_e2deg'
-
+      !                       !==  grid point position  ==!   (in degrees)
       DO jj = 1, jpj
          DO ji = 1, jpi
@@ -94,4 +94,5 @@
             pphiv(ji,jj) = rn_phi0 + rn_e2deg * zvj
             pphif(ji,jj) = rn_phi0 + rn_e2deg * zfj
+            
      !                       !==  Horizontal scale factors  ==!   (in meters)
      ! e1
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/MY_SRC/usrdef_sbc.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/MY_SRC/usrdef_sbc.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/MY_SRC/usrdef_sbc.F90	(revision 9019)
@@ -17,4 +17,5 @@
    USE dom_oce         ! ocean space and time domain
    USE sbc_oce         ! Surface boundary condition: ocean fields
+   USE sbc_ice         ! Surface boundary condition: ice fields
    USE phycst          ! physical constants
    !
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/cpp_ISOMIP.fcm
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/cpp_ISOMIP.fcm	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/cpp_ISOMIP.fcm	(revision 9019)
@@ -1,1 +1,1 @@
- bld::tool::fppkeys key_zdfcst key_iomput key_mpp_mpi key_nosignedzero 
+ bld::tool::fppkeys   key_iomput key_mpp_mpi key_nosignedzero 
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_flux_cen2_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_flux_cen2_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_flux_cen2_cfg	(revision 9019)
@@ -68,16 +68,7 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.    !  free-slip       : Cd = 0                  
 /
 !-----------------------------------------------------------------------
@@ -104,6 +95,4 @@
       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
@@ -119,5 +108,6 @@
 &namtra_ldf    !   lateral diffusion scheme for tracers
 !-----------------------------------------------------------------------
-   !                       !  Operator type:    both false = No lateral diffusion
+   !                       !  Operator type:
+   ln_traldf_NONE  =  .true.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -139,5 +129,4 @@
    ln_dynadv_cen2= .true.  !  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
 /
 !-----------------------------------------------------------------------
@@ -197,11 +186,22 @@
    rn_bhm_0      =     1.e+12  !  horizontal bilaplacian eddy viscosity [m4/s]
 /
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .true.       !  constant mixing
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.e-4      !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   0.e0       !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_flux_ubs_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_flux_ubs_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_flux_ubs_cfg	(revision 9019)
@@ -68,16 +68,7 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.    !  free-slip       : Cd = 0                  
 /
 !-----------------------------------------------------------------------
@@ -104,6 +95,4 @@
       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
@@ -119,5 +108,6 @@
 &namtra_ldf    !   lateral diffusion scheme for tracers
 !-----------------------------------------------------------------------
-   !                       !  Operator type:    both false = No lateral diffusion
+  !                       !  Operator type:
+   ln_traldf_NONE  =  .true.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -139,5 +129,4 @@
    ln_dynadv_cen2= .false. !  flux form - 2nd order centered scheme
    ln_dynadv_ubs = .true.  !  flux form - 3rd order UBS      scheme
-   ln_dynzad_zts = .false. !  Use (T) sub timestepping for vertical momentum advection
 /
 !-----------------------------------------------------------------------
@@ -177,15 +166,15 @@
 !-----------------------------------------------------------------------
    !                       !  Type of the operator :
-   !                           !  no diffusion: set ln_dynldf_lap=..._blp=F 
+   ln_dynldf_NONE=  .true.    !  No operator (i.e. no explicit diffusion)
    ln_dynldf_lap =  .false.    !    laplacian operator
    ln_dynldf_blp =  .false.    !  bilaplacian operator
    !                       !  Direction of action  :
-   ln_dynldf_lev =  .false.     !  iso-level
+   ln_dynldf_lev =  .false.    !  iso-level
    ln_dynldf_hor =  .true.    !  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
+   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
@@ -193,15 +182,32 @@
    !                                !  = 30  F(i,j,k)=c2d*c1d
    !                                !  = 31  F(i,j,k)=F(grid spacing and local velocity)
+   !                                !  = 32  F(i,j,k)=F(local gridscale and deformation rate)
+   ! Caution in 20 and 30 cases the coefficient have to be given for a 1 degree grid (~111km)
    rn_ahm_0      =     0.01    !  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]
-/
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
+   !                       !  Smagorinsky settings (nn_ahm_ijk_t  = 32) :
+   rn_csmc       = 3.5         !  Smagorinsky constant of proportionality
+   rn_minfac     = 1.0         !  multiplier of theorectical lower limit
+   rn_maxfac     = 1.0         !  multiplier of theorectical upper limit
+/
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .true.       !  constant mixing
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.e-4      !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   0.e0       !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_vect_eenH_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_vect_eenH_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_vect_eenH_cfg	(revision 9019)
@@ -68,16 +68,7 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.    !  free-slip       : Cd = 0                  
 /
 !-----------------------------------------------------------------------
@@ -104,6 +95,4 @@
       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
@@ -119,5 +108,6 @@
 &namtra_ldf    !   lateral diffusion scheme for tracers
 !-----------------------------------------------------------------------
-   !                       !  Operator type:    both false = No lateral diffusion
+   !                       !  Operator type:
+   ln_traldf_NONE  =  .true.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -139,5 +129,4 @@
    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
 /
 !-----------------------------------------------------------------------
@@ -197,11 +186,22 @@
    rn_bhm_0      =     1.e+12  !  horizontal bilaplacian eddy viscosity [m4/s]
 /
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .true.       !  constant mixing
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.e-4      !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   0.e0       !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_vect_een_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_vect_een_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_vect_een_cfg	(revision 9019)
@@ -68,16 +68,7 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.    !  free-slip       : Cd = 0                  
 /
 !-----------------------------------------------------------------------
@@ -104,6 +95,4 @@
       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
@@ -119,5 +108,6 @@
 &namtra_ldf    !   lateral diffusion scheme for tracers
 !-----------------------------------------------------------------------
-   !                       !  Operator type:    both false = No lateral diffusion
+   !                       !  Operator type:
+   ln_traldf_NONE  =  .true.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -139,5 +129,4 @@
    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
 /
 !-----------------------------------------------------------------------
@@ -197,11 +186,22 @@
    rn_bhm_0      =     1.e+12  !  horizontal bilaplacian eddy viscosity [m4/s]
 /
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .true.       !  constant mixing
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.e-4      !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   0.e0       !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_vect_ene_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_vect_ene_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_vect_ene_cfg	(revision 9019)
@@ -68,16 +68,7 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.    !  free-slip       : Cd = 0                  
 /
 !-----------------------------------------------------------------------
@@ -104,6 +95,4 @@
       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
@@ -119,5 +108,6 @@
 &namtra_ldf    !   lateral diffusion scheme for tracers
 !-----------------------------------------------------------------------
-   !                       !  Operator type:    both false = No lateral diffusion
+  !                       !  Operator type:
+   ln_traldf_NONE  =  .true.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -139,5 +129,4 @@
    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
 /
 !-----------------------------------------------------------------------
@@ -197,11 +186,22 @@
    rn_bhm_0      =     1.e+12  !  horizontal bilaplacian eddy viscosity [m4/s]
 /
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .true.       !  constant mixing
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.e-4      !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   0.e0       !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_vect_ens_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_vect_ens_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT2_vect_ens_cfg	(revision 9019)
@@ -68,16 +68,7 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.    !  free-slip       : Cd = 0                  
 /
 !-----------------------------------------------------------------------
@@ -104,6 +95,4 @@
       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
@@ -119,5 +108,6 @@
 &namtra_ldf    !   lateral diffusion scheme for tracers
 !-----------------------------------------------------------------------
-   !                       !  Operator type:    both false = No lateral diffusion
+  !                       !  Operator type:
+   ln_traldf_NONE  =  .true.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -139,5 +129,4 @@
    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
 /
 !-----------------------------------------------------------------------
@@ -197,11 +186,22 @@
    rn_bhm_0      =     1.e+12  !  horizontal bilaplacian eddy viscosity [m4/s]
 /
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .true.       !  constant mixing
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.e-4      !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   0.e0       !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_flux_cen2_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_flux_cen2_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_flux_cen2_cfg	(revision 9019)
@@ -68,16 +68,7 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.    !  free-slip       : Cd = 0                  
 /
 !-----------------------------------------------------------------------
@@ -104,6 +95,4 @@
       nn_fct_h   =  4            !  =2/4, horizontal 2nd / 4th order
       nn_fct_v   =  4            !  =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
@@ -119,5 +108,6 @@
 &namtra_ldf    !   lateral diffusion scheme for tracers
 !-----------------------------------------------------------------------
-   !                       !  Operator type:    both false = No lateral diffusion
+  !                       !  Operator type:
+   ln_traldf_NONE  =  .true.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -139,5 +129,4 @@
    ln_dynadv_cen2= .true.  !  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
 /
 !-----------------------------------------------------------------------
@@ -197,11 +186,22 @@
    rn_bhm_0      =     1.e+12  !  horizontal bilaplacian eddy viscosity [m4/s]
 /
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .true.       !  constant mixing
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.e-4      !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   0.e0       !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_flux_ubs_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_flux_ubs_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_flux_ubs_cfg	(revision 9019)
@@ -68,16 +68,7 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.    !  free-slip       : Cd = 0                  
 /
 !-----------------------------------------------------------------------
@@ -104,6 +95,4 @@
       nn_fct_h   =  4            !  =2/4, horizontal 2nd / 4th order
       nn_fct_v   =  4            !  =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
@@ -119,5 +108,6 @@
 &namtra_ldf    !   lateral diffusion scheme for tracers
 !-----------------------------------------------------------------------
-   !                       !  Operator type:    both false = No lateral diffusion
+  !                       !  Operator type:
+   ln_traldf_NONE  =  .true.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -139,5 +129,4 @@
    ln_dynadv_cen2= .false. !  flux form - 2nd order centered scheme
    ln_dynadv_ubs = .true.  !  flux form - 3rd order UBS      scheme
-   ln_dynzad_zts = .false. !  Use (T) sub timestepping for vertical momentum advection
 /
 !-----------------------------------------------------------------------
@@ -177,15 +166,15 @@
 !-----------------------------------------------------------------------
    !                       !  Type of the operator :
-   !                           !  no diffusion: set ln_dynldf_lap=..._blp=F 
+   ln_dynldf_NONE=  .true.    !  No operator (i.e. no explicit diffusion)
    ln_dynldf_lap =  .false.    !    laplacian operator
    ln_dynldf_blp =  .false.    !  bilaplacian operator
    !                       !  Direction of action  :
-   ln_dynldf_lev =  .false.     !  iso-level
+   ln_dynldf_lev =  .false.    !  iso-level
    ln_dynldf_hor =  .true.    !  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
+   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
@@ -193,15 +182,32 @@
    !                                !  = 30  F(i,j,k)=c2d*c1d
    !                                !  = 31  F(i,j,k)=F(grid spacing and local velocity)
+   !                                !  = 32  F(i,j,k)=F(local gridscale and deformation rate)
+   ! Caution in 20 and 30 cases the coefficient have to be given for a 1 degree grid (~111km)
    rn_ahm_0      =     0.01    !  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]
-/
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
+   !                       !  Smagorinsky settings (nn_ahm_ijk_t  = 32) :
+   rn_csmc       = 3.5         !  Smagorinsky constant of proportionality
+   rn_minfac     = 1.0         !  multiplier of theorectical lower limit
+   rn_maxfac     = 1.0         !  multiplier of theorectical upper limit
+/
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .true.       !  constant mixing
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.e-4      !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   0.e0       !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_vect_eenH_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_vect_eenH_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_vect_eenH_cfg	(revision 9019)
@@ -68,16 +68,7 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.    !  free-slip       : Cd = 0                  
 /
 !-----------------------------------------------------------------------
@@ -104,6 +95,4 @@
       nn_fct_h   =  4            !  =2/4, horizontal 2nd / 4th order
       nn_fct_v   =  4            !  =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
@@ -119,5 +108,6 @@
 &namtra_ldf    !   lateral diffusion scheme for tracers
 !-----------------------------------------------------------------------
-   !                       !  Operator type:    both false = No lateral diffusion
+  !                       !  Operator type:
+   ln_traldf_NONE  =  .true.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -139,5 +129,4 @@
    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
 /
 !-----------------------------------------------------------------------
@@ -197,11 +186,22 @@
    rn_bhm_0      =     1.e+12  !  horizontal bilaplacian eddy viscosity [m4/s]
 /
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .true.       !  constant mixing
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.e-4      !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   0.e0       !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_vect_een_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_vect_een_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_vect_een_cfg	(revision 9019)
@@ -68,16 +68,7 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.    !  free-slip       : Cd = 0                  
 /
 !-----------------------------------------------------------------------
@@ -104,6 +95,4 @@
       nn_fct_h   =  4            !  =2/4, horizontal 2nd / 4th order
       nn_fct_v   =  4            !  =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
@@ -119,5 +108,6 @@
 &namtra_ldf    !   lateral diffusion scheme for tracers
 !-----------------------------------------------------------------------
-   !                       !  Operator type:    both false = No lateral diffusion
+  !                       !  Operator type:
+   ln_traldf_NONE  =  .true.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -139,5 +129,4 @@
    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
 /
 !-----------------------------------------------------------------------
@@ -197,11 +186,22 @@
    rn_bhm_0      =     1.e+12  !  horizontal bilaplacian eddy viscosity [m4/s]
 /
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .true.       !  constant mixing
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.e-4      !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   0.e0       !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_vect_ene_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_vect_ene_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_vect_ene_cfg	(revision 9019)
@@ -68,16 +68,7 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.    !  free-slip       : Cd = 0                  
 /
 !-----------------------------------------------------------------------
@@ -104,6 +95,4 @@
       nn_fct_h   =  4            !  =2/4, horizontal 2nd / 4th order
       nn_fct_v   =  4            !  =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
@@ -119,5 +108,6 @@
 &namtra_ldf    !   lateral diffusion scheme for tracers
 !-----------------------------------------------------------------------
-   !                       !  Operator type:    both false = No lateral diffusion
+  !                       !  Operator type:
+   ln_traldf_NONE  =  .true.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -139,5 +129,4 @@
    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
 /
 !-----------------------------------------------------------------------
@@ -197,11 +186,22 @@
    rn_bhm_0      =     1.e+12  !  horizontal bilaplacian eddy viscosity [m4/s]
 /
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .true.       !  constant mixing
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.e-4      !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   0.e0       !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_vect_ens_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_vect_ens_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_FCT4_vect_ens_cfg	(revision 9019)
@@ -68,16 +68,7 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.    !  free-slip       : Cd = 0                  
 /
 !-----------------------------------------------------------------------
@@ -104,6 +95,4 @@
       nn_fct_h   =  4            !  =2/4, horizontal 2nd / 4th order
       nn_fct_v   =  4            !  =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
@@ -119,5 +108,6 @@
 &namtra_ldf    !   lateral diffusion scheme for tracers
 !-----------------------------------------------------------------------
-   !                       !  Operator type:    both false = No lateral diffusion
+  !                       !  Operator type:
+   ln_traldf_NONE  =  .true.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -139,5 +129,4 @@
    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
 /
 !-----------------------------------------------------------------------
@@ -197,11 +186,22 @@
    rn_bhm_0      =     1.e+12  !  horizontal bilaplacian eddy viscosity [m4/s]
 /
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .true.       !  constant mixing
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.e-4      !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   0.e0       !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/namelist_cfg	(revision 9019)
@@ -1,214 +1,1 @@
-!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-!! NEMO/OPA  Configuration namelist : used to overwrite defaults values defined in SHARED/namelist_ref
-!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-!
-!-----------------------------------------------------------------------
-&namusr_def    !   LOCK_EXCHANGE user defined namelist
-!-----------------------------------------------------------------------
-   rn_dx       =    500.   ! horizontal resolution in meters
-   rn_dz       =      1.   ! vertical   resolution in meters
-/
-!
-!-----------------------------------------------------------------------
-&namrun        !   parameters of the run
-!-----------------------------------------------------------------------
-   nn_no       =       0   !  job number (no more used...)
-   cn_exp      =   "LOCK_FCT2_flux_ubs"  !  experience name
-   nn_it000    =       1   !  first time step
-   nn_itend    =   61200   ! for 17h of simulation  (=61200 time-step)
-   nn_istate   =       0   !  output the initial state (1) or not (0)
-   nn_stock    =   61200   !  frequency of creation of a restart file (modulo referenced to 1)
-   nn_write    =   61200   !  frequency of write in the output file   (modulo referenced to nn_it000)
-/
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-   ln_read_cfg = .false.   !  (=T) read the domain configuration file
-      !                    !  (=F) user defined configuration  ==>>>  see usrdef(_...) modules
-   ln_write_cfg= .false.   !  (=T) create the domain configuration file
-/
-!-----------------------------------------------------------------------
-&namdom        !   space and time domain (bathymetry, mesh, timestep)
-!-----------------------------------------------------------------------
-   ln_linssh   = .false.   !  =T  linear free surface  ==>>  model level are fixed in time
-   nn_closea   =    1      !  remove (=0) or keep (=1) closed seas and lakes (ORCA)
-   !
-   nn_msh      =    1      !  create (>0) a mesh file or not (=0)
-   rn_isfhmin  =    0.00   !  treshold (m) to discriminate grounding ice to floating ice
-   !
-   rn_rdt      =    1.     !  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
-/
-!-----------------------------------------------------------------------
-&namtsd    !   data : Temperature  & Salinity
-!-----------------------------------------------------------------------
-   ln_tsd_init   = .false.   !  Initialisation of ocean T & S with T &S input data (T) or not (F)
-   ln_tsd_tradmp = .false.   !  damping of ocean T & S toward T &S input data (T) or not (F)
-/
-!-----------------------------------------------------------------------
-&namsbc        !   Surface Boundary Condition (surface module)
-!-----------------------------------------------------------------------
-  nn_fsbc     = 1         !  frequency of surface boundary condition computation
-                          !     (also = the frequency of sea-ice & iceberg model call)
-  ln_usr      = .true.    !  user defined formulation                  (T => check usrdef_sbc)
-  ln_blk      = .false.   !  Bulk formulation                          (T => fill namsbc_blk )
-  nn_ice      = 0         !  =0 no ice boundary condition   
-  ln_traqsr   = .false.   !  Light penetration in the ocean            (T => fill namtra_qsr )
-  ln_rnf      = .false.   !  runoffs                                   (T => fill namsbc_rnf)
-  ln_ssr      = .false.   !  Sea Surface Restoring on T and/or S       (T => fill namsbc_ssr)
-  nn_fwb      = 0         !  FreshWater Budget: =0 unchecked
-/
-!-----------------------------------------------------------------------
-&namlbc        !   lateral momentum boundary condition
-!-----------------------------------------------------------------------
-!                         !  free slip  !   partial slip  !   no slip   ! strong slip
-  rn_shlat    =    0.     !  shlat = 0  !  0 < shlat < 2  !  shlat = 2  !  2 < shlat
-/
-!-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nameos        !   ocean physical parameters
-!-----------------------------------------------------------------------
-   ln_seos     = .true.         !  = Use simplified equation of state (S-EOS)
-   !                     ! S-EOS coefficients (nn_eos=1):
-   !                          !  rd(T,S,Z)*rau0 = -a0*(1+.5*lambda*dT+mu*Z+nu*dS)*dT+b0*dS
-   rn_a0       =  0.2         !  thermal expension coefficient (nn_eos= 1)
-   rn_b0       =  0.          !  saline  expension coefficient (nn_eos= 1)
-   rn_lambda1  =  0.          !  cabbeling coeff in T^2  (=0 for linear eos)
-   rn_lambda2  =  0.          !  cabbeling coeff in S^2  (=0 for linear eos)
-   rn_mu1      =  0.          !  thermobaric coeff. in T (=0 for linear eos)
-   rn_mu2      =  0.          !  thermobaric coeff. in S (=0 for linear eos)
-   rn_nu       =  0.          !  cabbeling coeff in T*S  (=0 for linear eos)
-/
-!-----------------------------------------------------------------------
-&namtra_adv    !   advection scheme for tracer
-!-----------------------------------------------------------------------
-   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 = .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)
-   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)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namtra_ldf    !   lateral diffusion scheme for tracers
-!-----------------------------------------------------------------------
-   !                       !  Operator type:    both false = No lateral diffusion
-   ln_traldf_lap   =  .false.  !    laplacian operator
-   ln_traldf_blp   =  .false.  !  bilaplacian operator
-/
-!-----------------------------------------------------------------------
-&namtra_ldfeiv !   eddy induced velocity param.                         (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namtra_dmp    !   tracer: T & S newtonian damping                       (default: YES)
-!-----------------------------------------------------------------------
-   ln_tradmp   =  .false.   !  add a damping termn (T) or not (F)
-/
-!-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection
-!-----------------------------------------------------------------------
-   ln_dynadv_vec = .false. !  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 = .true.  !  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
-/
-!-----------------------------------------------------------------------
-&namdyn_vor    !   option of physics/algorithm
-!-----------------------------------------------------------------------
-   ln_dynvor_ene = .false. !  enstrophy conserving scheme
-   ln_dynvor_ens = .true.  !  energy conserving scheme
-   ln_dynvor_mix = .false. !  mixed scheme
-   ln_dynvor_een = .false. !  energy & enstrophy scheme
-      nn_een_e3f = 0             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
-/
-!-----------------------------------------------------------------------
-&namdyn_hpg    !   Hydrostatic pressure gradient option
-!-----------------------------------------------------------------------
-   ln_hpg_zps  = .false.  !  z-coordinate - partial steps (interpolation)
-   ln_hpg_sco  = .true.   !  s-coordinate (standard jacobian formulation)
-/
-!-----------------------------------------------------------------------
-&namdyn_spg    !   Surface pressure gradient
-!-----------------------------------------------------------------------
-   ln_dynspg_ts  = .true.   ! 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:
-         nn_baro      =  1         ! =F : the number of sub-step in rn_rdt seconds
-/
-!-----------------------------------------------------------------------
-&namdyn_ldf    !   lateral diffusion on momentum
-!-----------------------------------------------------------------------
-   !                       !  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 =  .true.    !  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      =     0.01    !  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]
-/
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
-/
-!-----------------------------------------------------------------------
-&nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namctl        !   Control prints & Benchmark
-!-----------------------------------------------------------------------
-/
+link namelist_FCT2_flux_ubs_cfg
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/MY_SRC/usrdef_sbc.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/MY_SRC/usrdef_sbc.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/MY_SRC/usrdef_sbc.F90	(revision 9019)
@@ -16,4 +16,5 @@
    USE dom_oce         ! ocean space and time domain
    USE sbc_oce         ! Surface boundary condition: ocean fields
+   USE sbc_ice         ! Surface boundary condition: ice fields
    USE phycst          ! physical constants
    !
Index: anches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/MY_SRC/zdfini.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/MY_SRC/zdfini.F90	(revision 9018)
+++ 	(revision )
@@ -1,183 +1,0 @@
-MODULE zdfini
-   !!======================================================================
-   !!                     ***  MODULE zdfini  ***
-   !!
-   !!                     ===  LOCK_EXCHANGE case  ===
-   !!
-   !! Ocean physics :   read vertical mixing namelist and check consistancy
-   !!======================================================================
-   !! History :  8.0  ! 1997-06  (G. Madec)  Original code from inimix
-   !!            1.0  ! 2002-08  (G. Madec)  F90 : free form
-   !!             -   ! 2005-06  (C. Ethe) KPP scheme
-   !!             -   ! 2009-07  (G. Madec) add avmb, avtb in restart for cen2 advection
-   !!            3.7  ! 2014-12  (G. Madec) remove KPP scheme
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   zdf_init    : initialization, namelist read, and parameters control
-   !!----------------------------------------------------------------------
-   USE par_oce         ! mesh and scale factors
-   USE zdf_oce         ! TKE vertical mixing          
-   USE sbc_oce         ! surface module (only for nn_isf in the option compatibility test)
-   USE zdftke          ! TKE vertical mixing
-   USE zdfgls          ! GLS vertical mixing
-   USE zdfric          ! Richardson vertical mixing   
-   USE zdfddm          ! double diffusion mixing      
-   USE zdfevd          ! enhanced vertical diffusion  
-   USE tranpc          ! convection: non penetrative adjustment
-   USE ldfslp          ! iso-neutral slopes
-   !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! IOM library
-   USE lib_mpp         ! distribued memory computing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   zdf_init   ! routine called by opa.F90
-   
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE zdf_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE zdf_init  ***
-      !! 
-      !! ** Purpose :   initializations of the vertical ocean physics
-      !!
-      !! ** Method  :   Read namelist namzdf, control logicals 
-      !!----------------------------------------------------------------------
-      INTEGER ::   ioptio, ios       ! local integers
-      !!
-      NAMELIST/namzdf/ rn_avm0, rn_avt0, nn_avb, nn_havtb, ln_zdfexp, nn_zdfexp,   &
-         &              ln_zdfevd, nn_evdm, rn_avevd, ln_zdfnpc, nn_npc, nn_npcp,  &
-         &              ln_zdfqiao
-      !!----------------------------------------------------------------------
-
-      REWIND( numnam_ref )              ! Namelist namzdf in reference namelist : Vertical mixing parameters
-      READ  ( numnam_ref, namzdf, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf in reference namelist', lwp )
-
-      REWIND( numnam_cfg )              ! Namelist namzdf in reference namelist : Vertical mixing parameters
-      READ  ( numnam_cfg, namzdf, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf in configuration namelist', lwp )
-      IF(lwm) WRITE ( numond, namzdf )
-
-      IF(lwp) THEN               !* Parameter print
-         WRITE(numout,*)
-         WRITE(numout,*) 'zdf_init: vertical physics'
-         WRITE(numout,*) '~~~~~~~~'
-         WRITE(numout,*) '   Namelist namzdf : set vertical mixing mixing parameters'
-         WRITE(numout,*) '      vertical eddy viscosity             rn_avm0   = ', rn_avm0
-         WRITE(numout,*) '      vertical eddy diffusivity           rn_avt0   = ', rn_avt0
-         WRITE(numout,*) '      constant background or profile      nn_avb    = ', nn_avb
-         WRITE(numout,*) '      horizontal variation for avtb       nn_havtb  = ', nn_havtb
-         WRITE(numout,*) '      time splitting / backward scheme    ln_zdfexp = ', ln_zdfexp
-         WRITE(numout,*) '      number of time step                 nn_zdfexp = ', nn_zdfexp
-         WRITE(numout,*) '      enhanced vertical diffusion         ln_zdfevd = ', ln_zdfevd
-         WRITE(numout,*) '         applied on momentum (=1/0)       nn_evdm   = ', nn_evdm
-         WRITE(numout,*) '      vertical coefficient for evd        rn_avevd  = ', rn_avevd
-         WRITE(numout,*) '      non-penetrative convection (npc)    ln_zdfnpc = ', ln_zdfnpc
-         WRITE(numout,*) '      npc call  frequency                 nn_npc    = ', nn_npc
-         WRITE(numout,*) '      npc print frequency                 nn_npcp   = ', nn_npcp
-      ENDIF
-
-      !                          !* Parameter & logical controls
-      !                          !  ----------------------------
-      !
-      !                               ! ... check of vertical mixing scheme on tracers
-      !                                              ==> will be done in trazdf module
-      !
-      !                               ! ... check of mixing coefficient
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) '   vertical mixing option :'
-      ioptio = 0
-      IF( lk_zdfcst ) THEN
-         IF(lwp) WRITE(numout,*) '      constant eddy diffusion coefficients'
-         ioptio = ioptio+1
-      ENDIF
-      IF( lk_zdfric ) THEN
-         IF(lwp) WRITE(numout,*) '      Richardson dependent eddy coefficients'
-         ioptio = ioptio+1
-      ENDIF
-      IF( lk_zdftke ) THEN
-         IF(lwp) WRITE(numout,*) '      TKE dependent eddy coefficients'
-         ioptio = ioptio+1
-      ENDIF
-      IF( lk_zdfgls ) THEN
-         IF(lwp) WRITE(numout,*) '      GLS dependent eddy coefficients'
-         ioptio = ioptio+1
-      ENDIF
-      IF( ioptio == 0 .OR. ioptio > 1 )   &
-         &   CALL ctl_stop( ' one and only one vertical diffusion option has to be defined ' )
-      IF( ( lk_zdfric .OR. lk_zdfgls ) .AND. ln_isfcav )   &
-         &   CALL ctl_stop( ' only zdfcst and zdftke were tested with ice shelves cavities ' )
-      !
-      !                               ! ... Convection
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) '   convection :'
-      !
-#if defined key_top
-      IF( ln_zdfnpc )   CALL ctl_stop( ' zdf_init: npc scheme is not working with key_top' )
-#endif
-      !
-      ioptio = 0
-      IF( ln_zdfnpc ) THEN
-         IF(lwp) WRITE(numout,*) '      use non penetrative convective scheme'
-         ioptio = ioptio+1
-      ENDIF
-      IF( ln_zdfevd ) THEN
-         IF(lwp) WRITE(numout,*) '      use enhanced vertical dif. scheme'
-         ioptio = ioptio+1
-      ENDIF
-      IF( lk_zdftke ) THEN
-         IF(lwp) WRITE(numout,*) '      use the 1.5 turbulent closure'
-      ENDIF
-      IF( lk_zdfgls ) THEN
-         IF(lwp) WRITE(numout,*) '      use the GLS closure scheme'
-      ENDIF
-      IF ( ioptio > 1 )   CALL ctl_stop( ' chose between ln_zdfnpc and ln_zdfevd' )
-      IF( ioptio == 0 .AND. .NOT.( lk_zdftke .OR. lk_zdfgls ) )           &
-         !SF CALL ctl_stop( ' except for TKE or GLS physics, a convection scheme is',   &
-         CALL ctl_warn( ' except for TKE or GLS physics, a convection scheme is',   &
-         &              ' required: ln_zdfevd or ln_zdfnpc logicals' )
-
-      !                               !* Background eddy viscosity and diffusivity profil
-      IF( nn_avb == 0 ) THEN                ! Define avmb, avtb from namelist parameter
-         avmb(:) = rn_avm0
-         avtb(:) = rn_avt0                     
-      ELSE                                  ! Background profile of avt (fit a theoretical/observational profile (Krauss 1990)
-         avmb(:) = rn_avm0
-         avtb(:) = rn_avt0 + ( 3.e-4_wp - 2._wp * rn_avt0 ) * 1.e-4_wp * gdepw_1d(:)   ! m2/s
-         IF(ln_sco .AND. lwp)   CALL ctl_warn( 'avtb profile not valid in sco' )
-      ENDIF
-      !
-      IF( ln_rstart ) THEN                  !  Read avmb, avtb in restart (if exist)
-         ! if ln_traadv_cen, avmb, avtb have been modified in traadv_cen2 module. 
-         ! To ensure the restartability, avmb & avtb are written in the restart 
-         ! file in traadv_cen2 end read here. 
-         IF( iom_varid( numror, 'avmb', ldstop = .FALSE. ) > 0 ) THEN
-            CALL iom_get( numror, jpdom_unknown, 'avmb', avmb )
-            CALL iom_get( numror, jpdom_unknown, 'avtb', avtb )
-         ENDIF
-      ENDIF
-      !                                     ! 2D shape of the avtb
-      avtb_2d(:,:) = 1.e0                        ! uniform 
-      !
-      IF( nn_havtb == 1 ) THEN                   ! decrease avtb in the equatorial band
-           !  -15S -5S : linear decrease from avt0 to avt0/10.
-           !  -5S  +5N : cst value avt0/10.
-           !   5N  15N : linear increase from avt0/10, to avt0
-           WHERE(-15. <= gphit .AND. gphit < -5 )   avtb_2d = (1.  - 0.09 * (gphit + 15.))
-           WHERE( -5. <= gphit .AND. gphit <  5 )   avtb_2d =  0.1
-           WHERE(  5. <= gphit .AND. gphit < 15 )   avtb_2d = (0.1 + 0.09 * (gphit -  5.))
-      ENDIF
-      !
-   END SUBROUTINE zdf_init
-
-   !!======================================================================
-END MODULE zdfini
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/cpp_LOCK_EXCHANGE.fcm
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/cpp_LOCK_EXCHANGE.fcm	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/cpp_LOCK_EXCHANGE.fcm	(revision 9019)
@@ -1,1 +1,1 @@
- bld::tool::fppkeys key_zdfcst key_iomput key_mpp_mpi key_nosignedzero
+ bld::tool::fppkeys   key_iomput key_mpp_mpi key_nosignedzero
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_cfg	(revision 9019)
@@ -1,207 +1,1 @@
-!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-!! NEMO/OPA  Configuration namelist : used to overwrite defaults values defined in SHARED/namelist_ref
-!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-!
-!-----------------------------------------------------------------------
-&namusr_def    !   User defined :   OVERFLOW configuration 
-!-----------------------------------------------------------------------
-   !                       !  type of vertical coordinate
-   ln_zco      = .false.      ! z-coordinate
-   ln_zps      = .true.       ! z-partial-step coordinate
-   ln_sco      = .false.      ! s-coordinate   
-   rn_dx       =   1000.   !  horizontal resolution   [meters]
-   rn_dz       =     20.   !  vertical   resolution   [meters]
-/
-!
-!-----------------------------------------------------------------------
-&namrun        !   parameters of the run
-!-----------------------------------------------------------------------
-   nn_no       =       0   !  job number (no more used...)
-   cn_exp      =   "OVF_FCT2_flux_ubs"  !  experience name
-   nn_it000    =       1   !  first time step
-   !nn_itend    =    6120  ! here 17h of simulation  (=6120 time-step) abort after 5802 for zps: pb of physiques conditions 
-   nn_itend    =    5760   ! here 16h of simulation  (=5760 time-step) 
-   nn_istate   =       0   !  output the initial state (1) or not (0)
-   nn_stock    =    5760   !  frequency of creation of a restart file (modulo referenced to 1)
-   nn_write    =    5760   !  frequency of write in the output file   (modulo referenced to nn_it000)
-/
-!-----------------------------------------------------------------------
-&namcfg        !   parameters of the configuration
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namdom        !   space and time domain (bathymetry, mesh, timestep)
-!-----------------------------------------------------------------------
-   rn_rdt      =   10.     !  time step for the dynamics (and tracer if nn_acc=0)
-   rn_atfp     =    0.1    !  asselin time filter parameter
-/
-!-----------------------------------------------------------------------
-&namtsd    !   data : Temperature  & Salinity
-!-----------------------------------------------------------------------
-   ln_tsd_init   = .false.   !  Initialisation of ocean T & S with T &S input data (T) or not (F)
-   ln_tsd_tradmp = .false.   !  damping of ocean T & S toward T &S input data (T) or not (F)
-/
-!-----------------------------------------------------------------------
-&namsbc        !   Surface Boundary Condition (surface module)
-!-----------------------------------------------------------------------
-  nn_fsbc     = 1         !  frequency of surface boundary condition computation
-                          !     (also = the frequency of sea-ice & iceberg model call)
-  ln_usr      = .true.    !  user defined formulation                  (T => check usrdef_sbc)
-  ln_blk      = .false.   !  Bulk formulation                          (T => fill namsbc_blk )
-  nn_ice      = 0         !  =0 no ice boundary condition   
-  ln_traqsr   = .false.   !  Light penetration in the ocean            (T => fill namtra_qsr )
-  ln_rnf      = .false.   !  runoffs                                   (T => fill namsbc_rnf)
-  ln_ssr      = .false.   !  Sea Surface Restoring on T and/or S       (T => fill namsbc_ssr)
-  nn_fwb      = 0         !  FreshWater Budget: =0 unchecked
-/
-!-----------------------------------------------------------------------
-&namlbc        !   lateral momentum boundary condition
-!-----------------------------------------------------------------------
-!                         !  free slip  !   partial slip  !   no slip   ! strong slip
-  rn_shlat    =    0.     !  shlat = 0  !  0 < shlat < 2  !  shlat = 2  !  2 < shlat
-/
-!-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nameos        !   ocean physical parameters
-!-----------------------------------------------------------------------
-   ln_seos     = .true.         !  = Use simplified equation of state (S-EOS)
-   !                             !  rd(T,S,Z)*rau0 = -a0*(1+.5*lambda*dT+mu*Z+nu*dS)*dT+b0*dS
-   rn_a0       =  0.2         !  thermal expension coefficient (for simplified equation of state)
-   rn_b0       =  0.          !  saline  expension coefficient (for simplified equation of state)
-   rn_lambda1  =  0.          !  cabbeling coeff in T^2  (=0 for linear eos)
-   rn_lambda2  =  0.          !  cabbeling coeff in S^2  (=0 for linear eos)
-   rn_mu1      =  0.          !  thermobaric coeff. in T (=0 for linear eos)
-   rn_mu2      =  0.          !  thermobaric coeff. in S (=0 for linear eos)
-   rn_nu       =  0.          !  cabbeling coeff in T*S  (=0 for linear eos)
-/
-!-----------------------------------------------------------------------
-&namtra_adv    !   advection scheme for tracer
-!-----------------------------------------------------------------------
-   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 = .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)
-   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)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namtra_ldf    !   lateral diffusion scheme for tracers
-!-----------------------------------------------------------------------
-   !                       !  Operator type:    both false = No lateral diffusion
-   ln_traldf_lap   =  .false.  !    laplacian operator
-   ln_traldf_blp   =  .false.  !  bilaplacian operator
-/
-!-----------------------------------------------------------------------
-&namtra_ldfeiv !   eddy induced velocity param.                         (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namtra_dmp    !   tracer: T & S newtonian damping                       (default: YES)
-!-----------------------------------------------------------------------
-   ln_tradmp   =  .false.   !  add a damping termn (T) or not (F)
-/
-!-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection
-!-----------------------------------------------------------------------
-   ln_dynadv_vec = .false. !  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 = .true.  !  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
-/
-!-----------------------------------------------------------------------
-&namdyn_vor    !   option of physics/algorithm
-!-----------------------------------------------------------------------
-   ln_dynvor_ene = .false. !  enstrophy conserving scheme
-   ln_dynvor_ens = .true.  !  energy conserving scheme
-   ln_dynvor_mix = .false. !  mixed scheme
-   ln_dynvor_een = .false. !  energy & enstrophy scheme
-      nn_een_e3f = 0             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
-/
-!-----------------------------------------------------------------------
-&namdyn_hpg    !   Hydrostatic pressure gradient option
-!-----------------------------------------------------------------------
-   ln_hpg_zps  = .false.  !  z-coordinate - partial steps (interpolation)
-   ln_hpg_sco  = .true.   !  s-coordinate (standard jacobian formulation)
-/
-!-----------------------------------------------------------------------
-&namdyn_spg    !   Surface pressure gradient
-!-----------------------------------------------------------------------
-   ln_dynspg_ts  = .true.   ! 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:
-         nn_baro      =  1         ! =F : the number of sub-step in rn_rdt seconds
-/
-!-----------------------------------------------------------------------
-&namdyn_ldf    !   lateral diffusion on momentum
-!-----------------------------------------------------------------------
-   !                       !  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 =  .true.      !  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      =     0.01    !  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]
-/
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
-/
-!-----------------------------------------------------------------------
-&nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namctl        !   Control prints & Benchmark
-!-----------------------------------------------------------------------
-/
+link namelist_zps_FCT2_flux_ubs_cfg
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_sco_FCT2_flux_ubs_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_sco_FCT2_flux_ubs_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_sco_FCT2_flux_ubs_cfg	(revision 9019)
@@ -21,5 +21,5 @@
    nn_it000    =       1   !  first time step
    nn_itend    =    6120  ! here 17h of simulation  (=6120 time-step) 
-   !nn_itend    =    5760   ! here 16h of simulation  (=5760 time-step) abort after 5802 for zps: pb of physiques conditions
+   !nn_itend    =    5760   ! here 16h of simulation  (=5760 time-step) abort after 5802 for zps: pb of physics conditions
    nn_istate   =       0   !  output the initial state (1) or not (0)
    nn_stock    =    1080   !  frequency of creation of a restart file (modulo referenced to 1)
@@ -61,17 +61,23 @@
   rn_shlat    =    0.     !  shlat = 0  !  0 < shlat < 2  !  shlat = 2  !  2 < shlat
 /
-!-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
+!!======================================================================
+!!                ***  Top/Bottom boundary condition  ***             !!
+!!======================================================================
+!!   namdrg        top/bottom drag coefficient                          (default: NO selection)
+!!   namdrg_top    top    friction                                      (ln_isfcav=T)
+!!   namdrg_bot    bottom friction
+!!   nambbc        bottom temperature boundary condition                (default: NO)
+!!   nambbl        bottom boundary layer scheme                         (default: NO)
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.     !  free-slip       : Cd = 0                  (F => fill namdrg_bot
+   ln_lin     = .false.    !      linear  drag: Cd = Cd0 Uc0                   &   namdrg_top)
+   ln_non_lin = .false.    !  non-linear  drag: Cd = Cd0 |U|
+   ln_loglayer= .false.    !  logarithmic drag: Cd = vkarmn/log(z/z0) |U|
+   !
+   ln_drgimp  = .true.     !  implicit top/bottom friction flag
 /
 !-----------------------------------------------------------------------
@@ -97,6 +103,4 @@
       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
@@ -113,4 +117,5 @@
 !-----------------------------------------------------------------------
    !                       !  Operator type:    both false = No lateral diffusion
+   ln_traldf_NONE  =  .true.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -126,11 +131,11 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection
-!-----------------------------------------------------------------------
+&namdyn_adv    !   formulation of the momentum advection                (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_dynadv_NONE= .false. !  linear dynamics (no momentum advection)
    ln_dynadv_vec = .false. !  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 = .true.  !  flux form - 3rd order UBS      scheme
-   ln_dynzad_zts = .false. !  Use (T) sub timestepping for vertical momentum advection
 /
 !-----------------------------------------------------------------------
@@ -167,34 +172,66 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_ldf    !   lateral diffusion on momentum
+&namdyn_ldf    !   lateral diffusion on momentum                        (default: NO selection)
 !-----------------------------------------------------------------------
    !                       !  Type of the operator :
-   !                           !  no diffusion: set ln_dynldf_lap=..._blp=F 
-   ln_dynldf_lap =  .true.     !    laplacian operator
+   ln_dynldf_NONE=  .true.    !  No operator (i.e. no explicit diffusion)
+   ln_dynldf_lap =  .false.    !    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
+   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
+   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 
+   !                                !  =  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      =     0.01    !  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]
-/
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
+   !                                !  = 32  F(i,j,k)=F(local gridscale and deformation rate)
+   ! Caution in 20 and 30 cases the coefficient have to be given for a 1 degree grid (~111km)
+   rn_ahm_0      =   1000.     !  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]
+   !                       !  Smagorinsky settings (nn_ahm_ijk_t  = 32) :
+   rn_csmc       = 3.5         !  Smagorinsky constant of proportionality
+   rn_minfac     = 1.0         !  multiplier of theorectical lower limit
+   rn_maxfac     = 1.0         !  multiplier of theorectical upper limit
+/
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure (required)
+   ln_zdfcst   = .true.      !  constant mixing
+   ln_zdfric   = .false.      !  local Richardson dependent formulation (T =>   fill namzdf_ric)
+   ln_zdftke   = .false.      !  Turbulent Kinetic Energy closure       (T =>   fill namzdf_tke)
+   ln_zdfgls   = .false.      !  Generic Length Scale closure           (T =>   fill namzdf_gls)
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+      nn_evdm     =    0         ! apply on tracer (=0) or on tracer and momentum (=1) 
+      rn_evd      =  100.        ! mixing coefficient [m2/s]
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+      nn_npc      =    1         ! frequency of application of npc
+      nn_npcp     =  365         ! npc control print frequency
+   !
+   ln_zdfddm   = .false.   ! double diffusive mixing
+      rn_avts  =    1.e-4     !  maximum avs (vertical mixing on salinity)
+      rn_hsbfr =    1.6       !  heat/salt buoyancy flux ratio
+   !
+   !                       ! gravity wave-driven vertical mixing
+   ln_zdfiwm   = .false.      ! internal wave-induced mixing            (T =>   fill namzdf_iwm)
+   ln_zdfswm   = .false.      ! surface  wave-induced mixing            (T => ln_wave=ln_sdw=T )
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.e-4     !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   0.0e      !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0        !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0        !  horizontal shape for avtb (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT2_flux_ubs_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT2_flux_ubs_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT2_flux_ubs_cfg	(revision 9019)
@@ -20,6 +20,6 @@
    cn_exp      =   "OVF_zps_FCT2_flux_ubs"  !  experience name
    nn_it000    =       1   !  first time step
-   nn_itend    =    6120  ! here 17h of simulation  (=6120 time-step) 
-   !nn_itend    =    5760   ! here 16h of simulation  (=5760 time-step) abort after 5802 for zps: pb of physiques conditions
+   !nn_itend    =    6120  ! here 17h of simulation  (=6120 time-step) 
+   nn_itend    =    5760   ! here 16h of simulation  (=5760 time-step) abort after 5802 for zps: pb of physics conditions
    nn_istate   =       0   !  output the initial state (1) or not (0)
    nn_stock    =    1080   !  frequency of creation of a restart file (modulo referenced to 1)
@@ -61,17 +61,23 @@
   rn_shlat    =    0.     !  shlat = 0  !  0 < shlat < 2  !  shlat = 2  !  2 < shlat
 /
-!-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
+!!======================================================================
+!!                ***  Top/Bottom boundary condition  ***             !!
+!!======================================================================
+!!   namdrg        top/bottom drag coefficient                          (default: NO selection)
+!!   namdrg_top    top    friction                                      (ln_isfcav=T)
+!!   namdrg_bot    bottom friction
+!!   nambbc        bottom temperature boundary condition                (default: NO)
+!!   nambbl        bottom boundary layer scheme                         (default: NO)
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.     !  free-slip       : Cd = 0                  (F => fill namdrg_bot
+   ln_lin     = .false.    !      linear  drag: Cd = Cd0 Uc0                   &   namdrg_top)
+   ln_non_lin = .false.    !  non-linear  drag: Cd = Cd0 |U|
+   ln_loglayer= .false.    !  logarithmic drag: Cd = vkarmn/log(z/z0) |U|
+   !
+   ln_drgimp  = .true.     !  implicit top/bottom friction flag
 /
 !-----------------------------------------------------------------------
@@ -97,6 +103,4 @@
       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
@@ -113,4 +117,5 @@
 !-----------------------------------------------------------------------
    !                       !  Operator type:    both false = No lateral diffusion
+   ln_traldf_NONE  =  .true.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -126,11 +131,11 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection
-!-----------------------------------------------------------------------
+&namdyn_adv    !   formulation of the momentum advection                (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_dynadv_NONE= .false. !  linear dynamics (no momentum advection)
    ln_dynadv_vec = .false. !  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 = .true.  !  flux form - 3rd order UBS      scheme
-   ln_dynzad_zts = .false. !  Use (T) sub timestepping for vertical momentum advection
 /
 !-----------------------------------------------------------------------
@@ -167,34 +172,67 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_ldf    !   lateral diffusion on momentum
+&namdyn_ldf    !   lateral diffusion on momentum                        (default: NO selection)
 !-----------------------------------------------------------------------
    !                       !  Type of the operator :
-   !                           !  no diffusion: set ln_dynldf_lap=..._blp=F 
-   ln_dynldf_lap =  .true.     !    laplacian operator
+   ln_dynldf_NONE=  .true.    !  No operator (i.e. no explicit diffusion)
+   ln_dynldf_lap =  .false.    !    laplacian operator
    ln_dynldf_blp =  .false.    !  bilaplacian operator
    !                       !  Direction of action  :
-   ln_dynldf_lev =  .false.     !  iso-level
-   ln_dynldf_hor =  .true.      !  horizontal (geopotential)
-   ln_dynldf_iso =  .false.     !  iso-neutral
+   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
+   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 
+   !                                !  =  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      =     0.01    !  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]
-/
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
+   !                                !  = 32  F(i,j,k)=F(local gridscale and deformation rate)
+   ! Caution in 20 and 30 cases the coefficient have to be given for a 1 degree grid (~111km)
+   rn_ahm_0      =   1000.     !  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]
+   !                       !  Smagorinsky settings (nn_ahm_ijk_t  = 32) :
+   rn_csmc       = 3.5         !  Smagorinsky constant of proportionality
+   rn_minfac     = 1.0         !  multiplier of theorectical lower limit
+   rn_maxfac     = 1.0         !  multiplier of theorectical upper limit
+/
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure (required)
+   ln_zdfcst   = .true.      !  constant mixing
+   ln_zdfric   = .false.      !  local Richardson dependent formulation (T =>   fill namzdf_ric)
+   ln_zdftke   = .false.      !  Turbulent Kinetic Energy closure       (T =>   fill namzdf_tke)
+   ln_zdfgls   = .false.      !  Generic Length Scale closure           (T =>   fill namzdf_gls)
+   ln_zdfosm   = .false.      !  OSMOSIS BL closure                     (T =>   fill namzdf_osm)
+   !   
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+      nn_evdm     =    0         ! apply on tracer (=0) or on tracer and momentum (=1) 
+      rn_evd      =  100.        ! mixing coefficient [m2/s]
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+      nn_npc      =    1         ! frequency of application of npc 
+      nn_npcp     =  365         ! npc control print frequency
+   !   
+   ln_zdfddm   = .false.   ! double diffusive mixing
+      rn_avts  =    1.e-4     !  maximum avs (vertical mixing on salinity)
+      rn_hsbfr =    1.6       !  heat/salt buoyancy flux ratio
+   !   
+   !                       ! gravity wave-driven vertical mixing
+   ln_zdfiwm   = .false.      ! internal wave-induced mixing            (T =>   fill namzdf_iwm)
+   ln_zdfswm   = .false.      ! surface  wave-induced mixing            (T => ln_wave=ln_sdw=T )
+   !   
+   !                       ! coefficients
+   rn_avm0     =   1.e-4     !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   0.0e      !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0        !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0        !  horizontal shape for avtb (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT4_flux_ubs_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT4_flux_ubs_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT4_flux_ubs_cfg	(revision 9019)
@@ -20,6 +20,6 @@
    cn_exp      =   "OVF_zps_FCT4_flux_ubs"  !  experience name
    nn_it000    =       1   !  first time step
-   nn_itend    =    6120  ! here 17h of simulation  (=6120 time-step) 
-   !nn_itend    =    5760   ! here 16h of simulation  (=5760 time-step) abort after 5802 for zps: pb of physiques conditions
+   !nn_itend    =    6120  ! here 17h of simulation  (=6120 time-step) 
+   nn_itend    =    5760   ! here 16h of simulation  (=5760 time-step) abort after 5802 for zps: pb of physics conditions
    nn_istate   =       0   !  output the initial state (1) or not (0)
    nn_stock    =    1080   !  frequency of creation of a restart file (modulo referenced to 1)
@@ -61,17 +61,23 @@
   rn_shlat    =    0.     !  shlat = 0  !  0 < shlat < 2  !  shlat = 2  !  2 < shlat
 /
-!-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
+!!======================================================================
+!!                ***  Top/Bottom boundary condition  ***             !!
+!!======================================================================
+!!   namdrg        top/bottom drag coefficient                          (default: NO selection)
+!!   namdrg_top    top    friction                                      (ln_isfcav=T)
+!!   namdrg_bot    bottom friction
+!!   nambbc        bottom temperature boundary condition                (default: NO)
+!!   nambbl        bottom boundary layer scheme                         (default: NO)
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.     !  free-slip       : Cd = 0                  (F => fill namdrg_bot
+   ln_lin     = .false.    !      linear  drag: Cd = Cd0 Uc0                   &   namdrg_top)
+   ln_non_lin = .false.    !  non-linear  drag: Cd = Cd0 |U|
+   ln_loglayer= .false.    !  logarithmic drag: Cd = vkarmn/log(z/z0) |U|
+   !
+   ln_drgimp  = .true.     !  implicit top/bottom friction flag
 /
 !-----------------------------------------------------------------------
@@ -97,6 +103,4 @@
       nn_fct_h   =  4            !  =2/4, horizontal 2nd / 4th order
       nn_fct_v   =  4            !  =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
@@ -113,4 +117,5 @@
 !-----------------------------------------------------------------------
    !                       !  Operator type:    both false = No lateral diffusion
+   ln_traldf_NONE  =  .true.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -126,11 +131,11 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection
-!-----------------------------------------------------------------------
+&namdyn_adv    !   formulation of the momentum advection                (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_dynadv_NONE= .false. !  linear dynamics (no momentum advection)
    ln_dynadv_vec = .false. !  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 = .true.  !  flux form - 3rd order UBS      scheme
-   ln_dynzad_zts = .false. !  Use (T) sub timestepping for vertical momentum advection
 /
 !-----------------------------------------------------------------------
@@ -167,34 +172,66 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_ldf    !   lateral diffusion on momentum
+&namdyn_ldf    !   lateral diffusion on momentum                        (default: NO selection)
 !-----------------------------------------------------------------------
    !                       !  Type of the operator :
-   !                           !  no diffusion: set ln_dynldf_lap=..._blp=F 
-   ln_dynldf_lap =  .true.     !    laplacian operator
+   ln_dynldf_NONE=  .true.    !  No operator (i.e. no explicit diffusion)
+   ln_dynldf_lap =  .false.    !    laplacian operator
    ln_dynldf_blp =  .false.    !  bilaplacian operator
    !                       !  Direction of action  :
-   ln_dynldf_lev =  .false.     !  iso-level
-   ln_dynldf_hor =  .true.      !  horizontal (geopotential)
-   ln_dynldf_iso =  .false.     !  iso-neutral
+   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
+   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 
+   !                                !  =  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      =     0.01    !  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]
-/
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
+   !                                !  = 32  F(i,j,k)=F(local gridscale and deformation rate)
+   ! Caution in 20 and 30 cases the coefficient have to be given for a 1 degree grid (~111km)
+   rn_ahm_0      =   1000.     !  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]
+   !                       !  Smagorinsky settings (nn_ahm_ijk_t  = 32) :
+   rn_csmc       = 3.5         !  Smagorinsky constant of proportionality
+   rn_minfac     = 1.0         !  multiplier of theorectical lower limit
+   rn_maxfac     = 1.0         !  multiplier of theorectical upper limit
+/
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure (required)
+   ln_zdfcst   = .true.      !  constant mixing
+   ln_zdfric   = .false.      !  local Richardson dependent formulation (T =>   fill namzdf_ric)
+   ln_zdftke   = .false.      !  Turbulent Kinetic Energy closure       (T =>   fill namzdf_tke)
+   ln_zdfgls   = .false.      !  Generic Length Scale closure           (T =>   fill namzdf_gls)
+   !   
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+      nn_evdm     =    0         ! apply on tracer (=0) or on tracer and momentum (=1) 
+      rn_evd      =  100.        ! mixing coefficient [m2/s]
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+      nn_npc      =    1         ! frequency of application of npc 
+      nn_npcp     =  365         ! npc control print frequency
+   !   
+   ln_zdfddm   = .false.   ! double diffusive mixing
+      rn_avts  =    1.e-4     !  maximum avs (vertical mixing on salinity)
+      rn_hsbfr =    1.6       !  heat/salt buoyancy flux ratio
+   !   
+   !                       ! gravity wave-driven vertical mixing
+   ln_zdfiwm   = .false.      ! internal wave-induced mixing            (T =>   fill namzdf_iwm)
+   ln_zdfswm   = .false.      ! surface  wave-induced mixing            (T => ln_wave=ln_sdw=T )
+   !   
+   !                       ! coefficients
+   rn_avm0     =   1.e-4     !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   0.0e      !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0        !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0        !  horizontal shape for avtb (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT4_vect_een_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT4_vect_een_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT4_vect_een_cfg	(revision 9019)
@@ -20,6 +20,6 @@
    cn_exp      =   "OVF_zps_FCT4_vect_een"  !  experience name
    nn_it000    =       1   !  first time step
-   nn_itend    =    6120  ! here 17h of simulation  (=6120 time-step) 
-   !nn_itend    =    5760   ! here 16h of simulation  (=5760 time-step) abort after 5802 for zps: pb of physiques conditions
+   !nn_itend    =    6120  ! here 17h of simulation  (=6120 time-step) 
+   nn_itend    =    5760   ! here 16h of simulation  (=5760 time-step) abort after 5802 for zps: pb of physics conditions
    nn_istate   =       0   !  output the initial state (1) or not (0)
    nn_stock    =    1080   !  frequency of creation of a restart file (modulo referenced to 1)
@@ -61,17 +61,23 @@
   rn_shlat    =    0.     !  shlat = 0  !  0 < shlat < 2  !  shlat = 2  !  2 < shlat
 /
-!-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    0      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-                           !                              = 2 : nonlinear friction
-/
-!-----------------------------------------------------------------------
-&nambbc        !   bottom temperature boundary condition                (default: NO)
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
-!-----------------------------------------------------------------------
+!!======================================================================
+!!                ***  Top/Bottom boundary condition  ***             !!
+!!======================================================================
+!!   namdrg        top/bottom drag coefficient                          (default: NO selection)
+!!   namdrg_top    top    friction                                      (ln_isfcav=T)
+!!   namdrg_bot    bottom friction
+!!   nambbc        bottom temperature boundary condition                (default: NO)
+!!   nambbl        bottom boundary layer scheme                         (default: NO)
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.     !  free-slip       : Cd = 0                  (F => fill namdrg_bot
+   ln_lin     = .false.    !      linear  drag: Cd = Cd0 Uc0                   &   namdrg_top)
+   ln_non_lin = .false.    !  non-linear  drag: Cd = Cd0 |U|
+   ln_loglayer= .false.    !  logarithmic drag: Cd = vkarmn/log(z/z0) |U|
+   !
+   ln_drgimp  = .true.     !  implicit top/bottom friction flag
 /
 !-----------------------------------------------------------------------
@@ -97,6 +103,4 @@
       nn_fct_h   =  4            !  =2/4, horizontal 2nd / 4th order
       nn_fct_v   =  4            !  =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
@@ -113,4 +117,5 @@
 !-----------------------------------------------------------------------
    !                       !  Operator type:    both false = No lateral diffusion
+   ln_traldf_NONE  =  .true.  !  No explicit diffusion
    ln_traldf_lap   =  .false.  !    laplacian operator
    ln_traldf_blp   =  .false.  !  bilaplacian operator
@@ -126,11 +131,11 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection
-!-----------------------------------------------------------------------
-   ln_dynadv_vec = .true.  !  vector form (T) or flux form (F)
+&namdyn_adv    !   formulation of the momentum advection                (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_dynadv_NONE= .false. !  linear dynamics (no momentum advection)
+   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
 /
 !-----------------------------------------------------------------------
@@ -143,7 +148,7 @@
 !-----------------------------------------------------------------------
    ln_dynvor_ene = .false. !  enstrophy conserving scheme
-   ln_dynvor_ens = .false. !  energy conserving scheme
+   ln_dynvor_ens = .true.  !  energy conserving scheme
    ln_dynvor_mix = .false. !  mixed scheme
-   ln_dynvor_een = .true.  !  energy & enstrophy 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)
 /
@@ -167,34 +172,66 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_ldf    !   lateral diffusion on momentum
+&namdyn_ldf    !   lateral diffusion on momentum                        (default: NO selection)
 !-----------------------------------------------------------------------
    !                       !  Type of the operator :
-   !                           !  no diffusion: set ln_dynldf_lap=..._blp=F 
-   ln_dynldf_lap =  .true.     !    laplacian operator
+   ln_dynldf_NONE=  .false.    !  No operator (i.e. no explicit diffusion)
+   ln_dynldf_lap =  .true.    !    laplacian operator
    ln_dynldf_blp =  .false.    !  bilaplacian operator
    !                       !  Direction of action  :
-   ln_dynldf_lev =  .false.     !  iso-level
-   ln_dynldf_hor =  .true.      !  horizontal (geopotential)
-   ln_dynldf_iso =  .false.     !  iso-neutral
+   ln_dynldf_lev =  .false.    !  iso-level
+   ln_dynldf_hor =  .true.    !  horizontal (geopotential)
+   ln_dynldf_iso =  .false.    !  iso-neutral
    !                       !  Coefficient
-   nn_ahm_ijk_t  = 0         !  space/time variation of eddy coef
+   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 
+   !                                !  =  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      =     0.01    !  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]
-/
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   rn_avm0     =   1.e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
-   rn_avt0     =   0.     !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
-   ln_zdfevd   = .false.  !  enhanced vertical diffusion (evd)
-   ln_zdfnpc   = .false.  !  Non-Penetrative Convective algorithm
+   !                                !  = 32  F(i,j,k)=F(local gridscale and deformation rate)
+   ! Caution in 20 and 30 cases the coefficient have to be given for a 1 degree grid (~111km)
+   rn_ahm_0      =    100.     !  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]
+   !                       !  Smagorinsky settings (nn_ahm_ijk_t  = 32) :
+   rn_csmc       = 3.5         !  Smagorinsky constant of proportionality
+   rn_minfac     = 1.0         !  multiplier of theorectical lower limit
+   rn_maxfac     = 1.0         !  multiplier of theorectical upper limit
+/
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure (required)
+   ln_zdfcst   = .true.      !  constant mixing
+   ln_zdfric   = .false.      !  local Richardson dependent formulation (T =>   fill namzdf_ric)
+   ln_zdftke   = .false.      !  Turbulent Kinetic Energy closure       (T =>   fill namzdf_tke)
+   ln_zdfgls   = .false.      !  Generic Length Scale closure           (T =>   fill namzdf_gls)
+   !   
+   !                       ! convection
+   ln_zdfevd   = .false.      !  enhanced vertical diffusion
+      nn_evdm     =    0         ! apply on tracer (=0) or on tracer and momentum (=1) 
+      rn_evd      =  100.        ! mixing coefficient [m2/s]
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+      nn_npc      =    1         ! frequency of application of npc 
+      nn_npcp     =  365         ! npc control print frequency
+   !   
+   ln_zdfddm   = .false.   ! double diffusive mixing
+      rn_avts  =    1.e-4     !  maximum avs (vertical mixing on salinity)
+      rn_hsbfr =    1.6       !  heat/salt buoyancy flux ratio
+   !   
+   !                       ! gravity wave-driven vertical mixing
+   ln_zdfiwm   = .false.      ! internal wave-induced mixing            (T =>   fill namzdf_iwm)
+   ln_zdfswm   = .false.      ! surface  wave-induced mixing            (T => ln_wave=ln_sdw=T )
+   !   
+   !                       ! coefficients
+   rn_avm0     =   1.e-4     !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   0.0e      !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0        !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0        !  horizontal shape for avtb (=1) or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/MY_SRC/usrdef_sbc.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/MY_SRC/usrdef_sbc.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/MY_SRC/usrdef_sbc.F90	(revision 9019)
@@ -16,4 +16,5 @@
    USE dom_oce         ! ocean space and time domain
    USE sbc_oce         ! Surface boundary condition: ocean fields
+   USE sbc_ice         ! Surface boundary condition: ice fields 
    USE phycst          ! physical constants
    !
Index: anches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/MY_SRC/zdfini.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/MY_SRC/zdfini.F90	(revision 9018)
+++ 	(revision )
@@ -1,183 +1,0 @@
-MODULE zdfini
-   !!======================================================================
-   !!                     ***  MODULE zdfini  ***
-   !!
-   !!                     ===  OVERFLOW case  ===
-   !!
-   !! Ocean physics :   read vertical mixing namelist and check consistancy
-   !!======================================================================
-   !! History :  8.0  ! 1997-06  (G. Madec)  Original code from inimix
-   !!            1.0  ! 2002-08  (G. Madec)  F90 : free form
-   !!             -   ! 2005-06  (C. Ethe) KPP scheme
-   !!             -   ! 2009-07  (G. Madec) add avmb, avtb in restart for cen2 advection
-   !!            3.7  ! 2014-12  (G. Madec) remove KPP scheme
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   zdf_init    : initialization, namelist read, and parameters control
-   !!----------------------------------------------------------------------
-   USE par_oce         ! mesh and scale factors
-   USE zdf_oce         ! TKE vertical mixing          
-   USE sbc_oce         ! surface module (only for nn_isf in the option compatibility test)
-   USE zdftke          ! TKE vertical mixing
-   USE zdfgls          ! GLS vertical mixing
-   USE zdfric          ! Richardson vertical mixing   
-   USE zdfddm          ! double diffusion mixing      
-   USE zdfevd          ! enhanced vertical diffusion  
-   USE tranpc          ! convection: non penetrative adjustment
-   USE ldfslp          ! iso-neutral slopes
-   !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! IOM library
-   USE lib_mpp         ! distribued memory computing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   zdf_init   ! routine called by opa.F90
-   
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE zdf_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE zdf_init  ***
-      !! 
-      !! ** Purpose :   initializations of the vertical ocean physics
-      !!
-      !! ** Method  :   Read namelist namzdf, control logicals 
-      !!----------------------------------------------------------------------
-      INTEGER ::   ioptio, ios       ! local integers
-      !!
-      NAMELIST/namzdf/ rn_avm0, rn_avt0, nn_avb, nn_havtb, ln_zdfexp, nn_zdfexp,   &
-         &              ln_zdfevd, nn_evdm, rn_avevd, ln_zdfnpc, nn_npc, nn_npcp,  &
-         &              ln_zdfqiao
-      !!----------------------------------------------------------------------
-
-      REWIND( numnam_ref )              ! Namelist namzdf in reference namelist : Vertical mixing parameters
-      READ  ( numnam_ref, namzdf, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf in reference namelist', lwp )
-
-      REWIND( numnam_cfg )              ! Namelist namzdf in reference namelist : Vertical mixing parameters
-      READ  ( numnam_cfg, namzdf, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf in configuration namelist', lwp )
-      IF(lwm) WRITE ( numond, namzdf )
-
-      IF(lwp) THEN               !* Parameter print
-         WRITE(numout,*)
-         WRITE(numout,*) 'zdf_init: vertical physics'
-         WRITE(numout,*) '~~~~~~~~'
-         WRITE(numout,*) '   Namelist namzdf : set vertical mixing mixing parameters'
-         WRITE(numout,*) '      vertical eddy viscosity             rn_avm0   = ', rn_avm0
-         WRITE(numout,*) '      vertical eddy diffusivity           rn_avt0   = ', rn_avt0
-         WRITE(numout,*) '      constant background or profile      nn_avb    = ', nn_avb
-         WRITE(numout,*) '      horizontal variation for avtb       nn_havtb  = ', nn_havtb
-         WRITE(numout,*) '      time splitting / backward scheme    ln_zdfexp = ', ln_zdfexp
-         WRITE(numout,*) '      number of time step                 nn_zdfexp = ', nn_zdfexp
-         WRITE(numout,*) '      enhanced vertical diffusion         ln_zdfevd = ', ln_zdfevd
-         WRITE(numout,*) '         applied on momentum (=1/0)       nn_evdm   = ', nn_evdm
-         WRITE(numout,*) '      vertical coefficient for evd        rn_avevd  = ', rn_avevd
-         WRITE(numout,*) '      non-penetrative convection (npc)    ln_zdfnpc = ', ln_zdfnpc
-         WRITE(numout,*) '      npc call  frequency                 nn_npc    = ', nn_npc
-         WRITE(numout,*) '      npc print frequency                 nn_npcp   = ', nn_npcp
-      ENDIF
-
-      !                          !* Parameter & logical controls
-      !                          !  ----------------------------
-      !
-      !                               ! ... check of vertical mixing scheme on tracers
-      !                                              ==> will be done in trazdf module
-      !
-      !                               ! ... check of mixing coefficient
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) '   vertical mixing option :'
-      ioptio = 0
-      IF( lk_zdfcst ) THEN
-         IF(lwp) WRITE(numout,*) '      constant eddy diffusion coefficients'
-         ioptio = ioptio+1
-      ENDIF
-      IF( lk_zdfric ) THEN
-         IF(lwp) WRITE(numout,*) '      Richardson dependent eddy coefficients'
-         ioptio = ioptio+1
-      ENDIF
-      IF( lk_zdftke ) THEN
-         IF(lwp) WRITE(numout,*) '      TKE dependent eddy coefficients'
-         ioptio = ioptio+1
-      ENDIF
-      IF( lk_zdfgls ) THEN
-         IF(lwp) WRITE(numout,*) '      GLS dependent eddy coefficients'
-         ioptio = ioptio+1
-      ENDIF
-      IF( ioptio == 0 .OR. ioptio > 1 )   &
-         &   CALL ctl_stop( ' one and only one vertical diffusion option has to be defined ' )
-      IF( ( lk_zdfric .OR. lk_zdfgls ) .AND. ln_isfcav )   &
-         &   CALL ctl_stop( ' only zdfcst and zdftke were tested with ice shelves cavities ' )
-      !
-      !                               ! ... Convection
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) '   convection :'
-      !
-#if defined key_top
-      IF( ln_zdfnpc )   CALL ctl_stop( ' zdf_init: npc scheme is not working with key_top' )
-#endif
-      !
-      ioptio = 0
-      IF( ln_zdfnpc ) THEN
-         IF(lwp) WRITE(numout,*) '      use non penetrative convective scheme'
-         ioptio = ioptio+1
-      ENDIF
-      IF( ln_zdfevd ) THEN
-         IF(lwp) WRITE(numout,*) '      use enhanced vertical dif. scheme'
-         ioptio = ioptio+1
-      ENDIF
-      IF( lk_zdftke ) THEN
-         IF(lwp) WRITE(numout,*) '      use the 1.5 turbulent closure'
-      ENDIF
-      IF( lk_zdfgls ) THEN
-         IF(lwp) WRITE(numout,*) '      use the GLS closure scheme'
-      ENDIF
-      IF ( ioptio > 1 )   CALL ctl_stop( ' chose between ln_zdfnpc and ln_zdfevd' )
-      IF( ioptio == 0 .AND. .NOT.( lk_zdftke .OR. lk_zdfgls ) )           &
-         !SF CALL ctl_stop( ' except for TKE or GLS physics, a convection scheme is',   &
-         CALL ctl_warn( ' except for TKE or GLS physics, a convection scheme is',   &
-         &              ' required: ln_zdfevd or ln_zdfnpc logicals' )
-
-      !                               !* Background eddy viscosity and diffusivity profil
-      IF( nn_avb == 0 ) THEN                ! Define avmb, avtb from namelist parameter
-         avmb(:) = rn_avm0
-         avtb(:) = rn_avt0                     
-      ELSE                                  ! Background profile of avt (fit a theoretical/observational profile (Krauss 1990)
-         avmb(:) = rn_avm0
-         avtb(:) = rn_avt0 + ( 3.e-4_wp - 2._wp * rn_avt0 ) * 1.e-4_wp * gdepw_1d(:)   ! m2/s
-         IF(ln_sco .AND. lwp)   CALL ctl_warn( 'avtb profile not valid in sco' )
-      ENDIF
-      !
-      IF( ln_rstart ) THEN                  !  Read avmb, avtb in restart (if exist)
-         ! if ln_traadv_cen, avmb, avtb have been modified in traadv_cen2 module. 
-         ! To ensure the restartability, avmb & avtb are written in the restart 
-         ! file in traadv_cen2 end read here. 
-         IF( iom_varid( numror, 'avmb', ldstop = .FALSE. ) > 0 ) THEN
-            CALL iom_get( numror, jpdom_unknown, 'avmb', avmb )
-            CALL iom_get( numror, jpdom_unknown, 'avtb', avtb )
-         ENDIF
-      ENDIF
-      !                                     ! 2D shape of the avtb
-      avtb_2d(:,:) = 1.e0                        ! uniform 
-      !
-      IF( nn_havtb == 1 ) THEN                   ! decrease avtb in the equatorial band
-           !  -15S -5S : linear decrease from avt0 to avt0/10.
-           !  -5S  +5N : cst value avt0/10.
-           !   5N  15N : linear increase from avt0/10, to avt0
-           WHERE(-15. <= gphit .AND. gphit < -5 )   avtb_2d = (1.  - 0.09 * (gphit + 15.))
-           WHERE( -5. <= gphit .AND. gphit <  5 )   avtb_2d =  0.1
-           WHERE(  5. <= gphit .AND. gphit < 15 )   avtb_2d = (0.1 + 0.09 * (gphit -  5.))
-      ENDIF
-      !
-   END SUBROUTINE zdf_init
-
-   !!======================================================================
-END MODULE zdfini
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/cpp_OVERFLOW.fcm
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/cpp_OVERFLOW.fcm	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/cpp_OVERFLOW.fcm	(revision 9019)
@@ -1,1 +1,1 @@
-bld::tool::fppkeys key_zdfcst key_mpp_mpi key_iomput key_nosignedzero
+bld::tool::fppkeys   key_mpp_mpi key_iomput key_nosignedzero
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/1_namelist_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/1_namelist_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/1_namelist_cfg	(revision 9019)
@@ -14,5 +14,6 @@
    cn_exp      =  "SASBIPER"  !  experience name
    nn_it000    =       1      !  first time step
-   nn_itend    =    30300     !  last  time step (std 5475)
+   nn_itend    =    1500      !  last  time step (std 5475)
+   nn_istate   =       1      !  output the initial state (1) or not (0)
 /
 !-----------------------------------------------------------------------
@@ -26,13 +27,12 @@
 &namdom        !   space and time domain (bathymetry, mesh, timestep)
 !-----------------------------------------------------------------------
-   ln_linssh   = .false.   !  =T  linear free surface  ==>>  model level are fixed in time
-   !
-   nn_msh      =    1      !  create (>0) a mesh file or not (=0)
+   ln_linssh   = .true.   !  =T  linear free surface  ==>>  model level are fixed in time
+   !
+   nn_msh      =    1     !  create (>0) a mesh file or not (=0)
    !
    rn_rdt      = 400.     !  time step for the dynamics (and tracer if nn_acc=0)
 /
 !-----------------------------------------------------------------------
-&namcrs        !   Grid coarsening for dynamics output and/or
-               !   passive tracer coarsened online simulations
+&namcrs        !   coarsened grid (for outputs and/or TOP)              (ln_crs =T)
 !-----------------------------------------------------------------------
 /
@@ -45,5 +45,7 @@
 !-----------------------------------------------------------------------
    ln_usr      = .true.   !  user defined formulation                  (T => check usrdef_sbc)
+   ln_blk      = .false.  !  Bulk formulation                          (T => fill namsbc_blk )
    nn_fsbc     =  1       !  frequency of surface boundary condition computation
+   nn_ice      =  2       !  sea-ice model
 /
 !-----------------------------------------------------------------------
@@ -52,4 +54,9 @@
 /
 !-----------------------------------------------------------------------
+&namsbc_sas    !   Stand Alone Surface boundary condition
+!-----------------------------------------------------------------------
+   l_sasread   = .false.   ! Read fields in a file if .TRUE. , or initialize to 0. in sbcssm.F90 if .FALSE.
+/
+!-----------------------------------------------------------------------
 &namtra_qsr    !   penetrative solar radiation
 !-----------------------------------------------------------------------
@@ -70,4 +77,5 @@
 &namberg       !   iceberg parameters
 !-----------------------------------------------------------------------
+   ln_bergdia               = .false.               ! Calculate budgets
 /
 !-----------------------------------------------------------------------
@@ -78,6 +86,12 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
+&namagrif      !  AGRIF zoom                                            ("key_agrif")
+!-----------------------------------------------------------------------
+   nn_cln_update =    1    !  baroclinic update frequency
+/
+!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.     !  free-slip       : Cd = 0                  
 /
 !-----------------------------------------------------------------------
@@ -95,11 +109,9 @@
 /
 !-----------------------------------------------------------------------
-&namtra_adv    !   advection scheme for tracer
+&namtra_adv    !   advection scheme for tracer                          (default: NO selection)
 !-----------------------------------------------------------------------
    ln_traadv_fct =  .true.    !  FCT scheme
       nn_fct_h   =  4               !  =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)
 /
 !-----------------------------------------------------------------------
@@ -155,7 +167,13 @@
 &namtra_dmp    !   tracer: T & S newtonian damping                      (default: NO)
 !-----------------------------------------------------------------------
-!-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection
-!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdyn_adv    !   formulation of the momentum advection                (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_dynadv_NONE= .false. !  linear dynamics (no momentum advection)
+   ln_dynadv_vec = .true. !  vector form - 2nd centered scheme
+     nn_dynkeg     = 0        ! grad(KE) scheme: =0   C2  ;  =1   Hollingsworth correction
+   ln_dynadv_cen2= .false. !  flux form - 2nd order centered scheme
+   ln_dynadv_ubs = .false. !  flux form - 3rd order UBS      scheme
 /
 !-----------------------------------------------------------------------
@@ -205,21 +223,19 @@
 /
 !-----------------------------------------------------------------------
-&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)
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .true.       !  constant mixing
+/
+!-----------------------------------------------------------------------
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  (ln_zdftke =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_iwm    !   tidal mixing parameterization                        (ln_zdfiwm =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi")
 !-----------------------------------------------------------------------
 /
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/1_namelist_ice_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/1_namelist_ice_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/1_namelist_ice_cfg	(revision 9019)
@@ -1,86 +1,96 @@
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-!! LIM3 namelist:  
-!!              1 - Generic parameters                 (namicerun)
-!!              2 - Diagnostics                        (namicediag)
-!!              3 - Ice initialization                 (namiceini)
-!!              4 - Ice discretization                 (namiceitd)
-!!              5 - Ice dynamics and transport         (namicedyn)
-!!              6 - Ice diffusion                      (namicehdf)
-!!              7 - Ice thermodynamics                 (namicethd)
-!!              8 - Ice salinity                       (namicesal)
-!!              9 - Ice mechanical redistribution      (namiceitdme)
+!! ESIM namelist:  
+!!              1 - Generic parameters                 (nampar)
+!!              2 - Ice thickness discretization       (namitd)
+!!              3 - Ice dynamics                       (namdyn)
+!!              4 - Ice ridging/rafting                (namdyn_rdgrft)
+!!              5 - Ice rheology                       (namdyn_rhg)
+!!              6 - Ice advection                      (namdyn_adv)
+!!              7 - Ice surface forcing                (namforcing)
+!!              8 - Ice thermodynamics                 (namthd)
+!!              9 - Ice heat diffusion                 (namthd_zdf)
+!!             10 - Ice lateral melting                (namthd_da)
+!!             11 - Ice growth in open water           (namthd_do)
+!!             12 - Ice salinity                       (namthd_sal)
+!!             13 - Ice melt ponds                     (namthd_pnd)
+!!             14 - Ice initialization                 (namini)
+!!             15 - Ice/snow albedos                   (namalb)
+!!             16 - Ice diagnostics                    (namdia)
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 !
 !------------------------------------------------------------------------------
-&namicerun     !   Generic parameters
+&nampar         !   Generic parameters
 !------------------------------------------------------------------------------
-   jpl              =    1          !  number of ice  categories
-   nlay_i           =    1          !  number of ice  layers
-   ln_limthd        =  .false.       !  ice thermo   (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-   ln_limdyn        =  .true.       !  ice dynamics (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-   nn_limdyn        =   0           !     (ln_limdyn=T) switch for ice dynamics
-                                    !      2: total
-                                    !      1: advection only (no diffusion, no ridging/rafting)
-                                    !      0: advection only (as 1 but with prescribed velocity, bypass rheology)
-   rn_uice          =   0.5    !     (nn_limdyn=0) ice u-velocity
-   rn_vice          =   0.0    !     (nn_limdyn=0) ice v-velocity
+   ln_icedyn        = .true.          !  ice dynamics (T) or not (F)
+   ln_icethd        = .false.         !  ice thermo   (T) or not (F)
 /
 !------------------------------------------------------------------------------
-&namicediag    !   Diagnostics
+&namitd         !   Ice discretization
+!------------------------------------------------------------------------------
+   rn_himin         =   0.1           !  minimum ice thickness (m) used in remapping
+/
+!------------------------------------------------------------------------------
+&namdyn         !   Ice dynamics
+!------------------------------------------------------------------------------
+   ln_dynFULL       = .false.         !  dyn.: full ice dynamics               (rheology + advection + ridging/rafting + correction)
+   ln_dynRHGADV     = .true.          !  dyn.: no ridge/raft & no corrections  (rheology + advection)
+   ln_dynADV        = .false.         !  dyn.: only advection w prescribed vel.(rn_uvice + advection)
+      rn_uice       =   0.5           !        prescribed ice u-velocity
+      rn_vice       =   0.            !        prescribed ice v-velocity
+/
+!------------------------------------------------------------------------------
+&namdyn_rdgrft  !   Ice ridging/rafting
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namiceini     !   Ice initialization
-!------------------------------------------------------------------------------
-                  ! -- limistate -- !
-   ln_limini      = .false.         !  activate ice initialization (T) or not (F)
-   ln_limini_file = .false.         !  netcdf file provided for initialization (T) or not (F)
-   cn_dir="./"
-   sn_hti = 'initice'    , -12 ,'hti'   ,  .false.  , .true., 'yearly'  , '' , '', ''
-   sn_hts = 'initice'    , -12 ,'hts'   ,  .false.  , .true., 'yearly'  , '' , '', ''
-   sn_ati = 'initice'    , -12 ,'ati'   ,  .false.  , .true., 'yearly'  , '' , '', ''
-   sn_tsu = 'initice'    , -12 ,'tsu'   ,  .false.  , .true., 'yearly'  , '' , '', ''
-   sn_tmi = 'initice'    , -12 ,'tmi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
-   sn_smi = 'initice'    , -12 ,'smi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
-/
-!------------------------------------------------------------------------------
-&namiceitd     !   Ice discretization
+&namdyn_rhg     !   Ice rheology
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namicedyn     !   Ice dynamics and transport
+&namdyn_adv     !   Ice advection
 !------------------------------------------------------------------------------
-                  ! -- limtrp & limadv -- !
-   nn_limadv      =    0            !  choose the advection scheme (-1=Prather ; 0=Ultimate-Macho)
-   nn_limadv_ord  =    5            !  choose the order of the advection scheme (if nn_limadv=0)
+   ln_adv_Pra       = .false.         !  Advection scheme (Prather)
+   ln_adv_UMx       = .true.          !  Advection scheme (Ultimate-Macho)
+      nn_UMx        =   5             !     order of the scheme for UMx (1-5 ; 20=centered 2nd order)
 /
 !------------------------------------------------------------------------------
-&namicehdf     !   Ice horizontal diffusion
+&namforcing     !   Ice surface forcing
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namicethd     !   Ice thermodynamics
+&namthd         !   Ice thermodynamics
 !------------------------------------------------------------------------------
-                  ! -- limthd_dh -- !
-   ln_limdH       = .true.          !  activate ice thickness change from growing/melting (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-                  ! -- limthd_da -- !
-   ln_limdA       = .true.          !  activate lateral melting param. (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-                 ! -- limthd_lac -- !
-   ln_limdO       = .true.          !  activate ice growth in open-water (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-   rn_hnewice     = 0.02            !  thickness for new ice formation in open water (m)
-                  ! -- limitd_th -- !
-   rn_himin       = 0.01            !  minimum ice thickness (m) used in remapping, must be smaller than rn_hnewice
 /
 !------------------------------------------------------------------------------
-&namicesal     !   Ice salinity
+&namthd_zdf     !   Ice heat diffusion
 !------------------------------------------------------------------------------
-                 ! -- limthd_sal -- !
-   ln_limdS       = .true.          !  activate gravity drainage and flushing (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
 /
 !------------------------------------------------------------------------------
-&namiceitdme   !   Ice mechanical redistribution (ridging and rafting)
+&namthd_da      !   Ice lateral melting
 !------------------------------------------------------------------------------
-                  ! -- limitd_me -- !
-   ln_ridging     =   .true.        !  ridging activated (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-   ln_rafting     =   .true.        !  rafting activated (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
 /
+!------------------------------------------------------------------------------
+&namthd_do      !   Ice growth in open water
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namthd_sal     !   Ice salinity
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namthd_pnd     !   Melt ponds
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namini         !   Ice initialization
+!------------------------------------------------------------------------------
+   ln_iceini        = .false.          !  activate ice initialization (T) or not (F)
+/
+!------------------------------------------------------------------------------
+&namalb         !   albedo parameters
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namdia         !   Diagnostics
+!------------------------------------------------------------------------------
+/
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/1_namelist_ice_ref
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/1_namelist_ice_ref	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/1_namelist_ice_ref	(revision 9019)
@@ -0,0 +1,1 @@
+link ../../../SHARED/1_namelist_ice_ref
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/README
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/README	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/README	(revision 9019)
@@ -0,0 +1,61 @@
+-------
+Purpose
+-------
+This demonstration case can serve to different purposes:
+
+1) The main one: study of the advection of a patch of ice in a bi-periodic channel with a slab ocean (i.e. 1 ocean layer)
+              ==> set ln_icethd=false in namelist_ice_cfg
+
+2) Secondary: study of ice thermodynamics in the same basin
+              ==> set ln_icedyn=false in namelist_ice_cfg
+              ==> eventually change usrdef_sbc.F90 in MY_SRC to fit your needs
+
+-----------
+Experiments
+-----------
+Two experiments can be configured:
+
+a) A simple channel at 3km horizontal resolution (slightly variable => +- 10%)
+              ==> remove key_agrif in cpp keys
+
+b) Same as a) but with an Agrif zoom in the center 1:3, and 3 ghost cells (defined in par_oce.F90)
+              ==> add key_agrif in cpp keys
+
+----------
+How to run
+----------
+Be careful, the model can only run on 1 processor in the N-S dimension
+
+a) Compile and run the model once to get a mesh_mask.nc file with the following command:
+../../../makenemo -a TEST_CASES -n SAS_BIPER -m X64_ADA -j 4
+poe ./opa -procs 1
+
+b) Create the initial condition file for sea-ice (initice.nc) by running this python script: 
+python ./make_INITICE.py
+
+c) Run the model a second time
+poe ./opa -procs 1
+
+---------------
+What to look at
+---------------
+In case of purpose 1, One can test
+---
+a) the advection scheme: Ultimate-Macho (ln_adv_UMx=T) versus Prather (ln_adv_Pra=T)
+   for a square (ice concentration) or a gaussian (ice volume)
+      with either a constant velocity (ln_dynADV=T)
+               or a constant ice-atm. stress, thus velocity is calculated by rheology (ln_dynRHGADV=T)
+      with 1 or 5 ice categories (jpl=1 or 5)
+
+b) the advection through an agrif zoom 1:3
+
+In case of purpose 2, one can test conservation of properties:
+---
+c) ice should not change at all if surface fluxes = 0 and SST = freezing temperature
+
+--------------------------------------
+Interpretation of the results (remarks)
+--------------------------------------
+- Prather conserves the max values but also creates side lobes
+- UM does not conserve the max but does not create side lobes
+- The "unmoving" ice (if any) is due to ice rheology which states that ice mass below a certain thresold (1kg/m2) is considered to move at the ocean velocity (thus 0 m/s)
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/domain_def_nemo.xml
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/domain_def_nemo.xml	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/domain_def_nemo.xml	(revision 9019)
@@ -0,0 +1,1 @@
+link ../../../SHARED/domain_def_nemo.xml
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/field_def_nemo-lim.xml
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/field_def_nemo-lim.xml	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/field_def_nemo-lim.xml	(revision 9019)
@@ -0,0 +1,1 @@
+link ../../../SHARED/field_def_nemo-lim.xml
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/field_def_nemo-opa.xml
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/field_def_nemo-opa.xml	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/field_def_nemo-opa.xml	(revision 9019)
@@ -0,0 +1,1 @@
+link ../../../SHARED/field_def_nemo-opa.xml
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/file_def_nemo-lim.xml
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/file_def_nemo-lim.xml	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/file_def_nemo-lim.xml	(revision 9019)
@@ -17,30 +17,37 @@
 	<file id="file1" name_suffix="_icemod" description="ice variables" enabled=".true." >
 
-        <field field_ref="snowthic_cea"     name="snthic"     long_name="surface_snow_thickness"   />
-        <field field_ref="snowvol"          name="snvolu" />
-        <field field_ref="isnowhc"          name="snheco" />
+        <field field_ref="snwvolu"          name="snvolu" />
+        <field field_ref="icethic"          name="sithic" />
+        <field field_ref="icevolu"          name="sivolu" />
+        <field field_ref="iceconc"          name="siconc" />
+        <field field_ref="icesalt"          name="sisali" />
+        <field field_ref="icetemp"          name="sitemp" />
+        <field field_ref="icettop"          name="sittop" />
+        <field field_ref="uice"             name="sivelu" />
+        <field field_ref="vice"             name="sivelv" />
+        <field field_ref="icevel"           name="sivelo" />
+        <field field_ref="icediv"           name="sidive" />
+        <field field_ref="iceshe"           name="sishea" />
+        <field field_ref="icestr"           name="sistre" />
+        <field field_ref="sst_m"            name="sst_m" />
 
-        <field field_ref="icethic_cea"      name="sithic"     long_name="sea_ice_thickness"        />
-        <field field_ref="icevolu"          name="sivolu" />
-        <field field_ref="iceconc"          name="siconc"  />
-        <field field_ref="micesalt"         name="sisali" />
-        <field field_ref="micet"            name="sitemp" />
-        <field field_ref="icest"            name="sistem" />
-        <field field_ref="icehc"            name="siheco" />
-        <field field_ref="uice_ipa"         name="sivelu" />
-        <field field_ref="vice_ipa"         name="sivelv" />
-        <field field_ref="icevel"           name="sivelo" />
-        <field field_ref="idive"            name="sidive" />
-        <field field_ref="ishear"           name="sishea" />
-        <field field_ref="icestr"           name="sistre" />
+        <!-- fluxes -->
+        <field field_ref="qt_oce_ai"        name="qt_oce_ai" />
+        <field field_ref="qt_atm_oi"        name="qt_atm_oi" />
+        <field field_ref="hfxcndtop"        name="hfxcndtop" />
+        <field field_ref="hfxcndbot"        name="hfxcndbot" />
+        <field field_ref="hfxsensib"        name="hfxsensib" />
+        <field field_ref="hfxbom"           name="hfxbom" />
+        <field field_ref="hfxbog"           name="hfxbog" />
+        <field field_ref="hfxsum"           name="hfxsum" />
+        <field field_ref="hfxopw"           name="hfxopw" />
+        <field field_ref="hfxdif"           name="hfxdif" />
+        <field field_ref="hfxsnw"           name="hfxsnw" />
+        <field field_ref="hfxerr"           name="hfxerr" />
+
         <!-- categories -->
-        <field field_ref="snowthic_cat"     name="snthicat"/>
+        <field field_ref="snwthic_cat"      name="snthicat"/>
         <field field_ref="iceconc_cat"      name="siconcat"/>
         <field field_ref="icethic_cat"      name="sithicat"/>
-        <field field_ref="salinity_cat"     name="salincat"/>
-        <field field_ref="iceage_cat"       name="siagecat"/>
-        <field field_ref="brinevol_cat"     name="sibricat"/>
-        <field field_ref="icetemp_cat"      name="sitemcat"/>
-        <field field_ref="snwtemp_cat"      name="sntemcat"/>
 
         </file>
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/make_INITICE.py
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/make_INITICE.py	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/make_INITICE.py	(revision 9019)
@@ -136,6 +136,6 @@
 # ----------------------------------------------
 # for basin=99x99km with dx=1km ; dy=1km + AGRIF
-sigx=-0.04
-sigy=-0.04
+sigx=-0.012
+sigy=-0.012
 xshift=20.-1.
 yshift=50.-1.
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/namelist_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/namelist_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/namelist_cfg	(revision 9019)
@@ -14,5 +14,6 @@
    cn_exp      =  "SASBIPER"  !  experience name
    nn_it000    =       1      !  first time step
-   nn_itend    =    10100     !  last  time step (std 5475)
+   nn_itend    =     500      !  last  time step (std 5475)
+   nn_istate   =       1      !  output the initial state (1) or not (0)
 /
 !-----------------------------------------------------------------------
@@ -26,5 +27,5 @@
 &namdom        !   space and time domain (bathymetry, mesh, timestep)
 !-----------------------------------------------------------------------
-   ln_linssh   = .true.   !  =T  linear free surface  ==>>  model level are fixed in time
+   ln_linssh   = .true.    !  =T  linear free surface  ==>>  model level are fixed in time
    !
    nn_msh      =    1      !  create (>0) a mesh file or not (=0)
@@ -33,6 +34,5 @@
 /
 !-----------------------------------------------------------------------
-&namcrs        !   Grid coarsening for dynamics output and/or
-               !   passive tracer coarsened online simulations
+&namcrs        !   coarsened grid (for outputs and/or TOP)              (ln_crs =T)
 !-----------------------------------------------------------------------
 /
@@ -47,4 +47,5 @@
    ln_blk      = .false.  !  Bulk formulation                          (T => fill namsbc_blk )
    nn_fsbc     =  1       !  frequency of surface boundary condition computation
+   nn_ice      =  2       !  sea-ice model
 /
 !-----------------------------------------------------------------------
@@ -53,4 +54,9 @@
 /
 !-----------------------------------------------------------------------
+&namsbc_sas    !   Stand Alone Surface boundary condition
+!-----------------------------------------------------------------------
+   l_sasread   = .false.   ! Read fields in a file if .TRUE. , or initialize to 0. in sbcssm.F90 if .FALSE.
+/
+!-----------------------------------------------------------------------
 &namtra_qsr    !   penetrative solar radiation
 !-----------------------------------------------------------------------
@@ -69,10 +75,7 @@
 /
 !-----------------------------------------------------------------------
-&namsbc_sas    !   Stand Alone Surface boundary condition
-!-----------------------------------------------------------------------
-   l_sasread   = .false.   ! Read fields in a file if .TRUE. , or initialize to 0. in sbcssm.F90 if .FALSE.
-!-----------------------------------------------------------------------
 &namberg       !   iceberg parameters
 !-----------------------------------------------------------------------
+   ln_bergdia               = .false.               ! Calculate budgets
 /
 !-----------------------------------------------------------------------
@@ -83,6 +86,12 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
+&namagrif      !  AGRIF zoom                                            ("key_agrif")
+!-----------------------------------------------------------------------
+   nn_cln_update =    1    !  baroclinic update frequency
+/
+!-----------------------------------------------------------------------
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_NONE    = .true.     !  free-slip       : Cd = 0                  
 /
 !-----------------------------------------------------------------------
@@ -100,11 +109,9 @@
 /
 !-----------------------------------------------------------------------
-&namtra_adv    !   advection scheme for tracer
+&namtra_adv    !   advection scheme for tracer                          (default: NO selection)
 !-----------------------------------------------------------------------
    ln_traadv_fct =  .true.    !  FCT scheme
       nn_fct_h   =  4               !  =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)
 /
 !-----------------------------------------------------------------------
@@ -160,7 +167,13 @@
 &namtra_dmp    !   tracer: T & S newtonian damping                      (default: NO)
 !-----------------------------------------------------------------------
-!-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection
-!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdyn_adv    !   formulation of the momentum advection                (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_dynadv_NONE= .false. !  linear dynamics (no momentum advection)
+   ln_dynadv_vec = .true. !  vector form - 2nd centered scheme
+     nn_dynkeg     = 0        ! grad(KE) scheme: =0   C2  ;  =1   Hollingsworth correction
+   ln_dynadv_cen2= .false. !  flux form - 2nd order centered scheme
+   ln_dynadv_ubs = .false. !  flux form - 3rd order UBS      scheme
 /
 !-----------------------------------------------------------------------
@@ -210,21 +223,19 @@
 /
 !-----------------------------------------------------------------------
-&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)
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .true.       !  constant mixing
+/
+!-----------------------------------------------------------------------
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  (ln_zdftke =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_iwm    !   tidal mixing parameterization                        (ln_zdfiwm =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi")
 !-----------------------------------------------------------------------
 /
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/namelist_ice_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/namelist_ice_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/namelist_ice_cfg	(revision 9019)
@@ -1,86 +1,105 @@
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-!! LIM3 namelist:  
-!!              1 - Generic parameters                 (namicerun)
-!!              2 - Diagnostics                        (namicediag)
-!!              3 - Ice initialization                 (namiceini)
-!!              4 - Ice discretization                 (namiceitd)
-!!              5 - Ice dynamics and transport         (namicedyn)
-!!              6 - Ice diffusion                      (namicehdf)
-!!              7 - Ice thermodynamics                 (namicethd)
-!!              8 - Ice salinity                       (namicesal)
-!!              9 - Ice mechanical redistribution      (namiceitdme)
+!! ESIM namelist:  
+!!              1 - Generic parameters                 (nampar)
+!!              2 - Ice thickness discretization       (namitd)
+!!              3 - Ice dynamics                       (namdyn)
+!!              4 - Ice ridging/rafting                (namdyn_rdgrft)
+!!              5 - Ice rheology                       (namdyn_rhg)
+!!              6 - Ice advection                      (namdyn_adv)
+!!              7 - Ice surface forcing                (namforcing)
+!!              8 - Ice thermodynamics                 (namthd)
+!!              9 - Ice heat diffusion                 (namthd_zdf)
+!!             10 - Ice lateral melting                (namthd_da)
+!!             11 - Ice growth in open water           (namthd_do)
+!!             12 - Ice salinity                       (namthd_sal)
+!!             13 - Ice melt ponds                     (namthd_pnd)
+!!             14 - Ice initialization                 (namini)
+!!             15 - Ice/snow albedos                   (namalb)
+!!             16 - Ice diagnostics                    (namdia)
 !!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 !
 !------------------------------------------------------------------------------
-&namicerun     !   Generic parameters
+&nampar         !   Generic parameters
 !------------------------------------------------------------------------------
-   jpl              =    1          !  number of ice  categories
-   nlay_i           =    1          !  number of ice  layers
-   ln_limthd        =  .false.       !  ice thermo   (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-   ln_limdyn        =  .true.       !  ice dynamics (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-   nn_limdyn        =   0           !     (ln_limdyn=T) switch for ice dynamics
-                                    !      2: total
-                                    !      1: advection only (no diffusion, no ridging/rafting)
-                                    !      0: advection only (as 1 but with prescribed velocity, bypass rheology)
-   rn_uice          =   0.5    !     (nn_limdyn=0) ice u-velocity
-   rn_vice          =   0.0    !     (nn_limdyn=0) ice v-velocity
+   ln_icedyn        = .true.          !  ice dynamics (T) or not (F)
+   ln_icethd        = .false.         !  ice thermo   (T) or not (F)
 /
 !------------------------------------------------------------------------------
-&namicediag    !   Diagnostics
+&namitd         !   Ice discretization
+!------------------------------------------------------------------------------
+   rn_himin         =   0.1           !  minimum ice thickness (m) used in remapping
+/
+!------------------------------------------------------------------------------
+&namdyn         !   Ice dynamics
+!------------------------------------------------------------------------------
+   ln_dynFULL       = .false.         !  dyn.: full ice dynamics               (rheology + advection + ridging/rafting + correction)
+   ln_dynRHGADV     = .true.          !  dyn.: no ridge/raft & no corrections  (rheology + advection)
+   ln_dynADV        = .false.         !  dyn.: only advection w prescribed vel.(rn_uvice + advection)
+      rn_uice       =   0.5           !        prescribed ice u-velocity
+      rn_vice       =   0.            !        prescribed ice v-velocity
+/
+!------------------------------------------------------------------------------
+&namdyn_rdgrft  !   Ice ridging/rafting
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namiceini     !   Ice initialization
-!------------------------------------------------------------------------------
-                  ! -- limistate -- !
-   ln_limini      = .true.         !  activate ice initialization (T) or not (F)
-   ln_limini_file = .true.         !  netcdf file provided for initialization (T) or not (F)
-   cn_dir="./"
-   sn_hti = 'initice'    , -12 ,'hti'   ,  .false.  , .true., 'yearly'  , '' , '', ''
-   sn_hts = 'initice'    , -12 ,'hts'   ,  .false.  , .true., 'yearly'  , '' , '', ''
-   sn_ati = 'initice'    , -12 ,'ati'   ,  .false.  , .true., 'yearly'  , '' , '', ''
-   sn_tsu = 'initice'    , -12 ,'tsu'   ,  .false.  , .true., 'yearly'  , '' , '', ''
-   sn_tmi = 'initice'    , -12 ,'tmi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
-   sn_smi = 'initice'    , -12 ,'smi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
-/
-!------------------------------------------------------------------------------
-&namiceitd     !   Ice discretization
+&namdyn_rhg     !   Ice rheology
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namicedyn     !   Ice dynamics and transport
+&namdyn_adv     !   Ice advection
 !------------------------------------------------------------------------------
-                  ! -- limtrp & limadv -- !
-   nn_limadv      =    0            !  choose the advection scheme (-1=Prather ; 0=Ultimate-Macho)
-   nn_limadv_ord  =    5            !  choose the order of the advection scheme (if nn_limadv=0)
+   ln_adv_Pra       = .false.         !  Advection scheme (Prather)
+   ln_adv_UMx       = .true.          !  Advection scheme (Ultimate-Macho)
+      nn_UMx        =   5             !     order of the scheme for UMx (1-5 ; 20=centered 2nd order)
 /
 !------------------------------------------------------------------------------
-&namicehdf     !   Ice horizontal diffusion
+&namforcing     !   Ice surface forcing
 !------------------------------------------------------------------------------
 /
 !------------------------------------------------------------------------------
-&namicethd     !   Ice thermodynamics
+&namthd         !   Ice thermodynamics
 !------------------------------------------------------------------------------
-                  ! -- limthd_dh -- !
-   ln_limdH       = .true.          !  activate ice thickness change from growing/melting (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-                  ! -- limthd_da -- !
-   ln_limdA       = .true.          !  activate lateral melting param. (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-                 ! -- limthd_lac -- !
-   ln_limdO       = .true.          !  activate ice growth in open-water (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-   rn_hnewice     = 0.02            !  thickness for new ice formation in open water (m)
-                  ! -- limitd_th -- !
-   rn_himin       = 0.01            !  minimum ice thickness (m) used in remapping, must be smaller than rn_hnewice
 /
 !------------------------------------------------------------------------------
-&namicesal     !   Ice salinity
+&namthd_zdf     !   Ice heat diffusion
 !------------------------------------------------------------------------------
-                 ! -- limthd_sal -- !
-   ln_limdS       = .true.          !  activate gravity drainage and flushing (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
 /
 !------------------------------------------------------------------------------
-&namiceitdme   !   Ice mechanical redistribution (ridging and rafting)
+&namthd_da      !   Ice lateral melting
 !------------------------------------------------------------------------------
-                  ! -- limitd_me -- !
-   ln_ridging     =   .true.        !  ridging activated (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
-   ln_rafting     =   .true.        !  rafting activated (T) or not (F) => DO NOT TOUCH UNLESS U KNOW WHAT U DO
 /
+!------------------------------------------------------------------------------
+&namthd_do      !   Ice growth in open water
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namthd_sal     !   Ice salinity
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namthd_pnd     !   Melt ponds
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namini         !   Ice initialization
+!------------------------------------------------------------------------------
+   ln_iceini        = .true.          !  activate ice initialization (T) or not (F)
+   ln_iceini_file   = .true.          !  netcdf file provided for initialization (T) or not (F)
+
+   sn_hti = 'initice'                 , -12 ,'hti'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_hts = 'initice'                 , -12 ,'hts'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_ati = 'initice'                 , -12 ,'ati'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_tsu = 'initice'                 , -12 ,'tsu'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_tmi = 'initice'                 , -12 ,'tmi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   sn_smi = 'initice'                 , -12 ,'smi'   ,  .false.  , .true., 'yearly'  , '' , '', ''
+   cn_dir='./'
+/
+!------------------------------------------------------------------------------
+&namalb         !   albedo parameters
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namdia         !   Diagnostics
+!------------------------------------------------------------------------------
+/
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/MY_SRC/par_oce.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/MY_SRC/par_oce.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/MY_SRC/par_oce.F90	(revision 9019)
@@ -0,0 +1,88 @@
+MODULE par_oce
+   !!======================================================================
+   !!                        ***  par_oce  ***
+   !! Ocean :   set the ocean parameters
+   !!======================================================================
+   !! History :  OPA  !  1991     (Imbard, Levy, Madec)  Original code
+   !!   NEMO     1.0  !  2004-01  (G. Madec, J.-M. Molines)  Free form and module
+   !!            3.3  !  2010-09  (C. Ethe) TRA-TRC merge: add jpts, jp_tem & jp_sal
+   !!----------------------------------------------------------------------
+   USE par_kind          ! kind parameters
+
+   IMPLICIT NONE
+   PUBLIC
+
+   !!----------------------------------------------------------------------
+   !!                   namcfg namelist parameters
+   !!----------------------------------------------------------------------
+   LOGICAL       ::   ln_read_cfg      !: (=T) read the domain configuration file or (=F) not
+   CHARACTER(lc) ::      cn_domcfg        !: filename the configuration file to be read
+   LOGICAL       ::   ln_write_cfg     !: (=T) create the domain configuration file
+   CHARACTER(lc) ::      cn_domcfg_out    !: filename the configuration file to be read
+   !
+   LOGICAL       ::   ln_use_jattr     !: input file read offset
+   !                                   !  Use file global attribute: open_ocean_jstart to determine start j-row 
+   !                                   !  when reading input from those netcdf files that have the 
+   !                                   !  attribute defined. This is designed to enable input files associated 
+   !                                   !  with the extended grids used in the under ice shelf configurations to 
+   !                                   !  be used without redundant rows when the ice shelves are not in use.
+   ! 
+
+   !!---------------------------------------------------------------------
+   !! Domain Matrix size 
+   !!---------------------------------------------------------------------
+   ! configuration name & resolution   (required only in ORCA family case)
+   CHARACTER(lc) ::   cn_cfg           !: name of the configuration
+   INTEGER       ::   nn_cfg           !: resolution of the configuration 
+
+   ! global domain size               !!! * total computational domain *
+   INTEGER       ::   jpiglo           !: 1st dimension of global domain --> i-direction
+   INTEGER       ::   jpjglo           !: 2nd    -                  -    --> j-direction
+   INTEGER       ::   jpkglo           !: 3nd    -                  -    --> k levels
+
+#if defined key_agrif
+
+!!gm  BUG ?   I'm surprised by the calculation below of nbcellsx and nbcellsy before jpiglo,jpjglo 
+!!gm                           has been assigned to a value....
+!!gm
+
+   ! global domain size for AGRIF     !!! * total AGRIF computational domain *
+   INTEGER, PUBLIC, PARAMETER ::   nbghostcells = 3                             !: number of ghost cells
+   INTEGER, PUBLIC            ::   nbcellsx     = jpiglo - 2 - 2*nbghostcells   !: number of cells in i-direction
+   INTEGER, PUBLIC            ::   nbcellsy     = jpjglo - 2 - 2*nbghostcells   !: number of cells in j-direction
+#endif
+
+   ! local domain size                !!! * local computational domain *
+   INTEGER, PUBLIC ::   jpi   ! = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   !: first  dimension
+   INTEGER, PUBLIC ::   jpj   ! = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   !: second dimension
+   INTEGER, PUBLIC ::   jpk   ! = jpkglo
+   INTEGER, PUBLIC ::   jpim1 ! = jpi-1                                            !: inner domain indices
+   INTEGER, PUBLIC ::   jpjm1 ! = jpj-1                                            !:   -     -      -
+   INTEGER, PUBLIC ::   jpkm1 ! = jpk-1                                            !:   -     -      -
+   INTEGER, PUBLIC ::   jpij  ! = jpi*jpj                                          !:  jpi x jpj
+
+   !!---------------------------------------------------------------------
+   !! Active tracer parameters
+   !!---------------------------------------------------------------------
+   INTEGER, PUBLIC, PARAMETER ::   jpts   = 2    !: Number of active tracers (=2, i.e. T & S )
+   INTEGER, PUBLIC, PARAMETER ::   jp_tem = 1    !: indice for temperature
+   INTEGER, PUBLIC, PARAMETER ::   jp_sal = 2    !: indice for salinity
+
+   !!----------------------------------------------------------------------
+   !!   Domain decomposition
+   !!----------------------------------------------------------------------
+   !! if we dont use massively parallel computer (parameters jpni=jpnj=1) so jpiglo=jpi and jpjglo=jpj
+   INTEGER, PUBLIC            ::   jpni         !: number of processors following i 
+   INTEGER, PUBLIC            ::   jpnj         !: number of processors following j
+   INTEGER, PUBLIC            ::   jpnij        !: nb of local domain = nb of processors ( <= jpni x jpnj )
+   INTEGER, PUBLIC, PARAMETER ::   jpr2di = 0   !: number of columns for extra outer halo 
+   INTEGER, PUBLIC, PARAMETER ::   jpr2dj = 0   !: number of rows    for extra outer halo 
+   INTEGER, PUBLIC, PARAMETER ::   jpreci = 1   !: number of columns for overlap 
+   INTEGER, PUBLIC, PARAMETER ::   jprecj = 1   !: number of rows    for overlap 
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2016)
+   !! $Id: par_oce.F90 7646 2017-02-06 09:25:03Z timgraham $ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!======================================================================
+END MODULE par_oce
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/MY_SRC/usrdef_sbc.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/MY_SRC/usrdef_sbc.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/MY_SRC/usrdef_sbc.F90	(revision 9019)
@@ -18,6 +18,6 @@
    USE sbc_ice         ! Surface boundary condition: ice fields
    USE phycst          ! physical constants
-   USE ice, ONLY       : pfrld, a_i_b
-   USE limthd_dh       ! for CALL lim_thd_snwblow
+   USE ice, ONLY       : at_i_b, a_i_b
+   USE icethd_dh       ! for CALL ice_thd_snwblow
    !
    USE in_out_manager  ! I/O manager
@@ -25,5 +25,4 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined) 
-   USE wrk_nemo
 
    IMPLICIT NONE
@@ -86,12 +85,12 @@
       INTEGER, INTENT(in) ::   kt   ! ocean time step
       !!---------------------------------------------------------------------
-      IF( kt==nit000 .AND. lwp)   WRITE(numout,*)' usrdef_sbc_ice : SAS_BIPER case: NO stress forcing'
+      IF( kt==nit000 .AND. lwp)   WRITE(numout,*)' usrdef_sbc_ice : SAS_BIPER case: constant stress forcing'
       !
-      utau_ice(:,:) = 0._wp
+      utau_ice(:,:) = 1.3_wp   ! <=> 0.5 m/s
       vtau_ice(:,:) = 0._wp
       !
    END SUBROUTINE usrdef_sbc_ice_tau
 
-   SUBROUTINE usrdef_sbc_ice_flx( kt )
+   SUBROUTINE usrdef_sbc_ice_flx( kt, phs, phi )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE usrdef_sbc_ice_flx  ***
@@ -99,8 +98,11 @@
       !! ** Purpose :   provide the surface boundary (flux) condition over sea-ice
       !!---------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:), POINTER ::   zsnw       ! snw distribution after wind blowing
       INTEGER, INTENT(in) ::   kt   ! ocean time step
+      REAL(wp), DIMENSION(:,:,:), INTENT(in)  ::   phs    ! snow thickness
+      REAL(wp), DIMENSION(:,:,:), INTENT(in)  ::   phi    ! ice thickness
+      !!
+      REAL(wp) ::   zfr1, zfr2                 ! local variables
+      REAL(wp), DIMENSION(jpi,jpj) ::   zsnw   ! snw distribution after wind blowing
       !!---------------------------------------------------------------------
-      CALL wrk_alloc( jpi,jpj, zsnw )
       !
       IF( kt==nit000 .AND. lwp)   WRITE(numout,*)' usrdef_sbc_ice : SAS_BIPER case: NO flux forcing'
@@ -120,5 +122,5 @@
       ! ice fields deduced from above
       zsnw(:,:) = 1._wp
-      !!CALL lim_thd_snwblow( pfrld, zsnw )  ! snow distribution over ice after wind blowing 
+      !!CALL lim_thd_snwblow( at_i_b, zsnw )  ! snow distribution over ice after wind blowing 
       emp_ice  (:,:)   = SUM( a_i_b(:,:,:) * evap_ice(:,:,:), dim=3 ) - sprecip(:,:) * zsnw(:,:)
       emp_oce  (:,:)   = emp_oce(:,:) - sprecip(:,:) * (1._wp - zsnw(:,:) )
@@ -130,16 +132,19 @@
       ! total fluxes
       emp_tot (:,:) = emp_ice  + emp_oce
-      qns_tot (:,:) = pfrld(:,:) * qns_oce(:,:) + SUM( a_i_b(:,:,:) * qns_ice(:,:,:), dim=3 ) + qemp_ice(:,:) + qemp_oce(:,:)
-      qsr_tot (:,:) = pfrld(:,:) * qsr_oce(:,:) + SUM( a_i_b(:,:,:) * qsr_ice(:,:,:), dim=3 )
+      qns_tot (:,:) = at_i_b(:,:) * qns_oce(:,:) + SUM( a_i_b(:,:,:) * qns_ice(:,:,:), dim=3 ) + qemp_ice(:,:) + qemp_oce(:,:)
+      qsr_tot (:,:) = at_i_b(:,:) * qsr_oce(:,:) + SUM( a_i_b(:,:,:) * qsr_ice(:,:,:), dim=3 )
 
-      !--------------------------------------------------------------------
-      ! FRACTIONs of net shortwave radiation which is not absorbed in the
-      ! thin surface layer and penetrates inside the ice cover
-      ! ( Maykut and Untersteiner, 1971 ; Ebert and Curry, 1993 )
-      fr1_i0(:,:) = ( 0.18 * ( 1.0 - cldf_ice ) + 0.35 * cldf_ice )
-      fr2_i0(:,:) = ( 0.82 * ( 1.0 - cldf_ice ) + 0.65 * cldf_ice )
-
-      CALL wrk_dealloc( jpi,jpj, zsnw )
-
+      ! --- shortwave radiation transmitted below the surface (W/m2, see Grenfell Maykut 77) --- !
+      zfr1 = ( 0.18 * ( 1.0 - cldf_ice ) + 0.35 * cldf_ice )            ! transmission when hi>10cm
+      zfr2 = ( 0.82 * ( 1.0 - cldf_ice ) + 0.65 * cldf_ice )            ! zfr2 such that zfr1 + zfr2 to equal 1
+      !
+      WHERE    ( phs(:,:,:) <= 0._wp .AND. phi(:,:,:) <  0.1_wp )       ! linear decrease from hi=0 to 10cm  
+         qsr_ice_tr(:,:,:) = qsr_ice(:,:,:) * ( zfr1 + zfr2 * ( 1._wp - phi(:,:,:) * 10._wp ) )
+      ELSEWHERE( phs(:,:,:) <= 0._wp .AND. phi(:,:,:) >= 0.1_wp )       ! constant (zfr1) when hi>10cm
+         qsr_ice_tr(:,:,:) = qsr_ice(:,:,:) * zfr1
+      ELSEWHERE                                                         ! zero when hs>0
+         qsr_ice_tr(:,:,:) = 0._wp 
+      END WHERE
+          
    END SUBROUTINE usrdef_sbc_ice_flx
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/MY_SRC/usrdef_zgr.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/MY_SRC/usrdef_zgr.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/MY_SRC/usrdef_zgr.F90	(revision 9019)
@@ -62,5 +62,5 @@
       !
       IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'usr_def_zgr : LOCK_EXCHANGE configuration (z-coordinate closed box ocean without cavities)'
+      IF(lwp) WRITE(numout,*) 'usr_def_zgr : SAS_BIPER configuration (slab ocean - advection of an ice patch in a biperiodic square box domain)'
       IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
       !
@@ -68,8 +68,7 @@
       ! type of vertical coordinate
       ! ---------------------------
-      ! set in usrdef_nam.F90 by reading the namusr_def namelist only ln_zco
-      ln_zco    = .TRUE.       ! z-partial-step coordinate
-      ln_zps    = .FALSE.      ! z-partial-step coordinate
-      ln_sco    = .FALSE.      ! s-coordinate
+      ld_zco    = .TRUE.       ! z-full-step coordinate
+      ld_zps    = .FALSE.      ! z-partial-step coordinate
+      ld_sco    = .FALSE.      ! s-coordinate
       ld_isfcav = .FALSE.      ! ISF Ice Shelves Flag
       !
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/WAD/EXP00/namelist_cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/WAD/EXP00/namelist_cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/WAD/EXP00/namelist_cfg	(revision 9019)
@@ -32,10 +32,4 @@
 /
 !-----------------------------------------------------------------------
-&namzgr        !   vertical coordinate
-!-----------------------------------------------------------------------
-   ln_zps      = .false.   !  z-coordinate - partial steps
-   ln_sco      = .true.    !  s-coordinate
-/
-!-----------------------------------------------------------------------
 &namdom        !   space and time domain (bathymetry, mesh, timestep)
 !-----------------------------------------------------------------------
@@ -46,6 +40,5 @@
 /
 !-----------------------------------------------------------------------
-&namcrs        !   Grid coarsening for dynamics output and/or
-               !   passive tracer coarsened online simulations
+&namcrs        !   coarsened grid (for outputs and/or TOP)              (ln_crs =T)
 !-----------------------------------------------------------------------
 /
@@ -62,32 +55,10 @@
    nn_fsbc     = 1         !  frequency of surface boundary condition computation
    !                       !     (also = the frequency of sea-ice model call)
-   ln_usr      = .true.    !  analytical formulation                    (T => fill namsbc_ana )
-   ln_blk      = .false.   !  CORE bulk formulation                     (T => fill namsbc_core)
+   ln_usr      = .true.    !  analytical formulation                    (T => check usrdef_sbc)
+   ln_blk      = .false.   !  CORE bulk formulation                     (T => fill namsbc_blk )
    nn_ice      = 0         !  =0 no ice boundary condition   ,
-   ln_rnf      = .false.   !  runoffs                                   (T => fill namsbc_rnf)
-   ln_ssr      = .false.   !  Sea Surface Restoring on T and/or S       (T => fill namsbc_ssr)
+   ln_rnf      = .false.   !  runoffs                                   (T => fill namsbc_rnf )
+   ln_ssr      = .false.   !  Sea Surface Restoring on T and/or S       (T => fill namsbc_ssr )
    nn_fwb      = 0         !  FreshWater Budget: =0 unchecked
-/
-!-----------------------------------------------------------------------
-&namsbc_ana    !   analytical surface boundary condition
-!-----------------------------------------------------------------------
-   nn_tau000   =   100     !  gently increase the stress over the first ntau_rst time-steps
-   rn_utau0    =   0.0e0   !  uniform value for the i-stress
-/
-!-----------------------------------------------------------------------
-&namsbc_flx    !   surface boundary condition : flux formulation
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namsbc_clio   !   namsbc_clio  CLIO bulk formulae
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namsbc_core   !   namsbc_core  CORE bulk formulae
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namsbc_mfs   !   namsbc_mfs  MFS bulk formulae
-!-----------------------------------------------------------------------
 /
 !-----------------------------------------------------------------------
@@ -202,14 +173,18 @@
 /
 !-----------------------------------------------------------------------
-&nambfr        !   bottom friction
-!-----------------------------------------------------------------------
-   nn_bfr      =    2      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
-   !rn_bfri2    =    1.e-5  !  bottom drag coefficient (non linear case). Minimum coeft if ln_loglayer=T
-   !rn_bfri2_max =   1.e-4  !  max. bottom drag coefficient (non linear case and ln_loglayer=T)
-   rn_bfri2    =    1.e-5  !  bottom drag coefficient (non linear case). Minimum coeft if ln_loglayer=T
-   rn_bfri2_max =   1.e-4  !  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_loglayer = .true.    !  logarithmic formulation (non linear case)
+&namdrg            !   top/bottom drag coefficient                      (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_loglayer= .false.    !  logarithmic drag: Cd = vkarmn/log(z/z0) |U|
+/
+!-----------------------------------------------------------------------
+&namdrg_bot        !   BOTTOM friction                                  
+!-----------------------------------------------------------------------
+   rn_Cd0     =  1.e-4    !  drag coefficient [-]
+   rn_Uc0     =  0.1      !  ref. velocity [m/s] (linear drag=Cd0*Uc0) 
+   rn_Cdmax   =  1.e-4    !  drag value maximum [-] (logarithmic drag)
+   rn_ke0     =  2.5e-3   !  background kinetic energy  [m2/s2] (non-linear cases)
+   rn_z0      =  3.e-3    !  roughness [m] (ln_loglayer=T)
+   ln_boost   = .false.   !  =T regional boost of Cd0 ; =F constant
+      rn_boost=  50.         !  local boost factor  [-]
 /
 !-----------------------------------------------------------------------
@@ -244,6 +219,7 @@
 /
 !-----------------------------------------------------------------------
-&namtra_adv    !   advection scheme for tracer
-!-----------------------------------------------------------------------
+&namtra_adv    !   advection scheme for tracer                          (default: No selection)
+!-----------------------------------------------------------------------
+   ln_traadv_NONE=  .false.  !  No tracer advection
    ln_traadv_cen =  .false.  !  2nd order centered scheme
    ln_traadv_mus =  .false.  !  MUSCL scheme
@@ -251,6 +227,4 @@
       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)
 /
 !-----------------------------------------------------------------------
@@ -300,5 +274,11 @@
 /
 !-----------------------------------------------------------------------
-&namdyn_adv    !   formulation of the momentum advection
+&namdyn_adv    !   formulation of the momentum advection                (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_dynadv_NONE= .false. !  linear dynamics (no momentum advection)
+   ln_dynadv_vec = .true. !  vector form - 2nd centered scheme
+     nn_dynkeg     = 0        ! grad(KE) scheme: =0   C2  ;  =1   Hollingsworth correction
+   ln_dynadv_cen2= .false. !  flux form - 2nd order centered scheme
+   ln_dynadv_ubs = .false. !  flux form - 3rd order UBS      scheme
 !-----------------------------------------------------------------------
 /
@@ -350,31 +330,54 @@
    rn_bhm_0      =      0.     !  horizontal bilaplacian eddy viscosity [m4/s]
 /
-!-----------------------------------------------------------------------
-&namzdf        !   vertical physics
-!-----------------------------------------------------------------------
-   nn_evdm     =    1      !  evd apply on tracer (=0) or on tracer and momentum (=1)
-/
-!-----------------------------------------------------------------------
-&namzdf_ric    !   richardson number dependent vertical diffusion       ("key_zdfric" )
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  ("key_zdftke")
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!======================================================================
+!!    namzdf        vertical physics
+!!    namzdf_ric    richardson number vertical mixing                   (ln_zdfric=T)
+!!    namzdf_tke    TKE vertical mixing                                 (ln_zdftke=T)
+!!    namzdf_gls    GLS vertical mixing                                 (ln_zdfgls=T)
+!!    namzdf_iwm    tidal mixing parameterization                       (ln_zdfiwm=T)
+!!======================================================================
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       ! type of vertical closure
+   ln_zdfcst   = .false.      !  constant mixing
+   ln_zdfric   = .false.      !  local Richardson dependent formulation (T =>   fill namzdf_ric)
+   ln_zdftke   = .true.       !  Turbulent Kinetic Energy closure       (T =>   fill namzdf_tke)
+   ln_zdfgls   = .false.      !  Generic Length Scale closure           (T =>   fill namzdf_gls)
+   ln_zdfosm   = .false.      !  OSMOSIS BL closure                     (T =>   fill namzdf_osm)
+   !
+   !                       ! convection
+   ln_zdfevd   = .true.       !  enhanced vertical diffusion
+      nn_evdm     =    1         ! apply on tracer (=0) or on tracer and momentum (=1)
+      rn_evd      =  100.        ! mixing coefficient [m2/s]
+   ln_zdfnpc   = .false.      !  Non-Penetrative Convective algorithm
+      nn_npc      =    1         ! frequency of application of npc
+      nn_npcp     =  365         ! npc control print frequency
+   !
+   ln_zdfddm   = .false.   ! double diffusive mixing
+      rn_avts  =    1.e-4     !  maximum avs (vertical mixing on salinity)
+      rn_hsbfr =    1.6       !  heat/salt buoyancy flux ratio
+   !
+   !                       ! gravity wave-driven vertical mixing
+   ln_zdfiwm   = .false.      ! internal wave-induced mixing            (T =>   fill namzdf_iwm)
+   ln_zdfswm   = .false.      ! surface  wave-induced mixing            (T => ln_wave=ln_sdw=T )
+   !
+   !                       ! coefficients
+   rn_avm0     =   1.2e-4     !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   1.2e-5     !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
+/
+!-----------------------------------------------------------------------
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  (ln_zdftke =T)
 !-----------------------------------------------------------------------
    nn_etau     =   0       !  penetration of tke below the mixed layer (ML) due to internal & intertial waves
 /
-!-----------------------------------------------------------------------
-&namzdf_gls                !   GLS vertical diffusion                   ("key_zdfgls")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_ddm    !   double diffusive mixing parameterization             ("key_zdfddm")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namzdf_tmx    !   tidal mixing parameterization                        ("key_zdftmx")
-!-----------------------------------------------------------------------
-   ln_tmx_itf  = .false.   !  ITF specific parameterisation
-/
+
+!!======================================================================
+!!                  ***  Miscellaneous namelists  ***
+!!======================================================================
 !-----------------------------------------------------------------------
 &nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi)
@@ -411,12 +414,4 @@
 !!gm
 !-----------------------------------------------------------------------
-&namflo       !   float parameters                                      ("key_float")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
-&namptr       !   Poleward Transport Diagnostic
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
 &namhsb       !  Heat and salt budgets
 !-----------------------------------------------------------------------
@@ -430,5 +425,5 @@
 /
 !-----------------------------------------------------------------------
-&namobs       !  observation usage switch                               ('key_diaobs')
+&namobs       !  observation usage switch
 !-----------------------------------------------------------------------
 /
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/WAD/MY_SRC/bdyini.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/WAD/MY_SRC/bdyini.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/WAD/MY_SRC/bdyini.F90	(revision 9019)
@@ -351,28 +351,5 @@
         IF(lwp) WRITE(numout,*)
 
-#if defined key_lim2
-        IF(lwp) WRITE(numout,*) 'Boundary conditions for sea ice:  '
-        SELECT CASE( cn_ice_lim(ib_bdy) )                  
-          CASE('none')
-             IF(lwp) WRITE(numout,*) '      no open boundary condition'        
-             dta_bdy(ib_bdy)%ll_frld  = .false.
-             dta_bdy(ib_bdy)%ll_hicif = .false.
-             dta_bdy(ib_bdy)%ll_hsnif = .false.
-          CASE('frs')
-             IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
-             dta_bdy(ib_bdy)%ll_frld  = .true.
-             dta_bdy(ib_bdy)%ll_hicif = .true.
-             dta_bdy(ib_bdy)%ll_hsnif = .true.
-          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_ice_lim' )
-        END SELECT
-        IF( cn_ice_lim(ib_bdy) /= 'none' ) THEN 
-           SELECT CASE( nn_ice_lim_dta(ib_bdy) )                   ! 
-              CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for bdy data'        
-              CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      boundary data taken from file'
-              CASE DEFAULT   ;   CALL ctl_stop( 'nn_ice_lim_dta must be 0 or 1' )
-           END SELECT
-        ENDIF
-        IF(lwp) WRITE(numout,*)
-#elif defined key_lim3
+#if defined key_lim3
         IF(lwp) WRITE(numout,*) 'Boundary conditions for sea ice:  '
         SELECT CASE( cn_ice_lim(ib_bdy) )                  
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/WAD/MY_SRC/usrdef_sbc.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/WAD/MY_SRC/usrdef_sbc.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/WAD/MY_SRC/usrdef_sbc.F90	(revision 9019)
@@ -16,4 +16,5 @@
    USE dom_oce         ! ocean space and time domain
    USE sbc_oce         ! Surface boundary condition: ocean fields
+   USE sbc_ice         ! Surface boundary condition: ice fields
    USE phycst          ! physical constants
    !
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/WAD/cpp_WAD.fcm
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/WAD/cpp_WAD.fcm	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/WAD/cpp_WAD.fcm	(revision 9019)
@@ -1,1 +1,1 @@
- bld::tool::fppkeys key_zdftke key_iomput key_mpp_mpi key_nosignedzero
+ bld::tool::fppkeys   key_iomput key_mpp_mpi key_nosignedzero
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/cfg.txt
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/cfg.txt	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/cfg.txt	(revision 9019)
@@ -2,4 +2,6 @@
 WAD OPA_SRC
 LOCK_EXCHANGE OPA_SRC
+ISOMIP OPA_SRC
 SAS_BIPER OPA_SRC SAS_SRC LIM_SRC_3 NST_SRC
-ISOMIP OPA_SRC
+ISOMIP_LONG OPA_SRC
+ISOMIP_32 OPA_SRC
Index: /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/cfg.txt
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/cfg.txt	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/CONFIG/cfg.txt	(revision 9019)
@@ -6,3 +6,6 @@
 ORCA2_OFF_PISCES OPA_SRC OFF_SRC TOP_SRC
 ORCA2_OFF_TRC OPA_SRC OFF_SRC TOP_SRC
+GYRE_PISCES_XIOS OPA_SRC TOP_SRC
+ORCA2_LIM3 OPA_SRC LIM_SRC_3 NST_SRC
+GYRE_PISCES_RK3 RK3_SRC TOP_SRC
 ORCA2_LIM3_PISCES OPA_SRC LIM_SRC_3 TOP_SRC NST_SRC
Index: /branches/2017/dev_merge_2017/NEMOGCM/EXTERNAL/AGRIF/LIB/decl.h
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/EXTERNAL/AGRIF/LIB/decl.h	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/EXTERNAL/AGRIF/LIB/decl.h	(revision 9019)
@@ -36,5 +36,5 @@
 #define LONG_FNAME 1000		// Max length for a file name
 #define LONG_C     200
-#define LONG_M     1500
+#define LONG_M     2000
 
 #define NB_CAT_VARIABLES 5
Index: /branches/2017/dev_merge_2017/NEMOGCM/EXTERNAL/AGRIF/nemo_mpi.h
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/EXTERNAL/AGRIF/nemo_mpi.h	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/EXTERNAL/AGRIF/nemo_mpi.h	(revision 9019)
@@ -0,0 +1,3 @@
+#if defined key_mpp_mpi
+#define AGRIF_MPI
+#endif
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/ice.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/ice.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/ice.F90	(revision 9019)
@@ -1,7 +1,7 @@
 MODULE ice
    !!======================================================================
-   !!                        ***  MODULE ice  ***
-   !! LIM-3 Sea Ice physics:  diagnostics variables of ice defined in memory
-   !!=====================================================================
+   !!                        ***  MODULE  ice  ***
+   !!   sea-ice:  ice variables defined in memory
+   !!======================================================================
    !! History :  3.0  ! 2008-03  (M. Vancoppenolle) original code LIM-3
    !!            4.0  ! 2011-02  (G. Madec) dynamical allocation
@@ -9,5 +9,5 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM-3 sea-ice model
+   !!   'key_lim3'                                       ESIM sea-ice model
    !!----------------------------------------------------------------------
    USE in_out_manager ! I/O manager
@@ -17,5 +17,5 @@
    PRIVATE
 
-   PUBLIC    ice_alloc  !  Called in sbc_lim_init
+   PUBLIC   ice_alloc   ! called by icestp.F90
 
    !!======================================================================
@@ -63,21 +63,20 @@
    !!   meaningful and/or used in ice thermodynamics                      |
    !!                                                                     |
-   !! Routines in limvar.F90 perform conversions                          |
-   !!  - lim_var_glo2eqv  : from global to equivalent variables           |
-   !!  - lim_var_eqv2glo  : from equivalent to global variables           |
+   !! Routines in icevar.F90 perform conversions                          |
+   !!  - ice_var_glo2eqv  : from global to equivalent variables           |
+   !!  - ice_var_eqv2glo  : from equivalent to global variables           |
    !!                                                                     |
    !! For various purposes, the sea ice state variables have sometimes    |
    !! to be aggregated over all ice thickness categories. This operation  |
    !! is done in :                                                        |
-   !!  - lim_var_agg                                                      |
+   !!  - ice_var_agg                                                      |
    !!                                                                     |
    !! in icestp.F90, the routines that compute the changes in the ice     |
    !! state variables are called                                          |
-   !! - lim_dyn : ice dynamics                                            |
-   !! - lim_trp : ice transport                                           |
-   !! - lim_itd_me : mechanical redistribution (ridging and rafting)      |
-   !! - lim_thd : ice halo-thermodynamics                                 |
-   !! - lim_itd_th : thermodynamic changes in ice thickness distribution  |
-   !!                and creation of new ice                              |
+   !! - ice_rhg : ice dynamics                                            |
+   !! - ice_adv : ice advection                                           |
+   !! - ice_rdgrft : ice ridging and rafting                              |
+   !! - ice_thd : ice halo-thermodynamics and creation of new ice         |
+   !! - ice_itd : thermodynamic changes in ice thickness distribution     |
    !!                                                                     |
    !! See the associated routines for more information                    |
@@ -107,10 +106,10 @@
    !! v_i         |      -      |    Ice volume per unit area     | m     |
    !! v_s         |      -      |    Snow volume per unit area    | m     |
-   !! smv_i       |      -      |    Sea ice salt content         | ppt.m |
-   !! oa_i        !      -      !    Sea ice areal age content    | day   |
+   !! sv_i        |      -      |    Sea ice salt content         | ppt.m |
+   !! oa_i        !      -      !    Sea ice areal age content    | s     |
    !! e_i         !      -      !    Ice enthalpy                 | J/m2  | 
-   !!      -      ! q_i_1d      !    Ice enthalpy per unit vol.   | J/m3  | 
+   !!      -      ! e_i_1d      !    Ice enthalpy per unit vol.   | J/m3  | 
    !! e_s         !      -      !    Snow enthalpy                | J/m2  | 
-   !!      -      ! q_s_1d      !    Snow enthalpy per unit vol.  | J/m3  | 
+   !!      -      ! e_s_1d      !    Snow enthalpy per unit vol.  | J/m3  | 
    !!                                                                     |
    !!-------------|-------------|---------------------------------|-------|
@@ -119,9 +118,9 @@
    !!-------------|-------------|---------------------------------|-------|
    !!                                                                     |
-   !! ht_i        | ht_i_1d     |    Ice thickness                | m     |
-   !! ht_s        ! ht_s_1d     |    Snow depth                   | m     |
-   !! sm_i        ! sm_i_1d     |    Sea ice bulk salinity        ! ppt   |
-   !! s_i         ! s_i_1d      |    Sea ice salinity profile     ! ppt   |
-   !! o_i         !      -      |    Sea ice Age                  ! days  |
+   !! h_i         | h_i_1d      |    Ice thickness                | m     |
+   !! h_s         ! h_s_1d      |    Snow depth                   | m     |
+   !! s_i         ! s_i_1d      |    Sea ice bulk salinity        ! ppt   |
+   !! sz_i        ! sz_i_1d     |    Sea ice salinity profile     ! ppt   |
+   !! o_i         !      -      |    Sea ice Age                  ! s     |
    !! t_i         ! t_i_1d      |    Sea ice temperature          ! K     |
    !! t_s         ! t_s_1d      |    Snow temperature             ! K     |
@@ -144,5 +143,5 @@
    !! vt_i        |      -      |    Total ice vol. per unit area | m     |
    !! vt_s        |      -      |    Total snow vol. per unit ar. | m     |
-   !! smt_i       |      -      |    Mean sea ice salinity        | ppt   |
+   !! sm_i        |      -      |    Mean sea ice salinity        | ppt   |
    !! tm_i        |      -      |    Mean sea ice temperature     | K     |
    !! et_i        !      -      !    Total ice enthalpy           | J/m2  | 
@@ -151,105 +150,60 @@
    !!=====================================================================
 
-   LOGICAL, PUBLIC ::   con_i = .false.   ! switch for conservation test
-
-   !!--------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    !! * Share Module variables
-   !!--------------------------------------------------------------------------
-   !                                     !!** ice-generic parameters namelist (namicerun) **
-   INTEGER           , PUBLIC ::   jpl             !: number of ice  categories 
-   INTEGER           , PUBLIC ::   nlay_i          !: number of ice  layers 
-   INTEGER           , PUBLIC ::   nlay_s          !: number of snow layers 
-   REAL(wp)          , PUBLIC ::   rn_amax_n       !: maximum ice concentration Northern hemisphere
-   REAL(wp)          , PUBLIC ::   rn_amax_s       !: maximum ice concentration Southern hemisphere
-   CHARACTER(len=32) , PUBLIC ::   cn_icerst_in    !: suffix of ice restart name (input)
-   CHARACTER(len=32) , PUBLIC ::   cn_icerst_out   !: suffix of ice restart name (output)
-   CHARACTER(len=256), PUBLIC ::   cn_icerst_indir !: ice restart input directory
-   CHARACTER(len=256), PUBLIC ::   cn_icerst_outdir!: ice restart output directory
-   LOGICAL           , PUBLIC ::   ln_limthd       !: flag for ice thermo (T) or not (F)
-   LOGICAL           , PUBLIC ::   ln_limdyn       !: flag for ice dynamics (T) or not (F)
-   INTEGER           , PUBLIC ::   nn_limdyn       !: flag for ice dynamics
-   REAL(wp)          , PUBLIC ::   rn_uice         !: prescribed u-vel (case nn_limdyn=0)
-   REAL(wp)          , PUBLIC ::   rn_vice         !: prescribed v-vel (case nn_limdyn=0)
+   !!----------------------------------------------------------------------
+   !                                     !!** ice-generic parameters namelist (nampar) **
+   INTEGER           , PUBLIC ::   jpl              !: number of ice  categories 
+   INTEGER           , PUBLIC ::   nlay_i           !: number of ice  layers 
+   INTEGER           , PUBLIC ::   nlay_s           !: number of snow layers 
+   INTEGER           , PUBLIC ::   nn_monocat       !: virtual ITD mono-category parameterizations (1-4) or not (0)
+   LOGICAL           , PUBLIC ::   ln_icedyn        !: flag for ice dynamics (T) or not (F)
+   LOGICAL           , PUBLIC ::   ln_icethd        !: flag for ice thermo   (T) or not (F)
+   REAL(wp)          , PUBLIC ::   rn_amax_n        !: maximum ice concentration Northern hemisphere
+   REAL(wp)          , PUBLIC ::   rn_amax_s        !: maximum ice concentration Southern hemisphere
+   CHARACTER(len=256), PUBLIC ::   cn_icerst_in     !: suffix of ice restart name (input)
+   CHARACTER(len=256), PUBLIC ::   cn_icerst_out    !: suffix of ice restart name (output)
+   CHARACTER(len=256), PUBLIC ::   cn_icerst_indir  !: ice restart input directory
+   CHARACTER(len=256), PUBLIC ::   cn_icerst_outdir !: ice restart output directory
+
+   !                                     !!** ice-itd namelist (namitd) **
+   REAL(wp), PUBLIC ::   rn_himin         !: minimum ice thickness
    
-   !                                     !!** ice-diagnostics namelist (namicediag) **
-   LOGICAL , PUBLIC ::   ln_limdiachk     !: flag for ice diag (T) or not (F)
-   LOGICAL , PUBLIC ::   ln_limdiahsb     !: flag for ice diag (T) or not (F)
-   LOGICAL , PUBLIC ::   ln_limctl        !: flag for sea-ice points output (T) or not (F)
-   INTEGER , PUBLIC ::   iiceprt          !: debug i-point
-   INTEGER , PUBLIC ::   jiceprt          !: debug j-point
-
-   !                                     !!** ice-init namelist (namiceini) **
-                                          ! -- limistate -- !
-   LOGICAL , PUBLIC ::   ln_limini        ! initialization or not
-   LOGICAL , PUBLIC ::   ln_limini_file   ! Ice initialization state from 2D netcdf file
-   REAL(wp), PUBLIC ::   rn_thres_sst     ! threshold water temperature for initial sea ice
-   REAL(wp), PUBLIC ::   rn_hts_ini_n     ! initial snow thickness in the north
-   REAL(wp), PUBLIC ::   rn_hts_ini_s     ! initial snow thickness in the south
-   REAL(wp), PUBLIC ::   rn_hti_ini_n     ! initial ice thickness in the north
-   REAL(wp), PUBLIC ::   rn_hti_ini_s     ! initial ice thickness in the south
-   REAL(wp), PUBLIC ::   rn_ati_ini_n     ! initial leads area in the north
-   REAL(wp), PUBLIC ::   rn_ati_ini_s     ! initial leads area in the south
-   REAL(wp), PUBLIC ::   rn_smi_ini_n     ! initial salinity 
-   REAL(wp), PUBLIC ::   rn_smi_ini_s     ! initial salinity
-   REAL(wp), PUBLIC ::   rn_tmi_ini_n     ! initial temperature
-   REAL(wp), PUBLIC ::   rn_tmi_ini_s     ! initial temperature
-   
-   !                                     !!** ice-thickness distribution namelist (namiceitd) **
-   INTEGER , PUBLIC ::   nn_catbnd        !: categories distribution following: tanh function (1), or h^(-alpha) function (2)
-   REAL(wp), PUBLIC ::   rn_himean        !: mean thickness of the domain (used to compute the distribution, nn_itdshp = 2 only)
-
-   !                                     !!** ice-dynamics namelist (namicedyn) **
-                                          ! -- limtrp & limadv -- !
-   INTEGER , PUBLIC ::   nn_limadv        !: choose the advection scheme (-1=Prather ; 0=Ultimate-Macho)
-   INTEGER , PUBLIC ::   nn_limadv_ord    !: choose the order of the advection scheme (if Ultimate-Macho)   
-                                          ! -- limitd_me -- !
-   INTEGER , PUBLIC ::   nn_icestr        !: ice strength parameterization (0=Hibler79 1=Rothrock75)
-   REAL(wp), PUBLIC ::   rn_pe_rdg        !: ridging work divided by pot. energy change in ridging, nn_icestr = 1
-   REAL(wp), PUBLIC ::   rn_pstar         !: determines ice strength, Hibler JPO79
-   REAL(wp), PUBLIC ::   rn_crhg          !: determines changes in ice strength
-   LOGICAL , PUBLIC ::   ln_icestr_bvf    !: use brine volume to diminish ice strength
-                                          ! -- limdyn & limrhg -- !
-   REAL(wp), PUBLIC ::   rn_cio           !: drag coefficient for oceanic stress
+   !                                     !!** ice-dynamics namelist (namdyn) **
+   REAL(wp), PUBLIC ::   rn_ishlat        !: lateral boundary condition for sea-ice
+   LOGICAL , PUBLIC ::   ln_landfast      !: landfast ice parameterization (T or F) 
+   REAL(wp), PUBLIC ::   rn_gamma         !:    fraction of ocean depth that ice must reach to initiate landfast ice
+   REAL(wp), PUBLIC ::   rn_icebfr        !:    maximum bottom stress per unit area of contact (landfast ice) 
+   REAL(wp), PUBLIC ::   rn_lfrelax       !:    relaxation time scale (s-1) to reach static friction (landfast ice) 
+   !
+   !                                     !!** ice-rheology namelist (namrhg) **
+   LOGICAL , PUBLIC ::   ln_aEVP          !: using adaptive EVP (T or F) 
    REAL(wp), PUBLIC ::   rn_creepl        !: creep limit : has to be under 1.0e-9
    REAL(wp), PUBLIC ::   rn_ecc           !: eccentricity of the elliptical yield curve
    INTEGER , PUBLIC ::   nn_nevp          !: number of iterations for subcycling
    REAL(wp), PUBLIC ::   rn_relast        !: ratio => telast/rdt_ice (1/3 or 1/9 depending on nb of subcycling nevp) 
-   LOGICAL , PUBLIC ::   ln_landfast      !: landfast ice parameterization (T or F) 
-   REAL(wp), PUBLIC ::   rn_gamma         !: fraction of ocean depth that ice must reach to initiate landfast ice
-   REAL(wp), PUBLIC ::   rn_icebfr        !: maximum bottom stress per unit area of contact (landfast ice) 
-   REAL(wp), PUBLIC ::   rn_lfrelax       !: relaxation time scale (s-1) to reach static friction (landfast ice) 
-
-   !                                     !!** ice-diffusion namelist (namicehdf) **
-   INTEGER , PUBLIC ::   nn_ahi0          !: sea-ice hor. eddy diffusivity coeff. (3 ways of calculation)
-   REAL(wp), PUBLIC ::   rn_ahi0_ref      !: sea-ice hor. eddy diffusivity coeff. (m2/s)
-
-   !                                     !!** ice-thermodynamics namelist (namicethd) **
-                                          ! -- limthd_dif -- !
+   !
+   !                                     !!** ice-surface forcing namelist (namforcing) **
+                                          ! -- icethd_dh -- !
+   REAL(wp), PUBLIC ::   rn_blow_s        !: coef. for partitioning of snowfall between leads and sea ice
+                                          ! -- icethd -- !
+   REAL(wp), PUBLIC ::   rn_cio           !: drag coefficient for oceanic stress
+   INTEGER , PUBLIC ::   nn_flxdist       !: Redistribute heat flux over ice categories
+   !                                      !   =-1  Do nothing (needs N(cat) fluxes)
+   !                                      !   = 0  Average N(cat) fluxes then apply the average over the N(cat) ice 
+   !                                      !   = 1  Average N(cat) fluxes then redistribute over the N(cat) ice using T-ice and albedo sensitivity
+   !                                      !   = 2  Redistribute a single flux over categories
+   INTEGER , PUBLIC            ::   nice_jules           !: Choice of jules coupling 
+   INTEGER , PUBLIC, PARAMETER ::   np_jules_OFF    = 0  !: no Jules coupling (ice thermodynamics forced via qsr and qns)
+   INTEGER , PUBLIC, PARAMETER ::   np_jules_EMULE  = 1  !: emulated Jules coupling via icethd_zdf.F90 (BL99) (1st round compute qcn and qsr_tr, 2nd round use it)
+   INTEGER , PUBLIC, PARAMETER ::   np_jules_ACTIVE = 2  !: active Jules coupling                      (SM0L) (compute qcn and qsr_tr via sbcblk.F90 or sbccpl.F90)
+
+   !                                     !!** ice-vertical diffusion namelist (namthd_zdf) **
+   LOGICAL , PUBLIC ::   ln_cndi_U64      !: thermal conductivity: Untersteiner (1964)
+   LOGICAL , PUBLIC ::   ln_cndi_P07      !: thermal conductivity: Pringle et al (2007)
    REAL(wp), PUBLIC ::   rn_kappa_i       !: coef. for the extinction of radiation Grenfell et al. (2006) [1/m]
-   REAL(wp), PUBLIC ::   nn_conv_dif      !: maximal number of iterations for heat diffusion
-   REAL(wp), PUBLIC ::   rn_terr_dif      !: maximal tolerated error (C) for heat diffusion
-   INTEGER , PUBLIC ::   nn_ice_thcon     !: thermal conductivity: =0 Untersteiner (1964) ; =1 Pringle et al (2007)
-   LOGICAL , PUBLIC ::   ln_it_qnsice     !: iterate surface flux with changing surface temperature or not (F)
-   INTEGER , PUBLIC ::   nn_monocat       !: virtual ITD mono-category parameterizations (1) or not (0)
-   REAL(wp), PUBLIC ::   rn_cdsn          !: thermal conductivity of the snow [W/m/K]
-                                          ! -- limthd_dh -- !
-   LOGICAL , PUBLIC ::   ln_limdH         !: activate ice thickness change from growing/melting (T) or not (F)
-   REAL(wp), PUBLIC ::   rn_betas         !: coef. for partitioning of snowfall between leads and sea ice
-                                          ! -- limthd_da -- !
-   LOGICAL , PUBLIC ::   ln_limdA         !: activate lateral melting param. (T) or not (F)
-   REAL(wp), PUBLIC ::   rn_beta          !: coef. beta for lateral melting param.
-   REAL(wp), PUBLIC ::   rn_dmin          !: minimum floe diameter for lateral melting param.
-                                          ! -- limthd_lac -- !
-   LOGICAL , PUBLIC ::   ln_limdO         !: activate ice growth in open-water (T) or not (F)
-   REAL(wp), PUBLIC ::   rn_hnewice       !: thickness for new ice formation (m)
-   LOGICAL , PUBLIC ::   ln_frazil        !: use of frazil ice collection as function of wind (T) or not (F)
-   REAL(wp), PUBLIC ::   rn_maxfrazb      !: maximum portion of frazil ice collecting at the ice bottom
-   REAL(wp), PUBLIC ::   rn_vfrazb        !: threshold drift speed for collection of bottom frazil ice
-   REAL(wp), PUBLIC ::   rn_Cfrazb        !: squeezing coefficient for collection of bottom frazil ice
-                                          ! -- limitd_th -- !
-   REAL(wp), PUBLIC ::   rn_himin         !: minimum ice thickness
-
-   !                                     !!** ice-salinity namelist (namicesal) **
-   LOGICAL , PUBLIC ::   ln_limdS         !: activate gravity drainage and flushing (T) or not (F)
+   REAL(wp), PUBLIC ::   rn_cnd_s         !: thermal conductivity of the snow [W/m/K]   
+
+   !                                     !!** ice-salinity namelist (namthd_sal) **
    INTEGER , PUBLIC ::   nn_icesal        !: salinity configuration used in the model
    !                                      ! 1 - constant salinity in both space and time
@@ -257,30 +211,24 @@
    !                                      ! 3 - salinity profile, constant in time
    REAL(wp), PUBLIC ::   rn_icesal        !: bulk salinity (ppt) in case of constant salinity
-   REAL(wp), PUBLIC ::   rn_sal_gd        !: restoring salinity for gravity drainage [PSU]
-   REAL(wp), PUBLIC ::   rn_time_gd       !: restoring time constant for gravity drainage (= 20 days) [s]
-   REAL(wp), PUBLIC ::   rn_sal_fl        !: restoring salinity for flushing [PSU]
-   REAL(wp), PUBLIC ::   rn_time_fl       !: restoring time constant for gravity drainage (= 10 days) [s]
    REAL(wp), PUBLIC ::   rn_simax         !: maximum ice salinity [PSU]
    REAL(wp), PUBLIC ::   rn_simin         !: minimum ice salinity [PSU]
 
-   !                                     !!** ice-mechanical redistribution namelist (namiceitdme)
-   REAL(wp), PUBLIC ::   rn_cs            !: fraction of shearing energy contributing to ridging            
-   INTEGER , PUBLIC ::   nn_partfun       !: participation function: =0 Thorndike et al. (1975), =1 Lipscomb et al. (2007)
-   REAL(wp), PUBLIC ::   rn_gstar         !: fractional area of young ice contributing to ridging
-   REAL(wp), PUBLIC ::   rn_astar         !: equivalent of G* for an exponential participation function
-   LOGICAL , PUBLIC ::   ln_ridging       !: ridging of ice or not                        
-   REAL(wp), PUBLIC ::   rn_hstar         !: thickness that determines the maximal thickness of ridged ice
-   REAL(wp), PUBLIC ::   rn_por_rdg       !: initial porosity of ridges (0.3 regular value)
-   REAL(wp), PUBLIC ::   rn_fsnowrdg      !: fractional snow loss to the ocean during ridging
-   LOGICAL , PUBLIC ::   ln_rafting       !: rafting of ice or not                        
-   REAL(wp), PUBLIC ::   rn_hraft         !: threshold thickness (m) for rafting / ridging 
-   REAL(wp), PUBLIC ::   rn_craft         !: coefficient for smoothness of the hyperbolic tangent in rafting
-   REAL(wp), PUBLIC ::   rn_fsnowrft      !: fractional snow loss to the ocean during ridging
+   !                                     !!** ice-ponds namelist (namthd_pnd)
+   LOGICAL , PUBLIC ::   ln_pnd_H12       !: Melt ponds scheme from Holland et al 2012
+   LOGICAL , PUBLIC ::   ln_pnd_fwb       !: melt ponds store freshwater
+   LOGICAL , PUBLIC ::   ln_pnd_CST       !: Melt ponds scheme with constant fraction and depth
+   REAL(wp), PUBLIC ::   rn_apnd          !: prescribed pond fraction (0<rn_apnd<1)
+   REAL(wp), PUBLIC ::   rn_hpnd          !: prescribed pond depth    (0<rn_hpnd<1)
+   LOGICAL , PUBLIC ::   ln_pnd_alb       !: melt ponds affect albedo
+
+   !                                     !!** ice-diagnostics namelist (namdia) **
+   LOGICAL , PUBLIC ::   ln_icediachk     !: flag for ice diag (T) or not (F)
+   LOGICAL , PUBLIC ::   ln_icediahsb     !: flag for ice diag (T) or not (F)
+   LOGICAL , PUBLIC ::   ln_icectl        !: flag for sea-ice points output (T) or not (F)
+   INTEGER , PUBLIC ::   iiceprt          !: debug i-point
+   INTEGER , PUBLIC ::   jiceprt          !: debug j-point
 
    !                                     !!** some other parameters 
-   INTEGER , PUBLIC ::   nstart           !: iteration number of the begining of the run 
-   INTEGER , PUBLIC ::   nlast            !: iteration number of the end of the run 
-   INTEGER , PUBLIC ::   nitrun           !: number of iteration
-   INTEGER , PUBLIC ::   numit            !: iteration number
+   INTEGER , PUBLIC ::   kt_ice           !: iteration number
    REAL(wp), PUBLIC ::   rdt_ice          !: ice time step
    REAL(wp), PUBLIC ::   r1_rdtice        !: = 1. / rdt_ice
@@ -288,12 +236,13 @@
    REAL(wp), PUBLIC ::   r1_nlay_s        !: 1 / nlay_s 
    REAL(wp), PUBLIC ::   rswitch          !: switch for the presence of ice (1) or not (0)
-   REAL(wp), PUBLIC, PARAMETER ::   epsi06   = 1.e-06_wp  !: small number 
-   REAL(wp), PUBLIC, PARAMETER ::   epsi10   = 1.e-10_wp  !: small number 
-   REAL(wp), PUBLIC, PARAMETER ::   epsi20   = 1.e-20_wp  !: small number 
+   REAL(wp), PUBLIC ::   rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft   !: conservation diagnostics
+   REAL(wp), PUBLIC, PARAMETER ::   epsi06 = 1.e-06_wp  !: small number 
+   REAL(wp), PUBLIC, PARAMETER ::   epsi10 = 1.e-10_wp  !: small number 
+   REAL(wp), PUBLIC, PARAMETER ::   epsi20 = 1.e-20_wp  !: small number 
+
 
    !                                     !!** define arrays
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   u_oce, v_oce !: surface ocean velocity used in ice dynamics
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ahiu , ahiv !: hor. diffusivity coeff. at U- and V-points [m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hicol       !: ice collection thickness accreted in leads
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   u_oce,v_oce !: surface ocean velocity used in ice dynamics
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ht_i_new    !: ice collection thickness accreted in leads
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   strength    !: ice strength
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   stress1_i, stress2_i, stress12_i   !: 1st, 2nd & diagonal stress tensor element
@@ -303,7 +252,4 @@
    !
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_bo        !: Sea-Ice bottom temperature [Kelvin]     
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   frld        !: Leads fraction = 1 - ice fraction
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   pfrld       !: Leads fraction at previous time  
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   phicif      !: Old ice thickness
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qlead       !: heat balance of the lead (or of the open ocean)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   fhtur       !: net downward heat flux from the ice to the ocean
@@ -311,6 +257,13 @@
 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_snw     !: snow-ocean mass exchange   [kg.m-2.s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_snw_sni !: snow ice growth component of wfx_snw [kg.m-2.s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_snw_sum !: surface melt component of wfx_snw [kg.m-2.s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_pnd     !: melt pond-ocean mass exchange   [kg.m-2.s-1]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_spr     !: snow precipitation on ice  [kg.m-2.s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_sub     !: snow/ice sublimation       [kg.m-2.s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_sub     !: sublimation of snow/ice    [kg.m-2.s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_snw_sub !: snow sublimation           [kg.m-2.s-1]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_ice_sub !: ice sublimation            [kg.m-2.s-1]
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_snw_dyn !: dynamical component of wfx_snw    [kg.m-2.s-1]
 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   wfx_ice     !: ice-ocean mass exchange                   [kg.m-2.s-1]
@@ -325,6 +278,4 @@
 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   afx_tot     !: ice concentration tendency (total)          [s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   afx_thd     !: ice concentration tendency (thermodynamics) [s-1]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   afx_dyn     !: ice concentration tendency (dynamics)       [s-1]
 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sfx_bog     !: salt flux due to ice growth/melt                      [PSU/m2/s]
@@ -346,5 +297,4 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_dif     !: total heat flux causing Temp change in the ice   [W.m-2]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_snw     !: heat flux for snow melt                          [W.m-2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_err     !: heat flux error after heat diffusion             [W.m-2]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_err_dif !: heat flux remaining due to change in non-solar flux [W.m-2]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_err_rem !: heat flux error after heat remapping             [W.m-2]
@@ -358,27 +308,27 @@
 
    ! heat flux associated with ice-ocean mass exchange
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_thd     !: ice-ocean heat flux from thermo processes (limthd_dh)  [W.m-2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_dyn     !: ice-ocean heat flux from mecanical processes (limitd_me)  [W.m-2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_thd     !: ice-ocean heat flux from thermo processes (icethd_dh) [W.m-2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_dyn     !: ice-ocean heat flux from ridging                      [W.m-2]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_res     !: residual heat flux due to correction of ice thickness [W.m-2]
 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   rn_amax_2d     !: maximum ice concentration 2d array
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ftr_ice        !: transmitted solar radiation under ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   pahu3D, pahv3D !: ice hor. eddy diffusivity coef. at U- and V-points
-
-   !!--------------------------------------------------------------------------
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   t1_ice         !: temperature of the first layer (Jules coupling) [K]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   cnd_ice        !: effective conductivity at the top of ice/snow (Jules coupling) [W.m-2.K-1]
+
+   !!----------------------------------------------------------------------
    !! * Ice global state variables
-   !!--------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    !! Variables defined for each ice category
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ht_i      !: Ice thickness (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   h_i       !: Ice thickness (m)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   a_i       !: Ice fractional areas (concentration)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   v_i       !: Ice volume per unit area (m)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   v_s       !: Snow volume per unit area(m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ht_s      !: Snow thickness (m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   h_s       !: Snow thickness (m)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   t_su      !: Sea-Ice Surface Temperature (K)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   sm_i      !: Sea-Ice Bulk salinity (ppt)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   smv_i     !: Sea-Ice Bulk salinity times volume per area (ppt.m)
-   !                                                                    !  this is an extensive variable that has to be transported
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   o_i       !: Sea-Ice Age (days)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   oa_i      !: Sea-Ice Age times ice area (days)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   s_i       !: Sea-Ice Bulk salinity (ppt)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   sv_i      !: Sea-Ice Bulk salinity times volume per area (ppt.m)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   o_i       !: Sea-Ice Age (s)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   oa_i      !: Sea-Ice Age times ice area (s)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   bv_i      !: brine volume
 
@@ -391,65 +341,71 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tm_i         !: mean ice temperature over all categories
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bvm_i        !: brine volume averaged over all categories
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   smt_i        !: mean sea ice salinity averaged over all categories [PSU]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sm_i         !: mean sea ice salinity averaged over all categories [PSU]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tm_su        !: mean surface temperature over all categories
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   htm_i        !: mean ice  thickness over all categories
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   htm_s        !: mean snow thickness over all categories
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hm_i         !: mean ice  thickness over all categories
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hm_s         !: mean snow thickness over all categories
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   om_i         !: mean ice age over all categories
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tau_icebfr   !: ice friction with bathy (landfast param activated)
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   t_s      !: Snow temperatures [K]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e_s      !: Snow ...      
-      
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   t_i      !: ice temperatures          [K]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e_i      !: ice thermal contents    [J/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   s_i      !: ice salinities          [PSU]
-
-   !!--------------------------------------------------------------------------
-   !! * Moments for advection
-   !!--------------------------------------------------------------------------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   sxopw, syopw, sxxopw, syyopw, sxyopw   !: open water in sea ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxice, syice, sxxice, syyice, sxyice   !: ice thickness 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxsn , sysn , sxxsn , syysn , sxysn    !: snow thickness
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxa  , sya  , sxxa  , syya  , sxya     !: lead fraction
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxc0 , syc0 , sxxc0 , syyc0 , sxyc0    !: snow thermal content
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxsal, sysal, sxxsal, syysal, sxysal   !: ice salinity
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxage, syage, sxxage, syyage, sxyage   !: ice age
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   sxe  , sye  , sxxe  , syye  , sxye     !: ice layers heat content
-
-   !!--------------------------------------------------------------------------
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   t_s      !: Snow temperatures     [K]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e_s      !: Snow enthalpy         [J/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   t_i      !: ice temperatures      [K]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e_i      !: ice enthalpy          [J/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   sz_i     !: ice salinity          [PSU]
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   a_ip       !: melt pond fraction per grid cell area
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   v_ip       !: melt pond volume per grid cell area [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   a_ip_frac  !: melt pond volume per ice area
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   h_ip       !: melt pond thickness [m]
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   at_ip      !: total melt pond fraction
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   vt_ip      !: total melt pond volume per unit area [m]
+
+   !!----------------------------------------------------------------------
    !! * Old values of global variables
-   !!--------------------------------------------------------------------------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   v_s_b, v_i_b               !: snow and ice volumes
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   a_i_b, smv_i_b, oa_i_b     !:
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e_s_b                      !: snow heat content
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e_i_b                      !: ice temperatures
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   u_ice_b, v_ice_b           !: ice velocity
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   at_i_b                     !: ice concentration (total)
+   !!----------------------------------------------------------------------
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   v_s_b, v_i_b, h_s_b, h_i_b    !: snow and ice volumes/thickness
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   a_i_b, sv_i_b, oa_i_b         !:
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e_s_b                         !: snow heat content
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e_i_b                         !: ice temperatures
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   u_ice_b, v_ice_b              !: ice velocity
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   at_i_b                        !: ice concentration (total)
             
-   !!--------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    !! * Ice thickness distribution variables
-   !!--------------------------------------------------------------------------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   hi_max         !: Boundary of ice thickness categories in thickness space
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   hi_mean        !: Mean ice thickness in catgories 
-   !
-   !!--------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hi_max         !: Boundary of ice thickness categories in thickness space
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hi_mean        !: Mean ice thickness in catgories 
+   !
+   !!----------------------------------------------------------------------
    !! * Ice diagnostics
-   !!--------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    ! thd refers to changes induced by thermodynamics
    ! trp   ''         ''     ''       advection (transport of ice)
    !
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   diag_trp_vi   !: transport of ice volume
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   diag_trp_vs   !: transport of snw volume
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   diag_trp_ei   !: transport of ice enthalpy (W/m2)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   diag_trp_es   !: transport of snw enthalpy (W/m2)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   diag_trp_smv  !: transport of salt content
-   !
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   diag_heat     !: snw/ice heat content variation   [W/m2] 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   diag_smvi     !: ice salt content variation   [] 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   diag_vice     !: ice volume variation   [m/s] 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   diag_vsnw     !: snw volume variation   [m/s] 
-   !
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_trp_vi   !: transport of ice volume
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_trp_vs   !: transport of snw volume
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_trp_ei   !: transport of ice enthalpy (W/m2)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_trp_es   !: transport of snw enthalpy (W/m2)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_trp_sv   !: transport of salt content
+   !
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_heat     !: snw/ice heat content variation   [W/m2] 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_sice     !: ice salt content variation   [] 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_vice     !: ice volume variation   [m/s] 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   diag_vsnw     !: snw volume variation   [m/s] 
+
+   !
+   !!----------------------------------------------------------------------
+   !! * SIMIP extra diagnostics
+   !!----------------------------------------------------------------------
+   ! Extra sea ice diagnostics to address the data request
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   t_si          !: Temperature at Snow-ice interface (K) 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   tm_si         !: mean temperature at the snow-ice interface (K) 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_fc_bo    !: Bottom conduction flux (W/m2)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   diag_fc_su    !: Surface conduction flux (W/m2)
+
+   !
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -463,5 +419,5 @@
       INTEGER :: ice_alloc
       !
-      INTEGER :: ierr(15), ii
+      INTEGER :: ierr(18), ii
       !!-----------------------------------------------------------------
 
@@ -471,19 +427,20 @@
       ! stay within Fortran's max-line length limit.
       ii = 1
-      ALLOCATE( u_oce   (jpi,jpj) , v_oce    (jpi,jpj) ,                                             &
-         &      ahiu    (jpi,jpj) , ahiv     (jpi,jpj) , hicol    (jpi,jpj) ,                        &
+      ALLOCATE( u_oce   (jpi,jpj) , v_oce    (jpi,jpj) , ht_i_new (jpi,jpj) ,                        &
          &      strength(jpi,jpj) , stress1_i(jpi,jpj) , stress2_i(jpi,jpj) , stress12_i(jpi,jpj) ,  &
          &      delta_i (jpi,jpj) , divu_i   (jpi,jpj) , shear_i  (jpi,jpj) , STAT=ierr(ii) )
 
       ii = ii + 1
-      ALLOCATE( t_bo   (jpi,jpj) , frld   (jpi,jpj) , pfrld  (jpi,jpj) , phicif (jpi,jpj) ,     &
-         &      wfx_snw(jpi,jpj) , wfx_ice(jpi,jpj) , wfx_sub(jpi,jpj) , wfx_lam(jpi,jpj) ,     &
+      ALLOCATE( t_bo   (jpi,jpj) , wfx_snw_sni(jpi,jpj) ,                                                &
+         &      wfx_snw(jpi,jpj) , wfx_snw_dyn(jpi,jpj) , wfx_snw_sum(jpi,jpj) , wfx_snw_sub(jpi,jpj) ,  &
+         &      wfx_ice(jpi,jpj) , wfx_sub    (jpi,jpj) , wfx_ice_sub(jpi,jpj) , wfx_lam    (jpi,jpj) ,  &
+         &      wfx_pnd(jpi,jpj) ,                                                              &
          &      wfx_bog(jpi,jpj) , wfx_dyn(jpi,jpj) , wfx_bom(jpi,jpj) , wfx_sum(jpi,jpj) ,     &
          &      wfx_res(jpi,jpj) , wfx_sni(jpi,jpj) , wfx_opw(jpi,jpj) , wfx_spr(jpi,jpj) ,     &
-         &      afx_tot(jpi,jpj) , afx_thd(jpi,jpj),  afx_dyn(jpi,jpj) , rn_amax_2d(jpi,jpj),   &
+         &      afx_tot(jpi,jpj) , rn_amax_2d(jpi,jpj),                                         &
          &      fhtur  (jpi,jpj) , qlead  (jpi,jpj) ,                                           &
          &      sfx_res(jpi,jpj) , sfx_bri(jpi,jpj) , sfx_dyn(jpi,jpj) , sfx_sub(jpi,jpj) , sfx_lam(jpi,jpj) ,  &
          &      sfx_bog(jpi,jpj) , sfx_bom(jpi,jpj) , sfx_sum(jpi,jpj) , sfx_sni(jpi,jpj) , sfx_opw(jpi,jpj) ,  &
-         &      hfx_res(jpi,jpj) , hfx_snw(jpi,jpj) , hfx_sub(jpi,jpj) , hfx_err(jpi,jpj) ,     & 
+         &      hfx_res(jpi,jpj) , hfx_snw(jpi,jpj) , hfx_sub(jpi,jpj) ,     & 
          &      hfx_in (jpi,jpj) , hfx_out(jpi,jpj) , fhld   (jpi,jpj) ,                        &
          &      hfx_sum(jpi,jpj) , hfx_bom(jpi,jpj) , hfx_bog(jpi,jpj) , hfx_dif(jpi,jpj) ,     &
@@ -493,42 +450,30 @@
       ! * Ice global state variables
       ii = ii + 1
-      ALLOCATE( ftr_ice(jpi,jpj,jpl) , pahu3D(jpi,jpj,jpl+1) , pahv3D(jpi,jpj,jpl+1) , &
-         &      ht_i   (jpi,jpj,jpl) , a_i   (jpi,jpj,jpl) , v_i   (jpi,jpj,jpl) ,     &
-         &      v_s    (jpi,jpj,jpl) , ht_s  (jpi,jpj,jpl) , t_su  (jpi,jpj,jpl) ,     &
-         &      sm_i   (jpi,jpj,jpl) , smv_i (jpi,jpj,jpl) , o_i   (jpi,jpj,jpl) ,     &
-         &      oa_i   (jpi,jpj,jpl) , bv_i  (jpi,jpj,jpl) ,  STAT=ierr(ii) )
-      ii = ii + 1
-      ALLOCATE( u_ice(jpi,jpj) , v_ice(jpi,jpj) ,                                       &
-         &      vt_i (jpi,jpj) , vt_s (jpi,jpj) , at_i (jpi,jpj) , ato_i(jpi,jpj) ,     &
-         &      et_i (jpi,jpj) , et_s (jpi,jpj) , tm_i (jpi,jpj) , bvm_i(jpi,jpj) ,     &
-         &      smt_i(jpi,jpj) , tm_su(jpi,jpj) , htm_i(jpi,jpj) , htm_s(jpi,jpj) ,     &
-         &      om_i (jpi,jpj) , tau_icebfr(jpi,jpj)                              , STAT=ierr(ii) )
+      ALLOCATE( ftr_ice(jpi,jpj,jpl) , cnd_ice(jpi,jpj,jpl) , t1_ice(jpi,jpj,jpl) , &
+         &      h_i (jpi,jpj,jpl) , a_i (jpi,jpj,jpl) , v_i (jpi,jpj,jpl) ,     &
+         &      v_s (jpi,jpj,jpl) , h_s (jpi,jpj,jpl) , t_su(jpi,jpj,jpl) ,     &
+         &      s_i (jpi,jpj,jpl) , sv_i(jpi,jpj,jpl) , o_i (jpi,jpj,jpl) ,     &
+         &      oa_i(jpi,jpj,jpl) , bv_i(jpi,jpj,jpl) ,  STAT=ierr(ii) )
+      ii = ii + 1
+      ALLOCATE( u_ice(jpi,jpj) , v_ice(jpi,jpj) ,                                      &
+         &      vt_i (jpi,jpj) , vt_s (jpi,jpj) , at_i(jpi,jpj) , ato_i(jpi,jpj) ,     &
+         &      et_i (jpi,jpj) , et_s (jpi,jpj) , tm_i(jpi,jpj) , bvm_i(jpi,jpj) ,     &
+         &      sm_i (jpi,jpj) , tm_su(jpi,jpj) , hm_i(jpi,jpj) , hm_s (jpi,jpj) ,     &
+         &      om_i (jpi,jpj) , tau_icebfr(jpi,jpj)                             , STAT=ierr(ii) )
       ii = ii + 1
       ALLOCATE( t_s(jpi,jpj,nlay_s,jpl) , e_s(jpi,jpj,nlay_s,jpl) , STAT=ierr(ii) )
       ii = ii + 1
-      ALLOCATE( t_i(jpi,jpj,nlay_i,jpl) , e_i(jpi,jpj,nlay_i,jpl) , s_i(jpi,jpj,nlay_i,jpl) , STAT=ierr(ii) )
-
-      ! * Moments for advection
-      ii = ii + 1
-      ALLOCATE( sxopw(jpi,jpj) , syopw(jpi,jpj) , sxxopw(jpi,jpj) , syyopw(jpi,jpj) , sxyopw(jpi,jpj) , STAT=ierr(ii) )
-      ii = ii + 1
-      ALLOCATE( sxice(jpi,jpj,jpl) , syice(jpi,jpj,jpl) , sxxice(jpi,jpj,jpl) , syyice(jpi,jpj,jpl) , sxyice(jpi,jpj,jpl) ,   &
-         &      sxsn (jpi,jpj,jpl) , sysn (jpi,jpj,jpl) , sxxsn (jpi,jpj,jpl) , syysn (jpi,jpj,jpl) , sxysn (jpi,jpj,jpl) ,   &
-         &      STAT=ierr(ii) )
-      ii = ii + 1
-      ALLOCATE( sxa  (jpi,jpj,jpl) , sya  (jpi,jpj,jpl) , sxxa  (jpi,jpj,jpl) , syya  (jpi,jpj,jpl) , sxya  (jpi,jpj,jpl) ,   &
-         &      sxc0 (jpi,jpj,jpl) , syc0 (jpi,jpj,jpl) , sxxc0 (jpi,jpj,jpl) , syyc0 (jpi,jpj,jpl) , sxyc0 (jpi,jpj,jpl) ,   &
-         &      sxsal(jpi,jpj,jpl) , sysal(jpi,jpj,jpl) , sxxsal(jpi,jpj,jpl) , syysal(jpi,jpj,jpl) , sxysal(jpi,jpj,jpl) ,   &
-         &      sxage(jpi,jpj,jpl) , syage(jpi,jpj,jpl) , sxxage(jpi,jpj,jpl) , syyage(jpi,jpj,jpl) , sxyage(jpi,jpj,jpl) ,   &
-         &      STAT=ierr(ii) )
-      ii = ii + 1
-      ALLOCATE( sxe (jpi,jpj,nlay_i,jpl) , sye (jpi,jpj,nlay_i,jpl) , sxxe(jpi,jpj,nlay_i,jpl) ,     &
-         &      syye(jpi,jpj,nlay_i,jpl) , sxye(jpi,jpj,nlay_i,jpl)                            , STAT=ierr(ii) )
+      ALLOCATE( t_i(jpi,jpj,nlay_i,jpl) , e_i(jpi,jpj,nlay_i,jpl) , sz_i(jpi,jpj,nlay_i,jpl) , STAT=ierr(ii) )
+
+      ii = ii + 1
+      ALLOCATE( a_ip(jpi,jpj,jpl) , v_ip(jpi,jpj,jpl) , a_ip_frac(jpi,jpj,jpl) , h_ip(jpi,jpj,jpl) , STAT = ierr(ii) )
+      ii = ii + 1
+      ALLOCATE( at_ip(jpi,jpj) , vt_ip(jpi,jpj) , STAT = ierr(ii) )
 
       ! * Old values of global variables
       ii = ii + 1
-      ALLOCATE( v_s_b  (jpi,jpj,jpl) , v_i_b  (jpi,jpj,jpl) , e_s_b(jpi,jpj,nlay_s,jpl) ,     &
-         &      a_i_b  (jpi,jpj,jpl) , smv_i_b(jpi,jpj,jpl) , e_i_b(jpi,jpj,nlay_i,jpl) ,     &
-         &      oa_i_b (jpi,jpj,jpl)                                                    , STAT=ierr(ii) )
+      ALLOCATE( v_s_b  (jpi,jpj,jpl) , v_i_b (jpi,jpj,jpl) , h_s_b(jpi,jpj,jpl)        , h_i_b(jpi,jpj,jpl)        ,   &
+         &      a_i_b  (jpi,jpj,jpl) , sv_i_b(jpi,jpj,jpl) , e_i_b(jpi,jpj,nlay_i,jpl) , e_s_b(jpi,jpj,nlay_s,jpl) ,   &
+         &      oa_i_b (jpi,jpj,jpl)                                                   , STAT=ierr(ii) )
       ii = ii + 1
       ALLOCATE( u_ice_b(jpi,jpj) , v_ice_b(jpi,jpj) , at_i_b(jpi,jpj) , STAT=ierr(ii) )
@@ -541,6 +486,10 @@
       ii = ii + 1
       ALLOCATE( diag_trp_vi(jpi,jpj) , diag_trp_vs (jpi,jpj) , diag_trp_ei(jpi,jpj),   & 
-         &      diag_trp_es(jpi,jpj) , diag_trp_smv(jpi,jpj) , diag_heat  (jpi,jpj),   &
-         &      diag_smvi  (jpi,jpj) , diag_vice   (jpi,jpj) , diag_vsnw  (jpi,jpj), STAT=ierr(ii) )
+         &      diag_trp_es(jpi,jpj) , diag_trp_sv (jpi,jpj) , diag_heat  (jpi,jpj),   &
+         &      diag_sice  (jpi,jpj) , diag_vice   (jpi,jpj) , diag_vsnw  (jpi,jpj), STAT=ierr(ii) )
+
+      ! * SIMIP diagnostics
+      ii = ii + 1
+      ALLOCATE( t_si (jpi,jpj,jpl) , tm_si(jpi,jpj) , diag_fc_bo(jpi,jpj) , diag_fc_su(jpi,jpj) , STAT = ierr(ii) )
 
       ice_alloc = MAXVAL( ierr(:) )
@@ -551,5 +500,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option         Empty module            NO LIM sea-ice model
+   !!   Default option         Empty module           NO ESIM sea-ice model
    !!----------------------------------------------------------------------
 #endif
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/ice1d.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/ice1d.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/ice1d.F90	(revision 9019)
@@ -0,0 +1,245 @@
+MODULE ice1D
+   !!======================================================================
+   !!                       ***  MODULE ice1D  ***
+   !! sea-ice :   Ice thermodynamics variables in 1D
+   !!=====================================================================
+   !! History :  3.0  !  2002-11  (C. Ethe)  F90: Free form and module
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   USE ice     , ONLY :   nlay_i, nlay_s, jpl   ! number of ice/snow layers and categories
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice1D_alloc   ! called by icestp.F90
+
+   !!----------------------
+   !! * 1D Module variables
+   !!----------------------
+   !: In ice thermodynamics, to spare memory, the vectors are folded
+   !: from 1D to 2D vectors. The following variables, with ending _1d
+   !: are the variables corresponding to 2d vectors
+
+   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   nptidx !: selected points for ice thermo
+   INTEGER , PUBLIC                                  ::   npti   !  number of selected points
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qlead_1d     
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ftr_ice_1d   
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qsr_ice_1d  
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qns_ice_1d  
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   t_bo_1d     
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   rn_amax_1d
+   
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qml_ice_1d     !: heat available for snow / ice surface melting [W/m2] 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qcn_ice_1d     !: heat available for snow / ice surface sublimation [W/m2] 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qsr_ice_tr_1d  !: solar flux transmitted below the ice surface [W/m2] 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   t1_ice_1d      !: temperature of the 1st layer (Jules coupling) [K]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   cnd_ice_1d     !: conductivity at the top of ice/snow (Jules coupling) [W/K/m2]
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_sum_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_bom_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_bog_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_dif_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_opw_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_snw_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_dyn_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_err_rem_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_err_dif_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_out_1d
+
+   ! heat flux associated with ice-atmosphere mass exchange
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_sub_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_spr_1d
+
+   ! heat flux associated with ice-ocean mass exchange
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_thd_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_res_1d
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_snw_sni_1d 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_snw_sum_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_snw_dyn_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_sub_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_snw_sub_1d 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_ice_sub_1d 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_err_sub_1d 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_lam_1d 
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_bog_1d    
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_bom_1d   
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_sum_1d  
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_sni_1d 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_opw_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_res_1d 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_spr_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_dyn_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_pnd_1d
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_bri_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_bog_1d    
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_bom_1d    
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_sum_1d    
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_sni_1d    
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_opw_1d   
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_res_1d  
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_sub_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_lam_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_dyn_1d
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sprecip_1d    !: <==> the 2D  sprecip
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   at_i_1d       !: <==> the 2D  at_i
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ato_i_1d      !: <==> the 2D  ato_i
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fhtur_1d      !: <==> the 2D  fhtur
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fhld_1d       !: <==> the 2D  fhld
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dqns_ice_1d   !: <==> the 2D  dqns_ice
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   evap_ice_1d   !: <==> the 2D  evap_ice
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qprec_ice_1d  !: <==> the 2D  qprec_ice
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   t_su_1d       !: <==> the 2D  t_su
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   t_si_1d       !: <==> the 2D  t_si
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   a_i_1d        !: <==> the 2D  a_i
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   a_ib_1d       !: <==> the 2D  a_i_b
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   h_i_1d        !:
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   h_ib_1d       !:
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   h_s_1d        !:
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fc_su         !: Surface Conduction flux 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fc_bo_i       !: Bottom  Conduction flux 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_s_tot      !: Snow accretion/ablation        [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_i_surf     !: Ice surface accretion/ablation [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_i_sub      !: Ice surface sublimation [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_i_bott     !: Ice bottom accretion/ablation  [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_s_mlt      !: Snow melt [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_snowice    !: Snow ice formation             [m of ice]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   s_i_1d        !: Ice bulk salinity [ppt]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   s_i_new       !: Salinity of new ice at the bottom
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   v_i_1d        !:
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   v_s_1d        !:
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sv_i_1d       !:
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   oa_i_1d       !:
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   a_ip_1d       !:
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   v_ip_1d       !:
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   h_ip_1d       !:
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   a_ip_frac_1d  !:
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_s_1d      !: corresponding to the 2D var  t_s
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_i_1d      !: corresponding to the 2D var  t_i
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sz_i_1d     !: profiled ice salinity
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   e_i_1d      !:    Ice  enthalpy per unit volume
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   e_s_1d      !:    Snow enthalpy per unit volume
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   eh_i_old    !: ice heat content (q*h, J.m-2)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   h_i_old     !: ice thickness layer (m)
+
+   ! Conduction flux diagnostics (SIMIP)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   diag_fc_bo_1d      !: <==> the 2D  diag_fc_bo
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   diag_fc_su_1d      !: <==> the 2D  diag_fc_su
+
+   ! surface fields from the ocean
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sst_1d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sss_1d
+
+   ! 
+   !!----------------------
+   !! * 2D Module variables
+   !!----------------------
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   a_i_2d 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   v_i_2d 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   v_s_2d 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   oa_i_2d 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   sv_i_2d 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   a_ip_2d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   v_ip_2d 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_su_2d 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   h_i_2d
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   a_ib_2d
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   h_ib_2d
+   
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: ice1D.F90 8379 2017-07-26 15:35:49Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   FUNCTION ice1D_alloc()
+      !!---------------------------------------------------------------------!
+      !!                ***  ROUTINE ice1D_alloc ***
+      !!---------------------------------------------------------------------!
+      INTEGER ::   ice1D_alloc   ! return value
+      INTEGER ::   ierr(7), ii
+      !!---------------------------------------------------------------------!
+      ierr(:) = 0
+
+      ii = 1
+      ALLOCATE( nptidx    (jpij) ,   &
+         &      qlead_1d  (jpij) , ftr_ice_1d(jpij) , qsr_ice_1d (jpij) ,   &
+         &      qns_ice_1d(jpij) ,   &
+         &      qml_ice_1d(jpij) , qcn_ice_1d(jpij) , qsr_ice_tr_1d(jpij) , &
+         &      cnd_ice_1d(jpij) , t1_ice_1d(jpij)  , t_bo_1d   (jpij) ,      &
+         &      hfx_sum_1d(jpij) , hfx_bom_1d(jpij) , hfx_bog_1d(jpij) ,    & 
+         &      hfx_dif_1d(jpij) , hfx_opw_1d(jpij) , hfx_dyn_1d(jpij) ,    &
+         &      rn_amax_1d(jpij) ,                                         &
+         &      hfx_thd_1d(jpij) , hfx_spr_1d(jpij) ,                      &
+         &      hfx_snw_1d(jpij) , hfx_sub_1d(jpij) ,                      &
+         &      hfx_res_1d(jpij) , hfx_err_rem_1d(jpij) , hfx_err_dif_1d(jpij) , hfx_out_1d(jpij), STAT=ierr(ii) )
+      !
+      ii = ii + 1
+      ALLOCATE( sprecip_1d (jpij) , at_i_1d    (jpij) , ato_i_1d(jpij) ,                    &
+         &      fhtur_1d   (jpij) , wfx_snw_sni_1d (jpij) , wfx_spr_1d (jpij) , wfx_snw_sum_1d(jpij) , &
+         &      fhld_1d    (jpij) , wfx_sub_1d (jpij) , wfx_bog_1d (jpij) , wfx_bom_1d(jpij) ,  &
+         &      wfx_sum_1d(jpij)  , wfx_sni_1d (jpij) , wfx_opw_1d (jpij) , wfx_res_1d(jpij) ,  &
+         &      wfx_snw_sub_1d(jpij), wfx_snw_dyn_1d(jpij), wfx_ice_sub_1d(jpij), wfx_err_sub_1d(jpij) ,   &
+         &      wfx_lam_1d(jpij)  , wfx_dyn_1d(jpij), wfx_pnd_1d(jpij),dqns_ice_1d(jpij) , evap_ice_1d (jpij),   &
+         &      qprec_ice_1d(jpij),                                                             &  
+         &      sfx_bri_1d (jpij) , sfx_bog_1d (jpij) , sfx_bom_1d (jpij) , sfx_sum_1d (jpij),  &
+         &      sfx_sni_1d (jpij) , sfx_opw_1d (jpij) , sfx_res_1d (jpij) , sfx_sub_1d (jpij),  &
+         &      sfx_lam_1d (jpij) , sfx_dyn_1d(jpij)  , STAT=ierr(ii) )
+      !
+      ii = ii + 1
+      ALLOCATE( t_su_1d  (jpij) , t_si_1d   (jpij) , a_i_1d  (jpij) , a_ib_1d(jpij) ,                  &
+         &      h_i_1d  (jpij) , h_ib_1d  (jpij) , h_s_1d (jpij) , fc_su  (jpij) , fc_bo_i(jpij) ,  &    
+         &      dh_s_tot (jpij) , dh_i_surf (jpij) , dh_i_sub(jpij) ,                                  &    
+         &      dh_i_bott(jpij) , dh_s_mlt(jpij), dh_snowice(jpij) , s_i_1d (jpij) , s_i_new(jpij) , &
+         &      a_ip_1d  (jpij) , v_ip_1d   (jpij) , v_i_1d  (jpij) , v_s_1d (jpij) , &
+         &      h_ip_1d  (jpij) , a_ip_frac_1d(jpij) , &
+         &      sv_i_1d (jpij) , oa_i_1d   (jpij) , STAT=ierr(ii) )
+      !
+      ii = ii + 1
+      ALLOCATE( t_s_1d  (jpij,nlay_s)     , t_i_1d (jpij,nlay_i)     , sz_i_1d(jpij,nlay_i) ,  &            
+         &      e_i_1d  (jpij,nlay_i)     , e_s_1d (jpij,nlay_s)     ,                        &
+         &      eh_i_old(jpij,0:nlay_i+1) , h_i_old(jpij,0:nlay_i+1) , STAT=ierr(ii) )
+      !
+      ii = ii + 1
+      ALLOCATE( diag_fc_bo_1d(jpij)      , diag_fc_su_1d(jpij)      , STAT=ierr(ii) )
+      !
+      ii = ii + 1
+      ALLOCATE( sst_1d(jpij) , sss_1d(jpij) , STAT=ierr(ii) )
+      !
+      ii = ii + 1
+      ALLOCATE( a_i_2d(jpij,jpl) , a_ib_2d(jpij,jpl) , h_i_2d(jpij,jpl) , h_ib_2d(jpij,jpl) , &
+         &      v_i_2d(jpij,jpl) ,v_s_2d(jpij,jpl) ,oa_i_2d(jpij,jpl) ,sv_i_2d(jpij,jpl) ,  &
+         &      a_ip_2d(jpij,jpl) ,v_ip_2d(jpij,jpl) ,t_su_2d(jpij,jpl) ,  &
+         &      STAT=ierr(ii) )
+
+      ice1D_alloc = MAXVAL( ierr(:) )
+      IF( ice1D_alloc /= 0 )   CALL ctl_warn( 'ice1D_alloc: failed to allocate arrays.' )
+      !
+   END FUNCTION ice1D_alloc
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :         Empty module         NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE ice1D_alloc          ! Empty routine
+   END SUBROUTINE ice1D_alloc
+#endif
+ 
+   !!======================================================================
+END MODULE ice1D
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icealb.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icealb.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icealb.F90	(revision 9019)
@@ -0,0 +1,223 @@
+MODULE icealb
+   !!======================================================================
+   !!                       ***  MODULE  icealb  ***
+   !! Atmospheric forcing:  Albedo over sea ice
+   !!=====================================================================
+   !! History :  4.0  ! 2017-07  (C. Rousset) Split ice and ocean albedos
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_alb        : albedo for ice (clear and overcast skies)
+   !!   ice_alb_init   : initialisation of albedo computation
+   !!----------------------------------------------------------------------
+   USE ice, ONLY: jpl ! sea-ice: number of categories
+   USE phycst         ! physical constants
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   USE timing         ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_alb_init   ! called in icestp
+   PUBLIC   ice_alb        ! called in iceforcing.F90 and iceupdate.F90
+
+   REAL(wp), PUBLIC, PARAMETER ::   rn_alb_oce = 0.066   !: ocean or lead albedo (Pegau and Paulson, Ann. Glac. 2001)
+
+   REAL(wp) , PARAMETER ::   ppc1    = 0.05    ! snow thickness (only for nn_ice_alb=0)
+   REAL(wp) , PARAMETER ::   ppc2    = 0.10    !  "        "
+   REAL(wp) , PARAMETER ::   ppcloud = 0.06    ! cloud effect on albedo (only-for nn_ice_alb=0)
+   REAL(wp) , PARAMETER ::   pp1_c1 = 1. / ppc1
+   REAL(wp) , PARAMETER ::   pp1_c2 = 1. / ppc2
+   !
+   !                             !!* albedo namelist (namalb)
+   REAL(wp) ::   rn_alb_sdry      ! dry snow albedo
+   REAL(wp) ::   rn_alb_smlt      ! melting snow albedo
+   REAL(wp) ::   rn_alb_idry      ! dry ice albedo
+   REAL(wp) ::   rn_alb_imlt      ! bare puddled ice albedo
+   REAL(wp) ::   rn_alb_dpnd      ! ponded ice albedo
+
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icealb.F90 8268 2017-07-03 15:01:04Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_alb( pt_su, ph_ice, ph_snw, ld_pnd_alb, pafrac_pnd, ph_pnd, palb_cs, palb_os )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE ice_alb  ***
+      !!          
+      !! ** Purpose :   Computation of the albedo of the snow/ice system 
+      !!       
+      !! ** Method  :   The scheme is "home made" (for cloudy skies) and based on Brandt et al. (J. Climate 2005)
+      !!                                                                      and Grenfell & Perovich (JGR 2004)
+      !!                  1) Albedo dependency on ice thickness follows the findings from Brandt et al (2005)
+      !!                     which are an update of Allison et al. (JGR 1993) ; Brandt et al. 1999
+      !!                     0-5cm  : linear function of ice thickness
+      !!                     5-150cm: log    function of ice thickness
+      !!                     > 150cm: constant
+      !!                  2) Albedo dependency on snow thickness follows the findings from Grenfell & Perovich (2004)
+      !!                     i.e. it increases as -EXP(-snw_thick/0.02) during freezing and -EXP(-snw_thick/0.03) during melting
+      !!                  3) Albedo dependency on clouds is speculated from measurements of Grenfell and Perovich (2004)
+      !!                     i.e. cloudy-clear albedo depend on cloudy albedo following a 2d order polynomial law
+      !!                  4) The needed 4 parameters are: dry and melting snow, freezing ice and bare puddled ice
+      !!
+      !!                     compilation of values from literature (reference overcast sky values)
+      !!                        rn_alb_sdry = 0.85      ! dry snow
+      !!                        rn_alb_smlt = 0.75      ! melting snow
+      !!                        rn_alb_idry = 0.60      ! bare frozen ice
+      !!                        rn_alb_imlt = 0.50      ! bare puddled ice albedo
+      !!                        rn_alb_dpnd = 0.36      ! ponded-ice overcast albedo (Lecomte et al, 2015)
+      !!                                                ! early melt pnds 0.27, late melt ponds 0.14 Grenfell & Perovich
+      !!                     Perovich et al 2002 (Sheba) => the only dataset for which all types of ice/snow were retrieved
+      !!                        rn_alb_sdry = 0.85      ! dry snow
+      !!                        rn_alb_smlt = 0.72      ! melting snow
+      !!                        rn_alb_idry = 0.65      ! bare frozen ice
+      !!                     Brandt et al 2005 (East Antarctica)
+      !!                        rn_alb_sdry = 0.87      ! dry snow
+      !!                        rn_alb_smlt = 0.82      ! melting snow
+      !!                        rn_alb_idry = 0.54      ! bare frozen ice
+      !!
+      !! ** Note    :   The old parameterization from Shine & Henderson-Sellers (not here anymore) presented several misconstructions
+      !!                  1) ice albedo when ice thick. tends to 0 is different than ocean albedo
+      !!                  2) for small ice thick. covered with some snow (<3cm?), albedo is larger 
+      !!                     under melting conditions than under freezing conditions
+      !!                  3) the evolution of ice albedo as a function of ice thickness shows  
+      !!                     3 sharp inflexion points (at 5cm, 100cm and 150cm) that look highly unrealistic
+      !!
+      !! References :   Shine & Henderson-Sellers 1985, JGR, 90(D1), 2243-2250.
+      !!                Brandt et al. 2005, J. Climate, vol 18
+      !!                Grenfell & Perovich 2004, JGR, vol 109 
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   pt_su        !  ice surface temperature (Kelvin)
+      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   ph_ice       !  sea-ice thickness
+      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   ph_snw       !  snow depth
+      LOGICAL , INTENT(in   )                   ::   ld_pnd_alb   !  effect of melt ponds on albedo
+      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   pafrac_pnd   !  melt pond relative fraction (per unit ice area)
+      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   ph_pnd       !  melt pond depth
+      REAL(wp), INTENT(  out), DIMENSION(:,:,:) ::   palb_cs      !  albedo of ice under clear    sky
+      REAL(wp), INTENT(  out), DIMENSION(:,:,:) ::   palb_os      !  albedo of ice under overcast sky
+      !
+      INTEGER  ::   ji, jj, jl                ! dummy loop indices
+      REAL(wp) ::   z1_c1, z1_c2,z1_c3, z1_c4 ! local scalar
+      REAL(wp) ::   z1_href_pnd               ! inverse of the characteristic length scale (Lecomte et al. 2015)
+      REAL(wp) ::   zalb_pnd, zafrac_pnd      ! ponded sea ice albedo & relative pound fraction
+      REAL(wp) ::   zalb_ice, zafrac_ice      ! bare sea ice albedo & relative ice fraction
+      REAL(wp) ::   zalb_snw, zafrac_snw      ! snow-covered sea ice albedo & relative snow fraction
+      !!---------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('icealb')
+      !
+      z1_href_pnd = 0.05
+      z1_c1 = 1. / ( LOG(1.5) - LOG(0.05) ) 
+      z1_c2 = 1. / 0.05
+      z1_c3 = 1. / 0.02
+      z1_c4 = 1. / 0.03
+      !
+      DO jl = 1, jpl
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               !                       !--- Specific snow, ice and pond fractions (for now, we prevent melt ponds and snow at the same time)
+               IF( ph_snw(ji,jj,jl) == 0._wp ) THEN
+                  zafrac_snw = 0._wp
+                  IF( ld_pnd_alb ) THEN
+                     zafrac_pnd = pafrac_pnd(ji,jj,jl)
+                  ELSE
+                     zafrac_pnd = 0._wp
+                  ENDIF
+                  zafrac_ice = 1._wp - zafrac_pnd
+               ELSE
+                  zafrac_snw = 1._wp      ! Snow fully "shades" melt ponds and ice
+                  zafrac_pnd = 0._wp
+                  zafrac_ice = 0._wp
+               ENDIF
+               !
+               !                       !--- Bare ice albedo (for hi > 150cm)
+               IF( ld_pnd_alb ) THEN
+                  zalb_ice = rn_alb_idry
+               ELSE
+                  IF( ph_snw(ji,jj,jl) == 0._wp .AND. pt_su(ji,jj,jl) >= rt0 ) THEN  ;   zalb_ice = rn_alb_imlt
+                  ELSE                                                               ;   zalb_ice = rn_alb_idry   ;   ENDIF
+               ENDIF
+               !                       !--- Bare ice albedo (for hi < 150cm)
+               IF( 0.05 < ph_ice(ji,jj,jl) .AND. ph_ice(ji,jj,jl) <= 1.5 ) THEN      ! 5cm < hi < 150cm
+                  zalb_ice = zalb_ice    + ( 0.18 - zalb_ice   ) * z1_c1 * ( LOG(1.5) - LOG(ph_ice(ji,jj,jl)) )
+               ELSEIF( ph_ice(ji,jj,jl) <= 0.05 ) THEN                               ! 0cm < hi < 5cm
+                  zalb_ice = rn_alb_oce  + ( 0.18 - rn_alb_oce ) * z1_c2 * ph_ice(ji,jj,jl)
+               ENDIF
+               !
+               !                       !--- Snow-covered ice albedo (freezing, melting cases)
+               IF( pt_su(ji,jj,jl) < rt0_snow ) THEN
+                  zalb_snw = rn_alb_sdry - ( rn_alb_sdry - zalb_ice ) * EXP( - ph_snw(ji,jj,jl) * z1_c3 )
+               ELSE
+                  zalb_snw = rn_alb_smlt - ( rn_alb_smlt - zalb_ice ) * EXP( - ph_snw(ji,jj,jl) * z1_c4 )
+               ENDIF
+               !                       !--- Ponded ice albedo
+               IF( ld_pnd_alb ) THEN
+                  zalb_pnd = rn_alb_dpnd - ( rn_alb_dpnd - zalb_ice ) * EXP( - ph_pnd(ji,jj,jl) * z1_href_pnd ) 
+               ELSE
+                  zalb_pnd = rn_alb_dpnd
+               ENDIF
+               !                       !--- Surface albedo is weighted mean of snow, ponds and bare ice contributions
+               palb_os(ji,jj,jl) = zafrac_snw * zalb_snw + zafrac_pnd * zalb_pnd + zafrac_ice * zalb_ice
+               !
+            END DO
+         END DO
+      END DO
+      !
+      palb_cs(:,:,:) = palb_os(:,:,:) - ( - 0.1010 * palb_os(:,:,:) * palb_os(:,:,:) + 0.1933 * palb_os(:,:,:) - 0.0148 )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('icealb')
+      !
+   END SUBROUTINE ice_alb
+
+
+   SUBROUTINE ice_alb_init
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE alb_init  ***
+      !!
+      !! ** Purpose :   initializations for the albedo parameters
+      !!
+      !! ** Method  :   Read the namelist namalb
+      !!----------------------------------------------------------------------
+      INTEGER ::   ios   ! Local integer output status for namelist read
+      !!
+      NAMELIST/namalb/ rn_alb_sdry, rn_alb_smlt, rn_alb_idry, rn_alb_imlt, rn_alb_dpnd
+      !!----------------------------------------------------------------------
+      !
+      REWIND( numnam_ice_ref )              ! Namelist namalb in reference namelist : Albedo parameters
+      READ  ( numnam_ice_ref, namalb, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namalb in reference namelist', lwp )
+
+      REWIND( numnam_ice_cfg )              ! Namelist namalb in configuration namelist : Albedo parameters
+      READ  ( numnam_ice_cfg, namalb, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namalb in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namalb )
+      !
+      IF(lwp) THEN                      ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_alb_init: set albedo parameters'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namalb:'
+         WRITE(numout,*) '      albedo of dry snow                   rn_alb_sdry = ', rn_alb_sdry
+         WRITE(numout,*) '      albedo of melting snow               rn_alb_smlt = ', rn_alb_smlt
+         WRITE(numout,*) '      albedo of dry ice                    rn_alb_idry = ', rn_alb_idry
+         WRITE(numout,*) '      albedo of bare puddled ice           rn_alb_imlt = ', rn_alb_imlt
+         WRITE(numout,*) '      albedo of ponded ice                 rn_alb_dpnd = ', rn_alb_dpnd
+      ENDIF
+      !
+   END SUBROUTINE ice_alb_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option           Dummy module         NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icealb
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icecor.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icecor.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icecor.F90	(revision 9019)
@@ -0,0 +1,191 @@
+MODULE icecor
+   !!======================================================================
+   !!                     ***  MODULE  icecor  ***
+   !!   ESIM : Corrections on sea-ice variables at the end of the time step
+   !!======================================================================
+   !! History :  3.0  !  2006-04  (M. Vancoppenolle) Original code
+   !!            3.5  !  2014-06  (C. Rousset)       Complete rewriting/cleaning
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!    ice_cor      : corrections on sea-ice variables
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean domain
+   USE phycst         ! physical constants
+   USE ice            ! sea-ice: variable
+   USE ice1D          ! sea-ice: thermodynamic sea-ice variables
+   USE iceitd         ! sea-ice: rebining
+   USE icevar         ! sea-ice: operations
+   USE icectl         ! sea-ice: control prints
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE lbclnk         ! lateral boundary conditions (or mpp links)
+   USE timing         ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_cor   ! called by icestp.F90
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icecor.F90 8378 2017-07-26 13:55:59Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_cor( kt, kn )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE ice_cor  ***
+      !!               
+      !! ** Purpose :   Computes corrections on sea-ice global variables at 
+      !!              the end of the dynamics (kn=1) and thermodynamics (kn=2)
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt    ! number of iteration
+      INTEGER, INTENT(in) ::   kn    ! 1 = after dyn ; 2 = after thermo
+      !
+      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
+      REAL(wp) ::   zsal, zzc
+      REAL(wp), DIMENSION(jpi,jpj) ::   zafx   ! concentration trends diag
+      !!----------------------------------------------------------------------
+      ! controls
+      IF( nn_timing == 1 )   CALL timing_start('icecor')                                                             ! timing
+      IF( ln_icediachk   )   CALL ice_cons_hsm(0, 'icecor', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
+      !
+      IF( kt == nit000 .AND. lwp .AND. kn == 2 ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_cor:  correct sea ice variables if out of bounds ' 
+         WRITE(numout,*) '~~~~~~~'
+      ENDIF
+      !
+      IF( kn == 2 ) THEN
+         !                          !-----------------------------------------------------
+         !                          !  thickness of the smallest category above himin    !
+         !                          !-----------------------------------------------------
+         WHERE( a_i(:,:,1) >= epsi20 )   ;   h_i(:,:,1) = v_i (:,:,1) / a_i(:,:,1)
+         ELSEWHERE                       ;   h_i(:,:,1) = 0._wp
+         END WHERE
+         WHERE( h_i(:,:,1) < rn_himin )      a_i(:,:,1) = a_i (:,:,1) * h_i(:,:,1) / rn_himin
+         !
+      ENDIF
+      !                             !-----------------------------------------------------
+      !                             !  ice concentration should not exceed amax          !
+      !                             !-----------------------------------------------------
+      at_i(:,:) = SUM( a_i(:,:,:), dim=3 )
+      DO jl  = 1, jpl
+         WHERE( at_i(:,:) > rn_amax_2d(:,:) )   a_i(:,:,jl) = a_i(:,:,jl) * rn_amax_2d(:,:) / at_i(:,:)
+      END DO
+    
+      !                             !-----------------------------------------------------
+      IF ( nn_icesal == 2 ) THEN    !  salinity must stay in bounds [Simin,Simax]        !
+      !                             !-----------------------------------------------------
+         zzc = rhoic * r1_rdtice
+         DO jl = 1, jpl
+            DO jj = 1, jpj 
+               DO ji = 1, jpi
+                  zsal = sv_i(ji,jj,jl)
+                  sv_i(ji,jj,jl) = MIN(  MAX( rn_simin*v_i(ji,jj,jl) , sv_i(ji,jj,jl) ) , rn_simax*v_i(ji,jj,jl)  )
+                  sfx_res(ji,jj) = sfx_res(ji,jj) - ( sv_i(ji,jj,jl) - zsal ) * zzc   ! associated salt flux
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+      !                             !-----------------------------------------------------
+      !                             !  Rebin categories with thickness out of bounds     !
+      !                             !-----------------------------------------------------
+      IF ( jpl > 1 )   CALL ice_itd_reb( kt )
+
+      !                             !-----------------------------------------------------
+      CALL ice_var_zapsmall         !  Zap small values                                  !
+      !                             !-----------------------------------------------------
+
+      !                             !-----------------------------------------------------
+      IF( kn == 2 ) THEN            !  Ice drift case: Corrections to avoid wrong values !
+         DO jj = 2, jpjm1           !-----------------------------------------------------
+            DO ji = 2, jpim1
+               IF ( at_i(ji,jj) == 0._wp ) THEN    ! what to do if there is no ice
+                  IF ( at_i(ji+1,jj) == 0._wp )   u_ice(ji  ,jj) = 0._wp   ! right side
+                  IF ( at_i(ji-1,jj) == 0._wp )   u_ice(ji-1,jj) = 0._wp   ! left side
+                  IF ( at_i(ji,jj+1) == 0._wp )   v_ice(ji,jj  ) = 0._wp   ! upper side
+                  IF ( at_i(ji,jj-1) == 0._wp )   v_ice(ji,jj-1) = 0._wp   ! bottom side
+               ENDIF
+            END DO
+         END DO
+         CALL lbc_lnk_multi( u_ice, 'U', -1., v_ice, 'V', -1. )            ! lateral boundary conditions
+      ENDIF
+
+!!gm I guess the trends are only out on demand 
+!!   So please, only do this is it exite an iom_use of on a these variables
+!!   furthermore, only allocate the diag_ arrays in this case 
+!!   and do the iom_put here so that it is only a local allocation
+!!gm 
+      !                             !-----------------------------------------------------
+      SELECT CASE( kn )             !  Diagnostics                                       !
+      !                             !-----------------------------------------------------
+      CASE( 1 )                        !--- dyn trend diagnostics
+         !
+!!gm   here I think the number of ice cat is too small to use a SUM instruction...
+         DO jj = 1, jpj
+            DO ji = 1, jpi            
+               !                 ! heat content variation (W.m-2)
+               diag_heat(ji,jj) = - (  SUM( e_i(ji,jj,1:nlay_i,:) - e_i_b(ji,jj,1:nlay_i,:) )    & 
+                  &                  + SUM( e_s(ji,jj,1:nlay_s,:) - e_s_b(ji,jj,1:nlay_s,:) )  ) * r1_rdtice
+               !                 ! salt, volume
+               diag_sice(ji,jj) = SUM( sv_i(ji,jj,:) - sv_i_b(ji,jj,:) ) * rhoic * r1_rdtice
+               diag_vice(ji,jj) = SUM( v_i (ji,jj,:) - v_i_b (ji,jj,:) ) * rhoic * r1_rdtice
+               diag_vsnw(ji,jj) = SUM( v_s (ji,jj,:) - v_s_b (ji,jj,:) ) * rhosn * r1_rdtice
+            END DO
+         END DO
+         !                       ! concentration tendency (dynamics)
+         zafx   (:,:) = SUM( a_i(:,:,:) - a_i_b(:,:,:), dim=3 ) * r1_rdtice 
+         afx_tot(:,:) = zafx(:,:)
+         IF( iom_use('afxdyn') )   CALL iom_put( 'afxdyn' , zafx(:,:) )
+         !
+      CASE( 2 )                        !--- thermo trend diagnostics & ice aging
+         !
+         oa_i(:,:,:) = oa_i(:,:,:) + a_i(:,:,:) * rdt_ice   ! ice natural aging incrementation
+         !
+!!gm   here I think the number of ice cat is too small to use a SUM instruction...
+         DO jj = 1, jpj
+            DO ji = 1, jpi            
+               !                 ! heat content variation (W.m-2)
+               diag_heat(ji,jj) = diag_heat(ji,jj) - (  SUM( e_i(ji,jj,1:nlay_i,:) - e_i_b(ji,jj,1:nlay_i,:) )    & 
+                  &                                   + SUM( e_s(ji,jj,1:nlay_s,:) - e_s_b(ji,jj,1:nlay_s,:) )  ) * r1_rdtice
+               !                 ! salt, volume
+               diag_sice(ji,jj) = diag_sice(ji,jj) + SUM( sv_i(ji,jj,:) - sv_i_b(ji,jj,:) ) * rhoic * r1_rdtice
+               diag_vice(ji,jj) = diag_vice(ji,jj) + SUM( v_i (ji,jj,:) - v_i_b (ji,jj,:) ) * rhoic * r1_rdtice
+               diag_vsnw(ji,jj) = diag_vsnw(ji,jj) + SUM( v_s (ji,jj,:) - v_s_b (ji,jj,:) ) * rhosn * r1_rdtice
+            END DO
+         END DO
+         !                       ! concentration tendency (total + thermo)
+         zafx   (:,:) = SUM( a_i(:,:,:) - a_i_b(:,:,:), dim=3 ) * r1_rdtice
+         afx_tot(:,:) = afx_tot(:,:) + zafx(:,:)
+         IF( iom_use('afxthd') )   CALL iom_put( 'afxthd' , zafx(:,:) )
+         IF( iom_use('afxtot') )   CALL iom_put( 'afxtot' , afx_tot(:,:) )
+         !
+      END SELECT
+      !
+      ! controls
+      IF( ln_icediachk   )   CALL ice_cons_hsm(1, 'icecor', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
+      IF( ln_ctl         )   CALL ice_prt3D   ('icecor')                                                             ! prints
+      IF( ln_icectl .AND. kn == 2 )   CALL ice_prt( kt, iiceprt, jiceprt, 2, ' - Final state - ' )                   ! prints
+      IF( nn_timing == 1 )   CALL timing_stop ('icecor')                                                             ! timing
+      !
+   END SUBROUTINE ice_cor
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option           Dummy module         NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icecor
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icectl.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icectl.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icectl.F90	(revision 9019)
@@ -0,0 +1,676 @@
+MODULE icectl
+   !!======================================================================
+   !!                     ***  MODULE  icectl  ***
+   !!   sea-ice : controls and prints
+   !!======================================================================
+   !! History :  3.5  !  2015-01  (M. Vancoppenolle) Original code
+   !!            3.7  !  2016-10  (C. Rousset)       Add routine ice_prt3D
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!    ice_cons_hsm     : conservation tests on heat, salt and mass
+   !!    ice_cons_final   : conservation tests on heat, salt and mass at end of time step
+   !!    ice_ctl          : control prints in case of crash
+   !!    ice_prt          : control prints at a given grid point
+   !!    ice_prt3D        : control prints of ice arrays
+   !!----------------------------------------------------------------------
+   USE phycst         ! physical constants
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE ice            ! sea-ice: variables
+   USE ice1D          ! sea-ice: thermodynamics variables
+   USE sbc_oce        ! Surface boundary condition: ocean fields
+   USE sbc_ice        ! Surface boundary condition: ice   fields
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE timing         ! Timing
+   USE prtctl         ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_cons_hsm
+   PUBLIC   ice_cons_final
+   PUBLIC   ice_ctl
+   PUBLIC   ice_prt
+   PUBLIC   ice_prt3D
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icectl.F90 5043 2015-01-28 16:44:18Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_cons_hsm( icount, cd_routine, pdiag_v, pdiag_s, pdiag_t, pdiag_fv, pdiag_fs, pdiag_ft )
+      !!-------------------------------------------------------------------
+      !!                       ***  ROUTINE ice_cons_hsm ***
+      !!
+      !! ** Purpose : Test the conservation of heat, salt and mass for each ice routine
+      !!                     + test if ice concentration and volume are > 0
+      !!
+      !! ** Method  : This is an online diagnostics which can be activated with ln_icediachk=true
+      !!              It prints in ocean.output if there is a violation of conservation at each time-step
+      !!              The thresholds (zv_sill, zs_sill, zt_sill) which determine violations are set to
+      !!              a minimum of 1 mm of ice (over the ice area) that is lost/gained spuriously during 100 years.
+      !!              For salt and heat thresholds, ice is considered to have a salinity of 10 
+      !!              and a heat content of 3e5 J/kg (=latent heat of fusion) 
+      !!-------------------------------------------------------------------
+      INTEGER         , INTENT(in)    ::   icount        ! called at: =0 the begining of the routine, =1  the end
+      CHARACTER(len=*), INTENT(in)    ::   cd_routine    ! name of the routine
+      REAL(wp)        , INTENT(inout) ::   pdiag_v, pdiag_s, pdiag_t, pdiag_fv, pdiag_fs, pdiag_ft
+      !!
+      REAL(wp) ::   zv, zs, zt, zfs, zfv, zft
+      REAL(wp) ::   zvmin, zamin, zamax 
+      REAL(wp) ::   zvtrp, zetrp
+      REAL(wp) ::   zarea, zv_sill, zs_sill, zt_sill
+      REAL(wp), PARAMETER ::   zconv = 1.e-9 ! convert W to GW and kg to Mt
+      !!-------------------------------------------------------------------
+      !
+      IF( icount == 0 ) THEN
+         !                          ! water flux
+         pdiag_fv = glob_sum( -( wfx_bog(:,:) + wfx_bom(:,:) + wfx_sum(:,:) + wfx_sni(:,:) +                  &
+            &                    wfx_opw(:,:) + wfx_res(:,:) + wfx_dyn(:,:) + wfx_lam(:,:) + wfx_pnd(:,:)  +  &
+            &                    wfx_snw_sni(:,:) + wfx_snw_sum(:,:) + wfx_snw_dyn(:,:) + wfx_snw_sub(:,:) +  &
+            &                    wfx_ice_sub(:,:) + wfx_spr(:,:)  &
+            &                  ) * e1e2t(:,:) ) * zconv
+         !
+         !                          ! salt flux
+         pdiag_fs = glob_sum(  ( sfx_bri(:,:) + sfx_bog(:,:) + sfx_bom(:,:) + sfx_sum(:,:) + sfx_sni(:,:) +  &
+            &                    sfx_opw(:,:) + sfx_res(:,:) + sfx_dyn(:,:) + sfx_sub(:,:) + sfx_lam(:,:)    &
+            &                  ) *  e1e2t(:,:) ) * zconv 
+         !
+         !                          ! heat flux
+         pdiag_ft = glob_sum(  ( hfx_sum(:,:) + hfx_bom(:,:) + hfx_bog(:,:) + hfx_dif(:,:) + hfx_opw(:,:) + hfx_snw(:,:)  & 
+            &                  - hfx_thd(:,:) - hfx_dyn(:,:) - hfx_res(:,:) - hfx_sub(:,:) - hfx_spr(:,:)   &
+            &                  ) *  e1e2t(:,:) ) * zconv
+
+         pdiag_v = glob_sum( SUM( v_i * rhoic + v_s * rhosn, dim=3 ) * e1e2t * zconv )
+
+         pdiag_s = glob_sum( SUM( sv_i * rhoic             , dim=3 ) * e1e2t * zconv )
+
+         pdiag_t = glob_sum( (  SUM( SUM( e_i(:,:,1:nlay_i,:), dim=4 ), dim=3 )     &
+            &                 + SUM( SUM( e_s(:,:,1:nlay_s,:), dim=4 ), dim=3 ) ) * e1e2t ) * zconv
+
+      ELSEIF( icount == 1 ) THEN
+
+         ! water flux
+         zfv  = glob_sum( -( wfx_bog(:,:) + wfx_bom(:,:) + wfx_sum(:,:) + wfx_sni(:,:) +                  &
+            &                wfx_opw(:,:) + wfx_res(:,:) + wfx_dyn(:,:) + wfx_lam(:,:) + wfx_pnd(:,:)  +  &
+            &                wfx_snw_sni(:,:) + wfx_snw_sum(:,:) + wfx_snw_dyn(:,:) + wfx_snw_sub(:,:) +  &
+            &                wfx_ice_sub(:,:) + wfx_spr(:,:)  &
+            &              ) * e1e2t(:,:) ) * zconv - pdiag_fv
+
+         ! salt flux
+         zfs  = glob_sum(  ( sfx_bri(:,:) + sfx_bog(:,:) + sfx_bom(:,:) + sfx_sum(:,:) + sfx_sni(:,:) +  &
+            &                sfx_opw(:,:) + sfx_res(:,:) + sfx_dyn(:,:) + sfx_sub(:,:) + sfx_lam(:,:)    & 
+            &              ) * e1e2t(:,:) ) * zconv - pdiag_fs
+
+         ! heat flux
+         zft  = glob_sum(  ( hfx_sum(:,:) + hfx_bom(:,:) + hfx_bog(:,:) + hfx_dif(:,:) + hfx_opw(:,:) + hfx_snw(:,:)  & 
+            &              - hfx_thd(:,:) - hfx_dyn(:,:) - hfx_res(:,:) - hfx_sub(:,:) - hfx_spr(:,:)   &
+            &              ) * e1e2t(:,:) ) * zconv - pdiag_ft
+ 
+         ! outputs
+         zv = ( ( glob_sum( SUM( v_i * rhoic + v_s * rhosn, dim=3 ) * e1e2t ) * zconv  &
+            &     - pdiag_v ) * r1_rdtice - zfv ) * rday
+
+         zs = ( ( glob_sum( SUM( sv_i * rhoic             , dim=3 ) * e1e2t ) * zconv  &
+            &     - pdiag_s ) * r1_rdtice + zfs ) * rday
+
+         zt = ( glob_sum( (  SUM( SUM( e_i(:,:,1:nlay_i,:), dim=4 ), dim=3 )   &
+            &              + SUM( SUM( e_s(:,:,1:nlay_s,:), dim=4 ), dim=3 ) ) * e1e2t ) * zconv   &
+            &   - pdiag_t ) * r1_rdtice + zft
+
+         ! zvtrp and zetrp must be close to 0 if the advection scheme is conservative
+         zvtrp = glob_sum( ( diag_trp_vi * rhoic + diag_trp_vs * rhosn ) * e1e2t  ) * zconv * rday 
+         zetrp = glob_sum( ( diag_trp_ei         + diag_trp_es         ) * e1e2t  ) * zconv
+
+         zvmin = glob_min( v_i )
+         zamax = glob_max( SUM( a_i, dim=3 ) )
+         zamin = glob_min( a_i )
+
+         ! set threshold values and calculate the ice area (+epsi10 to set a threshold > 0 when there is no ice) 
+         zarea   = glob_sum( SUM( a_i + epsi10, dim=3 ) * e1e2t ) * zconv ! in 1.e9 m2
+         zv_sill = zarea * 2.5e-5
+         zs_sill = zarea * 25.e-5
+         zt_sill = zarea * 10.e-5
+
+         IF(lwp) THEN
+            IF ( ABS( zv   ) > zv_sill )   WRITE(numout,*) 'violation volume [Mt/day]     (',cd_routine,') = ',zv
+            IF ( ABS( zs   ) > zs_sill )   WRITE(numout,*) 'violation saline [psu*Mt/day] (',cd_routine,') = ',zs
+            IF ( ABS( zt   ) > zt_sill )   WRITE(numout,*) 'violation enthalpy [GW]       (',cd_routine,') = ',zt
+            IF ( ABS(zvtrp ) > zv_sill .AND. cd_routine == 'icedyn_adv' ) THEN
+                                           WRITE(numout,*) 'violation vtrp [Mt/day]       (',cd_routine,') = ',zvtrp
+                                           WRITE(numout,*) 'violation etrp [GW]           (',cd_routine,') = ',zetrp
+            ENDIF
+            IF ( zvmin < -epsi10 )         WRITE(numout,*) 'violation v_i<0  [m]          (',cd_routine,') = ',zvmin
+            IF ( zamax > MAX(rn_amax_n,rn_amax_s)+epsi10 .AND. cd_routine /= 'icedyn_adv' .AND. cd_routine /= 'icedyn_rdgrft' )  &
+               &                           WRITE(numout,*) 'violation a_i>amax            (',cd_routine,') = ',zamax
+            IF ( zamin < -epsi10 )         WRITE(numout,*) 'violation a_i<0               (',cd_routine,') = ',zamin
+         ENDIF
+         !
+      ENDIF
+
+   END SUBROUTINE ice_cons_hsm
+
+
+   SUBROUTINE ice_cons_final( cd_routine )
+      !!-------------------------------------------------------------------
+      !!                     ***  ROUTINE ice_cons_final ***
+      !!
+      !! ** Purpose : Test the conservation of heat, salt and mass at the end of each ice time-step
+      !!
+      !! ** Method  : This is an online diagnostics which can be activated with ln_icediachk=true
+      !!              It prints in ocean.output if there is a violation of conservation at each time-step
+      !!              The thresholds (zv_sill, zs_sill, zt_sill) which determine the violation are set to
+      !!              a minimum of 1 mm of ice (over the ice area) that is lost/gained spuriously during 100 years.
+      !!              For salt and heat thresholds, ice is considered to have a salinity of 10 
+      !!              and a heat content of 3e5 J/kg (=latent heat of fusion) 
+      !!-------------------------------------------------------------------
+      CHARACTER(len=*), INTENT(in)    :: cd_routine    ! name of the routine
+      REAL(wp)                        :: zhfx, zsfx, zvfx
+      REAL(wp)                        :: zarea, zv_sill, zs_sill, zt_sill
+      REAL(wp), PARAMETER             :: zconv = 1.e-9 ! convert W to GW and kg to Mt
+      !!-------------------------------------------------------------------
+
+      ! water flux
+      zvfx  = glob_sum( ( wfx_ice + wfx_snw + wfx_spr + wfx_sub + diag_vice + diag_vsnw ) * e1e2t ) * zconv * rday
+
+      ! salt flux
+      zsfx  = glob_sum( ( sfx + diag_sice ) * e1e2t ) * zconv * rday
+
+      ! heat flux
+      zhfx  = glob_sum( ( hfx_in - hfx_out - diag_heat - diag_trp_ei - diag_trp_es   &
+      !  &              - SUM( qevap_ice * a_i_b, dim=3 )                           & !!clem: I think this line must be commented (but need check)
+         &              ) * e1e2t ) * zconv
+
+      ! set threshold values and calculate the ice area (+epsi10 to set a threshold > 0 when there is no ice) 
+      zarea   = glob_sum( SUM( a_i + epsi10, dim=3 ) * e1e2t ) * zconv ! in 1.e9 m2
+      zv_sill = zarea * 2.5e-5
+      zs_sill = zarea * 25.e-5
+      zt_sill = zarea * 10.e-5
+
+      IF(lwp) THEN
+         IF( ABS( zvfx ) > zv_sill )   WRITE(numout,*) 'violation vfx  [Mt/day]       (',cd_routine,') = ',zvfx
+         IF( ABS( zsfx ) > zs_sill )   WRITE(numout,*) 'violation sfx  [psu*Mt/day]   (',cd_routine,') = ',zsfx
+         IF( ABS( zhfx ) > zt_sill )   WRITE(numout,*) 'violation hfx  [GW]           (',cd_routine,') = ',zhfx
+      ENDIF
+      !
+   END SUBROUTINE ice_cons_final
+
+   
+   SUBROUTINE ice_ctl( kt )
+      !!-------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_ctl *** 
+      !!                 
+      !! ** Purpose :   Alerts in case of model crash
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt      ! ocean time step
+      INTEGER  ::   ji, jj, jk,  jl   ! dummy loop indices
+      INTEGER  ::   inb_altests       ! number of alert tests (max 20)
+      INTEGER  ::   ialert_id         ! number of the current alert
+      REAL(wp) ::   ztmelts           ! ice layer melting point
+      CHARACTER (len=30), DIMENSION(20) ::   cl_alname   ! name of alert
+      INTEGER           , DIMENSION(20) ::   inb_alp     ! number of alerts positive
+      !!-------------------------------------------------------------------
+
+      inb_altests = 10
+      inb_alp(:)  =  0
+
+      ! Alert if incompatible volume and concentration
+      ialert_id = 2 ! reference number of this alert
+      cl_alname(ialert_id) = ' Incompat vol and con         '    ! name of the alert
+
+      DO jl = 1, jpl
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF(  v_i(ji,jj,jl) /= 0._wp   .AND.   a_i(ji,jj,jl) == 0._wp   ) THEN
+                  !WRITE(numout,*) ' ALERTE 2 :   Incompatible volume and concentration '
+                  !WRITE(numout,*) ' at_i     ', at_i(ji,jj)
+                  !WRITE(numout,*) ' Point - category', ji, jj, jl
+                  !WRITE(numout,*) ' a_i *** a_i_b   ', a_i      (ji,jj,jl), a_i_b  (ji,jj,jl)
+                  !WRITE(numout,*) ' v_i *** v_i_b   ', v_i      (ji,jj,jl), v_i_b  (ji,jj,jl)
+                  inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+      ! Alerte if very thick ice
+      ialert_id = 3 ! reference number of this alert
+      cl_alname(ialert_id) = ' Very thick ice               ' ! name of the alert
+      jl = jpl 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF(   h_i(ji,jj,jl)  >  50._wp   ) THEN
+               !CALL ice_prt( kt, ji, jj, 2, ' ALERTE 3 :   Very thick ice ' )
+               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+            ENDIF
+         END DO
+      END DO
+
+      ! Alert if very fast ice
+      ialert_id = 4 ! reference number of this alert
+      cl_alname(ialert_id) = ' Very fast ice               ' ! name of the alert
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF(   MAX( ABS( u_ice(ji,jj) ), ABS( v_ice(ji,jj) ) ) > 1.5  .AND.  &
+               &  at_i(ji,jj) > 0._wp   ) THEN
+               !CALL ice_prt( kt, ji, jj, 1, ' ALERTE 4 :   Very fast ice ' )
+               !WRITE(numout,*) ' ice strength             : ', strength(ji,jj)
+               !WRITE(numout,*) ' oceanic stress utau      : ', utau(ji,jj) 
+               !WRITE(numout,*) ' oceanic stress vtau      : ', vtau(ji,jj)
+               !WRITE(numout,*) ' sea-ice stress utau_ice  : ', utau_ice(ji,jj) 
+               !WRITE(numout,*) ' sea-ice stress vtau_ice  : ', vtau_ice(ji,jj)
+               !WRITE(numout,*) ' sst                      : ', sst_m(ji,jj)
+               !WRITE(numout,*) ' sss                      : ', sss_m(ji,jj)
+               !WRITE(numout,*) 
+               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+            ENDIF
+         END DO
+      END DO
+
+      ! Alert if there is ice on continents
+      ialert_id = 6 ! reference number of this alert
+      cl_alname(ialert_id) = ' Ice on continents           ' ! name of the alert
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF(   tmask(ji,jj,1) <= 0._wp   .AND.   at_i(ji,jj) > 0._wp   ) THEN 
+               !CALL ice_prt( kt, ji, jj, 1, ' ALERTE 6 :   Ice on continents ' )
+               !WRITE(numout,*) ' masks s, u, v        : ', tmask(ji,jj,1), umask(ji,jj,1), vmask(ji,jj,1) 
+               !WRITE(numout,*) ' sst                  : ', sst_m(ji,jj)
+               !WRITE(numout,*) ' sss                  : ', sss_m(ji,jj)
+               !WRITE(numout,*) ' at_i(ji,jj)          : ', at_i(ji,jj)
+               !WRITE(numout,*) ' v_ice(ji,jj)         : ', v_ice(ji,jj)
+               !WRITE(numout,*) ' v_ice(ji,jj-1)       : ', v_ice(ji,jj-1)
+               !WRITE(numout,*) ' u_ice(ji-1,jj)       : ', u_ice(ji-1,jj)
+               !WRITE(numout,*) ' u_ice(ji,jj)         : ', v_ice(ji,jj)
+               !
+               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+            ENDIF
+         END DO
+      END DO
+
+!
+!     ! Alert if very fresh ice
+      ialert_id = 7 ! reference number of this alert
+      cl_alname(ialert_id) = ' Very fresh ice               ' ! name of the alert
+      DO jl = 1, jpl
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( s_i(ji,jj,jl) < 0.1 .AND. a_i(ji,jj,jl) > 0._wp ) THEN
+!                 CALL ice_prt(kt,ji,jj,1, ' ALERTE 7 :   Very fresh ice ' )
+!                 WRITE(numout,*) ' sst                  : ', sst_m(ji,jj)
+!                 WRITE(numout,*) ' sss                  : ', sss_m(ji,jj)
+!                 WRITE(numout,*) 
+                  inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+               ENDIF
+            END DO
+         END DO
+      END DO
+!
+
+!     ! Alert if too old ice
+      ialert_id = 9 ! reference number of this alert
+      cl_alname(ialert_id) = ' Very old   ice               ' ! name of the alert
+      DO jl = 1, jpl
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF ( ( ( ABS( o_i(ji,jj,jl) ) > rdt_ice ) .OR. &
+                      ( ABS( o_i(ji,jj,jl) ) < 0._wp) ) .AND. &
+                             ( a_i(ji,jj,jl) > 0._wp ) ) THEN
+                  !CALL ice_prt( kt, ji, jj, 1, ' ALERTE 9 :   Wrong ice age ')
+                  inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+               ENDIF
+            END DO
+         END DO
+      END DO
+ 
+      ! Alert on salt flux
+      ialert_id = 5 ! reference number of this alert
+      cl_alname(ialert_id) = ' High salt flux               ' ! name of the alert
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( ABS( sfx (ji,jj) ) > 1.0e-2 ) THEN  ! = 1 psu/day for 1m ocean depth
+               !CALL ice_prt( kt, ji, jj, 3, ' ALERTE 5 :   High salt flux ' )
+               !DO jl = 1, jpl
+                  !WRITE(numout,*) ' Category no: ', jl
+                  !WRITE(numout,*) ' a_i        : ', a_i      (ji,jj,jl) , ' a_i_b      : ', a_i_b  (ji,jj,jl)   
+                  !WRITE(numout,*) ' v_i        : ', v_i      (ji,jj,jl) , ' v_i_b      : ', v_i_b  (ji,jj,jl)   
+                  !WRITE(numout,*) ' '
+               !END DO
+               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+            ENDIF
+         END DO
+      END DO
+
+      ! Alert if qns very big
+      ialert_id = 8 ! reference number of this alert
+      cl_alname(ialert_id) = ' fnsolar very big             ' ! name of the alert
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( ABS( qns(ji,jj) ) > 1500._wp .AND. at_i(ji,jj) > 0._wp ) THEN
+               !
+               !WRITE(numout,*) ' ALERTE 8 :   Very high non-solar heat flux'
+               !WRITE(numout,*) ' ji, jj    : ', ji, jj
+               !WRITE(numout,*) ' qns       : ', qns(ji,jj)
+               !WRITE(numout,*) ' sst       : ', sst_m(ji,jj)
+               !WRITE(numout,*) ' sss       : ', sss_m(ji,jj)
+               !
+               !CALL ice_prt( kt, ji, jj, 2, '   ')
+               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+               !
+            ENDIF
+         END DO
+      END DO
+      !+++++
+ 
+      ! Alert if very warm ice
+      ialert_id = 10 ! reference number of this alert
+      cl_alname(ialert_id) = ' Very warm ice                ' ! name of the alert
+      inb_alp(ialert_id) = 0
+      DO jl = 1, jpl
+         DO jk = 1, nlay_i
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ztmelts    =  -tmut * sz_i(ji,jj,jk,jl) + rt0
+                  IF( t_i(ji,jj,jk,jl) >= ztmelts  .AND.  v_i(ji,jj,jl) > 1.e-10   &
+                     &                             .AND.  a_i(ji,jj,jl) > 0._wp   ) THEN
+                     !WRITE(numout,*) ' ALERTE 10 :   Very warm ice'
+                     !WRITE(numout,*) ' ji, jj, jk, jl : ', ji, jj, jk, jl
+                     !WRITE(numout,*) ' t_i : ', t_i(ji,jj,jk,jl)
+                     !WRITE(numout,*) ' e_i : ', e_i(ji,jj,jk,jl)
+                     !WRITE(numout,*) ' sz_i: ', sz_i(ji,jj,jk,jl)
+                     !WRITE(numout,*) ' ztmelts : ', ztmelts
+                     inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+                  ENDIF
+               END DO
+            END DO
+         END DO
+      END DO
+
+      ! sum of the alerts on all processors
+      IF( lk_mpp ) THEN
+         DO ialert_id = 1, inb_altests
+            CALL mpp_sum(inb_alp(ialert_id))
+         END DO
+      ENDIF
+
+      ! print alerts
+      IF( lwp ) THEN
+         ialert_id = 1                                 ! reference number of this alert
+         cl_alname(ialert_id) = ' NO alerte 1      '   ! name of the alert
+         WRITE(numout,*) ' time step ',kt
+         WRITE(numout,*) ' All alerts at the end of ice model '
+         DO ialert_id = 1, inb_altests
+            WRITE(numout,*) ialert_id, cl_alname(ialert_id)//' : ', inb_alp(ialert_id), ' times ! '
+         END DO
+      ENDIF
+     !
+   END SUBROUTINE ice_ctl
+ 
+   
+   SUBROUTINE ice_prt( kt, ki, kj, kn, cd1 )
+      !!-------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_prt *** 
+      !!                 
+      !! ** Purpose :   Writes global ice state on the (i,j) point 
+      !!                in ocean.ouput 
+      !!                3 possibilities exist 
+      !!                n = 1/-1 -> simple ice state (plus Mechanical Check if -1)
+      !!                n = 2    -> exhaustive state
+      !!                n = 3    -> ice/ocean salt fluxes
+      !!
+      !! ** input   :   point coordinates (i,j) 
+      !!                n : number of the option
+      !!-------------------------------------------------------------------
+      INTEGER         , INTENT(in) ::   kt            ! ocean time step
+      INTEGER         , INTENT(in) ::   ki, kj, kn    ! ocean gridpoint indices
+      CHARACTER(len=*), INTENT(in) ::   cd1           !
+      !!
+      INTEGER :: jl, ji, jj
+      !!-------------------------------------------------------------------
+
+      DO ji = mi0(ki), mi1(ki)
+         DO jj = mj0(kj), mj1(kj)
+
+            WRITE(numout,*) ' time step ',kt,' ',cd1             ! print title
+
+            !----------------
+            !  Simple state
+            !----------------
+            
+            IF ( kn == 1 .OR. kn == -1 ) THEN
+               WRITE(numout,*) ' ice_prt - Point : ',ji,jj
+               WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
+               WRITE(numout,*) ' Simple state '
+               WRITE(numout,*) ' masks s,u,v   : ', tmask(ji,jj,1), umask(ji,jj,1), vmask(ji,jj,1)
+               WRITE(numout,*) ' lat - long    : ', gphit(ji,jj), glamt(ji,jj)
+               WRITE(numout,*) ' - Ice drift   '
+               WRITE(numout,*) '   ~~~~~~~~~~~ '
+               WRITE(numout,*) ' u_ice(i-1,j)  : ', u_ice(ji-1,jj)
+               WRITE(numout,*) ' u_ice(i  ,j)  : ', u_ice(ji,jj)
+               WRITE(numout,*) ' v_ice(i  ,j-1): ', v_ice(ji,jj-1)
+               WRITE(numout,*) ' v_ice(i  ,j)  : ', v_ice(ji,jj)
+               WRITE(numout,*) ' strength      : ', strength(ji,jj)
+               WRITE(numout,*)
+               WRITE(numout,*) ' - Cell values '
+               WRITE(numout,*) '   ~~~~~~~~~~~ '
+               WRITE(numout,*) ' cell area     : ', e1e2t(ji,jj)
+               WRITE(numout,*) ' at_i          : ', at_i(ji,jj)       
+               WRITE(numout,*) ' vt_i          : ', vt_i(ji,jj)       
+               WRITE(numout,*) ' vt_s          : ', vt_s(ji,jj)       
+               DO jl = 1, jpl
+                  WRITE(numout,*) ' - Category (', jl,')'
+                  WRITE(numout,*) ' a_i           : ', a_i(ji,jj,jl)
+                  WRITE(numout,*) ' h_i           : ', h_i(ji,jj,jl)
+                  WRITE(numout,*) ' h_s           : ', h_s(ji,jj,jl)
+                  WRITE(numout,*) ' v_i           : ', v_i(ji,jj,jl)
+                  WRITE(numout,*) ' v_s           : ', v_s(ji,jj,jl)
+                  WRITE(numout,*) ' e_s           : ', e_s(ji,jj,1,jl)
+                  WRITE(numout,*) ' e_i           : ', e_i(ji,jj,1:nlay_i,jl)
+                  WRITE(numout,*) ' t_su          : ', t_su(ji,jj,jl)
+                  WRITE(numout,*) ' t_snow        : ', t_s(ji,jj,1,jl)
+                  WRITE(numout,*) ' t_i           : ', t_i(ji,jj,1:nlay_i,jl)
+                  WRITE(numout,*) ' s_i           : ', s_i(ji,jj,jl)
+                  WRITE(numout,*) ' sv_i          : ', sv_i(ji,jj,jl)
+                  WRITE(numout,*)
+               END DO
+            ENDIF
+            IF( kn == -1 ) THEN
+               WRITE(numout,*) ' Mechanical Check ************** '
+               WRITE(numout,*) ' Check what means ice divergence '
+               WRITE(numout,*) ' Total ice concentration ', at_i (ji,jj)
+               WRITE(numout,*) ' Total lead fraction     ', ato_i(ji,jj)
+               WRITE(numout,*) ' Sum of both             ', ato_i(ji,jj) + at_i(ji,jj)
+               WRITE(numout,*) ' Sum of both minus 1     ', ato_i(ji,jj) + at_i(ji,jj) - 1.00
+            ENDIF
+            
+
+            !--------------------
+            !  Exhaustive state
+            !--------------------
+            
+            IF ( kn .EQ. 2 ) THEN
+               WRITE(numout,*) ' ice_prt - Point : ',ji,jj
+               WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
+               WRITE(numout,*) ' Exhaustive state '
+               WRITE(numout,*) ' lat - long ', gphit(ji,jj), glamt(ji,jj)
+               WRITE(numout,*) 
+               WRITE(numout,*) ' - Cell values '
+               WRITE(numout,*) '   ~~~~~~~~~~~ '
+               WRITE(numout,*) ' cell area     : ', e1e2t(ji,jj)
+               WRITE(numout,*) ' at_i          : ', at_i(ji,jj)       
+               WRITE(numout,*) ' vt_i          : ', vt_i(ji,jj)       
+               WRITE(numout,*) ' vt_s          : ', vt_s(ji,jj)       
+               WRITE(numout,*) ' u_ice(i-1,j)  : ', u_ice(ji-1,jj)
+               WRITE(numout,*) ' u_ice(i  ,j)  : ', u_ice(ji,jj)
+               WRITE(numout,*) ' v_ice(i  ,j-1): ', v_ice(ji,jj-1)
+               WRITE(numout,*) ' v_ice(i  ,j)  : ', v_ice(ji,jj)
+               WRITE(numout,*) ' strength      : ', strength(ji,jj)
+               WRITE(numout,*) ' u_ice_b       : ', u_ice_b(ji,jj)    , ' v_ice_b       : ', v_ice_b(ji,jj)  
+               WRITE(numout,*)
+               
+               DO jl = 1, jpl
+                  WRITE(numout,*) ' - Category (',jl,')'
+                  WRITE(numout,*) '   ~~~~~~~~         ' 
+                  WRITE(numout,*) ' h_i        : ', h_i(ji,jj,jl)              , ' h_s        : ', h_s(ji,jj,jl)
+                  WRITE(numout,*) ' t_i        : ', t_i(ji,jj,1:nlay_i,jl)
+                  WRITE(numout,*) ' t_su       : ', t_su(ji,jj,jl)             , ' t_s        : ', t_s(ji,jj,1,jl)
+                  WRITE(numout,*) ' s_i        : ', s_i(ji,jj,jl)              , ' o_i        : ', o_i(ji,jj,jl)
+                  WRITE(numout,*) ' a_i        : ', a_i(ji,jj,jl)              , ' a_i_b      : ', a_i_b(ji,jj,jl)   
+                  WRITE(numout,*) ' v_i        : ', v_i(ji,jj,jl)              , ' v_i_b      : ', v_i_b(ji,jj,jl)   
+                  WRITE(numout,*) ' v_s        : ', v_s(ji,jj,jl)              , ' v_s_b      : ', v_s_b(ji,jj,jl)  
+                  WRITE(numout,*) ' e_i1       : ', e_i(ji,jj,1,jl)            , ' ei1        : ', e_i_b(ji,jj,1,jl) 
+                  WRITE(numout,*) ' e_i2       : ', e_i(ji,jj,2,jl)            , ' ei2_b      : ', e_i_b(ji,jj,2,jl)  
+                  WRITE(numout,*) ' e_snow     : ', e_s(ji,jj,1,jl)            , ' e_snow_b   : ', e_s_b(ji,jj,1,jl) 
+                  WRITE(numout,*) ' sv_i       : ', sv_i(ji,jj,jl)             , ' sv_i_b     : ', sv_i_b(ji,jj,jl)   
+                  WRITE(numout,*) ' oa_i       : ', oa_i(ji,jj,jl)             , ' oa_i_b     : ', oa_i_b(ji,jj,jl)
+               END DO !jl
+               
+               WRITE(numout,*)
+               WRITE(numout,*) ' - Heat / FW fluxes '
+               WRITE(numout,*) '   ~~~~~~~~~~~~~~~~ '
+               WRITE(numout,*) ' - Heat fluxes in and out the ice ***'
+               WRITE(numout,*) ' qsr_ini       : ', (1._wp-at_i_b(ji,jj)) * qsr(ji,jj) + SUM( a_i_b(ji,jj,:) * qsr_ice(ji,jj,:) )
+               WRITE(numout,*) ' qns_ini       : ', (1._wp-at_i_b(ji,jj)) * qns(ji,jj) + SUM( a_i_b(ji,jj,:) * qns_ice(ji,jj,:) )
+               WRITE(numout,*)
+               WRITE(numout,*) 
+               WRITE(numout,*) ' sst        : ', sst_m(ji,jj)  
+               WRITE(numout,*) ' sss        : ', sss_m(ji,jj)  
+               WRITE(numout,*) 
+               WRITE(numout,*) ' - Stresses '
+               WRITE(numout,*) '   ~~~~~~~~ '
+               WRITE(numout,*) ' utau_ice   : ', utau_ice(ji,jj) 
+               WRITE(numout,*) ' vtau_ice   : ', vtau_ice(ji,jj)
+               WRITE(numout,*) ' utau       : ', utau    (ji,jj) 
+               WRITE(numout,*) ' vtau       : ', vtau    (ji,jj)
+            ENDIF
+            
+            !---------------------
+            ! Salt / heat fluxes
+            !---------------------
+            
+            IF ( kn .EQ. 3 ) THEN
+               WRITE(numout,*) ' ice_prt - Point : ',ji,jj
+               WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
+               WRITE(numout,*) ' - Salt / Heat Fluxes '
+               WRITE(numout,*) '   ~~~~~~~~~~~~~~~~ '
+               WRITE(numout,*) ' lat - long ', gphit(ji,jj), glamt(ji,jj)
+               WRITE(numout,*)
+               WRITE(numout,*) ' - Heat fluxes at bottom interface ***'
+               WRITE(numout,*) ' qsr       : ', qsr(ji,jj)
+               WRITE(numout,*) ' qns       : ', qns(ji,jj)
+               WRITE(numout,*)
+               WRITE(numout,*) ' hfx_mass     : ', hfx_thd(ji,jj) + hfx_dyn(ji,jj) + hfx_snw(ji,jj) + hfx_res(ji,jj)
+               WRITE(numout,*) ' hfx_in       : ', hfx_in(ji,jj)
+               WRITE(numout,*) ' hfx_out      : ', hfx_out(ji,jj)
+               WRITE(numout,*) ' dhc          : ', diag_heat(ji,jj)              
+               WRITE(numout,*)
+               WRITE(numout,*) ' hfx_dyn      : ', hfx_dyn(ji,jj)
+               WRITE(numout,*) ' hfx_thd      : ', hfx_thd(ji,jj)
+               WRITE(numout,*) ' hfx_res      : ', hfx_res(ji,jj)
+               WRITE(numout,*) ' fhtur        : ', fhtur(ji,jj) 
+               WRITE(numout,*) ' qlead        : ', qlead(ji,jj) * r1_rdtice
+               WRITE(numout,*)
+               WRITE(numout,*) ' - Salt fluxes at bottom interface ***'
+               WRITE(numout,*) ' emp       : ', emp    (ji,jj)
+               WRITE(numout,*) ' sfx       : ', sfx    (ji,jj)
+               WRITE(numout,*) ' sfx_res   : ', sfx_res(ji,jj)
+               WRITE(numout,*) ' sfx_bri   : ', sfx_bri(ji,jj)
+               WRITE(numout,*) ' sfx_dyn   : ', sfx_dyn(ji,jj)
+               WRITE(numout,*)
+               WRITE(numout,*) ' - Momentum fluxes '
+               WRITE(numout,*) ' utau      : ', utau(ji,jj) 
+               WRITE(numout,*) ' vtau      : ', vtau(ji,jj)
+            ENDIF 
+            WRITE(numout,*) ' '
+            !
+         END DO
+      END DO
+      !
+   END SUBROUTINE ice_prt
+
+   SUBROUTINE ice_prt3D( cd_routine )
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_prt3D ***
+      !!
+      !! ** Purpose : CTL prints of ice arrays in case ln_ctl is activated 
+      !!
+      !!-------------------------------------------------------------------
+      CHARACTER(len=*), INTENT(in)  :: cd_routine    ! name of the routine
+      INTEGER                       :: jk, jl        ! dummy loop indices
+      
+      CALL prt_ctl_info(' ========== ')
+      CALL prt_ctl_info( cd_routine )
+      CALL prt_ctl_info(' ========== ')
+      CALL prt_ctl_info(' - Cell values : ')
+      CALL prt_ctl_info('   ~~~~~~~~~~~~~ ')
+      CALL prt_ctl(tab2d_1=e1e2t      , clinfo1=' cell area   :')
+      CALL prt_ctl(tab2d_1=at_i       , clinfo1=' at_i        :')
+      CALL prt_ctl(tab2d_1=ato_i      , clinfo1=' ato_i       :')
+      CALL prt_ctl(tab2d_1=vt_i       , clinfo1=' vt_i        :')
+      CALL prt_ctl(tab2d_1=vt_s       , clinfo1=' vt_s        :')
+      CALL prt_ctl(tab2d_1=divu_i     , clinfo1=' divu_i      :')
+      CALL prt_ctl(tab2d_1=delta_i    , clinfo1=' delta_i     :')
+      CALL prt_ctl(tab2d_1=stress1_i  , clinfo1=' stress1_i   :')
+      CALL prt_ctl(tab2d_1=stress2_i  , clinfo1=' stress2_i   :')
+      CALL prt_ctl(tab2d_1=stress12_i , clinfo1=' stress12_i  :')
+      CALL prt_ctl(tab2d_1=strength   , clinfo1=' strength    :')
+      CALL prt_ctl(tab2d_1=delta_i    , clinfo1=' delta_i     :')
+      CALL prt_ctl(tab2d_1=u_ice      , clinfo1=' u_ice       :', tab2d_2=v_ice      , clinfo2=' v_ice       :')
+       
+      DO jl = 1, jpl
+         CALL prt_ctl_info(' ')
+         CALL prt_ctl_info(' - Category : ', ivar1=jl)
+         CALL prt_ctl_info('   ~~~~~~~~~~')
+         CALL prt_ctl(tab2d_1=h_i        (:,:,jl)        , clinfo1= ' h_i         : ')
+         CALL prt_ctl(tab2d_1=h_s        (:,:,jl)        , clinfo1= ' h_s         : ')
+         CALL prt_ctl(tab2d_1=t_su       (:,:,jl)        , clinfo1= ' t_su        : ')
+         CALL prt_ctl(tab2d_1=t_s        (:,:,1,jl)      , clinfo1= ' t_snow      : ')
+         CALL prt_ctl(tab2d_1=s_i        (:,:,jl)        , clinfo1= ' s_i         : ')
+         CALL prt_ctl(tab2d_1=o_i        (:,:,jl)        , clinfo1= ' o_i         : ')
+         CALL prt_ctl(tab2d_1=a_i        (:,:,jl)        , clinfo1= ' a_i         : ')
+         CALL prt_ctl(tab2d_1=v_i        (:,:,jl)        , clinfo1= ' v_i         : ')
+         CALL prt_ctl(tab2d_1=v_s        (:,:,jl)        , clinfo1= ' v_s         : ')
+         CALL prt_ctl(tab2d_1=e_i        (:,:,1,jl)      , clinfo1= ' e_i1        : ')
+         CALL prt_ctl(tab2d_1=e_s        (:,:,1,jl)      , clinfo1= ' e_snow      : ')
+         CALL prt_ctl(tab2d_1=sv_i       (:,:,jl)        , clinfo1= ' sv_i        : ')
+         CALL prt_ctl(tab2d_1=oa_i       (:,:,jl)        , clinfo1= ' oa_i        : ')
+         
+         DO jk = 1, nlay_i
+            CALL prt_ctl_info(' - Layer : ', ivar1=jk)
+            CALL prt_ctl(tab2d_1=t_i(:,:,jk,jl) , clinfo1= ' t_i       : ')
+         END DO
+      END DO
+      
+      CALL prt_ctl_info(' ')
+      CALL prt_ctl_info(' - Heat / FW fluxes : ')
+      CALL prt_ctl_info('   ~~~~~~~~~~~~~~~~~~ ')
+      CALL prt_ctl(tab2d_1=sst_m  , clinfo1= ' sst   : ', tab2d_2=sss_m     , clinfo2= ' sss       : ')
+      CALL prt_ctl(tab2d_1=qsr    , clinfo1= ' qsr   : ', tab2d_2=qns       , clinfo2= ' qns       : ')
+      CALL prt_ctl(tab2d_1=emp    , clinfo1= ' emp   : ', tab2d_2=sfx       , clinfo2= ' sfx       : ')
+      
+      CALL prt_ctl_info(' ')
+      CALL prt_ctl_info(' - Stresses : ')
+      CALL prt_ctl_info('   ~~~~~~~~~~ ')
+      CALL prt_ctl(tab2d_1=utau       , clinfo1= ' utau      : ', tab2d_2=vtau       , clinfo2= ' vtau      : ')
+      CALL prt_ctl(tab2d_1=utau_ice   , clinfo1= ' utau_ice  : ', tab2d_2=vtau_ice   , clinfo2= ' vtau_ice  : ')
+      
+   END SUBROUTINE ice_prt3D
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty Module           No ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icectl
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedia.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedia.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedia.F90	(revision 9019)
@@ -0,0 +1,286 @@
+MODULE icedia
+   !!======================================================================
+   !!                       ***  MODULE icedia  ***
+   !!  Sea-Ice model :   global budgets 
+   !!======================================================================
+   !! History :  3.4  ! 2012-10  (C. Rousset)  original code
+   !!            4.0  ! 2017-08  (C. Rousset)  fits nemo4.0 standards
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!    ice_dia      : diagnostic of the sea-ice global heat content, salt content and volume conservation
+   !!    ice_dia_init : initialization of budget calculation
+   !!    ice_dia_rst  : read/write budgets restart
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean domain
+   USE phycst         ! physical constant
+   USE daymod         ! model calendar
+   USE sbc_oce , ONLY : sfx, nn_fsbc   ! surface boundary condition: ocean fields
+   USE ice            ! sea-ice: variables
+   USE icerst         ! sea-ice: restart
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE timing         ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_dia        ! called by icestp.F90
+   PUBLIC   ice_dia_init   ! called in icestp.F90
+
+   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   vol_loc_ini, sal_loc_ini, tem_loc_ini ! initial volume, salt and heat contents
+   REAL(wp)                              ::   frc_sal, frc_voltop, frc_volbot, frc_temtop, frc_tembot  ! global forcing trends
+   
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icedia.F90 8413 2017-08-07 17:05:39Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION ice_dia_alloc()
+      !!---------------------------------------------------------------------!
+      !!                ***  ROUTINE ice_dia_alloc ***
+      !!---------------------------------------------------------------------!
+      ALLOCATE( vol_loc_ini(jpi,jpj), sal_loc_ini(jpi,jpj), tem_loc_ini(jpi,jpj), STAT=ice_dia_alloc )
+
+      IF( lk_mpp             )   CALL mpp_sum ( ice_dia_alloc )
+      IF( ice_dia_alloc /= 0 )   CALL ctl_warn( 'ice_dia_alloc: failed to allocate arrays' )
+      !
+   END FUNCTION ice_dia_alloc
+
+   SUBROUTINE ice_dia( kt )
+      !!---------------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_dia  ***
+      !!     
+      !! ** Purpose:   Compute the sea-ice global heat content, salt content 
+      !!             and volume conservation
+      !!---------------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time step 
+      !!
+      REAL(wp)   ::   zbg_ivol, zbg_item, zbg_area, zbg_isal
+      REAL(wp)   ::   zbg_svol, zbg_stem
+      REAL(wp)   ::   z_frc_voltop, z_frc_temtop, z_frc_sal
+      REAL(wp)   ::   z_frc_volbot, z_frc_tembot  
+      REAL(wp)   ::   zdiff_vol, zdiff_sal, zdiff_tem  
+      !!---------------------------------------------------------------------------
+      IF( nn_timing == 1 )   CALL timing_start('ice_dia')
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*)'icedia: output ice diagnostics (integrated over the domain)'
+         WRITE(numout,*)'~~~~~~'
+      ENDIF
+
+!!gm glob_sum includes a " * tmask_i ", so remove  " * tmask(:,:,1) "
+
+      ! ----------------------- !
+      ! 1 -  Contents !
+      ! ----------------------- !
+      zbg_ivol = glob_sum( vt_i(:,:) * e1e2t(:,:) ) * 1.e-9                  ! ice volume (km3)
+      zbg_svol = glob_sum( vt_s(:,:) * e1e2t(:,:) ) * 1.e-9                  ! snow volume (km3)
+      zbg_area = glob_sum( at_i(:,:) * e1e2t(:,:) ) * 1.e-6                  ! area (km2)
+      zbg_isal = glob_sum( SUM( sv_i(:,:,:), dim=3 ) * e1e2t(:,:) ) * 1.e-9 ! salt content (pss*km3)
+      zbg_item = glob_sum( et_i * e1e2t(:,:) ) * 1.e-20                      ! heat content (1.e20 J)
+      zbg_stem = glob_sum( et_s * e1e2t(:,:) ) * 1.e-20                      ! heat content (1.e20 J)
+      
+      ! ---------------------------!
+      ! 2 - Trends due to forcing  !
+      ! ---------------------------!
+      z_frc_volbot = r1_rau0 * glob_sum( - ( wfx_ice(:,:) + wfx_snw(:,:) + wfx_err_sub(:,:) ) * e1e2t(:,:) ) * 1.e-9  ! freshwater flux ice/snow-ocean 
+      z_frc_voltop = r1_rau0 * glob_sum( - ( wfx_sub(:,:) + wfx_spr(:,:) ) * e1e2t(:,:) ) * 1.e-9                     ! freshwater flux ice/snow-atm
+      z_frc_sal    = r1_rau0 * glob_sum(   - sfx(:,:) * e1e2t(:,:) ) * 1.e-9                                          ! salt fluxes ice/snow-ocean
+      z_frc_tembot =           glob_sum( hfx_out(:,:) * e1e2t(:,:) ) * 1.e-20                                         ! heat on top of ocean (and below ice)
+      z_frc_temtop =           glob_sum( hfx_in (:,:) * e1e2t(:,:) ) * 1.e-20                                         ! heat on top of ice-coean
+      !
+      frc_voltop  = frc_voltop  + z_frc_voltop  * rdt_ice ! km3
+      frc_volbot  = frc_volbot  + z_frc_volbot  * rdt_ice ! km3
+      frc_sal     = frc_sal     + z_frc_sal     * rdt_ice ! km3*pss
+      frc_temtop  = frc_temtop  + z_frc_temtop  * rdt_ice ! 1.e20 J
+      frc_tembot  = frc_tembot  + z_frc_tembot  * rdt_ice ! 1.e20 J
+            
+      ! ----------------------- !
+      ! 3 -  Content variations !
+      ! ----------------------- !
+      zdiff_vol = r1_rau0 * glob_sum( ( rhoic*vt_i(:,:) + rhosn*vt_s(:,:) - vol_loc_ini(:,:) ) * e1e2t(:,:) ) * 1.e-9 ! freshwater trend (km3) 
+      zdiff_sal = r1_rau0 * glob_sum( ( rhoic* SUM( sv_i(:,:,:), dim=3 ) - sal_loc_ini(:,:) ) * e1e2t(:,:) ) * 1.e-9 ! salt content trend (km3*pss)
+      zdiff_tem =           glob_sum( ( et_i(:,:) + et_s(:,:)             - tem_loc_ini(:,:) ) * e1e2t(:,:) ) * 1.e-20 ! heat content trend (1.e20 J)
+      !                               + SUM( qevap_ice * a_i_b, dim=3 )       !! clem: I think this term should not be there (but needs a check)
+
+      ! ----------------------- !
+      ! 4 -  Drifts             !
+      ! ----------------------- !
+      zdiff_vol = zdiff_vol - ( frc_voltop + frc_volbot )
+      zdiff_sal = zdiff_sal - frc_sal
+      zdiff_tem = zdiff_tem - ( frc_tembot - frc_temtop )
+
+      ! ----------------------- !
+      ! 5 - Diagnostics writing !
+      ! ----------------------- !
+!!gm I don't understand the division by the ocean surface (i.e. glob_sum( e1e2t(:,:) ) * 1.e-20 * kt*rdt )
+!!   and its multiplication bu kt ! is it really what we want ? what is this quantity ?
+!!   IF it is really what we want, compute it at kt=nit000, not 3 time by time-step !
+!!   kt*rdt  : you mean rdtice ?
+!!gm
+      !
+      IF( iom_use('ibgvolume')    )   CALL iom_put( 'ibgvolume' , zdiff_vol     )   ! ice/snow volume  drift            (km3 equivalent ocean water)         
+      IF( iom_use('ibgsaltco')    )   CALL iom_put( 'ibgsaltco' , zdiff_sal     )   ! ice salt content drift            (psu*km3 equivalent ocean water)
+      IF( iom_use('ibgheatco')    )   CALL iom_put( 'ibgheatco' , zdiff_tem     )   ! ice/snow heat content drift       (1.e20 J)
+      IF( iom_use('ibgheatfx')    )   CALL iom_put( 'ibgheatfx' ,               &   ! ice/snow heat flux drift          (W/m2)
+         &                                                     zdiff_tem /glob_sum( e1e2t(:,:) * 1.e-20 * kt*rdt ) )
+
+      IF( iom_use('ibgfrcvoltop') )   CALL iom_put( 'ibgfrcvoltop' , frc_voltop )   ! vol  forcing ice/snw-atm          (km3 equivalent ocean water) 
+      IF( iom_use('ibgfrcvolbot') )   CALL iom_put( 'ibgfrcvolbot' , frc_volbot )   ! vol  forcing ice/snw-ocean        (km3 equivalent ocean water) 
+      IF( iom_use('ibgfrcsal')    )   CALL iom_put( 'ibgfrcsal'    , frc_sal    )   ! sal - forcing                     (psu*km3 equivalent ocean water)   
+      IF( iom_use('ibgfrctemtop') )   CALL iom_put( 'ibgfrctemtop' , frc_temtop )   ! heat on top of ice/snw/ocean      (1.e20 J)   
+      IF( iom_use('ibgfrctembot') )   CALL iom_put( 'ibgfrctembot' , frc_tembot )   ! heat on top of ocean(below ice)   (1.e20 J)   
+      IF( iom_use('ibgfrchfxtop') )   CALL iom_put( 'ibgfrchfxtop' ,            &   ! heat on top of ice/snw/ocean      (W/m2) 
+         &                                                          frc_temtop / glob_sum( e1e2t(:,:) ) * 1.e-20 * kt*rdt  )
+      IF( iom_use('ibgfrchfxbot') )   CALL iom_put( 'ibgfrchfxbot' ,            &   ! heat on top of ocean(below ice)   (W/m2) 
+         &                                                          frc_tembot / glob_sum( e1e2t(:,:) ) * 1.e-20 * kt*rdt  )
+
+      IF( iom_use('ibgvol_tot' )  )   CALL iom_put( 'ibgvol_tot'  , zbg_ivol     )   ! ice volume                       (km3)
+      IF( iom_use('sbgvol_tot' )  )   CALL iom_put( 'sbgvol_tot'  , zbg_svol     )   ! snow volume                      (km3)
+      IF( iom_use('ibgarea_tot')  )   CALL iom_put( 'ibgarea_tot' , zbg_area     )   ! ice area                         (km2)
+      IF( iom_use('ibgsalt_tot')  )   CALL iom_put( 'ibgsalt_tot' , zbg_isal     )   ! ice salinity content             (pss*km3)
+      IF( iom_use('ibgheat_tot')  )   CALL iom_put( 'ibgheat_tot' , zbg_item     )   ! ice heat content                 (1.e20 J)
+      IF( iom_use('sbgheat_tot')  )   CALL iom_put( 'sbgheat_tot' , zbg_stem     )   ! snow heat content                (1.e20 J)
+      !
+      IF( lrst_ice )   CALL ice_dia_rst( 'WRITE', kt_ice )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('ice_dia')
+      !
+   END SUBROUTINE ice_dia
+
+
+   SUBROUTINE ice_dia_init
+      !!---------------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_dia_init  ***
+      !!     
+      !! ** Purpose: Initialization for the heat salt volume budgets
+      !!	
+      !! ** Method : Compute initial heat content, salt content and volume
+      !!
+      !! ** Action : - Compute initial heat content, salt content and volume
+      !!             - Initialize forcing trends
+      !!             - Compute coefficients for conversion
+      !!---------------------------------------------------------------------------
+      INTEGER            ::   ios, ierror   ! local integer
+      !!
+      NAMELIST/namdia/ ln_icediachk, ln_icediahsb, ln_icectl, iiceprt, jiceprt  
+      !!----------------------------------------------------------------------
+      !
+      REWIND( numnam_ice_ref )      ! Namelist namdia in reference namelist : Parameters for ice
+      READ  ( numnam_ice_ref, namdia, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdia in reference namelist', lwp )
+
+      REWIND( numnam_ice_cfg )      ! Namelist namdia in configuration namelist : Parameters for ice
+      READ  ( numnam_ice_cfg, namdia, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdia in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namdia )
+      !
+      IF(lwp) THEN                  ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_dia_init: ice diagnostics'
+         WRITE(numout,*) ' ~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namdia:'
+         WRITE(numout,*) '      Diagnose online heat/mass/salt budget      ln_icediachk = ', ln_icediachk
+         WRITE(numout,*) '      Output          heat/mass/salt budget      ln_icediahsb = ', ln_icediahsb
+         WRITE(numout,*) '      control prints for a given grid point      ln_icectl    = ', ln_icectl
+         WRITE(numout,*) '         chosen grid point position         (iiceprt,jiceprt) = (', iiceprt,',', jiceprt,')'
+      ENDIF
+      !      
+      IF( ln_icediahsb ) THEN
+         IF( ice_dia_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'ice_dia_init : unable to allocate arrays' )   ! allocate tke arrays
+         CALL ice_dia_rst( 'READ' )   ! read or initialize all required files
+      ENDIF
+      !
+   END SUBROUTINE ice_dia_init
+
+
+   SUBROUTINE ice_dia_rst( cdrw, kt )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE icedia_rst  ***
+      !!                     
+      !! ** Purpose :   Read or write DIA file in restart file
+      !!
+      !! ** Method  :   use of IOM library
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*) , INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
+      INTEGER, OPTIONAL, INTENT(in) ::   kt     ! ice time-step
+      !
+      INTEGER  ::   iter    ! local integer
+      REAL(wp) ::   ziter   ! local scalar
+      !!----------------------------------------------------------------------
+      !
+      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
+         IF( ln_rstart ) THEN                   !* Read the restart file
+            !
+            CALL iom_get( numrir, 'kt_ice' , ziter )
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'ice_dia_rst read at time step = ', ziter
+            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+            CALL iom_get( numrir, 'frc_voltop' , frc_voltop  )
+            CALL iom_get( numrir, 'frc_volbot' , frc_volbot  )
+            CALL iom_get( numrir, 'frc_temtop' , frc_temtop  )
+            CALL iom_get( numrir, 'frc_tembot' , frc_tembot  )
+            CALL iom_get( numrir, 'frc_sal'    , frc_sal     )
+            CALL iom_get( numrir, jpdom_autoglo, 'vol_loc_ini', vol_loc_ini )
+            CALL iom_get( numrir, jpdom_autoglo, 'tem_loc_ini', tem_loc_ini )
+            CALL iom_get( numrir, jpdom_autoglo, 'sal_loc_ini', sal_loc_ini )
+         ELSE
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) ' ice_dia at initial state '
+            IF(lwp) WRITE(numout,*) '~~~~~~~'
+            ! set trends to 0
+            frc_voltop  = 0._wp                                          
+            frc_volbot  = 0._wp                                          
+            frc_temtop  = 0._wp                                                 
+            frc_tembot  = 0._wp                                                 
+            frc_sal     = 0._wp                                                 
+            ! record initial ice volume, salt and temp
+            vol_loc_ini(:,:) = rhoic * vt_i(:,:) + rhosn * vt_s(:,:)  ! ice/snow volume (kg/m2)
+            tem_loc_ini(:,:) = et_i(:,:) + et_s(:,:)                  ! ice/snow heat content (J)
+            sal_loc_ini(:,:) = rhoic * SUM( sv_i(:,:,:), dim=3 )      ! ice salt content (pss*kg/m2)
+         ENDIF
+         !
+      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
+         !                                   ! -------------------
+         iter = kt + nn_fsbc - 1   ! ice restarts are written at kt == nitrst - nn_fsbc + 1
+         !
+         IF( iter == nitrst ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'ice_dia_rst write at time step = ', kt
+            IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+         ENDIF
+         !
+         ! Write in numriw (if iter == nitrst)
+         ! ------------------ 
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_voltop' , frc_voltop  )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_volbot' , frc_volbot  )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_temtop' , frc_temtop  )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_tembot' , frc_tembot  )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_sal'    , frc_sal     )
+         CALL iom_rstput( iter, nitrst, numriw, 'vol_loc_ini', vol_loc_ini )
+         CALL iom_rstput( iter, nitrst, numriw, 'tem_loc_ini', tem_loc_ini )
+         CALL iom_rstput( iter, nitrst, numriw, 'sal_loc_ini', sal_loc_ini )
+         !
+      ENDIF
+      !
+   END SUBROUTINE ice_dia_rst
+ 
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :         Empty module         NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icedia
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn.F90	(revision 9019)
@@ -0,0 +1,284 @@
+MODULE icedyn
+   !!======================================================================
+   !!                     ***  MODULE  icedyn  ***
+   !!   Sea-Ice dynamics : master routine for sea ice dynamics 
+   !!======================================================================
+   !! history :  4.0  ! 2017-09  (C. Rousset)  original code 
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_dyn       : dynamics of sea ice
+   !!   ice_dyn_init  : initialization and namelist read
+   !!----------------------------------------------------------------------
+   USE phycst         ! physical constants
+   USE dom_oce        ! ocean space and time domain
+   USE ice            ! sea-ice: variables
+   USE icedyn_rhg     ! sea-ice: rheology
+   USE icedyn_adv     ! sea-ice: advection
+   USE icedyn_rdgrft  ! sea-ice: ridging/rafting
+   USE icecor         ! sea-ice: corrections
+   USE icevar         ! sea-ice: operations
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE lbclnk         ! lateral boundary conditions (or mpp links)
+   USE timing         ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_dyn        ! called by icestp.F90
+   PUBLIC   ice_dyn_init   ! called by icestp.F90
+   
+   INTEGER ::              nice_dyn   ! choice of the type of dynamics
+   !                                        ! associated indices:
+   INTEGER, PARAMETER ::   np_dynFULL    = 1   ! full ice dynamics               (rheology + advection + ridging/rafting + correction)
+   INTEGER, PARAMETER ::   np_dynRHGADV1 = 2   ! no ridging/rafting              (rheology + advection                   + correction)
+   INTEGER, PARAMETER ::   np_dynRHGADV2 = 3   ! pure dynamics                   (rheology + advection) 
+   INTEGER, PARAMETER ::   np_dynADV     = 4   ! only advection w prescribed vel.(rn_uvice + advection)
+   !
+   ! ** namelist (namdyn) **
+   LOGICAL  ::   ln_dynFULL       ! full ice dynamics               (rheology + advection + ridging/rafting + correction)
+   LOGICAL  ::   ln_dynRHGADV     ! no ridge/raft & no corrections  (rheology + advection)
+   LOGICAL  ::   ln_dynADV        ! only advection w prescribed vel.(rn_uvice + advection)
+   REAL(wp) ::   rn_uice          !    prescribed u-vel (case np_dynADV)
+   REAL(wp) ::   rn_vice          !    prescribed v-vel (case np_dynADV)
+   
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icedyn.F90 8378 2017-07-26 13:55:59Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_dyn( kt )
+      !!-------------------------------------------------------------------
+      !!               ***  ROUTINE ice_dyn  ***
+      !!               
+      !! ** Purpose :   this routine manages sea ice dynamics
+      !!
+      !! ** Action : - Initialisation of some variables
+      !!             - call ice_rhg
+      !!--------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! ice time step
+      !!
+      INTEGER ::   ji, jj, jl         ! dummy loop indices
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zhmax
+      !!--------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('icedyn')
+      !
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*)'ice_dyn: sea-ice dynamics'
+         WRITE(numout,*)'~~~~~~~'
+      ENDIF
+
+      !                      
+      IF( ln_landfast ) THEN            !-- Landfast ice parameterization: define max bottom friction
+         tau_icebfr(:,:) = 0._wp
+         DO jl = 1, jpl
+            WHERE( h_i(:,:,jl) > ht_n(:,:) * rn_gamma )   tau_icebfr(:,:) = tau_icebfr(:,:) + a_i(:,:,jl) * rn_icebfr
+         END DO
+         IF( iom_use('tau_icebfr') )   CALL iom_put( 'tau_icebfr', tau_icebfr )  
+      ENDIF
+
+      zhmax(:,:,:) = h_i_b(:,:,:)      !-- Record max of the surrounding 9-pts ice thick. (for CALL Hbig)
+      DO jl = 1, jpl
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+!!gm use of MAXVAL here is very probably less efficient than expending the 9 values
+               zhmax(ji,jj,jl) = MAX( epsi20, MAXVAL( h_i_b(ji-1:ji+1,jj-1:jj+1,jl) ) )
+            END DO
+         END DO
+      END DO
+      CALL lbc_lnk( zhmax(:,:,:), 'T', 1. )
+      !
+      !
+      SELECT CASE( nice_dyn )           !-- Set which dynamics is running
+
+      CASE ( np_dynFULL )          !==  all dynamical processes  ==!
+         CALL ice_dyn_rhg   ( kt )                            ! -- rheology  
+         CALL ice_dyn_adv   ( kt )   ;   CALL Hbig( zhmax )   ! -- advection of ice + correction on ice thickness
+         CALL ice_dyn_rdgrft( kt )                            ! -- ridging/rafting 
+         CALL ice_cor       ( kt , 1 )                        ! -- Corrections
+
+      CASE ( np_dynRHGADV1 )       !==  no ridge/raft ==!   (mono cat. case 2)
+         CALL ice_dyn_rhg   ( kt )                            ! -- rheology  
+         CALL ice_dyn_adv   ( kt )                            ! -- advection of ice
+         CALL Hpiling                                         ! -- simple pile-up (replaces ridging/rafting)
+         CALL ice_cor       ( kt , 1 )                        ! -- Corrections
+
+      CASE ( np_dynRHGADV2 )       !==  no ridge/raft & no corrections ==!
+         CALL ice_dyn_rhg   ( kt )                            ! -- rheology  
+         CALL ice_dyn_adv   ( kt )                            ! -- advection of ice
+         CALL Hpiling                                         ! -- simple pile-up (replaces ridging/rafting)
+
+      CASE ( np_dynADV )           !==  pure advection ==!   (prescribed velocities)
+         u_ice(:,:) = rn_uice * umask(:,:,1)
+         v_ice(:,:) = rn_vice * vmask(:,:,1)
+         !!CALL RANDOM_NUMBER(u_ice(:,:))
+         !!CALL RANDOM_NUMBER(v_ice(:,:))
+         CALL ice_dyn_adv   ( kt )                            ! -- advection of ice
+
+      END SELECT
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('icedyn')
+      !
+   END SUBROUTINE ice_dyn
+
+   SUBROUTINE Hbig( phmax )
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE Hbig  ***
+      !!
+      !! ** Purpose : Thickness correction in case advection scheme creates
+      !!              abnormally tick ice
+      !!
+      !! ** Method  : 1- check whether ice thickness resulting from advection is
+      !!                 larger than the surrounding 9-points before advection
+      !!                 and reduce it if a) divergence or b) convergence & at_i>0.8
+      !!              2- bound ice thickness with hi_max (99m)
+      !!
+      !! ** input   : Max thickness of the surrounding 9-points
+      !!-------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(in) ::   phmax   ! max ice thick from surrounding 9-pts
+      !
+      INTEGER  ::   ji, jj, jl         ! dummy loop indices
+      REAL(wp) ::   zh, zdv
+      !!-------------------------------------------------------------------
+      !
+      CALL ice_var_zapsmall                       !-- zap small areas
+      !
+      DO jl = 1, jpl
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF ( v_i(ji,jj,jl) > 0._wp ) THEN  !-- bound to hmax
+                  !
+                  zh  = v_i (ji,jj,jl) / a_i(ji,jj,jl)
+                  zdv = v_i(ji,jj,jl) - v_i_b(ji,jj,jl)  
+                  !
+                  IF ( ( zdv >  0.0 .AND. zh > phmax(ji,jj,jl) .AND. at_i_b(ji,jj) < 0.80 ) .OR. &
+                     & ( zdv <= 0.0 .AND. zh > phmax(ji,jj,jl) ) ) THEN
+                     a_i (ji,jj,jl) = v_i(ji,jj,jl) / MIN( phmax(ji,jj,jl), hi_max(jpl) )   !-- bound h_i to hi_max (99 m)
+                  ENDIF
+                  !
+               ENDIF
+            END DO
+         END DO
+      END DO 
+      !                                           !-- correct pond fraction to avoid a_ip > a_i
+      WHERE( a_ip(:,:,:) > a_i(:,:,:) )   a_ip(:,:,:) = a_i(:,:,:)
+      !
+   END SUBROUTINE Hbig
+
+   SUBROUTINE Hpiling
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE Hpiling  ***
+      !!
+      !! ** Purpose : Simple conservative piling comparable with 1-cat models
+      !!
+      !! ** Method  : pile-up ice when no ridging/rafting
+      !!
+      !! ** input   : a_i
+      !!-------------------------------------------------------------------
+      INTEGER ::   jl         ! dummy loop indices
+      !!-------------------------------------------------------------------
+      !
+      CALL ice_var_zapsmall                       !-- zap small areas
+      !
+      at_i(:,:) = SUM( a_i(:,:,:), dim=3 )
+      DO jl = 1, jpl
+         WHERE( at_i(:,:) > epsi20 )
+            a_i(:,:,jl) = a_i(:,:,jl) * (  1._wp + MIN( rn_amax_2d(:,:) - at_i(:,:) , 0._wp ) / at_i(:,:)  )
+         END WHERE
+      END DO
+      !
+   END SUBROUTINE Hpiling
+
+
+   SUBROUTINE ice_dyn_init
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_dyn_init  ***
+      !!
+      !! ** Purpose : Physical constants and parameters linked to the ice
+      !!      dynamics
+      !!
+      !! ** Method  :  Read the namdyn namelist and check the ice-dynamic
+      !!       parameter values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namdyn
+      !!-------------------------------------------------------------------
+      INTEGER ::   ios, ioptio   ! Local integer output status for namelist read
+      !!
+      NAMELIST/namdyn/ ln_dynFULL, ln_dynRHGADV, ln_dynADV, rn_uice, rn_vice,  &
+         &             rn_ishlat  ,                                            &
+         &             ln_landfast, rn_gamma , rn_icebfr, rn_lfrelax
+      !!-------------------------------------------------------------------
+      !
+      REWIND( numnam_ice_ref )         ! Namelist namdyn in reference namelist : Ice dynamics
+      READ  ( numnam_ice_ref, namdyn, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn in reference namelist', lwp )
+      !
+      REWIND( numnam_ice_cfg )         ! Namelist namdyn in configuration namelist : Ice dynamics
+      READ  ( numnam_ice_cfg, namdyn, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namdyn )
+      !
+      IF(lwp) THEN                     ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_dyn_init: ice parameters for ice dynamics '
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namdyn:'
+         WRITE(numout,*) '      Full ice dynamics      (rhg + adv + ridge/raft + corr)  ln_dynFULL   = ', ln_dynFULL
+         WRITE(numout,*) '      No ridge/raft & No cor (rhg + adv)                      ln_dynRHGADV = ', ln_dynRHGADV
+         WRITE(numout,*) '      Advection only         (rn_uvice + adv)                 ln_dynADV    = ', ln_dynADV
+         WRITE(numout,*) '           with prescribed velocity given by '
+         WRITE(numout,*) '               a uniform field               (u,v)_ice = (rn_uice,rn_vice) = (', rn_uice,',', rn_vice,')'
+         WRITE(numout,*) '      lateral boundary condition for sea ice dynamics         rn_ishlat    = ', rn_ishlat
+         WRITE(numout,*) '      Landfast: param (T or F)                                ln_landfast  = ', ln_landfast
+         WRITE(numout,*) '         fraction of ocean depth that ice must reach          rn_gamma     = ', rn_gamma
+         WRITE(numout,*) '         maximum bottom stress per unit area of contact       rn_icebfr    = ', rn_icebfr
+         WRITE(numout,*) '         relax time scale (s-1) to reach static friction      rn_lfrelax   = ', rn_lfrelax
+      ENDIF
+      !                             !== set the choice of ice dynamics ==!
+      ioptio = 0 
+      !      !--- full dynamics                               (rheology + advection + ridging/rafting + correction)
+      IF( ln_dynFULL .AND. nn_monocat /= 2 ) THEN   ;   ioptio = ioptio + 1   ;   nice_dyn = np_dynFULL      ;   ENDIF
+      !      !--- dynamics without ridging/rafting            (rheology + advection                   + correction)
+      IF( ln_dynFULL .AND. nn_monocat == 2 ) THEN   ;   ioptio = ioptio + 1   ;   nice_dyn = np_dynRHGADV1   ;   ENDIF
+      !      !--- dynamics without ridging/rafting and corr   (rheology + advection)
+      IF( ln_dynRHGADV                     ) THEN   ;   ioptio = ioptio + 1   ;   nice_dyn = np_dynRHGADV2   ;   ENDIF
+      !      !--- advection only with prescribed ice velocities (from namelist)
+      IF( ln_dynADV                        ) THEN   ;   ioptio = ioptio + 1   ;   nice_dyn = np_dynADV       ;   ENDIF
+      !
+      IF( ioptio /= 1 )    CALL ctl_stop( 'ice_dyn_init: one and only one ice dynamics option has to be defined ' )
+      !
+      !                                      !--- Lateral boundary conditions
+      IF     (      rn_ishlat == 0.                ) THEN   ;   IF(lwp) WRITE(numout,*) '   ===>>>   ice lateral  free-slip'
+      ELSEIF (      rn_ishlat == 2.                ) THEN   ;   IF(lwp) WRITE(numout,*) '   ===>>>   ice lateral  no-slip'
+      ELSEIF ( 0. < rn_ishlat .AND. rn_ishlat < 2. ) THEN   ;   IF(lwp) WRITE(numout,*) '   ===>>>   ice lateral  partial-slip'
+      ELSEIF ( 2. < rn_ishlat                      ) THEN   ;   IF(lwp) WRITE(numout,*) '   ===>>>   ice lateral  strong-slip'
+      ENDIF
+      !                                      !--- NO Landfast ice : set to zero once for all
+      IF( .NOT. ln_landfast )   tau_icebfr(:,:) = 0._wp
+      !
+      CALL ice_dyn_rdgrft_init          ! set ice ridging/rafting parameters
+      CALL ice_dyn_rhg_init             ! set ice rheology parameters
+      CALL ice_dyn_adv_init             ! set ice advection parameters
+      !
+   END SUBROUTINE ice_dyn_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty module           NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif 
+
+   !!======================================================================
+END MODULE icedyn
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv.F90	(revision 9019)
@@ -0,0 +1,175 @@
+MODULE icedyn_adv
+   !!======================================================================
+   !!                       ***  MODULE icedyn_adv   ***
+   !!   ESIM : sea-ice advection
+   !!======================================================================
+   !! History : LIM-2 ! 2000-01 (M.A. Morales Maqueda, H. Goosse, and T. Fichefet)  Original code
+   !!            3.0  ! 2005-11 (M. Vancoppenolle)   Multi-layer sea ice, salinity variations
+   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_dyn_adv   : advection of sea ice variables
+   !!----------------------------------------------------------------------
+   USE phycst         ! physical constant
+   USE dom_oce        ! ocean domain
+   USE sbc_oce , ONLY : nn_fsbc   ! frequency of sea-ice call
+   USE ice            ! sea-ice: variables
+   USE icevar         ! sea-ice: operations
+   USE icedyn_adv_pra ! sea-ice: advection scheme (Prather)
+   USE icedyn_adv_umx ! sea-ice: advection scheme (ultimate-macho)
+   USE icectl         ! sea-ice: control prints
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE timing         ! Timing
+   USE prtctl         ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_dyn_adv        ! called by icestp
+   PUBLIC   ice_dyn_adv_init   ! called by icedyn
+
+   INTEGER ::              nice_adv   ! choice of the type of advection scheme
+   !                                        ! associated indices:
+   INTEGER, PARAMETER ::   np_advPRA = 1   ! Prather scheme
+   INTEGER, PARAMETER ::   np_advUMx = 2   ! Ultimate-Macho scheme
+   !
+   ! ** namelist (namdyn_adv) **
+   LOGICAL ::   ln_adv_Pra   ! Prather        advection scheme
+   LOGICAL ::   ln_adv_UMx   ! Ultimate-Macho advection scheme
+   INTEGER ::   nn_UMx       ! order of the UMx advection scheme   
+   !
+   !! * Substitution
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icedyn_adv.F90 8373 2017-07-25 17:44:54Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_dyn_adv( kt ) 
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_dyn_adv ***
+      !!                    
+      !! ** purpose : advection of sea ice
+      !!
+      !! ** method  : One can choose between 
+      !!     a) an Ultimate-Macho scheme (with order defined by nn_UMx) => ln_adv_UMx
+      !!     b) and a second order Prather scheme => ln_adv_Pra
+      !!
+      !! ** action :
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! number of iteration
+      !!---------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('icedyn_adv')
+      !
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_dyn_adv: sea-ice advection'
+         WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+      
+      ! conservation test
+      IF( ln_icediachk )   CALL ice_cons_hsm(0, 'icedyn_adv', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft)
+                     
+      !----------
+      ! Advection
+      !----------
+      SELECT CASE( nice_adv )
+      !                                !-----------------------!
+      CASE( np_advUMx )                ! ULTIMATE-MACHO scheme !
+         !                             !-----------------------!
+         CALL ice_dyn_adv_umx( nn_UMx, kt, u_ice, v_ice,  &
+            &                  ato_i, v_i, v_s, sv_i, oa_i, a_i, a_ip, v_ip, e_s, e_i )
+      !                                !-----------------------!
+      CASE( np_advPRA )                ! PRATHER scheme        !
+         !                             !-----------------------!
+         CALL ice_dyn_adv_pra( kt, u_ice, v_ice,  &
+            &                  ato_i, v_i, v_s, sv_i, oa_i, a_i, a_ip, v_ip, e_s, e_i )
+      END SELECT
+
+      !------------
+      ! diagnostics
+      !------------
+      diag_trp_ei(:,:) = SUM(SUM( e_i (:,:,1:nlay_i,:) - e_i_b (:,:,1:nlay_i,:), dim=4 ), dim=3 ) * r1_rdtice
+      diag_trp_es(:,:) = SUM(SUM( e_s (:,:,1:nlay_s,:) - e_s_b (:,:,1:nlay_s,:), dim=4 ), dim=3 ) * r1_rdtice
+      diag_trp_sv(:,:) = SUM(     sv_i(:,:,:)          - sv_i_b(:,:,:)                  , dim=3 ) * r1_rdtice
+      diag_trp_vi(:,:) = SUM(     v_i (:,:,:)          - v_i_b (:,:,:)                  , dim=3 ) * r1_rdtice
+      diag_trp_vs(:,:) = SUM(     v_s (:,:,:)          - v_s_b (:,:,:)                  , dim=3 ) * r1_rdtice
+      IF( iom_use('icemtrp') )   CALL iom_put( "icemtrp" , diag_trp_vi * rhoic          )   ! ice mass transport
+      IF( iom_use('snwmtrp') )   CALL iom_put( "snwmtrp" , diag_trp_vs * rhosn          )   ! snw mass transport
+      IF( iom_use('salmtrp') )   CALL iom_put( "salmtrp" , diag_trp_sv * rhoic * 1.e-03 )   ! salt mass transport (kg/m2/s)
+      IF( iom_use('dihctrp') )   CALL iom_put( "dihctrp" , -diag_trp_ei                 )   ! advected ice heat content (W/m2)
+      IF( iom_use('dshctrp') )   CALL iom_put( "dshctrp" , -diag_trp_es                 )   ! advected snw heat content (W/m2)
+
+      ! controls
+      IF( ln_icediachk   )   CALL ice_cons_hsm(1, 'icedyn_adv', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
+      IF( ln_icectl      )   CALL ice_prt     (kt, iiceprt, jiceprt,-1, ' - ice dyn & trp - ')                           ! prints
+      IF( nn_timing == 1 )   CALL timing_stop ('icedyn_adv')                                                             ! timing
+      !
+   END SUBROUTINE ice_dyn_adv
+
+
+   SUBROUTINE ice_dyn_adv_init
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_dyn_adv_init  ***
+      !!
+      !! ** Purpose :   Physical constants and parameters linked to the ice
+      !!                dynamics
+      !!
+      !! ** Method  :   Read the namdyn_adv namelist and check the ice-dynamic
+      !!                parameter values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namdyn_adv
+      !!-------------------------------------------------------------------
+      INTEGER ::   ios, ioptio   ! Local integer output status for namelist read
+      !!
+      NAMELIST/namdyn_adv/ ln_adv_Pra, ln_adv_UMx, nn_UMx
+      !!-------------------------------------------------------------------
+      !
+      REWIND( numnam_ice_ref )         ! Namelist namdyn_adv in reference namelist : Ice dynamics
+      READ  ( numnam_ice_ref, namdyn_adv, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn_adv in reference namelist', lwp )
+      !
+      REWIND( numnam_ice_cfg )         ! Namelist namdyn_adv in configuration namelist : Ice dynamics
+      READ  ( numnam_ice_cfg, namdyn_adv, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn_adv in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namdyn_adv )
+      !
+      IF(lwp) THEN                     ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_dyn_adv_init: ice parameters for ice dynamics '
+         WRITE(numout,*) '~~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namdyn_adv:'
+         WRITE(numout,*) '      type of advection scheme (Prather)             ln_adv_Pra = ', ln_adv_Pra 
+         WRITE(numout,*) '      type of advection scheme (Ulimate-Macho)       ln_adv_UMx = ', ln_adv_UMx 
+         WRITE(numout,*) '         order of the Ultimate-Macho scheme          nn_UMx     = ', nn_UMx
+      ENDIF
+      !
+      !                             !== set the choice of ice advection ==!
+      ioptio = 0 
+      IF( ln_adv_Pra ) THEN   ;   ioptio = ioptio + 1   ;   nice_adv = np_advPRA    ;   ENDIF
+      IF( ln_adv_UMx ) THEN   ;   ioptio = ioptio + 1   ;   nice_adv = np_advUMx    ;   ENDIF
+      IF( ioptio /= 1 )   CALL ctl_stop( 'ice_dyn_adv_init: choose one and only one ice adv. scheme (ln_adv_Pra or ln_adv_UMx)' )
+      !
+      IF( ln_adv_Pra )   CALL adv_pra_init  !* read or initialize all required files
+      !
+   END SUBROUTINE ice_dyn_adv_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty Module           NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icedyn_adv
+
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv_pra.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv_pra.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv_pra.F90	(revision 9019)
@@ -0,0 +1,844 @@
+MODULE icedyn_adv_pra 
+   !!======================================================================
+   !!                       ***  MODULE icedyn_adv_pra   ***
+   !!   sea-ice : advection => Prather scheme
+   !!======================================================================
+   !! History :  LIM  ! 2008-03 (M. Vancoppenolle)  LIM-3 from LIM-2 code
+   !!            3.2  ! 2009-06 (F. Dupont)  correct a error in the North fold b.c.
+   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!--------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_dyn_adv_pra : advection of sea ice using Prather scheme
+   !!   adv_x, adv_y    : Prather scheme applied in i- and j-direction, resp.
+   !!   adv_pra_init    : initialisation of the Prather scheme
+   !!   adv_pra_rst     : read/write Prather field in ice restart file, or initialized to zero
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean domain
+   USE ice            ! sea-ice variables
+   USE sbc_oce , ONLY : nn_fsbc   ! frequency of sea-ice call
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE lbclnk         ! lateral boundary conditions (or mpp links)
+   USE prtctl         ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_dyn_adv_pra   ! called by icedyn_adv
+   PUBLIC   adv_pra_init      ! called by icedyn_adv
+
+   ! Moments for advection
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxice, syice, sxxice, syyice, sxyice   ! ice thickness 
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxsn , sysn , sxxsn , syysn , sxysn    ! snow thickness
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxa  , sya  , sxxa  , syya  , sxya     ! lead fraction
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxc0 , syc0 , sxxc0 , syyc0 , sxyc0    ! snow thermal content
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxsal, sysal, sxxsal, syysal, sxysal   ! ice salinity
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxage, syage, sxxage, syyage, sxyage   ! ice age
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   sxopw, syopw, sxxopw, syyopw, sxyopw   ! open water in sea ice
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   sxe  , sye  , sxxe  , syye  , sxye     ! ice layers heat content
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxap , syap , sxxap , syyap , sxyap    ! melt pond fraction
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   sxvp , syvp , sxxvp , syyvp , sxyvp    ! melt pond volume
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icedyn_adv_pra.F90 6746 2016-06-27 17:20:57Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_dyn_adv_pra( kt, pu_ice, pv_ice,  &
+      &                        pato_i, pv_i, pv_s, psv_i, poa_i, pa_i, pa_ip, pv_ip, pe_s, pe_i )
+      !!----------------------------------------------------------------------
+      !!                **  routine ice_dyn_adv_pra  **
+      !!  
+      !! ** purpose :   Computes and adds the advection trend to sea-ice
+      !!
+      !! ** method  :   Uses Prather second order scheme that advects tracers
+      !!                but also their quadratic forms. The method preserves
+      !!                tracer structures by conserving second order moments.
+      !!
+      !! Reference:  Prather, 1986, JGR, 91, D6. 6671-6681.
+      !!----------------------------------------------------------------------
+      INTEGER                     , INTENT(in   ) ::   kt         ! time step
+      REAL(wp), DIMENSION(:,:)    , INTENT(in   ) ::   pu_ice     ! ice i-velocity
+      REAL(wp), DIMENSION(:,:)    , INTENT(in   ) ::   pv_ice     ! ice j-velocity
+      REAL(wp), DIMENSION(:,:)    , INTENT(inout) ::   pato_i     ! open water area
+      REAL(wp), DIMENSION(:,:,:)  , INTENT(inout) ::   pv_i       ! ice volume
+      REAL(wp), DIMENSION(:,:,:)  , INTENT(inout) ::   pv_s       ! snw volume
+      REAL(wp), DIMENSION(:,:,:)  , INTENT(inout) ::   psv_i      ! salt content
+      REAL(wp), DIMENSION(:,:,:)  , INTENT(inout) ::   poa_i      ! age content
+      REAL(wp), DIMENSION(:,:,:)  , INTENT(inout) ::   pa_i       ! ice concentration
+      REAL(wp), DIMENSION(:,:,:)  , INTENT(inout) ::   pa_ip      ! melt pond fraction
+      REAL(wp), DIMENSION(:,:,:)  , INTENT(inout) ::   pv_ip      ! melt pond volume
+      REAL(wp), DIMENSION(:,:,:,:), INTENT(inout) ::   pe_s       ! snw heat content
+      REAL(wp), DIMENSION(:,:,:,:), INTENT(inout) ::   pe_i       ! ice heat content
+      !
+      INTEGER  ::   jk, jl, jt              ! dummy loop indices
+      INTEGER  ::   initad                  ! number of sub-timestep for the advection
+      REAL(wp) ::   zcfl , zusnit           !   -      -
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:)     ::   zarea
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::   z0opw
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::   z0ice, z0snw, z0ai, z0es , z0smi , z0oi
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::   z0ap , z0vp
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) ::   z0ei
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nit000 .AND. lwp )   WRITE(numout,*) '-- ice_dyn_adv_pra: Prather advection scheme'
+      !
+      ALLOCATE( zarea(jpi,jpj)     , z0opw(jpi,jpj, 1 ) ,                                           &
+         &      z0ice(jpi,jpj,jpl) , z0snw(jpi,jpj,jpl) , z0ai(jpi,jpj,jpl) , z0es(jpi,jpj,jpl) ,   &
+         &      z0smi(jpi,jpj,jpl) , z0oi (jpi,jpj,jpl) , z0ap(jpi,jpj,jpl) , z0vp(jpi,jpj,jpl) ,   &
+         &      z0ei (jpi,jpj,nlay_i,jpl)                                                           )
+      !
+      ! --- If ice drift field is too fast, use an appropriate time step for advection (CFL test for stability) --- !        
+      zcfl  =            MAXVAL( ABS( pu_ice(:,:) ) * rdt_ice * r1_e1u(:,:) )
+      zcfl  = MAX( zcfl, MAXVAL( ABS( pv_ice(:,:) ) * rdt_ice * r1_e2v(:,:) ) )
+      IF( lk_mpp )   CALL mpp_max( zcfl )
+      
+      IF( zcfl > 0.5 ) THEN   ;   initad = 2   ;   zusnit = 0.5_wp
+      ELSE                    ;   initad = 1   ;   zusnit = 1.0_wp
+      ENDIF
+      
+      zarea(:,:) = e1e2t(:,:)
+      !-------------------------
+      ! transported fields                                        
+      !-------------------------
+      z0opw(:,:,1) = pato_i(:,:) * e1e2t(:,:)              ! Open water area 
+      DO jl = 1, jpl
+         z0snw(:,:,jl) = pv_s (:,:,  jl) * e1e2t(:,:)     ! Snow volume
+         z0ice(:,:,jl) = pv_i (:,:,  jl) * e1e2t(:,:)     ! Ice  volume
+         z0ai (:,:,jl) = pa_i (:,:,  jl) * e1e2t(:,:)     ! Ice area
+         z0smi(:,:,jl) = psv_i(:,:,  jl) * e1e2t(:,:)     ! Salt content
+         z0oi (:,:,jl) = poa_i(:,:,  jl) * e1e2t(:,:)     ! Age content
+         z0es (:,:,jl) = pe_s (:,:,1,jl) * e1e2t(:,:)     ! Snow heat content
+         DO jk = 1, nlay_i
+            z0ei(:,:,jk,jl) = pe_i(:,:,jk,jl) * e1e2t(:,:) ! Ice  heat content
+         END DO
+         IF ( ln_pnd_H12 ) THEN
+            z0ap(:,:,jl)  = pa_ip(:,:,jl) * e1e2t(:,:)     ! Melt pond fraction
+            z0vp(:,:,jl)  = pv_ip(:,:,jl) * e1e2t(:,:)     ! Melt pond volume
+         ENDIF
+      END DO
+
+      !                                                    !--------------------------------------------!
+      IF( MOD( ( kt - 1) / nn_fsbc , 2 ) == 0 ) THEN       !==  odd ice time step:  adv_x then adv_y  ==!
+         !                                                 !--------------------------------------------!
+         DO jt = 1, initad
+            CALL adv_x( zusnit, pu_ice, 1._wp, zarea, z0opw (:,:,1), sxopw(:,:),   &             !--- ice open water area
+               &                                      sxxopw(:,:)  , syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
+            CALL adv_y( zusnit, pv_ice, 0._wp, zarea, z0opw (:,:,1), sxopw(:,:),   &
+               &                                      sxxopw(:,:)  , syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
+            DO jl = 1, jpl
+               CALL adv_x( zusnit, pu_ice, 1._wp, zarea, z0ice (:,:,jl), sxice(:,:,jl),   &    !--- ice volume  ---
+                  &                                      sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
+               CALL adv_y( zusnit, pv_ice, 0._wp, zarea, z0ice (:,:,jl), sxice(:,:,jl),   &
+                  &                                      sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
+               CALL adv_x( zusnit, pu_ice, 1._wp, zarea, z0snw (:,:,jl), sxsn (:,:,jl),   &    !--- snow volume  ---
+                  &                                      sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
+               CALL adv_y( zusnit, pv_ice, 0._wp, zarea, z0snw (:,:,jl), sxsn (:,:,jl),   &
+                  &                                      sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
+               CALL adv_x( zusnit, pu_ice, 1._wp, zarea, z0smi (:,:,jl), sxsal(:,:,jl),   &    !--- ice salinity ---
+                  &                                      sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
+               CALL adv_y( zusnit, pv_ice, 0._wp, zarea, z0smi (:,:,jl), sxsal(:,:,jl),   &
+                  &                                      sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
+               CALL adv_x( zusnit, pu_ice, 1._wp, zarea, z0oi  (:,:,jl), sxage(:,:,jl),   &    !--- ice age      ---     
+                  &                                      sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
+               CALL adv_y( zusnit, pv_ice, 0._wp, zarea, z0oi  (:,:,jl), sxage(:,:,jl),   &
+                  &                                      sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
+               CALL adv_x( zusnit, pu_ice, 1._wp, zarea, z0ai  (:,:,jl), sxa  (:,:,jl),   &    !--- ice concentrations ---
+                  &                                      sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
+               CALL adv_y( zusnit, pv_ice, 0._wp, zarea, z0ai  (:,:,jl), sxa  (:,:,jl),   & 
+                  &                                      sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
+               CALL adv_x( zusnit, pu_ice, 1._wp, zarea, z0es  (:,:,jl), sxc0 (:,:,jl),   &    !--- snow heat contents ---
+                  &                                      sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
+               CALL adv_y( zusnit, pv_ice, 0._wp, zarea, z0es  (:,:,jl), sxc0 (:,:,jl),   &
+                  &                                      sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
+               DO jk = 1, nlay_i                                                               !--- ice heat contents ---
+                  CALL adv_x( zusnit, pu_ice, 1._wp, zarea, z0ei(:,:,jk,jl), sxe (:,:,jk,jl),   & 
+                     &                                      sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
+                     &                                      syye(:,:,jk,jl), sxye(:,:,jk,jl) )
+                  CALL adv_y( zusnit, pv_ice, 0._wp, zarea, z0ei(:,:,jk,jl), sxe (:,:,jk,jl),   & 
+                     &                                      sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
+                     &                                      syye(:,:,jk,jl), sxye(:,:,jk,jl) )
+               END DO
+               IF ( ln_pnd_H12 ) THEN
+                  CALL adv_x( zusnit, pu_ice, 1._wp, zarea, z0ap  (:,:,jl), sxap (:,:,jl),   &    !--- melt pond fraction --
+                     &                                      sxxap (:,:,jl), syap (:,:,jl), syyap (:,:,jl), sxyap (:,:,jl)  )
+                  CALL adv_y( zusnit, pv_ice, 0._wp, zarea, z0ap  (:,:,jl), sxap (:,:,jl),   & 
+                     &                                      sxxap (:,:,jl), syap (:,:,jl), syyap (:,:,jl), sxyap (:,:,jl)  )
+                  CALL adv_x( zusnit, pu_ice, 1._wp, zarea, z0vp  (:,:,jl), sxvp (:,:,jl),   &    !--- melt pond volume   --
+                     &                                      sxxvp (:,:,jl), syvp (:,:,jl), syyvp (:,:,jl), sxyvp (:,:,jl)  )
+                  CALL adv_y( zusnit, pv_ice, 0._wp, zarea, z0vp  (:,:,jl), sxvp (:,:,jl),   & 
+                     &                                      sxxvp (:,:,jl), syvp (:,:,jl), syyvp (:,:,jl), sxyvp (:,:,jl)  )
+               ENDIF
+            END DO
+         END DO
+      !                                                    !--------------------------------------------!
+      ELSE                                                 !== even ice time step:  adv_y then adv_x  ==!
+         !                                                 !--------------------------------------------!
+         DO jt = 1, initad
+            CALL adv_y( zusnit, pv_ice, 1._wp, zarea, z0opw (:,:,1), sxopw(:,:),   &             !--- ice open water area
+               &                                      sxxopw(:,:)  , syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
+            CALL adv_x( zusnit, pu_ice, 0._wp, zarea, z0opw (:,:,1), sxopw(:,:),   &
+               &                                      sxxopw(:,:)  , syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
+            DO jl = 1, jpl
+               CALL adv_y( zusnit, pv_ice, 1._wp, zarea, z0ice (:,:,jl), sxice(:,:,jl),   &    !--- ice volume  ---
+                  &                                      sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
+               CALL adv_x( zusnit, pu_ice, 0._wp, zarea, z0ice (:,:,jl), sxice(:,:,jl),   &
+                  &                                      sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
+               CALL adv_y( zusnit, pv_ice, 1._wp, zarea, z0snw (:,:,jl), sxsn (:,:,jl),   &    !--- snow volume  ---
+                  &                                      sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
+               CALL adv_x( zusnit, pu_ice, 0._wp, zarea, z0snw (:,:,jl), sxsn (:,:,jl),   &
+                  &                                      sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
+               CALL adv_y( zusnit, pv_ice, 1._wp, zarea, z0smi (:,:,jl), sxsal(:,:,jl),   &    !--- ice salinity ---
+                  &                                      sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
+               CALL adv_x( zusnit, pu_ice, 0._wp, zarea, z0smi (:,:,jl), sxsal(:,:,jl),   &
+                  &                                      sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
+               CALL adv_y( zusnit, pv_ice, 1._wp, zarea, z0oi  (:,:,jl), sxage(:,:,jl),   &   !--- ice age      ---
+                  &                                      sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
+               CALL adv_x( zusnit, pu_ice, 0._wp, zarea, z0oi  (:,:,jl), sxage(:,:,jl),   &
+                  &                                      sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
+               CALL adv_y( zusnit, pv_ice, 1._wp, zarea, z0ai  (:,:,jl), sxa  (:,:,jl),   &   !--- ice concentrations ---
+                  &                                      sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
+               CALL adv_x( zusnit, pu_ice, 0._wp, zarea, z0ai  (:,:,jl), sxa  (:,:,jl),   &
+                  &                                      sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
+               CALL adv_y( zusnit, pv_ice, 1._wp, zarea, z0es  (:,:,jl), sxc0 (:,:,jl),   &  !--- snow heat contents ---
+                  &                                      sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
+               CALL adv_x( zusnit, pu_ice, 0._wp, zarea, z0es  (:,:,jl), sxc0 (:,:,jl),   &
+                  &                                      sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
+               DO jk = 1, nlay_i                                                             !--- ice heat contents ---
+                  CALL adv_y( zusnit, pv_ice, 1._wp, zarea, z0ei(:,:,jk,jl), sxe (:,:,jk,jl),   & 
+                     &                                      sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
+                     &                                      syye(:,:,jk,jl), sxye(:,:,jk,jl) )
+                  CALL adv_x( zusnit, pu_ice, 0._wp, zarea, z0ei(:,:,jk,jl), sxe (:,:,jk,jl),   & 
+                     &                                      sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
+                     &                                      syye(:,:,jk,jl), sxye(:,:,jk,jl) )
+               END DO
+               IF ( ln_pnd_H12 ) THEN
+                  CALL adv_y( zusnit, pv_ice, 1._wp, zarea, z0ap  (:,:,jl), sxap (:,:,jl),   &   !--- melt pond fraction ---
+                     &                                      sxxap (:,:,jl), syap (:,:,jl), syyap (:,:,jl), sxyap (:,:,jl)  )
+                  CALL adv_x( zusnit, pu_ice, 0._wp, zarea, z0ap  (:,:,jl), sxap (:,:,jl),   &
+                     &                                      sxxap (:,:,jl), syap (:,:,jl), syyap (:,:,jl), sxyap (:,:,jl)  )
+                  CALL adv_y( zusnit, pv_ice, 1._wp, zarea, z0vp  (:,:,jl), sxvp (:,:,jl),   &   !--- melt pond volume   ---
+                     &                                      sxxvp (:,:,jl), syvp (:,:,jl), syyvp (:,:,jl), sxyvp (:,:,jl)  )
+                  CALL adv_x( zusnit, pu_ice, 0._wp, zarea, z0vp  (:,:,jl), sxvp (:,:,jl),   &
+                     &                                      sxxvp (:,:,jl), syvp (:,:,jl), syyvp (:,:,jl), sxyvp (:,:,jl)  )
+               ENDIF
+            END DO
+         END DO
+      ENDIF
+
+      !-------------------------------------------
+      ! Recover the properties from their contents
+      !-------------------------------------------
+      pato_i(:,:) = z0opw(:,:,1) * r1_e1e2t(:,:)
+      DO jl = 1, jpl
+         pv_i (:,:,  jl) = z0ice(:,:,jl) * r1_e1e2t(:,:)
+         pv_s (:,:,  jl) = z0snw(:,:,jl) * r1_e1e2t(:,:)
+         psv_i(:,:,  jl) = z0smi(:,:,jl) * r1_e1e2t(:,:)
+         poa_i(:,:,  jl) = z0oi (:,:,jl) * r1_e1e2t(:,:)
+         pa_i (:,:,  jl) = z0ai (:,:,jl) * r1_e1e2t(:,:)
+         pe_s (:,:,1,jl) = z0es (:,:,jl) * r1_e1e2t(:,:)
+         DO jk = 1, nlay_i
+            pe_i(:,:,jk,jl) = z0ei(:,:,jk,jl) * r1_e1e2t(:,:)
+         END DO
+         IF ( ln_pnd_H12 ) THEN
+            pa_ip  (:,:,jl) = z0ap (:,:,jl) * r1_e1e2t(:,:)
+            pv_ip  (:,:,jl) = z0vp (:,:,jl) * r1_e1e2t(:,:)
+         ENDIF
+      END DO
+      !
+      DEALLOCATE( zarea , z0opw , z0ice, z0snw , z0ai , z0es , z0smi , z0oi , z0ap , z0vp , z0ei )
+      !
+      IF( lrst_ice )   CALL adv_pra_rst( 'WRITE', kt )   !* write Prather fields in the restart file
+      !
+   END SUBROUTINE ice_dyn_adv_pra
+   
+   
+   SUBROUTINE adv_x( pdf, put , pcrh, psm , ps0 ,   &
+      &              psx, psxx, psy , psyy, psxy )
+      !!----------------------------------------------------------------------
+      !!                **  routine adv_x  **
+      !!  
+      !! ** purpose :   Computes and adds the advection trend to sea-ice
+      !!                variable on x axis
+      !!----------------------------------------------------------------------
+      REAL(wp)                    , INTENT(in   ) ::   pdf                ! reduction factor for the time step
+      REAL(wp)                    , INTENT(in   ) ::   pcrh               ! call adv_x then adv_y (=1) or the opposite (=0)
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   put                ! i-direction ice velocity at U-point [m/s]
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psm                ! area
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ps0                ! field to be advected
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psx , psy          ! 1st moments 
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psxx, psyy, psxy   ! 2nd moments
+      !! 
+      INTEGER  ::   ji, jj                               ! dummy loop indices
+      REAL(wp) ::   zs1max, zrdt, zslpmax, ztemp         ! local scalars
+      REAL(wp) ::   zs1new, zalf , zalfq , zbt           !   -      -
+      REAL(wp) ::   zs2new, zalf1, zalf1q, zbt1          !   -      -
+      REAL(wp), DIMENSION(jpi,jpj) ::   zf0 , zfx  , zfy   , zbet   ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj) ::   zfm , zfxx , zfyy  , zfxy   !  -      -
+      REAL(wp), DIMENSION(jpi,jpj) ::   zalg, zalg1, zalg1q         !  -      -
+      !-----------------------------------------------------------------------
+
+      ! Limitation of moments.                                           
+
+      zrdt = rdt_ice * pdf      ! If ice drift field is too fast, use an appropriate time step for advection.
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zslpmax = MAX( 0._wp, ps0(ji,jj) )
+            zs1max  = 1.5 * zslpmax
+            zs1new  = MIN( zs1max, MAX( -zs1max, psx(ji,jj) ) )
+            zs2new  = MIN(  2.0 * zslpmax - 0.3334 * ABS( zs1new ),      &
+               &            MAX( ABS( zs1new ) - zslpmax, psxx(ji,jj) )  )
+            rswitch = ( 1.0 - MAX( 0._wp, SIGN( 1._wp, -zslpmax) ) ) * tmask(ji,jj,1)   ! Case of empty boxes & Apply mask
+
+            ps0 (ji,jj) = zslpmax  
+            psx (ji,jj) = zs1new      * rswitch
+            psxx(ji,jj) = zs2new      * rswitch
+            psy (ji,jj) = psy (ji,jj) * rswitch
+            psyy(ji,jj) = psyy(ji,jj) * rswitch
+            psxy(ji,jj) = MIN( zslpmax, MAX( -zslpmax, psxy(ji,jj) ) ) * rswitch
+         END DO
+      END DO
+
+      !  Initialize volumes of boxes  (=area if adv_x first called, =psm otherwise)                                     
+      psm (:,:)  = MAX( pcrh * e1e2t(:,:) + ( 1.0 - pcrh ) * psm(:,:) , epsi20 )
+
+      !  Calculate fluxes and moments between boxes i<-->i+1              
+      DO jj = 1, jpj                      !  Flux from i to i+1 WHEN u GT 0 
+         DO ji = 1, jpi
+            zbet(ji,jj)  =  MAX( 0._wp, SIGN( 1._wp, put(ji,jj) ) )
+            zalf         =  MAX( 0._wp, put(ji,jj) ) * zrdt * e2u(ji,jj) / psm(ji,jj)
+            zalfq        =  zalf * zalf
+            zalf1        =  1.0 - zalf
+            zalf1q       =  zalf1 * zalf1
+            !
+            zfm (ji,jj)  =  zalf  *   psm (ji,jj)
+            zf0 (ji,jj)  =  zalf  * ( ps0 (ji,jj) + zalf1 * ( psx(ji,jj) + (zalf1 - zalf) * psxx(ji,jj) )  )
+            zfx (ji,jj)  =  zalfq * ( psx (ji,jj) + 3.0 * zalf1 * psxx(ji,jj) )
+            zfxx(ji,jj)  =  zalf  *   psxx(ji,jj) * zalfq
+            zfy (ji,jj)  =  zalf  * ( psy (ji,jj) + zalf1 * psxy(ji,jj) )
+            zfxy(ji,jj)  =  zalfq *   psxy(ji,jj)
+            zfyy(ji,jj)  =  zalf  *   psyy(ji,jj)
+
+            !  Readjust moments remaining in the box.
+            psm (ji,jj)  =  psm (ji,jj) - zfm(ji,jj)
+            ps0 (ji,jj)  =  ps0 (ji,jj) - zf0(ji,jj)
+            psx (ji,jj)  =  zalf1q * ( psx(ji,jj) - 3.0 * zalf * psxx(ji,jj) )
+            psxx(ji,jj)  =  zalf1  * zalf1q * psxx(ji,jj)
+            psy (ji,jj)  =  psy (ji,jj) - zfy(ji,jj)
+            psyy(ji,jj)  =  psyy(ji,jj) - zfyy(ji,jj)
+            psxy(ji,jj)  =  zalf1q * psxy(ji,jj)
+         END DO
+      END DO
+
+      DO jj = 1, jpjm1                      !  Flux from i+1 to i when u LT 0.
+         DO ji = 1, fs_jpim1
+            zalf          = MAX( 0._wp, -put(ji,jj) ) * zrdt * e2u(ji,jj) / psm(ji+1,jj) 
+            zalg  (ji,jj) = zalf
+            zalfq         = zalf * zalf
+            zalf1         = 1.0 - zalf
+            zalg1 (ji,jj) = zalf1
+            zalf1q        = zalf1 * zalf1
+            zalg1q(ji,jj) = zalf1q
+            !
+            zfm   (ji,jj) = zfm (ji,jj) + zalf  *   psm (ji+1,jj)
+            zf0   (ji,jj) = zf0 (ji,jj) + zalf  * ( ps0 (ji+1,jj) - zalf1 * ( psx(ji+1,jj) - (zalf1 - zalf ) * psxx(ji+1,jj) ) )
+            zfx   (ji,jj) = zfx (ji,jj) + zalfq * ( psx (ji+1,jj) - 3.0 * zalf1 * psxx(ji+1,jj) )
+            zfxx  (ji,jj) = zfxx(ji,jj) + zalf  *   psxx(ji+1,jj) * zalfq
+            zfy   (ji,jj) = zfy (ji,jj) + zalf  * ( psy (ji+1,jj) - zalf1 * psxy(ji+1,jj) )
+            zfxy  (ji,jj) = zfxy(ji,jj) + zalfq *   psxy(ji+1,jj)
+            zfyy  (ji,jj) = zfyy(ji,jj) + zalf  *   psyy(ji+1,jj)
+         END DO
+      END DO
+
+      DO jj = 2, jpjm1                     !  Readjust moments remaining in the box. 
+         DO ji = fs_2, fs_jpim1
+            zbt  =       zbet(ji-1,jj)
+            zbt1 = 1.0 - zbet(ji-1,jj)
+            !
+            psm (ji,jj) = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) - zfm(ji-1,jj) )
+            ps0 (ji,jj) = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) - zf0(ji-1,jj) )
+            psx (ji,jj) = zalg1q(ji-1,jj) * ( psx(ji,jj) + 3.0 * zalg(ji-1,jj) * psxx(ji,jj) )
+            psxx(ji,jj) = zalg1 (ji-1,jj) * zalg1q(ji-1,jj) * psxx(ji,jj)
+            psy (ji,jj) = zbt * psy (ji,jj) + zbt1 * ( psy (ji,jj) - zfy (ji-1,jj) )
+            psyy(ji,jj) = zbt * psyy(ji,jj) + zbt1 * ( psyy(ji,jj) - zfyy(ji-1,jj) )
+            psxy(ji,jj) = zalg1q(ji-1,jj) * psxy(ji,jj)
+         END DO
+      END DO
+
+      !   Put the temporary moments into appropriate neighboring boxes.    
+      DO jj = 2, jpjm1                     !   Flux from i to i+1 IF u GT 0.
+         DO ji = fs_2, fs_jpim1
+            zbt  =       zbet(ji-1,jj)
+            zbt1 = 1.0 - zbet(ji-1,jj)
+            psm(ji,jj)  = zbt * ( psm(ji,jj) + zfm(ji-1,jj) ) + zbt1 * psm(ji,jj)
+            zalf        = zbt * zfm(ji-1,jj) / psm(ji,jj)
+            zalf1       = 1.0 - zalf
+            ztemp       = zalf * ps0(ji,jj) - zalf1 * zf0(ji-1,jj)
+            !
+            ps0 (ji,jj) = zbt * ( ps0(ji,jj) + zf0(ji-1,jj) ) + zbt1 * ps0(ji,jj)
+            psx (ji,jj) = zbt * ( zalf * zfx(ji-1,jj) + zalf1 * psx(ji,jj) + 3.0 * ztemp ) + zbt1 * psx(ji,jj)
+            psxx(ji,jj) = zbt * ( zalf * zalf * zfxx(ji-1,jj) + zalf1 * zalf1 * psxx(ji,jj)                               &
+               &                + 5.0 * ( zalf * zalf1 * ( psx (ji,jj) - zfx(ji-1,jj) ) - ( zalf1 - zalf ) * ztemp )  )   &
+               &                                                + zbt1 * psxx(ji,jj)
+            psxy(ji,jj) = zbt * ( zalf * zfxy(ji-1,jj) + zalf1 * psxy(ji,jj)             &
+               &                + 3.0 * (- zalf1*zfy(ji-1,jj)  + zalf * psy(ji,jj) ) )   &
+               &                                                + zbt1 * psxy(ji,jj)
+            psy (ji,jj) = zbt * ( psy (ji,jj) + zfy (ji-1,jj) ) + zbt1 * psy (ji,jj)
+            psyy(ji,jj) = zbt * ( psyy(ji,jj) + zfyy(ji-1,jj) ) + zbt1 * psyy(ji,jj)
+         END DO
+      END DO
+
+      DO jj = 2, jpjm1                     !  Flux from i+1 to i IF u LT 0.
+         DO ji = fs_2, fs_jpim1
+            zbt  =       zbet(ji,jj)
+            zbt1 = 1.0 - zbet(ji,jj)
+            psm(ji,jj)  = zbt * psm(ji,jj)  + zbt1 * ( psm(ji,jj) + zfm(ji,jj) )
+            zalf        = zbt1 * zfm(ji,jj) / psm(ji,jj)
+            zalf1       = 1.0 - zalf
+            ztemp       = - zalf * ps0(ji,jj) + zalf1 * zf0(ji,jj)
+            !
+            ps0(ji,jj)  = zbt * ps0 (ji,jj) + zbt1 * ( ps0(ji,jj) + zf0(ji,jj) )
+            psx(ji,jj)  = zbt * psx (ji,jj) + zbt1 * ( zalf * zfx(ji,jj) + zalf1 * psx(ji,jj) + 3.0 * ztemp )
+            psxx(ji,jj) = zbt * psxx(ji,jj) + zbt1 * ( zalf * zalf * zfxx(ji,jj)  + zalf1 * zalf1 * psxx(ji,jj)  &
+               &                                      + 5.0 *( zalf * zalf1 * ( - psx(ji,jj) + zfx(ji,jj) )      &
+               &                                      + ( zalf1 - zalf ) * ztemp ) )
+            psxy(ji,jj) = zbt * psxy(ji,jj) + zbt1 * (  zalf * zfxy(ji,jj) + zalf1 * psxy(ji,jj)  &
+               &                                      + 3.0 * ( zalf1 * zfy(ji,jj) - zalf * psy(ji,jj) )  )
+            psy(ji,jj)  = zbt * psy (ji,jj)  + zbt1 * ( psy (ji,jj) + zfy (ji,jj) )
+            psyy(ji,jj) = zbt * psyy(ji,jj)  + zbt1 * ( psyy(ji,jj) + zfyy(ji,jj) )
+         END DO
+      END DO
+
+      !-- Lateral boundary conditions
+      CALL lbc_lnk_multi( psm , 'T',  1., ps0 , 'T',  1.   &
+         &              , psx , 'T', -1., psy , 'T', -1.   &   ! caution gradient ==> the sign changes
+         &              , psxx, 'T',  1., psyy, 'T',  1.   &
+         &              , psxy, 'T',  1. )
+
+      IF(ln_ctl) THEN
+         CALL prt_ctl(tab2d_1=psm  , clinfo1=' adv_x: psm  :', tab2d_2=ps0 , clinfo2=' ps0  : ')
+         CALL prt_ctl(tab2d_1=psx  , clinfo1=' adv_x: psx  :', tab2d_2=psxx, clinfo2=' psxx : ')
+         CALL prt_ctl(tab2d_1=psy  , clinfo1=' adv_x: psy  :', tab2d_2=psyy, clinfo2=' psyy : ')
+         CALL prt_ctl(tab2d_1=psxy , clinfo1=' adv_x: psxy :')
+      ENDIF
+      !
+   END SUBROUTINE adv_x
+
+
+   SUBROUTINE adv_y( pdf, pvt , pcrh, psm , ps0 ,   &
+      &              psx, psxx, psy , psyy, psxy )
+      !!---------------------------------------------------------------------
+      !!                **  routine adv_y  **
+      !!            
+      !! ** purpose :   Computes and adds the advection trend to sea-ice 
+      !!                variable on y axis
+      !!---------------------------------------------------------------------
+      REAL(wp)                    , INTENT(in   ) ::   pdf                ! reduction factor for the time step
+      REAL(wp)                    , INTENT(in   ) ::   pcrh               ! call adv_x then adv_y (=1) or the opposite (=0)
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pvt                ! j-direction ice velocity at V-point [m/s]
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psm                ! area
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ps0                ! field to be advected
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psx , psy          ! 1st moments 
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psxx, psyy, psxy   ! 2nd moments
+      !!
+      INTEGER  ::   ji, jj                               ! dummy loop indices
+      REAL(wp) ::   zs1max, zrdt, zslpmax, ztemp         ! temporary scalars
+      REAL(wp) ::   zs1new, zalf , zalfq , zbt           !    -         -
+      REAL(wp) ::   zs2new, zalf1, zalf1q, zbt1          !    -         -
+      REAL(wp), DIMENSION(jpi,jpj) ::   zf0, zfx , zfy , zbet   ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj) ::   zfm, zfxx, zfyy, zfxy   !  -      -
+      REAL(wp), DIMENSION(jpi,jpj) ::   zalg, zalg1, zalg1q     !  -      -
+      !---------------------------------------------------------------------
+
+      ! Limitation of moments.
+
+      zrdt = rdt_ice * pdf ! If ice drift field is too fast, use an appropriate time step for advection.
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zslpmax = MAX( 0._wp, ps0(ji,jj) )
+            zs1max  = 1.5 * zslpmax
+            zs1new  = MIN( zs1max, MAX( -zs1max, psy(ji,jj) ) )
+            zs2new  = MIN(  ( 2.0 * zslpmax - 0.3334 * ABS( zs1new ) ),   &
+               &             MAX( ABS( zs1new )-zslpmax, psyy(ji,jj) )  )
+            rswitch = ( 1.0 - MAX( 0._wp, SIGN( 1._wp, -zslpmax) ) ) * tmask(ji,jj,1)   ! Case of empty boxes & Apply mask
+            !
+            ps0 (ji,jj) = zslpmax  
+            psx (ji,jj) = psx (ji,jj) * rswitch
+            psxx(ji,jj) = psxx(ji,jj) * rswitch
+            psy (ji,jj) = zs1new * rswitch
+            psyy(ji,jj) = zs2new * rswitch
+            psxy(ji,jj) = MIN( zslpmax, MAX( -zslpmax, psxy(ji,jj) ) ) * rswitch
+         END DO
+      END DO
+
+      !  Initialize volumes of boxes (=area if adv_x first called, =psm otherwise)
+      psm(:,:)  = MAX(  pcrh * e1e2t(:,:) + ( 1.0 - pcrh ) * psm(:,:) , epsi20  )
+
+      !  Calculate fluxes and moments between boxes j<-->j+1              
+      DO jj = 1, jpj                     !  Flux from j to j+1 WHEN v GT 0   
+         DO ji = 1, jpi
+            zbet(ji,jj)  =  MAX( 0._wp, SIGN( 1._wp, pvt(ji,jj) ) )
+            zalf         =  MAX( 0._wp, pvt(ji,jj) ) * zrdt * e1v(ji,jj) / psm(ji,jj)
+            zalfq        =  zalf * zalf
+            zalf1        =  1.0 - zalf
+            zalf1q       =  zalf1 * zalf1
+            !
+            zfm (ji,jj)  =  zalf  * psm(ji,jj)
+            zf0 (ji,jj)  =  zalf  * ( ps0(ji,jj) + zalf1 * ( psy(ji,jj)  + (zalf1-zalf) * psyy(ji,jj)  ) ) 
+            zfy (ji,jj)  =  zalfq *( psy(ji,jj) + 3.0*zalf1*psyy(ji,jj) )
+            zfyy(ji,jj)  =  zalf  * zalfq * psyy(ji,jj)
+            zfx (ji,jj)  =  zalf  * ( psx(ji,jj) + zalf1 * psxy(ji,jj) )
+            zfxy(ji,jj)  =  zalfq * psxy(ji,jj)
+            zfxx(ji,jj)  =  zalf  * psxx(ji,jj)
+            !
+            !  Readjust moments remaining in the box.
+            psm (ji,jj)  =  psm (ji,jj) - zfm(ji,jj)
+            ps0 (ji,jj)  =  ps0 (ji,jj) - zf0(ji,jj)
+            psy (ji,jj)  =  zalf1q * ( psy(ji,jj) -3.0 * zalf * psyy(ji,jj) )
+            psyy(ji,jj)  =  zalf1 * zalf1q * psyy(ji,jj)
+            psx (ji,jj)  =  psx (ji,jj) - zfx(ji,jj)
+            psxx(ji,jj)  =  psxx(ji,jj) - zfxx(ji,jj)
+            psxy(ji,jj)  =  zalf1q * psxy(ji,jj)
+         END DO
+      END DO
+      !
+      DO jj = 1, jpjm1                   !  Flux from j+1 to j when v LT 0.
+         DO ji = 1, jpi
+            zalf          = ( MAX(0._wp, -pvt(ji,jj) ) * zrdt * e1v(ji,jj) ) / psm(ji,jj+1) 
+            zalg  (ji,jj) = zalf
+            zalfq         = zalf * zalf
+            zalf1         = 1.0 - zalf
+            zalg1 (ji,jj) = zalf1
+            zalf1q        = zalf1 * zalf1
+            zalg1q(ji,jj) = zalf1q
+            !
+            zfm   (ji,jj) = zfm (ji,jj) + zalf  *   psm (ji,jj+1)
+            zf0   (ji,jj) = zf0 (ji,jj) + zalf  * ( ps0 (ji,jj+1) - zalf1 * (psy(ji,jj+1) - (zalf1 - zalf ) * psyy(ji,jj+1) ) )
+            zfy   (ji,jj) = zfy (ji,jj) + zalfq * ( psy (ji,jj+1) - 3.0 * zalf1 * psyy(ji,jj+1) )
+            zfyy  (ji,jj) = zfyy(ji,jj) + zalf  *   psyy(ji,jj+1) * zalfq
+            zfx   (ji,jj) = zfx (ji,jj) + zalf  * ( psx (ji,jj+1) - zalf1 * psxy(ji,jj+1) )
+            zfxy  (ji,jj) = zfxy(ji,jj) + zalfq *   psxy(ji,jj+1)
+            zfxx  (ji,jj) = zfxx(ji,jj) + zalf  *   psxx(ji,jj+1)
+         END DO
+      END DO
+
+      !  Readjust moments remaining in the box. 
+      DO jj = 2, jpj
+         DO ji = 1, jpi
+            zbt  =         zbet(ji,jj-1)
+            zbt1 = ( 1.0 - zbet(ji,jj-1) )
+            !
+            psm (ji,jj) = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) - zfm(ji,jj-1) )
+            ps0 (ji,jj) = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) - zf0(ji,jj-1) )
+            psy (ji,jj) = zalg1q(ji,jj-1) * ( psy(ji,jj) + 3.0 * zalg(ji,jj-1) * psyy(ji,jj) )
+            psyy(ji,jj) = zalg1 (ji,jj-1) * zalg1q(ji,jj-1) * psyy(ji,jj)
+            psx (ji,jj) = zbt * psx (ji,jj) + zbt1 * ( psx (ji,jj) - zfx (ji,jj-1) )
+            psxx(ji,jj) = zbt * psxx(ji,jj) + zbt1 * ( psxx(ji,jj) - zfxx(ji,jj-1) )
+            psxy(ji,jj) = zalg1q(ji,jj-1) * psxy(ji,jj)
+         END DO
+      END DO
+
+      !   Put the temporary moments into appropriate neighboring boxes.    
+      DO jj = 2, jpjm1                    !   Flux from j to j+1 IF v GT 0.
+         DO ji = 1, jpi
+            zbt  =         zbet(ji,jj-1)
+            zbt1 = ( 1.0 - zbet(ji,jj-1) )
+            psm(ji,jj)  = zbt * ( psm(ji,jj) + zfm(ji,jj-1) ) + zbt1 * psm(ji,jj) 
+            zalf        = zbt * zfm(ji,jj-1) / psm(ji,jj) 
+            zalf1       = 1.0 - zalf
+            ztemp       = zalf * ps0(ji,jj) - zalf1 * zf0(ji,jj-1)
+            !
+            ps0(ji,jj)  = zbt  * ( ps0(ji,jj) + zf0(ji,jj-1) ) + zbt1 * ps0(ji,jj)
+            psy(ji,jj)  = zbt  * ( zalf * zfy(ji,jj-1) + zalf1 * psy(ji,jj) + 3.0 * ztemp )   &
+               &                                               + zbt1 * psy(ji,jj)  
+            psyy(ji,jj) = zbt  * ( zalf * zalf * zfyy(ji,jj-1) + zalf1 * zalf1 * psyy(ji,jj)                             &
+               &                 + 5.0 * ( zalf * zalf1 * ( psy(ji,jj) - zfy(ji,jj-1) ) - ( zalf1 - zalf ) * ztemp ) )   & 
+               &                                               + zbt1 * psyy(ji,jj)
+            psxy(ji,jj) = zbt  * (  zalf * zfxy(ji,jj-1) + zalf1 * psxy(ji,jj)               &
+               &                  + 3.0 * (- zalf1 * zfx(ji,jj-1) + zalf * psx(ji,jj) )  )   &
+               &                                                + zbt1 * psxy(ji,jj)
+            psx (ji,jj) = zbt * ( psx (ji,jj) + zfx (ji,jj-1) ) + zbt1 * psx (ji,jj)
+            psxx(ji,jj) = zbt * ( psxx(ji,jj) + zfxx(ji,jj-1) ) + zbt1 * psxx(ji,jj)
+         END DO
+      END DO
+
+      DO jj = 2, jpjm1                   !  Flux from j+1 to j IF v LT 0.
+         DO ji = 1, jpi
+            zbt  =         zbet(ji,jj)
+            zbt1 = ( 1.0 - zbet(ji,jj) )
+            psm(ji,jj)  = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) + zfm(ji,jj) )
+            zalf        = zbt1 * zfm(ji,jj) / psm(ji,jj)
+            zalf1       = 1.0 - zalf
+            ztemp       = - zalf * ps0 (ji,jj) + zalf1 * zf0(ji,jj)
+            ps0 (ji,jj) =   zbt  * ps0 (ji,jj) + zbt1  * ( ps0(ji,jj) + zf0(ji,jj) )
+            psy (ji,jj) =   zbt  * psy (ji,jj) + zbt1  * ( zalf * zfy(ji,jj) + zalf1 * psy(ji,jj) + 3.0 * ztemp )
+            psyy(ji,jj) =   zbt  * psyy(ji,jj) + zbt1 * (  zalf * zalf * zfyy(ji,jj) + zalf1 * zalf1 * psyy(ji,jj)   &
+               &                                         + 5.0 *( zalf *zalf1 *( -psy(ji,jj) + zfy(ji,jj) )          &
+               &                                         + ( zalf1 - zalf ) * ztemp )                                )
+            psxy(ji,jj) =   zbt  * psxy(ji,jj) + zbt1 * (  zalf * zfxy(ji,jj) + zalf1 * psxy(ji,jj)       &
+               &                                         + 3.0 * ( zalf1 * zfx(ji,jj) - zalf * psx(ji,jj) )  )
+            psx (ji,jj) =   zbt  * psx (ji,jj) + zbt1 * ( psx (ji,jj) + zfx (ji,jj) )
+            psxx(ji,jj) =   zbt  * psxx(ji,jj) + zbt1 * ( psxx(ji,jj) + zfxx(ji,jj) )
+         END DO
+      END DO
+
+      !-- Lateral boundary conditions
+      CALL lbc_lnk_multi( psm , 'T',  1.,  ps0 , 'T',  1.   &
+         &              , psx , 'T', -1.,  psy , 'T', -1.   &   ! caution gradient ==> the sign changes
+         &              , psxx, 'T',  1.,  psyy, 'T',  1.   &
+         &              , psxy, 'T',  1. )
+
+      IF(ln_ctl) THEN
+         CALL prt_ctl(tab2d_1=psm  , clinfo1=' adv_y: psm  :', tab2d_2=ps0 , clinfo2=' ps0  : ')
+         CALL prt_ctl(tab2d_1=psx  , clinfo1=' adv_y: psx  :', tab2d_2=psxx, clinfo2=' psxx : ')
+         CALL prt_ctl(tab2d_1=psy  , clinfo1=' adv_y: psy  :', tab2d_2=psyy, clinfo2=' psyy : ')
+         CALL prt_ctl(tab2d_1=psxy , clinfo1=' adv_y: psxy :')
+      ENDIF
+      !
+   END SUBROUTINE adv_y
+
+
+   SUBROUTINE adv_pra_init
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE adv_pra_init  ***
+      !!
+      !! ** Purpose :   allocate and initialize arrays for Prather advection 
+      !!-------------------------------------------------------------------
+      INTEGER ::   ierr
+      !!-------------------------------------------------------------------
+      !
+      !                             !* allocate prather fields
+      ALLOCATE( sxopw(jpi,jpj)     , syopw(jpi,jpj)     , sxxopw(jpi,jpj)     , syyopw(jpi,jpj)     , sxyopw(jpi,jpj)     ,   &
+         &      sxice(jpi,jpj,jpl) , syice(jpi,jpj,jpl) , sxxice(jpi,jpj,jpl) , syyice(jpi,jpj,jpl) , sxyice(jpi,jpj,jpl) ,   &
+         &      sxsn (jpi,jpj,jpl) , sysn (jpi,jpj,jpl) , sxxsn (jpi,jpj,jpl) , syysn (jpi,jpj,jpl) , sxysn (jpi,jpj,jpl) ,   &
+         &      sxa  (jpi,jpj,jpl) , sya  (jpi,jpj,jpl) , sxxa  (jpi,jpj,jpl) , syya  (jpi,jpj,jpl) , sxya  (jpi,jpj,jpl) ,   &
+         &      sxc0 (jpi,jpj,jpl) , syc0 (jpi,jpj,jpl) , sxxc0 (jpi,jpj,jpl) , syyc0 (jpi,jpj,jpl) , sxyc0 (jpi,jpj,jpl) ,   &
+         &      sxsal(jpi,jpj,jpl) , sysal(jpi,jpj,jpl) , sxxsal(jpi,jpj,jpl) , syysal(jpi,jpj,jpl) , sxysal(jpi,jpj,jpl) ,   &
+         &      sxage(jpi,jpj,jpl) , syage(jpi,jpj,jpl) , sxxage(jpi,jpj,jpl) , syyage(jpi,jpj,jpl) , sxyage(jpi,jpj,jpl) ,   &
+         &      sxap(jpi,jpj,jpl)  , syap (jpi,jpj,jpl) , sxxap (jpi,jpj,jpl) , syyap (jpi,jpj,jpl) , sxyap (jpi,jpj,jpl) ,   &
+         &      sxvp(jpi,jpj,jpl)  , syvp (jpi,jpj,jpl) , sxxvp (jpi,jpj,jpl) , syyvp (jpi,jpj,jpl) , sxyvp (jpi,jpj,jpl) ,   &
+         &      sxe (jpi,jpj,nlay_i,jpl) , sye (jpi,jpj,nlay_i,jpl) , sxxe(jpi,jpj,nlay_i,jpl) , &
+         &      syye(jpi,jpj,nlay_i,jpl) , sxye(jpi,jpj,nlay_i,jpl)                            , &
+         &      STAT = ierr )
+      !
+      IF( lk_mpp    )   CALL mpp_sum( ierr )
+      IF( ierr /= 0 )   CALL ctl_stop('STOP', 'adv_pra_init : unable to allocate ice arrays for Prather advection scheme')
+      !
+      CALL adv_pra_rst( 'READ' )    !* read or initialize all required files
+      !
+   END SUBROUTINE adv_pra_init
+
+
+   SUBROUTINE adv_pra_rst( cdrw, kt )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE adv_pra_rst  ***
+      !!                     
+      !! ** Purpose :   Read or write RHG file in restart file
+      !!
+      !! ** Method  :   use of IOM library
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*) , INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
+      INTEGER, OPTIONAL, INTENT(in) ::   kt     ! ice time-step
+      !
+      INTEGER ::   jk, jl   ! dummy loop indices
+      INTEGER ::   iter     ! local integer
+      INTEGER ::   id1      ! local integer
+      CHARACTER(len=25) ::   znam
+      CHARACTER(len=2)  ::   zchar, zchar1
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z3d   ! 3D workspace
+      !!----------------------------------------------------------------------
+      !
+      !                                      !==========================!
+      IF( TRIM(cdrw) == 'READ' ) THEN        !==  Read or initialize  ==!
+         !                                   !==========================!
+         !
+         IF( ln_rstart ) THEN   ;   id1 = iom_varid( numrir, 'sxopw' , ldstop = .FALSE. )    ! file exist: id1>0
+         ELSE                   ;   id1 = 0                                                  ! no restart: id1=0
+         ENDIF
+         !
+         IF( id1 > 0 ) THEN                     !**  Read the restart file  **!
+            !
+            !                                                        ! ice thickness
+            CALL iom_get( numrir, jpdom_autoglo, 'sxice' , sxice  )
+            CALL iom_get( numrir, jpdom_autoglo, 'syice' , syice  )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxxice', sxxice )
+            CALL iom_get( numrir, jpdom_autoglo, 'syyice', syyice )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxyice', sxyice )
+            !                                                        ! snow thickness
+            CALL iom_get( numrir, jpdom_autoglo, 'sxsn'  , sxsn   )
+            CALL iom_get( numrir, jpdom_autoglo, 'sysn'  , sysn   )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxxsn' , sxxsn  )
+            CALL iom_get( numrir, jpdom_autoglo, 'syysn' , syysn  )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxysn' , sxysn  )
+            !                                                        ! lead fraction
+            CALL iom_get( numrir, jpdom_autoglo, 'sxa'   , sxa    )
+            CALL iom_get( numrir, jpdom_autoglo, 'sya'   , sya    )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxxa'  , sxxa   )
+            CALL iom_get( numrir, jpdom_autoglo, 'syya'  , syya   )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxya'  , sxya   )
+            !                                                        ! snow thermal content
+            CALL iom_get( numrir, jpdom_autoglo, 'sxc0'  , sxc0   )
+            CALL iom_get( numrir, jpdom_autoglo, 'syc0'  , syc0   )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxxc0' , sxxc0  )
+            CALL iom_get( numrir, jpdom_autoglo, 'syyc0' , syyc0  )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxyc0' , sxyc0  )
+            !                                                        ! ice salinity
+            CALL iom_get( numrir, jpdom_autoglo, 'sxsal' , sxsal  )
+            CALL iom_get( numrir, jpdom_autoglo, 'sysal' , sysal  )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxxsal', sxxsal )
+            CALL iom_get( numrir, jpdom_autoglo, 'syysal', syysal )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxysal', sxysal )
+            !                                                        ! ice age
+            CALL iom_get( numrir, jpdom_autoglo, 'sxage' , sxage  )
+            CALL iom_get( numrir, jpdom_autoglo, 'syage' , syage  )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxxage', sxxage )
+            CALL iom_get( numrir, jpdom_autoglo, 'syyage', syyage )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxyage', sxyage )
+            !                                                        ! open water in sea ice
+            CALL iom_get( numrir, jpdom_autoglo, 'sxopw ', sxopw  )
+            CALL iom_get( numrir, jpdom_autoglo, 'syopw ', syopw  )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxxopw', sxxopw )
+            CALL iom_get( numrir, jpdom_autoglo, 'syyopw', syyopw )
+            CALL iom_get( numrir, jpdom_autoglo, 'sxyopw', sxyopw )
+            !                                                        ! ice layers heat content
+            DO jk = 1, nlay_i 
+               WRITE(zchar1,'(I2.2)') jk
+               znam = 'sxe'//'_il'//zchar1   ;   CALL iom_get( numrir, jpdom_autoglo, znam , z3d )   ;   sxe (:,:,jk,:) = z3d(:,:,:)
+               znam = 'sye'//'_il'//zchar1   ;   CALL iom_get( numrir, jpdom_autoglo, znam , z3d )   ;   sye (:,:,jk,:) = z3d(:,:,:)
+               znam = 'sxxe'//'_il'//zchar1  ;   CALL iom_get( numrir, jpdom_autoglo, znam , z3d )   ;   sxxe(:,:,jk,:) = z3d(:,:,:)
+               znam = 'syye'//'_il'//zchar1  ;   CALL iom_get( numrir, jpdom_autoglo, znam , z3d )   ;   syye(:,:,jk,:) = z3d(:,:,:)
+               znam = 'sxye'//'_il'//zchar1  ;   CALL iom_get( numrir, jpdom_autoglo, znam , z3d )   ;   sxye(:,:,jk,:) = z3d(:,:,:)
+            END DO
+            !
+            IF( ln_pnd_H12 ) THEN                                    ! melt pond fraction
+               CALL iom_get( numrir, jpdom_autoglo, 'sxap' , sxap  )
+               CALL iom_get( numrir, jpdom_autoglo, 'syap' , syap  )
+               CALL iom_get( numrir, jpdom_autoglo, 'sxxap', sxxap )
+               CALL iom_get( numrir, jpdom_autoglo, 'syyap', syyap )
+               CALL iom_get( numrir, jpdom_autoglo, 'sxyap', sxyap )
+               !                                                     ! melt pond volume
+               CALL iom_get( numrir, jpdom_autoglo, 'sxvp' , sxvp  )
+               CALL iom_get( numrir, jpdom_autoglo, 'syvp' , syvp  )
+               CALL iom_get( numrir, jpdom_autoglo, 'sxxvp', sxxvp )
+               CALL iom_get( numrir, jpdom_autoglo, 'syyvp', syyvp )
+               CALL iom_get( numrir, jpdom_autoglo, 'sxyvp', sxyvp )
+            ENDIF
+            !
+         ELSE                                   !**  start rheology from rest  **!
+            !
+            IF(lwp) WRITE(numout,*) '   ==>>   start from rest OR previous run without Prather, set moments to 0'
+            !
+            sxice = 0._wp   ;   syice = 0._wp   ;   sxxice = 0._wp   ;   syyice = 0._wp   ;   sxyice = 0._wp      ! ice thickness
+            sxsn  = 0._wp   ;   sysn  = 0._wp   ;   sxxsn  = 0._wp   ;   syysn  = 0._wp   ;   sxysn  = 0._wp      ! snow thickness
+            sxa   = 0._wp   ;   sya   = 0._wp   ;   sxxa   = 0._wp   ;   syya   = 0._wp   ;   sxya   = 0._wp      ! lead fraction
+            sxc0  = 0._wp   ;   syc0  = 0._wp   ;   sxxc0  = 0._wp   ;   syyc0  = 0._wp   ;   sxyc0  = 0._wp      ! snow thermal content
+            sxsal = 0._wp   ;   sysal = 0._wp   ;   sxxsal = 0._wp   ;   syysal = 0._wp   ;   sxysal = 0._wp      ! ice salinity
+            sxage = 0._wp   ;   syage = 0._wp   ;   sxxage = 0._wp   ;   syyage = 0._wp   ;   sxyage = 0._wp      ! ice age
+            sxopw = 0._wp   ;   syopw = 0._wp   ;   sxxopw = 0._wp   ;   syyopw = 0._wp   ;   sxyopw = 0._wp      ! open water in sea ice
+            sxe   = 0._wp   ;   sye   = 0._wp   ;   sxxe   = 0._wp   ;   syye   = 0._wp   ;   sxye   = 0._wp      ! ice layers heat content
+            IF( ln_pnd_H12 ) THEN
+               sxap  = 0._wp   ;   syap  = 0._wp   ;   sxxap  = 0._wp   ;   syyap  = 0._wp   ;   sxyap  = 0._wp   ! melt pond fraction
+               sxvp  = 0._wp   ;   syvp  = 0._wp   ;   sxxvp  = 0._wp   ;   syyvp  = 0._wp   ;   sxyvp  = 0._wp   ! melt pond volume
+            ENDIF
+         ENDIF
+         !
+         !                                   !=====================================!
+      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   !==  write in the ice restart file  ==!
+         !                                   !=====================================!
+         IF(lwp) WRITE(numout,*) '----  ice-adv-rst  ----'
+         iter = kt + nn_fsbc - 1             ! ice restarts are written at kt == nitrst - nn_fsbc + 1
+         !
+         !
+         ! In case Prather scheme is used for advection, write second order moments
+         ! ------------------------------------------------------------------------
+         !
+         !                                                           ! ice thickness
+         CALL iom_rstput( iter, nitrst, numriw, 'sxice' , sxice  )
+         CALL iom_rstput( iter, nitrst, numriw, 'syice' , syice  )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxice', sxxice )
+         CALL iom_rstput( iter, nitrst, numriw, 'syyice', syyice )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxyice', sxyice )
+         !                                                           ! snow thickness
+         CALL iom_rstput( iter, nitrst, numriw, 'sxsn'  , sxsn   )
+         CALL iom_rstput( iter, nitrst, numriw, 'sysn'  , sysn   )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxsn' , sxxsn  )
+         CALL iom_rstput( iter, nitrst, numriw, 'syysn' , syysn  )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxysn' , sxysn  )
+         !                                                           ! lead fraction
+         CALL iom_rstput( iter, nitrst, numriw, 'sxa'   , sxa    )
+         CALL iom_rstput( iter, nitrst, numriw, 'sya'   , sya    )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxa'  , sxxa   )
+         CALL iom_rstput( iter, nitrst, numriw, 'syya'  , syya   )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxya'  , sxya   )
+         !                                                           ! snow thermal content
+         CALL iom_rstput( iter, nitrst, numriw, 'sxc0'  , sxc0   )
+         CALL iom_rstput( iter, nitrst, numriw, 'syc0'  , syc0   )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxc0' , sxxc0  )
+         CALL iom_rstput( iter, nitrst, numriw, 'syyc0' , syyc0  )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxyc0' , sxyc0  )
+         !                                                           ! ice salinity
+         CALL iom_rstput( iter, nitrst, numriw, 'sxsal' , sxsal  )
+         CALL iom_rstput( iter, nitrst, numriw, 'sysal' , sysal  )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxsal', sxxsal )
+         CALL iom_rstput( iter, nitrst, numriw, 'syysal', syysal )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxysal', sxysal )
+         !                                                           ! ice age
+         CALL iom_rstput( iter, nitrst, numriw, 'sxage' , sxage  )
+         CALL iom_rstput( iter, nitrst, numriw, 'syage' , syage  )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxage', sxxage )
+         CALL iom_rstput( iter, nitrst, numriw, 'syyage', syyage )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxyage', sxyage )
+         !                                                           ! open water in sea ice
+         CALL iom_rstput( iter, nitrst, numriw, 'sxopw ', sxopw  )
+         CALL iom_rstput( iter, nitrst, numriw, 'syopw ', syopw  )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxxopw', sxxopw )
+         CALL iom_rstput( iter, nitrst, numriw, 'syyopw', syyopw )
+         CALL iom_rstput( iter, nitrst, numriw, 'sxyopw', sxyopw )
+         !                                                           ! ice layers heat content
+         DO jk = 1, nlay_i 
+            WRITE(zchar1,'(I2.2)') jk
+            znam = 'sxe'//'_il'//zchar1   ;   z3d(:,:,:) = sxe (:,:,jk,:)   ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
+            znam = 'sye'//'_il'//zchar1   ;   z3d(:,:,:) = sye (:,:,jk,:)   ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
+            znam = 'sxxe'//'_il'//zchar1  ;   z3d(:,:,:) = sxxe(:,:,jk,:)   ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
+            znam = 'syye'//'_il'//zchar1  ;   z3d(:,:,:) = syye(:,:,jk,:)   ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
+            znam = 'sxye'//'_il'//zchar1  ;   z3d(:,:,:) = sxye(:,:,jk,:)   ;   CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
+         END DO
+         !
+         IF( ln_pnd_H12 ) THEN                                       ! melt pond fraction
+            CALL iom_rstput( iter, nitrst, numriw, 'sxap' , sxap  )
+            CALL iom_rstput( iter, nitrst, numriw, 'syap' , syap  )
+            CALL iom_rstput( iter, nitrst, numriw, 'sxxap', sxxap )
+            CALL iom_rstput( iter, nitrst, numriw, 'syyap', syyap )
+            CALL iom_rstput( iter, nitrst, numriw, 'sxyap', sxyap )
+            !                                                        ! melt pond volume
+            CALL iom_rstput( iter, nitrst, numriw, 'sxvp' , sxvp  )
+            CALL iom_rstput( iter, nitrst, numriw, 'syvp' , syvp  )
+            CALL iom_rstput( iter, nitrst, numriw, 'sxxvp', sxxvp )
+            CALL iom_rstput( iter, nitrst, numriw, 'syyvp', syyvp )
+            CALL iom_rstput( iter, nitrst, numriw, 'sxyvp', sxyvp )
+         ENDIF
+         !
+      ENDIF
+      !
+   END SUBROUTINE adv_pra_rst
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option            Dummy module        NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icedyn_adv_pra
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv_umx.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv_umx.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv_umx.F90	(revision 9019)
@@ -0,0 +1,642 @@
+MODULE icedyn_adv_umx
+   !!==============================================================================
+   !!                       ***  MODULE  icedyn_adv_umx  ***
+   !! sea-ice : advection using the ULTIMATE-MACHO scheme
+   !!==============================================================================
+   !! History :  3.6  !  2014-11  (C. Rousset, G. Madec)  Original code
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_dyn_adv_umx   : update the tracer trend with the 3D advection trends using a TVD scheme
+   !!   ultimate_x(_y)    : compute a tracer value at velocity points using ULTIMATE scheme at various orders
+   !!   macho             : ???
+   !!   nonosc_2d         : compute monotonic tracer fluxes by a non-oscillatory algorithm 
+   !!----------------------------------------------------------------------
+   USE phycst         ! physical constant
+   USE dom_oce        ! ocean domain
+   USE sbc_oce , ONLY : nn_fsbc   ! update frequency of surface boundary condition
+   USE ice            ! sea-ice variables
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE lbclnk         ! lateral boundary conditions (or mpp links)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_dyn_adv_umx   ! called by icedyn_adv.F90
+      
+   REAL(wp) ::   z1_6   = 1._wp /   6._wp   ! =1/6
+   REAL(wp) ::   z1_120 = 1._wp / 120._wp   ! =1/120
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icedyn_adv_umx.F90 4499 2014-02-18 15:14:31Z timgraham $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_dyn_adv_umx( k_order, kt, pu_ice, pv_ice,  &
+      &                    pato_i, pv_i, pv_s, psv_i, poa_i, pa_i, pa_ip, pv_ip, pe_s, pe_i )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_dyn_adv_umx  ***
+      !! 
+      !! **  Purpose :   Compute the now trend due to total advection of 
+      !!                 tracers and add it to the general trend of tracer equations
+      !!                 using an "Ultimate-Macho" scheme
+      !!
+      !! Reference : Leonard, B.P., 1991, Comput. Methods Appl. Mech. Eng., 88, 17-74. 
+      !!----------------------------------------------------------------------
+      INTEGER                     , INTENT(in   ) ::   k_order    ! order of the scheme (1-5 or 20)
+      INTEGER                     , INTENT(in   ) ::   kt         ! time step
+      REAL(wp), DIMENSION(:,:)    , INTENT(in   ) ::   pu_ice     ! ice i-velocity
+      REAL(wp), DIMENSION(:,:)    , INTENT(in   ) ::   pv_ice     ! ice j-velocity
+      REAL(wp), DIMENSION(:,:)    , INTENT(inout) ::   pato_i     ! open water area
+      REAL(wp), DIMENSION(:,:,:)  , INTENT(inout) ::   pv_i       ! ice volume
+      REAL(wp), DIMENSION(:,:,:)  , INTENT(inout) ::   pv_s       ! snw volume
+      REAL(wp), DIMENSION(:,:,:)  , INTENT(inout) ::   psv_i      ! salt content
+      REAL(wp), DIMENSION(:,:,:)  , INTENT(inout) ::   poa_i      ! age content
+      REAL(wp), DIMENSION(:,:,:)  , INTENT(inout) ::   pa_i       ! ice concentration
+      REAL(wp), DIMENSION(:,:,:)  , INTENT(inout) ::   pa_ip      ! melt pond fraction
+      REAL(wp), DIMENSION(:,:,:)  , INTENT(inout) ::   pv_ip      ! melt pond volume
+      REAL(wp), DIMENSION(:,:,:,:), INTENT(inout) ::   pe_s       ! snw heat content
+      REAL(wp), DIMENSION(:,:,:,:), INTENT(inout) ::   pe_i       ! ice heat content
+      !
+      INTEGER  ::   ji, jj, jk, jl, jt      ! dummy loop indices
+      INTEGER  ::   initad                  ! number of sub-timestep for the advection
+      REAL(wp) ::   zcfl , zusnit, zdt      !   -      -
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zudy, zvdx, zcu_box, zcv_box
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nit000 .AND. lwp )   WRITE(numout,*) '-- ice_dyn_adv_umx: Ultimate-Macho advection scheme'
+      !
+      ALLOCATE( zudy(jpi,jpj) , zvdx(jpi,jpj) , zcu_box(jpi,jpj) , zcv_box(jpi,jpj) )
+      !
+      ! --- If ice drift field is too fast, use an appropriate time step for advection (CFL test for stability) --- !        
+      zcfl  =            MAXVAL( ABS( pu_ice(:,:) ) * rdt_ice * r1_e1u(:,:) )
+      zcfl  = MAX( zcfl, MAXVAL( ABS( pv_ice(:,:) ) * rdt_ice * r1_e2v(:,:) ) )
+      IF( lk_mpp )   CALL mpp_max( zcfl )
+
+      IF( zcfl > 0.5 ) THEN   ;   initad = 2   ;   zusnit = 0.5_wp
+      ELSE                    ;   initad = 1   ;   zusnit = 1.0_wp
+      ENDIF
+
+      zdt = rdt_ice / REAL(initad)
+
+      ! --- transport --- !
+      zudy(:,:) = pu_ice(:,:) * e2u(:,:)
+      zvdx(:,:) = pv_ice(:,:) * e1v(:,:)
+
+      ! --- define velocity for advection: u*grad(H) --- !
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            IF    ( pu_ice(ji,jj) * pu_ice(ji-1,jj) <= 0._wp ) THEN   ;   zcu_box(ji,jj) = 0._wp
+            ELSEIF( pu_ice(ji,jj)                   >  0._wp ) THEN   ;   zcu_box(ji,jj) = pu_ice(ji-1,jj)
+            ELSE                                                      ;   zcu_box(ji,jj) = pu_ice(ji  ,jj)
+            ENDIF
+
+            IF    ( pv_ice(ji,jj) * pv_ice(ji,jj-1) <= 0._wp ) THEN   ;   zcv_box(ji,jj) = 0._wp
+            ELSEIF( pv_ice(ji,jj)                   >  0._wp ) THEN   ;   zcv_box(ji,jj) = pv_ice(ji,jj-1)
+            ELSE                                                      ;   zcv_box(ji,jj) = pv_ice(ji,jj  )
+            ENDIF
+         END DO
+      END DO
+
+      !---------------!
+      !== advection ==!
+      !---------------!
+      DO jt = 1, initad
+         CALL adv_umx( k_order, kt, zdt, zudy, zvdx, zcu_box, zcv_box, pato_i(:,:) )             ! Open water area 
+         DO jl = 1, jpl
+            CALL adv_umx( k_order, kt, zdt, zudy, zvdx, zcu_box, zcv_box, pa_i(:,:,jl) )         ! Ice area
+            CALL adv_umx( k_order, kt, zdt, zudy, zvdx, zcu_box, zcv_box, pv_i(:,:,jl) )         ! Ice  volume
+            CALL adv_umx( k_order, kt, zdt, zudy, zvdx, zcu_box, zcv_box, psv_i(:,:,jl) )        ! Salt content
+            CALL adv_umx( k_order, kt, zdt, zudy, zvdx, zcu_box, zcv_box, poa_i(:,:,jl) )        ! Age content
+            DO jk = 1, nlay_i
+               CALL adv_umx( k_order, kt, zdt, zudy, zvdx, zcu_box, zcv_box, pe_i(:,:,jk,jl) )   ! Ice  heat content
+            END DO
+            CALL adv_umx( k_order, kt, zdt, zudy, zvdx, zcu_box, zcv_box, pv_s(:,:,jl) )         ! Snow volume
+            CALL adv_umx( k_order, kt, zdt, zudy, zvdx, zcu_box, zcv_box, pe_s(:,:,1,jl) )       ! Snow heat content
+            IF ( ln_pnd_H12 ) THEN
+               CALL adv_umx( k_order, kt, zdt, zudy, zvdx, zcu_box, zcv_box, pa_ip(:,:,jl) )     ! Melt pond fraction
+               CALL adv_umx( k_order, kt, zdt, zudy, zvdx, zcu_box, zcv_box, pv_ip(:,:,jl) )     ! Melt pond volume
+            ENDIF
+         END DO
+      END DO
+      !
+      DEALLOCATE( zudy, zvdx, zcu_box, zcv_box )
+      !
+   END SUBROUTINE ice_dyn_adv_umx
+   
+   SUBROUTINE adv_umx( k_order, kt, pdt, puc, pvc, pubox, pvbox, ptc )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE adv_umx  ***
+      !! 
+      !! **  Purpose :   Compute the now trend due to total advection of 
+      !!       tracers and add it to the general trend of tracer equations
+      !!
+      !! **  Method  :   TVD scheme, i.e. 2nd order centered scheme with
+      !!       corrected flux (monotonic correction)
+      !!       note: - this advection scheme needs a leap-frog time scheme
+      !!
+      !! ** Action : - pt  the after advective tracer
+      !!----------------------------------------------------------------------
+      INTEGER                     , INTENT(in   ) ::   k_order        ! order of the ULTIMATE scheme
+      INTEGER                     , INTENT(in   ) ::   kt             ! number of iteration
+      REAL(wp)                    , INTENT(in   ) ::   pdt            ! tracer time-step
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   puc  , pvc     ! 2 ice velocity components => u*e2
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pubox, pvbox   ! upstream velocity
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ptc            ! tracer content field
+      !
+      INTEGER  ::   ji, jj           ! dummy loop indices  
+      REAL(wp) ::   ztra             ! local scalar
+      REAL(wp) ::   zfp_ui, zfp_vj   !   -      -
+      REAL(wp) ::   zfm_ui, zfm_vj   !   -      -
+      REAL(wp), DIMENSION(jpi,jpj) ::   zfu_ups, zfu_ho, zt_u, zt_ups
+      REAL(wp), DIMENSION(jpi,jpj) ::   zfv_ups, zfv_ho, zt_v, ztrd
+      !!----------------------------------------------------------------------
+      !
+      !  upstream advection with initial mass fluxes & intermediate update
+      ! --------------------------------------------------------------------
+      DO jj = 1, jpjm1         ! upstream tracer flux in the i and j direction
+         DO ji = 1, fs_jpim1   ! vector opt.
+            zfp_ui = puc(ji,jj) + ABS( puc(ji,jj) )
+            zfm_ui = puc(ji,jj) - ABS( puc(ji,jj) )
+            zfp_vj = pvc(ji,jj) + ABS( pvc(ji,jj) )
+            zfm_vj = pvc(ji,jj) - ABS( pvc(ji,jj) )
+            zfu_ups(ji,jj) = 0.5_wp * ( zfp_ui * ptc(ji,jj) + zfm_ui * ptc(ji+1,jj  ) )
+            zfv_ups(ji,jj) = 0.5_wp * ( zfp_vj * ptc(ji,jj) + zfm_vj * ptc(ji  ,jj+1) )
+         END DO
+      END DO
+      
+      DO jj = 2, jpjm1            ! total intermediate advective trends
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ztra = - (   zfu_ups(ji,jj) - zfu_ups(ji-1,jj  )   &
+               &       + zfv_ups(ji,jj) - zfv_ups(ji  ,jj-1)   ) * r1_e1e2t(ji,jj)
+            !
+            ztrd(ji,jj) =                         ztra                         ! upstream trend [ -div(uh) or -div(uhT) ]  
+            zt_ups (ji,jj) = ( ptc(ji,jj) + pdt * ztra ) * tmask(ji,jj,1)      ! guess after content field with monotonic scheme
+         END DO
+      END DO
+      CALL lbc_lnk( zt_ups, 'T', 1. )        ! Lateral boundary conditions   (unchanged sign)
+      
+      ! High order (_ho) fluxes 
+      ! -----------------------
+      SELECT CASE( k_order )
+      CASE ( 20 )                          ! centered second order
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zfu_ho(ji,jj) = 0.5 * puc(ji,jj) * ( ptc(ji,jj) + ptc(ji+1,jj) )
+               zfv_ho(ji,jj) = 0.5 * pvc(ji,jj) * ( ptc(ji,jj) + ptc(ji,jj+1) )
+            END DO
+         END DO
+         !
+      CASE ( 1:5 )                      ! 1st to 5th order ULTIMATE-MACHO scheme
+         CALL macho( k_order, kt, pdt, ptc, puc, pvc, pubox, pvbox, zt_u, zt_v )
+         !
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zfu_ho(ji,jj) = puc(ji,jj) * zt_u(ji,jj)
+               zfv_ho(ji,jj) = pvc(ji,jj) * zt_v(ji,jj)
+            END DO
+         END DO
+         !
+      END SELECT
+         
+      ! antidiffusive flux : high order minus low order
+      ! --------------------------------------------------
+      DO jj = 1, jpjm1
+         DO ji = 1, fs_jpim1   ! vector opt.
+            zfu_ho(ji,jj) = zfu_ho(ji,jj) - zfu_ups(ji,jj)
+            zfv_ho(ji,jj) = zfv_ho(ji,jj) - zfv_ups(ji,jj)
+         END DO
+      END DO
+      
+      ! monotonicity algorithm
+      ! -------------------------
+      CALL nonosc_2d( ptc, zfu_ho, zfv_ho, zt_ups, pdt )
+      
+      ! final trend with corrected fluxes
+      ! ------------------------------------
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.  
+            ztra       = ztrd(ji,jj)  - (  zfu_ho(ji,jj) - zfu_ho(ji-1,jj  )   &
+               &                         + zfv_ho(ji,jj) - zfv_ho(ji  ,jj-1) ) * r1_e1e2t(ji,jj)  
+            ptc(ji,jj) = ptc(ji,jj) + pdt * ztra
+         END DO
+      END DO
+      CALL lbc_lnk( ptc(:,:) , 'T',  1. )
+      !
+   END SUBROUTINE adv_umx
+
+
+   SUBROUTINE macho( k_order, kt, pdt, ptc, puc, pvc, pubox, pvbox, pt_u, pt_v )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE ultimate_x  ***
+      !!     
+      !! **  Purpose :   compute  
+      !!
+      !! **  Method  :   ... ???
+      !!                 TIM = transient interpolation Modeling 
+      !!
+      !! Reference : Leonard, B.P., 1991, Comput. Methods Appl. Mech. Eng., 88, 17-74. 
+      !!----------------------------------------------------------------------
+      INTEGER                     , INTENT(in   ) ::   k_order    ! order of the ULTIMATE scheme
+      INTEGER                     , INTENT(in   ) ::   kt         ! number of iteration
+      REAL(wp)                    , INTENT(in   ) ::   pdt        ! tracer time-step
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   ptc        ! tracer fields
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   puc, pvc   ! 2 ice velocity components
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pubox, pvbox   ! upstream velocity
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   pt_u, pt_v ! tracer at u- and v-points 
+      !
+      INTEGER  ::   ji, jj    ! dummy loop indices
+      REAL(wp) ::   zc_box    !   -      -
+      REAL(wp), DIMENSION(jpi,jpj) :: zzt
+      !!----------------------------------------------------------------------
+      !
+      IF( MOD( (kt - 1) / nn_fsbc , 2 ) == 0 ) THEN         !==  odd ice time step:  adv_x then adv_y  ==!
+         !
+         !                                                           !--  ultimate interpolation of pt at u-point  --!
+         CALL ultimate_x( k_order, pdt, ptc, puc, pt_u )
+         !
+         !                                                           !--  advective form update in zzt  --!
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zzt(ji,jj) = ptc(ji,jj) - pubox(ji,jj) * pdt * ( pt_u(ji,jj) - pt_u(ji-1,jj) ) * r1_e1t(ji,jj)  &
+                  &                    - ptc  (ji,jj) * pdt * ( puc (ji,jj) - puc (ji-1,jj) ) * r1_e1e2t(ji,jj)
+               zzt(ji,jj) = zzt(ji,jj) * tmask(ji,jj,1)
+            END DO
+         END DO
+         CALL lbc_lnk( zzt, 'T', 1. )
+         !
+         !                                                           !--  ultimate interpolation of pt at v-point  --!
+         CALL ultimate_y( k_order, pdt, zzt, pvc, pt_v )
+         !
+      ELSE                                                  !==  even ice time step:  adv_y then adv_x  ==!
+         !
+         !                                                           !--  ultimate interpolation of pt at v-point  --!
+         CALL ultimate_y( k_order, pdt, ptc, pvc, pt_v )
+         !
+         !                                                           !--  advective form update in zzt  --!
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zzt(ji,jj) = ptc(ji,jj) - pvbox(ji,jj) * pdt * ( pt_v(ji,jj) - pt_v(ji,jj-1) ) * r1_e2t(ji,jj)  &
+                  &                    - ptc  (ji,jj) * pdt * ( pvc (ji,jj) - pvc (ji,jj-1) ) * r1_e1e2t(ji,jj)
+               zzt(ji,jj) = zzt(ji,jj) * tmask(ji,jj,1)
+            END DO
+         END DO
+         CALL lbc_lnk( zzt, 'T', 1. )
+         !
+         !                                                           !--  ultimate interpolation of pt at u-point  --!
+         CALL ultimate_x( k_order, pdt, zzt, puc, pt_u )
+         !      
+      ENDIF      
+      !
+   END SUBROUTINE macho
+
+
+   SUBROUTINE ultimate_x( k_order, pdt, pt, puc, pt_u )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE ultimate_x  ***
+      !!     
+      !! **  Purpose :   compute  
+      !!
+      !! **  Method  :   ... ???
+      !!                 TIM = transient interpolation Modeling 
+      !!
+      !! Reference : Leonard, B.P., 1991, Comput. Methods Appl. Mech. Eng., 88, 17-74. 
+      !!----------------------------------------------------------------------
+      INTEGER                     , INTENT(in   ) ::   k_order   ! ocean time-step index
+      REAL(wp)                    , INTENT(in   ) ::   pdt       ! tracer time-step
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   puc       ! ice i-velocity component
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pt        ! tracer fields
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   pt_u      ! tracer at u-point 
+      !
+      INTEGER  ::   ji, jj       ! dummy loop indices
+      REAL(wp) ::   zcu, zdx2, zdx4    !   -      -
+      REAL(wp), DIMENSION(jpi,jpj) :: ztu1, ztu2, ztu3, ztu4
+      !!----------------------------------------------------------------------
+      !
+      !                                                     !--  Laplacian in i-direction  --!
+      DO jj = 2, jpjm1         ! First derivative (gradient)
+         DO ji = 1, fs_jpim1
+            ztu1(ji,jj) = ( pt(ji+1,jj) - pt(ji,jj) ) * r1_e1u(ji,jj) * umask(ji,jj,1)
+         END DO
+         !                     ! Second derivative (Laplacian)
+         DO ji = fs_2, fs_jpim1
+            ztu2(ji,jj) = ( ztu1(ji,jj) - ztu1(ji-1,jj) ) * r1_e1t(ji,jj)
+         END DO
+      END DO
+      CALL lbc_lnk( ztu2, 'T', 1. )
+      !
+      !                                                     !--  BiLaplacian in i-direction  --!
+      DO jj = 2, jpjm1         ! Third derivative
+         DO ji = 1, fs_jpim1
+            ztu3(ji,jj) = ( ztu2(ji+1,jj) - ztu2(ji,jj) ) * r1_e1u(ji,jj) * umask(ji,jj,1)
+         END DO
+         !                     ! Fourth derivative
+         DO ji = fs_2, fs_jpim1
+            ztu4(ji,jj) = ( ztu3(ji,jj) - ztu3(ji-1,jj) ) * r1_e1t(ji,jj)
+         END DO
+      END DO
+      CALL lbc_lnk( ztu4, 'T', 1. )
+      !
+      !
+      SELECT CASE (k_order )
+      !
+      CASE( 1 )                                                   !==  1st order central TIM  ==! (Eq. 21)
+         !        
+         DO jj = 2, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               pt_u(ji,jj) = 0.5_wp * umask(ji,jj,1) * (                               pt(ji+1,jj) + pt(ji,jj)   &
+                  &                                    - SIGN( 1._wp, puc(ji,jj) ) * ( pt(ji+1,jj) - pt(ji,jj) ) )
+            END DO
+         END DO
+         !
+      CASE( 2 )                                                   !==  2nd order central TIM  ==! (Eq. 23)
+         !
+         DO jj = 2, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zcu  = puc(ji,jj) * r1_e2u(ji,jj) * pdt * r1_e1u(ji,jj)
+               pt_u(ji,jj) = 0.5_wp * umask(ji,jj,1) * (                                   pt(ji+1,jj) + pt(ji,jj)   &
+                  &                                               -              zcu   * ( pt(ji+1,jj) - pt(ji,jj) ) ) 
+            END DO
+         END DO
+         !  
+      CASE( 3 )                                                   !==  3rd order central TIM  ==! (Eq. 24)
+         !
+         DO jj = 2, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zcu  = puc(ji,jj) * r1_e2u(ji,jj) * pdt * r1_e1u(ji,jj)
+               zdx2 = e1u(ji,jj) * e1u(ji,jj)
+!!rachid       zdx2 = e1u(ji,jj) * e1t(ji,jj)
+               pt_u(ji,jj) = 0.5_wp * umask(ji,jj,1) * (         (                         pt  (ji+1,jj) + pt  (ji,jj)        &
+                  &                                               -              zcu   * ( pt  (ji+1,jj) - pt  (ji,jj) )  )   &
+                  &        + z1_6 * zdx2 * ( zcu*zcu - 1._wp ) * (                         ztu2(ji+1,jj) + ztu2(ji,jj)        &
+                  &                                               - SIGN( 1._wp, zcu ) * ( ztu2(ji+1,jj) - ztu2(ji,jj) )  )   )
+            END DO
+         END DO
+         !
+      CASE( 4 )                                                   !==  4th order central TIM  ==! (Eq. 27)
+         !
+         DO jj = 2, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zcu  = puc(ji,jj) * r1_e2u(ji,jj) * pdt * r1_e1u(ji,jj)
+               zdx2 = e1u(ji,jj) * e1u(ji,jj)
+!!rachid       zdx2 = e1u(ji,jj) * e1t(ji,jj)
+               pt_u(ji,jj) = 0.5_wp * umask(ji,jj,1) * (         (                   pt  (ji+1,jj) + pt  (ji,jj)        &
+                  &                                               -          zcu * ( pt  (ji+1,jj) - pt  (ji,jj) )  )   &
+                  &        + z1_6 * zdx2 * ( zcu*zcu - 1._wp ) * (                   ztu2(ji+1,jj) + ztu2(ji,jj)        &
+                  &                                               - 0.5_wp * zcu * ( ztu2(ji+1,jj) - ztu2(ji,jj) )  )   )
+            END DO
+         END DO
+         !
+      CASE( 5 )                                                   !==  5th order central TIM  ==! (Eq. 29)
+         !
+         DO jj = 2, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zcu  = puc(ji,jj) * r1_e2u(ji,jj) * pdt * r1_e1u(ji,jj)
+               zdx2 = e1u(ji,jj) * e1u(ji,jj)
+!!rachid       zdx2 = e1u(ji,jj) * e1t(ji,jj)
+               zdx4 = zdx2 * zdx2
+               pt_u(ji,jj) = 0.5_wp * umask(ji,jj,1) * (               (                   pt  (ji+1,jj) + pt  (ji,jj)       &
+                  &                                                     -          zcu * ( pt  (ji+1,jj) - pt  (ji,jj) ) )   &
+                  &        + z1_6   * zdx2 * ( zcu*zcu - 1._wp ) *     (                   ztu2(ji+1,jj) + ztu2(ji,jj)       &
+                  &                                                     - 0.5_wp * zcu * ( ztu2(ji+1,jj) - ztu2(ji,jj) ) )   &
+                  &        + z1_120 * zdx4 * ( zcu*zcu - 1._wp ) * ( zcu*zcu - 4._wp ) * ( ztu4(ji+1,jj) + ztu4(ji,jj)       &
+                  &                                               - SIGN( 1._wp, zcu ) * ( ztu4(ji+1,jj) - ztu4(ji,jj) ) ) )
+            END DO
+         END DO
+         !
+      END SELECT
+      !
+   END SUBROUTINE ultimate_x
+   
+ 
+   SUBROUTINE ultimate_y( k_order, pdt, pt, pvc, pt_v )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE ultimate_y  ***
+      !!     
+      !! **  Purpose :   compute  
+      !!
+      !! **  Method  :   ... ???
+      !!                 TIM = transient interpolation Modeling 
+      !!
+      !! Reference : Leonard, B.P., 1991, Comput. Methods Appl. Mech. Eng., 88, 17-74. 
+      !!----------------------------------------------------------------------
+      INTEGER                     , INTENT(in   ) ::   k_order   ! ocean time-step index
+      REAL(wp)                    , INTENT(in   ) ::   pdt       ! tracer time-step
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pvc       ! ice j-velocity component
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pt        ! tracer fields
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   pt_v      ! tracer at v-point 
+      !
+      INTEGER  ::   ji, jj       ! dummy loop indices
+      REAL(wp) ::   zcv, zdy2, zdy4    !   -      -
+      REAL(wp), DIMENSION(jpi,jpj) :: ztv1, ztv2, ztv3, ztv4
+      !!----------------------------------------------------------------------
+      !
+      !                                                     !--  Laplacian in j-direction  --!
+      DO jj = 1, jpjm1         ! First derivative (gradient)
+         DO ji = fs_2, fs_jpim1
+            ztv1(ji,jj) = ( pt(ji,jj+1) - pt(ji,jj) ) * r1_e2v(ji,jj) * vmask(ji,jj,1)
+         END DO
+      END DO
+      DO jj = 2, jpjm1         ! Second derivative (Laplacian)
+         DO ji = fs_2, fs_jpim1
+            ztv2(ji,jj) = ( ztv1(ji,jj) - ztv1(ji,jj-1) ) * r1_e2t(ji,jj)
+         END DO
+      END DO
+      CALL lbc_lnk( ztv2, 'T', 1. )
+      !
+      !                                                     !--  BiLaplacian in j-direction  --!
+      DO jj = 1, jpjm1         ! First derivative
+         DO ji = fs_2, fs_jpim1
+            ztv3(ji,jj) = ( ztv2(ji,jj+1) - ztv2(ji,jj) ) * r1_e2v(ji,jj) * vmask(ji,jj,1)
+         END DO
+      END DO
+      DO jj = 2, jpjm1         ! Second derivative
+         DO ji = fs_2, fs_jpim1
+            ztv4(ji,jj) = ( ztv3(ji,jj) - ztv3(ji,jj-1) ) * r1_e2t(ji,jj)
+         END DO
+      END DO
+      CALL lbc_lnk( ztv4, 'T', 1. )
+      !
+      !
+      SELECT CASE (k_order )
+      !
+      CASE( 1 )                                                !==  1st order central TIM  ==! (Eq. 21)
+         DO jj = 1, jpjm1
+            DO ji = fs_2, fs_jpim1
+               pt_v(ji,jj) = 0.5_wp * vmask(ji,jj,1) * (                              ( pt(ji,jj+1) + pt(ji,jj) )  &
+                  &                                     - SIGN( 1._wp, pvc(ji,jj) ) * ( pt(ji,jj+1) - pt(ji,jj) ) )
+            END DO
+         END DO
+         !
+      CASE( 2 )                                                !==  2nd order central TIM  ==! (Eq. 23)
+         DO jj = 1, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zcv  = pvc(ji,jj) * r1_e1v(ji,jj) * pdt * r1_e2v(ji,jj)
+               pt_v(ji,jj) = 0.5_wp * vmask(ji,jj,1) * (        ( pt(ji,jj+1) + pt(ji,jj) )  &
+                  &                                     - zcv * ( pt(ji,jj+1) - pt(ji,jj) ) )
+            END DO
+         END DO
+         CALL lbc_lnk( pt_v(:,:) , 'V',  1. )
+         !
+      CASE( 3 )                                                !==  3rd order central TIM  ==! (Eq. 24)
+         DO jj = 1, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zcv  = pvc(ji,jj) * r1_e1v(ji,jj) * pdt * r1_e2v(ji,jj)
+               zdy2 = e2v(ji,jj) * e2v(ji,jj)
+!!rachid       zdy2 = e2v(ji,jj) * e2t(ji,jj)
+               pt_v(ji,jj) = 0.5_wp * vmask(ji,jj,1) * (                                 ( pt  (ji,jj+1) + pt  (ji,jj)       &
+                  &                                     -                        zcv   * ( pt  (ji,jj+1) - pt  (ji,jj) ) )   &
+                  &        + z1_6 * zdy2 * ( zcv*zcv - 1._wp ) * (                         ztv2(ji,jj+1) + ztv2(ji,jj)       &
+                  &                                               - SIGN( 1._wp, zcv ) * ( ztv2(ji,jj+1) - ztv2(ji,jj) ) ) )
+            END DO
+         END DO
+         !
+      CASE( 4 )                                                !==  4th order central TIM  ==! (Eq. 27)
+         DO jj = 1, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zcv  = pvc(ji,jj) * r1_e1v(ji,jj) * pdt * r1_e2v(ji,jj)
+               zdy2 = e2v(ji,jj) * e2v(ji,jj)
+!!rachid       zdy2 = e2v(ji,jj) * e2t(ji,jj)
+               pt_v(ji,jj) = 0.5_wp * vmask(ji,jj,1) * (                           ( pt  (ji,jj+1) + pt  (ji,jj)       &
+                  &                                               -          zcv * ( pt  (ji,jj+1) - pt  (ji,jj) ) )   &
+                  &        + z1_6 * zdy2 * ( zcv*zcv - 1._wp ) * (                   ztv2(ji,jj+1) + ztv2(ji,jj)       &
+                  &                                               - 0.5_wp * zcv * ( ztv2(ji,jj+1) - ztv2(ji,jj) ) ) )
+            END DO
+         END DO
+         !
+      CASE( 5 )                                                !==  5th order central TIM  ==! (Eq. 29)
+         DO jj = 1, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zcv  = pvc(ji,jj) * r1_e1v(ji,jj) * pdt * r1_e2v(ji,jj)
+               zdy2 = e2v(ji,jj) * e2v(ji,jj)
+!!rachid       zdy2 = e2v(ji,jj) * e2t(ji,jj)
+               zdy4 = zdy2 * zdy2
+               pt_v(ji,jj) = 0.5_wp * vmask(ji,jj,1) * (                                 ( pt  (ji,jj+1) + pt  (ji,jj)      &
+                  &                                                     -          zcv * ( pt  (ji,jj+1) - pt  (ji,jj) ) )  &
+                  &        + z1_6   * zdy2 * ( zcv*zcv - 1._wp ) *     (                   ztv2(ji,jj+1) + ztv2(ji,jj)      &
+                  &                                                     - 0.5_wp * zcv * ( ztv2(ji,jj+1) - ztv2(ji,jj) ) )  &
+                  &        + z1_120 * zdy4 * ( zcv*zcv - 1._wp ) * ( zcv*zcv - 4._wp ) * ( ztv4(ji,jj+1) + ztv4(ji,jj)      &
+                  &                                               - SIGN( 1._wp, zcv ) * ( ztv4(ji,jj+1) - ztv4(ji,jj) ) ) )
+            END DO
+         END DO
+         !
+      END SELECT
+      !
+   END SUBROUTINE ultimate_y
+   
+  
+   SUBROUTINE nonosc_2d( pbef, paa, pbb, paft, pdt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE nonosc  ***
+      !!     
+      !! **  Purpose :   compute monotonic tracer fluxes from the upstream 
+      !!       scheme and the before field by a nonoscillatory algorithm 
+      !!
+      !! **  Method  :   ... ???
+      !!       warning : pbef and paft must be masked, but the boundaries
+      !!       conditions on the fluxes are not necessary zalezak (1979)
+      !!       drange (1995) multi-dimensional forward-in-time and upstream-
+      !!       in-space based differencing for fluid
+      !!----------------------------------------------------------------------
+      REAL(wp)                     , INTENT(in   ) ::   pdt          ! tracer time-step
+      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   pbef, paft   ! before & after field
+      REAL(wp), DIMENSION (jpi,jpj), INTENT(inout) ::   paa, pbb     ! monotonic fluxes in the 2 directions
+      !
+      INTEGER  ::   ji, jj    ! dummy loop indices
+      INTEGER  ::   ikm1      ! local integer
+      REAL(wp) ::   zpos, zneg, zbt, za, zb, zc, zbig, zsml, z1_dt   ! local scalars
+      REAL(wp) ::   zau, zbu, zcu, zav, zbv, zcv, zup, zdo            !   -      -
+      REAL(wp), DIMENSION(jpi,jpj) :: zbetup, zbetdo, zbup, zbdo, zmsk, zdiv
+      !!----------------------------------------------------------------------
+      !
+      zbig = 1.e+40_wp
+      zsml = 1.e-15_wp
+
+      ! test on divergence
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.  
+            zdiv(ji,jj) =  - (  paa(ji,jj) - paa(ji-1,jj  )   &
+               &              + pbb(ji,jj) - pbb(ji  ,jj-1) )  
+         END DO
+      END DO
+      CALL lbc_lnk( zdiv, 'T', 1. )        ! Lateral boundary conditions   (unchanged sign)
+
+      ! Determine ice masks for before and after tracers 
+      WHERE( pbef(:,:) == 0._wp .AND. paft(:,:) == 0._wp .AND. zdiv(:,:) == 0._wp )   ;   zmsk(:,:) = 0._wp
+      ELSEWHERE                                                                       ;   zmsk(:,:) = 1._wp * tmask(:,:,1)
+      END WHERE
+
+      ! Search local extrema
+      ! --------------------
+      ! max/min of pbef & paft with large negative/positive value (-/+zbig) inside land
+!      zbup(:,:) = MAX( pbef(:,:) * tmask(:,:,1) - zbig * ( 1.e0 - tmask(:,:,1) ),   &
+!         &             paft(:,:) * tmask(:,:,1) - zbig * ( 1.e0 - tmask(:,:,1) )  )
+!      zbdo(:,:) = MIN( pbef(:,:) * tmask(:,:,1) + zbig * ( 1.e0 - tmask(:,:,1) ),   &
+!         &             paft(:,:) * tmask(:,:,1) + zbig * ( 1.e0 - tmask(:,:,1) )  )
+      zbup(:,:) = MAX( pbef(:,:) * zmsk(:,:) - zbig * ( 1.e0 - zmsk(:,:) ),   &
+         &             paft(:,:) * zmsk(:,:) - zbig * ( 1.e0 - zmsk(:,:) )  )
+      zbdo(:,:) = MIN( pbef(:,:) * zmsk(:,:) + zbig * ( 1.e0 - zmsk(:,:) ),   &
+         &             paft(:,:) * zmsk(:,:) + zbig * ( 1.e0 - zmsk(:,:) )  )
+
+      z1_dt = 1._wp / pdt
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            !
+            zup  = MAX(   zbup(ji,jj), zbup(ji-1,jj  ), zbup(ji+1,jj  ),   &        ! search max/min in neighbourhood
+               &                       zbup(ji  ,jj-1), zbup(ji  ,jj+1)    )
+            zdo  = MIN(   zbdo(ji,jj), zbdo(ji-1,jj  ), zbdo(ji+1,jj  ),   &
+               &                       zbdo(ji  ,jj-1), zbdo(ji  ,jj+1)    )
+               !
+            zpos = MAX( 0., paa(ji-1,jj  ) ) - MIN( 0., paa(ji  ,jj  ) )   &        ! positive/negative  part of the flux
+               & + MAX( 0., pbb(ji  ,jj-1) ) - MIN( 0., pbb(ji  ,jj  ) )
+            zneg = MAX( 0., paa(ji  ,jj  ) ) - MIN( 0., paa(ji-1,jj  ) )   &
+               & + MAX( 0., pbb(ji  ,jj  ) ) - MIN( 0., pbb(ji  ,jj-1) )
+               !
+            zbt = e1e2t(ji,jj) * z1_dt                                   ! up & down beta terms
+            zbetup(ji,jj) = ( zup         - paft(ji,jj) ) / ( zpos + zsml ) * zbt
+            zbetdo(ji,jj) = ( paft(ji,jj) - zdo         ) / ( zneg + zsml ) * zbt
+         END DO
+      END DO
+      CALL lbc_lnk_multi( zbetup, 'T', 1., zbetdo, 'T', 1. )   ! lateral boundary cond. (unchanged sign)
+
+      ! monotonic flux in the i & j direction (paa & pbb)
+      ! -------------------------------------
+      DO jj = 2, jpjm1
+         DO ji = 1, fs_jpim1   ! vector opt.
+            zau = MIN( 1._wp , zbetdo(ji,jj) , zbetup(ji+1,jj) )
+            zbu = MIN( 1._wp , zbetup(ji,jj) , zbetdo(ji+1,jj) )
+            zcu = 0.5  + SIGN( 0.5 , paa(ji,jj) )
+            !
+            paa(ji,jj) = paa(ji,jj) * ( zcu * zau + ( 1._wp - zcu) * zbu )
+         END DO
+      END DO
+      !
+      DO jj = 1, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zav = MIN( 1._wp , zbetdo(ji,jj) , zbetup(ji,jj+1) )
+            zbv = MIN( 1._wp , zbetup(ji,jj) , zbetdo(ji,jj+1) )
+            zcv = 0.5  + SIGN( 0.5 , pbb(ji,jj) )
+            !
+            pbb(ji,jj) = pbb(ji,jj) * ( zcv * zav + ( 1._wp - zcv) * zbv )
+         END DO
+      END DO
+      !
+   END SUBROUTINE nonosc_2d
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option           Dummy module         NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icedyn_adv_umx
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rdgrft.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rdgrft.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rdgrft.F90	(revision 9019)
@@ -0,0 +1,940 @@
+MODULE icedyn_rdgrft
+   !!======================================================================
+   !!                       ***  MODULE icedyn_rdgrft ***
+   !!    sea-ice : Mechanical impact on ice thickness distribution      
+   !!======================================================================
+   !! History :  LIM  ! 2006-02  (M. Vancoppenolle) Original code 
+   !!            3.2  ! 2009-07  (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in smsw & sfx_dyn
+   !!            4.0  ! 2011-02  (G. Madec) dynamical allocation
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_dyn_rdgrft       : ridging/rafting of sea ice
+   !!   ice_dyn_rdgrft_init  : initialization of ridging/rafting of sea ice
+   !!   ice_strength         : ice strength calculation
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean domain
+   USE phycst         ! physical constants (ocean directory) 
+   USE sbc_oce , ONLY : sss_m, sst_m   ! surface boundary condition: ocean fields
+   USE ice1D          ! sea-ice: thermodynamics
+   USE ice            ! sea-ice: variables
+   USE icetab         ! sea-ice: 1D <==> 2D transformation
+   USE icevar         ! sea-ice: operations
+   USE icectl         ! sea-ice: control prints
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE lbclnk         ! lateral boundary conditions (or mpp links)
+   USE timing         ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_dyn_rdgrft        ! called by icestp
+   PUBLIC   ice_dyn_rdgrft_init   ! called by icedyn
+   PUBLIC   ice_strength          ! called by icedyn_rhg_evp
+
+   ! Variables shared among ridging subroutines
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::   closing_net     ! net rate at which area is removed    (1/s)
+      !                                                 ! (ridging ice area - area of new ridges) / dt
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:)   ::   opning         ! rate of opening due to divergence/shear
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:)   ::   closing_gross  ! rate at which area removed, not counting area of new ridges
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   apartf   ! participation function; fraction of ridging/closing associated w/ category n
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hrmin    ! minimum ridge thickness
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hrmax    ! maximum ridge thickness
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hraft    ! thickness of rafted ice
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hi_hrdg  ! thickness of ridging ice / mean ridge thickness
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   aridge   ! participating ice ridging
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   araft    ! participating ice rafting
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ze_i_2d
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ze_s_2d
+   !
+   REAL(wp), PARAMETER ::   hrdg_hi_min = 1.1_wp    ! min ridge thickness multiplier: min(hrdg/hi)
+   REAL(wp), PARAMETER ::   hi_hrft     = 0.5_wp    ! rafting multipliyer: (hi/hraft)
+   !
+   ! ** namelist (namdyn_rdgrft) **
+   LOGICAL  ::   ln_str_H79       ! ice strength parameterization (Hibler79)
+   REAL(wp) ::   rn_pstar         ! determines ice strength, Hibler JPO79
+   REAL(wp) ::   rn_crhg          ! determines changes in ice strength
+   REAL(wp) ::   rn_csrdg         ! fraction of shearing energy contributing to ridging            
+   LOGICAL  ::   ln_partf_lin     ! participation function linear (Thorndike et al. (1975))
+   REAL(wp) ::   rn_gstar         !    fractional area of young ice contributing to ridging
+   LOGICAL  ::   ln_partf_exp     ! participation function exponential (Lipscomb et al. (2007))
+   REAL(wp) ::   rn_astar         !    equivalent of G* for an exponential participation function
+   LOGICAL  ::   ln_ridging       ! ridging of ice or not                        
+   REAL(wp) ::   rn_hstar         !    thickness that determines the maximal thickness of ridged ice
+   REAL(wp) ::   rn_porordg       !    initial porosity of ridges (0.3 regular value)
+   REAL(wp) ::   rn_fsnwrdg       !    fractional snow loss to the ocean during ridging
+   REAL(wp) ::   rn_fpndrdg       !    fractional pond loss to the ocean during ridging
+   LOGICAL  ::   ln_rafting       ! rafting of ice or not                        
+   REAL(wp) ::   rn_hraft         !    threshold thickness (m) for rafting / ridging 
+   REAL(wp) ::   rn_craft         !    coefficient for smoothness of the hyperbolic tangent in rafting
+   REAL(wp) ::   rn_fsnwrft       !    fractional snow loss to the ocean during rafting
+   REAL(wp) ::   rn_fpndrft       !    fractional pond loss to the ocean during rafting
+   !
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icedyn_rdgrft.F90 8378 2017-07-26 13:55:59Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION ice_dyn_rdgrft_alloc()
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_dyn_rdgrft_alloc ***
+      !!-------------------------------------------------------------------
+      ALLOCATE( closing_net(jpij), opning(jpij)   , closing_gross(jpij),   &
+         &      apartf(jpij,0:jpl), hrmin(jpij,jpl), hraft(jpij,jpl)    , aridge(jpij,jpl),   &
+         &      hrmax(jpij,jpl), hi_hrdg(jpij,jpl)  , araft (jpij,jpl),  &
+         &      ze_i_2d(jpij,nlay_i,jpl), ze_s_2d(jpij,nlay_s,jpl), STAT=ice_dyn_rdgrft_alloc )
+
+      IF( lk_mpp                    )   CALL mpp_sum ( ice_dyn_rdgrft_alloc )
+      IF( ice_dyn_rdgrft_alloc /= 0 )   CALL ctl_warn( 'ice_dyn_rdgrft_alloc: failed to allocate arrays' )
+      !
+   END FUNCTION ice_dyn_rdgrft_alloc
+
+
+   SUBROUTINE ice_dyn_rdgrft( kt )
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_dyn_rdgrft ***
+      !!
+      !! ** Purpose :   computes the mechanical redistribution of ice thickness
+      !!
+      !! ** Method  :   Steps :
+      !!       1) Thickness categories boundaries, ice / o.w. concentrations
+      !!          Ridge preparation
+      !!       2) Dynamical inputs (closing rate, divu_adv, opning)
+      !!       3) Ridging iteration
+      !!       4) Ridging diagnostics
+      !!       5) Heat, salt and freshwater fluxes
+      !!       6) Compute increments of tate variables and come back to old values
+      !!
+      !! References :   Flato, G. M., and W. D. Hibler III, 1995, JGR, 100, 18,611-18,626.
+      !!                Hibler, W. D. III, 1980, MWR, 108, 1943-1973, 1980.
+      !!                Rothrock, D. A., 1975: JGR, 80, 4514-4519.
+      !!                Thorndike et al., 1975, JGR, 80, 4501-4513. 
+      !!                Bitz et al., JGR, 2001
+      !!                Amundrud and Melling, JGR 2005
+      !!                Babko et al., JGR 2002 
+      !!
+      !!     This routine is based on CICE code and authors William H. Lipscomb,
+      !!  and Elizabeth C. Hunke, LANL are gratefully acknowledged
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! number of iteration
+      !!
+      INTEGER  ::   ji, jj, jk, jl             ! dummy loop index
+      INTEGER  ::   iter, iterate_ridging      ! local integer 
+      INTEGER  ::   ipti                       ! local integer
+      REAL(wp) ::   zfac                       ! local scalar
+      INTEGER , DIMENSION(jpij) ::   iptidx        ! compute ridge/raft or not
+      REAL(wp), DIMENSION(jpij) ::   zdivu_adv     ! divu as implied by transport scheme  (1/s)
+      REAL(wp), DIMENSION(jpij) ::   zdivu, zdelt  ! 1D divu_i & delta_i
+      !
+      INTEGER, PARAMETER ::   jp_itermax = 20    
+      !!-------------------------------------------------------------------
+      ! controls
+      IF( nn_timing == 1 )   CALL timing_start('icedyn_rdgrft')                                                             ! timing
+      IF( ln_icediachk   )   CALL ice_cons_hsm(0, 'icedyn_rdgrft', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*)'ice_dyn_rdgrft: ice ridging and rafting'
+         IF(lwp) WRITE(numout,*)'~~~~~~~~~~~~~~'
+      ENDIF      
+
+      CALL ice_var_zapsmall   ! Zero out categories with very small areas
+
+      !--------------------------------
+      ! 0) Identify grid cells with ice
+      !--------------------------------
+      npti = 0   ;   nptidx(:) = 0
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF ( SUM(a_i(ji,jj,:)) > 0._wp ) THEN
+               npti           = npti + 1
+               nptidx( npti ) = (jj - 1) * jpi + ji
+            ENDIF
+         END DO
+      END DO
+
+      IF( npti > 0 ) THEN
+        
+         ! just needed here
+         CALL tab_2d_1d( npti, nptidx(1:npti), zdivu(1:npti), divu_i(:,:) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), zdelt(1:npti), delta_i(:,:) )
+         ! needed here and in the iteration loop
+         CALL tab_3d_2d( npti, nptidx(1:npti), a_i_2d  (1:npti,1:jpl), a_i(:,:,:) )
+         CALL tab_3d_2d( npti, nptidx(1:npti), v_i_2d  (1:npti,1:jpl), v_i(:,:,:) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), ato_i_1d(1:npti)      , ato_i(:,:) )
+
+         DO ji = 1, npti
+            !-----------------------------------------------------------------------------!
+            ! 2) Dynamical inputs (closing rate, divu_adv, opning)
+            !-----------------------------------------------------------------------------!
+            !
+            ! 2.1 closing_net
+            !-----------------
+            ! Compute the net rate of closing due to convergence 
+            ! and shear, based on Flato and Hibler (1995).
+            ! 
+            ! The energy dissipation rate is equal to the net closing rate
+            ! times the ice strength.
+            !
+            ! NOTE: The NET closing rate is equal to the rate that open water 
+            !  area is removed, plus the rate at which ice area is removed by 
+            !  ridging, minus the rate at which area is added in new ridges.
+            !  The GROSS closing rate is equal to the first two terms (open
+            !  water closing and thin ice ridging) without the third term
+            !  (thick, newly ridged ice).
+
+            closing_net(ji) = rn_csrdg * 0.5_wp * ( zdelt(ji) - ABS( zdivu(ji) ) ) - MIN( zdivu(ji), 0._wp )
+
+            ! 2.2 divu_adv
+            !--------------
+            ! Compute divu_adv, the divergence rate given by the transport/
+            ! advection scheme, which may not be equal to divu as computed 
+            ! from the velocity field.
+            !
+            ! If divu_adv < 0, make sure the closing rate is large enough
+            ! to give asum = 1.0 after ridging.
+            zdivu_adv(ji) = ( 1._wp - ato_i_1d(ji) - SUM( a_i_2d(ji,:) ) ) * r1_rdtice
+
+            IF( zdivu_adv(ji) < 0._wp )   closing_net(ji) = MAX( closing_net(ji), -zdivu_adv(ji) )
+
+            ! 2.3 opning
+            !------------
+            ! Compute the (non-negative) opening rate that will give asum = 1.0 after ridging.
+            opning(ji) = closing_net(ji) + zdivu_adv(ji)
+         END DO
+
+         !
+         !------------------------------------------------
+         ! 2.1) Identify grid cells with nonzero ridging
+         !------------------------------------------------
+         CALL rdgrft_prep( a_i_2d, v_i_2d, ato_i_1d )
+         ipti = 0 ; iptidx(:) = 0
+         DO ji = 1, npti
+            IF( SUM( ABS(apartf(ji,1:jpl)) ) > 0._wp .AND. closing_gross(ji) > 0._wp ) THEN
+               ipti = ipti + 1
+               iptidx     (ipti)   = nptidx     (ji)
+               a_i_2d     (ipti,:) = a_i_2d     (ji,:)  ! adjust to new indices
+               v_i_2d     (ipti,:) = v_i_2d     (ji,:)  ! adjust to new indices
+               ato_i_1d   (ipti)   = ato_i_1d   (ji)    ! adjust to new indices
+               closing_net(ipti)   = closing_net(ji)    ! adjust to new indices
+               zdivu_adv  (ipti)   = zdivu_adv  (ji)    ! adjust to new indices
+               opning     (ipti)   = opning     (ji)    ! adjust to new indices
+            ENDIF
+         END DO
+         nptidx(:) = iptidx(:)
+         npti      = ipti
+
+      ENDIF
+
+      !--------------
+      ! Start ridging
+      !--------------
+      IF( npti > 0 ) THEN
+         
+         !-----------
+         ! 2D <==> 1D
+         !-----------
+         ! fields used but not modified
+         CALL tab_2d_1d( npti, nptidx(1:npti), sss_1d(1:npti), sss_m(:,:) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), sst_1d(1:npti), sst_m(:,:) )
+         ! the following fields are modified in this routine
+         !!CALL tab_2d_1d( npti, nptidx(1:npti), ato_i_1d(1:npti), ato_i(:,:) )
+         !!CALL tab_3d_2d( npti, nptidx(1:npti), a_i_2d(1:npti,1:jpl), a_i(:,:,:) )
+         !!CALL tab_3d_2d( npti, nptidx(1:npti), v_i_2d  (1:npti,1:jpl), v_i  (:,:,:) )
+         CALL tab_3d_2d( npti, nptidx(1:npti), v_s_2d (1:npti,1:jpl), v_s (:,:,:) )
+         CALL tab_3d_2d( npti, nptidx(1:npti), sv_i_2d(1:npti,1:jpl), sv_i(:,:,:) )
+         CALL tab_3d_2d( npti, nptidx(1:npti), oa_i_2d(1:npti,1:jpl), oa_i(:,:,:) )
+         CALL tab_3d_2d( npti, nptidx(1:npti), a_ip_2d(1:npti,1:jpl), a_ip(:,:,:) )
+         CALL tab_3d_2d( npti, nptidx(1:npti), v_ip_2d(1:npti,1:jpl), v_ip(:,:,:) )
+         DO jl = 1, jpl
+            DO jk = 1, nlay_s
+               CALL tab_2d_1d( npti, nptidx(1:npti), ze_s_2d(1:npti,jk,jl), e_s(:,:,jk,jl) )
+            END DO
+            DO jk = 1, nlay_i
+               CALL tab_2d_1d( npti, nptidx(1:npti), ze_i_2d(1:npti,jk,jl), e_i(:,:,jk,jl) )
+            END DO
+         END DO
+         CALL tab_2d_1d( npti, nptidx(1:npti), sfx_dyn_1d    (1:npti), sfx_dyn    (:,:) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), sfx_bri_1d    (1:npti), sfx_bri    (:,:) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_dyn_1d    (1:npti), wfx_dyn    (:,:) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), hfx_dyn_1d    (1:npti), hfx_dyn    (:,:) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_snw_dyn_1d(1:npti), wfx_snw_dyn(:,:) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_pnd_1d(1:npti), wfx_pnd(:,:) )
+         
+         !-----------------------------------------------------------------------------!
+         ! 3) Ridging iteration
+         !-----------------------------------------------------------------------------!
+         iter            = 1
+         iterate_ridging = 1      
+         DO WHILE( iterate_ridging > 0 .AND. iter < jp_itermax )
+
+            CALL rdgrft_prep( a_i_2d, v_i_2d, ato_i_1d )
+
+            ! 3.2 Redistribute area, volume, and energy.
+            !-----------------------------------------------------------------------------!
+            CALL rdgrft_shift
+
+            ! 3.4 Do we keep on iterating?
+            !-----------------------------------------------------------------------------!
+            ! Check whether asum = 1.  If not (because the closing and opening
+            ! rates were reduced above), ridge again with new rates.
+            iterate_ridging = 0
+            DO ji = 1, npti
+               zfac = 1._wp - ( ato_i_1d(ji) + SUM( a_i_2d(ji,:) ) )
+               IF( ABS( zfac ) < epsi10 ) THEN
+                  closing_net(ji) = 0._wp
+                  opning     (ji) = 0._wp
+                  ato_i_1d   (ji) = MAX( 0._wp, 1._wp - SUM( a_i_2d(ji,:) ) )
+               ELSE
+                  iterate_ridging  = 1
+                  zdivu_adv  (ji) = zfac * r1_rdtice
+                  closing_net(ji) = MAX( 0._wp, -zdivu_adv(ji) )
+                  opning     (ji) = MAX( 0._wp,  zdivu_adv(ji) )
+               ENDIF
+            END DO
+            !
+            iter = iter + 1
+            IF( iter  >  jp_itermax )    CALL ctl_warn( 'icedyn_rdgrft: non-converging ridging scheme' )
+            !
+         END DO
+
+         !-----------
+         ! 1D <==> 2D
+         !-----------
+         CALL tab_1d_2d( npti, nptidx(1:npti), ato_i_1d(1:npti), ato_i(:,:) )
+         CALL tab_2d_3d( npti, nptidx(1:npti), a_i_2d (1:npti,1:jpl), a_i (:,:,:) )
+         CALL tab_2d_3d( npti, nptidx(1:npti), v_i_2d (1:npti,1:jpl), v_i (:,:,:) )
+         CALL tab_2d_3d( npti, nptidx(1:npti), v_s_2d (1:npti,1:jpl), v_s (:,:,:) )
+         CALL tab_2d_3d( npti, nptidx(1:npti), sv_i_2d(1:npti,1:jpl), sv_i(:,:,:) )
+         CALL tab_2d_3d( npti, nptidx(1:npti), oa_i_2d(1:npti,1:jpl), oa_i(:,:,:) )
+         CALL tab_2d_3d( npti, nptidx(1:npti), a_ip_2d(1:npti,1:jpl), a_ip(:,:,:) )
+         CALL tab_2d_3d( npti, nptidx(1:npti), v_ip_2d(1:npti,1:jpl), v_ip(:,:,:) )
+         DO jl = 1, jpl
+            DO jk = 1, nlay_s
+               CALL tab_1d_2d( npti, nptidx(1:npti), ze_s_2d(1:npti,jk,jl), e_s(:,:,jk,jl) )
+            END DO
+            DO jk = 1, nlay_i
+               CALL tab_1d_2d( npti, nptidx(1:npti), ze_i_2d(1:npti,jk,jl), e_i(:,:,jk,jl) )
+            END DO
+         END DO
+         CALL tab_1d_2d( npti, nptidx(1:npti), sfx_dyn_1d    (1:npti), sfx_dyn    (:,:) )
+         CALL tab_1d_2d( npti, nptidx(1:npti), sfx_bri_1d    (1:npti), sfx_bri    (:,:) )
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_dyn_1d    (1:npti), wfx_dyn    (:,:) )
+         CALL tab_1d_2d( npti, nptidx(1:npti), hfx_dyn_1d    (1:npti), hfx_dyn    (:,:) )
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_snw_dyn_1d(1:npti), wfx_snw_dyn(:,:) )
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_pnd_1d(1:npti), wfx_pnd(:,:) )
+
+      ENDIF ! npti > 0
+   
+      CALL ice_var_agg( 1 ) 
+
+      ! controls
+      IF( ln_icediachk   )   CALL ice_cons_hsm(1, 'icedyn_rdgrft', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
+      IF( ln_ctl         )   CALL ice_prt3D   ('icedyn_rdgrft')                                                             ! prints
+      IF( nn_timing == 1 )   CALL timing_stop ('icedyn_rdgrft')                                                             ! timing
+      !
+   END SUBROUTINE ice_dyn_rdgrft
+
+
+   SUBROUTINE rdgrft_prep( pa_i, pv_i, pato_i )
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE rdgrft_prep ***
+      !!
+      !! ** Purpose :   preparation for ridging calculations
+      !!
+      !! ** Method  :   Compute the thickness distribution of the ice and open water 
+      !!              participating in ridging and of the resulting ridges.
+      !!-------------------------------------------------------------------
+      REAL(wp), DIMENSION(:)  , INTENT(in) ::   pato_i 
+      REAL(wp), DIMENSION(:,:), INTENT(in) ::   pa_i, pv_i 
+      !!
+      INTEGER  ::   ji, jl                     ! dummy loop indices
+      REAL(wp) ::   z1_gstar, z1_astar, zhmean, zfac   ! local scalar
+      REAL(wp), DIMENSION(jpij)        ::   zasum, z1_asum, zaksum   ! sum of a_i+ato_i and reverse 
+      REAL(wp), DIMENSION(jpij,jpl)    ::   zhi                      ! ice thickness
+      REAL(wp), DIMENSION(jpij,-1:jpl) ::   zGsum                    ! zGsum(n) = sum of areas in categories 0 to n
+      !--------------------------------------------------------------------
+
+      z1_gstar = 1._wp / rn_gstar
+      z1_astar = 1._wp / rn_astar
+
+      !                       ! Ice thickness needed for rafting
+      WHERE( pa_i(1:npti,:) > 0._wp )   ;   zhi(1:npti,:) = pv_i(1:npti,:) / pa_i(1:npti,:)
+      ELSEWHERE                         ;   zhi(1:npti,:) = 0._wp
+      END WHERE
+
+      !-----------------------------------------------------------------
+      ! 1) Participation function: a(h) = b(h).g(h) (apartf)
+      !-----------------------------------------------------------------
+      ! Compute the participation function apartf; this is analogous to
+      ! a(h) = b(h)g(h) as defined in Thorndike et al. (1975).
+      ! area lost from category n due to ridging/closing
+      ! apartf(n)   = total area lost due to ridging/closing
+      ! assume b(h) = (2/Gstar) * (1 - G(h)/Gstar). 
+      !
+      ! The expressions for apartf are found by integrating b(h)g(h) between
+      ! the category boundaries.
+      ! apartf is always >= 0 and SUM(apartf(0:jpl))=1
+      !-----------------------------------------------------------------
+      !
+      ! Compute total area of ice plus open water.
+      ! This is in general not equal to one because of divergence during transport
+      zasum(1:npti) = pato_i(1:npti) + SUM( pa_i(1:npti,:), dim=2 )
+      !
+      WHERE( zasum(1:npti) > 0._wp )   ;   z1_asum(1:npti) = 1._wp / zasum(1:npti)
+      ELSEWHERE                        ;   z1_asum(1:npti) = 0._wp
+      END WHERE
+      ! Compute cumulative thickness distribution function
+      ! Compute the cumulative thickness distribution function zGsum,
+      ! where zGsum(n) is the fractional area in categories 0 to n.
+      ! initial value (in h = 0) equals open water area
+      zGsum(1:npti,-1) = 0._wp
+      zGsum(1:npti,0 ) = pato_i(1:npti) * z1_asum(1:npti)
+      DO jl = 1, jpl
+         zGsum(1:npti,jl) = ( pato_i(1:npti) + SUM( pa_i(1:npti,1:jl), dim=2 ) ) * z1_asum(1:npti)  ! sum(1:jl) is ok (and not jpl)
+      END DO
+      !
+      IF( ln_partf_lin ) THEN          !--- Linear formulation (Thorndike et al., 1975)
+         DO jl = 0, jpl    
+            DO ji = 1, npti
+               IF    ( zGsum(ji,jl)   < rn_gstar ) THEN
+                  apartf(ji,jl) = z1_gstar * ( zGsum(ji,jl) - zGsum(ji,jl-1) ) * &
+                     &                       ( 2._wp - ( zGsum(ji,jl-1) + zGsum(ji,jl) ) * z1_gstar )
+               ELSEIF( zGsum(ji,jl-1) < rn_gstar ) THEN
+                  apartf(ji,jl) = z1_gstar * ( rn_gstar     - zGsum(ji,jl-1) ) *  &
+                     &                       ( 2._wp - ( zGsum(ji,jl-1) + rn_gstar        ) * z1_gstar )
+               ELSE
+                  apartf(ji,jl) = 0._wp
+               ENDIF
+            END DO
+         END DO
+         !
+      ELSEIF( ln_partf_exp ) THEN      !--- Exponential, more stable formulation (Lipscomb et al, 2007)
+         !                        
+         zfac = 1._wp / ( 1._wp - EXP(-z1_astar) )
+         DO jl = -1, jpl
+            DO ji = 1, npti
+               zGsum(ji,jl) = EXP( -zGsum(ji,jl) * z1_astar ) * zfac
+            END DO
+         END DO
+         DO jl = 0, jpl
+            DO ji = 1, npti
+               apartf(ji,jl) = zGsum(ji,jl-1) - zGsum(ji,jl)
+            END DO
+         END DO
+         !
+      ENDIF
+
+      !                                !--- Ridging and rafting participation concentrations
+      IF( ln_rafting .AND. ln_ridging ) THEN             !- ridging & rafting
+         DO jl = 1, jpl
+            DO ji = 1, npti
+               aridge(ji,jl) = ( 1._wp + TANH ( rn_craft * ( zhi(ji,jl) - rn_hraft ) ) ) * 0.5_wp * apartf(ji,jl)
+               araft (ji,jl) = apartf(ji,jl) - aridge(ji,jl)
+            END DO
+         END DO
+      ELSEIF( ln_ridging .AND. .NOT. ln_rafting ) THEN   !- ridging alone
+         DO jl = 1, jpl
+            DO ji = 1, npti
+               aridge(ji,jl) = apartf(ji,jl)
+               araft (ji,jl) = 0._wp
+            END DO
+         END DO
+      ELSEIF( ln_rafting .AND. .NOT. ln_ridging ) THEN   !- rafting alone   
+         DO jl = 1, jpl
+            DO ji = 1, npti
+               aridge(ji,jl) = 0._wp
+               araft (ji,jl) = apartf(ji,jl)
+            END DO
+         END DO
+      ELSE                                               !- no ridging & no rafting
+         DO jl = 1, jpl
+            DO ji = 1, npti
+               aridge(ji,jl) = 0._wp
+               araft (ji,jl) = 0._wp         
+            END DO
+         END DO
+      ENDIF
+
+      !-----------------------------------------------------------------
+      ! 2) Transfer function
+      !-----------------------------------------------------------------
+      ! Compute max and min ridged ice thickness for each ridging category.
+      ! Assume ridged ice is uniformly distributed between hrmin and hrmax.
+      ! 
+      ! This parameterization is a modified version of Hibler (1980).
+      ! The mean ridging thickness, zhmean, is proportional to hi^(0.5)
+      !  and for very thick ridging ice must be >= hrdg_hi_min*hi
+      !
+      ! The minimum ridging thickness, hrmin, is equal to 2*hi 
+      !  (i.e., rafting) and for very thick ridging ice is
+      !  constrained by hrmin <= (zhmean + hi)/2.
+      ! 
+      ! The maximum ridging thickness, hrmax, is determined by
+      !  zhmean and hrmin.
+      !
+      ! These modifications have the effect of reducing the ice strength
+      ! (relative to the Hibler formulation) when very thick ice is
+      ! ridging.
+      !
+      ! zaksum = net area removed/ total area removed
+      ! where total area removed = area of ice that ridges
+      !         net area removed = total area removed - area of new ridges
+      !-----------------------------------------------------------------
+
+      zfac = 1._wp / hi_hrft
+      zaksum(1:npti) = apartf(1:npti,0)
+      ! Transfer function
+      DO jl = 1, jpl !all categories have a specific transfer function
+         DO ji = 1, npti
+            IF ( apartf(ji,jl) > 0._wp ) THEN
+               zhmean         = MAX( SQRT( rn_hstar * zhi(ji,jl) ), zhi(ji,jl) * hrdg_hi_min )
+               hrmin  (ji,jl) = MIN( 2._wp * zhi(ji,jl), 0.5_wp * ( zhmean + zhi(ji,jl) ) )
+               hrmax  (ji,jl) = 2._wp * zhmean - hrmin(ji,jl)
+               hraft  (ji,jl) = zhi(ji,jl) * zfac
+               hi_hrdg(ji,jl) = zhi(ji,jl) / MAX( zhmean, epsi20 )
+               !
+               ! Normalization factor : zaksum, ensures mass conservation
+               zaksum(ji) = zaksum(ji) + aridge(ji,jl) * ( 1._wp - hi_hrdg(ji,jl) )    &
+                  &                    + araft (ji,jl) * ( 1._wp - hi_hrft )
+            ELSE
+               hrmin  (ji,jl) = 0._wp 
+               hrmax  (ji,jl) = 0._wp 
+               hraft  (ji,jl) = 0._wp 
+               hi_hrdg(ji,jl) = 1._wp
+            ENDIF
+         END DO
+      END DO
+      !
+      ! 3.1 closing_gross
+      !-----------------------------------------------------------------------------!
+      ! Based on the ITD of ridging and ridged ice, convert the net
+      !  closing rate to a gross closing rate.  
+      ! NOTE: 0 < aksum <= 1
+      WHERE( zaksum(1:npti) > 0._wp )   ;   closing_gross(1:npti) = closing_net(1:npti) / zaksum(1:npti)
+      ELSEWHERE                         ;   closing_gross(1:npti) = 0._wp
+      END WHERE
+      
+      DO ji = 1, npti  
+         ! correction to closing rate and opening if closing rate is excessive
+         !---------------------------------------------------------------------
+         ! Reduce the closing rate if more than 100% of the open water 
+         ! would be removed.  Reduce the opening rate proportionately.
+         zfac = ( opning(ji) - apartf(ji,0) * closing_gross(ji) ) * rdt_ice
+         IF    ( zfac < 0._wp .AND. zfac > - pato_i(ji) ) THEN                  ! would lead to negative ato_i
+            opning(ji) = apartf(ji,0) * closing_gross(ji) - pato_i(ji) * r1_rdtice 
+         ELSEIF( zfac > 0._wp .AND. zfac > ( zasum(ji) - pato_i(ji) ) ) THEN  ! would lead to ato_i > asum
+            opning(ji) = apartf(ji,0) * closing_gross(ji) + ( zasum(ji) - pato_i(ji) ) * r1_rdtice 
+         ENDIF
+      END DO
+      
+      ! correction to closing rate / opening if excessive ice removal
+      !---------------------------------------------------------------
+      ! Reduce the closing rate if more than 100% of any ice category 
+      ! would be removed.  Reduce the opening rate proportionately.
+      DO jl = 1, jpl
+         DO ji = 1, npti
+            zfac = apartf(ji,jl) * closing_gross(ji) * rdt_ice
+!!            IF( zfac > pa_i(ji,jl) .AND. zfac > 0._wp ) THEN
+            IF( zfac > pa_i(ji,jl) ) THEN
+               closing_gross(ji) = closing_gross(ji) * pa_i(ji,jl) / zfac
+            ENDIF
+         END DO
+      END DO      
+      !
+   END SUBROUTINE rdgrft_prep
+
+
+   SUBROUTINE rdgrft_shift
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE rdgrft_shift ***
+      !!
+      !! ** Purpose :   shift ridging ice among thickness categories of ice thickness
+      !!
+      !! ** Method  :   Remove area, volume, and energy from each ridging category
+      !!              and add to thicker ice categories.
+      !!-------------------------------------------------------------------
+      !
+      INTEGER  ::   ji, jj, jl, jl1, jl2, jk   ! dummy loop indices
+      REAL(wp) ::   hL, hR, farea              ! left and right limits of integration and new area going to jl2
+      REAL(wp) ::   vsw                        ! vol of water trapped into ridges
+      REAL(wp) ::   afrdg, afrft               ! fraction of category area ridged/rafted 
+      REAL(wp)                  ::   airdg1, oirdg1, aprdg1, virdg1, sirdg1
+      REAL(wp)                  ::   airft1, oirft1, aprft1
+      REAL(wp), DIMENSION(jpij) ::   airdg2, oirdg2, aprdg2, virdg2, sirdg2, vsrdg, vprdg, esrdg  ! area etc of new ridges
+      REAL(wp), DIMENSION(jpij) ::   airft2, oirft2, aprft2, virft , sirft , vsrft, vprft, esrft  ! area etc of rafted ice
+      !
+      REAL(wp), DIMENSION(jpij) ::   ersw             ! enth of water trapped into ridges
+      REAL(wp), DIMENSION(jpij) ::   zswitch, fvol    ! new ridge volume going to jl2
+      REAL(wp), DIMENSION(jpij) ::   z1_ai            ! 1 / a
+      !
+      REAL(wp), DIMENSION(jpij,nlay_i) ::   eirft     ! ice energy of rafting ice
+      REAL(wp), DIMENSION(jpij,nlay_i) ::   eirdg     ! enth*volume of new ridges
+      !!-------------------------------------------------------------------
+
+      !-------------------------------------------------------------------------------
+      ! 1) Compute change in open water area due to closing and opening.
+      !-------------------------------------------------------------------------------
+      DO ji = 1, npti
+         ato_i_1d(ji) = MAX( 0._wp, ato_i_1d(ji) + ( opning(ji) - apartf(ji,0) * closing_gross(ji) ) * rdt_ice )
+      END DO
+      
+      !-----------------------------------------------------------------
+      ! 2) compute categories participating to ridging/rafting (jl1) 
+      !-----------------------------------------------------------------
+      DO jl1 = 1, jpl
+
+         CALL tab_2d_1d( npti, nptidx(1:npti), s_i_1d(1:npti), s_i(:,:,jl1) )
+
+         DO ji = 1, npti
+
+            !------------------------------------------------
+            ! 2.1) Identify grid cells with nonzero ridging
+            !------------------------------------------------
+            IF( apartf(ji,jl1) > 0._wp .AND. closing_gross(ji) > 0._wp ) THEN
+
+               z1_ai(ji) = 1._wp / a_i_2d(ji,jl1)
+
+               !--------------------------------------------------------------------
+               ! 2.2) Compute area of ridging ice (airdg1) and of new ridge (airdg2)
+               !--------------------------------------------------------------------
+               airdg1 = aridge(ji,jl1) * closing_gross(ji) * rdt_ice
+               airft1 = araft (ji,jl1) * closing_gross(ji) * rdt_ice
+
+               airdg2(ji) = airdg1 * hi_hrdg(ji,jl1)
+               airft2(ji) = airft1 * hi_hrft
+
+               !---------------------------------------------------------------
+               ! 2.3) Compute ridging /rafting fractions, make sure afrdg <=1 
+               !---------------------------------------------------------------
+               afrdg = airdg1 * z1_ai(ji)
+               afrft = airft1 * z1_ai(ji)
+
+               ! volume and enthalpy (J/m2, >0) of seawater trapped into ridges
+               vsw = v_i_2d(ji,jl1) * afrdg * rn_porordg
+               ersw(ji) = -rhoic * vsw * rcp * sst_1d(ji)   ! clem: if sst>0, then ersw <0 (is that possible?)
+
+               !---------------------------------------------------------------
+               ! 2.4) Compute ridging ice and new ridges (vi, vs, sm, oi, es, ei)
+               !---------------------------------------------------------------
+               virdg1     = v_i_2d (ji,jl1)   * afrdg
+               virdg2(ji) = v_i_2d (ji,jl1)   * afrdg * ( 1. + rn_porordg )
+               vsrdg(ji)  = v_s_2d (ji,jl1)   * afrdg
+               sirdg1     = sv_i_2d(ji,jl1)   * afrdg
+               sirdg2(ji) = sv_i_2d(ji,jl1)   * afrdg + vsw * sss_1d(ji)
+               oirdg1     = oa_i_2d(ji,jl1)   * afrdg
+               oirdg2(ji) = oa_i_2d(ji,jl1)   * afrdg * hi_hrdg(ji,jl1) 
+               esrdg(ji)  = ze_s_2d(ji,1,jl1) * afrdg
+
+               virft(ji)  = v_i_2d (ji,jl1)   * afrft
+               vsrft(ji)  = v_s_2d (ji,jl1)   * afrft
+               sirft(ji)  = sv_i_2d(ji,jl1)   * afrft 
+               oirft1     = oa_i_2d(ji,jl1)   * afrft 
+               oirft2(ji) = oa_i_2d(ji,jl1)   * afrft * hi_hrft 
+               esrft(ji)  = ze_s_2d(ji,1,jl1) * afrft
+
+               IF ( ln_pnd_H12 ) THEN
+                  aprdg1     = a_ip_2d(ji,jl1) * afrdg
+                  aprdg2(ji) = a_ip_2d(ji,jl1) * afrdg * hi_hrdg(ji,jl1)
+                  vprdg (ji) = v_ip_2d(ji,jl1) * afrdg
+                  aprft1     = a_ip_2d(ji,jl1) * afrft
+                  aprft2(ji) = a_ip_2d(ji,jl1) * afrft * hi_hrft
+                  vprft (ji) = v_ip_2d(ji,jl1) * afrft
+               ENDIF
+
+               !-----------------------------------------------------------------
+               ! 2.5) Ice-ocean exchanges
+               !-----------------------------------------------------------------
+               wfx_dyn_1d(ji) = wfx_dyn_1d(ji) - vsw * rhoic * r1_rdtice   ! increase in ice volume due to seawater frozen in voids
+               sfx_dyn_1d(ji) = sfx_dyn_1d(ji) - vsw * sss_1d(ji) * rhoic * r1_rdtice
+               hfx_dyn_1d(ji) = hfx_dyn_1d(ji) + ersw(ji) * r1_rdtice          ! > 0 [W.m-2] 
+
+               ! Put the snow lost by ridging into the ocean
+               !------------------------------------------------
+               !  Note that esrdg > 0; the ocean must cool to melt snow. If the ocean temp = Tf already, new ice must grow.
+               wfx_snw_dyn_1d(ji) = wfx_snw_dyn_1d(ji) + ( rhosn * vsrdg(ji) * ( 1._wp - rn_fsnwrdg )   &   ! fresh water source for ocean
+                  &                                      + rhosn * vsrft(ji) * ( 1._wp - rn_fsnwrft ) ) * r1_rdtice
+
+               hfx_dyn_1d(ji) = hfx_dyn_1d(ji) + ( - esrdg(ji) * ( 1._wp - rn_fsnwrdg )   &                 ! heat sink for ocean (<0, W.m-2)
+                  &                                - esrft(ji) * ( 1._wp - rn_fsnwrft ) ) * r1_rdtice
+
+               ! Put the melt pond water into the ocean
+               !------------------------------------------            
+               ! clem: I think the following lines must be commented since there
+               !       is no net mass flux between melt ponds and the ocean (see icethd_pnd.F90 for ex.)
+               !IF ( ln_pnd_fwb ) THEN
+               !   wfx_pnd_1d(ji) = wfx_pnd_1d(ji) + ( rhofw * vprdg(ji) * ( 1._wp - rn_fpndrdg )   &        ! fresh water source for ocean
+               !      &                              + rhofw * vprft(ji) * ( 1._wp - rn_fpndrft ) ) * r1_rdtice
+               !ENDIF
+
+               ! virtual salt flux to keep salinity constant
+               !------------------------------------------            
+               IF( nn_icesal /= 2 )  THEN
+                  sirdg2(ji)     = sirdg2(ji)     - vsw * ( sss_1d(ji) - s_i_1d(ji) )        ! ridge salinity = s_i
+                  sfx_bri_1d(ji) = sfx_bri_1d(ji) + sss_1d(ji) * vsw * rhoic * r1_rdtice  &  ! put back sss_m into the ocean
+                     &                            - s_i_1d(ji) * vsw * rhoic * r1_rdtice     ! and get  s_i  from the ocean 
+               ENDIF
+
+
+               !------------------------------------------            
+               ! 2.6) update jl1 (removing ridged/rafted area)
+               !------------------------------------------            
+               a_i_2d (ji,jl1) = a_i_2d (ji,jl1) - airdg1    - airft1
+               v_i_2d (ji,jl1) = v_i_2d (ji,jl1) - virdg1    - virft(ji)
+               v_s_2d (ji,jl1) = v_s_2d (ji,jl1) - vsrdg(ji) - vsrft(ji)
+               sv_i_2d(ji,jl1) = sv_i_2d(ji,jl1) - sirdg1    - sirft(ji)
+               oa_i_2d(ji,jl1) = oa_i_2d(ji,jl1) - oirdg1    - oirft1
+               IF ( ln_pnd_H12 ) THEN
+                  a_ip_2d(ji,jl1) = a_ip_2d(ji,jl1) - aprdg1    - aprft1
+                  v_ip_2d(ji,jl1) = v_ip_2d(ji,jl1) - vprdg(ji) - vprft(ji)
+               ENDIF
+               ze_s_2d(ji,1,jl1) = ze_s_2d(ji,1,jl1) - esrdg (ji) - esrft (ji)
+            ENDIF
+
+         END DO ! ji
+
+         ! special loop for e_i because of layers jk
+         DO jk = 1, nlay_i
+            DO ji = 1, npti
+               IF( apartf(ji,jl1) > 0._wp .AND. closing_gross(ji) > 0._wp ) THEN
+                  ! Compute ridging /rafting fractions
+                  afrdg = aridge(ji,jl1) * closing_gross(ji) * rdt_ice * z1_ai(ji)
+                  afrft = araft (ji,jl1) * closing_gross(ji) * rdt_ice * z1_ai(ji)
+                  ! Compute ridging ice and new ridges for ei
+                  eirdg(ji,jk) = ze_i_2d (ji,jk,jl1) * afrdg + ersw(ji) * r1_nlay_i
+                  eirft(ji,jk) = ze_i_2d (ji,jk,jl1) * afrft
+                  ! Update jl1
+                  ze_i_2d(ji,jk,jl1) = ze_i_2d(ji,jk,jl1) * ( 1._wp - afrdg - afrft ) 
+               ENDIF
+            END DO
+         END DO
+         
+
+         !-------------------------------------------------------------------------------
+         ! 3) Add area, volume, and energy of new ridge to each category jl2
+         !-------------------------------------------------------------------------------
+         DO jl2  = 1, jpl 
+            !
+            DO ji = 1, npti
+
+               IF( apartf(ji,jl1) > 0._wp .AND. closing_gross(ji) > 0._wp ) THEN
+
+                  ! Compute the fraction of ridged ice area and volume going to thickness category jl2.
+                  IF( hrmin(ji,jl1) <= hi_max(jl2) .AND. hrmax(ji,jl1) > hi_max(jl2-1) ) THEN
+                     !-----------------------------------------------------------------
+                     ! 2.8 Compute quantities used to apportion ice among categories
+                     ! in the n2 loop below
+                     !-----------------------------------------------------------------
+                     hL = MAX( hrmin(ji,jl1), hi_max(jl2-1) )
+                     hR = MIN( hrmax(ji,jl1), hi_max(jl2)   )
+                     farea    = ( hR      - hL      ) / ( hrmax(ji,jl1)                 - hrmin(ji,jl1)                 )
+                     fvol(ji) = ( hR * hR - hL * hL ) / ( hrmax(ji,jl1) * hrmax(ji,jl1) - hrmin(ji,jl1) * hrmin(ji,jl1) )
+                  ELSE
+                     farea    = 0._wp 
+                     fvol(ji) = 0._wp                  
+                  ENDIF
+
+                  ! Compute the fraction of rafted ice area and volume going to thickness category jl2
+                  !!gm see above               IF( hraft(ji) <= hi_max(jl2) .AND. hraft(ji) >  hi_max(jl2-1) ) THEN
+                  IF( hi_max(jl2-1) < hraft(ji,jl1) .AND. hraft(ji,jl1) <= hi_max(jl2)  ) THEN   ;   zswitch(ji) = 1._wp
+                  ELSE                                                                           ;   zswitch(ji) = 0._wp
+                  ENDIF
+                  !
+                  a_i_2d (ji,jl2) = a_i_2d (ji,jl2) + ( airdg2(ji) * farea    + airft2(ji) * zswitch(ji) )
+                  oa_i_2d(ji,jl2) = oa_i_2d(ji,jl2) + ( oirdg2(ji) * farea    + oirft2(ji) * zswitch(ji) )
+                  v_i_2d (ji,jl2) = v_i_2d (ji,jl2) + ( virdg2(ji) * fvol(ji) + virft (ji) * zswitch(ji) )
+                  sv_i_2d(ji,jl2) = sv_i_2d(ji,jl2) + ( sirdg2(ji) * fvol(ji) + sirft (ji) * zswitch(ji) )
+                  v_s_2d (ji,jl2) = v_s_2d (ji,jl2) + ( vsrdg (ji) * rn_fsnwrdg * fvol(ji)  +  &
+                     &                                    vsrft (ji) * rn_fsnwrft * zswitch(ji) )
+                  IF ( ln_pnd_H12 ) THEN
+                     v_ip_2d (ji,jl2) = v_ip_2d(ji,jl2) + (   vprdg (ji) * rn_fpndrdg * fvol   (ji)   &
+                        &                                   + vprft (ji) * rn_fpndrft * zswitch(ji)   )
+                     a_ip_2d (ji,jl2) = a_ip_2d(ji,jl2) + (   aprdg2(ji) * rn_fpndrdg * farea         & 
+                        &                                   + aprft2(ji) * rn_fpndrft * zswitch(ji)   )
+                  ENDIF
+                  ze_s_2d(ji,1,jl2) = ze_s_2d(ji,1,jl2) + ( esrdg (ji) * rn_fsnwrdg * fvol(ji)  +  &
+                     &                                      esrft (ji) * rn_fsnwrft * zswitch(ji) )
+                  
+               ENDIF
+
+            END DO
+
+            DO jk = 1, nlay_i
+               DO ji = 1, npti
+                  IF( apartf(ji,jl1) > 0._wp .AND. closing_gross(ji) > 0._wp )   &
+                     &   ze_i_2d(ji,jk,jl2) = ze_i_2d(ji,jk,jl2) + eirdg(ji,jk) * fvol(ji) + eirft(ji,jk) * zswitch(ji)                  
+               END DO
+            END DO
+            !
+         END DO ! jl2
+         !
+      END DO ! jl1
+      !
+      ! In case ridging/rafting lead to very small negative values (sometimes it happens)
+      WHERE( a_i_2d(1:npti,:) < 0._wp )   a_i_2d(1:npti,:) = 0._wp
+      WHERE( v_i_2d(1:npti,:) < 0._wp )   v_i_2d(1:npti,:) = 0._wp
+      !
+   END SUBROUTINE rdgrft_shift
+
+
+   SUBROUTINE ice_strength
+      !!----------------------------------------------------------------------
+      !!                ***  ROUTINE ice_strength ***
+      !!
+      !! ** Purpose :   computes ice strength used in dynamics routines of ice thickness
+      !!
+      !! ** Method  :   Compute the strength of the ice pack, defined as the energy (J m-2) 
+      !!              dissipated per unit area removed from the ice pack under compression,
+      !!              and assumed proportional to the change in potential energy caused
+      !!              by ridging. Note that only Hibler's formulation is stable and that
+      !!              ice strength has to be smoothed
+      !!----------------------------------------------------------------------
+      INTEGER             ::   ji, jj, jl  ! dummy loop indices
+      INTEGER             ::   ismooth     ! smoothing the resistance to deformation
+      INTEGER             ::   itframe     ! number of time steps for the P smoothing
+      REAL(wp)            ::   zp, z1_3    ! local scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   zworka           ! temporary array used here
+      REAL(wp), DIMENSION(jpi,jpj) ::   zstrp1, zstrp2   ! strength at previous time steps
+      !!----------------------------------------------------------------------
+      !                              !--------------------------------------------------!
+      IF( ln_str_H79 ) THEN          ! Ice strength => Hibler (1979) method             !
+      !                              !--------------------------------------------------!
+         strength(:,:) = rn_pstar * SUM( v_i(:,:,:), dim=3 ) * EXP( -rn_crhg * ( 1._wp - SUM( a_i(:,:,:), dim=3 ) ) )
+         ismooth = 1
+         !                           !--------------------------------------------------!
+      ELSE                           ! Zero strength                                    !
+         !                           !--------------------------------------------------!
+         strength(:,:) = 0._wp
+         ismooth = 0
+      ENDIF
+      !                              !--------------------------------------------------!
+      SELECT CASE( ismooth )         ! Smoothing ice strength                           !
+      !                              !--------------------------------------------------!
+      CASE( 1 )               !--- Spatial smoothing
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               IF ( SUM( a_i(ji,jj,:) ) > 0._wp ) THEN 
+                  zworka(ji,jj) = ( 4.0 * strength(ji,jj)              &
+                     &                  + strength(ji-1,jj) * tmask(ji-1,jj,1) + strength(ji+1,jj) * tmask(ji+1,jj,1) &  
+                     &                  + strength(ji,jj-1) * tmask(ji,jj-1,1) + strength(ji,jj+1) * tmask(ji,jj+1,1) &
+                     &            ) / ( 4.0 + tmask(ji-1,jj,1) + tmask(ji+1,jj,1) + tmask(ji,jj-1,1) + tmask(ji,jj+1,1) )
+               ELSE
+                  zworka(ji,jj) = 0._wp
+               ENDIF
+            END DO
+         END DO
+         
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               strength(ji,jj) = zworka(ji,jj)
+            END DO
+         END DO
+         CALL lbc_lnk( strength, 'T', 1. )
+         !
+      CASE( 2 )               !--- Temporal smoothing
+         IF ( kt_ice == nit000 ) THEN
+            zstrp1(:,:) = 0._wp
+            zstrp2(:,:) = 0._wp
+         ENDIF
+         !
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               IF ( SUM( a_i(ji,jj,:) ) > 0._wp ) THEN 
+                  itframe = 1 ! number of time steps for the running mean
+                  IF ( zstrp1(ji,jj) > 0._wp ) itframe = itframe + 1
+                  IF ( zstrp2(ji,jj) > 0._wp ) itframe = itframe + 1
+                  zp = ( strength(ji,jj) + zstrp1(ji,jj) + zstrp2(ji,jj) ) / itframe
+                  zstrp2  (ji,jj) = zstrp1  (ji,jj)
+                  zstrp1  (ji,jj) = strength(ji,jj)
+                  strength(ji,jj) = zp
+               ENDIF
+            END DO
+         END DO
+         CALL lbc_lnk( strength, 'T', 1. )
+         !
+      END SELECT
+      !
+   END SUBROUTINE ice_strength
+
+
+   SUBROUTINE ice_dyn_rdgrft_init
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_dyn_rdgrft_init ***
+      !!
+      !! ** Purpose :   Physical constants and parameters linked 
+      !!                to the mechanical ice redistribution
+      !!
+      !! ** Method  :   Read the namdyn_rdgrft namelist 
+      !!                and check the parameters values 
+      !!                called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namdyn_rdgrft
+      !!-------------------------------------------------------------------
+      INTEGER :: ios                 ! Local integer output status for namelist read
+      !!
+      NAMELIST/namdyn_rdgrft/ ln_str_H79, rn_pstar, rn_crhg, &
+         &                    rn_csrdg  ,                    &
+         &                    ln_partf_lin, rn_gstar,        &
+         &                    ln_partf_exp, rn_astar,        & 
+         &                    ln_ridging, rn_hstar, rn_porordg, rn_fsnwrdg, rn_fpndrdg,  & 
+         &                    ln_rafting, rn_hraft, rn_craft  , rn_fsnwrft, rn_fpndrft
+      !!-------------------------------------------------------------------
+      !
+      REWIND( numnam_ice_ref )              ! Namelist namicetdme in reference namelist : Ice mechanical ice redistribution
+      READ  ( numnam_ice_ref, namdyn_rdgrft, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn_rdgrft in reference namelist', lwp )
+      !
+      REWIND( numnam_ice_cfg )              ! Namelist namdyn_rdgrft in configuration namelist : Ice mechanical ice redistribution
+      READ  ( numnam_ice_cfg, namdyn_rdgrft, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn_rdgrft in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namdyn_rdgrft )
+      !
+      IF (lwp) THEN                          ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_dyn_rdgrft_init: ice parameters for ridging/rafting '
+         WRITE(numout,*) '~~~~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namdyn_rdgrft:'
+         WRITE(numout,*) '      ice strength parameterization Hibler (1979)              ln_str_H79   = ', ln_str_H79 
+         WRITE(numout,*) '            1st bulk-rheology parameter                        rn_pstar     = ', rn_pstar
+         WRITE(numout,*) '            2nd bulk-rhelogy parameter                         rn_crhg      = ', rn_crhg
+         WRITE(numout,*) '      Fraction of shear energy contributing to ridging         rn_csrdg     = ', rn_csrdg 
+         WRITE(numout,*) '      linear ridging participation function                    ln_partf_lin = ', ln_partf_lin
+         WRITE(numout,*) '            Fraction of ice coverage contributing to ridging   rn_gstar     = ', rn_gstar
+         WRITE(numout,*) '      Exponential ridging participation function               ln_partf_exp = ', ln_partf_exp
+         WRITE(numout,*) '            Equivalent to G* for an exponential function       rn_astar     = ', rn_astar
+         WRITE(numout,*) '      Ridging of ice sheets or not                             ln_ridging   = ', ln_ridging
+         WRITE(numout,*) '            max ridged ice thickness                           rn_hstar     = ', rn_hstar
+         WRITE(numout,*) '            Initial porosity of ridges                         rn_porordg   = ', rn_porordg
+         WRITE(numout,*) '            Fraction of snow volume conserved during ridging   rn_fsnwrdg   = ', rn_fsnwrdg 
+         WRITE(numout,*) '            Fraction of pond volume conserved during ridging   rn_fpndrdg   = ', rn_fpndrdg 
+         WRITE(numout,*) '      Rafting of ice sheets or not                             ln_rafting   = ', ln_rafting
+         WRITE(numout,*) '            Parmeter thickness (threshold between ridge-raft)  rn_hraft     = ', rn_hraft
+         WRITE(numout,*) '            Rafting hyperbolic tangent coefficient             rn_craft     = ', rn_craft  
+         WRITE(numout,*) '            Fraction of snow volume conserved during rafting   rn_fsnwrft   = ', rn_fsnwrft 
+         WRITE(numout,*) '            Fraction of pond volume conserved during rafting   rn_fpndrft   = ', rn_fpndrft 
+      ENDIF
+      !
+      IF ( ( ln_partf_lin .AND. ln_partf_exp ) .OR. ( .NOT.ln_partf_lin .AND. .NOT.ln_partf_exp ) ) THEN
+         CALL ctl_stop( 'ice_dyn_rdgrft_init: choose one and only one participation function (ln_partf_lin or ln_partf_exp)' )
+      ENDIF
+      !                              ! allocate tke arrays
+      IF( ice_dyn_rdgrft_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'ice_dyn_rdgrft_init: unable to allocate arrays' )
+      !
+  END SUBROUTINE ice_dyn_rdgrft_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty module           NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icedyn_rdgrft
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rhg.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rhg.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rhg.F90	(revision 9019)
@@ -0,0 +1,151 @@
+MODULE icedyn_rhg
+   !!======================================================================
+   !!                     ***  MODULE  icedyn_rhg  ***
+   !!   Sea-Ice dynamics : master routine for rheology 
+   !!======================================================================
+   !! history :  1.0  ! 2002-08  (C. Ethe, G. Madec)  original VP code 
+   !!            3.0  ! 2007-03  (MA Morales Maqueda, S. Bouillon, M. Vancoppenolle)  LIM3: EVP-Cgrid
+   !!            3.5  ! 2011-02  (G. Madec) dynamical allocation
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!    ice_dyn_rhg      : computes ice velocities
+   !!    ice_dyn_rhg_init : initialization and namelist read
+   !!----------------------------------------------------------------------
+   USE phycst         ! physical constants
+   USE dom_oce        ! ocean space and time domain
+   USE ice            ! sea-ice: variables
+   USE icedyn_rhg_evp ! sea-ice: EVP rheology
+   USE icectl         ! sea-ice: control prints
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE timing         ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_dyn_rhg        ! called by icestp.F90
+   PUBLIC   ice_dyn_rhg_init   ! called by icestp.F90
+
+   INTEGER ::              nice_rhg   ! choice of the type of rheology
+   !                                        ! associated indices:
+   INTEGER, PARAMETER ::   np_rhgEVP = 1   ! EVP rheology
+!! INTEGER, PARAMETER ::   np_rhgEAP = 2   ! EAP rheology
+
+   ! ** namelist (namrhg) **
+   LOGICAL ::   ln_rhg_EVP       ! EVP rheology
+   !
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icedyn_rhg.F90 8378 2017-07-26 13:55:59Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_dyn_rhg( kt )
+      !!-------------------------------------------------------------------
+      !!               ***  ROUTINE ice_dyn_rhg  ***
+      !!               
+      !! ** Purpose :   compute ice velocity
+      !!
+      !! ** Action  : comupte - ice velocity (u_ice, v_ice)
+      !!                      - 3 components of the stress tensor (stress1_i, stress2_i, stress12_i)
+      !!                      - shear, divergence and delta (shear_i, divu_i, delta_i)
+      !!--------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! ice time step
+      !!--------------------------------------------------------------------
+      ! controls
+      IF( nn_timing == 1 )   CALL timing_start('icedyn_rhg')                                                             ! timing
+      IF( ln_icediachk   )   CALL ice_cons_hsm(0, 'icedyn_rhg', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
+      !
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*)'ice_dyn_rhg: sea-ice rheology'
+         WRITE(numout,*)'~~~~~~~~~~~'
+      ENDIF
+
+      ! --------
+      ! Rheology
+      ! --------   
+      SELECT CASE( nice_rhg )
+      !                                !------------------------!
+      CASE( np_rhgEVP )                ! Elasto-Viscous-Plastic !
+         !                             !------------------------!
+         CALL ice_dyn_rhg_evp( kt, stress1_i, stress2_i, stress12_i, shear_i, divu_i, delta_i )
+         !         
+      END SELECT
+      !
+      IF( lrst_ice ) THEN                       !* write EVP fields in the restart file
+         IF( ln_rhg_EVP )   CALL rhg_evp_rst( 'WRITE', kt )
+      ENDIF
+      !
+      ! controls
+      IF( ln_icediachk   )   CALL ice_cons_hsm(1, 'icedyn_rhg', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
+      IF( ln_ctl         )   CALL ice_prt3D   ('icedyn_rhg')                                                             ! prints
+      IF( nn_timing == 1 )   CALL timing_stop ('icedyn_rhg')                                                             ! timing
+      !
+   END SUBROUTINE ice_dyn_rhg
+
+   SUBROUTINE ice_dyn_rhg_init
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_dyn_rhg_init  ***
+      !!
+      !! ** Purpose : Physical constants and parameters linked to the ice
+      !!      dynamics
+      !!
+      !! ** Method  :  Read the namdyn_rhg namelist and check the ice-dynamic
+      !!       parameter values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namdyn_rhg
+      !!-------------------------------------------------------------------
+      INTEGER ::   ios, ioptio   ! Local integer output status for namelist read
+      !!
+      NAMELIST/namdyn_rhg/  ln_rhg_EVP, ln_aEVP, rn_creepl, rn_ecc , nn_nevp, rn_relast
+      !!-------------------------------------------------------------------
+      !
+      REWIND( numnam_ice_ref )         ! Namelist namdyn_rhg in reference namelist : Ice dynamics
+      READ  ( numnam_ice_ref, namdyn_rhg, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn_rhg in reference namelist', lwp )
+      !
+      REWIND( numnam_ice_cfg )         ! Namelist namdyn_rhg in configuration namelist : Ice dynamics
+      READ  ( numnam_ice_cfg, namdyn_rhg, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namdyn_rhg in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namdyn_rhg )
+      !
+      IF(lwp) THEN                     ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_dyn_rhg_init: ice parameters for ice dynamics '
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namdyn_rhg:'
+         WRITE(numout,*) '      rheology EVP (icedyn_rhg_evp)                        ln_rhg_EVP = ', ln_rhg_EVP
+         WRITE(numout,*) '         use adaptive EVP (aEVP)                           ln_aEVP    = ', ln_aEVP
+         WRITE(numout,*) '         creep limit                                       rn_creepl  = ', rn_creepl
+         WRITE(numout,*) '         eccentricity of the elliptical yield curve        rn_ecc     = ', rn_ecc
+         WRITE(numout,*) '         number of iterations for subcycling               nn_nevp    = ', nn_nevp
+         WRITE(numout,*) '         ratio of elastic timescale over ice time step     rn_relast  = ', rn_relast
+      ENDIF
+      !
+      !                             !== set the choice of ice advection ==!
+      ioptio = 0 
+      IF( ln_rhg_EVP ) THEN   ;   ioptio = ioptio + 1   ;   nice_rhg = np_rhgEVP    ;   ENDIF
+!!    IF( ln_rhg_EAP ) THEN   ;   ioptio = ioptio + 1   ;   nice_rhg = np_rhgEAP    ;   ENDIF
+      IF( ioptio /= 1 )   CALL ctl_stop( 'ice_dyn_rhg_init: choose one and only one ice rheology' )
+      !
+      IF( ln_rhg_EVP  )   CALL rhg_evp_rst( 'READ' )  !* read or initialize all required files
+      !
+   END SUBROUTINE ice_dyn_rhg_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty module           NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif 
+
+   !!======================================================================
+END MODULE icedyn_rhg
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rhg_evp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rhg_evp.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rhg_evp.F90	(revision 9019)
@@ -0,0 +1,910 @@
+MODULE icedyn_rhg_evp
+   !!======================================================================
+   !!                     ***  MODULE  icedyn_rhg_evp  ***
+   !!   Sea-Ice dynamics : rheology Elasto-Viscous-Plastic
+   !!======================================================================
+   !! History :   -   !  2007-03  (M.A. Morales Maqueda, S. Bouillon) Original code
+   !!            3.0  !  2008-03  (M. Vancoppenolle) LIM3
+   !!             -   !  2008-11  (M. Vancoppenolle, S. Bouillon, Y. Aksenov) add surface tilt in ice rheolohy 
+   !!            3.3  !  2009-05  (G.Garric) addition of the evp cas
+   !!            3.4  !  2011-01  (A. Porter)  dynamical allocation 
+   !!            3.5  !  2012-08  (R. Benshila)  AGRIF
+   !!            3.6  !  2016-06  (C. Rousset) Rewriting + landfast ice + possibility to use mEVP (Bouillon 2013)
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_dyn_rhg_evp : computes ice velocities from EVP rheology
+   !!   rhg_evp_rst     : read/write EVP fields in ice restart
+   !!----------------------------------------------------------------------
+   USE phycst         ! Physical constant
+   USE dom_oce        ! Ocean domain
+   USE sbc_oce , ONLY : ln_ice_embd, nn_fsbc, ssh_m
+   USE sbc_ice , ONLY : utau_ice, vtau_ice, snwice_mass, snwice_mass_b
+   USE ice            ! sea-ice: ice variables
+   USE icedyn_rdgrft  ! sea-ice: ice strength
+   USE bdy_oce , ONLY : ln_bdy 
+   USE bdyice 
+#if defined key_agrif
+   USE agrif_lim3_interp
+#endif
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE lbclnk         ! lateral boundary conditions (or mpp links)
+   USE prtctl         ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_dyn_rhg_evp   ! called by icedyn_rhg.F90
+   PUBLIC   rhg_evp_rst       ! called by icedyn_rhg.F90
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icedyn_rhg_evp.F90 8378 2017-07-26 13:55:59Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_dyn_rhg_evp( kt, pstress1_i, pstress2_i, pstress12_i, pshear_i, pdivu_i, pdelta_i )
+      !!-------------------------------------------------------------------
+      !!                 ***  SUBROUTINE ice_dyn_rhg_evp  ***
+      !!                             EVP-C-grid
+      !!
+      !! ** purpose : determines sea ice drift from wind stress, ice-ocean
+      !!  stress and sea-surface slope. Ice-ice interaction is described by 
+      !!  a non-linear elasto-viscous-plastic (EVP) law including shear 
+      !!  strength and a bulk rheology (Hunke and Dukowicz, 2002).	
+      !!
+      !!  The points in the C-grid look like this, dear reader
+      !!
+      !!                              (ji,jj)
+      !!                                 |
+      !!                                 |
+      !!                      (ji-1,jj)  |  (ji,jj)
+      !!                             ---------   
+      !!                            |         |
+      !!                            | (ji,jj) |------(ji,jj)
+      !!                            |         |
+      !!                             ---------   
+      !!                     (ji-1,jj-1)     (ji,jj-1)
+      !!
+      !! ** Inputs  : - wind forcing (stress), oceanic currents
+      !!                ice total volume (vt_i) per unit area
+      !!                snow total volume (vt_s) per unit area
+      !!
+      !! ** Action  : - compute u_ice, v_ice : the components of the 
+      !!                sea-ice velocity vector
+      !!              - compute delta_i, shear_i, divu_i, which are inputs
+      !!                of the ice thickness distribution
+      !!
+      !! ** Steps   : 0) compute mask at F point
+      !!              1) Compute ice snow mass, ice strength 
+      !!              2) Compute wind, oceanic stresses, mass terms and
+      !!                 coriolis terms of the momentum equation
+      !!              3) Solve the momentum equation (iterative procedure)
+      !!              4) Recompute delta, shear and divergence
+      !!                 (which are inputs of the ITD) & store stress
+      !!                 for the next time step
+      !!              5) Diagnostics including charge ellipse
+      !!
+      !! ** Notes   : There is the possibility to use aEVP from the nice work of Kimmritz et al. (2016 & 2017)
+      !!              by setting up ln_aEVP=T (i.e. changing alpha and beta parameters).
+      !!              This is an upgraded version of mEVP from Bouillon et al. 2013
+      !!              (i.e. more stable and better convergence)
+      !!
+      !! References : Hunke and Dukowicz, JPO97
+      !!              Bouillon et al., Ocean Modelling 2009
+      !!              Bouillon et al., Ocean Modelling 2013
+      !!              Kimmritz et al., Ocean Modelling 2016 & 2017
+      !!-------------------------------------------------------------------
+      INTEGER                 , INTENT(in   ) ::   kt                                    ! time step
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pstress1_i, pstress2_i, pstress12_i   !
+      REAL(wp), DIMENSION(:,:), INTENT(  out) ::   pshear_i  , pdivu_i   , pdelta_i      !
+      !!
+      INTEGER ::   ji, jj       ! dummy loop indices
+      INTEGER ::   jter         ! local integers
+      !
+      REAL(wp) ::   zrhoco                                                   ! rau0 * rn_cio
+      REAL(wp) ::   zdtevp, z1_dtevp                                         ! time step for subcycling
+      REAL(wp) ::   ecc2, z1_ecc2                                            ! square of yield ellipse eccenticity
+      REAL(wp) ::   zalph1, z1_alph1, zalph2, z1_alph2                       ! alpha coef from Bouillon 2009 or Kimmritz 2017
+      REAL(wp) ::   zm1, zm2, zm3, zmassU, zmassV                            ! ice/snow mass
+      REAL(wp) ::   zdelta, zp_delf, zds2, zdt, zdt2, zdiv, zdiv2            ! temporary scalars
+      REAL(wp) ::   zTauO, zTauB, zTauE, zvel                                ! temporary scalars
+      !
+      REAL(wp) ::   zresm                                                    ! Maximal error on ice velocity
+      REAL(wp) ::   zintb, zintn                                             ! dummy argument
+      REAL(wp) ::   zfac_x, zfac_y
+      REAL(wp) ::   zshear, zdum1, zdum2
+      !
+      REAL(wp), DIMENSION(jpi,jpj) ::   z1_e1t0, z1_e2t0                ! scale factors
+      REAL(wp), DIMENSION(jpi,jpj) ::   zp_delt                         ! P/delta at T points
+      REAL(wp), DIMENSION(jpi,jpj) ::   zbeta                           ! beta coef from Kimmritz 2017
+      !
+      REAL(wp), DIMENSION(jpi,jpj) ::   zdt_m                           ! (dt / ice-snow_mass) on T points
+      REAL(wp), DIMENSION(jpi,jpj) ::   zaU   , zaV                     ! ice fraction on U/V points
+      REAL(wp), DIMENSION(jpi,jpj) ::   zmU_t, zmV_t                    ! (ice-snow_mass / dt) on U/V points
+      REAL(wp), DIMENSION(jpi,jpj) ::   zmf                             ! coriolis parameter at T points
+      REAL(wp), DIMENSION(jpi,jpj) ::   zTauU_ia , ztauV_ia             ! ice-atm. stress at U-V points
+      REAL(wp), DIMENSION(jpi,jpj) ::   zspgU , zspgV                   ! surface pressure gradient at U/V points
+      REAL(wp), DIMENSION(jpi,jpj) ::   v_oceU, u_oceV, v_iceU, u_iceV  ! ocean/ice u/v component on V/U points                           
+      REAL(wp), DIMENSION(jpi,jpj) ::   zfU   , zfV                     ! internal stresses
+      !
+      REAL(wp), DIMENSION(jpi,jpj) ::   zds                             ! shear
+      REAL(wp), DIMENSION(jpi,jpj) ::   zs1, zs2, zs12                  ! stress tensor components
+      REAL(wp), DIMENSION(jpi,jpj) ::   zu_ice, zv_ice, zresr           ! check convergence
+      REAL(wp), DIMENSION(jpi,jpj) ::   zpice                           ! array used for the calculation of ice surface slope:
+      !                                                                      !   ocean surface (ssh_m) if ice is not embedded
+      !                                                                       !   ice top surface if ice is embedded   
+      REAL(wp), DIMENSION(jpi,jpj) ::   zCorx, zCory                    ! Coriolis stress array
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztaux_oi, ztauy_oi              ! Ocean-to-ice stress array
+      !
+      REAL(wp), DIMENSION(jpi,jpj) ::   zswitchU, zswitchV              ! dummy arrays
+      REAL(wp), DIMENSION(jpi,jpj) ::   zmaskU, zmaskV                  ! mask for ice presence
+      REAL(wp), DIMENSION(jpi,jpj) ::   zfmask, zwf                     ! mask at F points for the ice
+
+      REAL(wp), PARAMETER          ::   zepsi  = 1.0e-20_wp             ! tolerance parameter
+      REAL(wp), PARAMETER          ::   zmmin  = 1._wp                  ! ice mass (kg/m2) below which ice velocity equals ocean velocity
+      !! --- diags
+      REAL(wp), DIMENSION(jpi,jpj) ::   zswi
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zsig1, zsig2, zsig3
+      !! --- SIMIP diags
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_sig1      ! Average normal stress in sea ice   
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_sig2      ! Maximum shear stress in sea ice
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_dssh_dx   ! X-direction sea-surface tilt term (N/m2)
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_dssh_dy   ! X-direction sea-surface tilt term (N/m2)
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_corstrx   ! X-direction coriolis stress (N/m2)
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_corstry   ! Y-direction coriolis stress (N/m2)
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_intstrx   ! X-direction internal stress (N/m2)
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_intstry   ! Y-direction internal stress (N/m2)
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_utau_oi   ! X-direction ocean-ice stress
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_vtau_oi   ! Y-direction ocean-ice stress  
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_xmtrp_ice ! X-component of ice mass transport (kg/s)
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_ymtrp_ice ! Y-component of ice mass transport (kg/s)
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_xmtrp_snw ! X-component of snow mass transport (kg/s)
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_ymtrp_snw ! Y-component of snow mass transport (kg/s)
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_xatrp     ! X-component of area transport (m2/s)
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zdiag_yatrp     ! Y-component of area transport (m2/s)      
+      !!-------------------------------------------------------------------
+
+      IF( kt == nit000 .AND. lwp )   WRITE(numout,*) '-- ice_dyn_rhg_evp: EVP sea-ice rheology'
+
+#if defined key_agrif 
+      CALL agrif_interp_lim3( 'U', 0, nn_nevp )   ! First interpolation of coarse values
+      CALL agrif_interp_lim3( 'V', 0, nn_nevp )
+#endif
+      !
+!!gm for Clem:  OPTIMIZATION:  I think zfmask can be computed one for all at the initialization....
+      !------------------------------------------------------------------------------!
+      ! 0) mask at F points for the ice
+      !------------------------------------------------------------------------------!
+      ! ocean/land mask
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1      ! NO vector opt.
+            zfmask(ji,jj) = tmask(ji,jj,1) * tmask(ji+1,jj,1) * tmask(ji,jj+1,1) * tmask(ji+1,jj+1,1)
+         END DO
+      END DO
+      CALL lbc_lnk( zfmask, 'F', 1._wp )
+
+      ! Lateral boundary conditions on velocity (modify zfmask)
+      zwf(:,:) = zfmask(:,:)
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            IF( zfmask(ji,jj) == 0._wp ) THEN
+               zfmask(ji,jj) = rn_ishlat * MIN( 1._wp , MAX( zwf(ji+1,jj), zwf(ji,jj+1), zwf(ji-1,jj), zwf(ji,jj-1) ) )
+            ENDIF
+         END DO
+      END DO
+      DO jj = 2, jpjm1
+         IF( zfmask(1,jj) == 0._wp ) THEN
+            zfmask(1  ,jj) = rn_ishlat * MIN( 1._wp , MAX( zwf(2,jj), zwf(1,jj+1), zwf(1,jj-1) ) )
+         ENDIF
+         IF( zfmask(jpi,jj) == 0._wp ) THEN
+            zfmask(jpi,jj) = rn_ishlat * MIN( 1._wp , MAX( zwf(jpi,jj+1), zwf(jpim1,jj), zwf(jpi,jj-1) ) )
+         ENDIF
+      END DO
+      DO ji = 2, jpim1
+         IF( zfmask(ji,1) == 0._wp ) THEN
+            zfmask(ji,1  ) = rn_ishlat * MIN( 1._wp , MAX( zwf(ji+1,1), zwf(ji,2), zwf(ji-1,1) ) )
+         ENDIF
+         IF( zfmask(ji,jpj) == 0._wp ) THEN
+            zfmask(ji,jpj) = rn_ishlat * MIN( 1._wp , MAX( zwf(ji+1,jpj), zwf(ji-1,jpj), zwf(ji,jpjm1) ) )
+         ENDIF
+      END DO
+      CALL lbc_lnk( zfmask, 'F', 1._wp )
+
+      !------------------------------------------------------------------------------!
+      ! 1) define some variables and initialize arrays
+      !------------------------------------------------------------------------------!
+      zrhoco = rau0 * rn_cio 
+
+      ! ecc2: square of yield ellipse eccenticrity
+      ecc2    = rn_ecc * rn_ecc
+      z1_ecc2 = 1._wp / ecc2
+
+      ! Time step for subcycling
+      zdtevp   = rdt_ice / REAL( nn_nevp )
+      z1_dtevp = 1._wp / zdtevp
+
+      ! alpha parameters (Bouillon 2009)
+      IF( .NOT. ln_aEVP ) THEN
+         zalph1 = ( 2._wp * rn_relast * rdt_ice ) * z1_dtevp
+         zalph2 = zalph1 * z1_ecc2
+
+         z1_alph1 = 1._wp / ( zalph1 + 1._wp )
+         z1_alph2 = 1._wp / ( zalph2 + 1._wp )
+      ENDIF
+         
+      ! Initialise stress tensor 
+      zs1 (:,:) = pstress1_i (:,:) 
+      zs2 (:,:) = pstress2_i (:,:)
+      zs12(:,:) = pstress12_i(:,:)
+
+      ! Ice strength
+      CALL ice_strength
+
+      ! scale factors
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+            z1_e1t0(ji,jj) = 1._wp / ( e1t(ji+1,jj  ) + e1t(ji,jj  ) )
+            z1_e2t0(ji,jj) = 1._wp / ( e2t(ji  ,jj+1) + e2t(ji,jj  ) )
+         END DO
+      END DO
+            
+      !
+      !------------------------------------------------------------------------------!
+      ! 2) Wind / ocean stress, mass terms, coriolis terms
+      !------------------------------------------------------------------------------!
+
+      IF( ln_ice_embd ) THEN             !== embedded sea ice: compute representative ice top surface ==!
+         !                                            
+         ! average interpolation coeff as used in dynspg = (1/nn_fsbc)   * {SUM[n/nn_fsbc], n=0,nn_fsbc-1}
+         !                                               = (1/nn_fsbc)^2 * {SUM[n]        , n=0,nn_fsbc-1}
+         zintn = REAL( nn_fsbc - 1 ) / REAL( nn_fsbc ) * 0.5_wp     
+         !
+         ! average interpolation coeff as used in dynspg = (1/nn_fsbc)   *    {SUM[1-n/nn_fsbc], n=0,nn_fsbc-1}
+         !                                               = (1/nn_fsbc)^2 * (nn_fsbc^2 - {SUM[n], n=0,nn_fsbc-1})
+         zintb = REAL( nn_fsbc + 1 ) / REAL( nn_fsbc ) * 0.5_wp
+         !
+         zpice(:,:) = ssh_m(:,:) + ( zintn * snwice_mass(:,:) + zintb * snwice_mass_b(:,:) ) * r1_rau0
+         !
+      ELSE                                    !== non-embedded sea ice: use ocean surface for slope calculation ==!
+         zpice(:,:) = ssh_m(:,:)
+      ENDIF
+
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1
+
+            ! ice fraction at U-V points
+            zaU(ji,jj) = 0.5_wp * ( at_i(ji,jj) * e1e2t(ji,jj) + at_i(ji+1,jj) * e1e2t(ji+1,jj) ) * r1_e1e2u(ji,jj) * umask(ji,jj,1)
+            zaV(ji,jj) = 0.5_wp * ( at_i(ji,jj) * e1e2t(ji,jj) + at_i(ji,jj+1) * e1e2t(ji,jj+1) ) * r1_e1e2v(ji,jj) * vmask(ji,jj,1)
+
+            ! Ice/snow mass at U-V points
+            zm1 = ( rhosn * vt_s(ji  ,jj  ) + rhoic * vt_i(ji  ,jj  ) )
+            zm2 = ( rhosn * vt_s(ji+1,jj  ) + rhoic * vt_i(ji+1,jj  ) )
+            zm3 = ( rhosn * vt_s(ji  ,jj+1) + rhoic * vt_i(ji  ,jj+1) )
+            zmassU = 0.5_wp * ( zm1 * e1e2t(ji,jj) + zm2 * e1e2t(ji+1,jj) ) * r1_e1e2u(ji,jj) * umask(ji,jj,1)
+            zmassV = 0.5_wp * ( zm1 * e1e2t(ji,jj) + zm3 * e1e2t(ji,jj+1) ) * r1_e1e2v(ji,jj) * vmask(ji,jj,1)
+
+            ! Ocean currents at U-V points
+            v_oceU(ji,jj)   = 0.5_wp * ( ( v_oce(ji  ,jj) + v_oce(ji  ,jj-1) ) * e1t(ji+1,jj)    &
+               &                       + ( v_oce(ji+1,jj) + v_oce(ji+1,jj-1) ) * e1t(ji  ,jj) ) * z1_e1t0(ji,jj) * umask(ji,jj,1)
+            
+            u_oceV(ji,jj)   = 0.5_wp * ( ( u_oce(ji,jj  ) + u_oce(ji-1,jj  ) ) * e2t(ji,jj+1)    &
+               &                       + ( u_oce(ji,jj+1) + u_oce(ji-1,jj+1) ) * e2t(ji,jj  ) ) * z1_e2t0(ji,jj) * vmask(ji,jj,1)
+
+            ! Coriolis at T points (m*f)
+            zmf(ji,jj)      = zm1 * ff_t(ji,jj)
+
+            ! dt/m at T points (for alpha and beta coefficients)
+            zdt_m(ji,jj)    = zdtevp / MAX( zm1, zmmin )
+            
+            ! m/dt
+            zmU_t(ji,jj)    = zmassU * z1_dtevp
+            zmV_t(ji,jj)    = zmassV * z1_dtevp
+            
+            ! Drag ice-atm.
+            zTauU_ia(ji,jj) = zaU(ji,jj) * utau_ice(ji,jj)
+            zTauV_ia(ji,jj) = zaV(ji,jj) * vtau_ice(ji,jj)
+
+            ! Surface pressure gradient (- m*g*GRAD(ssh)) at U-V points
+            zspgU(ji,jj)    = - zmassU * grav * ( zpice(ji+1,jj) - zpice(ji,jj) ) * r1_e1u(ji,jj)
+            zspgV(ji,jj)    = - zmassV * grav * ( zpice(ji,jj+1) - zpice(ji,jj) ) * r1_e2v(ji,jj)
+
+            ! masks
+            zmaskU(ji,jj) = 1._wp - MAX( 0._wp, SIGN( 1._wp, -zmassU ) )  ! 0 if no ice
+            zmaskV(ji,jj) = 1._wp - MAX( 0._wp, SIGN( 1._wp, -zmassV ) )  ! 0 if no ice
+
+            ! switches
+            zswitchU(ji,jj) = MAX( 0._wp, SIGN( 1._wp, zmassU - zmmin ) ) ! 0 if ice mass < zmmin
+            zswitchV(ji,jj) = MAX( 0._wp, SIGN( 1._wp, zmassV - zmmin ) ) ! 0 if ice mass < zmmin
+
+         END DO
+      END DO
+      CALL lbc_lnk_multi( zmf, 'T', 1., zdt_m, 'T', 1. )
+      !
+      !------------------------------------------------------------------------------!
+      ! 3) Solution of the momentum equation, iterative procedure
+      !------------------------------------------------------------------------------!
+      !
+      !                                               !----------------------!
+      DO jter = 1 , nn_nevp                           !    loop over jter    !
+         !                                            !----------------------!        
+         IF(ln_ctl) THEN   ! Convergence test
+            DO jj = 1, jpjm1
+               zu_ice(:,jj) = u_ice(:,jj) ! velocity at previous time step
+               zv_ice(:,jj) = v_ice(:,jj)
+            END DO
+         ENDIF
+
+         ! --- divergence, tension & shear (Appendix B of Hunke & Dukowicz, 2002) --- !
+         DO jj = 1, jpjm1         ! loops start at 1 since there is no boundary condition (lbc_lnk) at i=1 and j=1 for F points
+            DO ji = 1, jpim1
+
+               ! shear at F points
+               zds(ji,jj) = ( ( u_ice(ji,jj+1) * r1_e1u(ji,jj+1) - u_ice(ji,jj) * r1_e1u(ji,jj) ) * e1f(ji,jj) * e1f(ji,jj)   &
+                  &         + ( v_ice(ji+1,jj) * r1_e2v(ji+1,jj) - v_ice(ji,jj) * r1_e2v(ji,jj) ) * e2f(ji,jj) * e2f(ji,jj)   &
+                  &         ) * r1_e1e2f(ji,jj) * zfmask(ji,jj)
+
+            END DO
+         END DO
+         CALL lbc_lnk( zds, 'F', 1. )
+
+         DO jj = 2, jpj    ! loop to jpi,jpj to avoid making a communication for zs1,zs2,zs12
+            DO ji = 2, jpi ! no vector loop
+
+               ! shear**2 at T points (doc eq. A16)
+               zds2 = ( zds(ji,jj  ) * zds(ji,jj  ) * e1e2f(ji,jj  ) + zds(ji-1,jj  ) * zds(ji-1,jj  ) * e1e2f(ji-1,jj  )  &
+                  &   + zds(ji,jj-1) * zds(ji,jj-1) * e1e2f(ji,jj-1) + zds(ji-1,jj-1) * zds(ji-1,jj-1) * e1e2f(ji-1,jj-1)  &
+                  &   ) * 0.25_wp * r1_e1e2t(ji,jj)
+              
+               ! divergence at T points
+               zdiv  = ( e2u(ji,jj) * u_ice(ji,jj) - e2u(ji-1,jj) * u_ice(ji-1,jj)   &
+                  &    + e1v(ji,jj) * v_ice(ji,jj) - e1v(ji,jj-1) * v_ice(ji,jj-1)   &
+                  &    ) * r1_e1e2t(ji,jj)
+               zdiv2 = zdiv * zdiv
+               
+               ! tension at T points
+               zdt  = ( ( u_ice(ji,jj) * r1_e2u(ji,jj) - u_ice(ji-1,jj) * r1_e2u(ji-1,jj) ) * e2t(ji,jj) * e2t(ji,jj)   &
+                  &   - ( v_ice(ji,jj) * r1_e1v(ji,jj) - v_ice(ji,jj-1) * r1_e1v(ji,jj-1) ) * e1t(ji,jj) * e1t(ji,jj)   &
+                  &   ) * r1_e1e2t(ji,jj)
+               zdt2 = zdt * zdt
+               
+               ! delta at T points
+               zdelta = SQRT( zdiv2 + ( zdt2 + zds2 ) * z1_ecc2 )  
+
+               ! P/delta at T points
+               zp_delt(ji,jj) = strength(ji,jj) / ( zdelta + rn_creepl )
+
+               ! alpha & beta for aEVP
+               !   gamma = 0.5*P/(delta+creepl) * (c*pi)**2/Area * dt/m
+               !   alpha = beta = sqrt(4*gamma)
+               IF( ln_aEVP ) THEN
+                  zalph1   = MAX( 50._wp, rpi * SQRT( 0.5_wp * zp_delt(ji,jj) * r1_e1e2t(ji,jj) * zdt_m(ji,jj) ) )
+                  z1_alph1 = 1._wp / ( zalph1 + 1._wp )
+                  zalph2   = zalph1
+                  z1_alph2 = z1_alph1
+               ENDIF
+               
+               ! stress at T points
+               zs1(ji,jj) = ( zs1(ji,jj) * zalph1 + zp_delt(ji,jj) * ( zdiv - zdelta ) ) * z1_alph1
+               zs2(ji,jj) = ( zs2(ji,jj) * zalph2 + zp_delt(ji,jj) * ( zdt * z1_ecc2 ) ) * z1_alph2
+             
+            END DO
+         END DO
+         CALL lbc_lnk( zp_delt, 'T', 1. )
+
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+
+               ! alpha & beta for aEVP
+               IF( ln_aEVP ) THEN
+                  zalph2   = MAX( 50._wp, rpi * SQRT( 0.5_wp * zp_delt(ji,jj) * r1_e1e2t(ji,jj) * zdt_m(ji,jj) ) )
+                  z1_alph2 = 1._wp / ( zalph2 + 1._wp )
+                  zbeta(ji,jj) = zalph2
+               ENDIF
+               
+               ! P/delta at F points
+               zp_delf = 0.25_wp * ( zp_delt(ji,jj) + zp_delt(ji+1,jj) + zp_delt(ji,jj+1) + zp_delt(ji+1,jj+1) )
+               
+               ! stress at F points
+               zs12(ji,jj)= ( zs12(ji,jj) * zalph2 + zp_delf * ( zds(ji,jj) * z1_ecc2 ) * 0.5_wp ) * z1_alph2
+
+            END DO
+         END DO
+
+         ! --- Ice internal stresses (Appendix C of Hunke and Dukowicz, 2002) --- !
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1               
+               !                   !--- U points
+               zfU(ji,jj) = 0.5_wp * ( ( zs1(ji+1,jj) - zs1(ji,jj) ) * e2u(ji,jj)                                             &
+                  &                  + ( zs2(ji+1,jj) * e2t(ji+1,jj) * e2t(ji+1,jj) - zs2(ji,jj) * e2t(ji,jj) * e2t(ji,jj)    &
+                  &                    ) * r1_e2u(ji,jj)                                                                      &
+                  &                  + ( zs12(ji,jj) * e1f(ji,jj) * e1f(ji,jj) - zs12(ji,jj-1) * e1f(ji,jj-1) * e1f(ji,jj-1)  &
+                  &                    ) * 2._wp * r1_e1u(ji,jj)                                                              &
+                  &                  ) * r1_e1e2u(ji,jj)
+               !
+               !                !--- V points
+               zfV(ji,jj) = 0.5_wp * ( ( zs1(ji,jj+1) - zs1(ji,jj) ) * e1v(ji,jj)                                             &
+                  &                  - ( zs2(ji,jj+1) * e1t(ji,jj+1) * e1t(ji,jj+1) - zs2(ji,jj) * e1t(ji,jj) * e1t(ji,jj)    &
+                  &                    ) * r1_e1v(ji,jj)                                                                      &
+                  &                  + ( zs12(ji,jj) * e2f(ji,jj) * e2f(ji,jj) - zs12(ji-1,jj) * e2f(ji-1,jj) * e2f(ji-1,jj)  &
+                  &                    ) * 2._wp * r1_e2v(ji,jj)                                                              &
+                  &                  ) * r1_e1e2v(ji,jj)
+               !
+               !                !--- u_ice at V point
+               u_iceV(ji,jj) = 0.5_wp * ( ( u_ice(ji,jj  ) + u_ice(ji-1,jj  ) ) * e2t(ji,jj+1)     &
+                  &                     + ( u_ice(ji,jj+1) + u_ice(ji-1,jj+1) ) * e2t(ji,jj  ) ) * z1_e2t0(ji,jj) * vmask(ji,jj,1)
+               !
+               !                !--- v_ice at U point
+               v_iceU(ji,jj) = 0.5_wp * ( ( v_ice(ji  ,jj) + v_ice(ji  ,jj-1) ) * e1t(ji+1,jj)     &
+                  &                     + ( v_ice(ji+1,jj) + v_ice(ji+1,jj-1) ) * e1t(ji  ,jj) ) * z1_e1t0(ji,jj) * umask(ji,jj,1)
+            END DO
+         END DO
+         !
+         ! --- Computation of ice velocity --- !
+         !  Bouillon et al. 2013 (eq 47-48) => unstable unless alpha, beta vary as in Kimmritz 2016 & 2017
+         !  Bouillon et al. 2009 (eq 34-35) => stable
+         IF( MOD(jter,2) == 0 ) THEN ! even iterations
+            !
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
+                  !                 !--- tau_io/(v_oce - v_ice)
+                  zTauO = zaV(ji,jj) * zrhoco * SQRT( ( v_ice (ji,jj) - v_oce (ji,jj) ) * ( v_ice (ji,jj) - v_oce (ji,jj) )  &
+                     &                              + ( u_iceV(ji,jj) - u_oceV(ji,jj) ) * ( u_iceV(ji,jj) - u_oceV(ji,jj) ) )
+                  !                 !--- Ocean-to-Ice stress
+                  ztauy_oi(ji,jj) = zTauO * ( v_oce(ji,jj) - v_ice(ji,jj) )
+                  !
+                  !                 !--- tau_bottom/v_ice
+                  zvel  = MAX( zepsi, SQRT( v_ice(ji,jj) * v_ice(ji,jj) + u_iceV(ji,jj) * u_iceV(ji,jj) ) )
+                  zTauB = - tau_icebfr(ji,jj) / zvel
+                  !
+                  !                 !--- Coriolis at V-points (energy conserving formulation)
+                  zCory(ji,jj)  = - 0.25_wp * r1_e2v(ji,jj) *  &
+                     &    ( zmf(ji,jj  ) * ( e2u(ji,jj  ) * u_ice(ji,jj  ) + e2u(ji-1,jj  ) * u_ice(ji-1,jj  ) )  &
+                     &    + zmf(ji,jj+1) * ( e2u(ji,jj+1) * u_ice(ji,jj+1) + e2u(ji-1,jj+1) * u_ice(ji-1,jj+1) ) )
+                  !
+                  !                 !--- Sum of external forces (explicit solution) = F + tau_ia + Coriolis + spg + tau_io
+                  zTauE = zfV(ji,jj) + zTauV_ia(ji,jj) + zCory(ji,jj) + zspgV(ji,jj) + ztauy_oi(ji,jj)
+                  !
+                  !                 !--- landfast switch => 0 = static friction ; 1 = sliding friction
+                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, ztauE - tau_icebfr(ji,jj) ) - SIGN( 1._wp, zTauE ) ) )
+                  !
+                  IF( ln_aEVP ) THEN !--- ice velocity using aEVP (Kimmritz et al 2016 & 2017)
+                  v_ice(ji,jj) = ( (          rswitch * ( zmV_t(ji,jj) * ( zbeta(ji,jj) * v_ice(ji,jj) + v_ice_b(ji,jj) )         & ! previous velocity
+                     &                                  + zTauE + zTauO * v_ice(ji,jj)                                            & ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
+                     &                                  ) / MAX( zepsi, zmV_t(ji,jj) * ( zbeta(ji,jj) + 1._wp ) + zTauO - zTauB ) & ! m/dt + tau_io(only ice part) + landfast
+                     &                 + ( 1._wp - rswitch ) * v_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )           & ! static friction => slow decrease to v=0
+                     &             ) * zswitchV(ji,jj) + v_oce(ji,jj) * ( 1._wp - zswitchV(ji,jj) )                               & ! v_ice = v_oce if mass < zmmin
+                     &           ) * zmaskV(ji,jj)
+                  ELSE               !--- ice velocity using EVP implicit formulation (cf Madec doc & Bouillon 2009)
+                  v_ice(ji,jj) = ( (           rswitch   * ( zmV_t(ji,jj)  * v_ice(ji,jj)                             &  ! previous velocity
+                     &                                     + zTauE + zTauO * v_ice(ji,jj)                             &  ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
+                     &                                     ) / MAX( zepsi, zmV_t(ji,jj) + zTauO - zTauB )             &  ! m/dt + tau_io(only ice part) + landfast
+                     &              + ( 1._wp - rswitch ) * v_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )  &  ! static friction => slow decrease to v=0
+                     &              ) * zswitchV(ji,jj) + v_oce(ji,jj) * ( 1._wp - zswitchV(ji,jj) )                  &  ! v_ice = v_oce if mass < zmmin
+                     &            ) * zmaskV(ji,jj)
+                  ENDIF
+               END DO
+            END DO
+            CALL lbc_lnk( v_ice, 'V', -1. )
+            !
+#if defined key_agrif
+!!            CALL agrif_interp_lim3( 'V', jter, nn_nevp )
+            CALL agrif_interp_lim3( 'V' )
+#endif
+            IF( ln_bdy ) CALL bdy_ice_dyn( 'V' )
+            !
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1          
+                  !                 !--- tau_io/(u_oce - u_ice)
+                  zTauO = zaU(ji,jj) * zrhoco * SQRT( ( u_ice (ji,jj) - u_oce (ji,jj) ) * ( u_ice (ji,jj) - u_oce (ji,jj) )  &
+                     &                              + ( v_iceU(ji,jj) - v_oceU(ji,jj) ) * ( v_iceU(ji,jj) - v_oceU(ji,jj) ) )
+                  !                 !--- Ocean-to-Ice stress
+                  ztaux_oi(ji,jj) = zTauO * ( u_oce(ji,jj) - u_ice(ji,jj) )
+                  !
+                  !                 !--- tau_bottom/u_ice
+                  zvel  = MAX( zepsi, SQRT( v_iceU(ji,jj) * v_iceU(ji,jj) + u_ice(ji,jj) * u_ice(ji,jj) ) )
+                  zTauB = - tau_icebfr(ji,jj) / zvel
+                  !
+                  !                 !--- Coriolis at U-points (energy conserving formulation)
+                  zCorx(ji,jj)  =   0.25_wp * r1_e1u(ji,jj) *  &
+                     &    ( zmf(ji  ,jj) * ( e1v(ji  ,jj) * v_ice(ji  ,jj) + e1v(ji  ,jj-1) * v_ice(ji  ,jj-1) )  &
+                     &    + zmf(ji+1,jj) * ( e1v(ji+1,jj) * v_ice(ji+1,jj) + e1v(ji+1,jj-1) * v_ice(ji+1,jj-1) ) )
+                  !
+                  !                 !--- Sum of external forces (explicit solution) = F + tau_ia + Coriolis + spg + tau_io
+                  zTauE = zfU(ji,jj) + zTauU_ia(ji,jj) + zCorx(ji,jj) + zspgU(ji,jj) + ztaux_oi(ji,jj)
+                  !
+                  !                 !--- landfast switch => 0 = static friction ; 1 = sliding friction
+                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, ztauE - tau_icebfr(ji,jj) ) - SIGN( 1._wp, zTauE ) ) )
+                  !
+                  IF( ln_aEVP ) THEN !--- ice velocity using aEVP (Kimmritz et al 2016 & 2017)
+                  u_ice(ji,jj) = ( (          rswitch * ( zmU_t(ji,jj) * ( zbeta(ji,jj) * u_ice(ji,jj) + u_ice_b(ji,jj) )         & ! previous velocity
+                     &                                     + zTauE + zTauO * u_ice(ji,jj)                                         & ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
+                     &                                  ) / MAX( zepsi, zmU_t(ji,jj) * ( zbeta(ji,jj) + 1._wp ) + zTauO - zTauB ) & ! m/dt + tau_io(only ice part) + landfast
+                     &              + ( 1._wp - rswitch ) * u_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )              & ! static friction => slow decrease to v=0
+                     &              ) * zswitchU(ji,jj) + u_oce(ji,jj) * ( 1._wp - zswitchU(ji,jj) )                              & ! v_ice = v_oce if mass < zmmin 
+                     &            ) * zmaskU(ji,jj)
+                  ELSE               !--- ice velocity using EVP implicit formulation (cf Madec doc & Bouillon 2009)
+                  u_ice(ji,jj) = ( (           rswitch   * ( zmU_t(ji,jj)  * u_ice(ji,jj)                             &  ! previous velocity
+                     &                                     + zTauE + zTauO * u_ice(ji,jj)                             &  ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
+                     &                                     ) / MAX( zepsi, zmU_t(ji,jj) + zTauO - zTauB )             &  ! m/dt + tau_io(only ice part) + landfast
+                     &              + ( 1._wp - rswitch ) * u_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )  &  ! static friction => slow decrease to v=0
+                     &              ) * zswitchU(ji,jj) + u_oce(ji,jj) * ( 1._wp - zswitchU(ji,jj) )                  &  ! v_ice = v_oce if mass < zmmin 
+                     &            ) * zmaskU(ji,jj)
+                  ENDIF
+               END DO
+            END DO
+            CALL lbc_lnk( u_ice, 'U', -1. )
+            !
+#if defined key_agrif
+!!            CALL agrif_interp_lim3( 'U', jter, nn_nevp )
+            CALL agrif_interp_lim3( 'U' )
+#endif
+            IF( ln_bdy ) CALL bdy_ice_dyn( 'U' )
+            !
+         ELSE ! odd iterations
+            !
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
+                  !                 !--- tau_io/(u_oce - u_ice)
+                  zTauO = zaU(ji,jj) * zrhoco * SQRT( ( u_ice (ji,jj) - u_oce (ji,jj) ) * ( u_ice (ji,jj) - u_oce (ji,jj) )  &
+                     &                              + ( v_iceU(ji,jj) - v_oceU(ji,jj) ) * ( v_iceU(ji,jj) - v_oceU(ji,jj) ) )
+                  !                 !--- Ocean-to-Ice stress
+                  ztaux_oi(ji,jj) = zTauO * ( u_oce(ji,jj) - u_ice(ji,jj) )
+                  !
+                  !                 !--- tau_bottom/u_ice
+                  zvel  = MAX( zepsi, SQRT( v_iceU(ji,jj) * v_iceU(ji,jj) + u_ice(ji,jj) * u_ice(ji,jj) ) )
+                  zTauB = - tau_icebfr(ji,jj) / zvel
+                  !
+                  !                 !--- Coriolis at U-points (energy conserving formulation)
+                  zCorx(ji,jj)  =   0.25_wp * r1_e1u(ji,jj) *  &
+                     &    ( zmf(ji  ,jj) * ( e1v(ji  ,jj) * v_ice(ji  ,jj) + e1v(ji  ,jj-1) * v_ice(ji  ,jj-1) )  &
+                     &    + zmf(ji+1,jj) * ( e1v(ji+1,jj) * v_ice(ji+1,jj) + e1v(ji+1,jj-1) * v_ice(ji+1,jj-1) ) )
+                  !
+                  !                 !--- Sum of external forces (explicit solution) = F + tau_ia + Coriolis + spg + tau_io
+                  zTauE = zfU(ji,jj) + zTauU_ia(ji,jj) + zCorx(ji,jj) + zspgU(ji,jj) + ztaux_oi(ji,jj)
+                  !
+                  !                 !--- landfast switch => 0 = static friction ; 1 = sliding friction
+                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, ztauE - tau_icebfr(ji,jj) ) - SIGN( 1._wp, zTauE ) ) )
+                  !
+                  IF( ln_aEVP ) THEN !--- ice velocity using aEVP (Kimmritz et al 2016 & 2017)
+                  u_ice(ji,jj) = ( (          rswitch * ( zmU_t(ji,jj) * ( zbeta(ji,jj) * u_ice(ji,jj) + u_ice_b(ji,jj) )         & ! previous velocity
+                     &                                     + zTauE + zTauO * u_ice(ji,jj)                                         & ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
+                     &                                  ) / MAX( zepsi, zmU_t(ji,jj) * ( zbeta(ji,jj) + 1._wp ) + zTauO - zTauB ) & ! m/dt + tau_io(only ice part) + landfast
+                     &              + ( 1._wp - rswitch ) * u_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )              & ! static friction => slow decrease to v=0
+                     &              ) * zswitchU(ji,jj) + u_oce(ji,jj) * ( 1._wp - zswitchU(ji,jj) )                              & ! v_ice = v_oce if mass < zmmin 
+                     &            ) * zmaskU(ji,jj)
+                  ELSE               !--- ice velocity using EVP implicit formulation (cf Madec doc & Bouillon 2009)
+                  u_ice(ji,jj) = ( (           rswitch   * ( zmU_t(ji,jj)  * u_ice(ji,jj)                             &  ! previous velocity
+                     &                                     + zTauE + zTauO * u_ice(ji,jj)                             &  ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
+                     &                                     ) / MAX( zepsi, zmU_t(ji,jj) + zTauO - zTauB )             &  ! m/dt + tau_io(only ice part) + landfast
+                     &              + ( 1._wp - rswitch ) * u_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )  &  ! static friction => slow decrease to v=0
+                     &              ) * zswitchU(ji,jj) + u_oce(ji,jj) * ( 1._wp - zswitchU(ji,jj) )                  &  ! v_ice = v_oce if mass < zmmin 
+                     &            ) * zmaskU(ji,jj)
+                  ENDIF
+               END DO
+            END DO
+            CALL lbc_lnk( u_ice, 'U', -1. )
+            !
+#if defined key_agrif
+!!            CALL agrif_interp_lim3( 'U', jter, nn_nevp )
+            CALL agrif_interp_lim3( 'U' )
+#endif
+            IF( ln_bdy ) CALL bdy_ice_dyn( 'U' )
+            !
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
+                  !                 !--- tau_io/(v_oce - v_ice)
+                  zTauO = zaV(ji,jj) * zrhoco * SQRT( ( v_ice (ji,jj) - v_oce (ji,jj) ) * ( v_ice (ji,jj) - v_oce (ji,jj) )  &
+                     &                              + ( u_iceV(ji,jj) - u_oceV(ji,jj) ) * ( u_iceV(ji,jj) - u_oceV(ji,jj) ) )
+                  !                 !--- Ocean-to-Ice stress
+                  ztauy_oi(ji,jj) = zTauO * ( v_oce(ji,jj) - v_ice(ji,jj) )
+                  !
+                  !                 !--- tau_bottom/v_ice
+                  zvel  = MAX( zepsi, SQRT( v_ice(ji,jj) * v_ice(ji,jj) + u_iceV(ji,jj) * u_iceV(ji,jj) ) )
+                  ztauB = - tau_icebfr(ji,jj) / zvel
+                  !
+                  !                 !--- Coriolis at v-points (energy conserving formulation)
+                  zCory(ji,jj)  = - 0.25_wp * r1_e2v(ji,jj) *  &
+                     &    ( zmf(ji,jj  ) * ( e2u(ji,jj  ) * u_ice(ji,jj  ) + e2u(ji-1,jj  ) * u_ice(ji-1,jj  ) )  &
+                     &    + zmf(ji,jj+1) * ( e2u(ji,jj+1) * u_ice(ji,jj+1) + e2u(ji-1,jj+1) * u_ice(ji-1,jj+1) ) )
+                  !
+                  !                 !--- Sum of external forces (explicit solution) = F + tau_ia + Coriolis + spg + tau_io
+                  zTauE = zfV(ji,jj) + zTauV_ia(ji,jj) + zCory(ji,jj) + zspgV(ji,jj) + ztauy_oi(ji,jj)
+                  !
+                  !                 !--- landfast switch => 0 = static friction ; 1 = sliding friction
+                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, zTauE - tau_icebfr(ji,jj) ) - SIGN( 1._wp, zTauE ) ) )
+                  !
+                  IF( ln_aEVP ) THEN !--- ice velocity using aEVP (Kimmritz et al 2016 & 2017)
+                  v_ice(ji,jj) = ( (          rswitch * ( zmV_t(ji,jj) * ( zbeta(ji,jj) * v_ice(ji,jj) + v_ice_b(ji,jj) )         & ! previous velocity
+                     &                                  + zTauE + zTauO * v_ice(ji,jj)                                            & ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
+                     &                                  ) / MAX( zepsi, zmV_t(ji,jj) * ( zbeta(ji,jj) + 1._wp ) + zTauO - zTauB ) & ! m/dt + tau_io(only ice part) + landfast
+                     &                 + ( 1._wp - rswitch ) * v_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )           & ! static friction => slow decrease to v=0
+                     &             ) * zswitchV(ji,jj) + v_oce(ji,jj) * ( 1._wp - zswitchV(ji,jj) )                               & ! v_ice = v_oce if mass < zmmin
+                     &           ) * zmaskV(ji,jj)
+                  ELSE               !--- ice velocity using EVP implicit formulation (cf Madec doc & Bouillon 2009)
+                  v_ice(ji,jj) = ( (           rswitch   * ( zmV_t(ji,jj)  * v_ice(ji,jj)                             &  ! previous velocity
+                     &                                     + zTauE + zTauO * v_ice(ji,jj)                             &  ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
+                     &                                     ) / MAX( zepsi, zmV_t(ji,jj) + zTauO - zTauB )             &  ! m/dt + tau_io(only ice part) + landfast
+                     &              + ( 1._wp - rswitch ) * v_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )  &  ! static friction => slow decrease to v=0
+                     &              ) * zswitchV(ji,jj) + v_oce(ji,jj) * ( 1._wp - zswitchV(ji,jj) )                  &  ! v_ice = v_oce if mass < zmmin
+                     &            ) * zmaskV(ji,jj)
+                  ENDIF
+               END DO
+            END DO
+            CALL lbc_lnk( v_ice, 'V', -1. )
+            !
+#if defined key_agrif
+!!            CALL agrif_interp_lim3( 'V', jter, nn_nevp )
+            CALL agrif_interp_lim3( 'V' )
+#endif
+            IF( ln_bdy ) CALL bdy_ice_dyn( 'V' )
+            !
+         ENDIF
+         
+         IF(ln_ctl) THEN   ! Convergence test
+            DO jj = 2 , jpjm1
+               zresr(:,jj) = MAX( ABS( u_ice(:,jj) - zu_ice(:,jj) ), ABS( v_ice(:,jj) - zv_ice(:,jj) ) )
+            END DO
+            zresm = MAXVAL( zresr( 1:jpi, 2:jpjm1 ) )
+            IF( lk_mpp )   CALL mpp_max( zresm )   ! max over the global domain
+         ENDIF
+         !
+         !                                                ! ==================== !
+      END DO                                              !  end loop over jter  !
+      !                                                   ! ==================== !
+      !
+      !------------------------------------------------------------------------------!
+      ! 4) Recompute delta, shear and div (inputs for mechanical redistribution) 
+      !------------------------------------------------------------------------------!
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+
+            ! shear at F points
+            zds(ji,jj) = ( ( u_ice(ji,jj+1) * r1_e1u(ji,jj+1) - u_ice(ji,jj) * r1_e1u(ji,jj) ) * e1f(ji,jj) * e1f(ji,jj)   &
+               &         + ( v_ice(ji+1,jj) * r1_e2v(ji+1,jj) - v_ice(ji,jj) * r1_e2v(ji,jj) ) * e2f(ji,jj) * e2f(ji,jj)   &
+               &         ) * r1_e1e2f(ji,jj) * zfmask(ji,jj)
+
+         END DO
+      END DO           
+      
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1 ! no vector loop
+            
+            ! tension**2 at T points
+            zdt  = ( ( u_ice(ji,jj) * r1_e2u(ji,jj) - u_ice(ji-1,jj) * r1_e2u(ji-1,jj) ) * e2t(ji,jj) * e2t(ji,jj)   &
+               &   - ( v_ice(ji,jj) * r1_e1v(ji,jj) - v_ice(ji,jj-1) * r1_e1v(ji,jj-1) ) * e1t(ji,jj) * e1t(ji,jj)   &
+               &   ) * r1_e1e2t(ji,jj)
+            zdt2 = zdt * zdt
+            
+            ! shear**2 at T points (doc eq. A16)
+            zds2 = ( zds(ji,jj  ) * zds(ji,jj  ) * e1e2f(ji,jj  ) + zds(ji-1,jj  ) * zds(ji-1,jj  ) * e1e2f(ji-1,jj  )  &
+               &   + zds(ji,jj-1) * zds(ji,jj-1) * e1e2f(ji,jj-1) + zds(ji-1,jj-1) * zds(ji-1,jj-1) * e1e2f(ji-1,jj-1)  &
+               &   ) * 0.25_wp * r1_e1e2t(ji,jj)
+            
+            ! shear at T points
+            pshear_i(ji,jj) = SQRT( zdt2 + zds2 )
+
+            ! divergence at T points
+            pdivu_i(ji,jj) = ( e2u(ji,jj) * u_ice(ji,jj) - e2u(ji-1,jj) * u_ice(ji-1,jj)   &
+               &             + e1v(ji,jj) * v_ice(ji,jj) - e1v(ji,jj-1) * v_ice(ji,jj-1)   &
+               &             ) * r1_e1e2t(ji,jj)
+            
+            ! delta at T points
+            zdelta         = SQRT( pdivu_i(ji,jj) * pdivu_i(ji,jj) + ( zdt2 + zds2 ) * z1_ecc2 )  
+            rswitch        = 1._wp - MAX( 0._wp, SIGN( 1._wp, -zdelta ) ) ! 0 if delta=0
+            pdelta_i(ji,jj) = zdelta + rn_creepl * rswitch
+
+         END DO
+      END DO
+      CALL lbc_lnk_multi( pshear_i, 'T', 1., pdivu_i, 'T', 1., pdelta_i, 'T', 1. )
+      
+      ! --- Store the stress tensor for the next time step --- !
+      CALL lbc_lnk_multi( zs1, 'T', 1., zs2, 'T', 1., zs12, 'F', 1. )
+      pstress1_i (:,:) = zs1 (:,:)
+      pstress2_i (:,:) = zs2 (:,:)
+      pstress12_i(:,:) = zs12(:,:)
+      !
+
+      !------------------------------------------------------------------------------!
+      ! 5) diagnostics
+      !------------------------------------------------------------------------------!
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zswi(ji,jj) = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi06 ) ) ! 1 if ice, 0 if no ice
+         END DO
+      END DO
+
+      ! --- divergence, shear and strength --- !
+      IF( iom_use('icediv') )   CALL iom_put( "icediv" , pdivu_i (:,:) * zswi(:,:) )   ! divergence
+      IF( iom_use('iceshe') )   CALL iom_put( "iceshe" , pshear_i(:,:) * zswi(:,:) )   ! shear
+      IF( iom_use('icestr') )   CALL iom_put( "icestr" , strength(:,:) * zswi(:,:) )   ! Ice strength
+
+      ! --- charge ellipse --- !
+      IF( iom_use('isig1') .OR. iom_use('isig2') .OR. iom_use('isig3') ) THEN
+         !
+         ALLOCATE( zsig1(jpi,jpj) , zsig2(jpi,jpj) , zsig3(jpi,jpj) )
+         !         
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               zdum1 = ( zswi(ji-1,jj) * pstress12_i(ji-1,jj) + zswi(ji  ,jj-1) * pstress12_i(ji  ,jj-1) +  &  ! stress12_i at T-point
+                  &      zswi(ji  ,jj) * pstress12_i(ji  ,jj) + zswi(ji-1,jj-1) * pstress12_i(ji-1,jj-1) )  &
+                  &    / MAX( 1._wp, zswi(ji-1,jj) + zswi(ji,jj-1) + zswi(ji,jj) + zswi(ji-1,jj-1) )
+
+               zshear = SQRT( pstress2_i(ji,jj) * pstress2_i(ji,jj) + 4._wp * zdum1 * zdum1 ) ! shear stress  
+
+               zdum2 = zswi(ji,jj) / MAX( 1._wp, strength(ji,jj) )
+
+!!               zsig1(ji,jj) = 0.5_wp * zdum2 * ( pstress1_i(ji,jj) + zshear ) ! principal stress (y-direction, see Hunke & Dukowicz 2002)
+!!               zsig2(ji,jj) = 0.5_wp * zdum2 * ( pstress1_i(ji,jj) - zshear ) ! principal stress (x-direction, see Hunke & Dukowicz 2002)
+!!               zsig3(ji,jj) = zdum2**2 * ( ( pstress1_i(ji,jj) + strength(ji,jj) )**2 + ( rn_ecc * zshear )**2 ) ! quadratic relation linking compressive stress to shear stress
+!!                                                                                                               ! (scheme converges if this value is ~1, see Bouillon et al 2009 (eq. 11))
+               zsig1(ji,jj) = 0.5_wp * zdum2 * ( pstress1_i(ji,jj) )          ! compressive stress, see Bouillon et al. 2015
+               zsig2(ji,jj) = 0.5_wp * zdum2 * ( zshear )                     ! shear stress
+               zsig3(ji,jj) = zdum2**2 * ( ( pstress1_i(ji,jj) + strength(ji,jj) )**2 + ( rn_ecc * zshear )**2 )
+            END DO
+         END DO
+         CALL lbc_lnk_multi( zsig1, 'T', 1., zsig2, 'T', 1., zsig3, 'T', 1. )
+         !
+         IF( iom_use('isig1') )   CALL iom_put( "isig1" , zsig1 )
+         IF( iom_use('isig2') )   CALL iom_put( "isig2" , zsig2 )
+         IF( iom_use('isig3') )   CALL iom_put( "isig3" , zsig3 )
+         !
+         DEALLOCATE( zsig1 , zsig2 , zsig3 )
+      ENDIF
+      
+      ! --- SIMIP --- !
+      IF ( iom_use( 'normstr'  ) .OR. iom_use( 'sheastr'  ) .OR. iom_use( 'dssh_dx'  ) .OR. iom_use( 'dssh_dy'  ) .OR. &
+         & iom_use( 'corstrx'  ) .OR. iom_use( 'corstry'  ) .OR. iom_use( 'intstrx'  ) .OR. iom_use( 'intstry'  ) .OR. &
+         & iom_use( 'utau_oi'  ) .OR. iom_use( 'vtau_oi'  ) .OR. iom_use( 'xmtrpice' ) .OR. iom_use( 'ymtrpice' ) .OR. &
+         & iom_use( 'xmtrpsnw' ) .OR. iom_use( 'ymtrpsnw' ) .OR. iom_use( 'xatrp'    ) .OR. iom_use( 'yatrp'    ) ) THEN
+
+         ALLOCATE( zdiag_sig1     (jpi,jpj) , zdiag_sig2     (jpi,jpj) , zdiag_dssh_dx  (jpi,jpj) , zdiag_dssh_dy  (jpi,jpj) ,  &
+            &      zdiag_corstrx  (jpi,jpj) , zdiag_corstry  (jpi,jpj) , zdiag_intstrx  (jpi,jpj) , zdiag_intstry  (jpi,jpj) ,  &
+            &      zdiag_utau_oi  (jpi,jpj) , zdiag_vtau_oi  (jpi,jpj) , zdiag_xmtrp_ice(jpi,jpj) , zdiag_ymtrp_ice(jpi,jpj) ,  &
+            &      zdiag_xmtrp_snw(jpi,jpj) , zdiag_ymtrp_snw(jpi,jpj) , zdiag_xatrp    (jpi,jpj) , zdiag_yatrp    (jpi,jpj) )
+         
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               rswitch  = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi06 ) ) ! 1 if ice, 0 if no ice
+               
+               ! Stress tensor invariants (normal and shear stress N/m)
+               zdiag_sig1(ji,jj) = ( zs1(ji,jj) + zs2(ji,jj) ) * rswitch                                 ! normal stress
+               zdiag_sig2(ji,jj) = SQRT( ( zs1(ji,jj) - zs2(ji,jj) )**2 + 4*zs12(ji,jj)**2 ) * rswitch   ! shear stress
+               
+               ! Stress terms of the momentum equation (N/m2)
+               zdiag_dssh_dx(ji,jj) = zspgU(ji,jj) * rswitch     ! sea surface slope stress term
+               zdiag_dssh_dy(ji,jj) = zspgV(ji,jj) * rswitch
+               
+               zdiag_corstrx(ji,jj) = zCorx(ji,jj) * rswitch     ! Coriolis stress term
+               zdiag_corstry(ji,jj) = zCory(ji,jj) * rswitch
+               
+               zdiag_intstrx(ji,jj) = zfU(ji,jj)   * rswitch     ! internal stress term
+               zdiag_intstry(ji,jj) = zfV(ji,jj)   * rswitch
+               
+               zdiag_utau_oi(ji,jj) = ztaux_oi(ji,jj) * rswitch  ! oceanic stress
+               zdiag_vtau_oi(ji,jj) = ztauy_oi(ji,jj) * rswitch
+               
+               ! 2D ice mass, snow mass, area transport arrays (X, Y)
+               zfac_x = 0.5 * u_ice(ji,jj) * e2u(ji,jj) * rswitch
+               zfac_y = 0.5 * v_ice(ji,jj) * e1v(ji,jj) * rswitch
+               
+               zdiag_xmtrp_ice(ji,jj) = rhoic * zfac_x * ( vt_i(ji+1,jj) + vt_i(ji,jj) ) ! ice mass transport, X-component
+               zdiag_ymtrp_ice(ji,jj) = rhoic * zfac_y * ( vt_i(ji,jj+1) + vt_i(ji,jj) ) !        ''           Y-   ''
+               
+               zdiag_xmtrp_snw(ji,jj) = rhosn * zfac_x * ( vt_s(ji+1,jj) + vt_s(ji,jj) ) ! snow mass transport, X-component
+               zdiag_ymtrp_snw(ji,jj) = rhosn * zfac_y * ( vt_s(ji,jj+1) + vt_s(ji,jj) ) !          ''          Y-   ''
+               
+               zdiag_xatrp(ji,jj)     = zfac_x * ( at_i(ji+1,jj) + at_i(ji,jj) )         ! area transport,      X-component
+               zdiag_yatrp(ji,jj)     = zfac_y * ( at_i(ji,jj+1) + at_i(ji,jj) )         !        ''            Y-   ''
+               
+            END DO
+         END DO
+         
+         CALL lbc_lnk_multi(   zdiag_sig1   , 'T',  1., zdiag_sig2   , 'T',  1.,   &
+            &                  zdiag_dssh_dx, 'U', -1., zdiag_dssh_dy, 'V', -1.,   &
+            &                  zdiag_corstrx, 'U', -1., zdiag_corstry, 'V', -1.,   & 
+            &                  zdiag_intstrx, 'U', -1., zdiag_intstry, 'V', -1.    )
+         
+         CALL lbc_lnk_multi(   zdiag_utau_oi, 'U', -1., zdiag_vtau_oi, 'V', -1.    )
+         
+         CALL lbc_lnk_multi(   zdiag_xmtrp_ice, 'U', -1., zdiag_xmtrp_snw, 'U', -1.,   &
+            &                  zdiag_xatrp    , 'U', -1., zdiag_ymtrp_ice, 'V', -1.,   &
+            &                  zdiag_ymtrp_snw, 'V', -1., zdiag_yatrp    , 'V', -1.    )
+         
+         IF( iom_use('normstr' ) )   CALL iom_put( 'normstr'  ,  zdiag_sig1(:,:)      )   ! Normal stress
+         IF( iom_use('sheastr' ) )   CALL iom_put( 'sheastr'  ,  zdiag_sig2(:,:)      )   ! Shear stress
+         IF( iom_use('dssh_dx' ) )   CALL iom_put( 'dssh_dx'  ,  zdiag_dssh_dx(:,:)   )   ! Sea-surface tilt term in force balance (x)
+         IF( iom_use('dssh_dy' ) )   CALL iom_put( 'dssh_dy'  ,  zdiag_dssh_dy(:,:)   )   ! Sea-surface tilt term in force balance (y)
+         IF( iom_use('corstrx' ) )   CALL iom_put( 'corstrx'  ,  zdiag_corstrx(:,:)   )   ! Coriolis force term in force balance (x)
+         IF( iom_use('corstry' ) )   CALL iom_put( 'corstry'  ,  zdiag_corstry(:,:)   )   ! Coriolis force term in force balance (y)
+         IF( iom_use('intstrx' ) )   CALL iom_put( 'intstrx'  ,  zdiag_intstrx(:,:)   )   ! Internal force term in force balance (x)
+         IF( iom_use('intstry' ) )   CALL iom_put( 'intstry'  ,  zdiag_intstry(:,:)   )   ! Internal force term in force balance (y)
+         IF( iom_use('utau_oi' ) )   CALL iom_put( 'utau_oi'  ,  zdiag_utau_oi(:,:)   )   ! Ocean stress term in force balance (x)
+         IF( iom_use('vtau_oi' ) )   CALL iom_put( 'vtau_oi'  ,  zdiag_vtau_oi(:,:)   )   ! Ocean stress term in force balance (y)
+         IF( iom_use('xmtrpice') )   CALL iom_put( 'xmtrpice' ,  zdiag_xmtrp_ice(:,:) )   ! X-component of sea-ice mass transport (kg/s)
+         IF( iom_use('ymtrpice') )   CALL iom_put( 'ymtrpice' ,  zdiag_ymtrp_ice(:,:) )   ! Y-component of sea-ice mass transport 
+         IF( iom_use('xmtrpsnw') )   CALL iom_put( 'xmtrpsnw' ,  zdiag_xmtrp_snw(:,:) )   ! X-component of snow mass transport (kg/s)
+         IF( iom_use('ymtrpsnw') )   CALL iom_put( 'ymtrpsnw' ,  zdiag_ymtrp_snw(:,:) )   ! Y-component of snow mass transport
+         IF( iom_use('xatrp'   ) )   CALL iom_put( 'xatrp'    ,  zdiag_xatrp(:,:)     )   ! X-component of ice area transport
+         IF( iom_use('yatrp'   ) )   CALL iom_put( 'yatrp'    ,  zdiag_yatrp(:,:)     )   ! Y-component of ice area transport
+
+         DEALLOCATE( zdiag_sig1      , zdiag_sig2      , zdiag_dssh_dx   , zdiag_dssh_dy   ,  &
+            &        zdiag_corstrx   , zdiag_corstry   , zdiag_intstrx   , zdiag_intstry   ,  &
+            &        zdiag_utau_oi   , zdiag_vtau_oi   , zdiag_xmtrp_ice , zdiag_ymtrp_ice ,  &
+            &        zdiag_xmtrp_snw , zdiag_ymtrp_snw , zdiag_xatrp     , zdiag_yatrp     )
+
+      ENDIF
+      !
+   END SUBROUTINE ice_dyn_rhg_evp
+
+
+   SUBROUTINE rhg_evp_rst( cdrw, kt )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE rhg_evp_rst  ***
+      !!                     
+      !! ** Purpose :   Read or write RHG file in restart file
+      !!
+      !! ** Method  :   use of IOM library
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*) , INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
+      INTEGER, OPTIONAL, INTENT(in) ::   kt     ! ice time-step
+      !
+      INTEGER  ::   iter            ! local integer
+      INTEGER  ::   id1, id2, id3   ! local integers
+      !!----------------------------------------------------------------------
+      !
+      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialize
+         !                                   ! ---------------
+         IF( ln_rstart ) THEN                   !* Read the restart file
+            !
+            id1 = iom_varid( numrir, 'stress1_i' , ldstop = .FALSE. )
+            id2 = iom_varid( numrir, 'stress2_i' , ldstop = .FALSE. )
+            id3 = iom_varid( numrir, 'stress12_i', ldstop = .FALSE. )
+            !
+            IF( MIN( id1, id2, id3 ) > 0 ) THEN      ! fields exist
+               CALL iom_get( numrir, jpdom_autoglo, 'stress1_i' , stress1_i  )
+               CALL iom_get( numrir, jpdom_autoglo, 'stress2_i' , stress2_i  )
+               CALL iom_get( numrir, jpdom_autoglo, 'stress12_i', stress12_i )
+            ELSE                                     ! start rheology from rest
+               IF(lwp) WRITE(numout,*) '   ==>>   previous run without rheology, set stresses to 0'
+               stress1_i (:,:) = 0._wp
+               stress2_i (:,:) = 0._wp
+               stress12_i(:,:) = 0._wp
+            ENDIF
+         ELSE                                   !* Start from rest
+            IF(lwp) WRITE(numout,*) '   ==>>   start from rest: set stresses to 0'
+            stress1_i (:,:) = 0._wp
+            stress2_i (:,:) = 0._wp
+            stress12_i(:,:) = 0._wp
+         ENDIF
+         !
+      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
+         !                                   ! -------------------
+         IF(lwp) WRITE(numout,*) '---- rhg-rst ----'
+         iter = kt + nn_fsbc - 1             ! ice restarts are written at kt == nitrst - nn_fsbc + 1
+         !
+         CALL iom_rstput( iter, nitrst, numriw, 'stress1_i' , stress1_i  )
+         CALL iom_rstput( iter, nitrst, numriw, 'stress2_i' , stress2_i  )
+         CALL iom_rstput( iter, nitrst, numriw, 'stress12_i', stress12_i )
+         !
+      ENDIF
+      !
+   END SUBROUTINE rhg_evp_rst
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty module           NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!==============================================================================
+END MODULE icedyn_rhg_evp
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/iceforcing.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/iceforcing.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/iceforcing.F90	(revision 9019)
@@ -0,0 +1,319 @@
+MODULE iceforcing
+   !!======================================================================
+   !!                       ***  MODULE  iceforcing  ***
+   !! Sea-Ice :   air-ice forcing fields
+   !!=====================================================================
+   !! History :  4.0  ! 2017-08  (C. Rousset) Original code
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3' :                                     ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE ice            ! sea-ice: variables
+   USE sbc_oce        ! Surface boundary condition: ocean fields
+   USE sbc_ice        ! Surface boundary condition: ice   fields
+   USE usrdef_sbc     ! Surface boundary condition: user defined
+   USE sbcblk         ! Surface boundary condition: bulk
+   USE sbccpl         ! Surface boundary condition: coupled interface
+   USE icealb         ! sea-ice: albedo
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE lbclnk         ! lateral boundary conditions (or mpp links)
+   USE timing         ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC ice_forcing_tau   ! called by icestp.F90
+   PUBLIC ice_forcing_flx   ! called by icestp.F90
+   PUBLIC ice_forcing_init  ! called by icestp.F90
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , UCL NEMO Consortium (2017)
+   !! $Id: icestp.F90 8319 2017-07-11 15:00:44Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_forcing_tau( kt, ksbc, utau_ice, vtau_ice )
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_forcing_tau  ***
+      !!
+      !! ** Purpose : provide surface boundary condition for sea ice (momentum)
+      !!
+      !! ** Action  : It provides the following fields:
+      !!              utau_ice, vtau_ice : surface ice stress (U- & V-points) [N/m2]
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt      ! ocean time step
+      INTEGER, INTENT(in) ::   ksbc    ! type of sbc flux ( 1 = user defined formulation, 
+                                       !                    3 = bulk formulation,
+                                       !                    4 = Pure Coupled formulation)
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(out) ::   utau_ice, vtau_ice 
+      !!
+      INTEGER  ::   ji, jj                 ! dummy loop index
+      REAL(wp), DIMENSION(jpi,jpj) ::   zutau_ice, zvtau_ice 
+      !!-------------------------------------------------------------------
+
+      IF( nn_timing == 1 )   CALL timing_start('ice_forcing')
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*)'ice_forcing_tau: Surface boundary condition for sea ice (momentum)'
+         WRITE(numout,*)'~~~~~~~~~~~~~~~'
+      ENDIF
+
+      SELECT CASE( ksbc )
+         CASE( jp_usr     )   ;    CALL usrdef_sbc_ice_tau( kt )                 ! user defined formulation
+         CASE( jp_blk     )   ;    CALL blk_ice_tau                              ! Bulk         formulation
+         CASE( jp_purecpl )   ;    CALL sbc_cpl_ice_tau( utau_ice , vtau_ice )   ! Coupled      formulation
+      END SELECT
+
+      IF( ln_mixcpl) THEN                                                        ! Case of a mixed Bulk/Coupled formulation
+                                   CALL sbc_cpl_ice_tau( zutau_ice , zvtau_ice )
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               utau_ice(ji,jj) = utau_ice(ji,jj) * xcplmask(ji,jj,0) + zutau_ice(ji,jj) * ( 1. - xcplmask(ji,jj,0) )
+               vtau_ice(ji,jj) = vtau_ice(ji,jj) * xcplmask(ji,jj,0) + zvtau_ice(ji,jj) * ( 1. - xcplmask(ji,jj,0) )
+            END DO
+         END DO
+         CALL lbc_lnk_multi( utau_ice, 'U', -1., vtau_ice, 'V', -1. )
+      ENDIF
+
+      IF( nn_timing == 1 )   CALL timing_stop('ice_forcing')
+      !
+   END SUBROUTINE ice_forcing_tau
+
+   
+   SUBROUTINE ice_forcing_flx( kt, ksbc )
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_forcing_flx  ***
+      !!
+      !! ** Purpose : provide surface boundary condition for sea ice (flux)
+      !!
+      !! ** Action  : It provides the following fields used in sea ice model:
+      !!                emp_oce , emp_ice                        = E-P over ocean and sea ice                    [Kg/m2/s]
+      !!                sprecip                                  = solid precipitation                           [Kg/m2/s]
+      !!                evap_ice                                 = sublimation                                   [Kg/m2/s]
+      !!                qsr_tot , qns_tot                        = solar & non solar heat flux (total)           [W/m2]
+      !!                qsr_ice , qns_ice                        = solar & non solar heat flux over ice          [W/m2]
+      !!                dqns_ice                                 = non solar  heat sensistivity                  [W/m2]
+      !!                qemp_oce, qemp_ice, qprec_ice, qevap_ice = sensible heat (associated with evap & precip) [W/m2]
+      !!            + some fields that are not used outside this module: 
+      !!                qla_ice                                  = latent heat flux over ice                     [W/m2]
+      !!                dqla_ice                                 = latent heat sensistivity                      [W/m2]
+      !!                tprecip                                  = total  precipitation                          [Kg/m2/s]
+      !!                alb_ice                                  = albedo above sea ice
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! ocean time step
+      INTEGER, INTENT(in) ::   ksbc   ! flux formulation (user defined, bulk or Pure Coupled)
+      !
+      INTEGER  ::   ji, jj, jl                                ! dummy loop index
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zalb_os, zalb_cs  ! ice albedo under overcast/clear sky
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zalb              ! 2D workspace
+      !!--------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('ice_forcing_flx')
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*)'ice_forcing_flx: Surface boundary condition for sea ice (flux)'
+         WRITE(numout,*)'~~~~~~~~~~~~~~~'
+      ENDIF
+
+      ! --- cloud-sky and overcast-sky ice albedos --- !
+      CALL ice_alb( t_su, h_i, h_s, ln_pnd_alb, a_ip_frac, h_ip, zalb_cs, zalb_os )
+
+      ! albedo depends on cloud fraction because of non-linear spectral effects
+!!gm cldf_ice is a real, DOCTOR naming rule: start with cd means CHARACTER passed in argument !
+      alb_ice(:,:,:) = ( 1. - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:)
+      !
+      !
+      SELECT CASE( ksbc )   !== fluxes over sea ice ==!
+      !
+      CASE( jp_usr )              !--- user defined formulation
+                                  CALL usrdef_sbc_ice_flx( kt, h_s, h_i )
+      CASE( jp_blk )              !--- bulk formulation
+                                  CALL blk_ice_flx    ( t_su, h_s, h_i, alb_ice )    ! 
+         IF( ln_mixcpl        )   CALL sbc_cpl_ice_flx( picefr=at_i_b, palbi=alb_ice, psst=sst_m, pist=t_su, phs=h_s, phi=h_i )
+         IF( nn_flxdist /= -1 )   CALL ice_flx_dist   ( t_su, alb_ice, qns_ice, qsr_ice, dqns_ice, evap_ice, devap_ice, nn_flxdist )
+         SELECT CASE( nice_jules )
+         CASE( np_jules_ACTIVE )  !    compute conduction flux and surface temperature (as in Jules surface module)
+                                  CALL blk_ice_qcn    ( nn_monocat, t_su, t_bo, h_s, h_i )
+         END SELECT
+      CASE ( jp_purecpl )         !--- coupled formulation
+                                  CALL sbc_cpl_ice_flx( picefr=at_i_b, palbi=alb_ice, psst=sst_m, pist=t_su, phs=h_s, phi=h_i )
+         IF( nn_flxdist /= -1 )   CALL ice_flx_dist   ( t_su, alb_ice, qns_ice, qsr_ice, dqns_ice, evap_ice, devap_ice, nn_flxdist )
+      END SELECT
+
+      !--- output ice albedo and surface albedo ---!
+      IF( iom_use('icealb') ) THEN
+         WHERE( at_i_b <= epsi06 )   ;   zalb(:,:) = rn_alb_oce
+         ELSEWHERE                   ;   zalb(:,:) = SUM( alb_ice * a_i_b, dim=3 ) / at_i_b
+         END WHERE
+         CALL iom_put( "icealb" , zalb(:,:) )
+      ENDIF
+      IF( iom_use('albedo') ) THEN
+         zalb(:,:) = SUM( alb_ice * a_i_b, dim=3 ) + rn_alb_oce * ( 1._wp - at_i_b )
+         CALL iom_put( "albedo" , zalb(:,:) )
+      ENDIF
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('ice_forcing_flx')
+      !
+   END SUBROUTINE ice_forcing_flx
+
+
+   SUBROUTINE ice_flx_dist( ptn_ice, palb_ice, pqns_ice, pqsr_ice, pdqn_ice, pevap_ice, pdevap_ice, k_iceflx )
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_flx_dist  ***
+      !!
+      !! ** Purpose :   update the ice surface boundary condition by averaging 
+      !!              and/or redistributing fluxes on ice categories
+      !!
+      !! ** Method  :   average then redistribute
+      !!
+      !! ** Action  :   depends on k_iceflx
+      !!                = -1  Do nothing (needs N(cat) fluxes)
+      !!                =  0  Average N(cat) fluxes then apply the average over the N(cat) ice 
+      !!                =  1  Average N(cat) fluxes then redistribute over the N(cat) ice
+      !!                                                 using T-ice and albedo sensitivity
+      !!                =  2  Redistribute a single flux over categories
+      !!-------------------------------------------------------------------
+      INTEGER                   , INTENT(in   ) ::   k_iceflx   ! redistributor
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   ptn_ice    ! ice surface temperature
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   palb_ice   ! ice albedo
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pqns_ice   ! non solar flux
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pqsr_ice   ! net solar flux
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdqn_ice   ! non solar flux sensitivity
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pevap_ice  ! sublimation
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdevap_ice ! sublimation sensitivity
+      !
+      INTEGER  ::   jl      ! dummy loop index
+      !
+      REAL(wp), DIMENSION(jpi,jpj) ::   z1_at_i   ! inverse of concentration
+      !
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   z_qsr_m   ! Mean solar heat flux over all categories
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   z_qns_m   ! Mean non solar heat flux over all categories
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   z_evap_m  ! Mean sublimation over all categories
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   z_dqn_m   ! Mean d(qns)/dT over all categories
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   z_devap_m ! Mean d(evap)/dT over all categories
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zalb_m    ! Mean albedo over all categories
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   ztem_m    ! Mean temperature over all categories
+      !!----------------------------------------------------------------------
+      !
+      WHERE ( at_i (:,:) > 0._wp )   ; z1_at_i(:,:) = 1._wp / at_i (:,:)
+      ELSEWHERE                      ; z1_at_i(:,:) = 0._wp
+      END WHERE
+      
+      SELECT CASE( k_iceflx )       !==  averaged on all ice categories  ==!
+      !
+      CASE( 0 , 1 )
+         !
+         ALLOCATE( z_qns_m(jpi,jpj), z_qsr_m(jpi,jpj), z_dqn_m(jpi,jpj), z_evap_m(jpi,jpj), z_devap_m(jpi,jpj) )  
+         !
+         z_qns_m  (:,:) = SUM( a_i(:,:,:) * pqns_ice  (:,:,:) , dim=3 ) * z1_at_i(:,:)
+         z_qsr_m  (:,:) = SUM( a_i(:,:,:) * pqsr_ice  (:,:,:) , dim=3 ) * z1_at_i(:,:)
+         z_dqn_m  (:,:) = SUM( a_i(:,:,:) * pdqn_ice  (:,:,:) , dim=3 ) * z1_at_i(:,:)
+         z_evap_m (:,:) = SUM( a_i(:,:,:) * pevap_ice (:,:,:) , dim=3 ) * z1_at_i(:,:)
+         z_devap_m(:,:) = SUM( a_i(:,:,:) * pdevap_ice(:,:,:) , dim=3 ) * z1_at_i(:,:)
+         DO jl = 1, jpl
+            pqns_ice  (:,:,jl) = z_qns_m (:,:)
+            pqsr_ice  (:,:,jl) = z_qsr_m (:,:)
+            pdqn_ice  (:,:,jl) = z_dqn_m  (:,:)
+            pevap_ice (:,:,jl) = z_evap_m(:,:)
+            pdevap_ice(:,:,jl) = z_devap_m(:,:)
+         END DO
+         !
+         DEALLOCATE( z_qns_m, z_qsr_m, z_dqn_m, z_evap_m, z_devap_m )  
+         !
+      END SELECT
+      !
+      SELECT CASE( k_iceflx )       !==  redistribution on all ice categories  ==!
+      !
+      CASE( 1 , 2 )
+         !
+         ALLOCATE( zalb_m(jpi,jpj), ztem_m(jpi,jpj) )  
+         !
+         zalb_m(:,:) = SUM( a_i(:,:,:) * palb_ice(:,:,:) , dim=3 ) * z1_at_i(:,:)
+         ztem_m(:,:) = SUM( a_i(:,:,:) * ptn_ice (:,:,:) , dim=3 ) * z1_at_i(:,:)
+         DO jl = 1, jpl
+            pqns_ice (:,:,jl) = pqns_ice (:,:,jl) + pdqn_ice  (:,:,jl) * ( ptn_ice(:,:,jl) - ztem_m(:,:) )
+            pevap_ice(:,:,jl) = pevap_ice(:,:,jl) + pdevap_ice(:,:,jl) * ( ptn_ice(:,:,jl) - ztem_m(:,:) )
+            pqsr_ice (:,:,jl) = pqsr_ice (:,:,jl) * ( 1._wp - palb_ice(:,:,jl) ) / ( 1._wp - zalb_m(:,:) )
+         END DO
+         !
+         DEALLOCATE( zalb_m, ztem_m )  
+         !
+      END SELECT
+      !
+   END SUBROUTINE ice_flx_dist
+
+   SUBROUTINE ice_forcing_init
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_forcing_init  ***
+      !!
+      !! ** Purpose : Physical constants and parameters linked to the ice
+      !!      dynamics
+      !!
+      !! ** Method  :  Read the namforcing namelist and check the ice-dynamic
+      !!       parameter values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namforcing
+      !!-------------------------------------------------------------------
+      INTEGER ::   ios, ioptio   ! Local integer output status for namelist read
+      !!
+      NAMELIST/namforcing/ rn_cio, rn_blow_s, nn_flxdist, nice_jules
+      !!-------------------------------------------------------------------
+      !
+      REWIND( numnam_ice_ref )         ! Namelist namforcing in reference namelist : Ice dynamics
+      READ  ( numnam_ice_ref, namforcing, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namforcing in reference namelist', lwp )
+      !
+      REWIND( numnam_ice_cfg )         ! Namelist namforcing in configuration namelist : Ice dynamics
+      READ  ( numnam_ice_cfg, namforcing, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namforcing in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namforcing )
+      !
+      IF(lwp) THEN                     ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_forcing_init: ice parameters for ice dynamics '
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namforcing:'
+         WRITE(numout,*) '      drag coefficient for oceanic stress              rn_cio     = ', rn_cio
+         WRITE(numout,*) '      coefficient for ice-lead partition of snowfall   rn_blow_s  = ', rn_blow_s
+         WRITE(numout,*) '      Multicategory heat flux formulation              nn_flxdist = ', nn_flxdist
+         WRITE(numout,*) '      Jules coupling (0=no, 1=emulated, 2=active)      nice_jules = ', nice_jules
+      ENDIF
+      !
+      IF(lwp) WRITE(numout,*)
+      SELECT CASE( nn_flxdist )         ! ESIM Multi-category heat flux formulation
+      CASE( -1  )
+         IF(lwp) WRITE(numout,*) '   ESIM: use per-category fluxes (nn_flxdist = -1) '
+      CASE(  0  )
+         IF(lwp) WRITE(numout,*) '   ESIM: use average per-category fluxes (nn_flxdist = 0) '
+      CASE(  1  )
+         IF(lwp) WRITE(numout,*) '   ESIM: use average then redistribute per-category fluxes (nn_flxdist = 1) '
+         IF( ln_cpl )         CALL ctl_stop( 'ice_thd_init: the chosen nn_flxdist for ESIM in coupled mode must be /=1' )
+      CASE(  2  )
+         IF(lwp) WRITE(numout,*) '   ESIM: Redistribute a single flux over categories (nn_flxdist = 2) '
+         IF( .NOT. ln_cpl )   CALL ctl_stop( 'ice_thd_init: the chosen nn_flxdist for ESIM in forced mode must be /=2' )
+      CASE DEFAULT
+         CALL ctl_stop( 'ice_thd_init: ESIM option, nn_flxdist, should be between -1 and 2' )
+      END SELECT
+      !
+   END SUBROUTINE ice_forcing_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :         Empty module         NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE iceforcing
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/iceistate.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/iceistate.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/iceistate.F90	(revision 9019)
@@ -0,0 +1,575 @@
+MODULE iceistate
+   !!======================================================================
+   !!                     ***  MODULE  iceistate  ***
+   !!   sea-ice : Initialization of ice variables
+   !!======================================================================
+   !! History :  2.0  ! 2004-01 (C. Ethe, G. Madec)  Original code
+   !!            3.0  ! 2007    (M. Vancoppenolle)  Rewrite for ice cats
+   !!            3.0  ! 2009-11 (M. Vancoppenolle)  Enhanced version for ice cats
+   !!            3.0  ! 2011-02 (G. Madec)  dynamical allocation
+   !!             -   ! 2014    (C. Rousset)  add N/S initializations
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_istate       :  initialization of diagnostics ice variables
+   !!   ice_istate_init  :  initialization of ice state and namelist read
+   !!----------------------------------------------------------------------
+   USE phycst         ! physical constant
+   USE oce            ! dynamics and tracers variables
+   USE dom_oce        ! ocean domain
+   USE sbc_oce , ONLY : sst_m, sss_m, ln_ice_embd 
+   USE sbc_ice , ONLY : tn_ice, snwice_mass, snwice_mass_b
+   USE eosbn2         ! equation of state
+   USE domvvl         ! Variable volume
+   USE ice            ! sea-ice variables
+   USE icevar         ! ice_var_salprof
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE fldread        ! read input fields
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_istate        ! called by icestp.F90
+   PUBLIC   ice_istate_init   ! called by icestp.F90
+
+   INTEGER , PARAMETER ::   jpfldi = 6           ! maximum number of files to read
+   INTEGER , PARAMETER ::   jp_hti = 1           ! index of ice thickness (m)    at T-point
+   INTEGER , PARAMETER ::   jp_hts = 2           ! index of snow thicknes (m)    at T-point
+   INTEGER , PARAMETER ::   jp_ati = 3           ! index of ice fraction (%) at T-point
+   INTEGER , PARAMETER ::   jp_tsu = 4           ! index of ice surface temp (K)    at T-point
+   INTEGER , PARAMETER ::   jp_tmi = 5           ! index of ice temp at T-point
+   INTEGER , PARAMETER ::   jp_smi = 6           ! index of ice sali at T-point
+   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   si  ! structure of input fields (file informations, fields read)
+   !
+   !                             !! ** namelist (namini) **
+   LOGICAL  ::   ln_iceini        ! initialization or not
+   LOGICAL  ::   ln_iceini_file   ! Ice initialization state from 2D netcdf file
+   REAL(wp) ::   rn_thres_sst     ! threshold water temperature for initial sea ice
+   REAL(wp) ::   rn_hts_ini_n     ! initial snow thickness in the north
+   REAL(wp) ::   rn_hts_ini_s     ! initial snow thickness in the south
+   REAL(wp) ::   rn_hti_ini_n     ! initial ice thickness in the north
+   REAL(wp) ::   rn_hti_ini_s     ! initial ice thickness in the south
+   REAL(wp) ::   rn_ati_ini_n     ! initial leads area in the north
+   REAL(wp) ::   rn_ati_ini_s     ! initial leads area in the south
+   REAL(wp) ::   rn_smi_ini_n     ! initial salinity 
+   REAL(wp) ::   rn_smi_ini_s     ! initial salinity
+   REAL(wp) ::   rn_tmi_ini_n     ! initial temperature
+   REAL(wp) ::   rn_tmi_ini_s     ! initial temperature
+   
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: iceistate.F90 8378 2017-07-26 13:55:59Z clem $
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_istate
+      !!-------------------------------------------------------------------
+      !!                    ***  ROUTINE ice_istate  ***
+      !!
+      !! ** Purpose :   defined the sea-ice initial state
+      !!
+      !! ** Method  :   This routine will put some ice where ocean
+      !!                is at the freezing point, then fill in ice 
+      !!                state variables using prescribed initial 
+      !!                values in the namelist            
+      !!
+      !! ** Steps   :   1) Set initial surface and basal temperatures
+      !!                2) Recompute or read sea ice state variables
+      !!                3) Fill in the ice thickness distribution using gaussian
+      !!                4) Fill in space-dependent arrays for state variables
+      !!                5) snow-ice mass computation
+      !!                6) store before fields
+      !!
+      !! ** Notes   : o_i, t_su, t_s, t_i, sz_i must be filled everywhere, even
+      !!              where there is no ice (clem: I do not know why, is it mandatory?) 
+      !!--------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk, jl         ! dummy loop indices
+      INTEGER  ::   i_hemis, i_fill, jl0   ! local integers
+      REAL(wp) ::   ztmelts, zdh
+      REAL(wp) ::   zarg, zV, zconv, zdv, zfac
+      INTEGER , DIMENSION(4)           ::   itest
+      REAL(wp), DIMENSION(jpi,jpj)     ::   z2d
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zswitch    ! ice indicator
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zht_i_ini, zat_i_ini, zvt_i_ini            !data from namelist or nc file
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zts_u_ini, zht_s_ini, zsm_i_ini, ztm_i_ini !data from namelist or nc file
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zh_i_ini , za_i_ini                        !data by cattegories to fill
+      !--------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'ice_istate: sea-ice initialization '
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+
+      !--------------------------------------------------------------------
+      ! 1) Set surface and bottom temperatures to initial values
+      !--------------------------------------------------------------------
+      !
+      ! init surface temperature
+      DO jl = 1, jpl
+         t_su  (:,:,jl) = rt0 * tmask(:,:,1)
+         tn_ice(:,:,jl) = rt0 * tmask(:,:,1)
+      END DO
+      !
+      ! init basal temperature (considered at freezing point)   [Kelvin]
+      CALL eos_fzp( sss_m(:,:), t_bo(:,:) )
+      t_bo(:,:) = ( t_bo(:,:) + rt0 ) * tmask(:,:,1) 
+
+      IF( ln_iceini ) THEN
+         !-----------------------------------------------------------
+         ! 2) Compute or read sea ice variables ===> single category
+         !-----------------------------------------------------------
+         !
+         !                             !---------------!
+         IF( ln_iceini_file )THEN      ! Read a file   !
+            !                          !---------------!
+            !
+            zht_i_ini(:,:)  = si(jp_hti)%fnow(:,:,1)
+            zht_s_ini(:,:)  = si(jp_hts)%fnow(:,:,1)
+            zat_i_ini(:,:)  = si(jp_ati)%fnow(:,:,1)
+            zts_u_ini(:,:)  = si(jp_tsu)%fnow(:,:,1)
+            ztm_i_ini(:,:)  = si(jp_tmi)%fnow(:,:,1)
+            zsm_i_ini(:,:)  = si(jp_smi)%fnow(:,:,1)
+            !
+            WHERE( zat_i_ini(:,:) > 0._wp ) ; zswitch(:,:) = tmask(:,:,1) 
+            ELSEWHERE                       ; zswitch(:,:) = 0._wp
+            END WHERE
+            zvt_i_ini(:,:) = zht_i_ini(:,:) * zat_i_ini(:,:)
+            !
+            !                          !---------------!
+         ELSE                          ! Read namelist !
+            !                          !---------------!
+            ! no ice if sst <= t-freez + ttest
+            WHERE( ( sst_m(:,:) - (t_bo(:,:) - rt0) ) * tmask(:,:,1) >= rn_thres_sst )   ;   zswitch(:,:) = 0._wp 
+            ELSEWHERE                                                                    ;   zswitch(:,:) = tmask(:,:,1)
+            END WHERE
+            !
+            ! assign initial thickness, concentration, snow depth and salinity to an hemisphere-dependent array
+            WHERE( ff_t(:,:) >= 0._wp )
+               zht_i_ini(:,:) = rn_hti_ini_n * zswitch(:,:)
+               zht_s_ini(:,:) = rn_hts_ini_n * zswitch(:,:)
+               zat_i_ini(:,:) = rn_ati_ini_n * zswitch(:,:)
+               zts_u_ini(:,:) = rn_tmi_ini_n * zswitch(:,:)
+               zsm_i_ini(:,:) = rn_smi_ini_n * zswitch(:,:)
+               ztm_i_ini(:,:) = rn_tmi_ini_n * zswitch(:,:)
+            ELSEWHERE
+               zht_i_ini(:,:) = rn_hti_ini_s * zswitch(:,:)
+               zht_s_ini(:,:) = rn_hts_ini_s * zswitch(:,:)
+               zat_i_ini(:,:) = rn_ati_ini_s * zswitch(:,:)
+               zts_u_ini(:,:) = rn_tmi_ini_s * zswitch(:,:)
+               zsm_i_ini(:,:) = rn_smi_ini_s * zswitch(:,:)
+               ztm_i_ini(:,:) = rn_tmi_ini_s * zswitch(:,:)
+            END WHERE
+            zvt_i_ini(:,:) = zht_i_ini(:,:) * zat_i_ini(:,:)
+            !
+         ENDIF
+         
+         !------------------------------------------------------------------
+         ! 3) Distribute ice concentration and thickness into the categories
+         !------------------------------------------------------------------
+         ! a gaussian distribution for ice concentration is used
+         ! then we check whether the distribution fullfills
+         ! volume and area conservation, positivity and ice categories bounds
+         zh_i_ini(:,:,:) = 0._wp 
+         za_i_ini(:,:,:) = 0._wp
+         !
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               !
+               IF( zat_i_ini(ji,jj) > 0._wp .AND. zht_i_ini(ji,jj) > 0._wp )THEN
+
+                  ! find which category (jl0) the input ice thickness falls into
+                  jl0 = jpl
+                  DO jl = 1, jpl
+                     IF ( ( zht_i_ini(ji,jj) >  hi_max(jl-1) ) .AND. ( zht_i_ini(ji,jj) <= hi_max(jl) ) ) THEN
+                        jl0 = jl
+                        CYCLE
+                     ENDIF
+                  END DO
+                  !
+                  itest(:) = 0
+                  i_fill   = jpl + 1                                            !------------------------------------
+                  DO WHILE ( ( SUM( itest(:) ) /= 4 ) .AND. ( i_fill >= 2 ) )   ! iterative loop on i_fill categories
+                     !                                                          !------------------------------------
+                     i_fill = i_fill - 1
+                     !
+                     zh_i_ini(ji,jj,:) = 0._wp 
+                     za_i_ini(ji,jj,:) = 0._wp
+                     itest(:) = 0
+                     !
+                     IF ( i_fill == 1 ) THEN      !-- case very thin ice: fill only category 1
+                        zh_i_ini(ji,jj,1) = zht_i_ini(ji,jj)
+                        za_i_ini(ji,jj,1) = zat_i_ini(ji,jj)
+                     ELSE                         !-- case ice is thicker: fill categories >1
+                        ! thickness
+                        DO jl = 1, i_fill-1
+                           zh_i_ini(ji,jj,jl) = hi_mean(jl)
+                        END DO
+                        !
+                        ! concentration
+                        za_i_ini(ji,jj,jl0) = zat_i_ini(ji,jj) / SQRT(REAL(jpl))
+                        DO jl = 1, i_fill - 1
+                           IF( jl /= jl0 )THEN
+                              zarg               = ( zh_i_ini(ji,jj,jl) - zht_i_ini(ji,jj) ) / ( 0.5_wp * zht_i_ini(ji,jj) )
+                              za_i_ini(ji,jj,jl) = za_i_ini(ji,jj,jl0) * EXP(-zarg**2)
+                           ENDIF
+                        END DO
+
+                        ! last category
+                        za_i_ini(ji,jj,i_fill) = zat_i_ini(ji,jj) - SUM( za_i_ini(ji,jj,1:i_fill-1) )
+                        zV = SUM( za_i_ini(ji,jj,1:i_fill-1) * zh_i_ini(ji,jj,1:i_fill-1) )
+                        zh_i_ini(ji,jj,i_fill) = ( zvt_i_ini(ji,jj) - zV ) / MAX( za_i_ini(ji,jj,i_fill), epsi10 ) 
+
+                        ! correction if concentration of upper cat is greater than lower cat
+                        !   (it should be a gaussian around jl0 but sometimes it is not)
+                        IF ( jl0 /= jpl ) THEN
+                           DO jl = jpl, jl0+1, -1
+                              IF ( za_i_ini(ji,jj,jl) > za_i_ini(ji,jj,jl-1) ) THEN
+                                 zdv = zh_i_ini(ji,jj,jl) * za_i_ini(ji,jj,jl)
+                                 zh_i_ini(ji,jj,jl    ) = 0._wp
+                                 za_i_ini(ji,jj,jl    ) = 0._wp
+                                 za_i_ini(ji,jj,1:jl-1) = za_i_ini(ji,jj,1:jl-1)  &
+                                    &                     + zdv / MAX( REAL(jl-1) * zht_i_ini(ji,jj), epsi10 )
+                              END IF
+                           ENDDO
+                        ENDIF
+                        !
+                     ENDIF
+                     !
+                     ! Compatibility tests
+                     zconv = ABS( zat_i_ini(ji,jj) - SUM( za_i_ini(ji,jj,1:jpl) ) )           ! Test 1: area conservation
+                     IF ( zconv < epsi06 ) itest(1) = 1
+                     !
+                     zconv = ABS(       zat_i_ini(ji,jj)       * zht_i_ini(ji,jj)   &         ! Test 2: volume conservation
+                        &        - SUM( za_i_ini (ji,jj,1:jpl) * zh_i_ini (ji,jj,1:jpl) ) )
+                     IF ( zconv < epsi06 ) itest(2) = 1
+                     !
+                     IF ( zh_i_ini(ji,jj,i_fill) >= hi_max(i_fill-1) ) itest(3) = 1           ! Test 3: thickness of the last category is in-bounds ?
+                     !
+                     itest(4) = 1
+                     DO jl = 1, i_fill
+                        IF ( za_i_ini(ji,jj,jl) < 0._wp ) itest(4) = 0                        ! Test 4: positivity of ice concentrations
+                     END DO
+                     !                                                          !----------------------------
+                  END DO                                                        ! end iteration on categories
+                  !                                                             !----------------------------
+                  IF( lwp .AND. SUM(itest) /= 4 ) THEN 
+                     WRITE(numout,*)
+                     WRITE(numout,*) ' !!!! ALERT itest is not equal to 4      !!! '
+                     WRITE(numout,*) ' !!!! Something is wrong in the LIM3 initialization procedure '
+                     WRITE(numout,*)
+                     WRITE(numout,*) ' *** itest_i (i=1,4) = ', itest(:)
+                     WRITE(numout,*) ' zat_i_ini : ', zat_i_ini(ji,jj)
+                     WRITE(numout,*) ' zht_i_ini : ', zht_i_ini(ji,jj)
+                  ENDIF
+                  !
+               ENDIF
+               !
+            END DO   
+         END DO   
+
+         !---------------------------------------------------------------------
+         ! 4) Fill in sea ice arrays
+         !---------------------------------------------------------------------
+         !
+         ! Ice concentration, thickness and volume, ice salinity, ice age, surface temperature
+         DO jl = 1, jpl ! loop over categories
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  a_i(ji,jj,jl)  = zswitch(ji,jj) * za_i_ini(ji,jj,jl)                       ! concentration
+                  h_i(ji,jj,jl)  = zswitch(ji,jj) * zh_i_ini(ji,jj,jl)                       ! ice thickness
+                  s_i(ji,jj,jl)  = zswitch(ji,jj) * zsm_i_ini(ji,jj)                         ! salinity
+                  o_i(ji,jj,jl)  = 0._wp                                                     ! age (0 day)
+                  t_su(ji,jj,jl) = zswitch(ji,jj) * zts_u_ini(ji,jj) + ( 1._wp - zswitch(ji,jj) ) * rt0 ! surf temp
+                  !
+                  IF( zht_i_ini(ji,jj) > 0._wp )THEN
+                    h_s(ji,jj,jl)= h_i(ji,jj,jl) * ( zht_s_ini(ji,jj) / zht_i_ini(ji,jj) )  ! snow depth
+                  ELSE
+                    h_s(ji,jj,jl)= 0._wp
+                  ENDIF
+                  !
+                  ! This case below should not be used if (h_s/h_i) is ok in namelist
+                  ! In case snow load is in excess that would lead to transformation from snow to ice
+                  ! Then, transfer the snow excess into the ice (different from icethd_dh)
+                  zdh = MAX( 0._wp, ( rhosn * h_s(ji,jj,jl) + ( rhoic - rau0 ) * h_i(ji,jj,jl) ) * r1_rau0 ) 
+                  ! recompute h_i, h_s avoiding out of bounds values
+                  h_i(ji,jj,jl) = MIN( hi_max(jl), h_i(ji,jj,jl) + zdh )
+                  h_s(ji,jj,jl) = MAX( 0._wp, h_s(ji,jj,jl) - zdh * rhoic * r1_rhosn )
+                  !
+                  ! ice volume, salt content, age content
+                  v_i (ji,jj,jl) = h_i(ji,jj,jl) * a_i(ji,jj,jl)              ! ice volume
+                  v_s (ji,jj,jl) = h_s(ji,jj,jl) * a_i(ji,jj,jl)              ! snow volume
+                  sv_i(ji,jj,jl) = MIN( s_i(ji,jj,jl) , sss_m(ji,jj) ) * v_i(ji,jj,jl) ! salt content
+                  oa_i(ji,jj,jl) = o_i(ji,jj,jl) * a_i(ji,jj,jl)               ! age content
+               END DO
+            END DO
+         END DO
+         !
+         IF( nn_icesal /= 2 )  THEN         ! for constant salinity in time
+            CALL ice_var_salprof
+            sv_i = s_i * v_i
+         ENDIF
+         !  
+         ! Snow temperature and heat content
+         DO jk = 1, nlay_s
+            DO jl = 1, jpl ! loop over categories
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     t_s(ji,jj,jk,jl) = zswitch(ji,jj) * ztm_i_ini(ji,jj) + ( 1._wp - zswitch(ji,jj) ) * rt0
+                     ! Snow energy of melting
+                     e_s(ji,jj,jk,jl) = zswitch(ji,jj) * rhosn * ( cpic * ( rt0 - t_s(ji,jj,jk,jl) ) + lfus )
+                     !
+                     ! Mutliply by volume, and divide by number of layers to get heat content in J/m2
+                     e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) * v_s(ji,jj,jl) * r1_nlay_s
+                  END DO
+               END DO
+            END DO
+         END DO
+         !
+         ! Ice salinity, temperature and heat content
+         DO jk = 1, nlay_i
+            DO jl = 1, jpl ! loop over categories
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     t_i (ji,jj,jk,jl) = zswitch(ji,jj) * ztm_i_ini(ji,jj) + ( 1._wp - zswitch(ji,jj) ) * rt0 
+                     sz_i(ji,jj,jk,jl) = zswitch(ji,jj) * zsm_i_ini(ji,jj) + ( 1._wp - zswitch(ji,jj) ) * rn_simin
+                     ztmelts          = - tmut * sz_i(ji,jj,jk,jl) + rt0 !Melting temperature in K
+                     !
+                     ! heat content per unit volume
+                     e_i(ji,jj,jk,jl) = zswitch(ji,jj) * rhoic * (   cpic    * ( ztmelts - t_i(ji,jj,jk,jl) )         &
+                        &             + lfus * ( 1._wp - (ztmelts-rt0) / MIN( (t_i(ji,jj,jk,jl)-rt0) , -epsi20 )  )   &
+                        &             - rcp  * ( ztmelts - rt0 ) )
+                     !
+                     ! Mutliply by ice volume, and divide by number of layers to get heat content in J/m2
+                     e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * v_i(ji,jj,jl) * r1_nlay_i
+                  END DO
+               END DO
+            END DO
+         END DO
+         !
+         tn_ice (:,:,:) = t_su (:,:,:)
+         t1_ice (:,:,:) = t_i (:,:,1,:)   ! initialisation of 1st layer temp for coupled simu
+         cnd_ice(:,:,:) = 0._wp           ! initialisation of the effective conductivity at the top of ice/snow (Jules coupling)
+
+         ! Melt pond volume and fraction
+         IF ( ln_pnd_CST .OR. ln_pnd_H12 ) THEN   ;   zfac = 1._wp
+         ELSE                                     ;   zfac = 0._wp
+         ENDIF 
+         DO jl = 1, jpl
+            a_ip_frac(:,:,jl) = rn_apnd * zswitch(:,:) * zfac
+            h_ip     (:,:,jl) = rn_hpnd * zswitch(:,:) * zfac
+         END DO
+         a_ip(:,:,:) = a_ip_frac(:,:,:) * a_i (:,:,:) 
+         v_ip(:,:,:) = h_ip     (:,:,:) * a_ip(:,:,:)
+         !
+      ELSE ! if ln_iceini=false
+         a_i  (:,:,:) = 0._wp
+         v_i  (:,:,:) = 0._wp
+         v_s  (:,:,:) = 0._wp
+         sv_i (:,:,:) = 0._wp
+         oa_i (:,:,:) = 0._wp
+         h_i  (:,:,:) = 0._wp
+         h_s  (:,:,:) = 0._wp
+         s_i  (:,:,:) = 0._wp
+         o_i  (:,:,:) = 0._wp
+         !
+         e_i(:,:,:,:) = 0._wp
+         e_s(:,:,:,:) = 0._wp
+         !
+         DO jl = 1, jpl
+            DO jk = 1, nlay_i
+               t_i(:,:,jk,jl) = rt0 * tmask(:,:,1)
+            END DO
+            DO jk = 1, nlay_s
+               t_s(:,:,jk,jl) = rt0 * tmask(:,:,1)
+            END DO
+         END DO
+
+         tn_ice (:,:,:) = t_i (:,:,1,:)
+         t1_ice (:,:,:) = t_i (:,:,1,:)   ! initialisation of 1st layer temp for coupled simu
+         cnd_ice(:,:,:) = 0._wp           ! initialisation of the effective conductivity at the top of ice/snow (Jules coupling)
+         
+         a_ip(:,:,:)      = 0._wp
+         v_ip(:,:,:)      = 0._wp
+         a_ip_frac(:,:,:) = 0._wp
+         h_ip     (:,:,:) = 0._wp
+         !
+      ENDIF ! ln_iceini
+      !
+      at_i (:,:) = 0.0_wp
+      DO jl = 1, jpl
+         at_i (:,:) = at_i (:,:) + a_i (:,:,jl)
+      END DO
+      !
+      ! --- set ice velocities --- !
+      u_ice (:,:) = 0._wp
+      v_ice (:,:) = 0._wp
+      !
+      !----------------------------------------------
+      ! 5) Snow-ice mass (case ice is fully embedded)
+      !----------------------------------------------
+      snwice_mass  (:,:) = tmask(:,:,1) * SUM( rhosn * v_s(:,:,:) + rhoic * v_i(:,:,:), dim=3  )   ! snow+ice mass
+      snwice_mass_b(:,:) = snwice_mass(:,:)
+      !
+      IF( ln_ice_embd ) THEN            ! embedded sea-ice: deplete the initial ssh below sea-ice area
+         !
+         sshn(:,:) = sshn(:,:) - snwice_mass(:,:) * r1_rau0
+         sshb(:,:) = sshb(:,:) - snwice_mass(:,:) * r1_rau0
+         !
+         IF( .NOT.ln_linssh ) THEN
+            !
+            WHERE( ht_0(:,:) > 0 )   ;   z2d(:,:) = 1._wp + sshn(:,:)*tmask(:,:,1) / ht_0(:,:)
+            ELSEWHERE                ;   z2d(:,:) = 1._wp   ;   END WHERE
+            !
+            DO jk = 1,jpkm1                     ! adjust initial vertical scale factors                
+               e3t_n(:,:,jk) = e3t_0(:,:,jk) * z2d(:,:)
+               e3t_b(:,:,jk) = e3t_n(:,:,jk)
+               e3t_a(:,:,jk) = e3t_n(:,:,jk)
+            END DO
+            !
+            ! Reconstruction of all vertical scale factors at now and before time-steps
+            ! =========================================================================
+            ! Horizontal scale factor interpolations
+            ! --------------------------------------
+            CALL dom_vvl_interpol( e3t_b(:,:,:), e3u_b(:,:,:), 'U' )
+            CALL dom_vvl_interpol( e3t_b(:,:,:), e3v_b(:,:,:), 'V' )
+            CALL dom_vvl_interpol( e3t_n(:,:,:), e3u_n(:,:,:), 'U' )
+            CALL dom_vvl_interpol( e3t_n(:,:,:), e3v_n(:,:,:), 'V' )
+            CALL dom_vvl_interpol( e3u_n(:,:,:), e3f_n(:,:,:), 'F' )
+            ! Vertical scale factor interpolations
+            ! ------------------------------------
+            CALL dom_vvl_interpol( e3t_n(:,:,:), e3w_n (:,:,:), 'W'  )
+            CALL dom_vvl_interpol( e3u_n(:,:,:), e3uw_n(:,:,:), 'UW' )
+            CALL dom_vvl_interpol( e3v_n(:,:,:), e3vw_n(:,:,:), 'VW' )
+            CALL dom_vvl_interpol( e3u_b(:,:,:), e3uw_b(:,:,:), 'UW' )
+            CALL dom_vvl_interpol( e3v_b(:,:,:), e3vw_b(:,:,:), 'VW' )
+            ! t- and w- points depth
+            ! ----------------------
+            !!gm not sure of that....
+            gdept_n(:,:,1) = 0.5_wp * e3w_n(:,:,1)
+            gdepw_n(:,:,1) = 0.0_wp
+            gde3w_n(:,:,1) = gdept_n(:,:,1) - sshn(:,:)
+            DO jk = 2, jpk
+               gdept_n(:,:,jk) = gdept_n(:,:,jk-1) + e3w_n(:,:,jk  )
+               gdepw_n(:,:,jk) = gdepw_n(:,:,jk-1) + e3t_n(:,:,jk-1)
+               gde3w_n(:,:,jk) = gdept_n(:,:,jk  ) - sshn (:,:)
+            END DO
+         ENDIF
+      ENDIF
+      
+      !------------------------------------
+      ! 6) store fields at before time-step
+      !------------------------------------
+      ! it is only necessary for the 1st interpolation by Agrif
+      a_i_b  (:,:,:)   = a_i  (:,:,:)
+      e_i_b  (:,:,:,:) = e_i  (:,:,:,:)
+      v_i_b  (:,:,:)   = v_i  (:,:,:)
+      v_s_b  (:,:,:)   = v_s  (:,:,:)
+      e_s_b  (:,:,:,:) = e_s  (:,:,:,:)
+      sv_i_b (:,:,:)   = sv_i (:,:,:)
+      oa_i_b (:,:,:)   = oa_i (:,:,:)
+      u_ice_b(:,:)     = u_ice(:,:)
+      v_ice_b(:,:)     = v_ice(:,:)
+
+!!clem: output of initial state should be written here but it is impossible because
+!!      the ocean and ice are in the same file
+!!      CALL dia_wri_state( 'output.init', nit000 )
+      !
+   END SUBROUTINE ice_istate
+
+
+   SUBROUTINE ice_istate_init
+      !!-------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_istate_init  ***
+      !!        
+      !! ** Purpose :   Definition of initial state of the ice 
+      !!
+      !! ** Method  :   Read the namini namelist and check the parameter 
+      !!              values called at the first timestep (nit000)
+      !!
+      !! ** input   :  Namelist namini
+      !!
+      !!-----------------------------------------------------------------------------
+      INTEGER ::   ji, jj
+      INTEGER ::   ios, ierr, inum_ice   ! Local integer output status for namelist read
+      INTEGER ::   ifpr, ierror
+      !
+      CHARACTER(len=256) ::  cn_dir          ! Root directory for location of ice files
+      TYPE(FLD_N)                    ::   sn_hti, sn_hts, sn_ati, sn_tsu, sn_tmi, sn_smi
+      TYPE(FLD_N), DIMENSION(jpfldi) ::   slf_i                 ! array of namelist informations on the fields to read
+      !
+      NAMELIST/namini/ ln_iceini, ln_iceini_file, rn_thres_sst, rn_hts_ini_n, rn_hts_ini_s,  &
+         &             rn_hti_ini_n, rn_hti_ini_s, rn_ati_ini_n, rn_ati_ini_s, rn_smi_ini_n, &
+         &             rn_smi_ini_s, rn_tmi_ini_n, rn_tmi_ini_s,                             &
+         &             sn_hti, sn_hts, sn_ati, sn_tsu, sn_tmi, sn_smi, cn_dir
+      !!-----------------------------------------------------------------------------
+      !
+      REWIND( numnam_ice_ref )              ! Namelist namini in reference namelist : Ice initial state
+      READ  ( numnam_ice_ref, namini, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namini in reference namelist', lwp )
+      !
+      REWIND( numnam_ice_cfg )              ! Namelist namini in configuration namelist : Ice initial state
+      READ  ( numnam_ice_cfg, namini, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namini in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namini )
+      !
+      slf_i(jp_hti) = sn_hti  ;  slf_i(jp_hts) = sn_hts
+      slf_i(jp_ati) = sn_ati  ;  slf_i(jp_tsu) = sn_tsu
+      slf_i(jp_tmi) = sn_tmi  ;  slf_i(jp_smi) = sn_smi
+      !
+      !
+      IF(lwp) THEN                          ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_istate_init: ice parameters inititialisation '
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namini:'
+         WRITE(numout,*) '      initialization with ice (T) or not (F)                 ln_iceini       = ', ln_iceini
+         WRITE(numout,*) '      ice initialization from a netcdf file                  ln_iceini_file  = ', ln_iceini_file
+         WRITE(numout,*) '      max delta ocean temp. above Tfreeze with initial ice   rn_thres_sst    = ', rn_thres_sst
+         WRITE(numout,*) '      initial snow thickness in the north                    rn_hts_ini_n    = ', rn_hts_ini_n
+         WRITE(numout,*) '      initial snow thickness in the south                    rn_hts_ini_s    = ', rn_hts_ini_s 
+         WRITE(numout,*) '      initial ice thickness  in the north                    rn_hti_ini_n    = ', rn_hti_ini_n
+         WRITE(numout,*) '      initial ice thickness  in the south                    rn_hti_ini_s    = ', rn_hti_ini_s
+         WRITE(numout,*) '      initial ice concentr.  in the north                    rn_ati_ini_n    = ', rn_ati_ini_n
+         WRITE(numout,*) '      initial ice concentr.  in the north                    rn_ati_ini_s    = ', rn_ati_ini_s
+         WRITE(numout,*) '      initial  ice salinity  in the north                    rn_smi_ini_n    = ', rn_smi_ini_n
+         WRITE(numout,*) '      initial  ice salinity  in the south                    rn_smi_ini_s    = ', rn_smi_ini_s
+         WRITE(numout,*) '      initial  ice/snw temp  in the north                    rn_tmi_ini_n    = ', rn_tmi_ini_n
+         WRITE(numout,*) '      initial  ice/snw temp  in the south                    rn_tmi_ini_s    = ', rn_tmi_ini_s
+      ENDIF
+      !
+      IF( ln_iceini_file ) THEN                      ! Ice initialization using input file
+         !
+         ! set si structure
+         ALLOCATE( si(jpfldi), STAT=ierror )
+         IF( ierror > 0 ) THEN
+            CALL ctl_stop( 'Ice_ini in iceistate: unable to allocate si structure' )   ;   RETURN
+         ENDIF
+         !
+         DO ifpr = 1, jpfldi
+            ALLOCATE( si(ifpr)%fnow(jpi,jpj,1) )
+            ALLOCATE( si(ifpr)%fdta(jpi,jpj,1,2) )
+         END DO
+         !
+         ! fill si with slf_i and control print
+         CALL fld_fill( si, slf_i, cn_dir, 'ice_istate', 'ice istate ini', 'numnam_ice' )
+         !
+         CALL fld_read( nit000, 1, si )                ! input fields provided at the current time-step
+         !
+      ENDIF
+      !
+   END SUBROUTINE ice_istate_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :         Empty module         NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE iceistate
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/iceitd.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/iceitd.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/iceitd.F90	(revision 9019)
@@ -0,0 +1,726 @@
+MODULE iceitd
+   !!======================================================================
+   !!                       ***  MODULE iceitd ***
+   !!   sea-ice : ice thickness distribution
+   !!======================================================================
+   !! History :   -   !          (W. H. Lipscomb and E.C. Hunke) CICE (c) original code
+   !!            3.0  ! 2005-12  (M. Vancoppenolle) adaptation to LIM-3
+   !!             -   ! 2006-06  (M. Vancoppenolle) adaptation to include salt, age
+   !!             -   ! 2007-04  (M. Vancoppenolle) Mass conservation checked
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_itd_rem   : redistribute ice thicknesses after thermo growth and melt
+   !!   itd_glinear   : build g(h) satisfying area and volume constraints
+   !!   itd_shiftice  : shift ice across category boundaries, conserving everything
+   !!   ice_itd_reb   : rebin ice thicknesses into bounded categories
+   !!   ice_itd_init  : read ice thicknesses mean and min from namelist
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean domain
+   USE phycst         ! physical constants 
+   USE ice1D          ! sea-ice: thermodynamic variables
+   USE ice            ! sea-ice: variables
+   USE icectl         ! sea-ice: conservation tests
+   USE icetab         ! sea-ice: convert 1D<=>2D
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE prtctl         ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_itd_init  ! called in icestp
+   PUBLIC   ice_itd_rem   ! called in icethd
+   PUBLIC   ice_itd_reb   ! called in icecor
+
+   INTEGER            ::   nice_catbnd     ! choice of the type of ice category function
+   !                                       ! associated indices:
+   INTEGER, PARAMETER ::   np_cathfn = 1   ! categories defined by a function
+   INTEGER, PARAMETER ::   np_catusr = 2   ! categories defined by the user
+   !
+   !                                           !! ** namelist (namitd) **
+   LOGICAL                    ::   ln_cat_hfn   ! ice categories are defined by function like rn_himean**(-0.05)
+   REAL(wp)                   ::   rn_himean    ! mean thickness of the domain
+   LOGICAL                    ::   ln_cat_usr   ! ice categories are defined by rn_catbnd
+   REAL(wp), DIMENSION(0:100) ::   rn_catbnd    ! ice categories bounds
+   !
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: iceitd.F90 8420 2017-08-08 12:18:46Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_itd_rem( kt )
+      !!------------------------------------------------------------------
+      !!                ***  ROUTINE ice_itd_rem ***
+      !!
+      !! ** Purpose :   computes the redistribution of ice thickness
+      !!                after thermodynamic growth of ice thickness
+      !!
+      !! ** Method  :   Linear remapping 
+      !!
+      !! References :   W.H. Lipscomb, JGR 2001
+      !!------------------------------------------------------------------
+      INTEGER , INTENT (in) ::   kt      ! Ocean time step 
+      !
+      INTEGER  ::   ji, jj, jl, jcat     ! dummy loop index
+      INTEGER  ::   ipti                 ! local integer
+      REAL(wp) ::   zx1, zwk1, zdh0, zetamin, zdamax   ! local scalars
+      REAL(wp) ::   zx2, zwk2, zda0, zetamax           !   -      -
+      REAL(wp) ::   zx3        
+      REAL(wp) ::   zslope          ! used to compute local thermodynamic "speeds"
+      !
+      INTEGER , DIMENSION(jpij)       ::   iptidx          ! compute remapping or not
+      INTEGER , DIMENSION(jpij,jpl-1) ::   jdonor          ! donor category index
+      REAL(wp), DIMENSION(jpij,jpl)   ::   zdhice          ! ice thickness increment
+      REAL(wp), DIMENSION(jpij,jpl)   ::   g0, g1          ! coefficients for fitting the line of the ITD
+      REAL(wp), DIMENSION(jpij,jpl)   ::   hL, hR          ! left and right boundary for the ITD for each thickness
+      REAL(wp), DIMENSION(jpij,jpl-1) ::   zdaice, zdvice  ! local increment of ice area and volume
+      REAL(wp), DIMENSION(jpij)       ::   zhb0, zhb1      ! category boundaries for thinnes categories
+      REAL(wp), DIMENSION(jpij,0:jpl) ::   zhbnew          ! new boundaries of ice categories
+      !!------------------------------------------------------------------
+
+      IF( kt == nit000 .AND. lwp )   WRITE(numout,*) '-- ice_itd_rem: remapping ice thickness distribution' 
+
+      IF( ln_icediachk )   CALL ice_cons_hsm(0, 'iceitd_rem', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft)
+
+      !-----------------------------------------------------------------------------------------------
+      !  1) Identify grid cells with ice
+      !-----------------------------------------------------------------------------------------------
+      npti = 0   ;   nptidx(:) = 0
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF ( at_i(ji,jj) > epsi10 ) THEN
+               npti         = npti + 1
+               nptidx( npti ) = (jj - 1) * jpi + ji
+            ENDIF
+         END DO
+      END DO
+      
+      !-----------------------------------------------------------------------------------------------
+      !  2) Compute new category boundaries
+      !-----------------------------------------------------------------------------------------------
+      IF( npti > 0 ) THEN
+         !
+         zdhice(:,:) = 0._wp
+         zhbnew(:,:) = 0._wp
+         !
+         CALL tab_3d_2d( npti, nptidx(1:npti), h_i_2d (1:npti,1:jpl), h_i   )
+         CALL tab_3d_2d( npti, nptidx(1:npti), h_ib_2d(1:npti,1:jpl), h_i_b )
+         CALL tab_3d_2d( npti, nptidx(1:npti), a_i_2d  (1:npti,1:jpl), a_i    )
+         CALL tab_3d_2d( npti, nptidx(1:npti), a_ib_2d (1:npti,1:jpl), a_i_b  )
+         !
+         DO jl = 1, jpl
+            ! Compute thickness change in each ice category
+            DO ji = 1, npti
+               zdhice(ji,jl) = h_i_2d(ji,jl) - h_ib_2d(ji,jl)
+            END DO
+         END DO
+         !
+         ! --- New boundaries for category 1:jpl-1 --- !
+         DO jl = 1, jpl - 1
+            !
+            DO ji = 1, npti
+               !
+               ! --- New boundary: Hn* = Hn + Fn*dt --- !
+               !     Fn*dt = ( fn + (fn+1 - fn)/(hn+1 - hn) * (Hn - hn) ) * dt = zdhice + zslope * (Hmax - h_i_b)
+               !
+               IF    ( a_ib_2d(ji,jl) >  epsi10 .AND. a_ib_2d(ji,jl+1) >  epsi10 ) THEN   ! a(jl+1) & a(jl) /= 0
+                  zslope           = ( zdhice(ji,jl+1) - zdhice(ji,jl) ) / ( h_ib_2d(ji,jl+1) - h_ib_2d(ji,jl) )
+                  zhbnew(ji,jl) = hi_max(jl) + zdhice(ji,jl) + zslope * ( hi_max(jl) - h_ib_2d(ji,jl) )
+               ELSEIF( a_ib_2d(ji,jl) >  epsi10 .AND. a_ib_2d(ji,jl+1) <= epsi10 ) THEN   ! a(jl+1)=0 => Hn* = Hn + fn*dt
+                  zhbnew(ji,jl) = hi_max(jl) + zdhice(ji,jl)
+               ELSEIF( a_ib_2d(ji,jl) <= epsi10 .AND. a_ib_2d(ji,jl+1) >  epsi10 ) THEN   ! a(jl)=0 => Hn* = Hn + fn+1*dt
+                  zhbnew(ji,jl) = hi_max(jl) + zdhice(ji,jl+1)
+               ELSE                                                                       ! a(jl+1) & a(jl) = 0 
+                  zhbnew(ji,jl) = hi_max(jl)
+               ENDIF
+               !
+               ! --- 2 conditions for remapping --- !
+               ! 1) hn(t+1)+espi < Hn* < hn+1(t+1)-epsi               
+               !    Note: hn(t+1) must not be too close to either HR or HL otherwise a division by nearly 0 is possible 
+               !          in itd_glinear in the case (HR-HL) = 3(Hice - HL) or = 3(HR - Hice)
+               IF( a_i_2d(ji,jl  ) > epsi10 .AND. h_i_2d(ji,jl  ) > ( zhbnew(ji,jl) - epsi10 ) )   nptidx(ji) = 0
+               IF( a_i_2d(ji,jl+1) > epsi10 .AND. h_i_2d(ji,jl+1) < ( zhbnew(ji,jl) + epsi10 ) )   nptidx(ji) = 0
+               !
+               ! 2) Hn-1 < Hn* < Hn+1  
+               IF( zhbnew(ji,jl) < hi_max(jl-1) )   nptidx(ji) = 0
+               IF( zhbnew(ji,jl) > hi_max(jl+1) )   nptidx(ji) = 0
+               !
+            END DO
+         END DO
+         !
+         ! --- New boundaries for category jpl --- !
+         DO ji = 1, npti
+            IF( a_i_2d(ji,jpl) > epsi10 ) THEN
+               zhbnew(ji,jpl) = MAX( hi_max(jpl-1), 3._wp * h_i_2d(ji,jpl) - 2._wp * zhbnew(ji,jpl-1) )
+            ELSE
+               zhbnew(ji,jpl) = hi_max(jpl)  
+            ENDIF
+            !
+            ! --- 1 additional condition for remapping (1st category) --- !
+            ! H0+epsi < h1(t) < H1-epsi 
+            !    h1(t) must not be too close to either HR or HL otherwise a division by nearly 0 is possible 
+            !    in itd_glinear in the case (HR-HL) = 3(Hice - HL) or = 3(HR - Hice)
+            IF( h_ib_2d(ji,1) < ( hi_max(0) + epsi10 ) )   nptidx(ji) = 0
+            IF( h_ib_2d(ji,1) > ( hi_max(1) - epsi10 ) )   nptidx(ji) = 0
+         END DO
+         !
+         !-----------------------------------------------------------------------------------------------
+         !  3) Identify cells where remapping
+         !-----------------------------------------------------------------------------------------------
+         ipti = 0   ;   iptidx(:) = 0
+         DO ji = 1, npti
+            IF( nptidx(ji) /= 0 ) THEN
+               ipti = ipti + 1
+               iptidx(ipti)   = nptidx(ji)
+               zhbnew(ipti,:) = zhbnew(ji,:)  ! adjust zhbnew to new indices
+            ENDIF
+         END DO
+         nptidx(:) = iptidx(:)
+         npti      = ipti
+         !
+      ENDIF
+   
+      !-----------------------------------------------------------------------------------------------
+      !  4) Compute g(h) 
+      !-----------------------------------------------------------------------------------------------
+      IF( npti > 0 ) THEN
+         !
+         zhb0(:) = hi_max(0)   ;   zhb1(:) = hi_max(1)
+         g0(:,:) = 0._wp       ;   g1(:,:) = 0._wp 
+         hL(:,:) = 0._wp       ;   hR(:,:) = 0._wp 
+         !
+         DO jl = 1, jpl
+            !
+            CALL tab_2d_1d( npti, nptidx(1:npti), h_ib_1d(1:npti), h_i_b(:,:,jl) )
+            CALL tab_2d_1d( npti, nptidx(1:npti), h_i_1d (1:npti), h_i(:,:,jl)   )
+            CALL tab_2d_1d( npti, nptidx(1:npti), a_i_1d  (1:npti), a_i(:,:,jl)    )
+            CALL tab_2d_1d( npti, nptidx(1:npti), v_i_1d  (1:npti), v_i(:,:,jl)    )
+            !
+            IF( jl == 1 ) THEN
+               !  
+               ! --- g(h) for category 1 --- !
+               CALL itd_glinear( zhb0(1:npti)  , zhb1(1:npti)  , h_ib_1d(1:npti)  , a_i_1d(1:npti)  ,  &   ! in
+                  &              g0  (1:npti,1), g1  (1:npti,1), hL      (1:npti,1), hR    (1:npti,1)   )   ! out
+                  !
+               ! Area lost due to melting of thin ice
+               DO ji = 1, npti
+                  !
+                  IF( a_i_1d(ji) > epsi10 ) THEN
+                     !
+                     zdh0 =  h_i_1d(ji) - h_ib_1d(ji)                
+                     IF( zdh0 < 0.0 ) THEN      !remove area from category 1
+                        zdh0 = MIN( -zdh0, hi_max(1) )
+                        !Integrate g(1) from 0 to dh0 to estimate area melted
+                        zetamax = MIN( zdh0, hR(ji,1) ) - hL(ji,1)
+                        !
+                        IF( zetamax > 0.0 ) THEN
+                           zx1    = zetamax
+                           zx2    = 0.5 * zetamax * zetamax 
+                           zda0   = g1(ji,1) * zx2 + g0(ji,1) * zx1                        ! ice area removed
+                           zdamax = a_i_1d(ji) * (1.0 - h_i_1d(ji) / h_ib_1d(ji) ) ! Constrain new thickness <= h_i                
+                           zda0   = MIN( zda0, zdamax )                                                  ! ice area lost due to melting 
+                           !     of thin ice (zdamax > 0)
+                           ! Remove area, conserving volume
+                           h_i_1d(ji) = h_i_1d(ji) * a_i_1d(ji) / ( a_i_1d(ji) - zda0 )
+                           a_i_1d(ji)  = a_i_1d(ji) - zda0
+                           v_i_1d(ji)  = a_i_1d(ji) * h_i_1d(ji) ! useless ?
+                        ENDIF
+                        !
+                     ELSE ! if ice accretion zdh0 > 0
+                        ! zhbnew was 0, and is shifted to the right to account for thin ice growth in openwater (F0 = f1)
+                        zhbnew(ji,0) = MIN( zdh0, hi_max(1) ) 
+                     ENDIF
+                     !
+                  ENDIF
+                  !
+               END DO
+               !
+               CALL tab_1d_2d( npti, nptidx(1:npti), h_i_1d (1:npti), h_i(:,:,jl)   )
+               CALL tab_1d_2d( npti, nptidx(1:npti), a_i_1d  (1:npti), a_i(:,:,jl)    )
+               CALL tab_1d_2d( npti, nptidx(1:npti), v_i_1d  (1:npti), v_i(:,:,jl)    )
+               !
+            ENDIF ! jl=1
+            !
+            ! --- g(h) for each thickness category --- !  
+            CALL itd_glinear( zhbnew(1:npti,jl-1), zhbnew(1:npti,jl), h_i_1d(1:npti)   , a_i_1d(1:npti)   ,  &   ! in
+               &              g0    (1:npti,jl  ), g1    (1:npti,jl), hL     (1:npti,jl), hR    (1:npti,jl)   )   ! out
+            !
+         END DO
+         
+         !-----------------------------------------------------------------------------------------------
+         !  5) Compute area and volume to be shifted across each boundary (Eq. 18)
+         !-----------------------------------------------------------------------------------------------
+         DO jl = 1, jpl - 1
+            !
+            DO ji = 1, npti
+               !
+               ! left and right integration limits in eta space
+               IF (zhbnew(ji,jl) > hi_max(jl)) THEN ! Hn* > Hn => transfer from jl to jl+1
+                  zetamin = MAX( hi_max(jl)   , hL(ji,jl) ) - hL(ji,jl)   ! hi_max(jl) - hL 
+                  zetamax = MIN( zhbnew(ji,jl), hR(ji,jl) ) - hL(ji,jl)   ! hR - hL
+                  jdonor(ji,jl) = jl
+               ELSE                                 ! Hn* <= Hn => transfer from jl+1 to jl
+                  zetamin = 0.0
+                  zetamax = MIN( hi_max(jl), hR(ji,jl+1) ) - hL(ji,jl+1)  ! hi_max(jl) - hL
+                  jdonor(ji,jl) = jl + 1
+               ENDIF
+               zetamax = MAX( zetamax, zetamin ) ! no transfer if etamax < etamin
+               !
+               zx1  = zetamax - zetamin
+               zwk1 = zetamin * zetamin
+               zwk2 = zetamax * zetamax
+               zx2  = 0.5 * ( zwk2 - zwk1 )
+               zwk1 = zwk1 * zetamin
+               zwk2 = zwk2 * zetamax
+               zx3  = 1.0 / 3.0 * ( zwk2 - zwk1 )
+               jcat = jdonor(ji,jl)
+               zdaice(ji,jl) = g1(ji,jcat)*zx2 + g0(ji,jcat)*zx1
+               zdvice(ji,jl) = g1(ji,jcat)*zx3 + g0(ji,jcat)*zx2 + zdaice(ji,jl)*hL(ji,jcat)
+               !
+            END DO
+         END DO
+         
+         !----------------------------------------------------------------------------------------------
+         ! 6) Shift ice between categories
+         !----------------------------------------------------------------------------------------------
+         CALL itd_shiftice ( jdonor(1:npti,:), zdaice(1:npti,:), zdvice(1:npti,:) )
+         
+         !----------------------------------------------------------------------------------------------
+         ! 7) Make sure h_i >= minimum ice thickness hi_min
+         !----------------------------------------------------------------------------------------------
+         CALL tab_2d_1d( npti, nptidx(1:npti), h_i_1d (1:npti), h_i (:,:,1) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), a_i_1d (1:npti), a_i (:,:,1) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), a_ip_1d(1:npti), a_ip(:,:,1) )
+         !
+         DO ji = 1, npti
+            IF ( a_i_1d(ji) > epsi10 .AND. h_i_1d(ji) < rn_himin ) THEN
+               a_i_1d (ji) = a_i_1d(ji) * h_i_1d(ji) / rn_himin 
+               IF( ln_pnd_H12 )   a_ip_1d(ji) = a_ip_1d(ji) * h_i_1d(ji) / rn_himin
+               h_i_1d(ji) = rn_himin
+            ENDIF
+         END DO
+         !
+         CALL tab_1d_2d( npti, nptidx(1:npti), h_i_1d (1:npti), h_i (:,:,1) )
+         CALL tab_1d_2d( npti, nptidx(1:npti), a_i_1d (1:npti), a_i (:,:,1) )
+         CALL tab_1d_2d( npti, nptidx(1:npti), a_ip_1d(1:npti), a_ip(:,:,1) )
+         !
+      ENDIF
+      !
+      IF( ln_icediachk )   CALL ice_cons_hsm(1, 'iceitd_rem', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft)
+      !
+   END SUBROUTINE ice_itd_rem
+
+
+   SUBROUTINE itd_glinear( HbL, Hbr, phice, paice, pg0, pg1, phL, phR )
+      !!------------------------------------------------------------------
+      !!                ***  ROUTINE itd_glinear ***
+      !!
+      !! ** Purpose :   build g(h) satisfying area and volume constraints (Eq. 6 and 9)
+      !!
+      !! ** Method  :   g(h) is linear and written as: g(eta) = g1(eta) + g0
+      !!                with eta = h - HL
+      !!------------------------------------------------------------------
+      REAL(wp), DIMENSION(:), INTENT(in   ) ::   HbL, HbR      ! left and right category boundaries
+      REAL(wp), DIMENSION(:), INTENT(in   ) ::   phice, paice  ! ice thickness and concentration
+      REAL(wp), DIMENSION(:), INTENT(inout) ::   pg0, pg1      ! coefficients in linear equation for g(eta)
+      REAL(wp), DIMENSION(:), INTENT(inout) ::   phL, phR      ! min and max value of range over which g(h) > 0
+      !
+      INTEGER  ::   ji           ! horizontal indices
+      REAL(wp) ::   z1_3 , z2_3  ! 1/3 , 2/3
+      REAL(wp) ::   zh13         ! HbL + 1/3 * (HbR - HbL)
+      REAL(wp) ::   zh23         ! HbL + 2/3 * (HbR - HbL)
+      REAL(wp) ::   zdhr         ! 1 / (hR - hL)
+      REAL(wp) ::   zwk1, zwk2   ! temporary variables
+      !!------------------------------------------------------------------
+      !
+      z1_3 = 1._wp / 3._wp
+      z2_3 = 2._wp / 3._wp
+      !
+      DO ji = 1, npti
+         !
+         IF( paice(ji) > epsi10  .AND. phice(ji) > 0._wp )  THEN
+            !
+            ! Initialize hL and hR
+            phL(ji) = HbL(ji)
+            phR(ji) = HbR(ji)
+            !
+            ! Change hL or hR if hice falls outside central third of range,
+            ! so that hice is in the central third of the range [HL HR]
+            zh13 = z1_3 * ( 2._wp * phL(ji) +         phR(ji) )
+            zh23 = z1_3 * (         phL(ji) + 2._wp * phR(ji) )
+            !
+            IF    ( phice(ji) < zh13 ) THEN   ;   phR(ji) = 3._wp * phice(ji) - 2._wp * phL(ji) ! move HR to the left
+            ELSEIF( phice(ji) > zh23 ) THEN   ;   phL(ji) = 3._wp * phice(ji) - 2._wp * phR(ji) ! move HL to the right
+            ENDIF
+            !
+            ! Compute coefficients of g(eta) = g0 + g1*eta
+            zdhr = 1._wp / (phR(ji) - phL(ji))
+            zwk1 = 6._wp * paice(ji) * zdhr
+            zwk2 = ( phice(ji) - phL(ji) ) * zdhr
+            pg0(ji) = zwk1 * ( z2_3 - zwk2 )                    ! Eq. 14
+            pg1(ji) = 2._wp * zdhr * zwk1 * ( zwk2 - 0.5_wp )   ! Eq. 14
+            !
+         ELSE  ! remap_flag = .false. or a_i < epsi10 
+            phL(ji) = 0._wp
+            phR(ji) = 0._wp
+            pg0(ji) = 0._wp
+            pg1(ji) = 0._wp
+         ENDIF
+         !
+      END DO
+      !
+   END SUBROUTINE itd_glinear
+
+
+   SUBROUTINE itd_shiftice( kdonor, pdaice, pdvice )
+      !!------------------------------------------------------------------
+      !!                ***  ROUTINE itd_shiftice ***
+      !!
+      !! ** Purpose :   shift ice across category boundaries, conserving everything
+      !!              ( area, volume, energy, age*vol, and mass of salt )
+      !!------------------------------------------------------------------
+      INTEGER , DIMENSION(:,:), INTENT(in) ::   kdonor   ! donor category index
+      REAL(wp), DIMENSION(:,:), INTENT(in) ::   pdaice   ! ice area transferred across boundary
+      REAL(wp), DIMENSION(:,:), INTENT(in) ::   pdvice   ! ice volume transferred across boundary
+      !
+      INTEGER  ::   ji, jj, jl, jk     ! dummy loop indices
+      INTEGER  ::   ii, ij, jl2, jl1   ! local integers
+      REAL(wp) ::   ztrans             ! ice/snow transferred
+      REAL(wp), DIMENSION(jpij)     ::   zworka, zworkv   ! workspace
+      REAL(wp), DIMENSION(jpij,jpl) ::   zaTsfn           !  -    -
+      !!------------------------------------------------------------------
+         
+      CALL tab_3d_2d( npti, nptidx(1:npti), h_i_2d (1:npti,1:jpl), h_i  )
+      CALL tab_3d_2d( npti, nptidx(1:npti), a_i_2d (1:npti,1:jpl), a_i  )
+      CALL tab_3d_2d( npti, nptidx(1:npti), v_i_2d (1:npti,1:jpl), v_i  )
+      CALL tab_3d_2d( npti, nptidx(1:npti), v_s_2d (1:npti,1:jpl), v_s  )
+      CALL tab_3d_2d( npti, nptidx(1:npti), oa_i_2d(1:npti,1:jpl), oa_i )
+      CALL tab_3d_2d( npti, nptidx(1:npti), sv_i_2d(1:npti,1:jpl), sv_i )
+      CALL tab_3d_2d( npti, nptidx(1:npti), a_ip_2d(1:npti,1:jpl), a_ip )
+      CALL tab_3d_2d( npti, nptidx(1:npti), v_ip_2d(1:npti,1:jpl), v_ip )
+      CALL tab_3d_2d( npti, nptidx(1:npti), t_su_2d(1:npti,1:jpl), t_su )
+
+      !----------------------------------------------------------------------------------------------
+      ! 1) Define a variable equal to a_i*T_su
+      !----------------------------------------------------------------------------------------------
+      DO jl = 1, jpl
+         DO ji = 1, npti
+            zaTsfn(ji,jl) = a_i_2d(ji,jl) * t_su_2d(ji,jl)
+         END DO
+      END DO
+      
+      !-------------------------------------------------------------------------------
+      ! 2) Transfer volume and energy between categories
+      !-------------------------------------------------------------------------------
+      DO jl = 1, jpl - 1
+         DO ji = 1, npti
+            !
+            jl1 = kdonor(ji,jl)
+            !
+            IF( jl1 > 0 ) THEN
+               !
+               IF ( jl1 == jl  ) THEN   ;   jl2 = jl1+1
+               ELSE                     ;   jl2 = jl 
+               ENDIF
+               !
+               IF( v_i_2d(ji,jl1) >= epsi10 ) THEN   ;   zworkv(ji) = pdvice(ji,jl) / v_i_2d(ji,jl1)
+               ELSE                                  ;   zworkv(ji) = 0._wp
+               ENDIF
+               IF( a_i_2d(ji,jl1) >= epsi10 ) THEN   ;   zworka(ji) = pdaice(ji,jl) / a_i_2d(ji,jl1)
+               ELSE                                  ;   zworka(ji) = 0._wp
+               ENDIF
+               !
+               a_i_2d(ji,jl1) = a_i_2d(ji,jl1) - pdaice(ji,jl)       ! Ice areas
+               a_i_2d(ji,jl2) = a_i_2d(ji,jl2) + pdaice(ji,jl)
+               !
+               v_i_2d(ji,jl1) = v_i_2d(ji,jl1) - pdvice(ji,jl)       ! Ice volumes
+               v_i_2d(ji,jl2) = v_i_2d(ji,jl2) + pdvice(ji,jl)
+               !
+               ztrans         = v_s_2d(ji,jl1) * zworkv(ji)          ! Snow volumes
+               v_s_2d(ji,jl1) = v_s_2d(ji,jl1) - ztrans
+               v_s_2d(ji,jl2) = v_s_2d(ji,jl2) + ztrans 
+               !          
+               !                                                     ! Ice age 
+               ztrans          = oa_i_2d(ji,jl1) * pdaice(ji,jl)  !!clem: should be * zworka(ji) but it does not work ????
+               oa_i_2d(ji,jl1) = oa_i_2d(ji,jl1) - ztrans
+               oa_i_2d(ji,jl2) = oa_i_2d(ji,jl2) + ztrans
+               !
+               ztrans          = sv_i_2d(ji,jl1) * zworkv(ji)        ! Ice salinity
+               !
+               sv_i_2d(ji,jl1) = sv_i_2d(ji,jl1) - ztrans
+               sv_i_2d(ji,jl2) = sv_i_2d(ji,jl2) + ztrans
+               !
+               !                                                     ! Surface temperature
+               ztrans          = t_su_2d(ji,jl1) * pdaice(ji,jl)     !!clem: should be * zworka(ji) but it does not work ????
+               zaTsfn(ji,jl1)  = zaTsfn(ji,jl1) - ztrans
+               zaTsfn(ji,jl2)  = zaTsfn(ji,jl2) + ztrans
+               !  
+               IF ( ln_pnd_H12 ) THEN
+                  !                                                  ! Pond fraction
+                  ztrans          = a_ip_2d(ji,jl1) * pdaice(ji,jl) !!clem: should be * zworka(ji) but it does not work
+                  a_ip_2d(ji,jl1) = a_ip_2d(ji,jl1) - ztrans
+                  a_ip_2d(ji,jl2) = a_ip_2d(ji,jl2) + ztrans
+                  !                                                  ! Pond volume (also proportional to da/a)
+                  ztrans          = v_ip_2d(ji,jl1) * pdaice(ji,jl) !!clem: should be * zworka(ji) but it does not work
+                  v_ip_2d(ji,jl1) = v_ip_2d(ji,jl1) - ztrans
+                  v_ip_2d(ji,jl2) = v_ip_2d(ji,jl2) + ztrans
+               ENDIF
+               !
+            ENDIF   ! jl1 >0
+         END DO
+         !
+         DO jk = 1, nlay_s         !--- Snow heat content
+            !
+            DO ji = 1, npti
+               ii = MOD( nptidx(ji) - 1, jpi ) + 1
+               ij = ( nptidx(ji) - 1 ) / jpi + 1
+               !
+               jl1 = kdonor(ji,jl)
+               !
+               IF( jl1 > 0 ) THEN
+                  IF(jl1 == jl) THEN  ;  jl2 = jl+1
+                  ELSE                ;  jl2 = jl
+                  ENDIF
+                  !
+                  ztrans            = e_s(ii,ij,jk,jl1) * zworkv(ji)
+                  e_s(ii,ij,jk,jl1) = e_s(ii,ij,jk,jl1) - ztrans
+                  e_s(ii,ij,jk,jl2) = e_s(ii,ij,jk,jl2) + ztrans
+               ENDIF
+            END DO
+         END DO
+         !
+         DO jk = 1, nlay_i         !--- Ice heat content
+            DO ji = 1, npti
+               ii = MOD( nptidx(ji) - 1, jpi ) + 1
+               ij = ( nptidx(ji) - 1 ) / jpi + 1
+               !
+               jl1 = kdonor(ji,jl)
+               !
+               IF( jl1 > 0 ) THEN
+                  IF(jl1 == jl) THEN  ;  jl2 = jl+1
+                  ELSE                ;  jl2 = jl
+                  ENDIF
+                  !
+                  ztrans            = e_i(ii,ij,jk,jl1) * zworkv(ji)
+                  e_i(ii,ij,jk,jl1) = e_i(ii,ij,jk,jl1) - ztrans
+                  e_i(ii,ij,jk,jl2) = e_i(ii,ij,jk,jl2) + ztrans
+               ENDIF
+            END DO
+         END DO
+         !
+      END DO                   ! boundaries, 1 to jpl-1
+      
+      !-------------------------------------------------------------------------------
+      ! 3) Update ice thickness and temperature
+      !-------------------------------------------------------------------------------
+      WHERE( a_i_2d(1:npti,:) >= epsi20 )
+         h_i_2d(1:npti,:)  =  v_i_2d(1:npti,:) / a_i_2d(1:npti,:) 
+         t_su_2d(1:npti,:)  =  zaTsfn(1:npti,:) / a_i_2d(1:npti,:) 
+      ELSEWHERE
+         h_i_2d(1:npti,:)  = 0._wp
+         t_su_2d(1:npti,:)  = rt0
+      END WHERE
+      !
+      CALL tab_2d_3d( npti, nptidx(1:npti), h_i_2d (1:npti,1:jpl), h_i  )
+      CALL tab_2d_3d( npti, nptidx(1:npti), a_i_2d (1:npti,1:jpl), a_i  )
+      CALL tab_2d_3d( npti, nptidx(1:npti), v_i_2d (1:npti,1:jpl), v_i  )
+      CALL tab_2d_3d( npti, nptidx(1:npti), v_s_2d (1:npti,1:jpl), v_s  )
+      CALL tab_2d_3d( npti, nptidx(1:npti), oa_i_2d(1:npti,1:jpl), oa_i )
+      CALL tab_2d_3d( npti, nptidx(1:npti), sv_i_2d(1:npti,1:jpl), sv_i )
+      CALL tab_2d_3d( npti, nptidx(1:npti), a_ip_2d(1:npti,1:jpl), a_ip )
+      CALL tab_2d_3d( npti, nptidx(1:npti), v_ip_2d(1:npti,1:jpl), v_ip )
+      CALL tab_2d_3d( npti, nptidx(1:npti), t_su_2d(1:npti,1:jpl), t_su )
+      !
+   END SUBROUTINE itd_shiftice
+   
+
+   SUBROUTINE ice_itd_reb( kt )
+      !!------------------------------------------------------------------
+      !!                ***  ROUTINE ice_itd_reb ***
+      !!
+      !! ** Purpose : rebin - rebins thicknesses into defined categories
+      !!
+      !! ** Method  : If a category thickness is out of bounds, shift part (for down to top)
+      !!              or entire (for top to down) area, volume, and energy
+      !!              to the neighboring category
+      !!------------------------------------------------------------------
+      INTEGER , INTENT (in) ::   kt      ! Ocean time step 
+      INTEGER ::   ji, jj, jl   ! dummy loop indices
+      !
+      INTEGER , DIMENSION(jpij,jpl-1) ::   jdonor           ! donor category index
+      REAL(wp), DIMENSION(jpij,jpl-1) ::   zdaice, zdvice   ! ice area and volume transferred
+      !!------------------------------------------------------------------
+      !
+      IF( kt == nit000 .AND. lwp )   WRITE(numout,*) '-- ice_itd_reb: rebining ice thickness distribution' 
+      !
+      jdonor(:,:) = 0
+      zdaice(:,:) = 0._wp
+      zdvice(:,:) = 0._wp
+      !
+      !                       !---------------------------------------
+      DO jl = 1, jpl-1        ! identify thicknesses that are too big
+         !                    !---------------------------------------
+         npti = 0   ;   nptidx(:) = 0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( a_i(ji,jj,jl) > epsi10 .AND. v_i(ji,jj,jl) > (a_i(ji,jj,jl) * hi_max(jl)) ) THEN
+                  npti = npti + 1
+                  nptidx( npti ) = (jj - 1) * jpi + ji                  
+               ENDIF
+            END DO
+         END DO
+         !
+!!clem   CALL tab_2d_1d( npti, nptidx(1:npti), h_i_1d (1:npti), h_i(:,:,jl)   )
+         CALL tab_2d_1d( npti, nptidx(1:npti), a_i_1d  (1:npti), a_i(:,:,jl)    )
+         CALL tab_2d_1d( npti, nptidx(1:npti), v_i_1d  (1:npti), v_i(:,:,jl)    )
+         !
+         DO ji = 1, npti
+            jdonor(ji,jl)  = jl 
+            ! how much of a_i you send in cat sup is somewhat arbitrary
+!!clem: these do not work properly after a restart (I do not know why)
+!!          zdaice(ji,jl)  = a_i_1d(ji) * ( h_i_1d(ji) - hi_max(jl) + epsi10 ) / h_i_1d(ji)  
+!!          zdvice(ji,jl)  = v_i_1d(ji) - ( a_i_1d(ji) - zdaice(ji,jl) ) * ( hi_max(jl) - epsi10 )
+!!clem: these do not work properly after a restart (I do not know why)
+!!            zdaice(ji,jl)  = a_i_1d(ji)
+!!            zdvice(ji,jl)  = v_i_1d(ji)
+!!clem: these are from UCL and work ok
+            zdaice(ji,jl)  = a_i_1d(ji) * 0.5_wp
+            zdvice(ji,jl)  = v_i_1d(ji) - zdaice(ji,jl) * ( hi_max(jl) + hi_max(jl-1) ) * 0.5_wp
+         END DO
+         !
+         IF( npti > 0 ) THEN
+            CALL itd_shiftice( jdonor(1:npti,:), zdaice(1:npti,:), zdvice(1:npti,:) )  ! Shift jl=>jl+1
+            ! Reset shift parameters
+            jdonor(1:npti,jl) = 0
+            zdaice(1:npti,jl) = 0._wp
+            zdvice(1:npti,jl) = 0._wp
+         ENDIF
+         !
+      END DO
+
+      !                       !-----------------------------------------
+      DO jl = jpl-1, 1, -1    ! Identify thicknesses that are too small
+         !                    !-----------------------------------------
+         npti = 0 ; nptidx(:) = 0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( a_i(ji,jj,jl+1) > epsi10 .AND. v_i(ji,jj,jl+1) <= (a_i(ji,jj,jl+1) * hi_max(jl)) ) THEN
+                  npti = npti + 1
+                  nptidx( npti ) = (jj - 1) * jpi + ji                  
+               ENDIF
+            END DO
+         END DO
+         !
+         CALL tab_2d_1d( npti, nptidx(1:npti), a_i_1d  (1:npti), a_i(:,:,jl+1)    ) ! jl+1 is ok
+         CALL tab_2d_1d( npti, nptidx(1:npti), v_i_1d  (1:npti), v_i(:,:,jl+1)    ) ! jl+1 is ok
+         DO ji = 1, npti
+            jdonor(ji,jl) = jl + 1
+            zdaice(ji,jl) = a_i_1d(ji) 
+            zdvice(ji,jl) = v_i_1d(ji)
+         END DO
+         !
+         IF( npti > 0 ) THEN
+            CALL itd_shiftice( jdonor(1:npti,:), zdaice(1:npti,:), zdvice(1:npti,:) )  ! Shift jl+1=>jl
+            ! Reset shift parameters
+            jdonor(1:npti,jl) = 0
+            zdaice(1:npti,jl) = 0._wp
+            zdvice(1:npti,jl) = 0._wp
+         ENDIF
+         !
+      END DO
+      !
+   END SUBROUTINE ice_itd_reb
+
+
+   SUBROUTINE ice_itd_init
+      !!------------------------------------------------------------------
+      !!                ***  ROUTINE ice_itd_init ***
+      !!
+      !! ** Purpose :   Initializes the ice thickness distribution
+      !! ** Method  :   ...
+      !! ** input   :   Namelist namitd
+      !!-------------------------------------------------------------------
+      INTEGER  ::   jl            ! dummy loop index
+      INTEGER  ::   ios, ioptio   ! Local integer output status for namelist read
+      REAL(wp) ::   zhmax, znum, zden, zalpha   !   -      -
+      !
+      NAMELIST/namitd/ ln_cat_hfn, rn_himean, ln_cat_usr, rn_catbnd, rn_himin
+      !!------------------------------------------------------------------
+      !
+      REWIND( numnam_ice_ref )      ! Namelist namitd in reference namelist : Parameters for ice
+      READ  ( numnam_ice_ref, namitd, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namitd in reference namelist', lwp )
+      !
+      REWIND( numnam_ice_cfg )      ! Namelist namitd in configuration namelist : Parameters for ice
+      READ  ( numnam_ice_cfg, namitd, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namitd in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namitd )
+      !
+      IF(lwp) THEN                  ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_itd_init: Initialization of ice cat distribution '
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namitd: '
+         WRITE(numout,*) '      Ice categories are defined by a function of rn_himean**(-0.05)    ln_cat_hfn = ', ln_cat_hfn
+         WRITE(numout,*) '         mean ice thickness in the domain                               rn_himean  = ', rn_himean
+         WRITE(numout,*) '      Ice categories are defined by rn_catbnd                           ln_cat_usr = ', ln_cat_usr
+         WRITE(numout,*) '      minimum ice thickness                                             rn_himin   = ', rn_himin 
+      ENDIF
+      !
+      !-----------------------------------!
+      !  Thickness categories boundaries  !
+      !-----------------------------------!
+      !                             !== set the choice of ice categories ==!
+      ioptio = 0 
+      IF( ln_cat_hfn ) THEN   ;   ioptio = ioptio + 1   ;   nice_catbnd = np_cathfn    ;   ENDIF
+      IF( ln_cat_usr ) THEN   ;   ioptio = ioptio + 1   ;   nice_catbnd = np_catusr    ;   ENDIF
+      IF( ioptio /= 1 )   CALL ctl_stop( 'ice_itd_init: choose one and only one ice categories boundaries' )
+      !
+      SELECT CASE( nice_catbnd )
+      !                                !------------------------!
+      CASE( np_cathfn )                ! h^(-alpha) function
+         !                             !------------------------!
+         zalpha = 0.05_wp
+         zhmax  = 3._wp * rn_himean
+         hi_max(0) = 0._wp
+         DO jl = 1, jpl
+            znum = jpl * ( zhmax+1 )**zalpha
+            zden = REAL( jpl-jl , wp ) * ( zhmax + 1._wp )**zalpha + REAL( jl , wp )
+            hi_max(jl) = ( znum / zden )**(1./zalpha) - 1
+         END DO
+         !                             !------------------------!
+      CASE( np_catusr )                ! user defined
+         !                             !------------------------!
+         DO jl = 0, jpl
+            hi_max(jl) = rn_catbnd(jl)
+         END DO
+         !
+      END SELECT
+      !
+      DO jl = 1, jpl                ! mean thickness by category
+         hi_mean(jl) = ( hi_max(jl) + hi_max(jl-1) ) * 0.5_wp
+      END DO
+      !
+      hi_max(jpl) = 99._wp          ! set to a big value to ensure that all ice is thinner than hi_max(jpl)
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '   ===>>>   resulting thickness category boundaries :'
+      IF(lwp) WRITE(numout,*) '            hi_max(:)= ', hi_max(0:jpl)
+      !
+   END SUBROUTINE ice_itd_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :         Empty module         NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE iceitd
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icerst.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icerst.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icerst.F90	(revision 9019)
@@ -0,0 +1,250 @@
+MODULE icerst
+   !!======================================================================
+   !!                     ***  MODULE  icerst  ***
+   !!   sea-ice :  write/read the ice restart file
+   !!======================================================================
+   !! History:   3.0  ! 2005-04 (M. Vancoppenolle) Original code
+   !!             -   ! 2008-03 (C. Ethe) restart files in using IOM interface
+   !!            3.4  ! 2011-02 (G. Madec) dynamical allocation
+   !!            4.0  ! 2017-11 (M. Andrejczuk) Extend IOM interface to write 3D ice fields
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_rst_opn   : open  restart file
+   !!   ice_rst_write : write restart file 
+   !!   ice_rst_read  : read  restart file 
+   !!----------------------------------------------------------------------
+   USE ice            ! sea-ice variables
+   USE dom_oce        ! ocean domain
+   USE sbc_oce , ONLY : nn_fsbc, ln_cpl
+   USE icectl
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_rst_opn     ! called by icestp
+   PUBLIC   ice_rst_write   ! called by icestp
+   PUBLIC   ice_rst_read    ! called by ice_init
+
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icerst.F90 8411 2017-08-07 16:09:12Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_rst_opn( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  ice_rst_opn  ***
+      !!
+      !! ** purpose  :   open restart file
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt       ! number of iteration
+      !
+      CHARACTER(len=20)   ::   clkt     ! ocean time-step define as a character
+      CHARACTER(len=50)   ::   clname   ! ice output restart file name
+      CHARACTER(len=256)  ::   clpath   ! full path to ice output restart file 
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nit000 )   lrst_ice = .FALSE.   ! default definition
+
+      ! in order to get better performances with NetCDF format, we open and define the ice restart file 
+      ! one ice time step before writing the data (-> at nitrst - 2*nn_fsbc + 1), except if we write ice 
+      ! restart files every ice time step or if an ice restart file was writen at nitend - 2*nn_fsbc + 1
+      IF( kt == nitrst - 2*nn_fsbc + 1 .OR. nstock == nn_fsbc    &
+         &                             .OR. ( kt == nitend - nn_fsbc + 1 .AND. .NOT. lrst_ice ) ) THEN
+         IF( nitrst <= nitend .AND. nitrst > 0 ) THEN
+            ! beware of the format used to write kt (default is i8.8, that should be large enough...)
+            IF( nitrst > 99999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
+            ELSE                           ;   WRITE(clkt, '(i8.8)') nitrst
+            ENDIF
+            ! create the file
+            clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_icerst_out)
+            clpath = TRIM(cn_icerst_outdir) 
+            IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath)//'/'
+            IF(lwp) THEN
+               WRITE(numout,*)
+               SELECT CASE ( jprstlib )
+               CASE DEFAULT
+                  WRITE(numout,*) '             open ice restart NetCDF file: ',TRIM(clpath)//clname
+               END SELECT
+               IF( kt == nitrst - 2*nn_fsbc + 1 ) THEN
+                  WRITE(numout,*) '             kt = nitrst - 2*nn_fsbc + 1 = ', kt,' date= ', ndastp
+               ELSE
+                  WRITE(numout,*) '             kt = '                         , kt,' date= ', ndastp
+               ENDIF
+            ENDIF
+            !
+            CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kiolib = jprstlib, kdlev = jpl )
+            lrst_ice = .TRUE.
+         ENDIF
+      ENDIF
+      !
+      IF( ln_icectl )   CALL ice_prt( kt, iiceprt, jiceprt, 1, ' - Beginning the time step - ' )   ! control print
+      !
+   END SUBROUTINE ice_rst_opn
+
+
+   SUBROUTINE ice_rst_write( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  ice_rst_write  ***
+      !!
+      !! ** purpose  :   write restart file
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! number of iteration
+      !!
+      INTEGER ::   jk ,jl   ! dummy loop indices
+      INTEGER ::   iter
+      CHARACTER(len=25) ::   znam
+      CHARACTER(len=2)  ::   zchar, zchar1
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z3d   ! 3D workspace
+      !!----------------------------------------------------------------------
+
+      iter = kt + nn_fsbc - 1   ! ice restarts are written at kt == nitrst - nn_fsbc + 1
+
+      IF( iter == nitrst ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'ice_rst_write : write ice restart file  kt =', kt
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'         
+      ENDIF
+
+      ! Write in numriw (if iter == nitrst)
+      ! ------------------ 
+      !                                                                        ! calendar control
+      CALL iom_rstput( iter, nitrst, numriw, 'nn_fsbc', REAL( nn_fsbc, wp ) )      ! time-step 
+      CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter   , wp ) )      ! date
+
+      ! Prognostic variables
+      CALL iom_rstput( iter, nitrst, numriw, 'v_i' , v_i  )
+      CALL iom_rstput( iter, nitrst, numriw, 'v_s' , v_s  )
+      CALL iom_rstput( iter, nitrst, numriw, 'sv_i', sv_i )
+      CALL iom_rstput( iter, nitrst, numriw, 'oa_i', oa_i )
+      CALL iom_rstput( iter, nitrst, numriw, 'a_i' , a_i  )
+      CALL iom_rstput( iter, nitrst, numriw, 't_su', t_su )
+      ! Melt ponds
+      CALL iom_rstput( iter, nitrst, numriw, 'a_ip', a_ip )
+      CALL iom_rstput( iter, nitrst, numriw, 'v_ip', v_ip )
+!!gm dangerous !!!!!  ===>>>> better reading writing all snow layers !
+      ! Snow enthalpy (1st snow layer only)
+      z3d = e_s(:,:,1,:)
+      CALL iom_rstput( iter, nitrst, numriw, 'tempt_sl1' , z3d )
+      ! Ice enthalpy (all ice layers)
+      DO jk = 1, nlay_i 
+         WRITE(zchar1,'(I2.2)') jk
+         znam = 'tempt'//'_il'//zchar1
+         z3d(:,:,:) = e_i(:,:,jk,:)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
+      END DO
+      ! ice velocity
+      CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice ) ! u_ice
+      CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice ) ! v_ice
+      ! fields needed for Met Office (Jules) coupling
+      IF( ln_cpl ) THEN
+         CALL iom_rstput( iter, nitrst, numriw, 'cnd_ice', cnd_ice )
+         CALL iom_rstput( iter, nitrst, numriw, 't1_ice' , t1_ice  )
+      ENDIF
+      !
+
+      ! close restart file
+      ! ------------------
+      IF( iter == nitrst ) THEN
+         CALL iom_close( numriw )
+         lrst_ice = .FALSE.
+      ENDIF
+      !
+   END SUBROUTINE ice_rst_write
+
+
+   SUBROUTINE ice_rst_read
+      !!----------------------------------------------------------------------
+      !!                    ***  ice_rst_read  ***
+      !!
+      !! ** purpose  :   read restart file
+      !!----------------------------------------------------------------------
+      INTEGER           ::   jk, jl
+      LOGICAL           ::   llok
+      INTEGER           ::   id1            ! local integer
+      INTEGER           ::   jlibalt = jprstlib
+      CHARACTER(len=25) ::   znam
+      CHARACTER(len=2)  ::   zchar, zchar1
+      REAL(wp)          ::   zfice, ziter
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z3d   ! 3D workspace
+      !!----------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_rst_read: read ice NetCDF restart file'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+      ENDIF
+
+      CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir, kiolib = jprstlib, kdlev = jpl )
+
+      CALL iom_get( numrir, 'nn_fsbc', zfice )
+      CALL iom_get( numrir, 'kt_ice' , ziter )    
+      IF(lwp) WRITE(numout,*) '   read ice restart file at time step    : ', ziter
+      IF(lwp) WRITE(numout,*) '   in any case we force it to nit000 - 1 : ', nit000 - 1
+
+      ! Control of date
+      IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 )   &
+         &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nit000 in ice restart',  &
+         &                   '   verify the file or rerun with the value 0 for the',        &
+         &                   '   control of time parameter  nrstdt' )
+      IF( NINT(zfice) /= nn_fsbc          .AND. ABS( nrstdt ) == 1 )   &
+         &     CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nn_fsbc in ice restart',  &
+         &                   '   verify the file or rerun with the value 0 for the',         &
+         &                   '   control of time parameter  nrstdt' )
+
+      ! Prognostic variables 
+      CALL iom_get( numrir, jpdom_autoglo, 'v_i' , v_i  )
+      CALL iom_get( numrir, jpdom_autoglo, 'v_s' , v_s  )
+      CALL iom_get( numrir, jpdom_autoglo, 'sv_i', sv_i )
+      CALL iom_get( numrir, jpdom_autoglo, 'oa_i', oa_i )
+      CALL iom_get( numrir, jpdom_autoglo, 'a_i' , a_i  )
+      CALL iom_get( numrir, jpdom_autoglo, 't_su', t_su )
+      ! Melt ponds
+      id1 = iom_varid( numrir, 'a_ip_htc01' , ldstop = .FALSE. )
+      IF( id1 > 0 ) THEN                       ! fields exist (melt ponds)
+         CALL iom_get( numrir, jpdom_autoglo, 'a_ip' , a_ip )
+         CALL iom_get( numrir, jpdom_autoglo, 'v_ip' , v_ip )
+      ELSE                                     ! start from rest
+         IF(lwp) WRITE(numout,*) '   ==>>   previous run without melt ponds output then set it to zero'
+         a_ip(:,:,:) = 0._wp
+         v_ip(:,:,:) = 0._wp
+      ENDIF
+!!gm dangerous !!!!!  ===>>>> better reading writing all snow layers !
+      ! Snow enthalpy (1st snow layer only)
+      CALL iom_get( numrir, jpdom_autoglo, 'tempt_sl1' , z3d )
+      e_s(:,:,1,:) = z3d
+      ! Ice enthalpy (all ice layers)
+      DO jk = 1, nlay_i 
+         WRITE(zchar1,'(I2.2)') jk
+         znam = 'tempt'//'_il'//zchar1
+         CALL iom_get( numrir, jpdom_autoglo, znam , z3d )
+         e_i(:,:,jk,:) = z3d(:,:,:)
+      END DO
+      ! ice velocity
+      CALL iom_get( numrir, jpdom_autoglo, 'u_ice', u_ice )
+      CALL iom_get( numrir, jpdom_autoglo, 'v_ice', v_ice )
+      ! fields needed for Met Office (Jules) coupling
+      IF( ln_cpl ) THEN
+         CALL iom_get( numrir, jpdom_autoglo, 'cnd_ice', cnd_ice )
+         CALL iom_get( numrir, jpdom_autoglo, 't1_ice' , t1_ice  )
+      ENDIF
+
+   END SUBROUTINE ice_rst_read
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :       Empty module           NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icerst
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icestp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icestp.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icestp.F90	(revision 9019)
@@ -0,0 +1,437 @@
+MODULE icestp
+   !!======================================================================
+   !!                       ***  MODULE  icestp  ***
+   !! Surface module :  update the ocean surface boundary condition over ice
+   !!                   covered area using ESIM sea-ice model
+   !!=====================================================================
+   !! History :  2.0  ! 2006-12  (M. Vancoppenolle) Original code
+   !!            3.0  ! 2008-02  (C. Talandier)  Surface module from icestp.F90
+   !!             -   ! 2008-04  (G. Madec)  sltyle and ice_ctl routine
+   !!            3.3  ! 2010-11  (G. Madec) ice-ocean stress always computed at each ocean time-step
+   !!            3.4  ! 2011-01  (A Porter)  dynamical allocation
+   !!             -   ! 2012-10  (C. Rousset)  add ice_dia
+   !!            3.6  ! 2014-07  (M. Vancoppenolle, G. Madec, O. Marti) revise coupled interface
+   !!            4.0  ! 2016-06  (L. Brodeau) new unified bulk routine (based on AeroBulk)
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_stp       : sea-ice model time-stepping and update ocean SBC over ice-covered area
+   !!   ice_init      : initialize sea-ice
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE c1d            ! 1D vertical configuration
+   USE ice            ! sea-ice: variables
+   USE ice1D          ! sea-ice: thermodynamical 1D variables
+   !
+   USE phycst         ! Define parameters for the routines
+   USE eosbn2         ! equation of state
+   USE sbc_oce        ! Surface boundary condition: ocean fields
+   USE sbc_ice        ! Surface boundary condition: ice   fields
+   !
+   USE iceforcing     ! sea-ice: Surface boundary condition       !!gm why not icesbc module name
+   USE icedyn         ! sea-ice: dynamics
+   USE icethd         ! sea-ice: thermodynamics
+   USE icecor         ! sea-ice: corrections
+   USE iceupdate      ! sea-ice: sea surface boundary condition update
+   USE icedia         ! sea-ice: budget diagnostics
+   USE icewri         ! sea-ice: outputs
+   USE icerst         ! sea-ice: restarts
+   USE icevar         ! sea-ice: operations
+   USE icectl         ! sea-ice: control
+   USE iceistate      ! sea-ice: initial state
+   USE iceitd         ! sea-ice: remapping thickness distribution
+   USE icealb         ! sea-ice: albedo
+   !
+   USE bdy_oce , ONLY : ln_bdy   ! flag for bdy
+   USE bdyice         ! unstructured open boundary data for sea-ice
+# if defined key_agrif
+   USE agrif_ice
+   USE agrif_lim3_update
+   USE agrif_lim3_interp
+# endif
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE timing         ! Timing
+   USE prtctl         ! Print control
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_stp    ! called by sbcmod.F90
+   PUBLIC   ice_init   ! called by sbcmod.F90
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icestp.F90 8319 2017-07-11 15:00:44Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_stp( kt, ksbc )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_stp  ***
+      !!
+      !! ** Purpose :   sea-ice model time-stepping and update ocean surface
+      !!              boundary condition over ice-covered area
+      !!
+      !! ** Method  :   ice model time stepping
+      !!              - call the ice dynamics routine
+      !!              - call the ice advection/diffusion routine
+      !!              - call the ice thermodynamics routine
+      !!              - call the routine that computes mass and
+      !!                heat fluxes at the ice/ocean interface
+      !!              - save the outputs
+      !!              - save the outputs for restart when necessary
+      !!
+      !! ** Action  : - time evolution of the LIM sea-ice model
+      !!              - update all sbc variables below sea-ice:
+      !!                utau, vtau, taum, wndm, qns , qsr, emp , sfx
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt      ! ocean time step
+      INTEGER, INTENT(in) ::   ksbc    ! flux formulation (user defined, bulk, or Pure Coupled)
+      !
+      INTEGER ::   jl   ! dummy loop index
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('ice_stp')
+      !
+      !                                      !-----------------------!
+      IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN   ! --- Ice time step --- !
+         !                                   !-----------------------!
+         !
+         kt_ice = kt                              ! -- Ice model time step
+         !
+# if defined key_agrif
+         IF( .NOT. Agrif_Root() )  lim_nbstep = MOD( lim_nbstep, Agrif_irhot() * Agrif_Parent(nn_fsbc) / nn_fsbc ) + 1
+# endif
+         u_oce(:,:) = ssu_m(:,:)                  ! -- mean surface ocean current
+         v_oce(:,:) = ssv_m(:,:)
+         !
+         CALL eos_fzp( sss_m(:,:) , t_bo(:,:) )   ! -- freezing temperature [Kelvin] (set to rt0 over land)
+         t_bo(:,:) = ( t_bo(:,:) + rt0 ) * tmask(:,:,1) + rt0 * ( 1._wp - tmask(:,:,1) )
+         !
+         CALL store_fields                        ! -- Store now ice values
+         !
+         !------------------------------------------------!
+         ! --- Dynamical coupling with the atmosphere --- !
+         !------------------------------------------------!
+         ! It provides the following fields used in sea ice model:
+         !    utau_ice, vtau_ice = surface ice stress [N/m2]
+         !------------------------------------------------!
+                                        CALL ice_forcing_tau( kt, ksbc, utau_ice, vtau_ice )          
+         !-------------------------------------!
+         ! --- ice dynamics and advection  --- !
+         !-------------------------------------!
+         CALL diag_set0             ! set diag of mass, heat and salt fluxes to 0
+         CALL ice_rst_opn( kt )     ! Open Ice restart file (if necessary) 
+         !
+         IF( ln_icedyn .AND. .NOT.lk_c1d )   &
+            &                           CALL ice_dyn( kt )            ! -- Ice dynamics
+         !
+         !                          !==  lateral boundary conditions  ==!
+#if defined key_agrif
+         IF( .NOT. Agrif_Root()     )   CALL agrif_interp_lim3('T')   ! -- AGRIF 
+#endif
+         IF( ln_icethd .AND. ln_bdy )   CALL bdy_ice( kt )            ! -- bdy ice thermo
+         !
+         !
+         !                          !==  previous lead fraction and ice volume for flux calculations
+         CALL ice_var_glo2eqv            ! h_i and h_s for ice albedo calculation
+         CALL ice_var_agg(1)             ! at_i for coupling 
+         CALL store_fields               ! Store now ice values
+
+         !------------------------------------------------------!
+         ! --- Thermodynamical coupling with the atmosphere --- !
+         !------------------------------------------------------!
+         ! It provides the following fields used in sea ice model:
+         !    emp_oce , emp_ice    = E-P over ocean and sea ice                    [Kg/m2/s]
+         !    sprecip              = solid precipitation                           [Kg/m2/s]
+         !    evap_ice             = sublimation                                   [Kg/m2/s]
+         !    qsr_tot , qns_tot    = solar & non solar heat flux (total)           [W/m2]
+         !    qsr_ice , qns_ice    = solar & non solar heat flux over ice          [W/m2]
+         !    dqns_ice             = non solar  heat sensistivity                  [W/m2]
+         !    qemp_oce, qemp_ice,  = sensible heat (associated with evap & precip) [W/m2]
+         !    qprec_ice, qevap_ice
+         !------------------------------------------------------!
+                                        CALL ice_forcing_flx( kt, ksbc )
+         !----------------------------!
+         ! --- ice thermodynamics --- !
+         !----------------------------!
+         IF( ln_icethd )                CALL ice_thd( kt )            ! -- Ice thermodynamics      
+         !
+         !
+         IF( ln_icethd )                CALL ice_cor( kt , 2 )        ! -- Corrections
+# if defined key_agrif
+         IF( .NOT. Agrif_Root() )       CALL agrif_update_lim3( kt )
+# endif
+         CALL ice_var_glo2eqv        ! necessary calls (at least for coupling)
+         CALL ice_var_agg( 2 )       ! necessary calls (at least for coupling)
+                                     !
+!! clem: one should switch the calculation of the fluxes onto the parent grid but the following calls do not work
+!!       moreover it should only be called at the update frequency (as in agrif_lim3_update.F90)
+!!# if defined key_agrif
+!!         IF( .NOT. Agrif_Root() )     CALL Agrif_ChildGrid_To_ParentGrid()
+!!# endif
+                                        CALL ice_update_flx( kt )     ! -- Update ocean surface mass, heat and salt fluxes
+!!# if defined key_agrif
+!!         IF( .NOT. Agrif_Root() )     CALL Agrif_ParentGrid_To_ChildGrid()
+!!# endif
+         IF( ln_icediahsb )             CALL ice_dia( kt )            ! -- Diagnostics outputs 
+         !
+                                        CALL ice_wri( kt )            ! -- Ice outputs 
+         !
+         IF( lrst_ice )                 CALL ice_rst_write( kt )      ! -- Ice restart file 
+         !
+         IF( ln_icectl )                CALL ice_ctl( kt )            ! -- alerts in case of model crash
+         !
+      ENDIF   ! End sea-ice time step only
+
+      !-------------------------!
+      ! --- Ocean time step --- !
+      !-------------------------!
+      IF( ln_icedyn )                   CALL ice_update_tau( kt, ub(:,:,1), vb(:,:,1) )   ! -- update surface ocean stresses
+!!gm   remark, the ocean-ice stress is not saved in ice diag call above .....  find a solution!!!
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('ice_stp')
+      !
+   END SUBROUTINE ice_stp
+
+
+   SUBROUTINE ice_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_init  ***
+      !!
+      !! ** purpose :   Initialize sea-ice parameters
+      !!----------------------------------------------------------------------
+      INTEGER :: ji, jj, ierr
+      !!----------------------------------------------------------------------
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'ice_init: Arrays allocation & Initialization off all routines & init state' 
+      IF(lwp) WRITE(numout,*) '~~~~~~~~'
+      !
+      !                                ! Open the reference and configuration namelist files and namelist output file
+      CALL ctl_opn( numnam_ice_ref, 'namelist_ice_ref',    'OLD',     'FORMATTED', 'SEQUENTIAL', -1, numout, lwp )
+      CALL ctl_opn( numnam_ice_cfg, 'namelist_ice_cfg',    'OLD',     'FORMATTED', 'SEQUENTIAL', -1, numout, lwp )
+      IF(lwm) CALL ctl_opn( numoni, 'output.namelist.ice', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, 1 )
+      !
+      CALL par_init                ! set some ice run parameters
+      !
+      !                                ! Allocate the ice arrays (sbc_ice already allocated in sbc_init)
+      ierr =        ice_alloc        ()      ! ice variables
+      ierr = ierr + sbc_ice_alloc    ()      ! surface forcing 
+      ierr = ierr + ice1D_alloc      ()      ! thermodynamics
+      !
+      IF( lk_mpp    )   CALL mpp_sum( ierr )
+      IF( ierr /= 0 )   CALL ctl_stop('STOP', 'ice_init : unable to allocate ice arrays')
+      !
+      CALL ice_itd_init                ! ice thickness distribution initialization
+      !
+      IF( ln_icethd ) THEN
+         CALL ice_thd_init             ! set ice thermodynics parameters (clem: important to call it first for melt ponds)
+      ENDIF   
+      !                                ! Initial sea-ice state
+      IF( .NOT. ln_rstart ) THEN              ! start from rest: sea-ice deduced from sst
+         CALL ice_istate_init
+         CALL ice_istate
+      ELSE                                    ! start from a restart file
+         CALL ice_rst_read
+      ENDIF
+      CALL ice_var_glo2eqv
+      CALL ice_var_agg(2)
+      !
+      CALL ice_forcing_init            ! set ice-ocean and ice-atm. coupling parameters
+      !
+      IF( ln_icedyn ) THEN
+         CALL ice_dyn_init             ! set ice dynamics parameters
+      ENDIF
+      !
+      CALL ice_update_init             ! ice surface boundary condition
+      !
+      CALL ice_alb_init                ! ice surface albedo
+      !
+      CALL ice_dia_init                ! initialization for diags
+      !
+      fr_i  (:,:)   = at_i(:,:)        ! initialisation of sea-ice fraction
+      tn_ice(:,:,:) = t_su(:,:,:)      ! initialisation of surface temp for coupled simu
+      !
+      !                                ! set max concentration in both hemispheres
+      WHERE( gphit(:,:) > 0._wp )   ;   rn_amax_2d(:,:) = rn_amax_n  ! NH
+      ELSEWHERE                     ;   rn_amax_2d(:,:) = rn_amax_s  ! SH
+      END WHERE
+
+      IF( ln_rstart )   CALL iom_close( numrir )  ! close input ice restart file
+      !
+   END SUBROUTINE ice_init
+
+
+   SUBROUTINE par_init
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE par_init ***
+      !!
+      !! ** Purpose :   Definition generic parameters for ice model
+      !!
+      !! ** Method  :   Read namelist and check the parameter
+      !!                values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist nampar
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ios                 ! Local integer output status for namelist read
+      NAMELIST/nampar/ jpl, nlay_i, nlay_s, nn_monocat, ln_icedyn, ln_icethd, rn_amax_n, rn_amax_s,  &
+         &             cn_icerst_in, cn_icerst_indir, cn_icerst_out, cn_icerst_outdir
+      !!-------------------------------------------------------------------
+      !
+      REWIND( numnam_ice_ref )      ! Namelist nampar in reference namelist : Parameters for ice
+      READ  ( numnam_ice_ref, nampar, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampar in reference namelist', lwp )
+
+      REWIND( numnam_ice_cfg )      ! Namelist nampar in configuration namelist : Parameters for ice
+      READ  ( numnam_ice_cfg, nampar, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampar in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, nampar )
+      !
+      IF(lwp) THEN                  ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'par_init: ice parameters shared among all the routines'
+         WRITE(numout,*) ' ~~~~~~~'
+         WRITE(numout,*) '   Namelist nampar: '
+         WRITE(numout,*) '      number of ice  categories                              jpl    = ', jpl
+         WRITE(numout,*) '      number of ice  layers                                  nlay_i = ', nlay_i
+         WRITE(numout,*) '      number of snow layers                                  nlay_s = ', nlay_s
+         WRITE(numout,*) '      virtual ITD mono-category param (1-4) or not (0)   nn_monocat = ', nn_monocat
+         WRITE(numout,*) '      Ice dynamics       (T) or not (F)                   ln_icedyn = ', ln_icedyn
+         WRITE(numout,*) '      Ice thermodynamics (T) or not (F)                   ln_icethd = ', ln_icethd
+         WRITE(numout,*) '      maximum ice concentration for NH                              = ', rn_amax_n 
+         WRITE(numout,*) '      maximum ice concentration for SH                              = ', rn_amax_s
+      ENDIF
+      !
+      !                                        !--- check consistency
+      IF ( jpl > 1 .AND. nn_monocat == 1 ) THEN
+         nn_monocat = 0
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '   nn_monocat forced to 0 as jpl>1, i.e. multi-category case is chosen'
+      ENDIF
+      !
+	  IF( ln_cpl .AND. nn_cats_cpl /= 1 .AND. nn_cats_cpl /= jpl ) THEN
+	     CALL ctl_stop( 'STOP', 'par_init: in coupled mode, nn_cats_cpl should be either 1 or jpl' )
+	  ENDIF
+!     IF ( jpl == 1 .AND. nn_monocat == 0 ) THEN
+!        CALL ctl_stop( 'STOP', 'par_init : if jpl=1 then nn_monocat should be between 1 and 4' )
+!     ENDIF
+      !
+      IF( ln_bdy .AND. ln_icediachk )   CALL ctl_warn('par_init: online conservation check does not work with BDY')
+      !
+      rdt_ice   = REAL(nn_fsbc) * rdt          !--- sea-ice timestep and inverse
+      r1_rdtice = 1._wp / rdt_ice
+      IF( lwp ) WRITE(numout,*) '   ice timestep rdt_ice = ', rdt_ice
+      !
+      r1_nlay_i = 1._wp / REAL( nlay_i, wp )   !--- inverse of nlay_i and nlay_s
+      r1_nlay_s = 1._wp / REAL( nlay_s, wp )
+      !
+   END SUBROUTINE par_init
+
+
+   SUBROUTINE store_fields
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE store_fields  ***
+      !!
+      !! ** purpose :  store ice variables at "before" time step
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jl      ! dummy loop index
+      !!----------------------------------------------------------------------
+      !
+      a_i_b (:,:,:)   = a_i (:,:,:)     ! ice area
+      v_i_b (:,:,:)   = v_i (:,:,:)     ! ice volume
+      v_s_b (:,:,:)   = v_s (:,:,:)     ! snow volume
+      sv_i_b(:,:,:)   = sv_i(:,:,:)     ! salt content
+      oa_i_b(:,:,:)   = oa_i(:,:,:)     ! areal age content
+      e_s_b (:,:,:,:) = e_s (:,:,:,:)   ! snow thermal energy
+      e_i_b (:,:,:,:) = e_i (:,:,:,:)   ! ice thermal energy
+      WHERE( a_i_b(:,:,:) >= epsi20 )
+         h_i_b(:,:,:) = v_i_b (:,:,:) / a_i_b(:,:,:)   ! ice thickness
+         h_s_b(:,:,:) = v_s_b (:,:,:) / a_i_b(:,:,:)   ! snw thickness
+      ELSEWHERE
+         h_i_b(:,:,:) = 0._wp
+         h_s_b(:,:,:) = 0._wp
+      END WHERE
+      
+      ! ice velocities & total concentration
+      at_i_b(:,:)  = SUM( a_i_b(:,:,:), dim=3 )
+      u_ice_b(:,:) = u_ice(:,:)
+      v_ice_b(:,:) = v_ice(:,:)
+      !
+   END SUBROUTINE store_fields
+
+
+   SUBROUTINE diag_set0
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE diag_set0  ***
+      !!
+      !! ** purpose :  set ice-ocean and ice-atm. fluxes to zeros at the beggining
+      !!               of the time step
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj      ! dummy loop index
+      !!----------------------------------------------------------------------
+      sfx    (:,:) = 0._wp   ;
+      sfx_bri(:,:) = 0._wp   ;   sfx_lam(:,:) = 0._wp
+      sfx_sni(:,:) = 0._wp   ;   sfx_opw(:,:) = 0._wp
+      sfx_bog(:,:) = 0._wp   ;   sfx_dyn(:,:) = 0._wp
+      sfx_bom(:,:) = 0._wp   ;   sfx_sum(:,:) = 0._wp
+      sfx_res(:,:) = 0._wp   ;   sfx_sub(:,:) = 0._wp
+      !
+      wfx_snw(:,:) = 0._wp   ;   wfx_ice(:,:) = 0._wp
+      wfx_sni(:,:) = 0._wp   ;   wfx_opw(:,:) = 0._wp
+      wfx_bog(:,:) = 0._wp   ;   wfx_dyn(:,:) = 0._wp
+      wfx_bom(:,:) = 0._wp   ;   wfx_sum(:,:) = 0._wp
+      wfx_res(:,:) = 0._wp   ;   wfx_sub(:,:) = 0._wp
+      wfx_spr(:,:) = 0._wp   ;   wfx_lam(:,:) = 0._wp  
+      wfx_snw_dyn(:,:) = 0._wp ; wfx_snw_sum(:,:) = 0._wp
+      wfx_snw_sub(:,:) = 0._wp ; wfx_ice_sub(:,:) = 0._wp
+      wfx_snw_sni(:,:) = 0._wp 
+      wfx_pnd(:,:) = 0._wp
+
+      hfx_thd(:,:) = 0._wp   ;
+      hfx_snw(:,:) = 0._wp   ;   hfx_opw(:,:) = 0._wp
+      hfx_bog(:,:) = 0._wp   ;   hfx_dyn(:,:) = 0._wp
+      hfx_bom(:,:) = 0._wp   ;   hfx_sum(:,:) = 0._wp
+      hfx_res(:,:) = 0._wp   ;   hfx_sub(:,:) = 0._wp
+      hfx_spr(:,:) = 0._wp   ;   hfx_dif(:,:) = 0._wp
+      hfx_err_rem(:,:) = 0._wp
+      hfx_err_dif(:,:) = 0._wp
+      wfx_err_sub(:,:) = 0._wp
+      !
+      afx_tot(:,:) = 0._wp   ;
+      !
+      diag_heat(:,:) = 0._wp ;   diag_sice(:,:) = 0._wp
+      diag_vice(:,:) = 0._wp ;   diag_vsnw(:,:) = 0._wp
+
+      ! SIMIP diagnostics
+      diag_fc_bo(:,:) = 0._wp ; diag_fc_su(:,:) = 0._wp
+
+      tau_icebfr(:,:)   = 0._wp   ! landfast ice param only (clem: important to keep the init here)
+      cnd_ice   (:,:,:) = 0._wp   ! initialisation of the effective conductivity at the top of ice/snow (Jules coupling)
+      
+   END SUBROUTINE diag_set0
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option           Dummy module         NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE ice_stp ( kt, ksbc )     ! Dummy routine
+      INTEGER, INTENT(in) ::   kt, ksbc
+      WRITE(*,*) 'ice_stp: You should not have seen this print! error?', kt
+   END SUBROUTINE ice_stp
+   SUBROUTINE ice_init                 ! Dummy routine
+   END SUBROUTINE ice_init
+#endif
+
+   !!======================================================================
+END MODULE icestp
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icetab.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icetab.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icetab.F90	(revision 9019)
@@ -0,0 +1,119 @@
+MODULE icetab
+   !!======================================================================
+   !!                       ***  MODULE icetab   ***
+   !!   sea-ice : transform 1D (2D) array to a 2D (1D) table
+   !!======================================================================
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   tab_3d_2d  : 3-D <==> 2-D
+   !!   tab_2d_3d  : 2-D <==> 3-D
+   !!   tab_2d_1d  : 2-D <==> 1-D
+   !!   tab_1d_2d  : 1-D <==> 2-D
+   !!----------------------------------------------------------------------
+   USE par_oce
+   USE ice, ONLY : jpl
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tab_3d_2d
+   PUBLIC   tab_2d_1d
+   PUBLIC   tab_2d_3d
+   PUBLIC   tab_1d_2d
+
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icetab.F90 8369 2017-07-25 14:38:38Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE tab_3d_2d( ndim1d, tab_ind, tab1d, tab2d )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tab_2d_1d  ***
+      !!----------------------------------------------------------------------
+      INTEGER                         , INTENT(in   ) ::   ndim1d   ! 1d size
+      INTEGER , DIMENSION(ndim1d)     , INTENT(in   ) ::   tab_ind  ! input index
+      REAL(wp), DIMENSION(jpi,jpj,jpl), INTENT(in   ) ::   tab2d    ! input 2D field
+      REAL(wp), DIMENSION(ndim1d,jpl) , INTENT(  out) ::   tab1d    ! output 1D field
+      !
+      INTEGER ::   jl, jn, jid, jjd
+      !!----------------------------------------------------------------------
+      DO jl = 1, jpl
+         DO jn = 1, ndim1d
+            jid          = MOD( tab_ind(jn) - 1 , jpi ) + 1
+            jjd          =    ( tab_ind(jn) - 1 ) / jpi + 1
+            tab1d(jn,jl) = tab2d(jid,jjd,jl)
+         END DO
+      END DO
+   END SUBROUTINE tab_3d_2d
+
+
+   SUBROUTINE tab_2d_1d( ndim1d, tab_ind, tab1d, tab2d )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tab_2d_1d  ***
+      !!----------------------------------------------------------------------
+      INTEGER                     , INTENT(in   ) ::   ndim1d   ! 1d size
+      INTEGER , DIMENSION(ndim1d) , INTENT(in   ) ::   tab_ind  ! input index
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   tab2d    ! input 2D field
+      REAL(wp), DIMENSION(ndim1d) , INTENT(  out) ::   tab1d    ! output 1D field
+      !
+      INTEGER ::   jn , jid, jjd
+      !!----------------------------------------------------------------------
+      DO jn = 1, ndim1d
+         jid        = MOD( tab_ind(jn) - 1 , jpi ) + 1
+         jjd        =    ( tab_ind(jn) - 1 ) / jpi + 1
+         tab1d( jn) = tab2d( jid, jjd)
+      END DO
+   END SUBROUTINE tab_2d_1d
+
+
+   SUBROUTINE tab_2d_3d( ndim1d, tab_ind, tab1d, tab2d )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tab_2d_1d  ***
+      !!----------------------------------------------------------------------
+      INTEGER                         , INTENT(in   ) ::   ndim1d    ! 1D size
+      INTEGER , DIMENSION(ndim1d)     , INTENT(in   ) ::   tab_ind   ! input index
+      REAL(wp), DIMENSION(ndim1d,jpl) , INTENT(in   ) ::   tab1d     ! input 1D field
+      REAL(wp), DIMENSION(jpi,jpj,jpl), INTENT(  out) ::   tab2d     ! output 2D field
+      !
+      INTEGER ::   jl, jn, jid, jjd
+      !!----------------------------------------------------------------------
+      DO jl = 1, jpl
+         DO jn = 1, ndim1d
+            jid               = MOD( tab_ind(jn) - 1 ,  jpi ) + 1
+            jjd               =    ( tab_ind(jn) - 1 ) / jpi  + 1
+            tab2d(jid,jjd,jl) = tab1d(jn,jl)
+         END DO
+      END DO
+   END SUBROUTINE tab_2d_3d
+
+
+   SUBROUTINE tab_1d_2d( ndim1d, tab_ind, tab1d, tab2d )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tab_2d_1d  ***
+      !!----------------------------------------------------------------------
+      INTEGER                     , INTENT(in   ) ::   ndim1d    ! 1D size
+      INTEGER , DIMENSION(ndim1d) , INTENT(in   ) ::   tab_ind   ! input index
+      REAL(wp), DIMENSION(ndim1d) , INTENT(in   ) ::   tab1d     ! input 1D field
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   tab2d     ! output 2D field
+      !
+      INTEGER ::   jn , jid, jjd
+      !!----------------------------------------------------------------------
+      DO jn = 1, ndim1d
+         jid             = MOD( tab_ind(jn) - 1 ,  jpi ) + 1
+         jjd             =    ( tab_ind(jn) - 1 ) / jpi  + 1
+         tab2d(jid, jjd) = tab1d( jn)
+      END DO
+   END SUBROUTINE tab_1d_2d
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option           Dummy module         NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icetab
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd.F90	(revision 9019)
@@ -0,0 +1,599 @@
+MODULE icethd
+   !!======================================================================
+   !!                  ***  MODULE icethd   ***
+   !!   sea-ice : master routine for thermodynamics
+   !!======================================================================
+   !! History :  LIM  ! 2000-01 (M.A. Morales Maqueda, H. Goosse, T. Fichefet) LIM-1
+   !!            2.0  ! 2002-07 (C. Ethe, G. Madec)  LIM-2 (F90 rewriting)
+   !!            3.0  ! 2005-11 (M. Vancoppenolle)  LIM-3 : Multi-layer thermodynamics + salinity variations
+   !!             -   ! 2007-04 (M. Vancoppenolle) add ice_thd_glohec, ice_thd_con_dh and ice_thd_con_dif
+   !!            3.2  ! 2009-07 (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in wfx_snw
+   !!            3.3  ! 2010-11 (G. Madec) corrected snow melting heat (due to factor betas)
+   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!             -   ! 2012-05 (C. Rousset) add penetration solar flux
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_thd       : thermodynamics of sea ice
+   !!   ice_thd_init  : initialisation of sea-ice thermodynamics
+   !!----------------------------------------------------------------------
+   USE phycst         ! physical constants
+   USE dom_oce        ! ocean space and time domain variables
+   USE ice            ! sea-ice: variables
+!!gm list trop longue ==>>> why not passage en argument d'appel ?
+   USE sbc_oce , ONLY : sss_m, sst_m, e3t_m, utau, vtau, ssu_m, ssv_m, frq_m, qns_tot, qsr_tot, sprecip, ln_cpl
+   USE sbc_ice , ONLY : qsr_oce, qns_oce, qemp_oce, qsr_ice, qns_ice, dqns_ice, evap_ice, qprec_ice, qevap_ice, &
+      &                 qml_ice, qcn_ice, qsr_ice_tr
+   USE ice1D          ! sea-ice: thermodynamics variables
+   USE icethd_zdf     ! sea-ice: vertical heat diffusion
+   USE icethd_dh      ! sea-ice: ice-snow growth and melt
+   USE icethd_da      ! sea-ice: lateral melting
+   USE icethd_sal     ! sea-ice: salinity
+   USE icethd_ent     ! sea-ice: enthalpy redistribution
+   USE icethd_do      ! sea-ice: growth in open water
+   USE icethd_pnd     ! sea-ice: melt ponds
+   USE iceitd         ! sea-ice: remapping thickness distribution
+   USE icetab         ! sea-ice: 1D <==> 2D transformation
+   USE icevar         ! sea-ice: operations
+   USE icectl         ! sea-ice: control print
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE lbclnk         ! lateral boundary conditions (or mpp links)
+   USE timing         ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_thd         ! called by limstp module
+   PUBLIC   ice_thd_init    ! called by ice_init
+
+   !!** namelist (namthd) **
+   LOGICAL ::   ln_icedH         ! activate ice thickness change from growing/melting (T) or not (F)
+   LOGICAL ::   ln_icedA         ! activate lateral melting param. (T) or not (F)
+   LOGICAL ::   ln_icedO         ! activate ice growth in open-water (T) or not (F)
+   LOGICAL ::   ln_icedS         ! activate gravity drainage and flushing (T) or not (F)
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icethd.F90 8420 2017-08-08 12:18:46Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_thd( kt )
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_thd  ***       
+      !!  
+      !! ** Purpose : This routine manages ice thermodynamics
+      !!         
+      !! ** Action : - Initialisation of some variables
+      !!             - Some preliminary computation (oceanic heat flux
+      !!               at the ice base, snow acc.,heat budget of the leads)
+      !!             - selection of the icy points and put them in an array
+      !!             - call ice_thd_zdf  for vertical heat diffusion
+      !!             - call ice_thd_dh   for vertical ice growth and melt
+      !!             - call ice_thd_ent  for enthalpy remapping
+      !!             - call ice_thd_sal  for ice desalination
+      !!             - call ice_thd_temp to  retrieve temperature from ice enthalpy
+      !!             - call ice_thd_lam  for extra lateral ice melt if monocat
+      !!             - call ice_thd_da   for lateral ice melt
+      !!             - back to the geographic grid
+      !!             - call ice_thd_rem  for remapping thickness distribution
+      !!             - call ice_thd_do   for ice growth in leads
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT(in) :: kt    ! number of iteration
+      !
+      INTEGER  :: ji, jj, jk, jl   ! dummy loop indices
+      REAL(wp) :: zfric_u, zqld, zqfr, zqfr_neg
+      REAL(wp), PARAMETER :: zfric_umin = 0._wp           ! lower bound for the friction velocity (cice value=5.e-04)
+      REAL(wp), PARAMETER :: zch        = 0.0057_wp       ! heat transfer coefficient
+      REAL(wp), DIMENSION(jpi,jpj) ::   zu_io, zv_io, zfric   ! ice-ocean velocity (m/s) and frictional velocity (m2/s2)
+      !
+      !!-------------------------------------------------------------------
+      ! controls
+      IF( nn_timing == 1 )   CALL timing_start('icethd')                                                             ! timing
+      IF( ln_icediachk   )   CALL ice_cons_hsm(0, 'icethd', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_thd: sea-ice thermodynamics'
+         WRITE(numout,*) '~~~~~~~'
+      ENDIF
+      
+      CALL ice_var_glo2eqv
+
+      !---------------------------------------------!
+      ! computation of friction velocity at T points
+      !---------------------------------------------!
+      IF( ln_icedyn ) THEN
+         zu_io(:,:) = u_ice(:,:) - ssu_m(:,:)
+         zv_io(:,:) = v_ice(:,:) - ssv_m(:,:)
+         DO jj = 2, jpjm1 
+            DO ji = fs_2, fs_jpim1
+               zfric(ji,jj) = rn_cio * ( 0.5_wp *  &
+                  &                    (  zu_io(ji,jj) * zu_io(ji,jj) + zu_io(ji-1,jj) * zu_io(ji-1,jj)   &
+                  &                     + zv_io(ji,jj) * zv_io(ji,jj) + zv_io(ji,jj-1) * zv_io(ji,jj-1) ) ) * tmask(ji,jj,1)
+            END DO
+         END DO
+      ELSE      !  if no ice dynamics => transmit directly the atmospheric stress to the ocean
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zfric(ji,jj) = r1_rau0 * SQRT( 0.5_wp *  &
+                  &                         (  utau(ji,jj) * utau(ji,jj) + utau(ji-1,jj) * utau(ji-1,jj)   &
+                  &                          + vtau(ji,jj) * vtau(ji,jj) + vtau(ji,jj-1) * vtau(ji,jj-1) ) ) * tmask(ji,jj,1)
+            END DO
+         END DO
+      ENDIF
+      CALL lbc_lnk( zfric, 'T',  1. )
+      !
+      ftr_ice(:,:,:) = 0._wp  ! initialization (part of solar radiation transmitted through the ice)
+
+      !--------------------------------------------------------------------!
+      ! Partial computation of forcing for the thermodynamic sea ice model
+      !--------------------------------------------------------------------!
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            rswitch  = tmask(ji,jj,1) * MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi10 ) ) ! 0 if no ice
+            !
+            !           !  solar irradiance transmission at the mixed layer bottom and used in the lead heat budget
+            !           !  practically no "direct lateral ablation"
+            !           
+            !           !  net downward heat flux from the ice to the ocean, expressed as a function of ocean 
+            !           !  temperature and turbulent mixing (McPhee, 1992)
+            !
+            ! --- Energy received in the lead, zqld is defined everywhere (J.m-2) --- !
+            zqld =  tmask(ji,jj,1) * rdt_ice *  &
+               &    ( ( 1._wp - at_i_b(ji,jj) ) * qsr_oce(ji,jj) * frq_m(ji,jj) +  &
+               &      ( 1._wp - at_i_b(ji,jj) ) * qns_oce(ji,jj) + qemp_oce(ji,jj) )
+
+            ! --- Energy needed to bring ocean surface layer until its freezing (<0, J.m-2) --- !
+            ! includes supercooling potential energy (>0) or "above-freezing" energy (<0)
+            zqfr = tmask(ji,jj,1) * rau0 * rcp * e3t_m(ji,jj) * ( t_bo(ji,jj) - ( sst_m(ji,jj) + rt0 ) )
+
+            ! --- Above-freezing sensible heat content (J/m2 grid)
+            zqfr_neg = tmask(ji,jj,1) * rau0 * rcp * e3t_m(ji,jj) * MIN( ( t_bo(ji,jj) - ( sst_m(ji,jj) + rt0 ) ), 0._wp )
+
+            ! --- Sensible ocean-to-ice heat flux (W/m2)
+            zfric_u      = MAX( SQRT( zfric(ji,jj) ), zfric_umin ) 
+            fhtur(ji,jj) = rswitch * rau0 * rcp * zch  * zfric_u * ( ( sst_m(ji,jj) + rt0 ) - t_bo(ji,jj) ) ! W.m-2
+
+            fhtur(ji,jj) = rswitch * MIN( fhtur(ji,jj), - zqfr_neg * r1_rdtice / MAX( at_i(ji,jj), epsi10 ) )
+            ! upper bound for fhtur: the heat retrieved from the ocean must be smaller than the heat necessary to reach 
+            !                        the freezing point, so that we do not have SST < T_freeze
+            !                        This implies: - ( fhtur(ji,jj) * at_i(ji,jj) * rtdice ) - zqfr >= 0
+
+            !-- Energy Budget of the leads (J.m-2), source of lateral accretion. Must be < 0 to form ice
+            qlead(ji,jj) = MIN( 0._wp , zqld - ( fhtur(ji,jj) * at_i(ji,jj) * rdt_ice ) - zqfr )
+
+            ! If there is ice and leads are warming, then transfer energy from the lead budget and use it for bottom melting 
+            IF( zqld > 0._wp ) THEN
+               fhld (ji,jj) = rswitch * zqld * r1_rdtice / MAX( at_i(ji,jj), epsi10 ) ! divided by at_i since this is (re)multiplied by a_i in icethd_dh.F90
+               qlead(ji,jj) = 0._wp
+            ELSE
+               fhld (ji,jj) = 0._wp
+            ENDIF
+            !
+            ! Net heat flux on top of the ice-ocean [W.m-2]
+            ! ---------------------------------------------
+            hfx_in(ji,jj) = qns_tot(ji,jj) + qsr_tot(ji,jj) 
+         END DO
+      END DO
+      
+      ! In case we bypass open-water ice formation
+      IF( .NOT. ln_icedO )  qlead(:,:) = 0._wp
+      ! In case we bypass growing/melting from top and bottom: we suppose ice is impermeable => ocean is isolated from atmosphere
+      IF( .NOT. ln_icedH ) THEN
+         hfx_in(:,:) = ( 1._wp - at_i_b(:,:) ) * ( qns_oce(:,:) + qsr_oce(:,:) ) + qemp_oce(:,:)
+         fhtur (:,:) = 0._wp
+         fhld  (:,:) = 0._wp
+      ENDIF
+
+      ! ---------------------------------------------------------------------
+      ! Net heat flux on top of the ocean after ice thermo (1st step) [W.m-2]
+      ! ---------------------------------------------------------------------
+      !     First  step here              :  non solar + precip - qlead - qturb
+      !     Second step in icethd_dh      :  heat remaining if total melt (zq_rema) 
+      !     Third  step in iceupdate.F90  :  heat from ice-ocean mass exchange (zf_mass) + solar
+      hfx_out(:,:) = ( 1._wp - at_i_b(:,:) ) * qns_oce(:,:) + qemp_oce(:,:)  &  ! Non solar heat flux received by the ocean               
+         &           - qlead(:,:) * r1_rdtice                                &  ! heat flux taken from the ocean where there is open water ice formation
+         &           - at_i (:,:) * fhtur(:,:)                               &  ! heat flux taken by turbulence
+         &           - at_i (:,:) *  fhld(:,:)                                  ! heat flux taken during bottom growth/melt 
+                                                                                !    (fhld should be 0 while bott growth)
+      !-------------------------------------------------------------------------------------------!
+      ! Thermodynamic computation (only on grid points covered by ice) => loop over ice categories
+      !-------------------------------------------------------------------------------------------!
+      DO jl = 1, jpl
+
+         ! select ice covered grid points
+         npti = 0 ; nptidx(:) = 0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF ( a_i(ji,jj,jl) > epsi10 ) THEN     
+                  npti         = npti  + 1
+                  nptidx(npti) = (jj - 1) * jpi + ji
+               ENDIF
+            END DO
+         END DO
+
+         IF( lk_mpp )         CALL mpp_ini_ice( npti , numout )
+
+         IF( npti > 0 ) THEN  ! If there is no ice, do nothing.
+            !                                                                
+                              CALL ice_thd_1d2d( jl, 1 )            ! --- Move to 1D arrays --- !
+            !                                                       ! --- & Change units of e_i, e_s from J/m2 to J/m3 --- !
+            !
+            s_i_new   (1:npti) = 0._wp ; dh_s_tot (1:npti) = 0._wp  ! --- some init --- !  (important to have them here) 
+            dh_i_surf (1:npti) = 0._wp ; dh_i_bott(1:npti) = 0._wp
+            dh_snowice(1:npti) = 0._wp ; dh_i_sub (1:npti) = 0._wp ; dh_s_mlt(1:npti) = 0._wp
+            !
+            IF( ln_icedH ) THEN                                     ! --- growing/melting --- !
+                              CALL ice_thd_zdf                             ! Ice/Snow Temperature profile
+                              CALL ice_thd_dh                              ! Ice/Snow thickness   
+                              CALL ice_thd_pnd                             ! Melt ponds formation
+                              CALL ice_thd_ent( e_i_1d(1:npti,:) )         ! Ice enthalpy remapping
+            ENDIF
+            !
+                              CALL ice_thd_sal( ln_icedS )          ! --- Ice salinity --- !    
+            !
+                              CALL ice_thd_temp                     ! --- temperature update --- !
+            !
+!!gm please create a new logical (l_thd_lam or a better explicit name) set one for all in icestp.F90 module
+!!gm        l_thd_lam = ln_icedH .AND. ( ( nn_monocat == 1 .OR. nn_monocat == 4 ) .AND. jpl == 1 )
+!!gm        by the way, the different options associated with nn_monocat =1 to 4  are quite impossible to identify
+!!gm        more comment to add when ready the namelist, with an explicit print in the ocean.output
+            IF( ln_icedH ) THEN
+               IF ( ( nn_monocat == 1 .OR. nn_monocat == 4 ) .AND. jpl == 1 ) THEN
+                              CALL ice_thd_lam                      ! --- extra lateral melting if monocat --- !
+               END IF
+            END IF
+            !
+            IF( ln_icedA )    CALL ice_thd_da                       ! --- lateral melting --- !
+            !
+                              CALL ice_thd_1d2d( jl, 2 )            ! --- Change units of e_i, e_s from J/m3 to J/m2 --- !
+            !                                                       ! --- & Move to 2D arrays --- !
+            !
+            IF( lk_mpp )      CALL mpp_comm_free( ncomm_ice ) !RB necessary ??
+         ENDIF
+         !
+      END DO
+      ! update ice age (in case a_i changed, i.e. becomes 0 or lateral melting)
+      oa_i(:,:,:) = o_i(:,:,:) * a_i(:,:,:)
+
+      IF( ln_icediachk )   CALL ice_cons_hsm(1, 'icethd', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft)
+      !
+                           CALL ice_var_zapsmall           ! --- remove very small ice concentration (<1e-10) --- !
+      !                                                    !     & make sure at_i=SUM(a_i) & ato_i=1 where at_i=0
+      !                   
+      IF( jpl > 1 )        CALL ice_itd_rem( kt )          ! --- Transport ice between thickness categories --- !
+      !
+      IF( ln_icedO )       CALL ice_thd_do                 ! --- frazil ice growing in leads --- !
+      !
+      ! controls
+      IF( ln_icectl      )   CALL ice_prt    (kt, iiceprt, jiceprt, 1, ' - ice thermodyn. - ') ! prints
+      IF( ln_ctl         )   CALL ice_prt3D  ('icethd')                                        ! prints
+      IF( nn_timing == 1 )   CALL timing_stop('icethd')                                        ! timing
+      !
+   END SUBROUTINE ice_thd 
+
+ 
+   SUBROUTINE ice_thd_temp
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_thd_temp *** 
+      !!                 
+      !! ** Purpose :   Computes sea ice temperature (Kelvin) from enthalpy
+      !!
+      !! ** Method  :   Formula (Bitz and Lipscomb, 1999)
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ji, jk   ! dummy loop indices
+      REAL(wp) ::   ztmelts, zbbb, zccc  ! local scalar 
+      !!-------------------------------------------------------------------
+      ! Recover ice temperature
+      DO jk = 1, nlay_i
+         DO ji = 1, npti
+            ztmelts       = -tmut * sz_i_1d(ji,jk)
+            ! Conversion q(S,T) -> T (second order equation)
+            zbbb          = ( rcp - cpic ) * ztmelts + e_i_1d(ji,jk) * r1_rhoic - lfus
+            zccc          = SQRT( MAX( zbbb * zbbb - 4._wp * cpic * lfus * ztmelts, 0._wp ) )
+            t_i_1d(ji,jk) = rt0 - ( zbbb + zccc ) * 0.5_wp * r1_cpic
+            
+            ! mask temperature
+            rswitch       = 1._wp - MAX( 0._wp , SIGN( 1._wp , - h_i_1d(ji) ) ) 
+            t_i_1d(ji,jk) = rswitch * t_i_1d(ji,jk) + ( 1._wp - rswitch ) * rt0
+         END DO 
+      END DO 
+      !
+   END SUBROUTINE ice_thd_temp
+
+
+   SUBROUTINE ice_thd_lam
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_thd_lam *** 
+      !!                 
+      !! ** Purpose :   Lateral melting in case monocategory
+      !!                          ( dA = A/2h dh )
+      !!-----------------------------------------------------------------------
+      INTEGER  ::   ji                 ! dummy loop indices
+      REAL(wp) ::   zhi_bef            ! ice thickness before thermo
+      REAL(wp) ::   zdh_mel, zda_mel   ! net melting
+      REAL(wp) ::   zvi, zvs           ! ice/snow volumes 
+      !!-----------------------------------------------------------------------
+      !
+      DO ji = 1, npti
+         zdh_mel = MIN( 0._wp, dh_i_surf(ji) + dh_i_bott(ji) + dh_snowice(ji) + dh_i_sub(ji) )
+         IF( zdh_mel < 0._wp .AND. a_i_1d(ji) > 0._wp )  THEN
+            zvi          = a_i_1d(ji) * h_i_1d(ji)
+            zvs          = a_i_1d(ji) * h_s_1d(ji)
+            ! lateral melting = concentration change
+            zhi_bef     = h_i_1d(ji) - zdh_mel
+            rswitch     = MAX( 0._wp , SIGN( 1._wp , zhi_bef - epsi20 ) )
+            zda_mel     = rswitch * a_i_1d(ji) * zdh_mel / ( 2._wp * MAX( zhi_bef, epsi20 ) )
+            a_i_1d(ji)  = MAX( epsi20, a_i_1d(ji) + zda_mel ) 
+            ! adjust thickness
+            h_i_1d(ji) = zvi / a_i_1d(ji)            
+            h_s_1d(ji) = zvs / a_i_1d(ji)            
+            ! retrieve total concentration
+            at_i_1d(ji) = a_i_1d(ji)
+         END IF
+      END DO
+      !
+   END SUBROUTINE ice_thd_lam
+
+
+   SUBROUTINE ice_thd_1d2d( kl, kn )
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_thd_1d2d *** 
+      !!                 
+      !! ** Purpose :   move arrays from 1d to 2d and the reverse
+      !!-----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kl   ! index of the ice category 
+      INTEGER, INTENT(in) ::   kn   ! 1= from 2D to 1D   ;   2= from 1D to 2D
+      !
+      INTEGER ::   jk   ! dummy loop indices
+      !!-----------------------------------------------------------------------
+      !
+      SELECT CASE( kn )
+      !                    !---------------------!
+      CASE( 1 )            !==  from 2D to 1D  ==!
+         !                 !---------------------!
+         CALL tab_2d_1d( npti, nptidx(1:npti), at_i_1d(1:npti), at_i             )
+         CALL tab_2d_1d( npti, nptidx(1:npti), a_i_1d (1:npti), a_i (:,:,kl)     )
+         CALL tab_2d_1d( npti, nptidx(1:npti), h_i_1d (1:npti), h_i (:,:,kl)     )
+         CALL tab_2d_1d( npti, nptidx(1:npti), h_s_1d (1:npti), h_s (:,:,kl)     )
+         CALL tab_2d_1d( npti, nptidx(1:npti), t_su_1d(1:npti), t_su(:,:,kl)     )
+         CALL tab_2d_1d( npti, nptidx(1:npti), s_i_1d (1:npti), s_i (:,:,kl)     )
+         DO jk = 1, nlay_s
+            CALL tab_2d_1d( npti, nptidx(1:npti), t_s_1d(1:npti,jk), t_s(:,:,jk,kl)    )
+            CALL tab_2d_1d( npti, nptidx(1:npti), e_s_1d(1:npti,jk), e_s(:,:,jk,kl)    )
+         END DO
+         DO jk = 1, nlay_i
+            CALL tab_2d_1d( npti, nptidx(1:npti), t_i_1d (1:npti,jk), t_i (:,:,jk,kl)  )
+            CALL tab_2d_1d( npti, nptidx(1:npti), e_i_1d (1:npti,jk), e_i (:,:,jk,kl)  )
+            CALL tab_2d_1d( npti, nptidx(1:npti), sz_i_1d(1:npti,jk), sz_i(:,:,jk,kl)  )
+         END DO
+         CALL tab_2d_1d( npti, nptidx(1:npti), a_ip_1d     (1:npti), a_ip     (:,:,kl) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), h_ip_1d     (1:npti), h_ip     (:,:,kl) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), a_ip_frac_1d(1:npti), a_ip_frac(:,:,kl) )
+         !
+         CALL tab_2d_1d( npti, nptidx(1:npti), qprec_ice_1d(1:npti), qprec_ice        )
+         CALL tab_2d_1d( npti, nptidx(1:npti), qsr_ice_1d  (1:npti), qsr_ice (:,:,kl) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), qns_ice_1d  (1:npti), qns_ice (:,:,kl) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), ftr_ice_1d  (1:npti), ftr_ice (:,:,kl) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), evap_ice_1d (1:npti), evap_ice(:,:,kl) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), dqns_ice_1d (1:npti), dqns_ice(:,:,kl) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), t_bo_1d     (1:npti), t_bo             )
+         CALL tab_2d_1d( npti, nptidx(1:npti), sprecip_1d  (1:npti), sprecip          ) 
+         CALL tab_2d_1d( npti, nptidx(1:npti), fhtur_1d    (1:npti), fhtur            )
+         CALL tab_2d_1d( npti, nptidx(1:npti), fhld_1d     (1:npti), fhld             )
+         
+         CALL tab_2d_1d( npti, nptidx(1:npti), qml_ice_1d   (1:npti), qml_ice      (:,:,kl)  )
+         CALL tab_2d_1d( npti, nptidx(1:npti), qcn_ice_1d   (1:npti), qcn_ice      (:,:,kl) )
+         CALL tab_2d_1d( npti, nptidx(1:npti), qsr_ice_tr_1d(1:npti), qsr_ice_tr   (:,:,kl) )
+         !
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_snw_sni_1d(1:npti), wfx_snw_sni   )
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_snw_sum_1d(1:npti), wfx_snw_sum   )
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_sub_1d    (1:npti), wfx_sub       )
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_snw_sub_1d(1:npti), wfx_snw_sub   )
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_ice_sub_1d(1:npti), wfx_ice_sub   )
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_err_sub_1d(1:npti), wfx_err_sub   )
+         !
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_bog_1d (1:npti), wfx_bog          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_bom_1d (1:npti), wfx_bom          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_sum_1d (1:npti), wfx_sum          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_sni_1d (1:npti), wfx_sni          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_res_1d (1:npti), wfx_res          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_spr_1d (1:npti), wfx_spr          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_lam_1d (1:npti), wfx_lam          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_pnd_1d (1:npti), wfx_pnd          )
+         !
+         CALL tab_2d_1d( npti, nptidx(1:npti), sfx_bog_1d (1:npti), sfx_bog          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), sfx_bom_1d (1:npti), sfx_bom          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), sfx_sum_1d (1:npti), sfx_sum          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), sfx_sni_1d (1:npti), sfx_sni          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), sfx_bri_1d (1:npti), sfx_bri          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), sfx_res_1d (1:npti), sfx_res          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), sfx_sub_1d (1:npti), sfx_sub          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), sfx_lam_1d (1:npti), sfx_lam          )
+         !
+         CALL tab_2d_1d( npti, nptidx(1:npti), hfx_thd_1d (1:npti), hfx_thd          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), hfx_spr_1d (1:npti), hfx_spr          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), hfx_sum_1d (1:npti), hfx_sum          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), hfx_bom_1d (1:npti), hfx_bom          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), hfx_bog_1d (1:npti), hfx_bog          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), hfx_dif_1d (1:npti), hfx_dif          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), hfx_opw_1d (1:npti), hfx_opw          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), hfx_snw_1d (1:npti), hfx_snw          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), hfx_sub_1d (1:npti), hfx_sub          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), hfx_res_1d (1:npti), hfx_res          )
+         CALL tab_2d_1d( npti, nptidx(1:npti), hfx_err_dif_1d(1:npti), hfx_err_dif   )
+         CALL tab_2d_1d( npti, nptidx(1:npti), hfx_err_rem_1d(1:npti), hfx_err_rem   )
+         CALL tab_2d_1d( npti, nptidx(1:npti), hfx_out_1d (1:npti), hfx_out          )
+         !
+         ! SIMIP diagnostics
+         CALL tab_2d_1d( npti, nptidx(1:npti), diag_fc_bo_1d(1:npti), diag_fc_bo   )
+         CALL tab_2d_1d( npti, nptidx(1:npti), diag_fc_su_1d(1:npti), diag_fc_su   )
+         ! ocean surface fields
+         CALL tab_2d_1d( npti, nptidx(1:npti), sst_1d(1:npti), sst_m )
+         CALL tab_2d_1d( npti, nptidx(1:npti), sss_1d(1:npti), sss_m )
+
+         ! --- Change units of e_i, e_s from J/m2 to J/m3 --- !
+         DO jk = 1, nlay_i
+            WHERE( h_i_1d(1:npti)>0._wp ) e_i_1d(1:npti,jk) = e_i_1d(1:npti,jk) / (h_i_1d(1:npti) * a_i_1d(1:npti)) * nlay_i
+         END DO
+         DO jk = 1, nlay_s
+            WHERE( h_s_1d(1:npti)>0._wp ) e_s_1d(1:npti,jk) = e_s_1d(1:npti,jk) / (h_s_1d(1:npti) * a_i_1d(1:npti)) * nlay_s
+         END DO
+         !
+         !                 !---------------------!
+      CASE( 2 )            !==  from 1D to 2D  ==!
+         !                 !---------------------!
+         ! --- Change units of e_i, e_s from J/m3 to J/m2 --- !
+         DO jk = 1, nlay_i
+            e_i_1d(1:npti,jk) = e_i_1d(1:npti,jk) * h_i_1d(1:npti) * a_i_1d(1:npti) * r1_nlay_i
+         END DO
+         DO jk = 1, nlay_s
+            e_s_1d(1:npti,jk) = e_s_1d(1:npti,jk) * h_s_1d(1:npti) * a_i_1d(1:npti) * r1_nlay_s
+         END DO
+         !
+         ! Change thickness to volume (replaces routine ice_var_eqv2glo)
+         v_i_1d (1:npti) = h_i_1d (1:npti) * a_i_1d (1:npti)
+         v_s_1d (1:npti) = h_s_1d (1:npti) * a_i_1d (1:npti)
+         sv_i_1d(1:npti) = s_i_1d (1:npti) * v_i_1d (1:npti)
+         v_ip_1d(1:npti) = h_ip_1d(1:npti) * a_ip_1d(1:npti)
+         
+         CALL tab_1d_2d( npti, nptidx(1:npti), at_i_1d(1:npti), at_i             )
+         CALL tab_1d_2d( npti, nptidx(1:npti), a_i_1d (1:npti), a_i (:,:,kl)     )
+         CALL tab_1d_2d( npti, nptidx(1:npti), h_i_1d (1:npti), h_i (:,:,kl)     )
+         CALL tab_1d_2d( npti, nptidx(1:npti), h_s_1d (1:npti), h_s (:,:,kl)     )
+         CALL tab_1d_2d( npti, nptidx(1:npti), t_su_1d(1:npti), t_su(:,:,kl)     )
+         CALL tab_1d_2d( npti, nptidx(1:npti), s_i_1d (1:npti), s_i (:,:,kl)     )
+         DO jk = 1, nlay_s
+            CALL tab_1d_2d( npti, nptidx(1:npti), t_s_1d(1:npti,jk), t_s(:,:,jk,kl)    )
+            CALL tab_1d_2d( npti, nptidx(1:npti), e_s_1d(1:npti,jk), e_s(:,:,jk,kl)    )
+         END DO
+         DO jk = 1, nlay_i
+            CALL tab_1d_2d( npti, nptidx(1:npti), t_i_1d (1:npti,jk), t_i (:,:,jk,kl)  )
+            CALL tab_1d_2d( npti, nptidx(1:npti), e_i_1d (1:npti,jk), e_i (:,:,jk,kl)  )
+            CALL tab_1d_2d( npti, nptidx(1:npti), sz_i_1d(1:npti,jk), sz_i(:,:,jk,kl)  )
+         END DO
+         CALL tab_1d_2d( npti, nptidx(1:npti), a_ip_1d     (1:npti), a_ip     (:,:,kl) )
+         CALL tab_1d_2d( npti, nptidx(1:npti), h_ip_1d     (1:npti), h_ip     (:,:,kl) )
+         CALL tab_1d_2d( npti, nptidx(1:npti), a_ip_frac_1d(1:npti), a_ip_frac(:,:,kl) )
+         !
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_snw_sni_1d(1:npti), wfx_snw_sni )
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_snw_sum_1d(1:npti), wfx_snw_sum )
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_sub_1d    (1:npti), wfx_sub     )
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_snw_sub_1d(1:npti), wfx_snw_sub )
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_ice_sub_1d(1:npti), wfx_ice_sub )
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_err_sub_1d(1:npti), wfx_err_sub )
+         !
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_bog_1d (1:npti), wfx_bog        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_bom_1d (1:npti), wfx_bom        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_sum_1d (1:npti), wfx_sum        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_sni_1d (1:npti), wfx_sni        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_res_1d (1:npti), wfx_res        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_spr_1d (1:npti), wfx_spr        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_lam_1d (1:npti), wfx_lam        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_pnd_1d (1:npti), wfx_pnd        )
+         !
+         CALL tab_1d_2d( npti, nptidx(1:npti), sfx_bog_1d (1:npti), sfx_bog        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), sfx_bom_1d (1:npti), sfx_bom        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), sfx_sum_1d (1:npti), sfx_sum        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), sfx_sni_1d (1:npti), sfx_sni        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), sfx_bri_1d (1:npti), sfx_bri        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), sfx_res_1d (1:npti), sfx_res        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), sfx_sub_1d (1:npti), sfx_sub        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), sfx_lam_1d (1:npti), sfx_lam        )
+         !
+         CALL tab_1d_2d( npti, nptidx(1:npti), hfx_thd_1d (1:npti), hfx_thd        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), hfx_spr_1d (1:npti), hfx_spr        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), hfx_sum_1d (1:npti), hfx_sum        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), hfx_bom_1d (1:npti), hfx_bom        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), hfx_bog_1d (1:npti), hfx_bog        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), hfx_dif_1d (1:npti), hfx_dif        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), hfx_opw_1d (1:npti), hfx_opw        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), hfx_snw_1d (1:npti), hfx_snw        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), hfx_sub_1d (1:npti), hfx_sub        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), hfx_res_1d (1:npti), hfx_res        )
+         CALL tab_1d_2d( npti, nptidx(1:npti), hfx_err_dif_1d(1:npti), hfx_err_dif )
+         CALL tab_1d_2d( npti, nptidx(1:npti), hfx_err_rem_1d(1:npti), hfx_err_rem )
+         CALL tab_1d_2d( npti, nptidx(1:npti), hfx_out_1d (1:npti), hfx_out        )
+         !
+         CALL tab_1d_2d( npti, nptidx(1:npti), qns_ice_1d(1:npti), qns_ice(:,:,kl) )
+         CALL tab_1d_2d( npti, nptidx(1:npti), ftr_ice_1d(1:npti), ftr_ice(:,:,kl) )
+         ! effective conductivity and 1st layer temperature (for Jules coupling)
+         CALL tab_1d_2d( npti, nptidx(1:npti), cnd_ice_1d(1:npti), cnd_ice(:,:,kl) )
+         CALL tab_1d_2d( npti, nptidx(1:npti), t1_ice_1d (1:npti), t1_ice (:,:,kl) )
+         ! SIMIP diagnostics         
+         CALL tab_1d_2d( npti, nptidx(1:npti), t_si_1d      (1:npti), t_si(:,:,kl) )
+         CALL tab_1d_2d( npti, nptidx(1:npti), diag_fc_bo_1d(1:npti), diag_fc_bo   )
+         CALL tab_1d_2d( npti, nptidx(1:npti), diag_fc_su_1d(1:npti), diag_fc_su   )
+         ! extensive variables
+         CALL tab_1d_2d( npti, nptidx(1:npti), v_i_1d (1:npti), v_i (:,:,kl) )
+         CALL tab_1d_2d( npti, nptidx(1:npti), v_s_1d (1:npti), v_s (:,:,kl) )
+         CALL tab_1d_2d( npti, nptidx(1:npti), sv_i_1d(1:npti), sv_i(:,:,kl) )
+         CALL tab_1d_2d( npti, nptidx(1:npti), v_ip_1d(1:npti), v_ip(:,:,kl) )
+         !
+      END SELECT
+      !
+   END SUBROUTINE ice_thd_1d2d
+
+
+   SUBROUTINE ice_thd_init
+      !!-------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_thd_init *** 
+      !!                 
+      !! ** Purpose :   Physical constants and parameters associated with
+      !!                ice thermodynamics
+      !!
+      !! ** Method  :   Read the namthd namelist and check the parameters
+      !!                called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namthd
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ios   ! Local integer output status for namelist read
+      !!
+      NAMELIST/namthd/ ln_icedH, ln_icedA, ln_icedO, ln_icedS
+      !!-------------------------------------------------------------------
+      !
+      REWIND( numnam_ice_ref )              ! Namelist namthd in reference namelist : Ice thermodynamics
+      READ  ( numnam_ice_ref, namthd, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namthd in reference namelist', lwp )
+
+      REWIND( numnam_ice_cfg )              ! Namelist namthd in configuration namelist : Ice thermodynamics
+      READ  ( numnam_ice_cfg, namthd, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namthd in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namthd )
+      !
+      !
+      IF(lwp) THEN                          ! control print
+         WRITE(numout,*) 'ice_thd_init: Ice Thermodynamics'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namthd:'
+         WRITE(numout,*) '      activate ice thick change from top/bot (T) or not (F)   ln_icedH  = ', ln_icedH
+         WRITE(numout,*) '      activate lateral melting (T) or not (F)                 ln_icedA  = ', ln_icedA
+         WRITE(numout,*) '      activate ice growth in open-water (T) or not (F)        ln_icedO  = ', ln_icedO
+         WRITE(numout,*) '      activate gravity drainage and flushing (T) or not (F)   ln_icedS  = ', ln_icedS
+     ENDIF
+      !
+                       CALL ice_thd_zdf_init   ! set ice heat diffusion parameters
+      IF( ln_icedA )   CALL ice_thd_da_init    ! set ice lateral melting parameters
+      IF( ln_icedO )   CALL ice_thd_do_init    ! set ice growth in open water parameters
+                       CALL ice_thd_sal_init   ! set ice salinity parameters
+                       CALL ice_thd_pnd_init   ! set melt ponds parameters
+      !
+   END SUBROUTINE ice_thd_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Dummy module          NO  ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icethd
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_da.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_da.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_da.F90	(revision 9019)
@@ -0,0 +1,203 @@
+MODULE icethd_da
+   !!======================================================================
+   !!                       ***  MODULE icethd_da ***
+   !!   sea-ice : lateral melting
+   !!======================================================================
+   !! History :  4.0  ! 2016-03 (C. Rousset)  original code
+   !!---------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_thd_da        : sea ice lateral melting
+   !!   ice_thd_da_init   : sea ice lateral melting initialization
+   !!----------------------------------------------------------------------
+   USE par_oce        ! ocean parameters
+   USE phycst         ! physical constants (ocean directory)
+   USE ice            ! sea-ice: variables
+   USE ice1D          ! sea-ice: thermodynamic 1D variables
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_thd_da        ! called by icethd.F90
+   PUBLIC   ice_thd_da_init   ! called by icestp.F90
+
+   ! ** namelist (namthd_da) **
+   REAL(wp) ::   rn_beta     ! coef. beta for lateral melting param.
+   REAL(wp) ::   rn_dmin     ! minimum floe diameter for lateral melting param.
+
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icethd_da.F90 5123 2015-03-04 16:06:03Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_thd_da
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_thd_da  ***    
+      !!   
+      !! ** Purpose :   computes sea ice lateral melting
+      !!
+      !! ** Method  :   dA/dt = - P * W   [s-1]
+      !!                   W = melting velocity [m.s-1]
+      !!                   P = perimeter of ice-ocean lateral interface normalized by grid cell area [m.m-2]
+      !!
+      !!                   W = m1 * (Tw -Tf)**m2                    --- originally from Josberger 1979 ---
+      !!                      (Tw - Tf) = elevation of water temp above freezing
+      !!                      m1 and m2 = (1.6e-6 , 1.36) best fit from field experiment near the coast of Prince Patrick Island
+      !!                                                                                           (Perovich 1983) => static ice
+      !!                      m1 and m2 = (3.0e-6 , 1.36) best fit from MIZEX 84 experiment
+      !!                                                                                (Maykut and Perovich 1987) => moving ice
+      !!
+      !!                   P = N * pi * D                           --- from Rothrock and Thorndike 1984 ---
+      !!                      D = mean floe caliper diameter
+      !!                      N = number of floes = ice area / floe area(average) = A / (Cs * D**2)
+      !!                         A = ice concentration
+      !!                         Cs = deviation from a square (square:Cs=1 ; circle:Cs=pi/4 ; floe:Cs=0.66)
+      !!
+      !!                   D = Dmin * ( Astar / (Astar-A) )**beta   --- from Lupkes et al., 2012 (eq. 26-27) ---
+      !!                                                             
+      !!                      Astar = 1 / ( 1 - (Dmin/Dmax)**(1/beta) )
+      !!                      Dmin = minimum floe diameter (recommended to be 8m +- 20%)
+      !!                      Dmax = maximum floe diameter (recommended to be 300m,
+      !!                                                    but it does not impact melting much except for Dmax<100m)
+      !!                      beta = 1.0 +-20% (recommended value)
+      !!                           = 0.3 best fit for western Fram Strait and Antarctica
+      !!                           = 1.4 best fit for eastern Fram Strait
+      !!
+      !! ** Tunable parameters  :   We propose to tune the lateral melting via 2 parameters
+      !!                               Dmin [6-10m]   => 6  vs 8m = +40% melting at the peak (A~0.5)
+      !!                                                 10 vs 8m = -20% melting
+      !!                               beta [0.8-1.2] => decrease = more melt and melt peaks toward higher concentration
+      !!                                                                  (A~0.5 for beta=1 ; A~0.8 for beta=0.2)
+      !!                                                 0.3 = best fit for western Fram Strait and Antarctica
+      !!                                                 1.4 = best fit for eastern Fram Strait
+      !!
+      !! ** Note   :   Former and more simple formulations for floe diameters can be found in Mai (1995), 
+      !!               Birnbaum and Lupkes (2002), Lupkes and Birnbaum (2005). They are reviewed in Lupkes et al 2012
+      !!               A simpler implementation for CICE can be found in Bitz et al (2001) and Tsamados et al (2015)
+      !!
+      !! ** References
+      !!    Bitz, C. M., Holland, M. M., Weaver, A. J., & Eby, M. (2001).
+      !!              Simulating the ice‐thickness distribution in a coupled climate model.
+      !!              Journal of Geophysical Research: Oceans, 106(C2), 2441-2463.
+      !!    Josberger, E. G. (1979).
+      !!              Laminar and turbulent boundary layers adjacent to melting vertical ice walls in salt water
+      !!              (No. SCIENTIFIC-16). WASHINGTON UNIV SEATTLE DEPT OF ATMOSPHERIC SCIENCES.
+      !!    Lüpkes, C., Gryanik, V. M., Hartmann, J., & Andreas, E. L. (2012).
+      !!              A parametrization, based on sea ice morphology, of the neutral atmospheric drag coefficients
+      !!              for weather prediction and climate models.
+      !!              Journal of Geophysical Research: Atmospheres, 117(D13).
+      !!    Maykut, G. A., & Perovich, D. K. (1987).
+      !!              The role of shortwave radiation in the summer decay of a sea ice cover.
+      !!              Journal of Geophysical Research: Oceans, 92(C7), 7032-7044.
+      !!    Perovich, D. K. (1983).
+      !!              On the summer decay of a sea ice cover. (Doctoral dissertation, University of Washington).
+      !!    Rothrock, D. A., & Thorndike, A. S. (1984).
+      !!              Measuring the sea ice floe size distribution.
+      !!              Journal of Geophysical Research: Oceans, 89(C4), 6477-6486.
+      !!    Tsamados, M., Feltham, D., Petty, A., Schroeder, D., & Flocco, D. (2015).
+      !!              Processes controlling surface, bottom and lateral melt of Arctic sea ice in a state of the art sea ice model.
+      !!              Phil. Trans. R. Soc. A, 373(2052), 20140167.
+      !!---------------------------------------------------------------------
+      INTEGER  ::   ji     ! dummy loop indices
+      REAL(wp)            ::   zastar, zdfloe, zperi, zwlat, zda
+      REAL(wp), PARAMETER ::   zdmax = 300._wp
+      REAL(wp), PARAMETER ::   zcs   = 0.66_wp
+      REAL(wp), PARAMETER ::   zm1   = 3.e-6_wp
+      REAL(wp), PARAMETER ::   zm2   = 1.36_wp
+      !
+      REAL(wp), DIMENSION(jpij) ::   zda_tot
+      !!---------------------------------------------------------------------
+      !
+      zastar = 1._wp / ( 1._wp - (rn_dmin / zdmax)**(1._wp/rn_beta) )
+      DO ji = 1, npti   
+         ! --- Calculate reduction of total sea ice concentration --- !
+         zdfloe = rn_dmin * ( zastar / ( zastar - at_i_1d(ji) ) )**rn_beta         ! Mean floe caliper diameter [m]
+         !
+         zperi  = at_i_1d(ji) * rpi / ( zcs * zdfloe )                             ! Mean perimeter of the floe [m.m-2]
+         !                                                                         !    = N*pi*D = (A/cs*D^2)*pi*D
+         zwlat  = zm1 * ( MAX( 0._wp, sst_1d(ji) - ( t_bo_1d(ji) - rt0 ) ) )**zm2  ! Melt speed rate [m/s]
+         !
+         zda_tot(ji) = MIN( zwlat * zperi * rdt_ice, at_i_1d(ji) )                 ! sea ice concentration decrease (>0)
+      
+         ! --- Distribute reduction among ice categories and calculate associated ice-ocean fluxes --- !
+         IF( a_i_1d(ji) > 0._wp ) THEN
+            ! decrease of concentration for the category jl
+            !    each category contributes to melting in proportion to its concentration
+            zda = MIN( a_i_1d(ji), zda_tot(ji) * a_i_1d(ji) / at_i_1d(ji) )
+            
+            ! Contribution to salt flux
+            sfx_lam_1d(ji) = sfx_lam_1d(ji) + rhoic *  h_i_1d(ji) * zda * s_i_1d(ji) * r1_rdtice
+            
+            ! Contribution to heat flux into the ocean [W.m-2], (<0)  
+            hfx_thd_1d(ji) = hfx_thd_1d(ji) - zda * r1_rdtice * ( h_i_1d(ji) * r1_nlay_i * SUM( e_i_1d(ji,1:nlay_i) )  &
+                                                                + h_s_1d(ji) * r1_nlay_s * SUM( e_s_1d(ji,1:nlay_s) ) ) 
+            
+            ! Contribution to mass flux
+            wfx_lam_1d(ji) =  wfx_lam_1d(ji) + zda * r1_rdtice * ( rhoic * h_i_1d(ji) + rhosn * h_s_1d(ji) )
+            
+            ! new concentration
+            a_i_1d(ji) = a_i_1d(ji) - zda
+
+            ! ensure that h_i = 0 where a_i = 0
+            IF( a_i_1d(ji) == 0._wp ) THEN
+               h_i_1d(ji) = 0._wp
+               h_s_1d(ji) = 0._wp
+            ENDIF
+         ENDIF
+      END DO
+      !
+   END SUBROUTINE ice_thd_da
+
+   SUBROUTINE ice_thd_da_init
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_thd_da_init *** 
+      !!                 
+      !! ** Purpose :   Physical constants and parameters associated with
+      !!                ice thermodynamics
+      !!
+      !! ** Method  :   Read the namthd_da namelist and check the parameters
+      !!                called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namthd_da
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ios   ! Local integer output status for namelist read
+      !!
+      NAMELIST/namthd_da/ rn_beta, rn_dmin
+      !!-------------------------------------------------------------------
+      !
+      REWIND( numnam_ice_ref )              ! Namelist namthd_da in reference namelist : Ice thermodynamics
+      READ  ( numnam_ice_ref, namthd_da, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namthd_da in reference namelist', lwp )
+
+      REWIND( numnam_ice_cfg )              ! Namelist namthd_da in configuration namelist : Ice thermodynamics
+      READ  ( numnam_ice_cfg, namthd_da, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namthd_da in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namthd_da )
+      !
+      !
+      IF(lwp) THEN                          ! control print
+         WRITE(numout,*) 'ice_thd_da_init: Ice lateral melting'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namthd_da:'
+         WRITE(numout,*) '      Coef. beta for lateral melting param.               rn_beta = ', rn_beta
+         WRITE(numout,*) '      Minimum floe diameter for lateral melting param.    rn_dmin = ', rn_dmin
+      ENDIF
+      !
+   END SUBROUTINE ice_thd_da_init
+  
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Dummy Module           NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icethd_da
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_dh.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_dh.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_dh.F90	(revision 9019)
@@ -0,0 +1,705 @@
+MODULE icethd_dh
+   !!======================================================================
+   !!                       ***  MODULE icethd_dh ***
+   !!   seaice : thermodynamic growth and melt 
+   !!======================================================================
+   !! History :  LIM  ! 2003-05 (M. Vancoppenolle) Original code in 1D
+   !!                 ! 2005-06 (M. Vancoppenolle) 3D version 
+   !!            3.2  ! 2009-07 (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in wfx_snw & wfx_ice
+   !!            3.4  ! 2011-02 (G. Madec) dynamical allocation
+   !!            3.5  ! 2012-10 (G. Madec & co) salt flux + bug fixes 
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_thd_dh        : vertical sea-ice growth and melt
+   !!   ice_thd_snwblow   : distribute snow fall between ice and ocean
+  !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE ice            ! sea-ice: variables
+   USE ice1D          ! sea-ice: thermodynamics variables
+   USE icethd_sal     ! sea-ice: salinity profiles
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_thd_dh        ! called by ice_thd
+   PUBLIC   ice_thd_snwblow   ! called in sbcblk/sbcclio/sbccpl and here
+
+   INTERFACE ice_thd_snwblow
+      MODULE PROCEDURE ice_thd_snwblow_1d, ice_thd_snwblow_2d
+   END INTERFACE
+
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icethd_dh.F90 8420 2017-08-08 12:18:46Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_thd_dh
+      !!------------------------------------------------------------------
+      !!                ***  ROUTINE ice_thd_dh  ***
+      !!
+      !! ** Purpose :   compute ice and snow thickness changes due to growing/melting
+      !!
+      !! ** Method  :   Ice/Snow surface melting arises from imbalance in surface fluxes
+      !!              Bottom accretion/ablation arises from flux budget
+      !!              Snow thickness can increase by precipitation and decrease by sublimation
+      !!              If snow load excesses Archmiede limit, snow-ice is formed by
+      !!              the flooding of sea-water in the snow
+      !!
+      !!                 1) Compute available flux of heat for surface ablation
+      !!                 2) Compute snow and sea ice enthalpies
+      !!                 3) Surface ablation and sublimation
+      !!                 4) Bottom accretion/ablation
+      !!                 5) Case of Total ablation
+      !!                 6) Snow ice formation
+      !!
+      !! References : Bitz and Lipscomb, 1999, J. Geophys. Res.
+      !!              Fichefet T. and M. Maqueda 1997, J. Geophys. Res., 102(C6), 12609-12646   
+      !!              Vancoppenolle, Fichefet and Bitz, 2005, Geophys. Res. Let. 
+      !!              Vancoppenolle et al.,2009, Ocean Modelling
+      !!------------------------------------------------------------------
+      INTEGER  ::   ji, jk       ! dummy loop indices
+      INTEGER  ::   iter         ! local integer
+
+      REAL(wp) ::   ztmelts      ! local scalar
+      REAL(wp) ::   zdum       
+      REAL(wp) ::   zfracs       ! fractionation coefficient for bottom salt entrapment
+      REAL(wp) ::   zswi1        ! switch for computation of bottom salinity
+      REAL(wp) ::   zswi12       ! switch for computation of bottom salinity
+      REAL(wp) ::   zswi2        ! switch for computation of bottom salinity
+      REAL(wp) ::   zgrr         ! bottom growth rate
+      REAL(wp) ::   zt_i_new     ! bottom formation temperature
+      REAL(wp) ::   z1_rho       ! 1/(rhosn+rau0-rhoic)
+
+      REAL(wp) ::   zQm          ! enthalpy exchanged with the ocean (J/m2), >0 towards the ocean
+      REAL(wp) ::   zEi          ! specific enthalpy of sea ice (J/kg)
+      REAL(wp) ::   zEw          ! specific enthalpy of exchanged water (J/kg)
+      REAL(wp) ::   zdE          ! specific enthalpy difference (J/kg)
+      REAL(wp) ::   zfmdt        ! exchange mass flux x time step (J/m2), >0 towards the ocean
+
+      REAL(wp), DIMENSION(jpij) ::   zqprec      ! energy of fallen snow                       (J.m-3)
+      REAL(wp), DIMENSION(jpij) ::   zq_su       ! heat for surface ablation                   (J.m-2)
+      REAL(wp), DIMENSION(jpij) ::   zq_bo       ! heat for bottom ablation                    (J.m-2)
+      REAL(wp), DIMENSION(jpij) ::   zq_rema     ! remaining heat at the end of the routine    (J.m-2)
+      REAL(wp), DIMENSION(jpij) ::   zf_tt       ! Heat budget to determine melting or freezing(W.m-2)
+      REAL(wp), DIMENSION(jpij) ::   zevap_rema  ! remaining mass flux from sublimation        (kg.m-2)
+
+      REAL(wp), DIMENSION(jpij) ::   zdh_s_mel   ! snow melt 
+      REAL(wp), DIMENSION(jpij) ::   zdh_s_pre   ! snow precipitation 
+      REAL(wp), DIMENSION(jpij) ::   zdh_s_sub   ! snow sublimation
+
+      REAL(wp), DIMENSION(jpij,nlay_i) ::   zdeltah
+      REAL(wp), DIMENSION(jpij,nlay_i) ::   zh_i      ! ice layer thickness
+      INTEGER , DIMENSION(jpij,nlay_i) ::   icount    ! number of layers vanished by melting 
+
+      REAL(wp), DIMENSION(jpij) ::   zeh_i       ! total ice heat content  (J.m-2)
+      REAL(wp), DIMENSION(jpij) ::   zsnw        ! distribution of snow after wind blowing
+
+      REAL(wp) ::   zswitch_sal
+
+      INTEGER  ::   num_iter_max      ! Heat conservation 
+      !!------------------------------------------------------------------
+
+      ! Discriminate between time varying salinity and constant
+      SELECT CASE( nn_icesal )                  ! varying salinity or not
+         CASE( 1 , 3 )   ;   zswitch_sal = 0._wp   ! prescribed salinity profile
+         CASE( 2 )       ;   zswitch_sal = 1._wp   ! varying salinity profile
+      END SELECT
+
+      ! initialize layer thicknesses and enthalpies
+      h_i_old (1:npti,0:nlay_i+1) = 0._wp
+      eh_i_old(1:npti,0:nlay_i+1) = 0._wp
+      DO jk = 1, nlay_i
+         DO ji = 1, npti
+            h_i_old (ji,jk) = h_i_1d(ji) * r1_nlay_i
+            eh_i_old(ji,jk) = e_i_1d(ji,jk) * h_i_old(ji,jk)
+         END DO
+      END DO
+      !
+      !------------------------------------------------------------------------------!
+      !  1) Calculate available heat for surface and bottom ablation                 !
+      !------------------------------------------------------------------------------!
+      !
+      SELECT CASE ( nice_jules )
+      !
+      CASE ( np_jules_ACTIVE )
+         !
+         DO ji = 1, npti
+            zq_su(ji)        =   MAX( 0._wp, qml_ice_1d(ji) * rdt_ice )
+         END DO
+         !
+      CASE ( np_jules_EMULE )
+         !
+         DO ji = 1, npti
+            zdum             =   ( qns_ice_1d(ji) + qsr_ice_1d(ji) - qsr_ice_tr_1d(ji) - fc_su(ji) ) 
+            qml_ice_1d(ji)   =   zdum * MAX( 0._wp , SIGN( 1._wp, t_su_1d(ji) - rt0 ) )
+            zq_su(ji)        =   MAX( 0._wp, qml_ice_1d(ji) * rdt_ice )
+         END DO
+         !
+      CASE ( np_jules_OFF ) 
+         !
+         DO ji = 1, npti
+            zdum             =   ( qns_ice_1d(ji) + qsr_ice_1d(ji) - qsr_ice_tr_1d(ji) - fc_su(ji) ) 
+            zdum             =   zdum * MAX( 0._wp , SIGN( 1._wp, t_su_1d(ji) - rt0 ) )
+            zq_su(ji)        =   MAX( 0._wp, zdum             * rdt_ice )
+         END DO
+         !
+      END SELECT
+      !
+      DO ji = 1, npti
+         zf_tt(ji)  = fc_bo_i(ji) + fhtur_1d(ji) + fhld_1d(ji) 
+         zq_bo (ji) = MAX( 0._wp, zf_tt(ji) * rdt_ice )
+      END DO
+
+      !------------------------------------------------------------------------------!
+      ! If snow temperature is above freezing point, then snow melts 
+      ! (should not happen but sometimes it does)
+      !------------------------------------------------------------------------------!
+      DO ji = 1, npti
+         IF( t_s_1d(ji,1) > rt0 ) THEN !!! Internal melting
+            ! Contribution to heat flux to the ocean [W.m-2], < 0  
+            hfx_res_1d(ji) = hfx_res_1d(ji) + e_s_1d(ji,1) * h_s_1d(ji) * a_i_1d(ji) * r1_rdtice
+            ! Contribution to mass flux
+            wfx_snw_sum_1d(ji) = wfx_snw_sum_1d(ji) + rhosn * h_s_1d(ji) * a_i_1d(ji) * r1_rdtice
+            dh_s_mlt(ji)       = dh_s_mlt(ji) - h_s_1d(ji)
+            ! updates
+            h_s_1d(ji)    = 0._wp
+            e_s_1d (ji,1) = 0._wp
+            t_s_1d (ji,1) = rt0
+         END IF
+      END DO
+
+      !------------------------------------------------------------!
+      !  2) Computing layer thicknesses and enthalpies.            !
+      !------------------------------------------------------------!
+      DO jk = 1, nlay_i
+         DO ji = 1, npti
+            zh_i(ji,jk) = h_i_1d(ji) * r1_nlay_i
+            zeh_i(ji)   = zeh_i(ji) + e_i_1d(ji,jk) * zh_i(ji,jk)
+         END DO
+      END DO
+
+      !------------------------------------------------------------------------------|
+      !  3) Surface ablation and sublimation                                         |
+      !------------------------------------------------------------------------------|
+      !
+      !-------------------------
+      ! 3.1 Snow precips / melt
+      !-------------------------
+      ! Snow accumulation in one thermodynamic time step
+      ! snowfall is partitionned between leads and ice
+      ! if snow fall was uniform, a fraction (1-at_i) would fall into leads
+      ! but because of the winds, more snow falls on leads than on sea ice
+      ! and a greater fraction (1-at_i)^beta of the total mass of snow 
+      ! (beta < 1) falls in leads.
+      ! In reality, beta depends on wind speed, 
+      ! and should decrease with increasing wind speed but here, it is 
+      ! considered as a constant. an average value is 0.66
+      ! Martin Vancoppenolle, December 2006
+
+      CALL ice_thd_snwblow( 1. - at_i_1d(1:npti), zsnw(1:npti) ) ! snow distribution over ice after wind blowing
+
+      zdeltah(1:npti,:) = 0._wp
+      DO ji = 1, npti
+         !-----------
+         ! Snow fall
+         !-----------
+         ! thickness change
+         zdh_s_pre(ji) = zsnw(ji) * sprecip_1d(ji) * rdt_ice * r1_rhosn / at_i_1d(ji)
+         ! enthalpy of the precip (>0, J.m-3)
+         zqprec   (ji) = - qprec_ice_1d(ji)   
+         IF( sprecip_1d(ji) == 0._wp ) zqprec(ji) = 0._wp
+         ! heat flux from snow precip (>0, W.m-2)
+         hfx_spr_1d(ji) = hfx_spr_1d(ji) + zdh_s_pre(ji) * a_i_1d(ji) * zqprec(ji) * r1_rdtice
+         ! mass flux, <0
+         wfx_spr_1d(ji) = wfx_spr_1d(ji) - rhosn * a_i_1d(ji) * zdh_s_pre(ji) * r1_rdtice
+
+         !---------------------
+         ! Melt of falling snow
+         !---------------------
+         ! thickness change
+         rswitch        = MAX( 0._wp , SIGN( 1._wp , zqprec(ji) - epsi20 ) )
+         zdeltah (ji,1) = - rswitch * zq_su(ji) / MAX( zqprec(ji) , epsi20 )
+         zdeltah (ji,1) = MAX( - zdh_s_pre(ji), zdeltah(ji,1) ) ! bound melting 
+         ! heat used to melt snow (W.m-2, >0)
+         hfx_snw_1d(ji) = hfx_snw_1d(ji) - zdeltah(ji,1) * a_i_1d(ji) * zqprec(ji) * r1_rdtice
+         ! snow melting only = water into the ocean (then without snow precip), >0
+         wfx_snw_sum_1d(ji) = wfx_snw_sum_1d(ji) - rhosn * a_i_1d(ji) * zdeltah(ji,1) * r1_rdtice
+         dh_s_mlt(ji)       = dh_s_mlt(ji) + zdeltah(ji,1)
+         ! updates available heat + precipitations after melting
+         zq_su     (ji) = MAX( 0._wp , zq_su (ji) + zdeltah(ji,1) * zqprec(ji) )      
+         zdh_s_pre (ji) = zdh_s_pre(ji) + zdeltah(ji,1)
+
+         ! update thickness
+         h_s_1d(ji) = MAX( 0._wp , h_s_1d(ji) + zdh_s_pre(ji) )
+      END DO
+
+      ! If heat still available (zq_su > 0), then melt more snow
+      zdeltah(1:npti,:) = 0._wp
+      zdh_s_mel(1:npti) = 0._wp
+      DO jk = 1, nlay_s
+         DO ji = 1, npti
+            ! thickness change
+            rswitch          = 1._wp - MAX( 0._wp, SIGN( 1._wp, - h_s_1d(ji) ) ) 
+            rswitch          = rswitch * ( MAX( 0._wp, SIGN( 1._wp, e_s_1d(ji,jk) - epsi20 ) ) ) 
+            zdeltah  (ji,jk) = - rswitch * zq_su(ji) / MAX( e_s_1d(ji,jk), epsi20 )
+            zdeltah  (ji,jk) = MAX( zdeltah(ji,jk) , - h_s_1d(ji) ) ! bound melting
+            zdh_s_mel(ji)    = zdh_s_mel(ji) + zdeltah(ji,jk)    
+            ! heat used to melt snow(W.m-2, >0)
+            hfx_snw_1d(ji)   = hfx_snw_1d(ji) - zdeltah(ji,jk) * a_i_1d(ji) * e_s_1d(ji,jk) * r1_rdtice 
+            ! snow melting only = water into the ocean (then without snow precip)
+            wfx_snw_sum_1d(ji) = wfx_snw_sum_1d(ji) - rhosn * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
+            dh_s_mlt(ji)       = dh_s_mlt(ji) + zdeltah(ji,jk)
+            ! updates available heat + thickness
+            zq_su (ji) = MAX( 0._wp , zq_su (ji) + zdeltah(ji,jk) * e_s_1d(ji,jk) )
+            h_s_1d(ji) = MAX( 0._wp , h_s_1d(ji) + zdeltah(ji,jk) )
+         END DO
+      END DO
+
+      !------------------------------
+      ! 3.2 Sublimation (part1: snow) 
+      !------------------------------
+      ! qla_ice is always >=0 (upwards), heat goes to the atmosphere, therefore snow sublimates
+      !    comment: not counted in mass/heat exchange in iceupdate.F90 since this is an exchange with atm. (not ocean)
+      zdeltah(1:npti,:) = 0._wp
+      DO ji = 1, npti
+         zdh_s_sub(ji)  = MAX( - h_s_1d(ji) , - evap_ice_1d(ji) * r1_rhosn * rdt_ice )
+         ! remaining evap in kg.m-2 (used for ice melting later on)
+         zevap_rema(ji)  = evap_ice_1d(ji) * rdt_ice + zdh_s_sub(ji) * rhosn
+         ! Heat flux by sublimation [W.m-2], < 0 (sublimate first snow that had fallen, then pre-existing snow)
+         zdeltah(ji,1)  = MAX( zdh_s_sub(ji), - zdh_s_pre(ji) )
+         hfx_sub_1d(ji) = hfx_sub_1d(ji) + ( zdeltah(ji,1) * zqprec(ji) + ( zdh_s_sub(ji) - zdeltah(ji,1) ) * e_s_1d(ji,1)  &
+            &                              ) * a_i_1d(ji) * r1_rdtice
+         ! Mass flux by sublimation
+         wfx_snw_sub_1d(ji) = wfx_snw_sub_1d(ji) - rhosn * a_i_1d(ji) * zdh_s_sub(ji) * r1_rdtice
+
+         ! new snow thickness
+         h_s_1d(ji)    =  MAX( 0._wp , h_s_1d(ji) + zdh_s_sub(ji) )
+         ! update precipitations after sublimation and correct sublimation
+         zdh_s_pre(ji) = zdh_s_pre(ji) + zdeltah(ji,1)
+         zdh_s_sub(ji) = zdh_s_sub(ji) - zdeltah(ji,1)
+      END DO
+      
+      ! --- Update snow diags --- !
+      DO ji = 1, npti
+         dh_s_tot(ji) = zdh_s_mel(ji) + zdh_s_pre(ji) + zdh_s_sub(ji)
+      END DO
+
+      !-------------------------------------------
+      ! 3.3 Update temperature, energy
+      !-------------------------------------------
+      ! new temp and enthalpy of the snow (remaining snow precip + remaining pre-existing snow)
+      DO jk = 1, nlay_s
+         DO ji = 1,npti
+            rswitch       = MAX( 0._wp , SIGN( 1._wp, h_s_1d(ji) - epsi20 ) )
+            e_s_1d(ji,jk) = rswitch / MAX( h_s_1d(ji), epsi20 ) *           &
+              &            ( ( zdh_s_pre(ji)               ) * zqprec(ji) +  &
+              &              ( h_s_1d(ji) - zdh_s_pre(ji) ) * rhosn * ( cpic * ( rt0 - t_s_1d(ji,jk) ) + lfus ) )
+         END DO
+      END DO
+
+      !--------------------------
+      ! 3.4 Surface ice ablation 
+      !--------------------------
+      zdeltah(1:npti,:) = 0._wp ! important
+      DO jk = 1, nlay_i
+         DO ji = 1, npti
+            ztmelts           = - tmut * sz_i_1d(ji,jk)          ! Melting point of layer k [C]
+            
+            IF( t_i_1d(ji,jk) >= (ztmelts+rt0) ) THEN !!! Internal melting
+
+               zEi            = - e_i_1d(ji,jk) * r1_rhoic            ! Specific enthalpy of layer k [J/kg, <0]       
+               zdE            = 0._wp                                 ! Specific enthalpy difference   (J/kg, <0)
+                                                                      ! set up at 0 since no energy is needed to melt water...(it is already melted)
+               zdeltah(ji,jk) = MIN( 0._wp , - zh_i(ji,jk) )          ! internal melting occurs when the internal temperature is above freezing     
+                                                                      ! this should normally not happen, but sometimes, heat diffusion leads to this
+               zfmdt          = - zdeltah(ji,jk) * rhoic              ! Mass flux x time step > 0
+                         
+               dh_i_surf(ji)  = dh_i_surf(ji) + zdeltah(ji,jk)        ! Cumulate surface melt
+               
+               zfmdt          = - rhoic * zdeltah(ji,jk)              ! Recompute mass flux [kg/m2, >0]
+
+               ! Contribution to heat flux to the ocean [W.m-2], <0 (ice enthalpy zEi is "sent" to the ocean) 
+               hfx_res_1d(ji) = hfx_res_1d(ji) + zfmdt * a_i_1d(ji) * zEi * r1_rdtice
+               
+               ! Contribution to salt flux (using s_i_1d and not sz_i_1d(jk) is ok)
+               sfx_res_1d(ji) = sfx_res_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * s_i_1d(ji) * r1_rdtice
+               
+               ! Contribution to mass flux
+               wfx_res_1d(ji) =  wfx_res_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
+
+            ELSE                                !!! Surface melting
+               
+               zEi            = - e_i_1d(ji,jk) * r1_rhoic            ! Specific enthalpy of layer k [J/kg, <0]
+               zEw            =    rcp * ztmelts                      ! Specific enthalpy of resulting meltwater [J/kg, <0]
+               zdE            =    zEi - zEw                          ! Specific enthalpy difference < 0
+               
+               zfmdt          = - zq_su(ji) / zdE                     ! Mass flux to the ocean [kg/m2, >0]
+               
+               zdeltah(ji,jk) = - zfmdt * r1_rhoic                    ! Melt of layer jk [m, <0]
+               
+               zdeltah(ji,jk) = MIN( 0._wp , MAX( zdeltah(ji,jk) , - zh_i(ji,jk) ) )    ! Melt of layer jk cannot exceed the layer thickness [m, <0]
+               
+               zq_su(ji)      = MAX( 0._wp , zq_su(ji) - zdeltah(ji,jk) * rhoic * zdE ) ! update available heat
+               
+               dh_i_surf(ji)  = dh_i_surf(ji) + zdeltah(ji,jk)        ! Cumulate surface melt
+               
+               zfmdt          = - rhoic * zdeltah(ji,jk)              ! Recompute mass flux [kg/m2, >0]
+               
+               zQm            = zfmdt * zEw                           ! Energy of the melt water sent to the ocean [J/m2, <0]
+               
+               ! Contribution to salt flux >0 (using s_i_1d and not sz_i_1d(jk) is ok)
+               sfx_sum_1d(ji) = sfx_sum_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * s_i_1d(ji) * r1_rdtice
+               
+               ! Contribution to heat flux [W.m-2], < 0
+               hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice
+               
+               ! Total heat flux used in this process [W.m-2], > 0  
+               hfx_sum_1d(ji) = hfx_sum_1d(ji) - zfmdt * a_i_1d(ji) * zdE * r1_rdtice
+               
+               ! Contribution to mass flux
+               wfx_sum_1d(ji) =  wfx_sum_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
+               
+            END IF
+            ! ----------------------
+            ! Sublimation part2: ice
+            ! ----------------------
+            zdum      = MAX( - ( zh_i(ji,jk) + zdeltah(ji,jk) ) , - zevap_rema(ji) * r1_rhoic )
+            zdeltah(ji,jk) = zdeltah(ji,jk) + zdum
+            dh_i_sub(ji)  = dh_i_sub(ji) + zdum
+            ! Salt flux > 0 (clem: flux is sent to the ocean for simplicity but salt should remain in the ice except if all ice is melted.
+            !                          It must be corrected at some point)
+            sfx_sub_1d(ji) = sfx_sub_1d(ji) - rhoic * a_i_1d(ji) * zdum * s_i_1d(ji) * r1_rdtice
+            ! Heat flux [W.m-2], < 0
+            hfx_sub_1d(ji) = hfx_sub_1d(ji) + zdum * e_i_1d(ji,jk) * a_i_1d(ji) * r1_rdtice
+            ! Mass flux > 0
+            wfx_ice_sub_1d(ji) =  wfx_ice_sub_1d(ji) - rhoic * a_i_1d(ji) * zdum * r1_rdtice
+
+            ! update remaining mass flux
+            zevap_rema(ji)  = zevap_rema(ji) + zdum * rhoic
+            
+            ! record which layers have disappeared (for bottom melting) 
+            !    => icount=0 : no layer has vanished
+            !    => icount=5 : 5 layers have vanished
+            rswitch       = MAX( 0._wp , SIGN( 1._wp , - ( zh_i(ji,jk) + zdeltah(ji,jk) ) ) ) 
+            icount(ji,jk) = NINT( rswitch )
+            zh_i(ji,jk)   = MAX( 0._wp , zh_i(ji,jk) + zdeltah(ji,jk) )
+                        
+            ! update heat content (J.m-2) and layer thickness
+            eh_i_old(ji,jk) = eh_i_old(ji,jk) + zdeltah(ji,jk) * e_i_1d(ji,jk)
+            h_i_old (ji,jk) = h_i_old (ji,jk) + zdeltah(ji,jk)
+         END DO
+      END DO
+      ! update ice thickness
+      DO ji = 1, npti
+         h_i_1d(ji) =  MAX( 0._wp , h_i_1d(ji) + dh_i_surf(ji) + dh_i_sub(ji) )
+      END DO
+
+      ! remaining "potential" evap is sent to ocean
+      DO ji = 1, npti
+         wfx_err_sub_1d(ji) = wfx_err_sub_1d(ji) - zevap_rema(ji) * a_i_1d(ji) * r1_rdtice  ! <=0 (net evap for the ocean in kg.m-2.s-1)
+      END DO
+
+
+      !------------------------------------------------------------------------------!
+      ! 4) Basal growth / melt                                                       !
+      !------------------------------------------------------------------------------!
+      !
+      !------------------
+      ! 4.1 Basal growth 
+      !------------------
+      ! Basal growth is driven by heat imbalance at the ice-ocean interface,
+      ! between the inner conductive flux  (fc_bo_i), from the open water heat flux 
+      ! (fhld) and the turbulent ocean flux (fhtur). 
+      ! fc_bo_i is positive downwards. fhtur and fhld are positive to the ice 
+
+      ! If salinity varies in time, an iterative procedure is required, because
+      ! the involved quantities are inter-dependent.
+      ! Basal growth (dh_i_bott) depends upon new ice specific enthalpy (zEi),
+      ! which depends on forming ice salinity (s_i_new), which depends on dh/dt (dh_i_bott)
+      ! -> need for an iterative procedure, which converges quickly
+
+      num_iter_max = 1
+      IF( nn_icesal == 2 )   num_iter_max = 5  ! salinity varying in time
+      
+      ! Iterative procedure
+      DO ji = 1, npti
+         IF(  zf_tt(ji) < 0._wp  ) THEN
+            DO iter = 1, num_iter_max
+
+               ! New bottom ice salinity (Cox & Weeks, JGR88 )
+               !--- zswi1  if dh/dt < 2.0e-8
+               !--- zswi12 if 2.0e-8 < dh/dt < 3.6e-7 
+               !--- zswi2  if dh/dt > 3.6e-7
+               zgrr               = MIN( 1.0e-3, MAX ( dh_i_bott(ji) * r1_rdtice , epsi10 ) )
+               zswi2              = MAX( 0._wp , SIGN( 1._wp , zgrr - 3.6e-7 ) )
+               zswi12             = MAX( 0._wp , SIGN( 1._wp , zgrr - 2.0e-8 ) ) * ( 1.0 - zswi2 )
+               zswi1              = 1. - zswi2 * zswi12
+               zfracs             = MIN ( zswi1  * 0.12 + zswi12 * ( 0.8925 + 0.0568 * LOG( 100.0 * zgrr ) )   &
+                  &               + zswi2  * 0.26 / ( 0.26 + 0.74 * EXP ( - 724300.0 * zgrr ) )  , 0.5 )
+
+               s_i_new(ji)        = zswitch_sal * zfracs * sss_1d(ji)  &  ! New ice salinity
+                                  + ( 1. - zswitch_sal ) * s_i_1d(ji) 
+               ! New ice growth
+               ztmelts            = - tmut * s_i_new(ji)                 ! New ice melting point (C)
+
+               zt_i_new           = zswitch_sal * t_bo_1d(ji) + ( 1. - zswitch_sal) * t_i_1d(ji, nlay_i)
+               
+               zEi                = cpic * ( zt_i_new - (ztmelts+rt0) ) &     ! Specific enthalpy of forming ice (J/kg, <0)      
+                  &               - lfus * ( 1.0 - ztmelts / ( zt_i_new - rt0 ) )   &
+                  &               + rcp  * ztmelts          
+
+               zEw                = rcp  * ( t_bo_1d(ji) - rt0 )         ! Specific enthalpy of seawater (J/kg, < 0)
+
+               zdE                = zEi - zEw                           ! Specific enthalpy difference (J/kg, <0)
+
+               dh_i_bott(ji)      = rdt_ice * MAX( 0._wp , zf_tt(ji) / ( zdE * rhoic ) )
+               
+            END DO
+            ! Contribution to Energy and Salt Fluxes                                    
+            zfmdt          = - rhoic * dh_i_bott(ji)             ! Mass flux x time step (kg/m2, < 0)
+
+            ztmelts        = - tmut * s_i_new(ji)                ! New ice melting point (C)
+            
+            zt_i_new       = zswitch_sal * t_bo_1d(ji) + ( 1. - zswitch_sal) * t_i_1d(ji, nlay_i)
+            
+            zEi            = cpic * ( zt_i_new - (ztmelts+rt0) ) &     ! Specific enthalpy of forming ice (J/kg, <0)      
+               &               - lfus * ( 1.0 - ztmelts / ( zt_i_new - rt0 ) )   &
+               &               + rcp  * ztmelts          
+            
+            zEw            = rcp  * ( t_bo_1d(ji) - rt0 )         ! Specific enthalpy of seawater (J/kg, < 0)
+            
+            zdE            = zEi - zEw                           ! Specific enthalpy difference (J/kg, <0)
+            
+            ! Contribution to heat flux to the ocean [W.m-2], >0  
+            hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice
+
+            ! Total heat flux used in this process [W.m-2], <0  
+            hfx_bog_1d(ji) = hfx_bog_1d(ji) - zfmdt * a_i_1d(ji) * zdE * r1_rdtice
+            
+            ! Contribution to salt flux, <0
+            sfx_bog_1d(ji) = sfx_bog_1d(ji) - rhoic * a_i_1d(ji) * dh_i_bott(ji) * s_i_new(ji) * r1_rdtice
+
+            ! Contribution to mass flux, <0
+            wfx_bog_1d(ji) =  wfx_bog_1d(ji) - rhoic * a_i_1d(ji) * dh_i_bott(ji) * r1_rdtice
+
+            ! update heat content (J.m-2) and layer thickness
+            eh_i_old(ji,nlay_i+1) = eh_i_old(ji,nlay_i+1) + dh_i_bott(ji) * (-zEi * rhoic)
+            h_i_old (ji,nlay_i+1) = h_i_old (ji,nlay_i+1) + dh_i_bott(ji)
+
+         ENDIF
+
+      END DO
+
+      !----------------
+      ! 4.2 Basal melt
+      !----------------
+      zdeltah(1:npti,:) = 0._wp ! important
+      DO jk = nlay_i, 1, -1
+         DO ji = 1, npti
+            IF(  zf_tt(ji)  >  0._wp  .AND. jk > icount(ji,jk) ) THEN   ! do not calculate where layer has already disappeared by surface melting 
+
+               ztmelts = - tmut * sz_i_1d(ji,jk)  ! Melting point of layer jk (C)
+
+               IF( t_i_1d(ji,jk) >= (ztmelts+rt0) ) THEN !!! Internal melting
+
+                  zEi               = - e_i_1d(ji,jk) * r1_rhoic    ! Specific enthalpy of melting ice (J/kg, <0)
+                  zdE               = 0._wp                         ! Specific enthalpy difference   (J/kg, <0)
+                                                                    ! set up at 0 since no energy is needed to melt water...(it is already melted)
+                  zdeltah   (ji,jk) = MIN( 0._wp , - zh_i(ji,jk) )  ! internal melting occurs when the internal temperature is above freezing     
+                                                                    ! this should normally not happen, but sometimes, heat diffusion leads to this
+
+                  dh_i_bott (ji)    = dh_i_bott(ji) + zdeltah(ji,jk)
+
+                  zfmdt             = - zdeltah(ji,jk) * rhoic      ! Mass flux x time step > 0
+
+                  ! Contribution to heat flux to the ocean [W.m-2], <0 (ice enthalpy zEi is "sent" to the ocean) 
+                  hfx_res_1d(ji) = hfx_res_1d(ji) + zfmdt * a_i_1d(ji) * zEi * r1_rdtice
+
+                  ! Contribution to salt flux (using s_i_1d and not sz_i_1d(jk) is ok)
+                  sfx_res_1d(ji) = sfx_res_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * s_i_1d(ji) * r1_rdtice
+                                    
+                  ! Contribution to mass flux
+                  wfx_res_1d(ji) =  wfx_res_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
+
+                  ! update heat content (J.m-2) and layer thickness
+                  eh_i_old(ji,jk) = eh_i_old(ji,jk) + zdeltah(ji,jk) * e_i_1d(ji,jk)
+                  h_i_old (ji,jk) = h_i_old (ji,jk) + zdeltah(ji,jk)
+
+               ELSE                               !!! Basal melting
+
+                  zEi             = - e_i_1d(ji,jk) * r1_rhoic ! Specific enthalpy of melting ice (J/kg, <0)
+                  zEw             = rcp * ztmelts              ! Specific enthalpy of meltwater (J/kg, <0)
+                  zdE             = zEi - zEw                  ! Specific enthalpy difference   (J/kg, <0)
+
+                  zfmdt           = - zq_bo(ji) / zdE          ! Mass flux x time step (kg/m2, >0)
+
+                  zdeltah(ji,jk)  = - zfmdt * r1_rhoic         ! Gross thickness change
+
+                  zdeltah(ji,jk)  = MIN( 0._wp , MAX( zdeltah(ji,jk), - zh_i(ji,jk) ) ) ! bound thickness change
+                  
+                  zq_bo(ji)       = MAX( 0._wp , zq_bo(ji) - zdeltah(ji,jk) * rhoic * zdE ) ! update available heat. MAX is necessary for roundup errors
+
+                  dh_i_bott(ji)   = dh_i_bott(ji) + zdeltah(ji,jk)    ! Update basal melt
+
+                  zfmdt           = - zdeltah(ji,jk) * rhoic          ! Mass flux x time step > 0
+
+                  zQm             = zfmdt * zEw         ! Heat exchanged with ocean
+
+                  ! Contribution to heat flux to the ocean [W.m-2], <0  
+                  hfx_thd_1d(ji)  = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice
+
+                  ! Contribution to salt flux (using s_i_1d and not sz_i_1d(jk) is ok)
+                  sfx_bom_1d(ji)  = sfx_bom_1d(ji) - rhoic *  a_i_1d(ji) * zdeltah(ji,jk) * s_i_1d(ji) * r1_rdtice
+                  
+                  ! Total heat flux used in this process [W.m-2], >0  
+                  hfx_bom_1d(ji)  = hfx_bom_1d(ji) - zfmdt * a_i_1d(ji) * zdE * r1_rdtice
+                  
+                  ! Contribution to mass flux
+                  wfx_bom_1d(ji)  =  wfx_bom_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
+
+                  ! update heat content (J.m-2) and layer thickness
+                  eh_i_old(ji,jk) = eh_i_old(ji,jk) + zdeltah(ji,jk) * e_i_1d(ji,jk)
+                  h_i_old (ji,jk) = h_i_old (ji,jk) + zdeltah(ji,jk)
+               ENDIF
+           
+            ENDIF
+         END DO
+      END DO
+
+      !-------------------------------------------
+      ! Update temperature, energy
+      !-------------------------------------------
+      DO ji = 1, npti
+         h_i_1d(ji) =  MAX( 0._wp , h_i_1d(ji) + dh_i_bott(ji) )
+      END DO  
+
+      !-------------------------------------------
+      ! 5. What to do with remaining energy
+      !-------------------------------------------
+      ! If heat still available for melting and snow remains, then melt more snow
+      !-------------------------------------------
+      zdeltah(1:npti,:) = 0._wp ! important
+      DO ji = 1, npti
+         zq_rema(ji)     = zq_su(ji) + zq_bo(ji) 
+         rswitch         = 1._wp - MAX( 0._wp, SIGN( 1._wp, - h_s_1d(ji) ) )   ! =1 if snow
+         rswitch         = rswitch * MAX( 0._wp, SIGN( 1._wp, e_s_1d(ji,1) - epsi20 ) )
+         zdeltah  (ji,1) = - rswitch * zq_rema(ji) / MAX( e_s_1d(ji,1), epsi20 )
+         zdeltah  (ji,1) = MIN( 0._wp , MAX( zdeltah(ji,1) , - h_s_1d(ji) ) ) ! bound melting
+         dh_s_tot (ji)   = dh_s_tot(ji)  + zdeltah(ji,1)
+         h_s_1d   (ji)   = h_s_1d(ji)   + zdeltah(ji,1)
+        
+         zq_rema(ji)     = zq_rema(ji) + zdeltah(ji,1) * e_s_1d(ji,1)                ! update available heat (J.m-2)
+         ! heat used to melt snow
+         hfx_snw_1d(ji)  = hfx_snw_1d(ji) - zdeltah(ji,1) * a_i_1d(ji) * e_s_1d(ji,1) * r1_rdtice ! W.m-2 (>0)
+         ! Contribution to mass flux
+         wfx_snw_sum_1d(ji) = wfx_snw_sum_1d(ji) - rhosn * a_i_1d(ji) * zdeltah(ji,1) * r1_rdtice
+         dh_s_mlt(ji)       = dh_s_mlt(ji) + zdeltah(ji,1)
+         !    
+         ! Remaining heat flux (W.m-2) is sent to the ocean heat budget
+         hfx_out_1d(ji)  = hfx_out_1d(ji) + ( zq_rema(ji) * a_i_1d(ji) ) * r1_rdtice
+
+         IF( ln_icectl .AND. zq_rema(ji) < 0. .AND. lwp ) WRITE(numout,*) 'ALERTE zq_rema <0 = ', zq_rema(ji)
+      END DO
+
+      !
+      !------------------------------------------------------------------------------|
+      !  6) Snow-Ice formation                                                       |
+      !------------------------------------------------------------------------------|
+      ! When snow load excesses Archimede's limit, snow-ice interface goes down under sea-level, 
+      ! flooding of seawater transforms snow into ice dh_snowice is positive for the ice
+      z1_rho = 1._wp / ( rhosn+rau0-rhoic )
+      DO ji = 1, npti
+         !
+         dh_snowice(ji) = MAX(  0._wp , ( rhosn * h_s_1d(ji) + (rhoic-rau0) * h_i_1d(ji) ) * z1_rho )
+
+         h_i_1d(ji)    = h_i_1d(ji) + dh_snowice(ji)
+         h_s_1d(ji)    = h_s_1d(ji) - dh_snowice(ji)
+
+         ! Contribution to energy flux to the ocean [J/m2], >0 (if sst<0)
+         zfmdt          = ( rhosn - rhoic ) * dh_snowice(ji)    ! <0
+         zEw            = rcp * sst_1d(ji)
+         zQm            = zfmdt * zEw 
+         
+         ! Contribution to heat flux
+         hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice 
+
+         ! Contribution to salt flux
+         sfx_sni_1d(ji) = sfx_sni_1d(ji) + sss_1d(ji) * a_i_1d(ji) * zfmdt * r1_rdtice 
+
+         ! Case constant salinity in time: virtual salt flux to keep salinity constant
+         IF( nn_icesal /= 2 )  THEN
+            sfx_bri_1d(ji) = sfx_bri_1d(ji) - sss_1d (ji) * a_i_1d(ji) * zfmdt                  * r1_rdtice  & ! put back sss_m     into the ocean
+               &                            - s_i_1d(ji)  * a_i_1d(ji) * dh_snowice(ji) * rhoic * r1_rdtice    ! and get  rn_icesal from the ocean 
+         ENDIF
+
+         ! Contribution to mass flux
+         ! All snow is thrown in the ocean, and seawater is taken to replace the volume
+         wfx_sni_1d(ji)     = wfx_sni_1d(ji)     - a_i_1d(ji) * dh_snowice(ji) * rhoic * r1_rdtice
+         wfx_snw_sni_1d(ji) = wfx_snw_sni_1d(ji) + a_i_1d(ji) * dh_snowice(ji) * rhosn * r1_rdtice
+
+         ! update heat content (J.m-2) and layer thickness
+         eh_i_old(ji,0) = eh_i_old(ji,0) + dh_snowice(ji) * e_s_1d(ji,1) + zfmdt * zEw
+         h_i_old (ji,0) = h_i_old (ji,0) + dh_snowice(ji)
+         
+      END DO
+
+      !
+      !-------------------------------------------
+      ! Update temperature, energy
+      !-------------------------------------------
+      DO ji = 1, npti
+         rswitch     =  1.0 - MAX( 0._wp , SIGN( 1._wp , - h_i_1d(ji) ) ) 
+         t_su_1d(ji) =  rswitch * t_su_1d(ji) + ( 1.0 - rswitch ) * rt0
+      END DO
+
+      DO jk = 1, nlay_s
+         DO ji = 1,npti
+            ! mask enthalpy
+            rswitch       = 1._wp - MAX(  0._wp , SIGN( 1._wp, - h_s_1d(ji) )  )
+            e_s_1d(ji,jk) = rswitch * e_s_1d(ji,jk)
+            ! recalculate t_s_1d from e_s_1d
+            t_s_1d(ji,jk) = rt0 + rswitch * ( - e_s_1d(ji,jk) * r1_rhosn * r1_cpic + lfus * r1_cpic )
+         END DO
+      END DO
+
+      ! --- ensure that a_i = 0 where h_i = 0 ---
+      WHERE( h_i_1d(1:npti) == 0._wp )   a_i_1d(1:npti) = 0._wp
+      !
+   END SUBROUTINE ice_thd_dh
+
+
+   !!--------------------------------------------------------------------------
+   !! INTERFACE ice_thd_snwblow
+   !! ** Purpose :   Compute distribution of precip over the ice
+   !!--------------------------------------------------------------------------
+!!gm  I think it can be usefull to set this as a FUNCTION, not a SUBROUTINE....
+   SUBROUTINE ice_thd_snwblow_2d( pin, pout )
+      REAL(wp), DIMENSION(:,:), INTENT(in   ) :: pin   ! previous fraction lead ( 1. - a_i_b )
+      REAL(wp), DIMENSION(:,:), INTENT(inout) :: pout
+      pout = ( 1._wp - ( pin )**rn_blow_s )
+   END SUBROUTINE ice_thd_snwblow_2d
+
+   SUBROUTINE ice_thd_snwblow_1d( pin, pout )
+      REAL(wp), DIMENSION(:), INTENT(in   ) :: pin
+      REAL(wp), DIMENSION(:), INTENT(inout) :: pout
+      pout = ( 1._wp - ( pin )**rn_blow_s )
+   END SUBROUTINE ice_thd_snwblow_1d
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icethd_dh
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_do.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_do.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_do.F90	(revision 9019)
@@ -0,0 +1,526 @@
+MODULE icethd_do
+   !!======================================================================
+   !!                       ***  MODULE icethd_do   ***
+   !!   sea-ice: sea ice growth in the leads (open water)  
+   !!======================================================================
+   !! History :  LIM  ! 2005-12 (M. Vancoppenolle)  Original code
+   !!             -   ! 2006-01 (M. Vancoppenolle)  add ITD
+   !!            3.0  ! 2007-07 (M. Vancoppenolle)  Mass and energy conservation tested
+   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_thd_do        : ice growth in open water (=lateral accretion of ice)
+   !!   ice_thd_do_init   : initialization
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE sbc_oce , ONLY : sss_m
+   USE sbc_ice , ONLY : utau_ice, vtau_ice
+   USE ice1D          ! sea-ice: thermodynamics variables
+   USE ice            ! sea-ice: variables
+   USE icetab         ! sea-ice: 2D <==> 1D
+   USE icectl         ! sea-ice: conservation
+   USE icethd_ent     ! sea-ice: thermodynamics, enthalpy
+   USE icevar         ! sea-ice: operations
+   USE icethd_sal     ! sea-ice: salinity profiles
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE lbclnk         ! lateral boundary conditions (or mpp links)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_thd_do        ! called by ice_thd
+   PUBLIC   ice_thd_do_init   ! called by ice_stp
+
+   ! ** namelist (namthd_do) **
+   REAL(wp) ::   rn_hinew         ! thickness for new ice formation (m)
+   LOGICAL  ::   ln_frazil        ! use of frazil ice collection as function of wind (T) or not (F)
+   REAL(wp) ::   rn_maxfraz       ! maximum portion of frazil ice collecting at the ice bottom
+   REAL(wp) ::   rn_vfraz         ! threshold drift speed for collection of bottom frazil ice
+   REAL(wp) ::   rn_Cfraz         ! squeezing coefficient for collection of bottom frazil ice
+
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icethd_do.F90 8420 2017-08-08 12:18:46Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_thd_do
+      !!-------------------------------------------------------------------
+      !!               ***   ROUTINE ice_thd_do  ***
+      !!  
+      !! ** Purpose : Computation of the evolution of the ice thickness and 
+      !!      concentration as a function of the heat balance in the leads.
+      !!       
+      !! ** Method  : Ice is formed in the open water when ocean lose heat
+      !!      (heat budget of open water Bl is negative) .
+      !!      Computation of the increase of 1-A (ice concentration) fol-
+      !!      lowing the law :
+      !!      (dA/dt)acc = F[ (1-A)/(1-a) ] * [ Bl / (Li*h0) ]
+      !!       where - h0 is the thickness of ice created in the lead
+      !!             - a is a minimum fraction for leads
+      !!             - F is a monotonic non-increasing function defined as:
+      !!                  F(X)=( 1 - X**exld )**(1.0/exld)
+      !!             - exld is the exponent closure rate (=2 default val.)
+      !! 
+      !! ** Action : - Adjustment of snow and ice thicknesses and heat
+      !!                content in brine pockets
+      !!             - Updating ice internal temperature
+      !!             - Computation of variation of ice volume and mass
+      !!             - Computation of a_i after lateral accretion and 
+      !!               update h_s_1d, h_i_1d      
+      !!------------------------------------------------------------------------
+      INTEGER  ::   ji,jj,jk,jl      ! dummy loop indices
+      INTEGER  ::   iter     !   -       -
+      REAL(wp) ::   ztmelts, zfrazb, zweight, zde                          ! local scalars
+      REAL(wp) ::   zgamafr, zvfrx, zvgx, ztaux, ztwogp, zf                     !   -      -
+      REAL(wp) ::   ztenagm, zvfry, zvgy, ztauy, zvrel2, zfp, zsqcd , zhicrit   !   -      -
+
+      REAL(wp) ::   zQm          ! enthalpy exchanged with the ocean (J/m2, >0 towards ocean)
+      REAL(wp) ::   zEi          ! sea ice specific enthalpy (J/kg)
+      REAL(wp) ::   zEw          ! seawater specific enthalpy (J/kg)
+      REAL(wp) ::   zfmdt        ! mass flux x time step (kg/m2, >0 towards ocean)
+     
+      REAL(wp) ::   zv_newfra
+  
+      INTEGER , DIMENSION(jpij) ::   jcat        ! indexes of categories where new ice grows
+      REAL(wp), DIMENSION(jpij) ::   zswinew     ! switch for new ice or not
+
+      REAL(wp), DIMENSION(jpij) ::   zv_newice   ! volume of accreted ice
+      REAL(wp), DIMENSION(jpij) ::   za_newice   ! fractional area of accreted ice
+      REAL(wp), DIMENSION(jpij) ::   zh_newice   ! thickness of accreted ice
+      REAL(wp), DIMENSION(jpij) ::   ze_newice   ! heat content of accreted ice
+      REAL(wp), DIMENSION(jpij) ::   zs_newice   ! salinity of accreted ice
+      REAL(wp), DIMENSION(jpij) ::   zo_newice   ! age of accreted ice
+      REAL(wp), DIMENSION(jpij) ::   zdv_res     ! residual volume in case of excessive heat budget
+      REAL(wp), DIMENSION(jpij) ::   zda_res     ! residual area in case of excessive heat budget
+      REAL(wp), DIMENSION(jpij) ::   zv_frazb    ! accretion of frazil ice at the ice bottom
+      REAL(wp), DIMENSION(jpij) ::   zvrel_1d    ! relative ice / frazil velocity (1D vector)
+
+      REAL(wp), DIMENSION(jpij,jpl) ::   zv_b      ! old volume of ice in category jl
+      REAL(wp), DIMENSION(jpij,jpl) ::   za_b      ! old area of ice in category jl
+
+      REAL(wp), DIMENSION(jpij,nlay_i,jpl) ::   ze_i_2d !: 1-D version of e_i
+
+      REAL(wp), DIMENSION(jpi,jpj) ::   zvrel     ! relative ice / frazil velocity
+
+      REAL(wp) :: zcai = 1.4e-3_wp                     ! ice-air drag (clem: should be dependent on coupling/forcing used)
+      !!-----------------------------------------------------------------------!
+
+      IF( ln_icediachk )   CALL ice_cons_hsm(0, 'icethd_do', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft)
+
+      CALL ice_var_agg(1)
+      CALL ice_var_glo2eqv
+
+      !------------------------------------------------------------------------------!
+      ! 3) Collection thickness of ice formed in leads and polynyas
+      !------------------------------------------------------------------------------!    
+      ! ht_i_new is the thickness of new ice formed in open water
+      ! ht_i_new can be either prescribed (frazswi = 0) or computed (frazswi = 1)
+      ! Frazil ice forms in open water, is transported by wind
+      ! accumulates at the edge of the consolidated ice edge
+      ! where it forms aggregates of a specific thickness called
+      ! collection thickness.
+
+      ! Note : the following algorithm currently breaks vectorization
+      ! 
+
+      zvrel(:,:) = 0._wp
+
+      ! Default new ice thickness
+      WHERE( qlead(:,:) < 0._wp )   ;   ht_i_new(:,:) = rn_hinew
+      ELSEWHERE                     ;   ht_i_new(:,:) = 0._wp
+      END WHERE
+
+      IF( ln_frazil ) THEN
+
+         !--------------------
+         ! Physical constants
+         !--------------------
+         ht_i_new(:,:) = 0._wp
+
+         zhicrit = 0.04 ! frazil ice thickness
+         ztwogp  = 2. * rau0 / ( grav * 0.3 * ( rau0 - rhoic ) ) ! reduced grav
+         zsqcd   = 1.0 / SQRT( 1.3 * zcai ) ! 1/SQRT(airdensity*drag)
+         zgamafr = 0.03
+
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               IF ( qlead(ji,jj) < 0._wp .AND. tau_icebfr(ji,jj) == 0._wp ) THEN ! activated if cooling and no landfast
+                  !-------------
+                  ! Wind stress
+                  !-------------
+                  ! C-grid wind stress components
+                  ztaux         = ( utau_ice(ji-1,jj  ) * umask(ji-1,jj  ,1)   &
+                     &          +   utau_ice(ji  ,jj  ) * umask(ji  ,jj  ,1) ) * 0.5_wp
+                  ztauy         = ( vtau_ice(ji  ,jj-1) * vmask(ji  ,jj-1,1)   &
+                     &          +   vtau_ice(ji  ,jj  ) * vmask(ji  ,jj  ,1) ) * 0.5_wp
+                  ! Square root of wind stress
+                  ztenagm       =  SQRT( SQRT( ztaux * ztaux + ztauy * ztauy ) )
+
+                  !---------------------
+                  ! Frazil ice velocity
+                  !---------------------
+                  rswitch = MAX( 0._wp, SIGN( 1._wp , ztenagm - epsi10 ) )
+                  zvfrx   = rswitch * zgamafr * zsqcd * ztaux / MAX( ztenagm, epsi10 )
+                  zvfry   = rswitch * zgamafr * zsqcd * ztauy / MAX( ztenagm, epsi10 )
+
+                  !-------------------
+                  ! Pack ice velocity
+                  !-------------------
+                  ! C-grid ice velocity
+                  zvgx    = ( u_ice(ji-1,jj  ) * umask(ji-1,jj  ,1)  + u_ice(ji,jj) * umask(ji,jj,1) ) * 0.5_wp
+                  zvgy    = ( v_ice(ji  ,jj-1) * vmask(ji  ,jj-1,1)  + v_ice(ji,jj) * vmask(ji,jj,1) ) * 0.5_wp
+
+                  !-----------------------------------
+                  ! Relative frazil/pack ice velocity
+                  !-----------------------------------
+                  ! absolute relative velocity
+                  rswitch      = MAX( 0._wp, SIGN( 1._wp , at_i(ji,jj) - epsi10 ) )
+                  zvrel2       = MAX(  ( zvfrx - zvgx ) * ( zvfrx - zvgx )   &
+                     &               + ( zvfry - zvgy ) * ( zvfry - zvgy ) , 0.15 * 0.15 ) * rswitch
+                  zvrel(ji,jj) = SQRT( zvrel2 )
+
+                  !---------------------
+                  ! Iterative procedure
+                  !---------------------
+                  ht_i_new(ji,jj) = zhicrit +   ( zhicrit + 0.1 )    &
+                     &                   / ( ( zhicrit + 0.1 ) * ( zhicrit + 0.1 ) -  zhicrit * zhicrit ) * ztwogp * zvrel2
+
+                  iter = 1
+                  DO WHILE ( iter < 20 ) 
+                     zf  = ( ht_i_new(ji,jj) - zhicrit ) * ( ht_i_new(ji,jj) * ht_i_new(ji,jj) - zhicrit * zhicrit ) -   &
+                        &    ht_i_new(ji,jj) * zhicrit * ztwogp * zvrel2
+                     zfp = ( ht_i_new(ji,jj) - zhicrit ) * ( 3.0 * ht_i_new(ji,jj) + zhicrit ) - zhicrit * ztwogp * zvrel2
+
+                     ht_i_new(ji,jj) = ht_i_new(ji,jj) - zf / MAX( zfp, epsi20 )
+                     iter = iter + 1
+                  END DO
+
+               ENDIF ! end of selection of pixels where ice forms
+
+            END DO 
+         END DO 
+         ! 
+         CALL lbc_lnk_multi( zvrel, 'T', 1., ht_i_new, 'T', 1.  )
+
+      ENDIF ! End of computation of frazil ice collection thickness
+
+      !------------------------------------------------------------------------------!
+      ! 4) Identify grid points where new ice forms
+      !------------------------------------------------------------------------------!
+
+      !-------------------------------------
+      ! Select points for new ice formation
+      !-------------------------------------
+      ! This occurs if open water energy budget is negative (cooling) and there is no landfast ice
+      npti = 0 ; nptidx(:) = 0
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF ( qlead(ji,jj)  <  0._wp .AND. tau_icebfr(ji,jj) == 0._wp ) THEN
+               npti = npti + 1
+               nptidx( npti ) = (jj - 1) * jpi + ji
+            ENDIF
+         END DO
+      END DO
+
+      !------------------------------
+      ! Move from 2-D to 1-D vectors
+      !------------------------------
+      ! If ocean gains heat do nothing. Otherwise compute new ice formation
+
+      IF ( npti > 0 ) THEN
+
+         CALL tab_2d_1d( npti, nptidx(1:npti), at_i_1d(1:npti)      , at_i        )
+         CALL tab_3d_2d( npti, nptidx(1:npti), a_i_2d (1:npti,1:jpl), a_i (:,:,:) )
+         CALL tab_3d_2d( npti, nptidx(1:npti), v_i_2d (1:npti,1:jpl), v_i (:,:,:) )
+         CALL tab_3d_2d( npti, nptidx(1:npti), sv_i_2d(1:npti,1:jpl), sv_i(:,:,:) )
+         DO jl = 1, jpl
+            DO jk = 1, nlay_i
+               CALL tab_2d_1d( npti, nptidx(1:npti), ze_i_2d(1:npti,jk,jl), e_i(:,:,jk,jl) )
+            END DO
+         END DO
+         CALL tab_2d_1d( npti, nptidx(1:npti), qlead_1d  (1:npti) , qlead       )
+         CALL tab_2d_1d( npti, nptidx(1:npti), t_bo_1d   (1:npti) , t_bo        )
+         CALL tab_2d_1d( npti, nptidx(1:npti), sfx_opw_1d(1:npti) , sfx_opw     )
+         CALL tab_2d_1d( npti, nptidx(1:npti), wfx_opw_1d(1:npti) , wfx_opw     )
+         CALL tab_2d_1d( npti, nptidx(1:npti), zh_newice (1:npti) , ht_i_new    )
+         CALL tab_2d_1d( npti, nptidx(1:npti), zvrel_1d  (1:npti) , zvrel       )
+
+         CALL tab_2d_1d( npti, nptidx(1:npti), hfx_thd_1d(1:npti) , hfx_thd     )
+         CALL tab_2d_1d( npti, nptidx(1:npti), hfx_opw_1d(1:npti) , hfx_opw     )
+         CALL tab_2d_1d( npti, nptidx(1:npti), rn_amax_1d(1:npti) , rn_amax_2d  )
+         CALL tab_2d_1d( npti, nptidx(1:npti), sss_1d    (1:npti) , sss_m       )
+
+         !------------------------------------------------------------------------------|
+         ! 2) Convert units for ice internal energy
+         !------------------------------------------------------------------------------|
+         DO jl = 1, jpl
+            DO jk = 1, nlay_i               
+               WHERE( v_i_2d(1:npti,jl) > 0._wp )
+                  ze_i_2d(1:npti,jk,jl) = ze_i_2d(1:npti,jk,jl) / v_i_2d(1:npti,jl) * REAL( nlay_i )
+               ELSEWHERE
+                  ze_i_2d(1:npti,jk,jl) = 0._wp
+               END WHERE
+            END DO
+         END DO
+         !------------------------------------------------------------------------------!
+         ! 5) Compute thickness, salinity, enthalpy, age, area and volume of new ice
+         !------------------------------------------------------------------------------!
+
+         !-----------------------------------------
+         ! Keep old ice areas and volume in memory
+         !-----------------------------------------
+         zv_b(1:npti,:) = v_i_2d(1:npti,:) 
+         za_b(1:npti,:) = a_i_2d(1:npti,:)
+
+         !----------------------
+         ! Salinity of new ice 
+         !----------------------
+         SELECT CASE ( nn_icesal )
+         CASE ( 1 )                    ! Sice = constant 
+            zs_newice(1:npti) = rn_icesal
+         CASE ( 2 )                    ! Sice = F(z,t) [Vancoppenolle et al (2005)]
+            DO ji = 1, npti
+               zs_newice(ji) = MIN(  4.606 + 0.91 / zh_newice(ji) , rn_simax , 0.5 * sss_1d(ji) )
+            END DO
+         CASE ( 3 )                    ! Sice = F(z) [multiyear ice]
+            zs_newice(1:npti) =   2.3
+         END SELECT
+
+         !-------------------------
+         ! Heat content of new ice
+         !-------------------------
+         ! We assume that new ice is formed at the seawater freezing point
+         DO ji = 1, npti
+            ztmelts       = - tmut * zs_newice(ji)                  ! Melting point (C)
+            ze_newice(ji) =   rhoic * (  cpic * ( ztmelts - ( t_bo_1d(ji) - rt0 ) )                     &
+               &                       + lfus * ( 1.0 - ztmelts / MIN( t_bo_1d(ji) - rt0, -epsi10 ) )   &
+               &                       - rcp  *         ztmelts )
+         END DO
+
+         !----------------
+         ! Age of new ice
+         !----------------
+         zo_newice(1:npti) = 0._wp
+
+         !-------------------
+         ! Volume of new ice
+         !-------------------
+         DO ji = 1, npti
+
+            zEi           = - ze_newice(ji) * r1_rhoic             ! specific enthalpy of forming ice [J/kg]
+
+            zEw           = rcp * ( t_bo_1d(ji) - rt0 )            ! specific enthalpy of seawater at t_bo_1d [J/kg]
+                                                                   ! clem: we suppose we are already at the freezing point (condition qlead<0 is satisfyied) 
+                                                                   
+            zdE           = zEi - zEw                              ! specific enthalpy difference [J/kg]
+                                              
+            zfmdt         = - qlead_1d(ji) / zdE                   ! Fm.dt [kg/m2] (<0) 
+                                                                   ! clem: we use qlead instead of zqld (icethd) because we suppose we are at the freezing point   
+            zv_newice(ji) = - zfmdt * r1_rhoic
+
+            zQm           = zfmdt * zEw                            ! heat to the ocean >0 associated with mass flux  
+
+            ! Contribution to heat flux to the ocean [W.m-2], >0  
+            hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * zEw * r1_rdtice
+            ! Total heat flux used in this process [W.m-2]  
+            hfx_opw_1d(ji) = hfx_opw_1d(ji) - zfmdt * zdE * r1_rdtice
+            ! mass flux
+            wfx_opw_1d(ji) = wfx_opw_1d(ji) - zv_newice(ji) * rhoic * r1_rdtice
+            ! salt flux
+            sfx_opw_1d(ji) = sfx_opw_1d(ji) - zv_newice(ji) * rhoic * zs_newice(ji) * r1_rdtice
+         END DO
+         
+         zv_frazb(1:npti) = 0._wp
+         IF( ln_frazil ) THEN
+            ! A fraction zfrazb of frazil ice is accreted at the ice bottom
+            DO ji = 1, npti
+               rswitch       = 1._wp - MAX( 0._wp, SIGN( 1._wp , - at_i_1d(ji) ) )
+               zfrazb        = rswitch * ( TANH( rn_Cfraz * ( zvrel_1d(ji) - rn_vfraz ) ) + 1.0 ) * 0.5 * rn_maxfraz
+               zv_frazb(ji)  =         zfrazb   * zv_newice(ji)
+               zv_newice(ji) = ( 1.0 - zfrazb ) * zv_newice(ji)
+            END DO
+         END IF
+         
+         !-----------------
+         ! Area of new ice
+         !-----------------
+         DO ji = 1, npti
+            za_newice(ji) = zv_newice(ji) / zh_newice(ji)
+         END DO
+
+         !------------------------------------------------------------------------------!
+         ! 6) Redistribute new ice area and volume into ice categories                  !
+         !------------------------------------------------------------------------------!
+
+         !------------------------
+         ! 6.1) lateral ice growth
+         !------------------------
+         ! If lateral ice growth gives an ice concentration gt 1, then
+         ! we keep the excessive volume in memory and attribute it later to bottom accretion
+         DO ji = 1, npti
+            IF ( za_newice(ji) >  ( rn_amax_1d(ji) - at_i_1d(ji) ) ) THEN
+               zda_res(ji)   = za_newice(ji) - ( rn_amax_1d(ji) - at_i_1d(ji) )
+               zdv_res(ji)   = zda_res  (ji) * zh_newice(ji) 
+               za_newice(ji) = za_newice(ji) - zda_res  (ji)
+               zv_newice(ji) = zv_newice(ji) - zdv_res  (ji)
+            ELSE
+               zda_res(ji) = 0._wp
+               zdv_res(ji) = 0._wp
+            ENDIF
+         END DO
+
+         ! find which category to fill
+         DO jl = 1, jpl
+            DO ji = 1, npti
+               IF( zh_newice(ji) > hi_max(jl-1) .AND. zh_newice(ji) <= hi_max(jl) ) THEN
+                  a_i_2d(ji,jl) = a_i_2d(ji,jl) + za_newice(ji)
+                  v_i_2d(ji,jl) = v_i_2d(ji,jl) + zv_newice(ji)
+                  jcat(ji) = jl
+               ENDIF
+            END DO
+         END DO
+         at_i_1d(1:npti) = SUM( a_i_2d(1:npti,:), dim=2 )
+
+         ! Heat content
+         DO ji = 1, npti
+            jl = jcat(ji)                                                    ! categroy in which new ice is put
+            zswinew  (ji) = MAX( 0._wp , SIGN( 1._wp , - za_b(ji,jl) ) )   ! 0 if old ice
+         END DO
+
+         DO jk = 1, nlay_i
+            DO ji = 1, npti
+               jl = jcat(ji)
+               rswitch = MAX( 0._wp, SIGN( 1._wp , v_i_2d(ji,jl) - epsi20 ) )
+               ze_i_2d(ji,jk,jl) = zswinew(ji)   *   ze_newice(ji) +                                                    &
+                  &        ( 1.0 - zswinew(ji) ) * ( ze_newice(ji) * zv_newice(ji) + ze_i_2d(ji,jk,jl) * zv_b(ji,jl) )  &
+                  &        * rswitch / MAX( v_i_2d(ji,jl), epsi20 )
+            END DO
+         END DO
+
+         !------------------------------------------------
+         ! 6.2) bottom ice growth + ice enthalpy remapping
+         !------------------------------------------------
+         DO jl = 1, jpl
+
+            ! for remapping
+            h_i_old (1:npti,0:nlay_i+1) = 0._wp
+            eh_i_old(1:npti,0:nlay_i+1) = 0._wp
+            DO jk = 1, nlay_i
+               DO ji = 1, npti
+                  h_i_old (ji,jk) = v_i_2d(ji,jl) * r1_nlay_i
+                  eh_i_old(ji,jk) = ze_i_2d(ji,jk,jl) * h_i_old(ji,jk)
+               END DO
+            END DO
+
+            ! new volumes including lateral/bottom accretion + residual
+            DO ji = 1, npti
+               rswitch        = MAX( 0._wp, SIGN( 1._wp , at_i_1d(ji) - epsi20 ) )
+               zv_newfra     = rswitch * ( zdv_res(ji) + zv_frazb(ji) ) * a_i_2d(ji,jl) / MAX( at_i_1d(ji) , epsi20 )
+               a_i_2d(ji,jl) = rswitch * a_i_2d(ji,jl)               
+               v_i_2d(ji,jl) = v_i_2d(ji,jl) + zv_newfra
+               ! for remapping
+               h_i_old (ji,nlay_i+1) = zv_newfra
+               eh_i_old(ji,nlay_i+1) = ze_newice(ji) * zv_newfra
+            ENDDO
+            ! --- Ice enthalpy remapping --- !
+            CALL ice_thd_ent( ze_i_2d(1:npti,:,jl) ) 
+         ENDDO
+
+         !-----------------
+         ! Update salinity
+         !-----------------
+         DO jl = 1, jpl
+            DO ji = 1, npti
+               sv_i_2d(ji,jl) = sv_i_2d(ji,jl) + zs_newice(ji) * ( v_i_2d(ji,jl) - zv_b(ji,jl) )
+            END DO
+         END DO
+
+         !------------------------------------------------------------------------------!
+         ! 8) Change units for e_i
+         !------------------------------------------------------------------------------!    
+         DO jl = 1, jpl
+            DO jk = 1, nlay_i
+               ze_i_2d(1:npti,jk,jl) = ze_i_2d(1:npti,jk,jl) * v_i_2d(1:npti,jl) * r1_nlay_i 
+            END DO
+         END DO
+         !------------------------------------------------------------------------------!
+         ! 7) Change 2D vectors to 1D vectors 
+         !------------------------------------------------------------------------------!
+         CALL tab_2d_3d( npti, nptidx(1:npti), a_i_2d (1:npti,1:jpl), a_i (:,:,:) )
+         CALL tab_2d_3d( npti, nptidx(1:npti), v_i_2d (1:npti,1:jpl), v_i (:,:,:) )
+         CALL tab_2d_3d( npti, nptidx(1:npti), sv_i_2d(1:npti,1:jpl), sv_i(:,:,:) )
+          DO jl = 1, jpl
+            DO jk = 1, nlay_i
+               CALL tab_1d_2d( npti, nptidx(1:npti), ze_i_2d(1:npti,jk,jl), e_i(:,:,jk,jl) )
+            END DO
+         END DO
+         CALL tab_1d_2d( npti, nptidx(1:npti), sfx_opw_1d(1:npti), sfx_opw )
+         CALL tab_1d_2d( npti, nptidx(1:npti), wfx_opw_1d(1:npti), wfx_opw )
+         CALL tab_1d_2d( npti, nptidx(1:npti), hfx_thd_1d(1:npti), hfx_thd )
+         CALL tab_1d_2d( npti, nptidx(1:npti), hfx_opw_1d(1:npti), hfx_opw )
+         !
+      ENDIF ! npti > 0
+      !
+      IF( ln_icediachk )   CALL ice_cons_hsm(1, 'icethd_do', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft)
+      !
+   END SUBROUTINE ice_thd_do
+
+   SUBROUTINE ice_thd_do_init
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_thd_do_init *** 
+      !!                 
+      !! ** Purpose :   Physical constants and parameters associated with
+      !!                ice growth in the leads
+      !!
+      !! ** Method  :   Read the namthd_do namelist and check the parameters
+      !!                called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namthd_do
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ios   ! Local integer output status for namelist read
+      !!
+      NAMELIST/namthd_do/ rn_hinew, ln_frazil, rn_maxfraz, rn_vfraz, rn_Cfraz
+      !!-------------------------------------------------------------------
+      !
+      REWIND( numnam_ice_ref )              ! Namelist namthd_do in reference namelist : Ice thermodynamics
+      READ  ( numnam_ice_ref, namthd_do, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namthd_do in reference namelist', lwp )
+
+      REWIND( numnam_ice_cfg )              ! Namelist namthd_do in configuration namelist : Ice thermodynamics
+      READ  ( numnam_ice_cfg, namthd_do, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namthd_do in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namthd_do )
+      !
+      !
+      IF(lwp) THEN                          ! control print
+         WRITE(numout,*) 'ice_thd_do_init: Ice growth in open water'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namthd_do:'
+         WRITE(numout,*) '      ice thickness for lateral accretion                       rn_hinew   = ', rn_hinew
+         WRITE(numout,*) '      Frazil ice thickness as a function of wind or not         ln_frazil  = ', ln_frazil
+         WRITE(numout,*) '      Maximum proportion of frazil ice collecting at bottom     rn_maxfraz = ', rn_maxfraz
+         WRITE(numout,*) '      Threshold relative drift speed for collection of frazil   rn_vfraz   = ', rn_vfraz
+         WRITE(numout,*) '      Squeezing coefficient for collection of frazil            rn_Cfraz   = ', rn_Cfraz
+      ENDIF
+      !
+      IF ( rn_hinew < rn_himin )   CALL ctl_stop( 'ice_thd_do_init : rn_hinew should be >= rn_himin' )
+      !
+   END SUBROUTINE ice_thd_do_init
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icethd_do
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_ent.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_ent.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_ent.F90	(revision 9019)
@@ -0,0 +1,146 @@
+MODULE icethd_ent
+   !!======================================================================
+   !!                       ***  MODULE icethd_ent   ***
+   !!   sea-ice: redistribution of enthalpy in the ice on the new vertical grid
+   !!                       after vertical growth/melt
+   !!======================================================================
+   !! History :  LIM  ! 2003-05 (M. Vancoppenolle) Original code in 1D
+   !!                 ! 2005-07 (M. Vancoppenolle) 3D version 
+   !!                 ! 2006-11 (X. Fettweis) Vectorized 
+   !!            3.0  ! 2008-03 (M. Vancoppenolle) Energy conservation and clean code
+   !!            3.4  ! 2011-02 (G. Madec) dynamical allocation
+   !!             -   ! 2014-05 (C. Rousset) complete rewriting
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_thd_ent   : ice redistribution of enthalpy
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! domain variables
+   USE domain         !
+   USE phycst         ! physical constants
+   USE ice            ! sea-ice: variables
+   USE ice1D          ! sea-ice: thermodynamics variables
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_thd_ent         ! called by icethd and icethd_do
+
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icethd_ent.F90 8420 2017-08-08 12:18:46Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+ 
+   SUBROUTINE ice_thd_ent( qnew )
+      !!-------------------------------------------------------------------
+      !!               ***   ROUTINE ice_thd_ent  ***
+      !!
+      !! ** Purpose :
+      !!           This routine computes new vertical grids in the ice, 
+      !!           and consistently redistributes temperatures. 
+      !!           Redistribution is made so as to ensure to energy conservation
+      !!
+      !!
+      !! ** Method  : linear conservative remapping
+      !!           
+      !! ** Steps : 1) cumulative integrals of old enthalpies/thicknesses
+      !!            2) linear remapping on the new layers
+      !!
+      !! ------------ cum0(0)                        ------------- cum1(0)
+      !!                                    NEW      -------------
+      !! ------------ cum0(1)               ==>      -------------
+      !!     ...                                     -------------
+      !! ------------                                -------------
+      !! ------------ cum0(nlay_i+2)                 ------------- cum1(nlay_i)
+      !!
+      !!
+      !! References : Bitz & Lipscomb, JGR 99; Vancoppenolle et al., GRL, 2005
+      !!-------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   qnew             ! new enthlapies (J.m-3, remapped)
+      !
+      INTEGER  :: ji         !  dummy loop indices
+      INTEGER  :: jk0, jk1   !  old/new layer indices
+      !
+      REAL(wp), DIMENSION(jpij,0:nlay_i+2) ::   zeh_cum0, zh_cum0   ! old cumulative enthlapies and layers interfaces
+      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   zeh_cum1, zh_cum1   ! new cumulative enthlapies and layers interfaces
+      REAL(wp), DIMENSION(jpij)            ::   zhnew               ! new layers thicknesses
+      !!-------------------------------------------------------------------
+
+      !--------------------------------------------------------------------------
+      !  1) Cumulative integral of old enthalpy * thickness and layers interfaces
+      !--------------------------------------------------------------------------
+      zeh_cum0(1:npti,0) = 0._wp 
+      zh_cum0 (1:npti,0) = 0._wp
+      DO jk0 = 1, nlay_i+2
+         DO ji = 1, npti
+            zeh_cum0(ji,jk0) = zeh_cum0(ji,jk0-1) + eh_i_old(ji,jk0-1)
+            zh_cum0 (ji,jk0) = zh_cum0 (ji,jk0-1) + h_i_old (ji,jk0-1)
+         END DO
+      END DO
+
+      !------------------------------------
+      !  2) Interpolation on the new layers
+      !------------------------------------
+      ! new layer thickesses
+      DO ji = 1, npti
+         zhnew(ji) = SUM( h_i_old(ji,0:nlay_i+1) ) * r1_nlay_i  
+      END DO
+
+      ! new layers interfaces
+      zh_cum1(1:npti,0) = 0._wp
+      DO jk1 = 1, nlay_i
+         DO ji = 1, npti
+            zh_cum1(ji,jk1) = zh_cum1(ji,jk1-1) + zhnew(ji)
+         END DO
+      END DO
+
+      zeh_cum1(1:npti,0) = 0._wp 
+      ! new cumulative q*h => linear interpolation
+      DO jk0 = 1, nlay_i+1
+         DO jk1 = 1, nlay_i-1
+            DO ji = 1, npti
+               IF( zh_cum1(ji,jk1) <= zh_cum0(ji,jk0) .AND. zh_cum1(ji,jk1) > zh_cum0(ji,jk0-1) ) THEN
+                  zeh_cum1(ji,jk1) = ( zeh_cum0(ji,jk0-1) * ( zh_cum0(ji,jk0) - zh_cum1(ji,jk1  ) ) +  &
+                     &                 zeh_cum0(ji,jk0  ) * ( zh_cum1(ji,jk1) - zh_cum0(ji,jk0-1) ) )  &
+                     &             / ( zh_cum0(ji,jk0) - zh_cum0(ji,jk0-1) )
+               ENDIF
+            END DO
+         END DO
+      END DO
+      ! to ensure that total heat content is strictly conserved, set:
+      zeh_cum1(1:npti,nlay_i) = zeh_cum0(1:npti,nlay_i+2) 
+
+      ! new enthalpies
+      DO jk1 = 1, nlay_i
+         DO ji = 1, npti
+            rswitch      = MAX( 0._wp , SIGN( 1._wp , zhnew(ji) - epsi20 ) ) 
+            qnew(ji,jk1) = rswitch * ( zeh_cum1(ji,jk1) - zeh_cum1(ji,jk1-1) ) / MAX( zhnew(ji), epsi20 )
+         END DO
+      END DO
+
+      ! --- diag error on heat remapping --- !
+      ! comment: if input h_i_old and eh_i_old are already multiplied by a_i (as in icethd_do), 
+      ! then we should not (* a_i) again but not important since this is just to check that remap error is ~0
+      DO ji = 1, npti
+         hfx_err_rem_1d(ji) = hfx_err_rem_1d(ji) + a_i_1d(ji) * r1_rdtice *  &
+            &               ( SUM( qnew(ji,1:nlay_i) ) * zhnew(ji) - SUM( eh_i_old(ji,0:nlay_i+1) ) ) 
+      END DO
+      
+   END SUBROUTINE ice_thd_ent
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icethd_ent
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_pnd.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_pnd.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_pnd.F90	(revision 9019)
@@ -0,0 +1,262 @@
+MODULE icethd_pnd 
+   !!======================================================================
+   !!                     ***  MODULE  icethd_pnd   ***
+   !!   Melt ponds
+   !!======================================================================
+   !! history :       ! Original code by Daniela Flocco and Adrian Turner
+   !!            1.0  ! 2012    (O. Lecomte) Adaptation for scientific tests (NEMO3.1)
+   !!            2.0  ! 2017    (M. Vancoppenolle, O. Lecomte, C. Rousset) Implementation in NEMO4
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3' :                                     ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_thd_pnd_init      : some initialization and namelist read
+   !!   ice_thd_pnd           : main calling routine
+   !!----------------------------------------------------------------------
+   USE phycst         ! physical constants
+   USE dom_oce        ! ocean space and time domain
+   USE ice            ! sea-ice: variables
+   USE ice1D          ! sea-ice: thermodynamics variables
+   USE icetab         ! sea-ice: 1D <==> 2D transformation
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE timing         ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_thd_pnd_init    ! routine called by icestp.F90
+   PUBLIC   ice_thd_pnd         ! routine called by icestp.F90
+
+   INTEGER ::              nice_pnd   ! choice of the type of pond scheme
+   !                                               ! associated indices:
+   INTEGER, PARAMETER ::   np_pndNO  = 0   ! No pond scheme
+   INTEGER, PARAMETER ::   np_pndCST = 1   ! Constant pond scheme
+   INTEGER, PARAMETER ::   np_pndH12 = 2   ! Evolutive pond scheme (Holland et al. 2012)
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icethd_pnd.F90 8420 2017-10-05 13:07:10Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_thd_pnd
+      !!-------------------------------------------------------------------
+      !!               ***  ROUTINE ice_thd_pnd   ***
+      !!               
+      !! ** Purpose :   change melt pond fraction
+      !!                
+      !! ** Method  :   brut force
+      !!
+      !! ** Action  : - 
+      !!              - 
+      !!-------------------------------------------------------------------
+
+      SELECT CASE ( nice_pnd )
+
+      CASE (np_pndCST)
+         !                             !-------------------------------!
+         CALL pnd_CST                  ! Constant melt ponds           !
+         !                             !-------------------------------!
+      CASE (np_pndH12)
+         !                             !-------------------------------!
+         CALL pnd_H12                  ! Holland et al 2012 melt ponds !
+         !                             !-------------------------------!
+      END SELECT
+
+   END SUBROUTINE ice_thd_pnd 
+
+   SUBROUTINE pnd_CST 
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE pnd_CST  ***
+      !!
+      !! ** Purpose    : Compute melt pond evolution
+      !!
+      !! ** Method     : Melt pond fraction and thickness are prescribed 
+      !!                 to non-zero values when t_su = 0C
+      !!
+      !! ** Tunable parameters : pond fraction (rn_apnd), pond depth (rn_hpnd)
+      !!                
+      !! ** Note       : Coupling with such melt ponds is only radiative
+      !!                 Advection, ridging, rafting... are bypassed
+      !!
+      !! ** References : Bush, G.W., and Trump, D.J. (2017)
+      !!    
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ji        ! loop indices
+      !!-------------------------------------------------------------------
+      DO ji = 1, npti
+         
+         IF( a_i_1d(ji) > 0._wp .AND. t_su_1d(ji) >= rt0 ) THEN
+            a_ip_frac_1d(ji) = rn_apnd
+            h_ip_1d(ji)      = rn_hpnd    
+            a_ip_1d(ji)      = a_ip_frac_1d(ji) * a_i_1d(ji)
+         ELSE
+            a_ip_frac_1d(ji) = 0._wp
+            h_ip_1d(ji)      = 0._wp    
+            a_ip_1d(ji)      = 0._wp
+         ENDIF
+         
+      END DO
+      
+   END SUBROUTINE pnd_CST
+
+   SUBROUTINE pnd_H12
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE pnd_H12  ***
+      !!
+      !! ** Purpose    : Compute melt pond evolution
+      !!
+      !! ** Method     : Empirical method. A fraction of meltwater is accumulated in ponds 
+      !!                 and sent to ocean when surface is freezing
+      !!
+      !!                 pond growth:      Vp = Vp + dVmelt
+      !!                    with dVmelt = R/rhow * ( rhoi*dh_i + rhos*dh_s ) * a_i
+      !!                 pond contraction: Vp = Vp * exp(0.01*MAX(Tp-Tsu,0)/Tp)
+      !!                    with Tp = -2degC
+      !!  
+      !! ** Tunable parameters : (no real expertise yet, ideas?)
+      !! 
+      !! ** Note       : Stolen from CICE for quick test of the melt pond
+      !!                 radiation and freshwater interfaces
+      !!                 Coupling can be radiative AND freshwater
+      !!                 Advection, ridging, rafting are called
+      !!
+      !! ** References : Holland, M. M. et al (J Clim 2012)
+      !!    
+      !!-------------------------------------------------------------------
+      REAL(wp), PARAMETER ::   zrmin       = 0.15_wp  ! minimum fraction of available meltwater retained for melt ponding
+      REAL(wp), PARAMETER ::   zrmax       = 0.70_wp  ! maximum   ''           ''       ''        ''            ''
+      REAL(wp), PARAMETER ::   zpnd_aspect = 0.8_wp   ! pond aspect ratio
+      REAL(wp), PARAMETER ::   zTp         = -2._wp   ! reference temperature
+
+      REAL(wp) ::   zfr_mlt          ! fraction of available meltwater retained for melt ponding
+      REAL(wp) ::   zdv_mlt          ! available meltwater for melt ponding
+      REAL(wp) ::   z1_Tp            ! inverse reference temperature
+      REAL(wp) ::   z1_rhofw         ! inverse freshwater density
+      REAL(wp) ::   z1_zpnd_aspect   ! inverse pond aspect ratio
+      REAL(wp) ::   zfac, zdum
+
+      INTEGER  ::   ji   ! loop indices
+      !!-------------------------------------------------------------------
+      z1_rhofw       = 1. / rhofw 
+      z1_zpnd_aspect = 1. / zpnd_aspect
+      z1_Tp          = 1._wp / zTp 
+
+      DO ji = 1, npti
+         !                                                        !--------------------------------!
+         IF( h_i_1d(ji) < rn_himin) THEN                          ! Case ice thickness < rn_himin  !
+            !                                                     !--------------------------------!
+            !--- Remove ponds on thin ice
+            a_ip_1d(ji)      = 0._wp
+            a_ip_frac_1d(ji) = 0._wp
+            h_ip_1d(ji)      = 0._wp
+            !                                                     !--------------------------------!
+         ELSE                                                     ! Case ice thickness >= rn_himin !
+            !                                                     !--------------------------------!
+            v_ip_1d(ji) = h_ip_1d(ji) * a_ip_1d(ji)   ! record pond volume at previous time step
+
+            ! available meltwater for melt ponding [m, >0] and fraction
+            zdv_mlt = -( dh_i_surf(ji)*rhoic + dh_s_mlt(ji)*rhosn ) * z1_rhofw * a_i_1d(ji)
+            zfr_mlt = zrmin + ( zrmax - zrmin ) * a_i_1d(ji)  ! from CICE doc
+            !zfr_mlt = zrmin + zrmax * a_i_1d(ji)             ! from Holland paper 
+
+            !--- Pond gowth ---!
+            ! v_ip should never be negative, otherwise code crashes
+            ! MV: as far as I saw, UM5 can create very small negative v_ip values (not Prather)
+            v_ip_1d(ji) = MAX( 0._wp, v_ip_1d(ji) + zfr_mlt * zdv_mlt )
+
+            ! melt pond mass flux (<0)
+            IF( ln_pnd_fwb .AND. zdv_mlt > 0._wp ) THEN
+               zfac = zfr_mlt * zdv_mlt * rhofw * r1_rdtice
+               wfx_pnd_1d(ji) = wfx_pnd_1d(ji) - zfac
+
+               ! adjust ice/snow melting flux to balance melt pond flux (>0)
+               zdum = zfac / ( wfx_snw_sum_1d(ji) + wfx_sum_1d(ji) )
+               wfx_snw_sum_1d(ji) = wfx_snw_sum_1d(ji) * (1._wp + zdum)
+               wfx_sum_1d(ji)     = wfx_sum_1d(ji)     * (1._wp + zdum)
+            ENDIF
+
+            !--- Pond contraction (due to refreezing) ---!
+            v_ip_1d(ji) = v_ip_1d(ji) * EXP( 0.01_wp * MAX( zTp+rt0 - t_su_1d(ji), 0._wp ) * z1_Tp )
+
+            ! Set new pond area and depth assuming linear relation between h_ip and a_ip_frac
+            !    h_ip = zpnd_aspect * a_ip_frac = zpnd_aspect * a_ip/a_i
+            a_ip_1d(ji)      = SQRT( v_ip_1d(ji) * z1_zpnd_aspect * a_i_1d(ji) )
+            a_ip_frac_1d(ji) = a_ip_1d(ji) / a_i_1d(ji)
+            h_ip_1d(ji)      = zpnd_aspect * a_ip_frac_1d(ji)
+
+         ENDIF
+      END DO
+
+   END SUBROUTINE pnd_H12
+
+   SUBROUTINE ice_thd_pnd_init 
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_thd_pnd_init   ***
+      !!
+      !! ** Purpose : Physical constants and parameters linked to melt ponds
+      !!              over sea ice
+      !!
+      !! ** Method  :  Read the namthd_pnd  namelist and check the melt pond  
+      !!               parameter values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namthd_pnd  
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ios, ioptio                 ! Local integer output status for namelist read
+      NAMELIST/namthd_pnd/  ln_pnd_H12, ln_pnd_fwb, ln_pnd_CST, rn_apnd, rn_hpnd, ln_pnd_alb
+      !!-------------------------------------------------------------------
+
+      REWIND( numnam_ice_ref )              ! Namelist namthd_pnd  in reference namelist : Melt Ponds  
+      READ  ( numnam_ice_ref, namthd_pnd, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namthd_pnd  in reference namelist', lwp )
+
+      REWIND( numnam_ice_cfg )              ! Namelist namthd_pnd  in configuration namelist : Melt Ponds
+      READ  ( numnam_ice_cfg, namthd_pnd, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namthd_pnd in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namthd_pnd )
+      
+      IF(lwp) THEN                        ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_thd_pnd_init: ice parameters for melt ponds'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namicethd_pnd:'
+         WRITE(numout,*) '      Evolutive melt pond fraction and depth (Holland et al 2012)  ln_pnd_H12 = ', ln_pnd_H12
+         WRITE(numout,*) '         Melt ponds store fresh water or not                       ln_pnd_fwb = ', ln_pnd_fwb
+         WRITE(numout,*) '      Prescribed melt pond fraction and depth                      ln_pnd_Cst = ', ln_pnd_CST
+         WRITE(numout,*) '         Prescribed pond fraction                                  rn_apnd    = ', rn_apnd
+         WRITE(numout,*) '         Prescribed pond depth                                     rn_hpnd    = ', rn_hpnd
+         WRITE(numout,*) '      Melt ponds affect albedo or not                              ln_pnd_alb = ', ln_pnd_alb
+      ENDIF
+      !
+      !                             !== set the choice of ice pond scheme ==!
+      ioptio = 0
+                                                            nice_pnd = np_pndNO
+      IF( ln_pnd_CST ) THEN   ;   ioptio = ioptio + 1   ;   nice_pnd = np_pndCST    ;   ENDIF
+      IF( ln_pnd_H12 ) THEN   ;   ioptio = ioptio + 1   ;   nice_pnd = np_pndH12    ;   ENDIF
+      IF( ioptio > 1 )   CALL ctl_stop( 'ice_thd_pnd_init: choose one and only one pond scheme (ln_pnd_H12 or ln_pnd_CST)' )
+
+      SELECT CASE( nice_pnd )
+      CASE( np_pndNO )         
+         IF(ln_pnd_fwb) THEN ; ln_pnd_fwb = .FALSE. ; CALL ctl_warn( 'ln_pnd_fwb=false when no ponds' ) ; ENDIF
+         IF(ln_pnd_alb) THEN ; ln_pnd_alb = .FALSE. ; CALL ctl_warn( 'ln_pnd_alb=false when no ponds' ) ; ENDIF
+      CASE( np_pndCST)
+         IF(ln_pnd_fwb) THEN ; ln_pnd_fwb = .FALSE. ; CALL ctl_warn( 'ln_pnd_fwb=false when ln_pnd_CST=true' ) ; ENDIF
+      END SELECT
+      !
+   END SUBROUTINE ice_thd_pnd_init
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option          Empty module          NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif 
+
+   !!======================================================================
+END MODULE icethd_pnd 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_sal.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_sal.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_sal.F90	(revision 9019)
@@ -0,0 +1,166 @@
+MODULE icethd_sal
+   !!======================================================================
+   !!                       ***  MODULE icethd_sal ***
+   !!   sea-ice : computation of salinity variations in the ice
+   !!======================================================================
+   !! History :   -   ! 2003-05 (M. Vancoppenolle) UCL-ASTR first coding for LIM3-1D
+   !!            3.0  ! 2005-12 (M. Vancoppenolle) adapted to the 3-D version
+   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!---------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_thd_sal        : salinity variations in the ice
+   !!   ice_thd_sal_init   : initialization
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE ice            ! sea-ice: variables
+   USE ice1D          ! sea-ice: thermodynamics variables
+   USE icevar         ! sea-ice: operations
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_thd_sal        ! called by icethd
+   PUBLIC   ice_thd_sal_init   ! called by ice_init
+   
+   ! ** namelist (namthd_sal) **
+   REAL(wp) ::   rn_sal_gd        ! restoring salinity for gravity drainage [PSU]
+   REAL(wp) ::   rn_time_gd       ! restoring time constant for gravity drainage (= 20 days) [s]
+   REAL(wp) ::   rn_sal_fl        ! restoring salinity for flushing [PSU]
+   REAL(wp) ::   rn_time_fl       ! restoring time constant for gravity drainage (= 10 days) [s]
+
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icethd_sal.F90 8420 2017-08-08 12:18:46Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_thd_sal( ld_sal )
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_thd_sal  ***    
+      !!   
+      !! ** Purpose :   computes new salinities in the ice
+      !!
+      !! ** Method  :  3 possibilities
+      !!               -> nn_icesal = 1 -> Sice = cst    [ice salinity constant in both time & space] 
+      !!               -> nn_icesal = 2 -> Sice = S(z,t) [Vancoppenolle et al. 2005]
+      !!               -> nn_icesal = 3 -> Sice = S(z)   [multiyear ice]
+      !!---------------------------------------------------------------------
+      LOGICAL, INTENT(in) ::   ld_sal            ! gravity drainage and flushing or not 
+      INTEGER  ::   ji, jk                       ! dummy loop indices 
+      REAL(wp) ::   iflush, igravdr              ! local scalars
+      REAL(wp) ::   zs_sni, zs_i_gd, zs_i_fl, zs_i_si, zs_i_bg   ! local scalars
+      REAL(wp) ::   z1_time_gd, z1_time_fl
+      !!---------------------------------------------------------------------
+
+      SELECT CASE ( nn_icesal )
+      !
+      !               !---------------------------------------------!
+      CASE( 2 )       !  time varying salinity with linear profile  !
+      !               !---------------------------------------------!
+         z1_time_gd = 1._wp / rn_time_gd * rdt_ice
+         z1_time_fl = 1._wp / rn_time_fl * rdt_ice
+         !
+         DO ji = 1, npti
+
+            !---------------------------------------------------------
+            !  Update ice salinity from snow-ice and bottom growth
+            !---------------------------------------------------------
+            IF( h_i_1d(ji) > 0._wp ) THEN
+               zs_sni   = sss_1d(ji) * ( rhoic - rhosn ) * r1_rhoic                                 ! Salinity of snow ice
+               zs_i_si = ( zs_sni      - s_i_1d(ji) ) *             dh_snowice(ji)  / h_i_1d(ji) ! snow-ice    
+               zs_i_bg = ( s_i_new(ji) - s_i_1d(ji) ) * MAX( 0._wp, dh_i_bott(ji) ) / h_i_1d(ji) ! bottom growth
+               ! Update salinity (nb: salt flux already included in icethd_dh)
+               s_i_1d(ji) = s_i_1d(ji) + zs_i_bg + zs_i_si
+            ENDIF
+
+            IF( ld_sal ) THEN
+               !---------------------------------------------------------
+               !  Update ice salinity from brine drainage and flushing
+               !---------------------------------------------------------
+               iflush   = MAX( 0._wp , SIGN( 1._wp , t_su_1d(ji) - rt0         ) )  ! =1 if summer 
+               igravdr  = MAX( 0._wp , SIGN( 1._wp , t_bo_1d(ji) - t_su_1d(ji) ) )  ! =1 if t_su < t_bo
+
+               zs_i_gd = - igravdr * MAX( s_i_1d(ji) - rn_sal_gd , 0._wp ) * z1_time_gd  ! gravity drainage 
+               zs_i_fl = - iflush  * MAX( s_i_1d(ji) - rn_sal_fl , 0._wp ) * z1_time_fl  ! flushing
+               
+               ! Update salinity   
+               s_i_1d(ji) = s_i_1d(ji) + zs_i_fl + zs_i_gd
+               
+               ! Salt flux
+               sfx_bri_1d(ji) = sfx_bri_1d(ji) - rhoic * a_i_1d(ji) * h_i_1d(ji) * ( zs_i_fl + zs_i_gd ) * r1_rdtice
+            ENDIF
+         END DO
+
+         ! Salinity profile
+         CALL ice_var_salprof1d
+         !
+      !         !---------------------------------------------!
+      CASE( 3 ) ! constant salinity with a fixed profile      ! (Schwarzacher (1959) multiyear salinity profile(mean = 2.30)
+      !         !---------------------------------------------!
+         CALL ice_var_salprof1d
+      !
+   END SELECT
+   !
+   END SUBROUTINE ice_thd_sal
+
+
+   SUBROUTINE ice_thd_sal_init
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_thd_sal_init  ***
+      !!
+      !! ** Purpose :   initialization of ice salinity parameters
+      !!
+      !! ** Method  :   Read the namthd_sal namelist and check the parameter
+      !!                values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namthd_sal
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ios                 ! Local integer output status for namelist read
+      !!
+      NAMELIST/namthd_sal/ nn_icesal, rn_icesal, rn_sal_gd, rn_time_gd,   &
+         &                 rn_sal_fl, rn_time_fl, rn_simax , rn_simin 
+      !!-------------------------------------------------------------------
+      !
+      REWIND( numnam_ice_ref )              ! Namelist namthd_sal in reference namelist : Ice salinity
+      READ  ( numnam_ice_ref, namthd_sal, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namthd_sal in reference namelist', lwp )
+      !
+      REWIND( numnam_ice_cfg )              ! Namelist namthd_sal in configuration namelist : Ice salinity
+      READ  ( numnam_ice_cfg, namthd_sal, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namthd_sal in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namthd_sal )
+      !
+      IF(lwp) THEN                           ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_thd_sal_init : Ice parameters for salinity '
+         WRITE(numout,*) '~~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namthd_sal:'
+         WRITE(numout,*) '      switch for salinity                                     nn_icesal  = ', nn_icesal
+         WRITE(numout,*) '      bulk salinity value if nn_icesal = 1                    rn_icesal  = ', rn_icesal
+         WRITE(numout,*) '      restoring salinity for gravity drainage                 rn_sal_gd  = ', rn_sal_gd
+         WRITE(numout,*) '      restoring time for for gravity drainage                 rn_time_gd = ', rn_time_gd
+         WRITE(numout,*) '      restoring salinity for flushing                         rn_sal_fl  = ', rn_sal_fl
+         WRITE(numout,*) '      restoring time for flushing                             rn_time_fl = ', rn_time_fl
+         WRITE(numout,*) '      Maximum tolerated ice salinity                          rn_simax   = ', rn_simax
+         WRITE(numout,*) '      Minimum tolerated ice salinity                          rn_simin   = ', rn_simin
+      ENDIF
+      !
+   END SUBROUTINE ice_thd_sal_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Dummy Module           No ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icethd_sal
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_zdf.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_zdf.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_zdf.F90	(revision 9019)
@@ -0,0 +1,139 @@
+MODULE icethd_zdf
+   !!======================================================================
+   !!                       ***  MODULE icethd_zdf ***
+   !!   sea-ice: vertical heat diffusion in sea ice (computation of temperatures) 
+   !!======================================================================
+   !! History :  LIM  ! 02-2003 (M. Vancoppenolle) original 1D code
+   !!                 ! 06-2005 (M. Vancoppenolle) 3d version
+   !!                 ! 11-2006 (X Fettweis) Vectorization by Xavier
+   !!                 ! 04-2007 (M. Vancoppenolle) Energy conservation
+   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!             -   ! 2012-05 (C. Rousset) add penetration solar flux
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!  ice_thd_zdf      : select the appropriate routine for vertical heat diffusion calculation
+   !!  ice_thd_zdf_BL99 : 
+   !!  ice_thd_zdf_init :
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants (ocean directory) 
+   USE ice             ! sea-ice: variables
+   USE icethd_zdf_BL99 ! sea-ice: vertical diffusion (Bitz and Lipscomb, 1999) 
+   !
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! MPP library
+   USE lib_fortran     ! fortran utilities (glob_sum + no signed zero)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_thd_zdf        ! called by icethd
+   PUBLIC   ice_thd_zdf_init   ! called by icestp
+
+   INTEGER ::   nice_zdf       ! Choice of the type of vertical heat diffusion formulation
+   !                                 ! associated indices:
+   INTEGER, PARAMETER ::   np_BL99 = 1   ! Bitz and Lipscomb (1999)
+!! INTEGER, PARAMETER ::   np_XXXX = 2
+
+   !!** namelist (namthd_zdf) **
+   LOGICAL ::   ln_zdf_BL99    ! Heat diffusion follows Bitz and Lipscomb (1999)
+
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icethd_zdf.F90 8420 2017-08-08 12:18:46Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_thd_zdf
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_thd_zdf  ***
+      !!
+      !! ** Purpose :   select the appropriate routine for the computation
+      !!              of vertical diffusion
+      !!-------------------------------------------------------------------
+   
+      SELECT CASE ( nice_zdf )      ! Choose the vertical heat diffusion solver
+      !
+      !                             !-------------!      
+      CASE( np_BL99 )               ! BL99 solver !
+         !                          !-------------!
+         SELECT CASE( nice_jules )
+         !                         ! No Jules coupler ==> default option
+         CASE( np_jules_OFF    )   ;   CALL ice_thd_zdf_BL99 ( np_jules_OFF    )
+         !
+         !                         ! Jules coupler is emulated => 1st call to get the needed fields (conduction...)
+         !                                                        2nd call to use these fields to calculate heat diffusion   
+         CASE( np_jules_EMULE  )   ;   CALL ice_thd_zdf_BL99 ( np_jules_EMULE  )
+                                       CALL ice_thd_zdf_BL99 ( np_jules_ACTIVE )
+         !
+         !                         ! Jules coupler is active ==> Met Office default option
+         CASE( np_jules_ACTIVE )   ;   CALL ice_thd_zdf_BL99 ( np_jules_ACTIVE )
+         !
+         END SELECT
+         !
+      END SELECT
+      
+   END SUBROUTINE ice_thd_zdf
+   
+   
+   SUBROUTINE ice_thd_zdf_init
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_thd_zdf_init *** 
+      !!                 
+      !! ** Purpose :   Physical constants and parameters associated with
+      !!                ice thermodynamics
+      !!
+      !! ** Method  :   Read the namthd_zdf namelist and check the parameters
+      !!                called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namthd_zdf
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ios, ioptio   ! Local integer
+      !!
+      NAMELIST/namthd_zdf/ ln_zdf_BL99, ln_cndi_U64, ln_cndi_P07, rn_cnd_s, rn_kappa_i
+      !!-------------------------------------------------------------------
+      !
+      REWIND( numnam_ice_ref )              ! Namelist namthd_zdf in reference namelist : Ice thermodynamics
+      READ  ( numnam_ice_ref, namthd_zdf, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namthd_zdf in reference namelist', lwp )
+
+      REWIND( numnam_ice_cfg )              ! Namelist namthd_zdf in configuration namelist : Ice thermodynamics
+      READ  ( numnam_ice_cfg, namthd_zdf, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namthd_zdf in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namthd_zdf )
+      !
+      !
+      IF(lwp) THEN                          ! control print
+         WRITE(numout,*) 'ice_thd_zdf_init: Ice vertical heat diffusion'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namthd_zdf:'
+         WRITE(numout,*) '      Bitz and Lipscomb (1999) formulation                    ln_zdf_BL99  = ', ln_zdf_BL99
+         WRITE(numout,*) '      thermal conductivity in the ice (Untersteiner 1964)     ln_cndi_U64  = ', ln_cndi_U64
+         WRITE(numout,*) '      thermal conductivity in the ice (Pringle et al 2007)    ln_cndi_P07  = ', ln_cndi_P07
+         WRITE(numout,*) '      thermal conductivity in the snow                        rn_cnd_s     = ', rn_cnd_s
+         WRITE(numout,*) '      extinction radiation parameter in sea ice               rn_kappa_i   = ', rn_kappa_i
+      ENDIF
+      !
+      IF ( ( ln_cndi_U64 .AND. ln_cndi_P07 ) .OR. ( .NOT.ln_cndi_U64 .AND. .NOT.ln_cndi_P07 ) ) THEN
+         CALL ctl_stop( 'ice_thd_zdf_init: choose one and only one formulation for thermal conduction (ln_cndi_U64 or ln_cndi_P07)' )
+      ENDIF
+      !                             !== set the choice of ice vertical thermodynamic formulation ==!
+      ioptio = 0 
+      IF( ln_zdf_BL99 ) THEN   ;   ioptio = ioptio + 1   ;   nice_zdf = np_BL99   ;   ENDIF   ! BL99 thermodynamics (linear liquidus + constant thermal properties)
+!!    IF( ln_zdf_XXXX ) THEN   ;   ioptio = ioptio + 1   ;   nice_zdf = np_XXXX   ;   ENDIF
+      IF( ioptio /= 1 )   CALL ctl_stop( 'ice_thd_init: one and only one ice thermo option has to be defined ' )
+      !
+   END SUBROUTINE ice_thd_zdf_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option       Dummy Module             No ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icethd_zdf
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_zdf_bl99.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_zdf_bl99.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icethd_zdf_bl99.F90	(revision 9019)
@@ -0,0 +1,844 @@
+MODULE icethd_zdf_BL99
+   !!======================================================================
+   !!                       ***  MODULE icethd_zdf_BL99 ***
+   !!   sea-ice: vertical heat diffusion in sea ice (computation of temperatures) 
+   !!======================================================================
+   !! History :  LIM  ! 02-2003 (M. Vancoppenolle) original 1D code
+   !!                 ! 06-2005 (M. Vancoppenolle) 3d version
+   !!                 ! 11-2006 (X Fettweis) Vectorization by Xavier
+   !!                 ! 04-2007 (M. Vancoppenolle) Energy conservation
+   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!             -   ! 2012-05 (C. Rousset) add penetration solar flux
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!  ice_thd_zdf_BL99 : vertical diffusion computation
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants (ocean directory) 
+   USE ice            ! sea-ice: variables
+   USE ice1D          ! sea-ice: thermodynamics variables
+   USE icevar         ! sea-ice: operations
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_thd_zdf_BL99   ! called by icethd_zdf
+
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icethd_zdf.F90 8420 2017-08-08 12:18:46Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_thd_zdf_BL99( k_jules )
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_thd_zdf_BL99  ***
+      !!
+      !! ** Purpose : computes the time evolution of snow and sea-ice temperature
+      !!              profiles, using the original Bitz and Lipscomb (1999) algorithm
+      !!
+      !! ** Method  : solves the heat equation diffusion with a Neumann boundary
+      !!              condition at the surface and a Dirichlet one at the bottom. 
+      !!              Solar radiation is partially absorbed into the ice.
+      !!              The specific heat and thermal conductivities depend on ice 
+      !!              salinity and temperature to take into account brine pocket   
+      !!              melting. The numerical scheme is an iterative Crank-Nicolson
+      !!              on a non-uniform multilayer grid in the ice and snow system.
+      !!
+      !!           The successive steps of this routine are
+      !!           1.  initialization of ice-snow layers thicknesses
+      !!           2.  Internal absorbed and transmitted radiation
+      !!           Then iterative procedure begins
+      !!           3.  Thermal conductivity
+      !!           4.  Kappa factors
+      !!           5.  specific heat in the ice
+      !!           6.  eta factors
+      !!           7.  surface flux computation
+      !!           8.  tridiagonal system terms
+      !!           9.  solving the tridiagonal system with Gauss elimination
+      !!           Iterative procedure ends according to a criterion on evolution
+      !!           of temperature
+      !!           10. Fluxes at the interfaces
+      !!
+      !! ** Inputs / Ouputs : (global commons)
+      !!           surface temperature              : t_su_1d
+      !!           ice/snow temperatures            : t_i_1d, t_s_1d
+      !!           ice salinities                   : sz_i_1d
+      !!           number of layers in the ice/snow : nlay_i, nlay_s
+      !!           total ice/snow thickness         : h_i_1d, h_s_1d
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   k_jules     ! Jules coupling (0=OFF, 1=EMULATED, 2=ACTIVE)
+      !
+      INTEGER ::   ji, jk         ! spatial loop index
+      INTEGER ::   jm             ! current reference number of equation
+      INTEGER ::   jm_mint, jm_maxt
+      INTEGER ::   iconv          ! number of iterations in iterative procedure
+      INTEGER ::   iconv_max = 50 ! max number of iterations in iterative procedure
+      !
+      INTEGER, DIMENSION(jpij) ::   jm_min    ! reference number of top equation
+      INTEGER, DIMENSION(jpij) ::   jm_max    ! reference number of bottom equation
+      !
+      REAL(wp) ::   zg1s      =  2._wp        ! for the tridiagonal system
+      REAL(wp) ::   zg1       =  2._wp        !
+      REAL(wp) ::   zgamma    =  18009._wp    ! for specific heat
+      REAL(wp) ::   zbeta     =  0.117_wp     ! for thermal conductivity (could be 0.13)
+      REAL(wp) ::   zraext_s  =  10._wp       ! extinction coefficient of radiation in the snow
+      REAL(wp) ::   zkimin    =  0.10_wp      ! minimum ice thermal conductivity
+      REAL(wp) ::   ztsu_err  =  1.e-5_wp     ! range around which t_su is considered at 0C 
+      REAL(wp) ::   zdti_bnd  =  1.e-4_wp     ! maximal authorized error on temperature 
+      REAL(wp) ::   ztmelt_i                  ! ice melting temperature
+      REAL(wp) ::   zdti_max                  ! current maximal error on temperature 
+      REAL(wp) ::   zcpi                      ! Ice specific heat
+      REAL(wp) ::   zhfx_err, zdq             ! diag errors on heat
+      REAL(wp) ::   zfac                      ! dummy factor
+      !
+      REAL(wp), DIMENSION(jpij) ::   isnow        ! switch for presence (1) or absence (0) of snow
+      REAL(wp), DIMENSION(jpij) ::   ztsub        ! surface temperature at previous iteration
+      REAL(wp), DIMENSION(jpij) ::   zh_i, z1_h_i ! ice layer thickness
+      REAL(wp), DIMENSION(jpij) ::   zh_s, z1_h_s ! snow layer thickness
+      REAL(wp), DIMENSION(jpij) ::   zqns_ice_b   ! solar radiation absorbed at the surface
+      REAL(wp), DIMENSION(jpij) ::   zfnet        ! surface flux function
+      REAL(wp), DIMENSION(jpij) ::   zdqns_ice_b  ! derivative of the surface flux function
+      !
+      REAL(wp), DIMENSION(jpij       )     ::   ztsuold     ! Old surface temperature in the ice
+      REAL(wp), DIMENSION(jpij,nlay_i)     ::   ztiold      ! Old temperature in the ice
+      REAL(wp), DIMENSION(jpij,nlay_s)     ::   ztsold      ! Old temperature in the snow
+      REAL(wp), DIMENSION(jpij,nlay_i)     ::   ztib        ! Temporary temperature in the ice to check the convergence
+      REAL(wp), DIMENSION(jpij,nlay_s)     ::   ztsb        ! Temporary temperature in the snow to check the convergence
+      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   ztcond_i    ! Ice thermal conductivity
+      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   zradtr_i    ! Radiation transmitted through the ice
+      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   zradab_i    ! Radiation absorbed in the ice
+      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   zkappa_i    ! Kappa factor in the ice
+      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   zeta_i      ! Eta factor in the ice
+      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   zradtr_s    ! Radiation transmited through the snow
+      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   zradab_s    ! Radiation absorbed in the snow
+      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   zkappa_s    ! Kappa factor in the snow
+      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   zeta_s      ! Eta factor in the snow
+      REAL(wp), DIMENSION(jpij,nlay_i+3)   ::   zindterm    ! 'Ind'ependent term
+      REAL(wp), DIMENSION(jpij,nlay_i+3)   ::   zindtbis    ! Temporary 'ind'ependent term
+      REAL(wp), DIMENSION(jpij,nlay_i+3)   ::   zdiagbis    ! Temporary 'dia'gonal term
+      REAL(wp), DIMENSION(jpij,nlay_i+3,3) ::   ztrid       ! Tridiagonal system terms
+      REAL(wp), DIMENSION(jpij)            ::   zq_ini      ! diag errors on heat
+      REAL(wp), DIMENSION(jpij)            ::   zghe        ! G(he), th. conduct enhancement factor, mono-cat
+      !
+      ! Mono-category
+      REAL(wp) ::   zepsilon   ! determines thres. above which computation of G(h) is done
+      REAL(wp) ::   zhe        ! dummy factor
+      REAL(wp) ::   zcnd_i     ! mean sea ice thermal conductivity
+      !!------------------------------------------------------------------     
+
+      ! --- diag error on heat diffusion - PART 1 --- !
+      DO ji = 1, npti
+         zq_ini(ji) = ( SUM( e_i_1d(ji,1:nlay_i) ) * h_i_1d(ji) * r1_nlay_i +  &
+            &           SUM( e_s_1d(ji,1:nlay_s) ) * h_s_1d(ji) * r1_nlay_s ) 
+      END DO
+
+      !------------------
+      ! 1) Initialization
+      !------------------
+      DO ji = 1, npti
+         isnow(ji) = 1._wp - MAX( 0._wp , SIGN(1._wp, - h_s_1d(ji) ) )  ! is there snow or not
+         ! layer thickness
+         zh_i(ji) = h_i_1d(ji) * r1_nlay_i
+         zh_s(ji) = h_s_1d(ji) * r1_nlay_s
+      END DO
+      !
+      WHERE( zh_i(1:npti) >= epsi10 )   ;   z1_h_i(1:npti) = 1._wp / zh_i(1:npti)
+      ELSEWHERE                         ;   z1_h_i(1:npti) = 0._wp
+      END WHERE
+      !
+      WHERE( zh_s(1:npti) >= epsi10 )   ;   z1_h_s(1:npti) = 1._wp / zh_s(1:npti)
+      ELSEWHERE                         ;   z1_h_s(1:npti) = 0._wp
+      END WHERE
+      !
+      ! Store initial temperatures and non solar heat fluxes
+      IF( k_jules == np_jules_OFF .OR. k_jules == np_jules_EMULE ) THEN
+         !
+         ztsub      (1:npti) = t_su_1d(1:npti)                          ! surface temperature at iteration n-1
+         ztsuold    (1:npti) = t_su_1d(1:npti)                          ! surface temperature initial value
+         t_su_1d    (1:npti) = MIN( t_su_1d(1:npti), rt0 - ztsu_err )   ! required to leave the choice between melting or not
+         zdqns_ice_b(1:npti) = dqns_ice_1d(1:npti)                      ! derivative of incoming nonsolar flux 
+         zqns_ice_b (1:npti) = qns_ice_1d(1:npti)                       ! store previous qns_ice_1d value
+         !
+      ENDIF
+      !
+      ztsold (1:npti,:) = t_s_1d(1:npti,:)   ! Old snow temperature
+      ztiold (1:npti,:) = t_i_1d(1:npti,:)   ! Old ice temperature
+
+      !-------------
+      ! 2) Radiation
+      !-------------
+      ! --- Transmission/absorption of solar radiation in the ice --- !
+      zradtr_s(1:npti,0) = qsr_ice_tr_1d(1:npti)
+      DO jk = 1, nlay_s
+         DO ji = 1, npti
+            !                             ! radiation transmitted below the layer-th snow layer
+            zradtr_s(ji,jk) = zradtr_s(ji,0) * EXP( - zraext_s * zh_s(ji) * REAL(jk) )
+            !                             ! radiation absorbed by the layer-th snow layer
+            zradab_s(ji,jk) = zradtr_s(ji,jk-1) - zradtr_s(ji,jk)
+         END DO
+      END DO
+      !
+      zradtr_i(1:npti,0) = zradtr_s(1:npti,nlay_s) * isnow(1:npti) + qsr_ice_tr_1d(1:npti) * ( 1._wp - isnow(1:npti) )
+      DO jk = 1, nlay_i 
+         DO ji = 1, npti
+            !                             ! radiation transmitted below the layer-th ice layer
+            zradtr_i(ji,jk) = zradtr_i(ji,0) * EXP( - rn_kappa_i * zh_i(ji) * REAL(jk) )
+            !                             ! radiation absorbed by the layer-th ice layer
+            zradab_i(ji,jk) = zradtr_i(ji,jk-1) - zradtr_i(ji,jk)
+         END DO
+      END DO
+      !
+      ftr_ice_1d(1:npti) = zradtr_i(1:npti,nlay_i)   ! record radiation transmitted below the ice
+      !
+      iconv    = 0          ! number of iterations
+      zdti_max = 1000._wp   ! maximal value of error on all points
+      !
+      !                                                          !============================!
+      DO WHILE ( zdti_max > zdti_bnd .AND. iconv < iconv_max )   ! Iterative procedure begins !
+         !                                                       !============================!
+         iconv = iconv + 1
+         !
+         ztib(1:npti,:) = t_i_1d(1:npti,:)
+         ztsb(1:npti,:) = t_s_1d(1:npti,:)
+         !
+         !--------------------------------
+         ! 3) Sea ice thermal conductivity
+         !--------------------------------
+         IF( ln_cndi_U64 ) THEN         !-- Untersteiner (1964) formula: k = k0 + beta.S/T
+            !
+            DO ji = 1, npti
+               ztcond_i(ji,0)      = rcdic + zbeta * sz_i_1d(ji,1)      / MIN( -epsi10, t_i_1d(ji,1) - rt0 )
+               ztcond_i(ji,nlay_i) = rcdic + zbeta * sz_i_1d(ji,nlay_i) / MIN( -epsi10, t_bo_1d(ji)  - rt0 )
+            END DO
+            DO jk = 1, nlay_i-1
+               DO ji = 1, npti
+                  ztcond_i(ji,jk) = rcdic + zbeta * 0.5_wp * ( sz_i_1d(ji,jk) + sz_i_1d(ji,jk+1) ) /  &
+                     &                      MIN( -epsi10, 0.5_wp * (t_i_1d(ji,jk) + t_i_1d(ji,jk+1)) - rt0 )
+               END DO
+            END DO
+            !
+         ELSEIF( ln_cndi_P07 ) THEN     !-- Pringle et al formula: k = k0 + beta1.S/T - beta2.T
+            !
+            DO ji = 1, npti
+               ztcond_i(ji,0)      = rcdic + 0.09_wp  *  sz_i_1d(ji,1)      / MIN( -epsi10, t_i_1d(ji,1) - rt0 )  &
+                  &                        - 0.011_wp * ( t_i_1d(ji,1) - rt0 )
+               ztcond_i(ji,nlay_i) = rcdic + 0.09_wp  *  sz_i_1d(ji,nlay_i) / MIN( -epsi10, t_bo_1d(ji)  - rt0 )  &
+                  &                        - 0.011_wp * ( t_bo_1d(ji) - rt0 )
+            END DO
+            DO jk = 1, nlay_i-1
+               DO ji = 1, npti
+                  ztcond_i(ji,jk) = rcdic + 0.09_wp  *   0.5_wp * ( sz_i_1d(ji,jk) + sz_i_1d(ji,jk+1) ) /        &
+                     &                     MIN( -epsi10, 0.5_wp * ( t_i_1d (ji,jk) + t_i_1d (ji,jk+1) ) - rt0 )  &
+                     &                    - 0.011_wp * ( 0.5_wp * ( t_i_1d (ji,jk) + t_i_1d (ji,jk+1) ) - rt0 )
+               END DO
+            END DO
+            !
+         ENDIF
+         ztcond_i(1:npti,:) = MAX( zkimin, ztcond_i(1:npti,:) )        
+         !
+         !--- G(he) : enhancement of thermal conductivity in mono-category case
+         ! Computation of effective thermal conductivity G(h)
+         ! Used in mono-category case only to simulate an ITD implicitly
+         ! Fichefet and Morales Maqueda, JGR 1997
+         zghe(1:npti) = 1._wp
+         !
+         SELECT CASE ( nn_monocat )
+         !
+         CASE ( 1 , 3 )
+            !
+            zepsilon = 0.1_wp
+            DO ji = 1, npti
+               zcnd_i = SUM( ztcond_i(ji,:) ) / REAL( nlay_i+1, wp )                                ! Mean sea ice thermal conductivity
+               zhe = ( rn_cnd_s * h_i_1d(ji) + zcnd_i * h_s_1d(ji) ) / ( rn_cnd_s + zcnd_i )        ! Effective thickness he (zhe)
+               IF( zhe >=  zepsilon * 0.5_wp * EXP(1._wp) )  &
+                  &   zghe(ji) = MIN( 2._wp, 0.5_wp * ( 1._wp + LOG( 2._wp * zhe / zepsilon ) ) )   ! G(he)
+            END DO
+            !
+         END SELECT
+         !
+         !-----------------
+         ! 4) kappa factors
+         !-----------------
+         !--- Snow
+         DO jk = 0, nlay_s-1
+            DO ji = 1, npti
+               zkappa_s(ji,jk) = zghe(ji) * rn_cnd_s * z1_h_s(ji)
+            END DO
+         END DO
+         DO ji = 1, npti   ! Snow-ice interface
+            zfac = 0.5_wp * ( ztcond_i(ji,0) * zh_s(ji) + rn_cnd_s * zh_i(ji) )
+            IF( zfac > epsi10 ) THEN
+               zkappa_s(ji,nlay_s) = zghe(ji) * rn_cnd_s * ztcond_i(ji,0) / zfac
+            ELSE
+               zkappa_s(ji,nlay_s) = 0._wp
+            ENDIF
+         END DO
+
+         !--- Ice
+         DO jk = 0, nlay_i
+            DO ji = 1, npti
+               zkappa_i(ji,jk) = zghe(ji) * ztcond_i(ji,jk) * z1_h_i(ji)
+            END DO
+         END DO
+         DO ji = 1, npti   ! Snow-ice interface
+            zkappa_i(ji,0) = zkappa_s(ji,nlay_s) * isnow(ji) + zkappa_i(ji,0) * ( 1._wp - isnow(ji) )
+         END DO
+         !
+         !--------------------------------------
+         ! 5) Sea ice specific heat, eta factors
+         !--------------------------------------
+         DO jk = 1, nlay_i
+            DO ji = 1, npti
+               zcpi = cpic + zgamma * sz_i_1d(ji,jk) / MAX( ( t_i_1d(ji,jk) - rt0 ) * ( ztiold(ji,jk) - rt0 ), epsi10 )
+               zeta_i(ji,jk) = rdt_ice * r1_rhoic * z1_h_i(ji) / MAX( epsi10, zcpi ) 
+            END DO
+         END DO
+
+         DO jk = 1, nlay_s
+            DO ji = 1, npti
+               zeta_s(ji,jk) = rdt_ice * r1_rhosn * r1_cpic * z1_h_s(ji)
+            END DO
+         END DO
+         !
+         !----------------------------------------!
+         !                                        !
+         !   JULES COUPLING IS OFF OR EMULATED    !
+         !                                        !
+         !----------------------------------------!
+         !
+         IF( k_jules == np_jules_OFF .OR. k_jules == np_jules_EMULE ) THEN
+            !
+            ! ==> The original BL99 temperature computation is used
+            !       (with qsr_ice, qns_ice and dqns_ice as inputs)
+            !
+            !----------------------------
+            ! 6) surface flux computation
+            !----------------------------
+            ! update of the non solar flux according to the update in T_su
+            DO ji = 1, npti
+               qns_ice_1d(ji) = qns_ice_1d(ji) + dqns_ice_1d(ji) * ( t_su_1d(ji) - ztsub(ji) )
+            END DO
+
+            DO ji = 1, npti
+               zfnet(ji) = qsr_ice_1d(ji) - qsr_ice_tr_1d(ji) + qns_ice_1d(ji) ! net heat flux = net - transmitted solar + non solar
+            END DO
+            !
+            !----------------------------
+            ! 7) tridiagonal system terms
+            !----------------------------
+            ! layer denotes the number of the layer in the snow or in the ice
+            ! jm denotes the reference number of the equation in the tridiagonal
+            ! system, terms of tridiagonal system are indexed as following :
+            ! 1 is subdiagonal term, 2 is diagonal and 3 is superdiagonal one
+
+            ! ice interior terms (top equation has the same form as the others)
+            ztrid   (1:npti,:,:) = 0._wp
+            zindterm(1:npti,:)   = 0._wp
+            zindtbis(1:npti,:)   = 0._wp
+            zdiagbis(1:npti,:)   = 0._wp
+
+            DO jm = nlay_s + 2, nlay_s + nlay_i 
+               DO ji = 1, npti
+                  jk = jm - nlay_s - 1
+                  ztrid   (ji,jm,1) =       - zeta_i(ji,jk) *   zkappa_i(ji,jk-1)
+                  ztrid   (ji,jm,2) = 1._wp + zeta_i(ji,jk) * ( zkappa_i(ji,jk-1) + zkappa_i(ji,jk) )
+                  ztrid   (ji,jm,3) =       - zeta_i(ji,jk) *                       zkappa_i(ji,jk)
+                  zindterm(ji,jm)   = ztiold(ji,jk) + zeta_i(ji,jk) * zradab_i(ji,jk)
+               END DO
+            END DO
+
+            jm =  nlay_s + nlay_i + 1
+            DO ji = 1, npti
+               ! ice bottom term
+               ztrid   (ji,jm,1) =       - zeta_i(ji,nlay_i) *   zkappa_i(ji,nlay_i-1)   
+               ztrid   (ji,jm,2) = 1._wp + zeta_i(ji,nlay_i) * ( zkappa_i(ji,nlay_i-1) + zkappa_i(ji,nlay_i) * zg1 )
+               ztrid   (ji,jm,3) = 0._wp
+               zindterm(ji,jm)   = ztiold(ji,nlay_i) + zeta_i(ji,nlay_i) *  &
+                  &              ( zradab_i(ji,nlay_i) + zkappa_i(ji,nlay_i) * zg1 * t_bo_1d(ji) ) 
+            END DO
+
+            DO ji = 1, npti
+               !                               !---------------------!
+               IF( h_s_1d(ji) > 0._wp ) THEN   !  snow-covered cells !
+                  !                            !---------------------!
+                  ! snow interior terms (bottom equation has the same form as the others)
+                  DO jm = 3, nlay_s + 1
+                     jk = jm - 1
+                     ztrid   (ji,jm,1) =       - zeta_s(ji,jk) *   zkappa_s(ji,jk-1)
+                     ztrid   (ji,jm,2) = 1._wp + zeta_s(ji,jk) * ( zkappa_s(ji,jk-1) + zkappa_s(ji,jk) )
+                     ztrid   (ji,jm,3) =       - zeta_s(ji,jk) *                       zkappa_s(ji,jk)
+                     zindterm(ji,jm)   = ztsold(ji,jk) + zeta_s(ji,jk) * zradab_s(ji,jk)
+                  END DO
+                  
+                  ! case of only one layer in the ice (ice equation is altered)
+                  IF( nlay_i == 1 ) THEN
+                     ztrid   (ji,nlay_s+2,3) = 0._wp
+                     zindterm(ji,nlay_s+2)   = zindterm(ji,nlay_s+2) + zkappa_i(ji,1) * t_bo_1d(ji) 
+                  ENDIF
+                  
+                  IF( t_su_1d(ji) < rt0 ) THEN   !--  case 1 : no surface melting
+                     
+                     jm_min(ji) = 1
+                     jm_max(ji) = nlay_i + nlay_s + 1
+                     
+                     ! surface equation
+                     ztrid   (ji,1,1) = 0._wp
+                     ztrid   (ji,1,2) = zdqns_ice_b(ji) - zg1s * zkappa_s(ji,0)
+                     ztrid   (ji,1,3) =                   zg1s * zkappa_s(ji,0)
+                     zindterm(ji,1)   = zdqns_ice_b(ji) * t_su_1d(ji) - zfnet(ji)
+                     
+                     ! first layer of snow equation
+                     ztrid   (ji,2,1) =       - zeta_s(ji,1) *                    zkappa_s(ji,0) * zg1s
+                     ztrid   (ji,2,2) = 1._wp + zeta_s(ji,1) * ( zkappa_s(ji,1) + zkappa_s(ji,0) * zg1s )
+                     ztrid   (ji,2,3) =       - zeta_s(ji,1) *   zkappa_s(ji,1)
+                     zindterm(ji,2)   = ztsold(ji,1) + zeta_s(ji,1) * zradab_s(ji,1)
+                     
+                  ELSE                            !--  case 2 : surface is melting
+                     !
+                     jm_min(ji) = 2
+                     jm_max(ji) = nlay_i + nlay_s + 1
+                     
+                     ! first layer of snow equation
+                     ztrid   (ji,2,1) = 0._wp
+                     ztrid   (ji,2,2) = 1._wp + zeta_s(ji,1) * ( zkappa_s(ji,1) + zkappa_s(ji,0) * zg1s )
+                     ztrid   (ji,2,3) =       - zeta_s(ji,1) *   zkappa_s(ji,1) 
+                     zindterm(ji,2)   = ztsold(ji,1) + zeta_s(ji,1) * ( zradab_s(ji,1) + zkappa_s(ji,0) * zg1s * t_su_1d(ji) ) 
+                  ENDIF
+                  !                            !---------------------!
+               ELSE                            ! cells without snow  !
+                  !                            !---------------------!
+                  !
+                  IF( t_su_1d(ji) < rt0 ) THEN   !--  case 1 : no surface melting
+                     !
+                     jm_min(ji) = nlay_s + 1
+                     jm_max(ji) = nlay_i + nlay_s + 1
+                     
+                     ! surface equation	
+                     ztrid   (ji,jm_min(ji),1) = 0._wp
+                     ztrid   (ji,jm_min(ji),2) = zdqns_ice_b(ji) - zkappa_i(ji,0) * zg1    
+                     ztrid   (ji,jm_min(ji),3) =                   zkappa_i(ji,0) * zg1
+                     zindterm(ji,jm_min(ji))   = zdqns_ice_b(ji) * t_su_1d(ji) - zfnet(ji)
+                     
+                     ! first layer of ice equation
+                     ztrid   (ji,jm_min(ji)+1,1) =       - zeta_i(ji,1) *                    zkappa_i(ji,0) * zg1
+                     ztrid   (ji,jm_min(ji)+1,2) = 1._wp + zeta_i(ji,1) * ( zkappa_i(ji,1) + zkappa_i(ji,0) * zg1 )
+                     ztrid   (ji,jm_min(ji)+1,3) =       - zeta_i(ji,1) *   zkappa_i(ji,1)  
+                     zindterm(ji,jm_min(ji)+1)   = ztiold(ji,1) + zeta_i(ji,1) * zradab_i(ji,1)  
+                     
+                     ! case of only one layer in the ice (surface & ice equations are altered)
+                     IF( nlay_i == 1 ) THEN
+                        ztrid   (ji,jm_min(ji),1)   = 0._wp
+                        ztrid   (ji,jm_min(ji),2)   = zdqns_ice_b(ji)      -   zkappa_i(ji,0) * 2._wp
+                        ztrid   (ji,jm_min(ji),3)   =                          zkappa_i(ji,0) * 2._wp
+                        ztrid   (ji,jm_min(ji)+1,1) =       - zeta_i(ji,1) *   zkappa_i(ji,0) * 2._wp
+                        ztrid   (ji,jm_min(ji)+1,2) = 1._wp + zeta_i(ji,1) * ( zkappa_i(ji,0) * 2._wp + zkappa_i(ji,1) )
+                        ztrid   (ji,jm_min(ji)+1,3) = 0._wp
+                        zindterm(ji,jm_min(ji)+1)   = ztiold(ji,1) + zeta_i(ji,1) * (zradab_i(ji,1) + zkappa_i(ji,1) * t_bo_1d(ji))
+                     ENDIF
+                     
+                  ELSE                            !--  case 2 : surface is melting
+                     
+                     jm_min(ji) = nlay_s + 2
+                     jm_max(ji) = nlay_i + nlay_s + 1
+                     
+                     ! first layer of ice equation
+                     ztrid   (ji,jm_min(ji),1) = 0._wp
+                     ztrid   (ji,jm_min(ji),2) = 1._wp + zeta_i(ji,1) * ( zkappa_i(ji,1) + zkappa_i(ji,0) * zg1 )  
+                     ztrid   (ji,jm_min(ji),3) =       - zeta_i(ji,1) *   zkappa_i(ji,1)
+                     zindterm(ji,jm_min(ji))   = ztiold(ji,1) + zeta_i(ji,1) * (zradab_i(ji,1) + zkappa_i(ji,0) * zg1 * t_su_1d(ji)) 
+                     
+                     ! case of only one layer in the ice (surface & ice equations are altered)
+                     IF( nlay_i == 1 ) THEN
+                        ztrid   (ji,jm_min(ji),1) = 0._wp
+                        ztrid   (ji,jm_min(ji),2) = 1._wp + zeta_i(ji,1) * ( zkappa_i(ji,0) * 2._wp + zkappa_i(ji,1) )
+                        ztrid   (ji,jm_min(ji),3) = 0._wp
+                        zindterm(ji,jm_min(ji))   = ztiold(ji,1) + zeta_i(ji,1) * ( zradab_i(ji,1) + zkappa_i(ji,1) * t_bo_1d(ji) ) &
+                           &                      + t_su_1d(ji) * zeta_i(ji,1) * zkappa_i(ji,0) * 2._wp
+                     ENDIF
+                     
+                  ENDIF
+               ENDIF
+               !
+               zindtbis(ji,jm_min(ji)) = zindterm(ji,jm_min(ji))
+               zdiagbis(ji,jm_min(ji)) = ztrid   (ji,jm_min(ji),2)
+               !
+            END DO
+            !
+            !------------------------------
+            ! 8) tridiagonal system solving
+            !------------------------------
+            ! Solve the tridiagonal system with Gauss elimination method.
+            ! Thomas algorithm, from Computational fluid Dynamics, J.D. ANDERSON, McGraw-Hill 1984
+            jm_maxt = 0
+            jm_mint = nlay_i+5
+            DO ji = 1, npti
+               jm_mint = MIN(jm_min(ji),jm_mint)
+               jm_maxt = MAX(jm_max(ji),jm_maxt)
+            END DO
+
+            DO jk = jm_mint+1, jm_maxt
+               DO ji = 1, npti
+                  jm = MIN(MAX(jm_min(ji)+1,jk),jm_max(ji))
+                  zdiagbis(ji,jm) = ztrid   (ji,jm,2) - ztrid(ji,jm,1) * ztrid   (ji,jm-1,3) / zdiagbis(ji,jm-1)
+                  zindtbis(ji,jm) = zindterm(ji,jm  ) - ztrid(ji,jm,1) * zindtbis(ji,jm-1  ) / zdiagbis(ji,jm-1)
+               END DO
+            END DO
+
+            ! ice temperatures
+            DO ji = 1, npti
+               t_i_1d(ji,nlay_i) = zindtbis(ji,jm_max(ji)) / zdiagbis(ji,jm_max(ji))
+            END DO
+
+            DO jm = nlay_i + nlay_s, nlay_s + 2, -1
+               DO ji = 1, npti
+                  jk = jm - nlay_s - 1
+                  t_i_1d(ji,jk) = ( zindtbis(ji,jm) - ztrid(ji,jm,3) * t_i_1d(ji,jk+1) ) / zdiagbis(ji,jm)
+               END DO
+            END DO
+
+            DO ji = 1, npti
+               ! snow temperatures      
+               IF( h_s_1d(ji) > 0._wp ) THEN
+                  t_s_1d(ji,nlay_s) = ( zindtbis(ji,nlay_s+1) - ztrid(ji,nlay_s+1,3) * t_i_1d(ji,1) ) / zdiagbis(ji,nlay_s+1)
+               ENDIF
+               ! surface temperature
+               ztsub(ji) = t_su_1d(ji)
+               IF( t_su_1d(ji) < rt0 ) THEN
+                  t_su_1d(ji) = ( zindtbis(ji,jm_min(ji)) - ztrid(ji,jm_min(ji),3) *  &
+                     &          ( isnow(ji) * t_s_1d(ji,1) + ( 1._wp - isnow(ji) ) * t_i_1d(ji,1) ) ) / zdiagbis(ji,jm_min(ji))
+               ENDIF
+            END DO
+            !
+            !--------------------------------------------------------------
+            ! 9) Has the scheme converged?, end of the iterative procedure
+            !--------------------------------------------------------------
+            ! check that nowhere it has started to melt
+            ! zdti_max is a measure of error, it has to be under zdti_bnd
+            zdti_max = 0._wp
+            DO ji = 1, npti
+               t_su_1d(ji) = MAX( MIN( t_su_1d(ji) , rt0 ) , rt0 - 100._wp )
+               zdti_max    = MAX( zdti_max, ABS( t_su_1d(ji) - ztsub(ji) ) )     
+            END DO
+
+            DO jk = 1, nlay_s
+               DO ji = 1, npti
+                  t_s_1d(ji,jk) = MAX( MIN( t_s_1d(ji,jk), rt0 ), rt0 - 100._wp )
+                  zdti_max      = MAX( zdti_max, ABS( t_s_1d(ji,jk) - ztsb(ji,jk) ) )
+               END DO
+            END DO
+
+            DO jk = 1, nlay_i
+               DO ji = 1, npti
+                  ztmelt_i      = -tmut * sz_i_1d(ji,jk) + rt0 
+                  t_i_1d(ji,jk) =  MAX( MIN( t_i_1d(ji,jk), ztmelt_i ), rt0 - 100._wp )
+                  zdti_max      =  MAX( zdti_max, ABS( t_i_1d(ji,jk) - ztib(ji,jk) ) )
+               END DO
+            END DO
+
+            ! Compute spatial maximum over all errors
+            ! note that this could be optimized substantially by iterating only the non-converging points
+            IF( lk_mpp ) CALL mpp_max( zdti_max, kcom=ncomm_ice )
+         !
+         !----------------------------------------!
+         !                                        !
+         !      JULES COUPLING IS ACTIVE          !
+         !                                        !
+         !----------------------------------------!
+         !
+         ELSEIF( k_jules == np_jules_ACTIVE ) THEN
+            !
+            ! ==> we use a modified BL99 solver with conduction flux (qcn_ice) as forcing term
+            !
+            !----------------------------
+            ! 7) tridiagonal system terms
+            !----------------------------
+            ! layer denotes the number of the layer in the snow or in the ice
+            ! jm denotes the reference number of the equation in the tridiagonal
+            ! system, terms of tridiagonal system are indexed as following :
+            ! 1 is subdiagonal term, 2 is diagonal and 3 is superdiagonal one
+
+            ! ice interior terms (top equation has the same form as the others)
+            ztrid   (1:npti,:,:) = 0._wp
+            zindterm(1:npti,:)   = 0._wp
+            zindtbis(1:npti,:)   = 0._wp
+            zdiagbis(1:npti,:)   = 0._wp
+
+            DO jm = nlay_s + 2, nlay_s + nlay_i 
+               DO ji = 1, npti
+                  jk = jm - nlay_s - 1
+                  ztrid   (ji,jm,1) =       - zeta_i(ji,jk) *   zkappa_i(ji,jk-1)
+                  ztrid   (ji,jm,2) = 1._wp + zeta_i(ji,jk) * ( zkappa_i(ji,jk-1) + zkappa_i(ji,jk) )
+                  ztrid   (ji,jm,3) =       - zeta_i(ji,jk) *                       zkappa_i(ji,jk)
+                  zindterm(ji,jm)   = ztiold(ji,jk) + zeta_i(ji,jk) * zradab_i(ji,jk)
+               END DO
+            ENDDO
+
+            jm =  nlay_s + nlay_i + 1
+            DO ji = 1, npti
+               ! ice bottom term
+               ztrid   (ji,jm,1) =       - zeta_i(ji,nlay_i) *   zkappa_i(ji,nlay_i-1)   
+               ztrid   (ji,jm,2) = 1._wp + zeta_i(ji,nlay_i) * ( zkappa_i(ji,nlay_i-1) + zkappa_i(ji,nlay_i) * zg1 )
+               ztrid   (ji,jm,3) = 0._wp
+               zindterm(ji,jm)   = ztiold(ji,nlay_i) + zeta_i(ji,nlay_i) *  &
+                  &              ( zradab_i(ji,nlay_i) + zkappa_i(ji,nlay_i) * zg1 * t_bo_1d(ji) ) 
+            ENDDO
+
+            DO ji = 1, npti
+               !                               !---------------------!
+               IF( h_s_1d(ji) > 0._wp ) THEN   !  snow-covered cells !
+                  !                            !---------------------!
+                  ! snow interior terms (bottom equation has the same form as the others)
+                  DO jm = 3, nlay_s + 1
+                     jk = jm - 1
+                     ztrid   (ji,jm,1) =       - zeta_s(ji,jk) *   zkappa_s(ji,jk-1)
+                     ztrid   (ji,jm,2) = 1._wp + zeta_s(ji,jk) * ( zkappa_s(ji,jk-1) + zkappa_s(ji,jk) )
+                     ztrid   (ji,jm,3) =       - zeta_s(ji,jk) *                       zkappa_s(ji,jk)
+                     zindterm(ji,jm)   = ztsold(ji,jk) + zeta_s(ji,jk) * zradab_s(ji,jk)
+                  END DO
+                  
+                  ! case of only one layer in the ice (ice equation is altered)
+                  IF ( nlay_i == 1 ) THEN
+                     ztrid   (ji,nlay_s+2,3) = 0._wp
+                     zindterm(ji,nlay_s+2)   = zindterm(ji,nlay_s+2) + zkappa_i(ji,1) * t_bo_1d(ji) 
+                  ENDIF
+                  
+                  jm_min(ji) = 2
+                  jm_max(ji) = nlay_i + nlay_s + 1
+                  
+                  ! first layer of snow equation
+                  ztrid   (ji,2,1) = 0._wp
+                  ztrid   (ji,2,2) = 1._wp + zeta_s(ji,1) * zkappa_s(ji,1)
+                  ztrid   (ji,2,3) =       - zeta_s(ji,1) * zkappa_s(ji,1) 
+                  zindterm(ji,2)   = ztsold(ji,1) + zeta_s(ji,1) * ( zradab_s(ji,1) + qcn_ice_1d(ji) ) 
+                  
+                  !                            !---------------------!
+               ELSE                            ! cells without snow  !
+                  !                            !---------------------!
+                  jm_min(ji) = nlay_s + 2
+                  jm_max(ji) = nlay_i + nlay_s + 1
+                  
+                  ! first layer of ice equation
+                  ztrid   (ji,jm_min(ji),1) = 0._wp
+                  ztrid   (ji,jm_min(ji),2) = 1._wp + zeta_i(ji,1) * zkappa_i(ji,1)  
+                  ztrid   (ji,jm_min(ji),3) =       - zeta_i(ji,1) * zkappa_i(ji,1)
+                  zindterm(ji,jm_min(ji))   = ztiold(ji,1) + zeta_i(ji,1) * ( zradab_i(ji,1) + qcn_ice_1d(ji) )
+                  
+                  ! case of only one layer in the ice (surface & ice equations are altered)
+                  IF( nlay_i == 1 ) THEN
+                     ztrid   (ji,jm_min(ji),1) = 0._wp
+                     ztrid   (ji,jm_min(ji),2) = 1._wp + zeta_i(ji,1) * zkappa_i(ji,1)
+                     ztrid   (ji,jm_min(ji),3) = 0._wp
+                     zindterm(ji,jm_min(ji))   = ztiold(ji,1) + zeta_i(ji,1) *  &
+                        &                                     ( zradab_i(ji,1) + zkappa_i(ji,1) * t_bo_1d(ji) + qcn_ice_1d(ji) )
+                  ENDIF
+                  
+               ENDIF
+               !
+               zindtbis(ji,jm_min(ji)) = zindterm(ji,jm_min(ji))
+               zdiagbis(ji,jm_min(ji)) = ztrid   (ji,jm_min(ji),2)
+               !
+            END DO
+            !
+            !------------------------------
+            ! 8) tridiagonal system solving
+            !------------------------------
+            ! Solve the tridiagonal system with Gauss elimination method.
+            ! Thomas algorithm, from Computational fluid Dynamics, J.D. ANDERSON, McGraw-Hill 1984
+            jm_maxt = 0
+            jm_mint = nlay_i+5
+            DO ji = 1, npti
+               jm_mint = MIN(jm_min(ji),jm_mint)
+               jm_maxt = MAX(jm_max(ji),jm_maxt)
+            END DO
+            
+            DO jk = jm_mint+1, jm_maxt
+               DO ji = 1, npti
+                  jm = MIN(MAX(jm_min(ji)+1,jk),jm_max(ji))
+                  zdiagbis(ji,jm) = ztrid   (ji,jm,2) - ztrid(ji,jm,1) * ztrid   (ji,jm-1,3) / zdiagbis(ji,jm-1)
+                  zindtbis(ji,jm) = zindterm(ji,jm)   - ztrid(ji,jm,1) * zindtbis(ji,jm-1)   / zdiagbis(ji,jm-1)
+               END DO
+            END DO
+            
+            ! ice temperatures
+           DO ji = 1, npti
+               t_i_1d(ji,nlay_i) = zindtbis(ji,jm_max(ji)) / zdiagbis(ji,jm_max(ji))
+            END DO
+
+            DO jm = nlay_i + nlay_s, nlay_s + 2, -1
+               DO ji = 1, npti
+                  jk = jm - nlay_s - 1
+                  t_i_1d(ji,jk) = ( zindtbis(ji,jm) - ztrid(ji,jm,3) * t_i_1d(ji,jk+1) ) / zdiagbis(ji,jm)
+               END DO
+            END DO
+            
+            ! snow temperatures      
+            DO ji = 1, npti
+               IF( h_s_1d(ji) > 0._wp ) THEN
+                  t_s_1d(ji,nlay_s) = ( zindtbis(ji,nlay_s+1) - ztrid(ji,nlay_s+1,3) * t_i_1d(ji,1) ) / zdiagbis(ji,nlay_s+1)
+               ENDIF
+            END DO
+            !
+            !--------------------------------------------------------------
+            ! 9) Has the scheme converged?, end of the iterative procedure
+            !--------------------------------------------------------------
+            ! check that nowhere it has started to melt
+            ! zdti_max is a measure of error, it has to be under zdti_bnd
+            zdti_max = 0._wp
+
+            DO jk = 1, nlay_s
+               DO ji = 1, npti
+                  t_s_1d(ji,jk) = MAX( MIN( t_s_1d(ji,jk), rt0 ), rt0 - 100._wp )
+                  zdti_max = MAX( zdti_max, ABS( t_s_1d(ji,jk) - ztsb(ji,jk) ) )
+               END DO
+            END DO
+            
+            DO jk = 1, nlay_i
+               DO ji = 1, npti
+                  ztmelt_i      = -tmut * sz_i_1d(ji,jk) + rt0 
+                  t_i_1d(ji,jk) =  MAX( MIN( t_i_1d(ji,jk), ztmelt_i ), rt0 - 100._wp )
+                  zdti_max      =  MAX( zdti_max, ABS( t_i_1d(ji,jk) - ztib(ji,jk) ) )
+               END DO
+            END DO
+
+            ! Compute spatial maximum over all errors
+            ! note that this could be optimized substantially by iterating only the non-converging points
+            IF( lk_mpp )   CALL mpp_max( zdti_max, kcom=ncomm_ice )
+
+         ENDIF ! k_jules
+         
+      END DO  ! End of the do while iterative procedure
+      
+      IF( ln_icectl .AND. lwp ) THEN
+         WRITE(numout,*) ' zdti_max : ', zdti_max
+         WRITE(numout,*) ' iconv    : ', iconv
+      ENDIF
+      
+      !
+      !-----------------------------
+      ! 10) Fluxes at the interfaces
+      !-----------------------------
+      !
+      ! --- update conduction fluxes
+      !
+      DO ji = 1, npti
+         !                                ! surface ice conduction flux
+         fc_su(ji)   =  -           isnow(ji)   * zkappa_s(ji,0) * zg1s * ( t_s_1d(ji,1) - t_su_1d(ji) )  &
+            &           - ( 1._wp - isnow(ji) ) * zkappa_i(ji,0) * zg1  * ( t_i_1d(ji,1) - t_su_1d(ji) )
+         !                                ! bottom ice conduction flux
+         fc_bo_i(ji) =  - zkappa_i(ji,nlay_i) * zg1 * ( t_bo_1d(ji) - t_i_1d(ji,nlay_i) )
+      END DO
+      
+      !
+      ! --- Diagnose the heat loss due to changing non-solar / conduction flux --- !
+      !
+      IF( k_jules == np_jules_OFF .OR. k_jules == np_jules_EMULE ) THEN
+         !
+         DO ji = 1, npti
+            hfx_err_dif_1d(ji) = hfx_err_dif_1d(ji) - ( qns_ice_1d(ji) - zqns_ice_b(ji) ) * a_i_1d(ji) 
+         END DO
+         !
+      ELSEIF( k_jules == np_jules_ACTIVE ) THEN
+         !
+         DO ji = 1, npti
+            hfx_err_dif_1d(ji) = hfx_err_dif_1d(ji) - ( fc_su(ji)      - qcn_ice_1d(ji) ) * a_i_1d(ji) 
+         END DO
+         !
+      ENDIF
+      
+      !
+      ! --- Diagnose the heat loss due to non-fully converged temperature solution (should not be above 10-4 W-m2) --- !
+      !
+      IF( k_jules == np_jules_OFF .OR. k_jules == np_jules_ACTIVE ) THEN
+         
+         CALL ice_var_enthalpy       
+         
+         ! zhfx_err = correction on the diagnosed heat flux due to non-convergence of the algorithm used to solve heat equation
+         DO ji = 1, npti
+            zdq = - zq_ini(ji) + ( SUM( e_i_1d(ji,1:nlay_i) ) * h_i_1d(ji) * r1_nlay_i +  &
+               &                   SUM( e_s_1d(ji,1:nlay_s) ) * h_s_1d(ji) * r1_nlay_s )
+            
+            IF( k_jules == np_jules_OFF ) THEN
+               
+               IF( t_su_1d(ji) < rt0 ) THEN  ! case T_su < 0degC
+                  zhfx_err = ( qns_ice_1d(ji) + qsr_ice_1d(ji)    - zradtr_i(ji,nlay_i) - fc_bo_i(ji) + zdq * r1_rdtice )*a_i_1d(ji)
+               ELSE                          ! case T_su = 0degC
+                  zhfx_err = ( fc_su(ji)      + qsr_ice_tr_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) + zdq * r1_rdtice )*a_i_1d(ji)
+               ENDIF
+               
+            ELSEIF( k_jules == np_jules_ACTIVE ) THEN
+            
+               zhfx_err = ( fc_su(ji) + qsr_ice_tr_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) + zdq * r1_rdtice ) * a_i_1d(ji)
+            
+            ENDIF
+            !
+            ! total heat sink to be sent to the ocean
+            hfx_err_dif_1d(ji) = hfx_err_dif_1d(ji) + zhfx_err
+            !
+            ! hfx_dif = Heat flux diagnostic of sensible heat used to warm/cool ice in W.m-2   
+            hfx_dif_1d(ji) = hfx_dif_1d(ji) - zdq * r1_rdtice * a_i_1d(ji)
+            !
+         END DO
+         !
+         ! --- SIMIP diagnostics
+         !
+         DO ji = 1, npti
+            !--- Conduction fluxes (positive downwards)
+            diag_fc_bo_1d(ji) = diag_fc_bo_1d(ji) + fc_bo_i(ji) * a_i_1d(ji) / at_i_1d(ji)
+            diag_fc_su_1d(ji) = diag_fc_su_1d(ji) + fc_su  (ji) * a_i_1d(ji) / at_i_1d(ji)
+   
+            !--- Snow-ice interfacial temperature (diagnostic SIMIP)
+            zfac = rn_cnd_s * zh_i(ji) + ztcond_i(ji,1) * zh_s(ji)
+            IF( zh_s(ji) >= 1.e-3 .AND. zfac > epsi10 ) THEN
+               t_si_1d(ji) = ( rn_cnd_s       * zh_i(ji) * t_s_1d(ji,1) +   &
+                  &            ztcond_i(ji,1) * zh_s(ji) * t_i_1d(ji,1) ) / zfac
+            ELSE
+               t_si_1d(ji) = t_su_1d(ji)
+            ENDIF
+         END DO
+         !
+      ENDIF
+      !
+      !---------------------------------------------------------------------------------------
+      ! 11) Jules coupling: reset inner snow and ice temperatures, update conduction fluxes
+      !---------------------------------------------------------------------------------------
+      ! effective conductivity and 1st layer temperature (needed by Met Office)
+      DO ji = 1, npti
+         IF( h_s_1d(ji) > 0.1_wp ) THEN 
+            cnd_ice_1d(ji) = 2._wp * zkappa_s(ji,0)
+         ELSE
+            IF( h_i_1d(ji) > 0.1_wp ) THEN
+               cnd_ice_1d(ji) = 2._wp * zkappa_i(ji,0)
+            ELSE
+               cnd_ice_1d(ji) = 2._wp * ztcond_i(ji,0) / 0.1_wp
+            ENDIF
+         ENDIF
+         t1_ice_1d(ji) = isnow(ji) * t_s_1d(ji,1) + ( 1._wp - isnow(ji) ) * t_i_1d(ji,1)
+      END DO
+      !
+      IF( k_jules == np_jules_EMULE ) THEN
+         ! Restore temperatures to their initial values
+         t_s_1d    (1:npti,:) = ztsold(1:npti,:)
+         t_i_1d    (1:npti,:) = ztiold(1:npti,:)
+         qcn_ice_1d(1:npti)   = fc_su (1:npti)
+      ENDIF
+      !
+   END SUBROUTINE ice_thd_zdf_BL99
+
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option       Dummy Module             No ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icethd_zdf_BL99
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/iceupdate.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/iceupdate.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/iceupdate.F90	(revision 9019)
@@ -0,0 +1,467 @@
+MODULE iceupdate
+   !!======================================================================
+   !!                       ***  MODULE iceupdate   ***
+   !!  Sea-ice :   computation of the flux at the sea ice/ocean interface
+   !!======================================================================
+   !! History :   -   ! 2006-07 (M. Vancoppelle)  LIM3 original code
+   !!            3.0  ! 2008-03 (C. Tallandier)  surface module
+   !!             -   ! 2008-04 (C. Tallandier)  split in 2 + new ice-ocean coupling
+   !!            3.3  ! 2010-05 (G. Madec) decrease ocean & ice reference salinities in the Baltic sea
+   !!                 !                  + simplification of the ice-ocean stress calculation
+   !!            3.4  ! 2011-02 (G. Madec) dynamical allocation
+   !!             -   ! 2012    (D. Iovino) salt flux change
+   !!             -   ! 2012-05 (C. Rousset) add penetration solar flux
+   !!            3.5  ! 2012-10 (A. Coward, G. Madec) salt fluxes ; ice+snow mass
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_update_alloc : allocate the iceupdate arrays
+   !!   ice_update_init  : initialisation
+   !!   ice_update_flx   : updates mass, heat and salt fluxes at the ocean surface
+   !!   ice_update_tau   : update i- and j-stresses, and its modulus at the ocean surface
+   !!----------------------------------------------------------------------
+   USE oce     , ONLY : sshn, sshb
+   USE phycst         ! physical constants
+   USE dom_oce        ! ocean domain
+   USE ice            ! sea-ice: variables
+!!gm  It should be probably better to pass these variable in argument of the routine, 
+!!gm  rather than having this long list in USE. This will also highlight what is updated, and what is just use.
+   USE sbc_ice
+   USE sbc_oce
+!!gm end
+   USE sbccpl         ! Surface boundary condition: coupled interface
+   USE icealb         ! sea-ice: albedo parameters
+   USE traqsr         ! add penetration of solar flux in the calculation of heat budget
+   USE icectl         ! sea-ice: control prints
+   USE bdy_oce , ONLY : ln_bdy
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE lbclnk         ! lateral boundary conditions (or mpp links)
+   USE timing         ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_update_init   ! called by ice_init
+   PUBLIC   ice_update_flx    ! called by ice_stp
+   PUBLIC   ice_update_tau    ! called by ice_stp
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   utau_oce, vtau_oce   ! air-ocean surface i- & j-stress     [N/m2]
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tmod_io              ! modulus of the ice-ocean velocity   [m/s]
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: iceupdate.F90 8411 2017-08-07 16:09:12Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION ice_update_alloc()
+      !!-------------------------------------------------------------------
+      !!             ***  ROUTINE ice_update_alloc ***
+      !!-------------------------------------------------------------------
+      ALLOCATE( utau_oce(jpi,jpj), vtau_oce(jpi,jpj), tmod_io(jpi,jpj), STAT=ice_update_alloc )
+      !
+      IF( lk_mpp                )   CALL mpp_sum( ice_update_alloc )
+      IF( ice_update_alloc /= 0 )   CALL ctl_warn('ice_update_alloc: failed to allocate arrays')
+      !
+   END FUNCTION ice_update_alloc
+
+
+   SUBROUTINE ice_update_flx( kt )
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_update_flx ***
+      !!  
+      !! ** Purpose :   Update the surface ocean boundary condition for heat 
+      !!                salt and mass over areas where sea-ice is non-zero
+      !!         
+      !! ** Action  : - computes the heat and freshwater/salt fluxes
+      !!                at the ice-ocean interface.
+      !!              - Update the ocean sbc
+      !!     
+      !! ** Outputs : - qsr     : sea heat flux:     solar 
+      !!              - qns     : sea heat flux: non solar
+      !!              - emp     : freshwater budget: volume flux 
+      !!              - sfx     : salt flux 
+      !!              - fr_i    : ice fraction
+      !!              - tn_ice  : sea-ice surface temperature
+      !!              - alb_ice : sea-ice albedo (recomputed only for coupled mode)
+      !!
+      !! References : Goosse, H. et al. 1996, Bul. Soc. Roy. Sc. Liege, 65, 87-90.
+      !!              Tartinville et al. 2001 Ocean Modelling, 3, 95-108.
+      !!              These refs are now obsolete since everything has been revised
+      !!              The ref should be Rousset et al., 2015
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! number of iteration
+      !
+      INTEGER  ::   ji, jj, jl, jk   ! dummy loop indices
+      REAL(wp) ::   zqmass           ! Heat flux associated with mass exchange ice->ocean (W.m-2)
+      REAL(wp) ::   zqsr             ! New solar flux received by the ocean
+      REAL(wp), DIMENSION(jpi,jpj)     ::   z2d                  ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zalb_cs, zalb_os     ! 3D workspace
+      !!---------------------------------------------------------------------
+      IF( nn_timing == 1 )  CALL timing_start('ice_update')
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*)'ice_update_flx: update fluxes (mass, salt and heat) at the ice-ocean interface'
+         WRITE(numout,*)'~~~~~~~~~~~~~~'
+      ENDIF
+
+      ! --- case we bypass ice thermodynamics --- !
+      IF( .NOT. ln_icethd ) THEN   ! we suppose ice is impermeable => ocean is isolated from atmosphere
+         hfx_in   (:,:)   = ( 1._wp - at_i_b(:,:) ) * ( qns_oce(:,:) + qsr_oce(:,:) ) + qemp_oce(:,:)
+         hfx_out  (:,:)   = ( 1._wp - at_i_b(:,:) ) *   qns_oce(:,:)                  + qemp_oce(:,:)
+         ftr_ice  (:,:,:) = 0._wp
+         emp_ice  (:,:)   = 0._wp
+         qemp_ice (:,:)   = 0._wp
+         qevap_ice(:,:,:) = 0._wp
+      ENDIF
+      
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+
+            ! Solar heat flux reaching the ocean = zqsr (W.m-2) 
+            !---------------------------------------------------
+            zqsr = qsr_tot(ji,jj) - SUM( a_i_b(ji,jj,:) * ( qsr_ice(ji,jj,:) - ftr_ice(ji,jj,:) ) )
+
+            ! Total heat flux reaching the ocean = hfx_out (W.m-2) 
+            !---------------------------------------------------
+            zqmass         = hfx_thd(ji,jj) + hfx_dyn(ji,jj) + hfx_res(ji,jj) ! heat flux from snow is 0 (T=0 degC)
+            hfx_out(ji,jj) = hfx_out(ji,jj) + zqmass + zqsr
+
+            ! Add the residual from heat diffusion equation and sublimation (W.m-2)
+            !----------------------------------------------------------------------
+            hfx_out(ji,jj) = hfx_out(ji,jj) + hfx_err_dif(ji,jj) +   &
+               &           ( hfx_sub(ji,jj) - SUM( qevap_ice(ji,jj,:) * a_i_b(ji,jj,:) ) )
+
+            ! New qsr and qns used to compute the oceanic heat flux at the next time step
+            !----------------------------------------------------------------------------
+            qsr(ji,jj) = zqsr                                      
+            qns(ji,jj) = hfx_out(ji,jj) - zqsr              
+
+            ! Mass flux at the atm. surface       
+            !-----------------------------------
+            wfx_sub(ji,jj) = wfx_snw_sub(ji,jj) + wfx_ice_sub(ji,jj)
+
+            ! Mass flux at the ocean surface      
+            !------------------------------------
+            !  case of realistic freshwater flux (Tartinville et al., 2001) (presently ACTIVATED)
+            !  ------------------------------------------------------------------------------------- 
+            !  The idea of this approach is that the system that we consider is the ICE-OCEAN system
+            !  Thus  FW  flux  =  External ( E-P+snow melt)
+            !       Salt flux  =  Exchanges in the ice-ocean system then converted into FW
+            !                     Associated to Ice formation AND Ice melting
+            !                     Even if i see Ice melting as a FW and SALT flux
+            !        
+            ! mass flux from ice/ocean
+            wfx_ice(ji,jj) = wfx_bog(ji,jj) + wfx_bom(ji,jj) + wfx_sum(ji,jj) + wfx_sni(ji,jj)   &
+               &           + wfx_opw(ji,jj) + wfx_dyn(ji,jj) + wfx_res(ji,jj) + wfx_lam(ji,jj) + wfx_pnd(ji,jj)
+
+            ! add the snow melt water to snow mass flux to the ocean
+            wfx_snw(ji,jj) = wfx_snw_sni(ji,jj) + wfx_snw_dyn(ji,jj) + wfx_snw_sum(ji,jj)
+
+            ! mass flux at the ocean/ice interface
+            fmmflx(ji,jj) = - ( wfx_ice(ji,jj) + wfx_snw(ji,jj) + wfx_err_sub(ji,jj) )              ! F/M mass flux save at least for biogeochemical model
+            emp(ji,jj)    = emp_oce(ji,jj) - wfx_ice(ji,jj) - wfx_snw(ji,jj) - wfx_err_sub(ji,jj)   ! mass flux + F/M mass flux (always ice/ocean mass exchange)
+
+
+            ! Salt flux at the ocean surface      
+            !------------------------------------------
+            sfx(ji,jj) = sfx_bog(ji,jj) + sfx_bom(ji,jj) + sfx_sum(ji,jj) + sfx_sni(ji,jj) + sfx_opw(ji,jj)   &
+               &       + sfx_res(ji,jj) + sfx_dyn(ji,jj) + sfx_bri(ji,jj) + sfx_sub(ji,jj) + sfx_lam(ji,jj)
+            
+            ! Mass of snow and ice per unit area   
+            !----------------------------------------
+            snwice_mass_b(ji,jj) = snwice_mass(ji,jj)       ! save mass from the previous ice time step
+            !                                               ! new mass per unit area
+            snwice_mass  (ji,jj) = tmask(ji,jj,1) * ( rhosn * vt_s(ji,jj) + rhoic * vt_i(ji,jj)  ) 
+            !                                               ! time evolution of snow+ice mass
+            snwice_fmass (ji,jj) = ( snwice_mass(ji,jj) - snwice_mass_b(ji,jj) ) * r1_rdtice
+            
+         END DO
+      END DO
+
+      ! Storing the transmitted variables
+      !----------------------------------
+      fr_i  (:,:)   = at_i(:,:)             ! Sea-ice fraction            
+      tn_ice(:,:,:) = t_su(:,:,:)           ! Ice surface temperature                      
+
+      ! Snow/ice albedo (only if sent to coupler, useless in forced mode)
+      !------------------------------------------------------------------
+      CALL ice_alb( t_su, h_i, h_s, ln_pnd_alb, a_ip_frac, h_ip, zalb_cs, zalb_os ) ! cloud-sky and overcast-sky ice albedos
+      !
+      alb_ice(:,:,:) = ( 1._wp - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:)
+      !
+      IF( lrst_ice ) THEN                       !* write snwice_mass fields in the restart file
+         CALL update_rst( 'WRITE', kt )
+      ENDIF
+      !
+      ! output all fluxes
+      !------------------
+      !
+      ! --- salt fluxes [kg/m2/s] --- !
+      !                           ! sfxice =  sfxbog + sfxbom + sfxsum + sfxsni + sfxopw + sfxres + sfxdyn + sfxbri + sfxsub + sfxlam
+      IF( iom_use('sfxice'  ) )   CALL iom_put( "sfxice", sfx     * 1.e-03 )   ! salt flux from total ice growth/melt
+      IF( iom_use('sfxbog'  ) )   CALL iom_put( "sfxbog", sfx_bog * 1.e-03 )   ! salt flux from bottom growth
+      IF( iom_use('sfxbom'  ) )   CALL iom_put( "sfxbom", sfx_bom * 1.e-03 )   ! salt flux from bottom melting
+      IF( iom_use('sfxsum'  ) )   CALL iom_put( "sfxsum", sfx_sum * 1.e-03 )   ! salt flux from surface melting
+      IF( iom_use('sfxlam'  ) )   CALL iom_put( "sfxlam", sfx_lam * 1.e-03 )   ! salt flux from lateral melting
+      IF( iom_use('sfxsni'  ) )   CALL iom_put( "sfxsni", sfx_sni * 1.e-03 )   ! salt flux from snow ice formation
+      IF( iom_use('sfxopw'  ) )   CALL iom_put( "sfxopw", sfx_opw * 1.e-03 )   ! salt flux from open water formation
+      IF( iom_use('sfxdyn'  ) )   CALL iom_put( "sfxdyn", sfx_dyn * 1.e-03 )   ! salt flux from ridging rafting
+      IF( iom_use('sfxbri'  ) )   CALL iom_put( "sfxbri", sfx_bri * 1.e-03 )   ! salt flux from brines
+      IF( iom_use('sfxres'  ) )   CALL iom_put( "sfxres", sfx_res * 1.e-03 )   ! salt flux from undiagnosed processes
+      IF( iom_use('sfxsub'  ) )   CALL iom_put( "sfxsub", sfx_sub * 1.e-03 )   ! salt flux from sublimation
+
+      ! --- mass fluxes [kg/m2/s] --- !
+      IF( iom_use('emp_oce' ) )   CALL iom_put( "emp_oce", emp_oce )   ! emp over ocean (taking into account the snow blown away from the ice)
+      IF( iom_use('emp_ice' ) )   CALL iom_put( "emp_ice", emp_ice )   ! emp over ice   (taking into account the snow blown away from the ice)
+
+      !                           ! vfxice = vfxbog + vfxbom + vfxsum + vfxsni + vfxopw + vfxdyn + vfxres + vfxlam + vfxpnd
+      IF( iom_use('vfxice'  ) )   CALL iom_put( "vfxice" , wfx_ice )   ! mass flux from total ice growth/melt
+      IF( iom_use('vfxbog'  ) )   CALL iom_put( "vfxbog" , wfx_bog )   ! mass flux from bottom growth
+      IF( iom_use('vfxbom'  ) )   CALL iom_put( "vfxbom" , wfx_bom )   ! mass flux from bottom melt 
+      IF( iom_use('vfxsum'  ) )   CALL iom_put( "vfxsum" , wfx_sum )   ! mass flux from surface melt 
+      IF( iom_use('vfxlam'  ) )   CALL iom_put( "vfxlam" , wfx_lam )   ! mass flux from lateral melt 
+      IF( iom_use('vfxsni'  ) )   CALL iom_put( "vfxsni" , wfx_sni )   ! mass flux from snow-ice formation
+      IF( iom_use('vfxopw'  ) )   CALL iom_put( "vfxopw" , wfx_opw )   ! mass flux from growth in open water
+      IF( iom_use('vfxdyn'  ) )   CALL iom_put( "vfxdyn" , wfx_dyn )   ! mass flux from dynamics (ridging)
+      IF( iom_use('vfxres'  ) )   CALL iom_put( "vfxres" , wfx_res )   ! mass flux from undiagnosed processes 
+      IF( iom_use('vfxpnd'  ) )   CALL iom_put( "vfxpnd" , wfx_pnd )   ! mass flux from melt ponds
+      IF( iom_use('vfxsub'  ) )   CALL iom_put( "vfxsub" , wfx_ice_sub )   ! mass flux from ice sublimation (ice-atm.)
+      IF( iom_use('vfxsub_err') ) CALL iom_put( "vfxsub_err", wfx_err_sub )   ! "excess" of sublimation sent to ocean      
+
+      IF ( iom_use( "vfxthin" ) ) THEN   ! mass flux from ice growth in open water + thin ice (<20cm) => comparable to observations  
+         WHERE( hm_i(:,:) < 0.2 .AND. hm_i(:,:) > 0. ) ; z2d = wfx_bog
+         ELSEWHERE                                     ; z2d = 0._wp
+         END WHERE
+         CALL iom_put( "vfxthin", wfx_opw + z2d )
+      ENDIF
+
+      !                              ! vfxsnw = vfxsnw_sni + vfxsnw_dyn + vfxsnw_sum
+      IF( iom_use('vfxsnw'     ) )   CALL iom_put( "vfxsnw"     , wfx_snw     )   ! mass flux from total snow growth/melt
+      IF( iom_use('vfxsnw_sum' ) )   CALL iom_put( "vfxsnw_sum" , wfx_snw_sum )   ! mass flux from snow melt at the surface
+      IF( iom_use('vfxsnw_sni' ) )   CALL iom_put( "vfxsnw_sni" , wfx_snw_sni )   ! mass flux from snow melt during snow-ice formation 
+      IF( iom_use('vfxsnw_dyn' ) )   CALL iom_put( "vfxsnw_dyn" , wfx_snw_dyn )   ! mass flux from dynamics (ridging) 
+      IF( iom_use('vfxsnw_sub' ) )   CALL iom_put( "vfxsnw_sub" , wfx_snw_sub )   ! mass flux from snow sublimation (ice-atm.) 
+      IF( iom_use('vfxsnw_pre' ) )   CALL iom_put( "vfxsnw_pre" , wfx_spr     )   ! snow precip
+
+      ! --- heat fluxes [W/m2] --- !
+      !                              ! qt_atm_oi - qt_oce_ai = hfxdhc - ( dihctrp + dshctrp )
+      IF( iom_use('qsr_oce'    ) )   CALL iom_put( "qsr_oce"    , qsr_oce * ( 1._wp - at_i_b )                               )   !     solar flux at ocean surface
+      IF( iom_use('qns_oce'    ) )   CALL iom_put( "qns_oce"    , qns_oce * ( 1._wp - at_i_b ) + qemp_oce                    )   ! non-solar flux at ocean surface
+      IF( iom_use('qsr_ice'    ) )   CALL iom_put( "qsr_ice"    , SUM( qsr_ice * a_i_b, dim=3 )                              )   !     solar flux at ice surface
+      IF( iom_use('qns_ice'    ) )   CALL iom_put( "qns_ice"    , SUM( qns_ice * a_i_b, dim=3 ) + qemp_ice                   )   ! non-solar flux at ice surface
+      IF( iom_use('qtr_ice_bot') )   CALL iom_put( "qtr_ice_bot", SUM( ftr_ice * a_i_b, dim=3 )                              )   !     solar flux transmitted thru ice
+      IF( iom_use('qtr_ice_top') )   CALL iom_put( "qtr_ice_top", SUM( qsr_ice_tr * a_i_b, dim=3 )                           )   !     solar flux transmitted thru ice surface
+      IF( iom_use('qt_oce'     ) )   CALL iom_put( "qt_oce"     ,      ( qsr_oce + qns_oce ) * ( 1._wp - at_i_b ) + qemp_oce )
+      IF( iom_use('qt_ice'     ) )   CALL iom_put( "qt_ice"     , SUM( ( qns_ice + qsr_ice ) * a_i_b, dim=3 )     + qemp_ice )
+      IF( iom_use('qt_oce_ai'  ) )   CALL iom_put( "qt_oce_ai"  , hfx_out                                                    )   ! total heat flux at the ocean   surface: interface oce-(ice+atm) 
+      IF( iom_use('qt_atm_oi'  ) )   CALL iom_put( "qt_atm_oi"  , hfx_in                                                     )   ! total heat flux at the oce-ice surface: interface atm-(ice+oce) 
+      IF( iom_use('qemp_oce'   ) )   CALL iom_put( "qemp_oce"   , qemp_oce                                                   )   ! Downward Heat Flux from E-P over ocean
+      IF( iom_use('qemp_ice'   ) )   CALL iom_put( "qemp_ice"   , qemp_ice                                                   )   ! Downward Heat Flux from E-P over ice
+
+      ! heat fluxes from ice transformations
+      !                              ! hfxdhc = hfxbog + hfxbom + hfxsum + hfxopw + hfxdif + hfxsnw - ( hfxthd + hfxdyn + hfxres + hfxsub + hfxspr )
+      IF( iom_use('hfxbog'     ) )   CALL iom_put ("hfxbog"     , hfx_bog             )   ! heat flux used for ice bottom growth 
+      IF( iom_use('hfxbom'     ) )   CALL iom_put ("hfxbom"     , hfx_bom             )   ! heat flux used for ice bottom melt
+      IF( iom_use('hfxsum'     ) )   CALL iom_put ("hfxsum"     , hfx_sum             )   ! heat flux used for ice surface growth
+      IF( iom_use('hfxopw'     ) )   CALL iom_put ("hfxopw"     , hfx_opw             )   ! heat flux used for ice formation in open water
+      IF( iom_use('hfxdif'     ) )   CALL iom_put ("hfxdif"     , hfx_dif             )   ! heat flux used for ice temperature change
+      IF( iom_use('hfxsnw'     ) )   CALL iom_put ("hfxsnw"     , hfx_snw             )   ! heat flux used for snow melt 
+      IF( iom_use('hfxerr'     ) )   CALL iom_put ("hfxerr"     , hfx_err_dif         )   ! heat flux error after heat diffusion (included in hfx_out)
+
+      ! heat fluxes associated with mass exchange (freeze/melt/precip...)
+      IF( iom_use('hfxthd'     ) )   CALL iom_put ("hfxthd"     , hfx_thd             )   !  
+      IF( iom_use('hfxdyn'     ) )   CALL iom_put ("hfxdyn"     , hfx_dyn             )   !  
+      IF( iom_use('hfxres'     ) )   CALL iom_put ("hfxres"     , hfx_res             )   !  
+      IF( iom_use('hfxsub'     ) )   CALL iom_put ("hfxsub"     , hfx_sub             )   !  
+      IF( iom_use('hfxspr'     ) )   CALL iom_put ("hfxspr"     , hfx_spr             )   ! Heat flux from snow precip heat content 
+
+      ! other heat fluxes
+      IF( iom_use('hfxsensib'  ) )   CALL iom_put( "hfxsensib"  , -fhtur     * at_i_b )   ! Sensible oceanic heat flux
+      IF( iom_use('hfxcndbot'  ) )   CALL iom_put( "hfxcndbot"  , diag_fc_bo * at_i_b )   ! Bottom conduction flux
+      IF( iom_use('hfxcndtop'  ) )   CALL iom_put( "hfxcndtop"  , diag_fc_su * at_i_b )   ! Surface conduction flux
+
+      ! diags
+      IF( iom_use('hfxdhc'     ) )   CALL iom_put ("hfxdhc"     , diag_heat           )   ! Heat content variation in snow and ice 
+      !
+      ! controls
+      !---------
+      IF( ln_icediachk .AND. .NOT. ln_bdy)   CALL ice_cons_final('iceupdate')                                       ! conservation
+      IF( ln_icectl                      )   CALL ice_prt       (kt, iiceprt, jiceprt, 3, 'Final state ice_update') ! prints
+      IF( ln_ctl                         )   CALL ice_prt3D     ('iceupdate')                                       ! prints
+      IF( nn_timing == 1                 )   CALL timing_stop   ('ice_update')                                      ! timing
+      !
+   END SUBROUTINE ice_update_flx
+
+
+   SUBROUTINE ice_update_tau( kt, pu_oce, pv_oce )
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_update_tau ***
+      !!  
+      !! ** Purpose : Update the ocean surface stresses due to the ice
+      !!         
+      !! ** Action  : * at each ice time step (every nn_fsbc time step):
+      !!                - compute the modulus of ice-ocean relative velocity 
+      !!                  (*rho*Cd) at T-point (C-grid) or I-point (B-grid)
+      !!                      tmod_io = rhoco * | U_ice-U_oce |
+      !!                - update the modulus of stress at ocean surface
+      !!                      taum = (1-a) * taum + a * tmod_io * | U_ice-U_oce |
+      !!              * at each ocean time step (every kt): 
+      !!                  compute linearized ice-ocean stresses as
+      !!                      Utau = tmod_io * | U_ice - pU_oce |
+      !!                using instantaneous current ocean velocity (usually before)
+      !!
+      !!    NB: - ice-ocean rotation angle no more allowed
+      !!        - here we make an approximation: taum is only computed every ice time step
+      !!          This avoids mutiple average to pass from T -> U,V grids and next from U,V grids 
+      !!          to T grid. taum is used in TKE and GLS, which should not be too sensitive to this approximaton...
+      !!
+      !! ** Outputs : - utau, vtau   : surface ocean i- and j-stress (u- & v-pts) updated with ice-ocean fluxes
+      !!              - taum         : modulus of the surface ocean stress (T-point) updated with ice-ocean fluxes
+      !!---------------------------------------------------------------------
+      INTEGER ,                     INTENT(in) ::   kt               ! ocean time-step index
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pu_oce, pv_oce   ! surface ocean currents
+      !
+      INTEGER  ::   ji, jj   ! dummy loop indices
+      REAL(wp) ::   zat_u, zutau_ice, zu_t, zmodt   ! local scalar
+      REAL(wp) ::   zat_v, zvtau_ice, zv_t, zrhoco  !   -      -
+      !!---------------------------------------------------------------------
+
+      IF( nn_timing == 1 )  CALL timing_start('ice_update_tau')
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*)'ice_update_tau: update stress at the ice-ocean interface'
+         WRITE(numout,*)'~~~~~~~~~~~~~~'
+      ENDIF
+
+      zrhoco = rau0 * rn_cio
+      !
+      IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN     !==  Ice time-step only  ==!   (i.e. surface module time-step)
+         DO jj = 2, jpjm1                             !* update the modulus of stress at ocean surface (T-point)
+            DO ji = fs_2, fs_jpim1
+               !                                               ! 2*(U_ice-U_oce) at T-point
+               zu_t = u_ice(ji,jj) + u_ice(ji-1,jj) - u_oce(ji,jj) - u_oce(ji-1,jj)   
+               zv_t = v_ice(ji,jj) + v_ice(ji,jj-1) - v_oce(ji,jj) - v_oce(ji,jj-1) 
+               !                                              ! |U_ice-U_oce|^2
+               zmodt =  0.25_wp * (  zu_t * zu_t + zv_t * zv_t  )
+               !                                               ! update the ocean stress modulus
+               taum(ji,jj) = ( 1._wp - at_i(ji,jj) ) * taum(ji,jj) + at_i(ji,jj) * zrhoco * zmodt
+               tmod_io(ji,jj) = zrhoco * SQRT( zmodt )          ! rhoco * |U_ice-U_oce| at T-point
+            END DO
+         END DO
+         CALL lbc_lnk_multi( taum, 'T', 1., tmod_io, 'T', 1. )
+         !
+         utau_oce(:,:) = utau(:,:)                    !* save the air-ocean stresses at ice time-step
+         vtau_oce(:,:) = vtau(:,:)
+         !
+      ENDIF
+      !
+      !                                      !==  every ocean time-step  ==!
+      !
+      DO jj = 2, jpjm1                                !* update the stress WITHOUT an ice-ocean rotation angle
+         DO ji = fs_2, fs_jpim1   ! Vect. Opt.
+            zat_u  = ( at_i(ji,jj) + at_i(ji+1,jj) ) * 0.5_wp   ! ice area at u and V-points
+            zat_v  = ( at_i(ji,jj) + at_i(ji,jj+1) ) * 0.5_wp
+            !                                                   ! linearized quadratic drag formulation
+            zutau_ice   = 0.5_wp * ( tmod_io(ji,jj) + tmod_io(ji+1,jj) ) * ( u_ice(ji,jj) - pu_oce(ji,jj) )
+            zvtau_ice   = 0.5_wp * ( tmod_io(ji,jj) + tmod_io(ji,jj+1) ) * ( v_ice(ji,jj) - pv_oce(ji,jj) )
+            !                                                   ! stresses at the ocean surface
+            utau(ji,jj) = ( 1._wp - zat_u ) * utau_oce(ji,jj) + zat_u * zutau_ice
+            vtau(ji,jj) = ( 1._wp - zat_v ) * vtau_oce(ji,jj) + zat_v * zvtau_ice
+         END DO
+      END DO
+      CALL lbc_lnk_multi( utau, 'U', -1., vtau, 'V', -1. )   ! lateral boundary condition
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('ice_update_tau')
+      !  
+   END SUBROUTINE ice_update_tau
+
+
+   SUBROUTINE ice_update_init
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_update_init  ***
+      !!             
+      !! ** Purpose :   ???
+      !!
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk               ! dummy loop indices
+      REAL(wp) ::   zcoefu, zcoefv, zcoeff   ! local scalar
+      !!-------------------------------------------------------------------
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'ice_update_init: ???? '
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~'
+
+      !                                      ! allocate ice_update array
+      IF( ice_update_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'ice_update_init : unable to allocate standard arrays' )
+      !
+      CALL update_rst( 'READ' )  !* read or initialize all required files
+      !
+   END SUBROUTINE ice_update_init
+
+   SUBROUTINE update_rst( cdrw, kt )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE rhg_evp_rst  ***
+      !!                     
+      !! ** Purpose :   Read or write RHG file in restart file
+      !!
+      !! ** Method  :   use of IOM library
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*) , INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
+      INTEGER, OPTIONAL, INTENT(in) ::   kt     ! ice time-step
+      !
+      INTEGER  ::   iter   ! local integer
+      INTEGER  ::   id1    ! local integer
+      !!----------------------------------------------------------------------
+      !
+      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialize
+         !                                   ! ---------------
+         IF( ln_rstart ) THEN                   !* Read the restart file
+            !
+            id1 = iom_varid( numrir, 'snwice_mass' , ldstop = .FALSE. )
+            !
+            IF( id1 > 0 ) THEN                       ! fields exist
+               CALL iom_get( numrir, jpdom_autoglo, 'snwice_mass'  , snwice_mass   )
+               CALL iom_get( numrir, jpdom_autoglo, 'snwice_mass_b', snwice_mass_b )
+            ELSE                                     ! start from rest
+               IF(lwp) WRITE(numout,*) '   ==>>   previous run without snow-ice mass output then set it'
+               snwice_mass  (:,:) = tmask(:,:,1) * ( rhosn * vt_s(:,:) + rhoic * vt_i(:,:) )
+               snwice_mass_b(:,:) = snwice_mass(:,:)
+            ENDIF
+         ELSE                                   !* Start from rest
+            IF(lwp) WRITE(numout,*) '   ==>>   start from rest: set the snow-ice mass'
+            snwice_mass  (:,:) = tmask(:,:,1) * ( rhosn * vt_s(:,:) + rhoic * vt_i(:,:) )
+            snwice_mass_b(:,:) = snwice_mass(:,:)
+         ENDIF
+         !
+      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
+         !                                   ! -------------------
+         IF(lwp) WRITE(numout,*) '---- update-rst ----'
+         iter = kt + nn_fsbc - 1             ! ice restarts are written at kt == nitrst - nn_fsbc + 1
+         !
+         CALL iom_rstput( iter, nitrst, numriw, 'snwice_mass'  , snwice_mass   )
+         CALL iom_rstput( iter, nitrst, numriw, 'snwice_mass_b', snwice_mass_b )
+         !
+      ENDIF
+      !
+   END SUBROUTINE update_rst
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Dummy module           NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif 
+
+   !!======================================================================
+END MODULE iceupdate
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icevar.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icevar.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icevar.F90	(revision 9019)
@@ -0,0 +1,863 @@
+MODULE icevar
+   !!======================================================================
+   !!                       ***  MODULE icevar ***
+   !!   sea-ice:     Different sets of ice model variables 
+   !!                   how to switch from one to another
+   !!
+   !!                 There are three sets of variables
+   !!                 VGLO : global variables of the model
+   !!                        - v_i (jpi,jpj,jpl)
+   !!                        - v_s (jpi,jpj,jpl)
+   !!                        - a_i (jpi,jpj,jpl)
+   !!                        - t_s (jpi,jpj,jpl)
+   !!                        - e_i (jpi,jpj,nlay_i,jpl)
+   !!                        - sv_i(jpi,jpj,jpl)
+   !!                        - oa_i(jpi,jpj,jpl)
+   !!                 VEQV : equivalent variables sometimes used in the model
+   !!                        - h_i(jpi,jpj,jpl)
+   !!                        - h_s(jpi,jpj,jpl)
+   !!                        - t_i(jpi,jpj,nlay_i,jpl)
+   !!                        ...
+   !!                 VAGG : aggregate variables, averaged/summed over all
+   !!                        thickness categories
+   !!                        - vt_i(jpi,jpj)
+   !!                        - vt_s(jpi,jpj)
+   !!                        - at_i(jpi,jpj)
+   !!                        - et_s(jpi,jpj)  !total snow heat content
+   !!                        - et_i(jpi,jpj)  !total ice thermal content 
+   !!                        - sm_i(jpi,jpj) !mean ice salinity
+   !!                        - tm_i (jpi,jpj) !mean ice temperature
+   !!======================================================================
+   !! History :   -   ! 2006-01 (M. Vancoppenolle) Original code
+   !!            3.4  ! 2011-02 (G. Madec) dynamical allocation
+   !!            3.5  ! 2012    (M. Vancoppenolle)  add ice_var_itd
+   !!            3.6  ! 2014-01 (C. Rousset) add ice_var_zapsmall, rewrite ice_var_itd
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_var_agg       : integrate variables over layers and categories
+   !!   ice_var_glo2eqv   : transform from VGLO to VEQV
+   !!   ice_var_eqv2glo   : transform from VEQV to VGLO
+   !!   ice_var_salprof   : salinity profile in the ice
+   !!   ice_var_salprof1d : salinity profile in the ice 1D
+   !!   ice_var_zapsmall  : remove very small area and volume
+   !!   ice_var_itd       : convert 1-cat to jpl-cat
+   !!   ice_var_itd2      : convert N-cat to jpl-cat
+   !!   ice_var_bv        : brine volume
+   !!   ice_var_enthalpy  : compute ice and snow enthalpies from temperature
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants (ocean directory) 
+   USE sbc_oce , ONLY : sss_m
+   USE ice            ! sea-ice: variables
+   USE ice1D          ! sea-ice: thermodynamics variables
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_var_agg          
+   PUBLIC   ice_var_glo2eqv      
+   PUBLIC   ice_var_eqv2glo      
+   PUBLIC   ice_var_salprof      
+   PUBLIC   ice_var_salprof1d    
+   PUBLIC   ice_var_zapsmall
+   PUBLIC   ice_var_itd
+   PUBLIC   ice_var_itd2
+   PUBLIC   ice_var_bv           
+   PUBLIC   ice_var_enthalpy           
+
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icevar.F90 8422 2017-08-08 13:58:05Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_var_agg( kn )
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_var_agg  ***
+      !!
+      !! ** Purpose :   aggregates ice-thickness-category variables to 
+      !!              all-ice variables, i.e. it turns VGLO into VAGG
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kn     ! =1 state variables only
+      !                                 ! >1 state variables + others
+      !
+      INTEGER ::   ji, jj, jk, jl   ! dummy loop indices
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   z1_at_i, z1_vt_i
+      !!-------------------------------------------------------------------
+      !
+      !                                      ! integrated values
+      vt_i(:,:) =       SUM( v_i(:,:,:)           , dim=3 )
+      vt_s(:,:) =       SUM( v_s(:,:,:)           , dim=3 )
+      at_i(:,:) =       SUM( a_i(:,:,:)           , dim=3 )
+      et_s(:,:)  = SUM( SUM( e_s(:,:,:,:), dim=4 ), dim=3 )
+      et_i(:,:)  = SUM( SUM( e_i(:,:,:,:), dim=4 ), dim=3 )
+      !
+      at_ip(:,:) = SUM( a_ip(:,:,:), dim=3 ) ! melt ponds
+      vt_ip(:,:) = SUM( v_ip(:,:,:), dim=3 )
+      !
+      ato_i(:,:) = 1._wp - at_i(:,:)         ! open water fraction  
+
+      IF( kn > 1 ) THEN
+         !
+         ALLOCATE( z1_at_i(jpi,jpj) , z1_vt_i(jpi,jpj) )
+         WHERE( at_i(:,:) > epsi20 )   ;   z1_at_i(:,:) = 1._wp / at_i(:,:)
+         ELSEWHERE                     ;   z1_at_i(:,:) = 0._wp
+         END WHERE
+         WHERE( vt_i(:,:) > epsi20 )   ;   z1_vt_i(:,:) = 1._wp / vt_i(:,:)
+         ELSEWHERE                     ;   z1_vt_i(:,:) = 0._wp
+         END WHERE
+         !
+         !                          ! mean ice/snow thickness
+         hm_i(:,:) = vt_i(:,:) * z1_at_i(:,:)
+         hm_s(:,:) = vt_s(:,:) * z1_at_i(:,:)
+         !         
+         !                          ! mean temperature (K), salinity and age
+         tm_su(:,:) = SUM( t_su(:,:,:) * a_i(:,:,:) , dim=3 ) * z1_at_i(:,:)
+         tm_si(:,:) = SUM( t_si(:,:,:) * a_i(:,:,:) , dim=3 ) * z1_at_i(:,:)
+         om_i (:,:) = SUM( oa_i(:,:,:)              , dim=3 ) * z1_at_i(:,:)
+         !
+         tm_i(:,:) = 0._wp
+         sm_i(:,:) = 0._wp
+         DO jl = 1, jpl
+            DO jk = 1, nlay_i
+               tm_i(:,:) = tm_i(:,:) + r1_nlay_i * t_i (:,:,jk,jl) * v_i(:,:,jl) * z1_vt_i(:,:)
+               sm_i(:,:) = sm_i(:,:) + r1_nlay_i * sz_i(:,:,jk,jl) * v_i(:,:,jl) * z1_vt_i(:,:)
+            END DO
+         END DO
+         !
+         !                           ! put rt0 where there is no ice
+         WHERE( at_i(:,:)<=epsi20 )
+            tm_su(:,:) = rt0
+            tm_si(:,:) = rt0
+            tm_i (:,:) = rt0
+         END WHERE
+
+         DEALLOCATE( z1_at_i , z1_vt_i )
+      ENDIF
+      !
+   END SUBROUTINE ice_var_agg
+
+
+   SUBROUTINE ice_var_glo2eqv
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_var_glo2eqv ***
+      !!
+      !! ** Purpose :   computes equivalent variables as function of  
+      !!              global variables, i.e. it turns VGLO into VEQV
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
+      REAL(wp) ::   ze_i             ! local scalars
+      REAL(wp) ::   ze_s, ztmelts, zbbb, zccc       !   -      -
+      REAL(wp) ::   zhmax, z1_zhmax                 !   -      -
+      REAL(wp) ::   zlay_i, zlay_s                  !   -      -
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z1_a_i, z1_v_i
+      !!-------------------------------------------------------------------
+
+!!gm Question 2:  It is possible to define existence of sea-ice in a common way between 
+!!                ice area and ice volume ?
+!!                the idea is to be able to define one for all at the begining of this routine
+!!                a criteria for icy area (i.e. a_i > epsi20 and v_i > epsi20 )
+
+      !---------------------------------------------------------------
+      ! Ice thickness, snow thickness, ice salinity, ice age and ponds
+      !---------------------------------------------------------------
+      !                                            !--- inverse of the ice area
+      WHERE( a_i(:,:,:) > epsi20 )   ;   z1_a_i(:,:,:) = 1._wp / a_i(:,:,:)
+      ELSEWHERE                      ;   z1_a_i(:,:,:) = 0._wp
+      END WHERE
+      !
+      WHERE( v_i(:,:,:) > epsi20 )   ;   z1_v_i(:,:,:) = 1._wp / v_i(:,:,:)
+      ELSEWHERE                      ;   z1_v_i(:,:,:) = 0._wp
+      END WHERE
+      !                                           !--- ice thickness
+      h_i(:,:,:) = v_i (:,:,:) * z1_a_i(:,:,:)
+
+      zhmax    =          hi_max(jpl)
+      z1_zhmax =  1._wp / hi_max(jpl)               
+      WHERE( h_i(:,:,jpl) > zhmax )   ! bound h_i by hi_max (i.e. 99 m) with associated update of ice area
+         h_i  (:,:,jpl) = zhmax
+         a_i   (:,:,jpl) = v_i(:,:,jpl) * z1_zhmax 
+         z1_a_i(:,:,jpl) = zhmax * z1_v_i(:,:,jpl)
+      END WHERE
+      !                                           !--- snow thickness
+      h_s(:,:,:) = v_s (:,:,:) * z1_a_i(:,:,:)
+      !                                           !--- ice age      
+      o_i(:,:,:) = oa_i(:,:,:) * z1_a_i(:,:,:)
+      !                                           !--- pond fraction and thickness      
+      a_ip_frac(:,:,:) = a_ip(:,:,:) * z1_a_i(:,:,:)
+      WHERE( a_ip_frac(:,:,:) > epsi20 )   ;   h_ip(:,:,:) = v_ip(:,:,:) * z1_a_i(:,:,:) / a_ip_frac(:,:,:)
+      ELSEWHERE                            ;   h_ip(:,:,:) = 0._wp
+      END WHERE
+      !
+      !                                           !---  salinity (with a minimum value imposed everywhere)     
+      IF( nn_icesal == 2 ) THEN
+         WHERE( v_i(:,:,:) > epsi20 )   ;   s_i(:,:,:) = MAX( rn_simin , MIN( rn_simax, sv_i(:,:,:) * z1_v_i(:,:,:) ) )
+         ELSEWHERE                      ;   s_i(:,:,:) = rn_simin
+         END WHERE
+      ENDIF
+      CALL ice_var_salprof   ! salinity profile
+
+      !-------------------
+      ! Ice temperature   [K]   (with a minimum value (rt0 - 100.))
+      !-------------------
+      zlay_i   = REAL( nlay_i , wp )    ! number of layers
+      DO jl = 1, jpl
+         DO jk = 1, nlay_i
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  IF ( v_i(ji,jj,jl) > epsi20 ) THEN     !--- icy area 
+                     !
+                     ze_i             =   e_i (ji,jj,jk,jl) * z1_v_i(ji,jj,jl) * zlay_i               ! Energy of melting e(S,T) [J.m-3]
+                     ztmelts          = - sz_i(ji,jj,jk,jl) * tmut                                 ! Ice layer melt temperature [C]
+                     ! Conversion q(S,T) -> T (second order equation)
+                     zbbb             = ( rcp - cpic ) * ztmelts + ze_i * r1_rhoic - lfus
+                     zccc             = SQRT( MAX( zbbb * zbbb - 4._wp * cpic * lfus * ztmelts , 0._wp) )
+                     t_i(ji,jj,jk,jl) = MAX( -100._wp , MIN( -( zbbb + zccc ) * 0.5_wp * r1_cpic , ztmelts ) ) + rt0   ! [K] with bounds: -100 < t_i < ztmelts
+                     !
+                  ELSE                                !--- no ice
+                     t_i(ji,jj,jk,jl) = rt0
+                  ENDIF
+               END DO
+            END DO
+         END DO
+      END DO
+
+      !--------------------
+      ! Snow temperature   [K]   (with a minimum value (rt0 - 100.))
+      !--------------------
+      zlay_s = REAL( nlay_s , wp )
+      DO jk = 1, nlay_s
+         WHERE( v_s(:,:,:) > epsi20 )        !--- icy area
+            t_s(:,:,jk,:) = MAX( -100._wp , MIN( r1_cpic * ( -r1_rhosn * (e_s(:,:,jk,:)/v_s(:,:,:)*zlay_s) + lfus ) , 0._wp ) ) + rt0
+         ELSEWHERE                           !--- no ice
+            t_s(:,:,jk,:) = rt0
+         END WHERE
+      END DO
+      !
+      ! integrated values 
+      vt_i (:,:) = SUM( v_i, dim=3 )
+      vt_s (:,:) = SUM( v_s, dim=3 )
+      at_i (:,:) = SUM( a_i, dim=3 )
+      !
+   END SUBROUTINE ice_var_glo2eqv
+
+
+   SUBROUTINE ice_var_eqv2glo
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_var_eqv2glo ***
+      !!
+      !! ** Purpose :   computes global variables as function of 
+      !!              equivalent variables,  i.e. it turns VEQV into VGLO
+      !!-------------------------------------------------------------------
+      !
+      v_i (:,:,:) = h_i (:,:,:) * a_i (:,:,:)
+      v_s (:,:,:) = h_s (:,:,:) * a_i (:,:,:)
+      sv_i(:,:,:) = s_i (:,:,:) * v_i (:,:,:)
+      v_ip(:,:,:) = h_ip(:,:,:) * a_ip(:,:,:)
+      !
+   END SUBROUTINE ice_var_eqv2glo
+
+
+   SUBROUTINE ice_var_salprof
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_var_salprof ***
+      !!
+      !! ** Purpose :   computes salinity profile in function of bulk salinity     
+      !!
+      !! ** Method  : If bulk salinity greater than zsi1, 
+      !!              the profile is assumed to be constant (S_inf)
+      !!              If bulk salinity lower than zsi0,
+      !!              the profile is linear with 0 at the surface (S_zero)
+      !!              If it is between zsi0 and zsi1, it is a
+      !!              alpha-weighted linear combination of s_inf and s_zero
+      !!
+      !! ** References : Vancoppenolle et al., 2007
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk, jl   ! dummy loop index
+      REAL(wp) ::   zsal, z1_dS
+      REAL(wp) ::   zargtemp , zs0, zs
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   z_slope_s, zalpha    ! case 2 only
+      REAL(wp), PARAMETER :: zsi0 = 3.5_wp
+      REAL(wp), PARAMETER :: zsi1 = 4.5_wp
+      !!-------------------------------------------------------------------
+
+!!gm Question: Remove the option 3 ?  How many years since it last use ? 
+
+      SELECT CASE ( nn_icesal )
+      !
+      !               !---------------------------------------!
+      CASE( 1 )       !  constant salinity in time and space  !
+         !            !---------------------------------------!
+         sz_i(:,:,:,:) = rn_icesal
+         s_i(:,:,:)   = rn_icesal
+         !
+         !            !---------------------------------------------!
+      CASE( 2 )       !  time varying salinity with linear profile  !
+         !            !---------------------------------------------!
+         !
+         ALLOCATE( z_slope_s(jpi,jpj,jpl) , zalpha(jpi,jpj,jpl) )
+         !
+         DO jl = 1, jpl
+            DO jk = 1, nlay_i
+               sz_i(:,:,jk,jl)  = s_i(:,:,jl)
+            END DO
+         END DO
+         !                                      ! Slope of the linear profile 
+         WHERE( h_i(:,:,:) > epsi20 )   ;   z_slope_s(:,:,:) = 2._wp * s_i(:,:,:) / h_i(:,:,:)
+         ELSEWHERE                       ;   z_slope_s(:,:,:) = 0._wp
+         END WHERE
+         !
+         z1_dS = 1._wp / ( zsi1 - zsi0 )
+         DO jl = 1, jpl
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zalpha(ji,jj,jl) = MAX(  0._wp , MIN( ( zsi1 - s_i(ji,jj,jl) ) * z1_dS , 1._wp )  )
+                  !                             ! force a constant profile when SSS too low (Baltic Sea)
+                  IF( 2._wp * s_i(ji,jj,jl) >= sss_m(ji,jj) )   zalpha(ji,jj,jl) = 0._wp  
+               END DO
+            END DO
+         END DO
+         !
+         ! Computation of the profile
+         DO jl = 1, jpl
+            DO jk = 1, nlay_i
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     !                          ! linear profile with 0 surface value
+                     zs0 = z_slope_s(ji,jj,jl) * ( REAL(jk,wp) - 0.5_wp ) * h_i(ji,jj,jl) * r1_nlay_i
+                     zs  = zalpha(ji,jj,jl) * zs0 + ( 1._wp - zalpha(ji,jj,jl) ) * s_i(ji,jj,jl)     ! weighting the profile
+                     sz_i(ji,jj,jk,jl) = MIN( rn_simax, MAX( zs, rn_simin ) )
+                  END DO
+               END DO
+            END DO
+         END DO
+         !
+         DEALLOCATE( z_slope_s , zalpha )
+         !
+         !            !-------------------------------------------!
+      CASE( 3 )       ! constant salinity with a fix profile      ! (Schwarzacher (1959) multiyear salinity profile
+         !            !-------------------------------------------!                                   (mean = 2.30)
+         !
+         s_i(:,:,:) = 2.30_wp
+!!gm Remark: if we keep the case 3, then compute an store one for all time-step
+!!           a array  S_prof(1:nlay_i) containing the calculation and just do:
+!         DO jk = 1, nlay_i
+!            sz_i(:,:,jk,:) = S_prof(jk)
+!         END DO
+!!gm end
+         !
+         DO jl = 1, jpl
+            DO jk = 1, nlay_i
+               zargtemp  = ( REAL(jk,wp) - 0.5_wp ) * r1_nlay_i
+               sz_i(:,:,jk,jl) =  1.6_wp * (  1._wp - COS( rpi * zargtemp**(0.407_wp/(0.573_wp+zargtemp)) )  )
+            END DO
+         END DO
+         !
+      END SELECT
+      !
+   END SUBROUTINE ice_var_salprof
+
+
+   SUBROUTINE ice_var_salprof1d
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_var_salprof1d  ***
+      !!
+      !! ** Purpose :   1d computation of the sea ice salinity profile
+      !!                Works with 1d vectors and is used by thermodynamic modules
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ji, jk    ! dummy loop indices
+      REAL(wp) ::   zargtemp, zsal, z1_dS   ! local scalars
+      REAL(wp) ::   zs, zs0              !   -      -
+      !
+      REAL(wp), ALLOCATABLE, DIMENSION(:) ::   z_slope_s, zalpha   !
+      REAL(wp), PARAMETER :: zsi0 = 3.5_wp
+      REAL(wp), PARAMETER :: zsi1 = 4.5_wp
+      !!-------------------------------------------------------------------
+      !
+      SELECT CASE ( nn_icesal )
+      !
+      !               !---------------------------------------!
+      CASE( 1 )       !  constant salinity in time and space  !
+         !            !---------------------------------------!
+         sz_i_1d(1:npti,:) = rn_icesal
+         !
+         !            !---------------------------------------------!
+      CASE( 2 )       !  time varying salinity with linear profile  !
+         !            !---------------------------------------------!
+         !
+         ALLOCATE( z_slope_s(jpij), zalpha(jpij) )
+         !
+         !                                      ! Slope of the linear profile 
+         WHERE( h_i_1d(1:npti) > epsi20 )   ;   z_slope_s(1:npti) = 2._wp * s_i_1d(1:npti) / h_i_1d(1:npti)
+         ELSEWHERE                          ;   z_slope_s(1:npti) = 0._wp
+         END WHERE
+         
+         z1_dS = 1._wp / ( zsi1 - zsi0 )
+         DO ji = 1, npti
+            zalpha(ji) = MAX(  0._wp , MIN(  ( zsi1 - s_i_1d(ji) ) * z1_dS , 1._wp  )  )
+            !                             ! force a constant profile when SSS too low (Baltic Sea)
+            IF( 2._wp * s_i_1d(ji) >= sss_1d(ji) )   zalpha(ji) = 0._wp
+         END DO
+         !
+         ! Computation of the profile
+         DO jk = 1, nlay_i
+            DO ji = 1, npti
+               !                          ! linear profile with 0 surface value
+               zs0 = z_slope_s(ji) * ( REAL(jk,wp) - 0.5_wp ) * h_i_1d(ji) * r1_nlay_i
+               zs  = zalpha(ji) * zs0 + ( 1._wp - zalpha(ji) ) * s_i_1d(ji)
+               sz_i_1d(ji,jk) = MIN( rn_simax , MAX( zs , rn_simin ) )
+            END DO
+         END DO
+         !
+         DEALLOCATE( z_slope_s, zalpha )
+
+         !            !-------------------------------------------!
+      CASE( 3 )       ! constant salinity with a fix profile      ! (Schwarzacher (1959) multiyear salinity profile
+         !            !-------------------------------------------!                                   (mean = 2.30)
+         !
+         s_i_1d(1:npti) = 2.30_wp
+         !
+!!gm cf remark in ice_var_salprof routine, CASE( 3 )
+         DO jk = 1, nlay_i
+            zargtemp  = ( REAL(jk,wp) - 0.5_wp ) * r1_nlay_i
+            zsal =  1.6_wp * ( 1._wp - COS( rpi * zargtemp**( 0.407_wp / ( 0.573_wp + zargtemp ) ) ) )
+            DO ji = 1, npti
+               sz_i_1d(ji,jk) = zsal
+            END DO
+         END DO
+         !
+      END SELECT
+      !
+   END SUBROUTINE ice_var_salprof1d
+
+
+   SUBROUTINE ice_var_zapsmall
+      !!-------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_var_zapsmall ***
+      !!
+      !! ** Purpose :   Remove too small sea ice areas and correct fluxes
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jl, jk   ! dummy loop indices
+      REAL(wp), DIMENSION(jpi,jpj) ::   zswitch
+      !!-------------------------------------------------------------------
+      !
+      DO jl = 1, jpl       !==  loop over the categories  ==!
+         !
+         !-----------------------------------------------------------------
+         ! Zap ice energy and use ocean heat to melt ice
+         !-----------------------------------------------------------------
+         WHERE( a_i(:,:,jl) > epsi20 )   ;   h_i(:,:,jl) = v_i(:,:,jl) / a_i(:,:,jl)
+         ELSEWHERE                       ;   h_i(:,:,jl) = 0._wp
+         END WHERE
+         !
+         WHERE( a_i(:,:,jl) < epsi10 .OR. v_i(:,:,jl) < epsi10 .OR. h_i(:,:,jl) < epsi10 )   ;   zswitch(:,:) = 0._wp
+         ELSEWHERE                                                                           ;   zswitch(:,:) = 1._wp
+         END WHERE
+         !
+         DO jk = 1, nlay_i
+            DO jj = 1 , jpj
+               DO ji = 1 , jpi
+                  ! update exchanges with ocean
+                  hfx_res(ji,jj)   = hfx_res(ji,jj) - (1._wp - zswitch(ji,jj) ) * e_i(ji,jj,jk,jl) * r1_rdtice ! W.m-2 <0
+                  e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * zswitch(ji,jj)
+                  t_i(ji,jj,jk,jl) = t_i(ji,jj,jk,jl) * zswitch(ji,jj) + rt0 * ( 1._wp - zswitch(ji,jj) )
+               END DO
+            END DO
+         END DO
+         !
+         DO jj = 1 , jpj
+            DO ji = 1 , jpi
+               ! update exchanges with ocean
+               sfx_res(ji,jj)  = sfx_res(ji,jj) + (1._wp - zswitch(ji,jj) ) * sv_i(ji,jj,jl)   * rhoic * r1_rdtice
+               wfx_res(ji,jj)  = wfx_res(ji,jj) + (1._wp - zswitch(ji,jj) ) * v_i (ji,jj,jl)   * rhoic * r1_rdtice
+               wfx_res(ji,jj)  = wfx_res(ji,jj) + (1._wp - zswitch(ji,jj) ) * v_s (ji,jj,jl)   * rhosn * r1_rdtice
+               hfx_res(ji,jj)  = hfx_res(ji,jj) - (1._wp - zswitch(ji,jj) ) * e_s (ji,jj,1,jl) * r1_rdtice ! W.m-2 <0
+               !-----------------------------------------------------------------
+               ! Zap snow energy 
+               !-----------------------------------------------------------------
+               t_s(ji,jj,1,jl) = t_s(ji,jj,1,jl) * zswitch(ji,jj) + rt0 * ( 1._wp - zswitch(ji,jj) )
+               e_s(ji,jj,1,jl) = e_s(ji,jj,1,jl) * zswitch(ji,jj)
+               !
+               !-----------------------------------------------------------------
+               ! zap ice and snow volume, add water and salt to ocean
+               !-----------------------------------------------------------------
+               ato_i(ji,jj)    = a_i (ji,jj,jl) * ( 1._wp - zswitch(ji,jj) ) + ato_i(ji,jj)
+               a_i  (ji,jj,jl) = a_i (ji,jj,jl) * zswitch(ji,jj)
+               v_i  (ji,jj,jl) = v_i (ji,jj,jl) * zswitch(ji,jj)
+               v_s  (ji,jj,jl) = v_s (ji,jj,jl) * zswitch(ji,jj)
+               t_su (ji,jj,jl) = t_su(ji,jj,jl) * zswitch(ji,jj) + t_bo(ji,jj) * ( 1._wp - zswitch(ji,jj) )
+               oa_i (ji,jj,jl) = oa_i(ji,jj,jl) * zswitch(ji,jj)
+               sv_i (ji,jj,jl) = sv_i(ji,jj,jl) * zswitch(ji,jj)
+               !
+               h_i (ji,jj,jl) = h_i (ji,jj,jl) * zswitch(ji,jj)
+               h_s (ji,jj,jl) = h_s (ji,jj,jl) * zswitch(ji,jj)
+               !
+               a_ip (ji,jj,jl) = a_ip (ji,jj,jl) * zswitch(ji,jj)
+               v_ip (ji,jj,jl) = v_ip (ji,jj,jl) * zswitch(ji,jj)
+               !
+            END DO
+         END DO
+         !
+      END DO 
+
+      ! to be sure that at_i is the sum of a_i(jl)
+      at_i (:,:) = SUM( a_i(:,:,:), dim=3 )
+      vt_i (:,:) = SUM( v_i(:,:,:), dim=3 )
+
+      ! open water = 1 if at_i=0
+      WHERE( at_i(:,:) == 0._wp )   ato_i(:,:) = 1._wp
+      !
+   END SUBROUTINE ice_var_zapsmall
+
+
+   SUBROUTINE ice_var_itd( zhti, zhts, zati, zh_i, zh_s, za_i )
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_var_itd   ***
+      !!
+      !! ** Purpose :  converting 1-cat ice to multiple ice categories
+      !!
+      !!                  ice thickness distribution follows a gaussian law
+      !!               around the concentration of the most likely ice thickness
+      !!                           (similar as iceistate.F90)
+      !!
+      !! ** Method:   Iterative procedure
+      !!                
+      !!               1) Try to fill the jpl ice categories (bounds hi_max(0:jpl)) with a gaussian
+      !!
+      !!               2) Check whether the distribution conserves area and volume, positivity and
+      !!                  category boundaries
+      !!              
+      !!               3) If not (input ice is too thin), the last category is empty and
+      !!                  the number of categories is reduced (jpl-1)
+      !!
+      !!               4) Iterate until ok (SUM(itest(:) = 4)
+      !!
+      !! ** Arguments : zhti: 1-cat ice thickness
+      !!                zhts: 1-cat snow depth
+      !!                zati: 1-cat ice concentration
+      !!
+      !! ** Output    : jpl-cat 
+      !!
+      !!  (Example of application: BDY forcings when input are cell averaged)  
+      !!-------------------------------------------------------------------
+      INTEGER  :: ji, jk, jl             ! dummy loop indices
+      INTEGER  :: idim, i_fill, jl0  
+      REAL(wp) :: zarg, zV, zconv, zdh, zdv
+      REAL(wp), DIMENSION(:),   INTENT(in)    ::   zhti, zhts, zati    ! input ice/snow variables
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   zh_i, zh_s, za_i ! output ice/snow variables
+      INTEGER , DIMENSION(4)                  ::   itest
+      !!-------------------------------------------------------------------
+      !
+      ! ----------------------------------------
+      ! distribution over the jpl ice categories
+      ! ----------------------------------------
+      ! a gaussian distribution for ice concentration is used
+      ! then we check whether the distribution fullfills
+      ! volume and area conservation, positivity and ice categories bounds
+      idim = SIZE( zhti , 1 )
+      zh_i(1:idim,1:jpl) = 0._wp
+      zh_s(1:idim,1:jpl) = 0._wp
+      za_i(1:idim,1:jpl) = 0._wp
+      !
+      DO ji = 1, idim
+         !
+         IF( zhti(ji) > 0._wp ) THEN
+            !
+            ! find which category (jl0) the input ice thickness falls into
+            jl0 = jpl
+            DO jl = 1, jpl
+               IF ( ( zhti(ji) >= hi_max(jl-1) ) .AND. ( zhti(ji) < hi_max(jl) ) ) THEN
+                  jl0 = jl
+                  CYCLE
+               ENDIF
+            END DO
+            !
+            itest(:) = 0
+            i_fill   = jpl + 1                                            !------------------------------------
+            DO WHILE ( ( SUM( itest(:) ) /= 4 ) .AND. ( i_fill >= 2 ) )   ! iterative loop on i_fill categories
+               !                                                          !------------------------------------
+               i_fill = i_fill - 1
+               !
+               zh_i(ji,1:jpl) = 0._wp
+               za_i(ji,1:jpl) = 0._wp
+               itest(:)       = 0      
+               !
+               IF ( i_fill == 1 ) THEN      !-- case very thin ice: fill only category 1
+                  zh_i(ji,1) = zhti(ji)
+                  za_i (ji,1) = zati (ji)
+               ELSE                         !-- case ice is thicker: fill categories >1
+                  ! thickness
+                  DO jl = 1, i_fill - 1
+                     zh_i(ji,jl) = hi_mean(jl)
+                  END DO
+                  !
+                  ! concentration
+                  za_i(ji,jl0) = zati(ji) / SQRT(REAL(jpl))
+                  DO jl = 1, i_fill - 1
+                     IF ( jl /= jl0 ) THEN
+                        zarg        = ( zh_i(ji,jl) - zhti(ji) ) / ( zhti(ji) * 0.5_wp )
+                        za_i(ji,jl) =   za_i (ji,jl0) * EXP(-zarg**2)
+                     ENDIF
+                  END DO
+                  !
+                  ! last category
+                  za_i(ji,i_fill) = zati(ji) - SUM( za_i(ji,1:i_fill-1) )
+                  zV = SUM( za_i(ji,1:i_fill-1) * zh_i(ji,1:i_fill-1) )
+                  zh_i(ji,i_fill) = ( zhti(ji) * zati(ji) - zV ) / MAX( za_i(ji,i_fill), epsi10 ) 
+                  !
+                  ! correction if concentration of upper cat is greater than lower cat
+                  !    (it should be a gaussian around jl0 but sometimes it is not)
+                  IF ( jl0 /= jpl ) THEN
+                     DO jl = jpl, jl0+1, -1
+                        IF ( za_i(ji,jl) > za_i(ji,jl-1) ) THEN
+                           zdv = zh_i(ji,jl) * za_i(ji,jl)
+                           zh_i(ji,jl    ) = 0._wp
+                           za_i (ji,jl    ) = 0._wp
+                           za_i (ji,1:jl-1) = za_i(ji,1:jl-1) + zdv / MAX( REAL(jl-1) * zhti(ji), epsi10 )
+                        END IF
+                     END DO
+                  ENDIF
+                  !
+               ENDIF
+               !
+               ! Compatibility tests
+               zconv = ABS( zati(ji) - SUM( za_i(ji,1:jpl) ) ) 
+               IF ( zconv < epsi06 )   itest(1) = 1                                        ! Test 1: area conservation
+               !
+               zconv = ABS( zhti(ji)*zati(ji) - SUM( za_i(ji,1:jpl)*zh_i(ji,1:jpl) ) )
+               IF ( zconv < epsi06 )   itest(2) = 1                                        ! Test 2: volume conservation
+               !
+               IF ( zh_i(ji,i_fill) >= hi_max(i_fill-1) )   itest(3) = 1                  ! Test 3: thickness of the last category is in-bounds ?
+               !
+               itest(4) = 1
+               DO jl = 1, i_fill
+                  IF ( za_i(ji,jl) < 0._wp ) itest(4) = 0                                ! Test 4: positivity of ice concentrations
+               END DO
+               !                                         !----------------------------
+            END DO                                       ! end iteration on categories
+            !                                            !----------------------------
+         ENDIF
+      END DO
+
+      ! Add Snow in each category where za_i is not 0
+      DO jl = 1, jpl
+         DO ji = 1, idim
+            IF( za_i(ji,jl) > 0._wp ) THEN
+               zh_s(ji,jl) = zh_i(ji,jl) * ( zhts(ji) / zhti(ji) )
+               ! In case snow load is in excess that would lead to transformation from snow to ice
+               ! Then, transfer the snow excess into the ice (different from icethd_dh)
+               zdh = MAX( 0._wp, ( rhosn * zh_s(ji,jl) + ( rhoic - rau0 ) * zh_i(ji,jl) ) * r1_rau0 ) 
+               ! recompute h_i, h_s avoiding out of bounds values
+               zh_i(ji,jl) = MIN( hi_max(jl), zh_i(ji,jl) + zdh )
+               zh_s(ji,jl) = MAX( 0._wp, zh_s(ji,jl) - zdh * rhoic * r1_rhosn )
+            ENDIF
+         END DO
+      END DO
+      !
+   END SUBROUTINE ice_var_itd
+
+
+   SUBROUTINE ice_var_itd2( zhti, zhts, zati, zh_i, zh_s, za_i )
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_var_itd2   ***
+      !!
+      !! ** Purpose :  converting N-cat ice to jpl ice categories
+      !!
+      !!                  ice thickness distribution follows a gaussian law
+      !!               around the concentration of the most likely ice thickness
+      !!                           (similar as iceistate.F90)
+      !!
+      !! ** Method:   Iterative procedure
+      !!                
+      !!               1) Fill ice cat that correspond to input thicknesses
+      !!                  Find the lowest(jlmin) and highest(jlmax) cat that are filled
+      !!
+      !!               2) Expand the filling to the cat jlmin-1 and jlmax+1
+      !!                   by removing 25% ice area from jlmin and jlmax (resp.) 
+      !!              
+      !!               3) Expand the filling to the empty cat between jlmin and jlmax 
+      !!                   by a) removing 25% ice area from the lower cat (ascendant loop jlmin=>jlmax)
+      !!                      b) removing 25% ice area from the higher cat (descendant loop jlmax=>jlmin)
+      !!
+      !! ** Arguments : zhti: N-cat ice thickness
+      !!                zhts: N-cat snow depth
+      !!                zati: N-cat ice concentration
+      !!
+      !! ** Output    : jpl-cat 
+      !!
+      !!  (Example of application: BDY forcings when inputs have N-cat /= jpl)  
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ji, jl, jl1, jl2             ! dummy loop indices
+      INTEGER  ::   idim, icat  
+      INTEGER, PARAMETER ::   ztrans = 0.25_wp
+      REAL(wp), DIMENSION(:,:), INTENT(in)    ::   zhti, zhts, zati    ! input ice/snow variables
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   zh_i, zh_s, za_i    ! output ice/snow variables
+      INTEGER , DIMENSION(:,:), ALLOCATABLE   ::   jlfil, jlfil2
+      INTEGER , DIMENSION(:)  , ALLOCATABLE   ::   jlmax, jlmin
+      !!-------------------------------------------------------------------
+      !
+      idim = SIZE( zhti, 1 )
+      icat = SIZE( zhti, 2 )
+      !
+      ALLOCATE( jlfil(idim,jpl), jlfil2(idim,jpl) )       ! allocate arrays
+      ALLOCATE( jlmin(idim), jlmax(idim) )
+
+      ! --- initialize output fields to 0 --- !
+      zh_i(1:idim,1:jpl) = 0._wp
+      zh_s(1:idim,1:jpl) = 0._wp
+      za_i(1:idim,1:jpl) = 0._wp
+      !
+      ! --- fill the categories --- !
+      !     find where cat-input = cat-output and fill cat-output fields  
+      jlmax(:) = 0
+      jlmin(:) = 999
+      jlfil(:,:) = 0
+      DO jl1 = 1, jpl
+         DO jl2 = 1, icat
+            DO ji = 1, idim
+               IF( hi_max(jl1-1) <= zhti(ji,jl2) .AND. hi_max(jl1) > zhti(ji,jl2) ) THEN
+                  ! fill the right category
+                  zh_i(ji,jl1) = zhti(ji,jl2)
+                  zh_s(ji,jl1) = zhts(ji,jl2)
+                  za_i(ji,jl1) = zati(ji,jl2)
+                  ! record categories that are filled
+                  jlmax(ji) = MAX( jlmax(ji), jl1 )
+                  jlmin(ji) = MIN( jlmin(ji), jl1 )
+                  jlfil(ji,jl1) = jl1
+               ENDIF
+            END DO
+         END DO
+      END DO
+      !
+      ! --- fill the gaps between categories --- !  
+      !     transfer from categories filled at the previous step to the empty ones in between
+      DO ji = 1, idim
+         jl1 = jlmin(ji)
+         jl2 = jlmax(ji)
+         IF( jl1 > 1 ) THEN
+            ! fill the lower cat (jl1-1)
+            za_i(ji,jl1-1) = ztrans * za_i(ji,jl1)
+            zh_i(ji,jl1-1) = hi_mean(jl1-1)
+            ! remove from cat jl1
+            za_i(ji,jl1  ) = ( 1._wp - ztrans ) * za_i(ji,jl1)
+         ENDIF
+         IF( jl2 < jpl ) THEN
+            ! fill the upper cat (jl2+1)
+            za_i(ji,jl2+1) = ztrans * za_i(ji,jl2)
+            zh_i(ji,jl2+1) = hi_mean(jl2+1)
+            ! remove from cat jl2
+            za_i(ji,jl2  ) = ( 1._wp - ztrans ) * za_i(ji,jl2)
+         ENDIF
+      END DO
+      !
+      jlfil2(:,:) = jlfil(:,:) 
+      ! fill categories from low to high
+      DO jl = 2, jpl-1
+         DO ji = 1, idim
+            IF( jlfil(ji,jl-1) /= 0 .AND. jlfil(ji,jl) == 0 ) THEN
+               ! fill high
+               za_i(ji,jl) = ztrans * za_i(ji,jl-1)
+               zh_i(ji,jl) = hi_mean(jl)
+               jlfil(ji,jl) = jl
+               ! remove low
+               za_i(ji,jl-1) = ( 1._wp - ztrans ) * za_i(ji,jl-1)
+            ENDIF
+         END DO
+      END DO
+      !
+      ! fill categories from high to low
+      DO jl = jpl-1, 2, -1
+         DO ji = 1, idim
+            IF( jlfil2(ji,jl+1) /= 0 .AND. jlfil2(ji,jl) == 0 ) THEN
+               ! fill low
+               za_i(ji,jl) = za_i(ji,jl) + ztrans * za_i(ji,jl+1)
+               zh_i(ji,jl) = hi_mean(jl) 
+               jlfil2(ji,jl) = jl
+               ! remove high
+               za_i(ji,jl+1) = ( 1._wp - ztrans ) * za_i(ji,jl+1)
+            ENDIF
+         END DO
+      END DO
+      !
+      DEALLOCATE( jlfil, jlfil2 )      ! deallocate arrays
+      DEALLOCATE( jlmin, jlmax )
+      !
+   END SUBROUTINE ice_var_itd2
+
+
+   SUBROUTINE ice_var_bv
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_var_bv ***
+      !!
+      !! ** Purpose :   computes mean brine volume (%) in sea ice
+      !!
+      !! ** Method  : e = - 0.054 * S (ppt) / T (C)
+      !!
+      !! References : Vancoppenolle et al., JGR, 2007
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
+      !!-------------------------------------------------------------------
+      !
+!!gm I prefere to use WHERE / ELSEWHERE  to set it to zero only where needed   <<<=== to be done
+!!   instead of setting everything to zero as just below
+      bv_i (:,:,:) = 0._wp
+      DO jl = 1, jpl
+         DO jk = 1, nlay_i
+            WHERE( t_i(:,:,jk,jl) < rt0 - epsi10 )   
+               bv_i(:,:,jl) = bv_i(:,:,jl) - tmut * sz_i(:,:,jk,jl) * r1_nlay_i / ( t_i(:,:,jk,jl) - rt0 )
+            END WHERE
+         END DO
+      END DO
+      WHERE( vt_i(:,:) > epsi20 )   ;   bvm_i(:,:) = SUM( bv_i(:,:,:) * v_i(:,:,:) , dim=3 ) / vt_i(:,:)
+      ELSEWHERE                     ;   bvm_i(:,:) = 0._wp
+      END WHERE
+      !
+   END SUBROUTINE ice_var_bv
+
+
+   SUBROUTINE ice_var_enthalpy
+      !!-------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_var_enthalpy *** 
+      !!                 
+      !! ** Purpose :   Computes sea ice energy of melting q_i (J.m-3) from temperature
+      !!
+      !! ** Method  :   Formula (Bitz and Lipscomb, 1999)
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ji, jk   ! dummy loop indices
+      REAL(wp) ::   ztmelts  ! local scalar 
+      !!-------------------------------------------------------------------
+      !
+      DO jk = 1, nlay_i             ! Sea ice energy of melting
+         DO ji = 1, npti
+            ztmelts      = - tmut  * sz_i_1d(ji,jk)
+            t_i_1d(ji,jk) = MIN( t_i_1d(ji,jk), ztmelts + rt0 ) ! Force t_i_1d to be lower than melting point
+                                                                !   (sometimes zdf scheme produces abnormally high temperatures)   
+            e_i_1d(ji,jk) = rhoic * ( cpic * ( ztmelts - ( t_i_1d(ji,jk) - rt0 ) )           &
+               &                    + lfus * ( 1._wp - ztmelts / ( t_i_1d(ji,jk) - rt0 ) )   &
+               &                    - rcp  *   ztmelts )
+         END DO
+      END DO
+      DO jk = 1, nlay_s             ! Snow energy of melting
+         DO ji = 1, npti
+            e_s_1d(ji,jk) = rhosn * ( cpic * ( rt0 - t_s_1d(ji,jk) ) + lfus )
+         END DO
+      END DO
+      !
+   END SUBROUTINE ice_var_enthalpy
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Dummy module           NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icevar
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icewri.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icewri.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/icewri.F90	(revision 9019)
@@ -0,0 +1,351 @@
+MODULE icewri
+   !!======================================================================
+   !!                     ***  MODULE  icewri  ***
+   !!   sea-ice : output ice variables
+   !!======================================================================
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_wri       : write of the diagnostics variables in ouput file 
+   !!   ice_wri_state : write for initial state or/and abandon
+   !!----------------------------------------------------------------------
+   USE dianam         ! build name of file (routine)
+   USE phycst         ! physical constant
+   USE dom_oce        ! domain: ocean
+   USE sbc_oce        ! surf. boundary cond.: ocean
+   USE sbc_ice        ! Surface boundary condition: ice fields
+   USE ice            ! sea-ice: variables
+   USE icevar         ! sea-ice: operations
+   !
+   USE ioipsl         !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE lbclnk         ! lateral boundary conditions (or mpp links)
+   USE timing         ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC ice_wri        ! called by ice_stp
+   PUBLIC ice_wri_state  ! called by dia_wri_state 
+
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
+   !! $Id: icewri.F90 8409 2017-08-07 15:29:21Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_wri( kt )
+      !!-------------------------------------------------------------------
+      !!  This routine computes the average of some variables and write it
+      !!  on the ouput files.
+      !!-------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! time-step
+      !
+      INTEGER  ::   ji, jj, jk, jl  ! dummy loop indices
+      REAL(wp) ::   z2da, z2db, zrho1, zrho2
+      REAL(wp), DIMENSION(jpi,jpj)     ::   z2d !  2D workspace
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zmsk00, zmsk05, zmsk15 ! O%, 5% and 15% concentration mask
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zmsk00l        ! cat masks
+      !
+      ! Global ice diagnostics (SIMIP)
+      REAL(wp) ::   zdiag_area_nh, zdiag_extt_nh, zdiag_volu_nh   ! area, extent, volume
+      REAL(wp) ::   zdiag_area_sh, zdiag_extt_sh, zdiag_volu_sh 
+      !!-------------------------------------------------------------------
+
+      IF( nn_timing == 1 )   CALL timing_start('icewri')
+
+      !----------------------------------------
+      ! Brine volume, switches, missing values
+      !----------------------------------------
+
+      CALL ice_var_bv      ! brine volume
+
+      ! tresholds for outputs
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zmsk00(ji,jj) = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi06  ) ) ! 1 if ice    , 0 if no ice
+            zmsk05(ji,jj) = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - 0.05_wp ) ) ! 1 if 5% ice , 0 if less
+            zmsk15(ji,jj) = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - 0.15_wp ) ) ! 1 if 15% ice, 0 if less
+         END DO
+      END DO
+      DO jl = 1, jpl
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zmsk00l(ji,jj,jl)  = MAX( 0._wp , SIGN( 1._wp , a_i(ji,jj,jl) - epsi06 ) )
+            END DO
+         END DO
+      END DO
+
+      !-----------------
+      ! Standard outputs
+      !-----------------
+      zrho1 = ( rau0 - rhoic ) * r1_rau0; zrho2 = rhosn * r1_rau0
+      ! masks
+      IF( iom_use('icemask'  ) )   CALL iom_put( "icemask"  , zmsk00              )   ! ice mask 0%
+      IF( iom_use('icemask05') )   CALL iom_put( "icemask05", zmsk05              )   ! ice mask 5%
+      IF( iom_use('icemask15') )   CALL iom_put( "icemask15", zmsk15              )   ! ice mask 15%
+      !
+      ! general fields
+      IF( iom_use('icemass'  ) )   CALL iom_put( "icemass", rhoic * vt_i * zmsk00 )   ! Ice mass per cell area 
+      IF( iom_use('snwmass'  ) )   CALL iom_put( "snwmass", rhosn * vt_s * zmsk00 )   ! Snow mass per cell area
+      IF( iom_use('icepres'  ) )   CALL iom_put( "icepres", zmsk00                )   ! Ice presence (1 or 0) 
+      IF( iom_use('iceconc'  ) )   CALL iom_put( "iceconc", at_i  * zmsk00        )   ! ice concentration
+      IF( iom_use('icevolu'  ) )   CALL iom_put( "icevolu", vt_i  * zmsk00        )   ! ice volume = mean ice thickness over the cell
+      IF( iom_use('icethic'  ) )   CALL iom_put( "icethic", hm_i  * zmsk00        )   ! ice thickness
+      IF( iom_use('snwthic'  ) )   CALL iom_put( "snwthic", hm_s  * zmsk00        )   ! snw thickness
+      IF( iom_use('icebrv'   ) )   CALL iom_put( "icebrv" , bvm_i * zmsk00 * 100. )   ! brine volume
+      IF( iom_use('iceage'   ) )   CALL iom_put( "iceage" , om_i  * zmsk00 / rday )   ! ice age
+      IF( iom_use('icehnew'  ) )   CALL iom_put( "icehnew", ht_i_new              )   ! new ice thickness formed in the leads
+      IF( iom_use('snwvolu'  ) )   CALL iom_put( "snwvolu", vt_s  * zmsk00        )   ! snow volume
+      IF( iom_use('icefrb') ) THEN
+         z2d(:,:) = ( zrho1 * hm_i(:,:) - zrho2 * hm_s(:,:) )                                         
+         WHERE( z2d < 0._wp )   z2d = 0._wp
+                                   CALL iom_put( "icefrb" , z2d * zmsk00          )   ! Ice freeboard
+      ENDIF
+      !
+      ! melt ponds
+      IF( iom_use('iceapnd'  ) )   CALL iom_put( "iceapnd", at_ip  * zmsk00       )   ! melt pond total fraction
+      IF( iom_use('icevpnd'  ) )   CALL iom_put( "icevpnd", vt_ip  * zmsk00       )   ! melt pond total volume per unit area
+      !
+      ! salt
+      IF( iom_use('icesalt'  ) )   CALL iom_put( "icesalt", sm_i  * zmsk00        )   ! mean ice salinity
+      IF( iom_use('icesalm'  ) )   CALL iom_put( "icesalm", SUM( sv_i, DIM = 3 ) * rhoic * 1.0e-3 * zmsk00 )   ! Mass of salt in sea ice per cell area
+
+      ! heat
+      IF( iom_use('icetemp'  ) )   CALL iom_put( "icetemp", ( tm_i  - rt0 ) * zmsk00 )   ! ice mean temperature
+      IF( iom_use('icettop'  ) )   CALL iom_put( "icettop", ( tm_su - rt0 ) * zmsk00 )   ! temperature at the ice surface
+      IF( iom_use('icetbot'  ) )   CALL iom_put( "icetbot", ( t_bo  - rt0 ) * zmsk00 )   ! temperature at the ice bottom
+      IF( iom_use('icetsni'  ) )   CALL iom_put( "icetsni", ( tm_si - rt0 ) * zmsk00 )   ! temperature at the snow-ice interface
+      IF( iom_use('icehc'    ) )   CALL iom_put( "icehc"  ,  -et_i          * zmsk00 )   ! ice heat content
+      IF( iom_use('snwhc'    ) )   CALL iom_put( "snwhc"  ,  -et_s          * zmsk00 )   ! snow heat content
+
+      ! momentum
+      IF( iom_use('uice'     ) )   CALL iom_put( "uice"   , u_ice                 )   ! ice velocity u component
+      IF( iom_use('vice'     ) )   CALL iom_put( "vice"   , v_ice                 )   ! ice velocity v component
+      IF( iom_use('utau_ai'  ) )   CALL iom_put( "utau_ai", utau_ice * zmsk00     )   ! Wind stress term in force balance (x)
+      IF( iom_use('vtau_ai'  ) )   CALL iom_put( "vtau_ai", vtau_ice * zmsk00     )   ! Wind stress term in force balance (y)
+
+      IF( iom_use('icevel') ) THEN 
+         DO jj = 2 , jpjm1
+            DO ji = 2 , jpim1
+               z2da  = ( u_ice(ji,jj) + u_ice(ji-1,jj) )
+               z2db  = ( v_ice(ji,jj) + v_ice(ji,jj-1) )
+               z2d(ji,jj) = 0.5_wp * SQRT( z2da * z2da + z2db * z2db )
+           END DO
+         END DO
+         CALL lbc_lnk( z2d, 'T', 1. )
+         IF( iom_use('icevel') )   CALL iom_put( "icevel" , z2d                   )   ! ice velocity module
+      ENDIF
+
+      ! --- category-dependent fields --- !
+      IF( iom_use('icemask_cat' ) )   CALL iom_put( "icemask_cat" , zmsk00l                                                    )   ! ice mask 0%
+      IF( iom_use('iceconc_cat' ) )   CALL iom_put( "iceconc_cat" , a_i * zmsk00l                                              )   ! area for categories
+      IF( iom_use('icethic_cat' ) )   CALL iom_put( "icethic_cat" , h_i * zmsk00l                                              )   ! thickness for categories
+      IF( iom_use('snwthic_cat' ) )   CALL iom_put( "snwthic_cat" , h_s * zmsk00l                                              )   ! snow depth for categories
+      IF( iom_use('icesalt_cat' ) )   CALL iom_put( "icesalt_cat" , s_i * zmsk00l                                              )   ! salinity for categories
+      IF( iom_use('iceage_cat'  ) )   CALL iom_put( "iceage_cat"  , o_i * zmsk00l / rday                                       )   ! ice age
+      IF( iom_use('icetemp_cat' ) )   CALL iom_put( "icetemp_cat" , ( SUM( t_i(:,:,:,:), dim=3 ) * r1_nlay_i - rt0 ) * zmsk00l )   ! ice temperature
+      IF( iom_use('snwtemp_cat' ) )   CALL iom_put( "snwtemp_cat" , ( SUM( t_s(:,:,:,:), dim=3 ) * r1_nlay_s - rt0 ) * zmsk00l )   ! snow temperature
+      IF( iom_use('icebrv_cat'  ) )   CALL iom_put( "icebrv_cat"  , bv_i * 100. * zmsk00l                                      )   ! brine volume
+      IF( iom_use('iceapnd_cat' ) )   CALL iom_put( "iceapnd_cat" , a_ip        * zmsk00l                                      )   ! melt pond frac for categories
+      IF( iom_use('icehpnd_cat' ) )   CALL iom_put( "icehpnd_cat" , h_ip        * zmsk00l                                      )   ! melt pond frac for categories
+      IF( iom_use('iceafpnd_cat') )   CALL iom_put( "iceafpnd_cat", a_ip_frac   * zmsk00l                                      )   ! melt pond frac for categories
+
+      !------------------
+      ! Add-ons for SIMIP
+      !------------------
+      ! trends
+      IF( iom_use('dmithd') )   CALL iom_put( "dmithd", - wfx_bog - wfx_bom - wfx_sum - wfx_sni - wfx_opw - wfx_lam - wfx_res ) ! Sea-ice mass change from thermodynamics
+      IF( iom_use('dmidyn') )   CALL iom_put( "dmidyn", - wfx_dyn + rhoic * diag_trp_vi     )   ! Sea-ice mass change from dynamics(kg/m2/s)
+      IF( iom_use('dmiopw') )   CALL iom_put( "dmiopw", - wfx_opw                           )   ! Sea-ice mass change through growth in open water
+      IF( iom_use('dmibog') )   CALL iom_put( "dmibog", - wfx_bog                           )   ! Sea-ice mass change through basal growth
+      IF( iom_use('dmisni') )   CALL iom_put( "dmisni", - wfx_sni                           )   ! Sea-ice mass change through snow-to-ice conversion
+      IF( iom_use('dmisum') )   CALL iom_put( "dmisum", - wfx_sum                           )   ! Sea-ice mass change through surface melting
+      IF( iom_use('dmibom') )   CALL iom_put( "dmibom", - wfx_bom                           )   ! Sea-ice mass change through bottom melting
+      IF( iom_use('dmtsub') )   CALL iom_put( "dmtsub", - wfx_sub                           )   ! Sea-ice mass change through evaporation and sublimation
+      IF( iom_use('dmssub') )   CALL iom_put( "dmssub", - wfx_snw_sub                       )   ! Snow mass change through sublimation
+      IF( iom_use('dmisub') )   CALL iom_put( "dmisub", - wfx_ice_sub                       )   ! Sea-ice mass change through sublimation
+      IF( iom_use('dmsspr') )   CALL iom_put( "dmsspr", - wfx_spr                           )   ! Snow mass change through snow fall
+      IF( iom_use('dmsssi') )   CALL iom_put( "dmsssi",   wfx_sni*rhosn*r1_rhoic            )   ! Snow mass change through snow-to-ice conversion
+      IF( iom_use('dmsmel') )   CALL iom_put( "dmsmel", - wfx_snw_sum                       )   ! Snow mass change through melt
+      IF( iom_use('dmsdyn') )   CALL iom_put( "dmsdyn", - wfx_snw_dyn + rhosn * diag_trp_vs )   ! Snow mass change through dynamics(kg/m2/s)
+
+      ! Global ice diagnostics
+      IF( iom_use('NH_icearea') .OR. iom_use('NH_icevolu') .OR. iom_use('NH_iceextt') )   THEN   ! NH diagnostics
+         !
+         WHERE( ff_t > 0._wp )   ;   zmsk00(:,:) = 1.0e-12
+         ELSEWHERE               ;   zmsk00(:,:) = 0.
+         END WHERE 
+         zdiag_area_nh = glob_sum( at_i(:,:) * zmsk00(:,:) * e1e2t(:,:) )
+         zdiag_volu_nh = glob_sum( vt_i(:,:) * zmsk00(:,:) * e1e2t(:,:) )
+         !
+         WHERE( ff_t > 0._wp .AND. at_i > 0.15 )   ; zmsk00(:,:) = 1.0e-12
+         ELSEWHERE                                 ; zmsk00(:,:) = 0.
+         END WHERE 
+         zdiag_extt_nh = glob_sum( zmsk00(:,:) * e1e2t(:,:) )
+         !
+         IF( iom_use('NH_icearea') )   CALL iom_put( "NH_icearea" ,  zdiag_area_nh )
+         IF( iom_use('NH_icevolu') )   CALL iom_put( "NH_icevolu" ,  zdiag_volu_nh )
+         IF( iom_use('NH_iceextt') )   CALL iom_put( "NH_iceextt" ,  zdiag_extt_nh )
+         !
+      ENDIF
+      !
+      IF( iom_use('SH_icearea') .OR. iom_use('SH_icevolu') .OR. iom_use('SH_iceextt') )   THEN   ! SH diagnostics
+         !
+         WHERE( ff_t < 0._wp ); zmsk00(:,:) = 1.0e-12; 
+         ELSEWHERE            ; zmsk00(:,:) = 0.
+         END WHERE 
+         zdiag_area_sh = glob_sum( at_i(:,:) * zmsk00(:,:) * e1e2t(:,:) ) 
+         zdiag_volu_sh = glob_sum( vt_i(:,:) * zmsk00(:,:) * e1e2t(:,:) )
+         !
+         WHERE( ff_t < 0._wp .AND. at_i > 0.15 ); zmsk00(:,:) = 1.0e-12
+         ELSEWHERE                              ; zmsk00(:,:) = 0.
+         END WHERE 
+         zdiag_extt_sh = glob_sum( zmsk00(:,:) * e1e2t(:,:) )
+         !
+         IF( iom_use('SH_icearea') ) CALL iom_put( "SH_icearea", zdiag_area_sh )
+         IF( iom_use('SH_icevolu') ) CALL iom_put( "SH_icevolu", zdiag_volu_sh )
+         IF( iom_use('SH_iceextt') ) CALL iom_put( "SH_iceextt", zdiag_extt_sh )
+         !
+      ENDIF 
+      !
+!!CR      !     !  Create an output files (output.lim.abort.nc) if S < 0 or u > 20 m/s
+!!CR      !     IF( kindic < 0 )   CALL ice_wri_state( 'output.abort' )
+!!CR      !     not yet implemented
+!!gm  idem for the ocean...  Ask Seb how to get read of ioipsl....
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('icewri')
+      !
+   END SUBROUTINE ice_wri
+
+ 
+   SUBROUTINE ice_wri_state( kt, kid, kh_i )
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE ice_wri_state  ***
+      !!        
+      !! ** Purpose :   create a NetCDF file named cdfile_name which contains 
+      !!      the instantaneous ice state and forcing fields for ice model
+      !!        Used to find errors in the initial state or save the last
+      !!      ocean state in case of abnormal end of a simulation
+      !!
+      !! History :   4.0  !  2013-06  (C. Rousset)
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt               ! ocean time-step index
+      INTEGER, INTENT( in ) ::   kid , kh_i
+      INTEGER               ::   nz_i, jl
+      REAL(wp), DIMENSION(jpl) ::   jcat
+      !!----------------------------------------------------------------------
+      !
+      DO jl = 1, jpl
+         jcat(jl) = REAL(jl)
+      END DO
+      
+      CALL histvert( kid, "ncatice", "Ice Categories","", jpl, jcat, nz_i, "up")
+
+      CALL histdef( kid, "sithic", "Ice thickness"           , "m"      ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "siconc", "Ice concentration"       , "%"      ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "sitemp", "Ice temperature"         , "C"      ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "sivelu", "i-Ice speed "            , "m/s"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "sivelv", "j-Ice speed "            , "m/s"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "sistru", "i-Wind stress over ice " , "Pa"     ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "sistrv", "j-Wind stress over ice " , "Pa"     ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "sisflx", "Solar flux over ocean"     , "w/m2" ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "sinflx", "Non-solar flux over ocean" , "w/m2" ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "isnowpre", "Snow precipitation"      , "kg/m2/s",   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "sisali", "Ice salinity"            , "PSU"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "sivolu", "Ice volume"              , "m"      ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "sidive", "Ice divergence"          , "10-8s-1",   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
+      CALL histdef( kid, "si_amp", "Melt pond fraction"      , "%"      ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "si_vmp", "Melt pond volume"        ,  "m"     ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "vfxbog", "Ice bottom production"   , "m/s"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "vfxdyn", "Ice dynamic production"  , "m/s"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "vfxopw", "Ice open water prod"     , "m/s"    ,   &
+      &       jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "vfxsni", "Snow ice production "    , "m/s"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "vfxres", "Ice prod from corrections" , "m/s"  ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "vfxbom", "Ice bottom melt"         , "m/s"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "vfxsum", "Ice surface melt"        , "m/s"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "vfxpnd", "Ice melt ponds flux"     , "m/s"    ,   &
+      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
+
+      CALL histdef( kid, "sithicat", "Ice thickness"         , "m"      ,   &
+      &      jpi, jpj, kh_i, jpl, 1, jpl, nz_i, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "siconcat", "Ice concentration"     , "%"      ,   &
+      &      jpi, jpj, kh_i, jpl, 1, jpl, nz_i, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "sisalcat", "Ice salinity"           , ""      ,   &
+      &      jpi, jpj, kh_i, jpl, 1, jpl, nz_i, 32, "inst(x)", rdt, rdt )
+      CALL histdef( kid, "snthicat", "Snw thickness"         , "m"      ,   &
+      &      jpi, jpj, kh_i, jpl, 1, jpl, nz_i, 32, "inst(x)", rdt, rdt )
+
+      CALL histend( kid, snc4set )   ! end of the file definition
+
+      CALL histwrite( kid, "sithic", kt, hm_i           , jpi*jpj, (/1/) )    
+      CALL histwrite( kid, "siconc", kt, at_i           , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sitemp", kt, tm_i - rt0     , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sivelu", kt, u_ice          , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sivelv", kt, v_ice          , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sistru", kt, utau_ice       , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sistrv", kt, vtau_ice       , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sisflx", kt, qsr , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sinflx", kt, qns , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "isnowpre", kt, sprecip        , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sisali", kt, sm_i           , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sivolu", kt, vt_i           , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "sidive", kt, divu_i*1.0e8   , jpi*jpj, (/1/) )
+
+      CALL histwrite( kid, "si_amp", kt, at_ip         , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "si_vmp", kt, vt_ip         , jpi*jpj, (/1/) )
+
+      CALL histwrite( kid, "vfxbog", kt, wfx_bog        , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "vfxdyn", kt, wfx_dyn        , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "vfxopw", kt, wfx_opw        , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "vfxsni", kt, wfx_sni        , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "vfxres", kt, wfx_res        , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "vfxbom", kt, wfx_bom        , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "vfxsum", kt, wfx_sum        , jpi*jpj, (/1/) )
+      CALL histwrite( kid, "vfxpnd", kt, wfx_pnd        , jpi*jpj, (/1/) )
+
+      CALL histwrite( kid, "sithicat", kt, h_i         , jpi*jpj*jpl, (/1/) )    
+      CALL histwrite( kid, "siconcat", kt, a_i         , jpi*jpj*jpl, (/1/) )    
+      CALL histwrite( kid, "sisalcat", kt, s_i         , jpi*jpj*jpl, (/1/) )    
+      CALL histwrite( kid, "snthicat", kt, h_s         , jpi*jpj*jpl, (/1/) )    
+
+      !! The file is closed in dia_wri_state (ocean routine)
+      !! CALL histclo( kid )
+      !
+    END SUBROUTINE ice_wri_state
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :         Empty module         NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icewri
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limadv_prather.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limadv_prather.F90	(revision 9018)
+++ 	(revision )
@@ -1,418 +1,0 @@
-MODULE limadv_prather 
-   !!======================================================================
-   !!                       ***  MODULE limadv_prather   ***
-   !! LIM sea-ice model : sea-ice advection => Prather scheme
-   !!======================================================================
-   !! History :  LIM  ! 2008-03 (M. Vancoppenolle)  LIM-3 from LIM-2 code
-   !!            3.2  ! 2009-06 (F. Dupont)  correct a error in the North fold b. c.
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!--------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                     LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_adv_x  : advection of sea ice on x axis
-   !!   lim_adv_y  : advection of sea ice on y axis
-   !!----------------------------------------------------------------------
-   USE dom_oce          ! ocean domain
-   USE ice              ! LIM-3 variables
-   USE lbclnk           ! lateral boundary condition - MPP exchanges
-   USE in_out_manager   ! I/O manager
-   USE prtctl           ! Print control
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE lib_fortran      ! to use key_nosignedzero
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_adv_x   ! called by lim_trp
-   PUBLIC   lim_adv_y   ! called by lim_trp
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limadv.F90 6746 2016-06-27 17:20:57Z clem $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_adv_x( pdf, put , pcrh, psm , ps0 ,   &
-      &                  psx, psxx, psy , psyy, psxy )
-      !!---------------------------------------------------------------------
-      !!                **  routine lim_adv_x  **
-      !!  
-      !! ** purpose :   Computes and adds the advection trend to sea-ice
-      !!              variable on i-axis
-      !!
-      !! ** method  :   Uses Prather second order scheme that advects tracers
-      !!              but also theirquadratic forms. The method preserves
-      !!              tracer structures by conserving second order moments.
-      !!
-      !! Reference:  Prather, 1986, JGR, 91, D6. 6671-6681.
-      !!--------------------------------------------------------------------
-      REAL(wp)                    , INTENT(in   ) ::   pdf                ! reduction factor for the time step
-      REAL(wp)                    , INTENT(in   ) ::   pcrh               ! call lim_adv_x then lim_adv_y (=1) or the opposite (=0)
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   put                ! i-direction ice velocity at U-point [m/s]
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psm                ! area
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ps0                ! field to be advected
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psx , psy          ! 1st moments 
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psxx, psyy, psxy   ! 2nd moments
-      !! 
-      INTEGER  ::   ji, jj                               ! dummy loop indices
-      REAL(wp) ::   zs1max, zrdt, zslpmax, ztemp         ! local scalars
-      REAL(wp) ::   zs1new, zalf , zalfq , zbt           !   -      -
-      REAL(wp) ::   zs2new, zalf1, zalf1q, zbt1          !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zf0 , zfx  , zfy   , zbet   ! 2D workspace
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zfm , zfxx , zfyy  , zfxy   !  -      -
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zalg, zalg1, zalg1q         !  -      -
-      !---------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, zf0 , zfx , zfy , zbet, zfm )
-      CALL wrk_alloc( jpi, jpj, zfxx, zfyy, zfxy, zalg, zalg1, zalg1q )
-
-      ! Limitation of moments.                                           
-
-      zrdt = rdt_ice * pdf      ! If ice drift field is too fast, use an appropriate time step for advection.
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            zslpmax = MAX( 0._wp, ps0(ji,jj) )
-            zs1max  = 1.5 * zslpmax
-            zs1new  = MIN( zs1max, MAX( -zs1max, psx(ji,jj) ) )
-            zs2new  = MIN(  2.0 * zslpmax - 0.3334 * ABS( zs1new ),      &
-               &            MAX( ABS( zs1new ) - zslpmax, psxx(ji,jj) )  )
-            rswitch = ( 1.0 - MAX( 0._wp, SIGN( 1._wp, -zslpmax) ) ) * tmask(ji,jj,1)   ! Case of empty boxes & Apply mask
-
-            ps0 (ji,jj) = zslpmax  
-            psx (ji,jj) = zs1new      * rswitch
-            psxx(ji,jj) = zs2new      * rswitch
-            psy (ji,jj) = psy (ji,jj) * rswitch
-            psyy(ji,jj) = psyy(ji,jj) * rswitch
-            psxy(ji,jj) = MIN( zslpmax, MAX( -zslpmax, psxy(ji,jj) ) ) * rswitch
-         END DO
-      END DO
-
-      !  Initialize volumes of boxes  (=area if adv_x first called, =psm otherwise)                                     
-      psm (:,:)  = MAX( pcrh * e1e2t(:,:) + ( 1.0 - pcrh ) * psm(:,:) , epsi20 )
-
-      !  Calculate fluxes and moments between boxes i<-->i+1              
-      DO jj = 1, jpj                      !  Flux from i to i+1 WHEN u GT 0 
-         DO ji = 1, jpi
-            zbet(ji,jj)  =  MAX( 0._wp, SIGN( 1._wp, put(ji,jj) ) )
-            zalf         =  MAX( 0._wp, put(ji,jj) ) * zrdt * e2u(ji,jj) / psm(ji,jj)
-            zalfq        =  zalf * zalf
-            zalf1        =  1.0 - zalf
-            zalf1q       =  zalf1 * zalf1
-            !
-            zfm (ji,jj)  =  zalf  *   psm (ji,jj)
-            zf0 (ji,jj)  =  zalf  * ( ps0 (ji,jj) + zalf1 * ( psx(ji,jj) + (zalf1 - zalf) * psxx(ji,jj) )  )
-            zfx (ji,jj)  =  zalfq * ( psx (ji,jj) + 3.0 * zalf1 * psxx(ji,jj) )
-            zfxx(ji,jj)  =  zalf  *   psxx(ji,jj) * zalfq
-            zfy (ji,jj)  =  zalf  * ( psy (ji,jj) + zalf1 * psxy(ji,jj) )
-            zfxy(ji,jj)  =  zalfq *   psxy(ji,jj)
-            zfyy(ji,jj)  =  zalf  *   psyy(ji,jj)
-
-            !  Readjust moments remaining in the box.
-            psm (ji,jj)  =  psm (ji,jj) - zfm(ji,jj)
-            ps0 (ji,jj)  =  ps0 (ji,jj) - zf0(ji,jj)
-            psx (ji,jj)  =  zalf1q * ( psx(ji,jj) - 3.0 * zalf * psxx(ji,jj) )
-            psxx(ji,jj)  =  zalf1  * zalf1q * psxx(ji,jj)
-            psy (ji,jj)  =  psy (ji,jj) - zfy(ji,jj)
-            psyy(ji,jj)  =  psyy(ji,jj) - zfyy(ji,jj)
-            psxy(ji,jj)  =  zalf1q * psxy(ji,jj)
-         END DO
-      END DO
-
-      DO jj = 1, jpjm1                      !  Flux from i+1 to i when u LT 0.
-         DO ji = 1, fs_jpim1
-            zalf          = MAX( 0._wp, -put(ji,jj) ) * zrdt * e2u(ji,jj) / psm(ji+1,jj) 
-            zalg  (ji,jj) = zalf
-            zalfq         = zalf * zalf
-            zalf1         = 1.0 - zalf
-            zalg1 (ji,jj) = zalf1
-            zalf1q        = zalf1 * zalf1
-            zalg1q(ji,jj) = zalf1q
-            !
-            zfm   (ji,jj) = zfm (ji,jj) + zalf  *   psm (ji+1,jj)
-            zf0   (ji,jj) = zf0 (ji,jj) + zalf  * ( ps0 (ji+1,jj) - zalf1 * ( psx(ji+1,jj) - (zalf1 - zalf ) * psxx(ji+1,jj) ) )
-            zfx   (ji,jj) = zfx (ji,jj) + zalfq * ( psx (ji+1,jj) - 3.0 * zalf1 * psxx(ji+1,jj) )
-            zfxx  (ji,jj) = zfxx(ji,jj) + zalf  *   psxx(ji+1,jj) * zalfq
-            zfy   (ji,jj) = zfy (ji,jj) + zalf  * ( psy (ji+1,jj) - zalf1 * psxy(ji+1,jj) )
-            zfxy  (ji,jj) = zfxy(ji,jj) + zalfq *   psxy(ji+1,jj)
-            zfyy  (ji,jj) = zfyy(ji,jj) + zalf  *   psyy(ji+1,jj)
-         END DO
-      END DO
-
-      DO jj = 2, jpjm1                     !  Readjust moments remaining in the box. 
-         DO ji = fs_2, fs_jpim1
-            zbt  =       zbet(ji-1,jj)
-            zbt1 = 1.0 - zbet(ji-1,jj)
-            !
-            psm (ji,jj) = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) - zfm(ji-1,jj) )
-            ps0 (ji,jj) = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) - zf0(ji-1,jj) )
-            psx (ji,jj) = zalg1q(ji-1,jj) * ( psx(ji,jj) + 3.0 * zalg(ji-1,jj) * psxx(ji,jj) )
-            psxx(ji,jj) = zalg1 (ji-1,jj) * zalg1q(ji-1,jj) * psxx(ji,jj)
-            psy (ji,jj) = zbt * psy (ji,jj) + zbt1 * ( psy (ji,jj) - zfy (ji-1,jj) )
-            psyy(ji,jj) = zbt * psyy(ji,jj) + zbt1 * ( psyy(ji,jj) - zfyy(ji-1,jj) )
-            psxy(ji,jj) = zalg1q(ji-1,jj) * psxy(ji,jj)
-         END DO
-      END DO
-
-      !   Put the temporary moments into appropriate neighboring boxes.    
-      DO jj = 2, jpjm1                     !   Flux from i to i+1 IF u GT 0.
-         DO ji = fs_2, fs_jpim1
-            zbt  =       zbet(ji-1,jj)
-            zbt1 = 1.0 - zbet(ji-1,jj)
-            psm(ji,jj)  = zbt * ( psm(ji,jj) + zfm(ji-1,jj) ) + zbt1 * psm(ji,jj)
-            zalf        = zbt * zfm(ji-1,jj) / psm(ji,jj)
-            zalf1       = 1.0 - zalf
-            ztemp       = zalf * ps0(ji,jj) - zalf1 * zf0(ji-1,jj)
-            !
-            ps0 (ji,jj) = zbt * ( ps0(ji,jj) + zf0(ji-1,jj) ) + zbt1 * ps0(ji,jj)
-            psx (ji,jj) = zbt * ( zalf * zfx(ji-1,jj) + zalf1 * psx(ji,jj) + 3.0 * ztemp ) + zbt1 * psx(ji,jj)
-            psxx(ji,jj) = zbt * ( zalf * zalf * zfxx(ji-1,jj) + zalf1 * zalf1 * psxx(ji,jj)                               &
-               &                + 5.0 * ( zalf * zalf1 * ( psx (ji,jj) - zfx(ji-1,jj) ) - ( zalf1 - zalf ) * ztemp )  )   &
-               &                                                + zbt1 * psxx(ji,jj)
-            psxy(ji,jj) = zbt * ( zalf * zfxy(ji-1,jj) + zalf1 * psxy(ji,jj)             &
-               &                + 3.0 * (- zalf1*zfy(ji-1,jj)  + zalf * psy(ji,jj) ) )   &
-               &                                                + zbt1 * psxy(ji,jj)
-            psy (ji,jj) = zbt * ( psy (ji,jj) + zfy (ji-1,jj) ) + zbt1 * psy (ji,jj)
-            psyy(ji,jj) = zbt * ( psyy(ji,jj) + zfyy(ji-1,jj) ) + zbt1 * psyy(ji,jj)
-         END DO
-      END DO
-
-      DO jj = 2, jpjm1                     !  Flux from i+1 to i IF u LT 0.
-         DO ji = fs_2, fs_jpim1
-            zbt  =       zbet(ji,jj)
-            zbt1 = 1.0 - zbet(ji,jj)
-            psm(ji,jj)  = zbt * psm(ji,jj)  + zbt1 * ( psm(ji,jj) + zfm(ji,jj) )
-            zalf        = zbt1 * zfm(ji,jj) / psm(ji,jj)
-            zalf1       = 1.0 - zalf
-            ztemp       = - zalf * ps0(ji,jj) + zalf1 * zf0(ji,jj)
-            !
-            ps0(ji,jj)  = zbt * ps0 (ji,jj) + zbt1 * ( ps0(ji,jj) + zf0(ji,jj) )
-            psx(ji,jj)  = zbt * psx (ji,jj) + zbt1 * ( zalf * zfx(ji,jj) + zalf1 * psx(ji,jj) + 3.0 * ztemp )
-            psxx(ji,jj) = zbt * psxx(ji,jj) + zbt1 * ( zalf * zalf * zfxx(ji,jj)  + zalf1 * zalf1 * psxx(ji,jj)  &
-               &                                      + 5.0 *( zalf * zalf1 * ( - psx(ji,jj) + zfx(ji,jj) )      &
-               &                                      + ( zalf1 - zalf ) * ztemp ) )
-            psxy(ji,jj) = zbt * psxy(ji,jj) + zbt1 * (  zalf * zfxy(ji,jj) + zalf1 * psxy(ji,jj)  &
-               &                                      + 3.0 * ( zalf1 * zfy(ji,jj) - zalf * psy(ji,jj) )  )
-            psy(ji,jj)  = zbt * psy (ji,jj)  + zbt1 * ( psy (ji,jj) + zfy (ji,jj) )
-            psyy(ji,jj) = zbt * psyy(ji,jj)  + zbt1 * ( psyy(ji,jj) + zfyy(ji,jj) )
-         END DO
-      END DO
-
-      !-- Lateral boundary conditions
-      CALL lbc_lnk_multi( psm , 'T',  1., ps0 , 'T',  1.   &
-         &              , psx , 'T', -1., psy , 'T', -1.   &   ! caution gradient ==> the sign changes
-         &              , psxx, 'T',  1., psyy, 'T',  1.   &
-         &              , psxy, 'T',  1. )
-
-      IF(ln_ctl) THEN
-         CALL prt_ctl(tab2d_1=psm  , clinfo1=' lim_adv_x: psm  :', tab2d_2=ps0 , clinfo2=' ps0  : ')
-         CALL prt_ctl(tab2d_1=psx  , clinfo1=' lim_adv_x: psx  :', tab2d_2=psxx, clinfo2=' psxx : ')
-         CALL prt_ctl(tab2d_1=psy  , clinfo1=' lim_adv_x: psy  :', tab2d_2=psyy, clinfo2=' psyy : ')
-         CALL prt_ctl(tab2d_1=psxy , clinfo1=' lim_adv_x: psxy :')
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj, zf0 , zfx , zfy , zbet, zfm )
-      CALL wrk_dealloc( jpi, jpj, zfxx, zfyy, zfxy, zalg, zalg1, zalg1q )
-      !
-   END SUBROUTINE lim_adv_x
-
-
-   SUBROUTINE lim_adv_y( pdf, pvt , pcrh, psm , ps0 ,   &
-      &                  psx, psxx, psy , psyy, psxy )
-      !!---------------------------------------------------------------------
-      !!                **  routine lim_adv_y  **
-      !!            
-      !! ** purpose :   Computes and adds the advection trend to sea-ice 
-      !!              variable on y axis
-      !!
-      !! ** method  :   Uses Prather second order scheme that advects tracers
-      !!              but also their quadratic forms. The method preserves 
-      !!              tracer structures by conserving second order moments.
-      !! 
-      !! Reference:  Prather, 1986, JGR, 91, D6. 6671-6681.
-      !!---------------------------------------------------------------------
-      REAL(wp)                    , INTENT(in   ) ::   pdf                ! reduction factor for the time step
-      REAL(wp)                    , INTENT(in   ) ::   pcrh               ! call lim_adv_x then lim_adv_y (=1) or the opposite (=0)
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pvt                ! j-direction ice velocity at V-point [m/s]
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psm                ! area
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ps0                ! field to be advected
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psx , psy          ! 1st moments 
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   psxx, psyy, psxy   ! 2nd moments
-      !!
-      INTEGER  ::   ji, jj                               ! dummy loop indices
-      REAL(wp) ::   zs1max, zrdt, zslpmax, ztemp         ! temporary scalars
-      REAL(wp) ::   zs1new, zalf , zalfq , zbt           !    -         -
-      REAL(wp) ::   zs2new, zalf1, zalf1q, zbt1          !    -         -
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zf0, zfx , zfy , zbet   ! 2D workspace
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zfm, zfxx, zfyy, zfxy   !  -      -
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zalg, zalg1, zalg1q     !  -      -
-      !---------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, zf0 , zfx , zfy , zbet, zfm )
-      CALL wrk_alloc( jpi, jpj, zfxx, zfyy, zfxy, zalg, zalg1, zalg1q )
-
-      ! Limitation of moments.
-
-      zrdt = rdt_ice * pdf ! If ice drift field is too fast, use an appropriate time step for advection.
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            zslpmax = MAX( 0._wp, ps0(ji,jj) )
-            zs1max  = 1.5 * zslpmax
-            zs1new  = MIN( zs1max, MAX( -zs1max, psy(ji,jj) ) )
-            zs2new  = MIN(  ( 2.0 * zslpmax - 0.3334 * ABS( zs1new ) ),   &
-               &             MAX( ABS( zs1new )-zslpmax, psyy(ji,jj) )  )
-            rswitch = ( 1.0 - MAX( 0._wp, SIGN( 1._wp, -zslpmax) ) ) * tmask(ji,jj,1)   ! Case of empty boxes & Apply mask
-            !
-            ps0 (ji,jj) = zslpmax  
-            psx (ji,jj) = psx (ji,jj) * rswitch
-            psxx(ji,jj) = psxx(ji,jj) * rswitch
-            psy (ji,jj) = zs1new * rswitch
-            psyy(ji,jj) = zs2new * rswitch
-            psxy(ji,jj) = MIN( zslpmax, MAX( -zslpmax, psxy(ji,jj) ) ) * rswitch
-         END DO
-      END DO
-
-      !  Initialize volumes of boxes (=area if adv_x first called, =psm otherwise)
-      psm(:,:)  = MAX(  pcrh * e1e2t(:,:) + ( 1.0 - pcrh ) * psm(:,:) , epsi20  )
-
-      !  Calculate fluxes and moments between boxes j<-->j+1              
-      DO jj = 1, jpj                     !  Flux from j to j+1 WHEN v GT 0   
-         DO ji = 1, jpi
-            zbet(ji,jj)  =  MAX( 0._wp, SIGN( 1._wp, pvt(ji,jj) ) )
-            zalf         =  MAX( 0._wp, pvt(ji,jj) ) * zrdt * e1v(ji,jj) / psm(ji,jj)
-            zalfq        =  zalf * zalf
-            zalf1        =  1.0 - zalf
-            zalf1q       =  zalf1 * zalf1
-            !
-            zfm (ji,jj)  =  zalf  * psm(ji,jj)
-            zf0 (ji,jj)  =  zalf  * ( ps0(ji,jj) + zalf1 * ( psy(ji,jj)  + (zalf1-zalf) * psyy(ji,jj)  ) ) 
-            zfy (ji,jj)  =  zalfq *( psy(ji,jj) + 3.0*zalf1*psyy(ji,jj) )
-            zfyy(ji,jj)  =  zalf  * zalfq * psyy(ji,jj)
-            zfx (ji,jj)  =  zalf  * ( psx(ji,jj) + zalf1 * psxy(ji,jj) )
-            zfxy(ji,jj)  =  zalfq * psxy(ji,jj)
-            zfxx(ji,jj)  =  zalf  * psxx(ji,jj)
-            !
-            !  Readjust moments remaining in the box.
-            psm (ji,jj)  =  psm (ji,jj) - zfm(ji,jj)
-            ps0 (ji,jj)  =  ps0 (ji,jj) - zf0(ji,jj)
-            psy (ji,jj)  =  zalf1q * ( psy(ji,jj) -3.0 * zalf * psyy(ji,jj) )
-            psyy(ji,jj)  =  zalf1 * zalf1q * psyy(ji,jj)
-            psx (ji,jj)  =  psx (ji,jj) - zfx(ji,jj)
-            psxx(ji,jj)  =  psxx(ji,jj) - zfxx(ji,jj)
-            psxy(ji,jj)  =  zalf1q * psxy(ji,jj)
-         END DO
-      END DO
-      !
-      DO jj = 1, jpjm1                   !  Flux from j+1 to j when v LT 0.
-         DO ji = 1, jpi
-            zalf          = ( MAX(0._wp, -pvt(ji,jj) ) * zrdt * e1v(ji,jj) ) / psm(ji,jj+1) 
-            zalg  (ji,jj) = zalf
-            zalfq         = zalf * zalf
-            zalf1         = 1.0 - zalf
-            zalg1 (ji,jj) = zalf1
-            zalf1q        = zalf1 * zalf1
-            zalg1q(ji,jj) = zalf1q
-            !
-            zfm   (ji,jj) = zfm (ji,jj) + zalf  *   psm (ji,jj+1)
-            zf0   (ji,jj) = zf0 (ji,jj) + zalf  * ( ps0 (ji,jj+1) - zalf1 * (psy(ji,jj+1) - (zalf1 - zalf ) * psyy(ji,jj+1) ) )
-            zfy   (ji,jj) = zfy (ji,jj) + zalfq * ( psy (ji,jj+1) - 3.0 * zalf1 * psyy(ji,jj+1) )
-            zfyy  (ji,jj) = zfyy(ji,jj) + zalf  *   psyy(ji,jj+1) * zalfq
-            zfx   (ji,jj) = zfx (ji,jj) + zalf  * ( psx (ji,jj+1) - zalf1 * psxy(ji,jj+1) )
-            zfxy  (ji,jj) = zfxy(ji,jj) + zalfq *   psxy(ji,jj+1)
-            zfxx  (ji,jj) = zfxx(ji,jj) + zalf  *   psxx(ji,jj+1)
-         END DO
-      END DO
-
-      !  Readjust moments remaining in the box. 
-      DO jj = 2, jpj
-         DO ji = 1, jpi
-            zbt  =         zbet(ji,jj-1)
-            zbt1 = ( 1.0 - zbet(ji,jj-1) )
-            !
-            psm (ji,jj) = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) - zfm(ji,jj-1) )
-            ps0 (ji,jj) = zbt * ps0(ji,jj) + zbt1 * ( ps0(ji,jj) - zf0(ji,jj-1) )
-            psy (ji,jj) = zalg1q(ji,jj-1) * ( psy(ji,jj) + 3.0 * zalg(ji,jj-1) * psyy(ji,jj) )
-            psyy(ji,jj) = zalg1 (ji,jj-1) * zalg1q(ji,jj-1) * psyy(ji,jj)
-            psx (ji,jj) = zbt * psx (ji,jj) + zbt1 * ( psx (ji,jj) - zfx (ji,jj-1) )
-            psxx(ji,jj) = zbt * psxx(ji,jj) + zbt1 * ( psxx(ji,jj) - zfxx(ji,jj-1) )
-            psxy(ji,jj) = zalg1q(ji,jj-1) * psxy(ji,jj)
-         END DO
-      END DO
-
-      !   Put the temporary moments into appropriate neighboring boxes.    
-      DO jj = 2, jpjm1                    !   Flux from j to j+1 IF v GT 0.
-         DO ji = 1, jpi
-            zbt  =         zbet(ji,jj-1)
-            zbt1 = ( 1.0 - zbet(ji,jj-1) )
-            psm(ji,jj)  = zbt * ( psm(ji,jj) + zfm(ji,jj-1) ) + zbt1 * psm(ji,jj) 
-            zalf        = zbt * zfm(ji,jj-1) / psm(ji,jj) 
-            zalf1       = 1.0 - zalf
-            ztemp       = zalf * ps0(ji,jj) - zalf1 * zf0(ji,jj-1)
-            !
-            ps0(ji,jj)  = zbt  * ( ps0(ji,jj) + zf0(ji,jj-1) ) + zbt1 * ps0(ji,jj)
-            psy(ji,jj)  = zbt  * ( zalf * zfy(ji,jj-1) + zalf1 * psy(ji,jj) + 3.0 * ztemp )   &
-               &                                               + zbt1 * psy(ji,jj)  
-            psyy(ji,jj) = zbt  * ( zalf * zalf * zfyy(ji,jj-1) + zalf1 * zalf1 * psyy(ji,jj)                             &
-               &                 + 5.0 * ( zalf * zalf1 * ( psy(ji,jj) - zfy(ji,jj-1) ) - ( zalf1 - zalf ) * ztemp ) )   & 
-               &                                               + zbt1 * psyy(ji,jj)
-            psxy(ji,jj) = zbt  * (  zalf * zfxy(ji,jj-1) + zalf1 * psxy(ji,jj)               &
-               &                  + 3.0 * (- zalf1 * zfx(ji,jj-1) + zalf * psx(ji,jj) )  )   &
-               &                                                + zbt1 * psxy(ji,jj)
-            psx (ji,jj) = zbt * ( psx (ji,jj) + zfx (ji,jj-1) ) + zbt1 * psx (ji,jj)
-            psxx(ji,jj) = zbt * ( psxx(ji,jj) + zfxx(ji,jj-1) ) + zbt1 * psxx(ji,jj)
-         END DO
-      END DO
-
-      DO jj = 2, jpjm1                   !  Flux from j+1 to j IF v LT 0.
-         DO ji = 1, jpi
-            zbt  =         zbet(ji,jj)
-            zbt1 = ( 1.0 - zbet(ji,jj) )
-            psm(ji,jj)  = zbt * psm(ji,jj) + zbt1 * ( psm(ji,jj) + zfm(ji,jj) )
-            zalf        = zbt1 * zfm(ji,jj) / psm(ji,jj)
-            zalf1       = 1.0 - zalf
-            ztemp       = - zalf * ps0 (ji,jj) + zalf1 * zf0(ji,jj)
-            ps0 (ji,jj) =   zbt  * ps0 (ji,jj) + zbt1  * ( ps0(ji,jj) + zf0(ji,jj) )
-            psy (ji,jj) =   zbt  * psy (ji,jj) + zbt1  * ( zalf * zfy(ji,jj) + zalf1 * psy(ji,jj) + 3.0 * ztemp )
-            psyy(ji,jj) =   zbt  * psyy(ji,jj) + zbt1 * (  zalf * zalf * zfyy(ji,jj) + zalf1 * zalf1 * psyy(ji,jj)   &
-               &                                         + 5.0 *( zalf *zalf1 *( -psy(ji,jj) + zfy(ji,jj) )          &
-               &                                         + ( zalf1 - zalf ) * ztemp )                                )
-            psxy(ji,jj) =   zbt  * psxy(ji,jj) + zbt1 * (  zalf * zfxy(ji,jj) + zalf1 * psxy(ji,jj)       &
-               &                                         + 3.0 * ( zalf1 * zfx(ji,jj) - zalf * psx(ji,jj) )  )
-            psx (ji,jj) =   zbt  * psx (ji,jj) + zbt1 * ( psx (ji,jj) + zfx (ji,jj) )
-            psxx(ji,jj) =   zbt  * psxx(ji,jj) + zbt1 * ( psxx(ji,jj) + zfxx(ji,jj) )
-         END DO
-      END DO
-
-      !-- Lateral boundary conditions
-      CALL lbc_lnk_multi( psm , 'T',  1.,  ps0 , 'T',  1.   &
-         &              , psx , 'T', -1.,  psy , 'T', -1.   &   ! caution gradient ==> the sign changes
-         &              , psxx, 'T',  1.,  psyy, 'T',  1.   &
-         &              , psxy, 'T',  1. )
-
-      IF(ln_ctl) THEN
-         CALL prt_ctl(tab2d_1=psm  , clinfo1=' lim_adv_y: psm  :', tab2d_2=ps0 , clinfo2=' ps0  : ')
-         CALL prt_ctl(tab2d_1=psx  , clinfo1=' lim_adv_y: psx  :', tab2d_2=psxx, clinfo2=' psxx : ')
-         CALL prt_ctl(tab2d_1=psy  , clinfo1=' lim_adv_y: psy  :', tab2d_2=psyy, clinfo2=' psyy : ')
-         CALL prt_ctl(tab2d_1=psxy , clinfo1=' lim_adv_y: psxy :')
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj, zf0 , zfx , zfy , zbet, zfm )
-      CALL wrk_dealloc( jpi, jpj, zfxx, zfyy, zfxy, zalg, zalg1, zalg1q )
-      !
-   END SUBROUTINE lim_adv_y
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option            Dummy module         NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-
-   !!======================================================================
-END MODULE limadv_prather
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limadv_umx.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limadv_umx.F90	(revision 9018)
+++ 	(revision )
@@ -1,587 +1,0 @@
-MODULE limadv_umx
-   !!==============================================================================
-   !!                       ***  MODULE  limadv_umx  ***
-   !! LIM sea-ice model : sea-ice advection using the ULTIMATE-MACHO scheme
-   !!==============================================================================
-   !! History :  3.5  !  2014-11  (C. Rousset, G. Madec)  Original code
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   lim_adv_umx   : update the tracer trend with the 3D advection trends using a TVD scheme
-   !!   ultimate      : compute a tracer value at velocity points using ULTIMATE scheme at various orders
-   !!   macho         : 
-   !!   nonosc_2d     : compute monotonic tracer fluxes by a non-oscillatory algorithm 
-   !!----------------------------------------------------------------------
-   USE phycst         ! physical constant
-   USE dom_oce        ! ocean domain
-   USE sbc_oce        ! ocean surface boundary condition
-   USE ice            ! ice variables
-   !
-   USE in_out_manager ! I/O manager
-   USE lbclnk         ! lateral boundary conditions -- MPP exchanges
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE timing         ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_adv_umx    ! routine called by limtrp.F90
-      
-   REAL(wp) ::   z1_6   = 1._wp / 6._wp   ! =1/6
-   REAL(wp) ::   z1_120 = 1._wp / 120._wp ! =1/120
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: limadv_umx.F90 4499 2014-02-18 15:14:31Z timgraham $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_adv_umx( kt, pdt, puc, pvc, pubox, pvbox, ptc )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_adv_umx  ***
-      !! 
-      !! **  Purpose :   Compute the now trend due to total advection of 
-      !!       tracers and add it to the general trend of tracer equations
-      !!
-      !! **  Method  :   TVD scheme, i.e. 2nd order centered scheme with
-      !!       corrected flux (monotonic correction)
-      !!       note: - this advection scheme needs a leap-frog time scheme
-      !!
-      !! ** Action : - pt  the after advective tracer
-      !!----------------------------------------------------------------------
-      INTEGER                     , INTENT(in   )           ::   kt         ! number of iteration
-      REAL(wp)                    , INTENT(in   )           ::   pdt        ! tracer time-step
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   )           ::   puc, pvc   ! 2 ice velocity components => u*e2
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   )           ::   pubox, pvbox   ! upstream velocity
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout)           ::   ptc        ! tracer content field
-      !
-      INTEGER  ::   ji, jj           ! dummy loop indices  
-      REAL(wp) ::   ztra             ! local scalar
-      REAL(wp) ::   zfp_ui, zfp_vj   !   -      -
-      REAL(wp) ::   zfm_ui, zfm_vj   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:) :: zt_ups, zfu_ups, zfv_ups, ztrd, zfu_ho, zfv_ho, zt_u, zt_v
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('lim_adv_umx')
-      !
-      CALL wrk_alloc( jpi,jpj,   zt_ups, zfu_ups, zfv_ups, ztrd, zfu_ho, zfv_ho, zt_u, zt_v )
-      !
-      !
-      !  upstream advection with initial mass fluxes & intermediate update
-      ! --------------------------------------------------------------------
-      DO jj = 1, jpjm1         ! upstream tracer flux in the i and j direction
-         DO ji = 1, fs_jpim1   ! vector opt.
-            zfp_ui = puc(ji,jj) + ABS( puc(ji,jj) )
-            zfm_ui = puc(ji,jj) - ABS( puc(ji,jj) )
-            zfp_vj = pvc(ji,jj) + ABS( pvc(ji,jj) )
-            zfm_vj = pvc(ji,jj) - ABS( pvc(ji,jj) )
-            zfu_ups(ji,jj) = 0.5_wp * ( zfp_ui * ptc(ji,jj) + zfm_ui * ptc(ji+1,jj  ) )
-            zfv_ups(ji,jj) = 0.5_wp * ( zfp_vj * ptc(ji,jj) + zfm_vj * ptc(ji  ,jj+1) )
-         END DO
-      END DO
-      
-      DO jj = 2, jpjm1            ! total intermediate advective trends
-         DO ji = fs_2, fs_jpim1   ! vector opt.
-            ztra = - (   zfu_ups(ji,jj) - zfu_ups(ji-1,jj  )   &
-               &       + zfv_ups(ji,jj) - zfv_ups(ji  ,jj-1)   ) * r1_e1e2t(ji,jj)
-            !
-            ztrd(ji,jj) =                         ztra                         ! upstream trend [ -div(uh) or -div(uhT) ]  
-            zt_ups (ji,jj) = ( ptc(ji,jj) + pdt * ztra ) * tmask(ji,jj,1)      ! guess after content field with monotonic scheme
-         END DO
-      END DO
-      CALL lbc_lnk( zt_ups, 'T', 1. )        ! Lateral boundary conditions   (unchanged sign)
-      
-      ! High order (_ho) fluxes 
-      ! -----------------------
-      SELECT CASE( nn_limadv_ord )
-      CASE ( 20 )                          ! centered second order
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zfu_ho(ji,jj) = 0.5 * puc(ji,jj) * ( ptc(ji,jj) + ptc(ji+1,jj) )
-               zfv_ho(ji,jj) = 0.5 * pvc(ji,jj) * ( ptc(ji,jj) + ptc(ji,jj+1) )
-            END DO
-         END DO
-         !
-      CASE ( 1:5 )                      ! 1st to 5th order ULTIMATE-MACHO scheme
-         CALL macho( kt, nn_limadv_ord, pdt, ptc, puc, pvc, pubox, pvbox, zt_u, zt_v )
-         !
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zfu_ho(ji,jj) = puc(ji,jj) * zt_u(ji,jj)
-               zfv_ho(ji,jj) = pvc(ji,jj) * zt_v(ji,jj)
-            END DO
-         END DO
-         !
-      END SELECT
-         
-      ! antidiffusive flux : high order minus low order
-      ! --------------------------------------------------
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1   ! vector opt.
-            zfu_ho(ji,jj) = zfu_ho(ji,jj) - zfu_ups(ji,jj)
-            zfv_ho(ji,jj) = zfv_ho(ji,jj) - zfv_ups(ji,jj)
-         END DO
-      END DO
-      CALL lbc_lnk_multi( zfu_ho, 'U', -1., zfv_ho, 'V', -1. )         ! Lateral bondary conditions
-      
-      ! monotonicity algorithm
-      ! -------------------------
-      CALL nonosc_2d( ptc, zfu_ho, zfv_ho, zt_ups, pdt )
-      
-      ! final trend with corrected fluxes
-      ! ------------------------------------
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1   ! vector opt.  
-            ztra       = ztrd(ji,jj)  - (  zfu_ho(ji,jj) - zfu_ho(ji-1,jj  )   &
-               &                         + zfv_ho(ji,jj) - zfv_ho(ji  ,jj-1) ) * r1_e1e2t(ji,jj)  
-            ptc(ji,jj) = ptc(ji,jj) + pdt * ztra
-         END DO
-      END DO
-      CALL lbc_lnk( ptc(:,:) , 'T',  1. )
-      !
-      !
-      CALL wrk_dealloc( jpi,jpj,   zt_ups, zfu_ups, zfv_ups, ztrd, zfu_ho, zfv_ho, zt_u, zt_v )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('lim_adv_umx')
-      !
-   END SUBROUTINE lim_adv_umx
-
-
-   SUBROUTINE macho( kt, k_order, pdt, ptc, puc, pvc, pubox, pvbox, pt_u, pt_v )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE ultimate_x  ***
-      !!     
-      !! **  Purpose :   compute  
-      !!
-      !! **  Method  :   ... ???
-      !!                 TIM = transient interpolation Modeling 
-      !!
-      !! Reference : Leonard, B.P., 1991, Comput. Methods Appl. Mech. Eng., 88, 17-74. 
-      !!----------------------------------------------------------------------
-      INTEGER                     , INTENT(in   ) ::   kt         ! number of iteration
-      INTEGER                     , INTENT(in   ) ::   k_order    ! order of the ULTIMATE scheme
-      REAL(wp)                    , INTENT(in   ) ::   pdt        ! tracer time-step
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   ptc        ! tracer fields
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   puc, pvc   ! 2 ice velocity components
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pubox, pvbox   ! upstream velocity
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   pt_u, pt_v ! tracer at u- and v-points 
-      !
-      INTEGER  ::   ji, jj    ! dummy loop indices
-      REAL(wp) ::   zc_box    !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:) :: zzt
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('macho')
-      !
-      CALL wrk_alloc( jpi,jpj,   zzt )
-      !
-      IF( MOD( (kt - 1) / nn_fsbc , 2 ) == 0 ) THEN         !==  odd ice time step:  adv_x then adv_y  ==!
-         !
-         !                                                           !--  ultimate interpolation of pt at u-point  --!
-         CALL ultimate_x( k_order, pdt, ptc, puc, pt_u )
-         !
-         !                                                           !--  advective form update in zzt  --!
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zzt(ji,jj) = ptc(ji,jj) - pubox(ji,jj) * pdt * ( pt_u(ji,jj) - pt_u(ji-1,jj) ) * r1_e1t(ji,jj)  &
-                  &                    - ptc  (ji,jj) * pdt * ( puc (ji,jj) - puc (ji-1,jj) ) * r1_e1e2t(ji,jj)
-               zzt(ji,jj) = zzt(ji,jj) * tmask(ji,jj,1)
-            END DO
-         END DO
-         CALL lbc_lnk( zzt, 'T', 1. )
-         !
-         !                                                           !--  ultimate interpolation of pt at v-point  --!
-         CALL ultimate_y( k_order, pdt, zzt, pvc, pt_v )
-         !
-      ELSE                                                  !==  even ice time step:  adv_y then adv_x  ==!
-         !
-         !                                                           !--  ultimate interpolation of pt at v-point  --!
-         CALL ultimate_y( k_order, pdt, ptc, pvc, pt_v )
-         !
-         !                                                           !--  advective form update in zzt  --!
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1
-               zzt(ji,jj) = ptc(ji,jj) - pvbox(ji,jj) * pdt * ( pt_v(ji,jj) - pt_v(ji,jj-1) ) * r1_e2t(ji,jj)  &
-                  &                    - ptc  (ji,jj) * pdt * ( pvc (ji,jj) - pvc (ji,jj-1) ) * r1_e1e2t(ji,jj)
-               zzt(ji,jj) = zzt(ji,jj) * tmask(ji,jj,1)
-            END DO
-         END DO
-         CALL lbc_lnk( zzt, 'T', 1. )
-         !
-         !                                                           !--  ultimate interpolation of pt at u-point  --!
-         CALL ultimate_x( k_order, pdt, zzt, puc, pt_u )
-         !      
-      ENDIF      
-      !
-      CALL wrk_dealloc( jpi,jpj,   zzt )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('macho')
-      !
-   END SUBROUTINE macho
-
-
-   SUBROUTINE ultimate_x( k_order, pdt, pt, puc, pt_u )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE ultimate_x  ***
-      !!     
-      !! **  Purpose :   compute  
-      !!
-      !! **  Method  :   ... ???
-      !!                 TIM = transient interpolation Modeling 
-      !!
-      !! Reference : Leonard, B.P., 1991, Comput. Methods Appl. Mech. Eng., 88, 17-74. 
-      !!----------------------------------------------------------------------
-      INTEGER                     , INTENT(in   ) ::   k_order   ! ocean time-step index
-      REAL(wp)                    , INTENT(in   ) ::   pdt       ! tracer time-step
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   puc       ! ice i-velocity component
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pt        ! tracer fields
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   pt_u      ! tracer at u-point 
-      !
-      INTEGER  ::   ji, jj       ! dummy loop indices
-      REAL(wp) ::   zcu, zdx2, zdx4    !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:) :: ztu1, ztu2, ztu3, ztu4
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('ultimate_x')
-      !
-      CALL wrk_alloc( jpi,jpj,   ztu1, ztu2, ztu3, ztu4 )
-      !
-      !                                                     !--  Laplacian in i-direction  --!
-      DO jj = 2, jpjm1         ! First derivative (gradient)
-         DO ji = 1, fs_jpim1
-            ztu1(ji,jj) = ( pt(ji+1,jj) - pt(ji,jj) ) * r1_e1u(ji,jj) * umask(ji,jj,1)
-         END DO
-         !                     ! Second derivative (Laplacian)
-         DO ji = fs_2, fs_jpim1
-            ztu2(ji,jj) = ( ztu1(ji,jj) - ztu1(ji-1,jj) ) * r1_e1t(ji,jj)
-         END DO
-      END DO
-      CALL lbc_lnk( ztu2, 'T', 1. )
-      !
-      !                                                     !--  BiLaplacian in i-direction  --!
-      DO jj = 2, jpjm1         ! Third derivative
-         DO ji = 1, fs_jpim1
-            ztu3(ji,jj) = ( ztu2(ji+1,jj) - ztu2(ji,jj) ) * r1_e1u(ji,jj) * umask(ji,jj,1)
-         END DO
-         !                     ! Fourth derivative
-         DO ji = fs_2, fs_jpim1
-            ztu4(ji,jj) = ( ztu3(ji,jj) - ztu3(ji-1,jj) ) * r1_e1t(ji,jj)
-         END DO
-      END DO
-      CALL lbc_lnk( ztu4, 'T', 1. )
-      !
-      !
-      SELECT CASE (k_order )
-      !
-      CASE( 1 )                                                   !==  1st order central TIM  ==! (Eq. 21)
-         !        
-         DO jj = 1, jpj
-            DO ji = 1, fs_jpim1   ! vector opt.
-               pt_u(ji,jj) = 0.5_wp * umask(ji,jj,1) * (                               pt(ji+1,jj) + pt(ji,jj)   &
-                  &                                    - SIGN( 1._wp, puc(ji,jj) ) * ( pt(ji+1,jj) - pt(ji,jj) ) )
-            END DO
-         END DO
-         !
-      CASE( 2 )                                                   !==  2nd order central TIM  ==! (Eq. 23)
-         !
-         DO jj = 1, jpj
-            DO ji = 1, fs_jpim1   ! vector opt.
-               zcu  = puc(ji,jj) * r1_e2u(ji,jj) * pdt * r1_e1u(ji,jj)
-               pt_u(ji,jj) = 0.5_wp * umask(ji,jj,1) * (                                   pt(ji+1,jj) + pt(ji,jj)   &
-                  &                                               -              zcu   * ( pt(ji+1,jj) - pt(ji,jj) ) ) 
-            END DO
-         END DO
-         CALL lbc_lnk( pt_u(:,:) , 'U',  1. )
-         !  
-      CASE( 3 )                                                   !==  3rd order central TIM  ==! (Eq. 24)
-         !
-         DO jj = 1, jpj
-            DO ji = 1, fs_jpim1   ! vector opt.
-               zcu  = puc(ji,jj) * r1_e2u(ji,jj) * pdt * r1_e1u(ji,jj)
-               zdx2 = e1u(ji,jj) * e1u(ji,jj)
-!!rachid       zdx2 = e1u(ji,jj) * e1t(ji,jj)
-               pt_u(ji,jj) = 0.5_wp * umask(ji,jj,1) * (         (                         pt  (ji+1,jj) + pt  (ji,jj)        &
-                  &                                               -              zcu   * ( pt  (ji+1,jj) - pt  (ji,jj) )  )   &
-                  &        + z1_6 * zdx2 * ( zcu*zcu - 1._wp ) * (                         ztu2(ji+1,jj) + ztu2(ji,jj)        &
-                  &                                               - SIGN( 1._wp, zcu ) * ( ztu2(ji+1,jj) - ztu2(ji,jj) )  )   )
-            END DO
-         END DO
-         !
-      CASE( 4 )                                                   !==  4th order central TIM  ==! (Eq. 27)
-         !
-         DO jj = 1, jpj
-            DO ji = 1, fs_jpim1   ! vector opt.
-               zcu  = puc(ji,jj) * r1_e2u(ji,jj) * pdt * r1_e1u(ji,jj)
-               zdx2 = e1u(ji,jj) * e1u(ji,jj)
-!!rachid       zdx2 = e1u(ji,jj) * e1t(ji,jj)
-               pt_u(ji,jj) = 0.5_wp * umask(ji,jj,1) * (         (                   pt  (ji+1,jj) + pt  (ji,jj)        &
-                  &                                               -          zcu * ( pt  (ji+1,jj) - pt  (ji,jj) )  )   &
-                  &        + z1_6 * zdx2 * ( zcu*zcu - 1._wp ) * (                   ztu2(ji+1,jj) + ztu2(ji,jj)        &
-                  &                                               - 0.5_wp * zcu * ( ztu2(ji+1,jj) - ztu2(ji,jj) )  )   )
-            END DO
-         END DO
-         !
-      CASE( 5 )                                                   !==  5th order central TIM  ==! (Eq. 29)
-         !
-         DO jj = 1, jpj
-            DO ji = 1, fs_jpim1   ! vector opt.
-               zcu  = puc(ji,jj) * r1_e2u(ji,jj) * pdt * r1_e1u(ji,jj)
-               zdx2 = e1u(ji,jj) * e1u(ji,jj)
-!!rachid       zdx2 = e1u(ji,jj) * e1t(ji,jj)
-               zdx4 = zdx2 * zdx2
-               pt_u(ji,jj) = 0.5_wp * umask(ji,jj,1) * (               (                   pt  (ji+1,jj) + pt  (ji,jj)       &
-                  &                                                     -          zcu * ( pt  (ji+1,jj) - pt  (ji,jj) ) )   &
-                  &        + z1_6   * zdx2 * ( zcu*zcu - 1._wp ) *     (                   ztu2(ji+1,jj) + ztu2(ji,jj)       &
-                  &                                                     - 0.5_wp * zcu * ( ztu2(ji+1,jj) - ztu2(ji,jj) ) )   &
-                  &        + z1_120 * zdx4 * ( zcu*zcu - 1._wp ) * ( zcu*zcu - 4._wp ) * ( ztu4(ji+1,jj) + ztu4(ji,jj)       &
-                  &                                               - SIGN( 1._wp, zcu ) * ( ztu4(ji+1,jj) - ztu4(ji,jj) ) ) )
-            END DO
-         END DO
-         !
-      END SELECT
-      !
-      CALL wrk_dealloc( jpi,jpj,   ztu1, ztu2, ztu3, ztu4 )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('ultimate_x')
-      !
-   END SUBROUTINE ultimate_x
-   
- 
-   SUBROUTINE ultimate_y( k_order, pdt, pt, pvc, pt_v )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE ultimate_y  ***
-      !!     
-      !! **  Purpose :   compute  
-      !!
-      !! **  Method  :   ... ???
-      !!                 TIM = transient interpolation Modeling 
-      !!
-      !! Reference : Leonard, B.P., 1991, Comput. Methods Appl. Mech. Eng., 88, 17-74. 
-      !!----------------------------------------------------------------------
-      INTEGER                     , INTENT(in   ) ::   k_order   ! ocean time-step index
-      REAL(wp)                    , INTENT(in   ) ::   pdt       ! tracer time-step
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pvc       ! ice j-velocity component
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   pt        ! tracer fields
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   pt_v      ! tracer at v-point 
-      !
-      INTEGER  ::   ji, jj       ! dummy loop indices
-      REAL(wp) ::   zcv, zdy2, zdy4    !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:) :: ztv1, ztv2, ztv3, ztv4
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('ultimate_y')
-      !
-      CALL wrk_alloc( jpi,jpj,   ztv1, ztv2, ztv3, ztv4 )
-      !
-      !                                                     !--  Laplacian in j-direction  --!
-      DO jj = 1, jpjm1         ! First derivative (gradient)
-         DO ji = fs_2, fs_jpim1
-            ztv1(ji,jj) = ( pt(ji,jj+1) - pt(ji,jj) ) * r1_e2v(ji,jj) * vmask(ji,jj,1)
-         END DO
-      END DO
-      DO jj = 2, jpjm1         ! Second derivative (Laplacian)
-         DO ji = fs_2, fs_jpim1
-            ztv2(ji,jj) = ( ztv1(ji,jj) - ztv1(ji,jj-1) ) * r1_e2t(ji,jj)
-         END DO
-      END DO
-      CALL lbc_lnk( ztv2, 'T', 1. )
-      !
-      !                                                     !--  BiLaplacian in j-direction  --!
-      DO jj = 1, jpjm1         ! First derivative
-         DO ji = fs_2, fs_jpim1
-            ztv3(ji,jj) = ( ztv2(ji,jj+1) - ztv2(ji,jj) ) * r1_e2v(ji,jj) * vmask(ji,jj,1)
-         END DO
-      END DO
-      DO jj = 2, jpjm1         ! Second derivative
-         DO ji = fs_2, fs_jpim1
-            ztv4(ji,jj) = ( ztv3(ji,jj) - ztv3(ji,jj-1) ) * r1_e2t(ji,jj)
-         END DO
-      END DO
-      CALL lbc_lnk( ztv4, 'T', 1. )
-      !
-      !
-      SELECT CASE (k_order )
-         !
-      CASE( 1 )                                                   !==  1st order central TIM  ==! (Eq. 21)
-         !        
-         DO jj = 1, jpjm1
-            DO ji = 1, jpi
-               pt_v(ji,jj) = 0.5_wp * vmask(ji,jj,1) * (                              ( pt(ji,jj+1) + pt(ji,jj) )  &
-                  &                                     - SIGN( 1._wp, pvc(ji,jj) ) * ( pt(ji,jj+1) - pt(ji,jj) ) )
-            END DO
-         END DO
-         !
-      CASE( 2 )                                                   !==  2nd order central TIM  ==! (Eq. 23)
-         DO jj = 1, jpjm1
-            DO ji = 1, jpi
-               zcv  = pvc(ji,jj) * r1_e1v(ji,jj) * pdt * r1_e2v(ji,jj)
-               pt_v(ji,jj) = 0.5_wp * vmask(ji,jj,1) * (        ( pt(ji,jj+1) + pt(ji,jj) )  &
-                  &                                     - zcv * ( pt(ji,jj+1) - pt(ji,jj) ) )
-            END DO
-         END DO
-         CALL lbc_lnk( pt_v(:,:) , 'V',  1. )
-         !
-      CASE( 3 )                                                   !==  3rd order central TIM  ==! (Eq. 24)
-         !
-         DO jj = 1, jpjm1
-            DO ji = 1, jpi
-               zcv  = pvc(ji,jj) * r1_e1v(ji,jj) * pdt * r1_e2v(ji,jj)
-               zdy2 = e2v(ji,jj) * e2v(ji,jj)
-!!rachid       zdy2 = e2v(ji,jj) * e2t(ji,jj)
-               pt_v(ji,jj) = 0.5_wp * vmask(ji,jj,1) * (                                 ( pt  (ji,jj+1) + pt  (ji,jj)       &
-                  &                                     -                        zcv   * ( pt  (ji,jj+1) - pt  (ji,jj) ) )   &
-                  &        + z1_6 * zdy2 * ( zcv*zcv - 1._wp ) * (                         ztv2(ji,jj+1) + ztv2(ji,jj)       &
-                  &                                               - SIGN( 1._wp, zcv ) * ( ztv2(ji,jj+1) - ztv2(ji,jj) ) ) )
-            END DO
-         END DO
-         !
-      CASE( 4 )                                                   !==  4th order central TIM  ==! (Eq. 27)
-         !
-         DO jj = 1, jpjm1
-            DO ji = 1, jpi
-               zcv  = pvc(ji,jj) * r1_e1v(ji,jj) * pdt * r1_e2v(ji,jj)
-               zdy2 = e2v(ji,jj) * e2v(ji,jj)
-!!rachid       zdy2 = e2v(ji,jj) * e2t(ji,jj)
-               pt_v(ji,jj) = 0.5_wp * vmask(ji,jj,1) * (                           ( pt  (ji,jj+1) + pt  (ji,jj)       &
-                  &                                               -          zcv * ( pt  (ji,jj+1) - pt  (ji,jj) ) )   &
-                  &        + z1_6 * zdy2 * ( zcv*zcv - 1._wp ) * (                   ztv2(ji,jj+1) + ztv2(ji,jj)       &
-                  &                                               - 0.5_wp * zcv * ( ztv2(ji,jj+1) - ztv2(ji,jj) ) ) )
-            END DO
-         END DO
-         !
-      CASE( 5 )                                                   !==  5th order central TIM  ==! (Eq. 29)
-         !
-         DO jj = 1, jpjm1
-            DO ji = 1, jpi
-               zcv  = pvc(ji,jj) * r1_e1v(ji,jj) * pdt * r1_e2v(ji,jj)
-               zdy2 = e2v(ji,jj) * e2v(ji,jj)
-!!rachid       zdy2 = e2v(ji,jj) * e2t(ji,jj)
-               zdy4 = zdy2 * zdy2
-               pt_v(ji,jj) = 0.5_wp * vmask(ji,jj,1) * (                                 ( pt  (ji,jj+1) + pt  (ji,jj)      &
-                  &                                                     -          zcv * ( pt  (ji,jj+1) - pt  (ji,jj) ) )  &
-                  &        + z1_6   * zdy2 * ( zcv*zcv - 1._wp ) *     (                   ztv2(ji,jj+1) + ztv2(ji,jj)      &
-                  &                                                     - 0.5_wp * zcv * ( ztv2(ji,jj+1) - ztv2(ji,jj) ) )  &
-                  &        + z1_120 * zdy4 * ( zcv*zcv - 1._wp ) * ( zcv*zcv - 4._wp ) * ( ztv4(ji,jj+1) + ztv4(ji,jj)      &
-                  &                                               - SIGN( 1._wp, zcv ) * ( ztv4(ji,jj+1) - ztv4(ji,jj) ) ) )
-            END DO
-         END DO
-         !
-      END SELECT
-      !
-      CALL wrk_dealloc( jpi,jpj,   ztv1, ztv2, ztv3, ztv4 )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('ultimate_y')
-      !
-   END SUBROUTINE ultimate_y
-   
-  
-   SUBROUTINE nonosc_2d( pbef, paa, pbb, paft, pdt )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE nonosc  ***
-      !!     
-      !! **  Purpose :   compute monotonic tracer fluxes from the upstream 
-      !!       scheme and the before field by a nonoscillatory algorithm 
-      !!
-      !! **  Method  :   ... ???
-      !!       warning : pbef and paft must be masked, but the boundaries
-      !!       conditions on the fluxes are not necessary zalezak (1979)
-      !!       drange (1995) multi-dimensional forward-in-time and upstream-
-      !!       in-space based differencing for fluid
-      !!----------------------------------------------------------------------
-      REAL(wp)                     , INTENT(in   ) ::   pdt          ! tracer time-step
-      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   pbef, paft   ! before & after field
-      REAL(wp), DIMENSION (jpi,jpj), INTENT(inout) ::   paa, pbb     ! monotonic fluxes in the 2 directions
-      !
-      INTEGER  ::   ji, jj    ! dummy loop indices
-      INTEGER  ::   ikm1      ! local integer
-      REAL(wp) ::   zpos, zneg, zbt, za, zb, zc, zbig, zsml, z1_dt   ! local scalars
-      REAL(wp) ::   zau, zbu, zcu, zav, zbv, zcv, zup, zdo            !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:) :: zbetup, zbetdo, zbup, zbdo, zmsk, zdiv
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('nonosc_2d')
-      !
-      CALL wrk_alloc( jpi,jpj,   zbetup, zbetdo, zbup, zbdo, zmsk, zdiv )
-      !
-      zbig = 1.e+40_wp
-      zsml = 1.e-15_wp
-
-      ! clem test
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1   ! vector opt.  
-            zdiv(ji,jj) =  - (  paa(ji,jj) - paa(ji-1,jj  )   &
-               &              + pbb(ji,jj) - pbb(ji  ,jj-1) )  
-         END DO
-      END DO
-      CALL lbc_lnk( zdiv, 'T', 1. )        ! Lateral boundary conditions   (unchanged sign)
-
-      ! Determine ice masks for before and after tracers 
-      WHERE( pbef(:,:) == 0._wp .AND. paft(:,:) == 0._wp .AND. zdiv(:,:) == 0._wp )   ;   zmsk(:,:) = 0._wp
-      ELSEWHERE                                                                       ;   zmsk(:,:) = 1._wp * tmask(:,:,1)
-      END WHERE
-
-      ! Search local extrema
-      ! --------------------
-      ! max/min of pbef & paft with large negative/positive value (-/+zbig) inside land
-!      zbup(:,:) = MAX( pbef(:,:) * tmask(:,:,1) - zbig * ( 1.e0 - tmask(:,:,1) ),   &
-!         &             paft(:,:) * tmask(:,:,1) - zbig * ( 1.e0 - tmask(:,:,1) )  )
-!      zbdo(:,:) = MIN( pbef(:,:) * tmask(:,:,1) + zbig * ( 1.e0 - tmask(:,:,1) ),   &
-!         &             paft(:,:) * tmask(:,:,1) + zbig * ( 1.e0 - tmask(:,:,1) )  )
-      zbup(:,:) = MAX( pbef(:,:) * zmsk(:,:) - zbig * ( 1.e0 - zmsk(:,:) ),   &
-         &             paft(:,:) * zmsk(:,:) - zbig * ( 1.e0 - zmsk(:,:) )  )
-      zbdo(:,:) = MIN( pbef(:,:) * zmsk(:,:) + zbig * ( 1.e0 - zmsk(:,:) ),   &
-         &             paft(:,:) * zmsk(:,:) + zbig * ( 1.e0 - zmsk(:,:) )  )
-
-      z1_dt = 1._wp / pdt
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1   ! vector opt.
-            !
-            zup  = MAX(   zbup(ji,jj), zbup(ji-1,jj  ), zbup(ji+1,jj  ),   &        ! search max/min in neighbourhood
-               &                       zbup(ji  ,jj-1), zbup(ji  ,jj+1)    )
-            zdo  = MIN(   zbdo(ji,jj), zbdo(ji-1,jj  ), zbdo(ji+1,jj  ),   &
-               &                       zbdo(ji  ,jj-1), zbdo(ji  ,jj+1)    )
-               !
-            zpos = MAX( 0., paa(ji-1,jj  ) ) - MIN( 0., paa(ji  ,jj  ) )   &        ! positive/negative  part of the flux
-               & + MAX( 0., pbb(ji  ,jj-1) ) - MIN( 0., pbb(ji  ,jj  ) )
-            zneg = MAX( 0., paa(ji  ,jj  ) ) - MIN( 0., paa(ji-1,jj  ) )   &
-               & + MAX( 0., pbb(ji  ,jj  ) ) - MIN( 0., pbb(ji  ,jj-1) )
-               !
-            zbt = e1e2t(ji,jj) * z1_dt                                   ! up & down beta terms
-            zbetup(ji,jj) = ( zup         - paft(ji,jj) ) / ( zpos + zsml ) * zbt
-            zbetdo(ji,jj) = ( paft(ji,jj) - zdo         ) / ( zneg + zsml ) * zbt
-         END DO
-      END DO
-      CALL lbc_lnk_multi( zbetup, 'T', 1., zbetdo, 'T', 1. )   ! lateral boundary cond. (unchanged sign)
-
-      ! monotonic flux in the i & j direction (paa & pbb)
-      ! -------------------------------------
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1   ! vector opt.
-            zau = MIN( 1._wp , zbetdo(ji,jj) , zbetup(ji+1,jj) )
-            zbu = MIN( 1._wp , zbetup(ji,jj) , zbetdo(ji+1,jj) )
-            zcu = 0.5  + SIGN( 0.5 , paa(ji,jj) )
-            !
-            zav = MIN( 1._wp , zbetdo(ji,jj) , zbetup(ji,jj+1) )
-            zbv = MIN( 1._wp , zbetup(ji,jj) , zbetdo(ji,jj+1) )
-            zcv = 0.5  + SIGN( 0.5 , pbb(ji,jj) )
-            !
-            paa(ji,jj) = paa(ji,jj) * ( zcu * zau + ( 1._wp - zcu) * zbu )
-            pbb(ji,jj) = pbb(ji,jj) * ( zcv * zav + ( 1._wp - zcv) * zbv )
-            !
-         END DO
-      END DO
-      CALL lbc_lnk_multi( paa, 'U', -1., pbb, 'V', -1. )   ! lateral boundary condition (changed sign)
-      !
-      CALL wrk_dealloc( jpi,jpj,   zbetup, zbetdo, zbup, zbdo, zmsk, zdiv )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('nonosc_2d')
-      !
-   END SUBROUTINE nonosc_2d
-
-   !!======================================================================
-END MODULE limadv_umx
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limcons.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limcons.F90	(revision 9018)
+++ 	(revision )
@@ -1,315 +1,0 @@
-MODULE limcons
-   !!======================================================================
-   !!                   ***  MODULE  limcons  ***
-   !! LIM-3 Sea Ice :   conservation check
-   !!======================================================================
-   !! History :   -   ! Original code from William H. Lipscomb, LANL
-   !!            3.0  ! 2004-06  (M. Vancoppenolle)   Energy Conservation 
-   !!            3.5  ! 2011-02  (G. Madec)  add mpp considerations
-   !!             -   ! 2014-05  (C. Rousset) add lim_cons_hsm
-   !!             -   ! 2015-03  (C. Rousset) add lim_cons_final
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!    lim_cons     :   checks whether energy, mass and salt are conserved 
-   !!----------------------------------------------------------------------
-   USE phycst         ! physical constants
-   USE ice            ! LIM-3 variables
-   USE dom_oce        ! ocean domain
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE sbc_oce , ONLY : sfx  ! Surface boundary condition: ocean fields
-   USE sbc_ice , ONLY : qevap_ice
-   
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_column_sum
-   PUBLIC   lim_column_sum_energy
-   PUBLIC   lim_cons_check
-   PUBLIC   lim_cons_hsm
-   PUBLIC   lim_cons_final
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_column_sum( ksum, pin, pout )
-      !!-------------------------------------------------------------------
-      !!               ***  ROUTINE lim_column_sum ***
-      !!
-      !! ** Purpose : Compute the sum of xin over nsum categories
-      !!
-      !! ** Method  : Arithmetics
-      !!
-      !! ** Action  : Gets xin(ji,jj,jl) and computes xout(ji,jj)
-      !!---------------------------------------------------------------------
-      INTEGER                   , INTENT(in   ) ::   ksum   ! number of categories/layers
-      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pin    ! input field
-      REAL(wp), DIMENSION(:,:)  , INTENT(  out) ::   pout   ! output field
-      !
-      INTEGER ::   jl   ! dummy loop indices
-      !!---------------------------------------------------------------------
-      !
-      pout(:,:) = pin(:,:,1)
-      DO jl = 2, ksum
-         pout(:,:) = pout(:,:) + pin(:,:,jl)
-      END DO
-      !
-   END SUBROUTINE lim_column_sum
-
-
-   SUBROUTINE lim_column_sum_energy( ksum, klay, pin, pout)
-      !!-------------------------------------------------------------------
-      !!               ***  ROUTINE lim_column_sum_energy ***
-      !!
-      !! ** Purpose : Compute the sum of xin over nsum categories
-      !!              and nlay layers
-      !!
-      !! ** Method  : Arithmetics
-      !!---------------------------------------------------------------------
-      INTEGER                                , INTENT(in   ) ::   ksum   !: number of categories
-      INTEGER                                , INTENT(in   ) ::   klay   !: number of vertical layers
-      REAL(wp), DIMENSION(jpi,jpj,nlay_i,jpl), INTENT(in   ) ::   pin    !: input field
-      REAL(wp), DIMENSION(jpi,jpj)           , INTENT(  out) ::   pout   !: output field
-      !
-      INTEGER ::   jk, jl   ! dummy loop indices
-      !!---------------------------------------------------------------------
-      !
-      pout(:,:) = 0._wp
-      DO jl = 1, ksum
-         DO jk = 2, klay 
-            pout(:,:) = pout(:,:) + pin(:,:,jk,jl)
-         END DO
-      END DO
-      !
-   END SUBROUTINE lim_column_sum_energy
-
-
-   SUBROUTINE lim_cons_check( px1, px2, pmax_err, cd_fieldid )
-      !!-------------------------------------------------------------------
-      !!               ***  ROUTINE lim_cons_check ***
-      !!
-      !! ** Purpose : Test the conservation of a certain variable
-      !!              For each physical grid cell, check that initial 
-      !!              and final values
-      !!              of a conserved field are equal to within a small value.
-      !!
-      !! ** Method  :
-      !!---------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   px1          !: initial field
-      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   px2          !: final field
-      REAL(wp)                , INTENT(in   ) ::   pmax_err     !: max allowed error
-      CHARACTER(len=15)       , INTENT(in   ) ::   cd_fieldid   !: field identifyer
-      !
-      INTEGER  ::   ji, jj          ! dummy loop indices
-      INTEGER  ::   inb_error       ! number of g.c where there is a cons. error
-      LOGICAL  ::   llconserv_err   ! = .true. if conservation check failed
-      REAL(wp) ::   zmean_error     ! mean error on error points
-      !!---------------------------------------------------------------------
-      !
-      IF(lwp) WRITE(numout,*) ' lim_cons_check '
-      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
-
-      llconserv_err = .FALSE.
-      inb_error     = 0
-      zmean_error   = 0._wp
-      IF( MAXVAL( px2(:,:) - px1(:,:) ) > pmax_err )   llconserv_err = .TRUE.
-
-      IF( llconserv_err ) THEN
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               IF( ABS( px2(ji,jj) - px1(ji,jj) ) > pmax_err ) THEN
-                  inb_error   = inb_error + 1
-                  zmean_error = zmean_error + ABS( px2(ji,jj) - px1(ji,jj) )
-                  !
-                  IF(lwp) THEN
-                     WRITE (numout,*) ' ALERTE 99 '
-                     WRITE (numout,*) ' Conservation error: ', cd_fieldid
-                     WRITE (numout,*) ' Point             : ', ji, jj 
-                     WRITE (numout,*) ' lat, lon          : ', gphit(ji,jj), glamt(ji,jj)
-                     WRITE (numout,*) ' Initial value     : ', px1(ji,jj)
-                     WRITE (numout,*) ' Final value       : ', px2(ji,jj)
-                     WRITE (numout,*) ' Difference        : ', px2(ji,jj) - px1(ji,jj)
-                  ENDIF
-               ENDIF
-            END DO
-         END DO
-         !
-      ENDIF
-      IF(lk_mpp)   CALL mpp_sum( inb_error   )
-      IF(lk_mpp)   CALL mpp_sum( zmean_error )
-      !
-      IF( inb_error > 0 .AND. lwp ) THEN
-         zmean_error = zmean_error / REAL( inb_error, wp )
-         WRITE(numout,*) ' Conservation check for : ', cd_fieldid
-         WRITE(numout,*) ' Number of error points : ', inb_error
-         WRITE(numout,*) ' Mean error on these pts: ', zmean_error
-      ENDIF
-      !
-   END SUBROUTINE lim_cons_check
-
-
-   SUBROUTINE lim_cons_hsm( icount, cd_routine, zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b )
-      !!--------------------------------------------------------------------------------------------------------
-      !!                                        ***  ROUTINE lim_cons_hsm ***
-      !!
-      !! ** Purpose : Test the conservation of heat, salt and mass for each ice routine
-      !!                     + test if ice concentration and volume are > 0
-      !!
-      !! ** Method  : This is an online diagnostics which can be activated with ln_limdiachk=true
-      !!              It prints in ocean.output if there is a violation of conservation at each time-step
-      !!              The thresholds (zv_sill, zs_sill, zh_sill) which determine violations are set to
-      !!              a minimum of 1 mm of ice (over the ice area) that is lost/gained spuriously during 100 years.
-      !!              For salt and heat thresholds, ice is considered to have a salinity of 10 
-      !!              and a heat content of 3e5 J/kg (=latent heat of fusion) 
-      !!--------------------------------------------------------------------------------------------------------
-      INTEGER         , INTENT(in)    :: icount        ! determine wether this is the beggining of the routine (0) or the end (1)
-      CHARACTER(len=*), INTENT(in)    :: cd_routine    ! name of the routine
-      REAL(wp)        , INTENT(inout) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
-      REAL(wp)                        :: zvi,   zsmv,   zei,   zfs,   zfw,   zft
-      REAL(wp)                        :: zvmin, zamin, zamax 
-      REAL(wp)                        :: zvtrp, zetrp
-      REAL(wp)                        :: zarea, zv_sill, zs_sill, zh_sill
-      REAL(wp), PARAMETER             :: zconv = 1.e-9 ! convert W to GW and kg to Mt
-
-      IF( icount == 0 ) THEN
-
-         ! salt flux
-         zfs_b  = glob_sum(  ( sfx_bri(:,:) + sfx_bog(:,:) + sfx_bom(:,:) + sfx_sum(:,:) + sfx_sni(:,:) +  &
-            &                  sfx_opw(:,:) + sfx_res(:,:) + sfx_dyn(:,:) + sfx_sub(:,:) + sfx_lam(:,:)    &
-            &                ) *  e1e2t(:,:) * tmask(:,:,1) * zconv )
-
-         ! water flux
-         zfw_b  = glob_sum( -( wfx_bog(:,:) + wfx_bom(:,:) + wfx_sum(:,:) + wfx_sni(:,:) + wfx_opw(:,:) +               &
-            &                  wfx_res(:,:) + wfx_dyn(:,:) + wfx_snw(:,:) + wfx_sub(:,:) + wfx_spr(:,:) + wfx_lam(:,:)  &
-            &                ) *  e1e2t(:,:) * tmask(:,:,1) * zconv )
-
-         ! heat flux
-         zft_b  = glob_sum(  ( hfx_sum(:,:) + hfx_bom(:,:) + hfx_bog(:,:) + hfx_dif(:,:) + hfx_opw(:,:) + hfx_snw(:,:)  & 
-            &                - hfx_thd(:,:) - hfx_dyn(:,:) - hfx_res(:,:) - hfx_sub(:,:) - hfx_spr(:,:)   &
-            &                ) *  e1e2t(:,:) * tmask(:,:,1) * zconv )
-
-         zvi_b  = glob_sum( SUM( v_i * rhoic + v_s * rhosn, dim=3 ) * e1e2t * tmask(:,:,1) * zconv )
-
-         zsmv_b = glob_sum( SUM( smv_i * rhoic            , dim=3 ) * e1e2t * tmask(:,:,1) * zconv )
-
-         zei_b  = glob_sum( ( SUM( SUM( e_i(:,:,1:nlay_i,:), dim=4 ), dim=3 ) +  &
-            &                 SUM( SUM( e_s(:,:,1:nlay_s,:), dim=4 ), dim=3 )    &
-                            ) * e1e2t * tmask(:,:,1) * zconv )
-
-      ELSEIF( icount == 1 ) THEN
-
-         ! salt flux
-         zfs  = glob_sum(  ( sfx_bri(:,:) + sfx_bog(:,:) + sfx_bom(:,:) + sfx_sum(:,:) + sfx_sni(:,:) +  &
-            &                sfx_opw(:,:) + sfx_res(:,:) + sfx_dyn(:,:) + sfx_sub(:,:) + sfx_lam(:,:)    & 
-            &              ) * e1e2t(:,:) * tmask(:,:,1) * zconv ) - zfs_b
-
-         ! water flux
-         zfw  = glob_sum( -( wfx_bog(:,:) + wfx_bom(:,:) + wfx_sum(:,:) + wfx_sni(:,:) + wfx_opw(:,:) +                &
-            &                wfx_res(:,:) + wfx_dyn(:,:) + wfx_snw(:,:) + wfx_sub(:,:) + wfx_spr(:,:) + wfx_lam(:,:)   &
-            &              ) * e1e2t(:,:) * tmask(:,:,1) * zconv ) - zfw_b
-
-         ! heat flux
-         zft  = glob_sum(  ( hfx_sum(:,:) + hfx_bom(:,:) + hfx_bog(:,:) + hfx_dif(:,:) + hfx_opw(:,:) + hfx_snw(:,:)  & 
-            &              - hfx_thd(:,:) - hfx_dyn(:,:) - hfx_res(:,:) - hfx_sub(:,:) - hfx_spr(:,:)   &
-            &              ) * e1e2t(:,:) * tmask(:,:,1) * zconv ) - zft_b
- 
-         ! outputs
-         zvi  = ( ( glob_sum( SUM( v_i * rhoic + v_s * rhosn, dim=3 )  &
-            &                    * e1e2t * tmask(:,:,1) * zconv ) - zvi_b ) * r1_rdtice - zfw ) * rday
-
-         zsmv = ( ( glob_sum( SUM( smv_i * rhoic            , dim=3 )  &
-            &                    * e1e2t * tmask(:,:,1) * zconv ) - zsmv_b ) * r1_rdtice + zfs ) * rday
-
-         zei  =   glob_sum( ( SUM( SUM( e_i(:,:,1:nlay_i,:), dim=4 ), dim=3 ) +  &
-            &                 SUM( SUM( e_s(:,:,1:nlay_s,:), dim=4 ), dim=3 )    &
-            &                ) * e1e2t * tmask(:,:,1) * zconv ) * r1_rdtice - zei_b * r1_rdtice + zft
-
-         ! zvtrp and zetrp must be close to 0 if the advection scheme is conservative
-         zvtrp = glob_sum( ( diag_trp_vi * rhoic + diag_trp_vs * rhosn ) * e1e2t * tmask(:,:,1) * zconv ) * rday 
-         zetrp = glob_sum( ( diag_trp_ei         + diag_trp_es         ) * e1e2t * tmask(:,:,1) * zconv )
-
-         zvmin = glob_min( v_i )
-         zamax = glob_max( SUM( a_i, dim=3 ) )
-         zamin = glob_min( a_i )
-
-         ! set threshold values and calculate the ice area (+epsi10 to set a threshold > 0 when there is no ice) 
-         zarea   = glob_sum( SUM( a_i + epsi10, dim=3 ) * e1e2t * zconv ) ! in 1.e9 m2
-         zv_sill = zarea * 2.5e-5
-         zs_sill = zarea * 25.e-5
-         zh_sill = zarea * 10.e-5
-
-         IF(lwp) THEN
-            IF ( ABS( zvi  ) > zv_sill ) WRITE(numout,*) 'violation volume [Mt/day]     (',cd_routine,') = ',zvi
-            IF ( ABS( zsmv ) > zs_sill ) WRITE(numout,*) 'violation saline [psu*Mt/day] (',cd_routine,') = ',zsmv
-            IF ( ABS( zei  ) > zh_sill ) WRITE(numout,*) 'violation enthalpy [GW]       (',cd_routine,') = ',zei
-            IF ( ABS(zvtrp ) > zv_sill .AND. cd_routine == 'limtrp' ) THEN
-                                         WRITE(numout,*) 'violation vtrp [Mt/day]       (',cd_routine,') = ',zvtrp
-                                         WRITE(numout,*) 'violation etrp [GW]           (',cd_routine,') = ',zetrp
-            ENDIF
-            IF (     zvmin   < -epsi10 ) WRITE(numout,*) 'violation v_i<0  [m]          (',cd_routine,') = ',zvmin
-            IF (     zamax   > MAX( rn_amax_n, rn_amax_s ) + epsi10 .AND. &
-               &                         cd_routine /= 'limtrp' .AND. cd_routine /= 'limitd_me' ) THEN
-                                         WRITE(numout,*) 'violation a_i>amax            (',cd_routine,') = ',zamax
-            IF (     zamax   > 1._wp   ) WRITE(numout,*) 'violation a_i>1               (',cd_routine,') = ',zamax
-            ENDIF
-            IF (      zamin  < -epsi10 ) WRITE(numout,*) 'violation a_i<0               (',cd_routine,') = ',zamin
-         ENDIF
-
-      ENDIF
-
-   END SUBROUTINE lim_cons_hsm
-
-   SUBROUTINE lim_cons_final( cd_routine )
-      !!---------------------------------------------------------------------------------------------------------
-      !!                                   ***  ROUTINE lim_cons_final ***
-      !!
-      !! ** Purpose : Test the conservation of heat, salt and mass at the end of each ice time-step
-      !!
-      !! ** Method  : This is an online diagnostics which can be activated with ln_limdiachk=true
-      !!              It prints in ocean.output if there is a violation of conservation at each time-step
-      !!              The thresholds (zv_sill, zs_sill, zh_sill) which determine the violation are set to
-      !!              a minimum of 1 mm of ice (over the ice area) that is lost/gained spuriously during 100 years.
-      !!              For salt and heat thresholds, ice is considered to have a salinity of 10 
-      !!              and a heat content of 3e5 J/kg (=latent heat of fusion) 
-      !!--------------------------------------------------------------------------------------------------------
-      CHARACTER(len=*), INTENT(in)    :: cd_routine    ! name of the routine
-      REAL(wp)                        :: zhfx, zsfx, zvfx
-      REAL(wp)                        :: zarea, zv_sill, zs_sill, zh_sill
-      REAL(wp), PARAMETER             :: zconv = 1.e-9 ! convert W to GW and kg to Mt
-
-      ! heat flux
-      zhfx  = glob_sum( ( hfx_in - hfx_out - diag_heat - diag_trp_ei - diag_trp_es   &
-      !  &              - SUM( qevap_ice * a_i_b, dim=3 )                           & !!clem: I think this line must be commented (but need check)
-         &              ) * e1e2t * tmask(:,:,1) * zconv ) 
-      ! salt flux
-      zsfx  = glob_sum( ( sfx + diag_smvi ) * e1e2t * tmask(:,:,1) * zconv ) * rday
-      ! water flux
-      zvfx  = glob_sum( ( wfx_ice + wfx_snw + wfx_spr + wfx_sub + diag_vice + diag_vsnw ) * e1e2t * tmask(:,:,1) * zconv ) * rday
-
-      ! set threshold values and calculate the ice area (+epsi10 to set a threshold > 0 when there is no ice) 
-      zarea   = glob_sum( SUM( a_i + epsi10, dim=3 ) * e1e2t * zconv ) ! in 1.e9 m2
-      zv_sill = zarea * 2.5e-5
-      zs_sill = zarea * 25.e-5
-      zh_sill = zarea * 10.e-5
-
-      IF( ABS( zvfx ) > zv_sill ) WRITE(numout,*) 'violation vfx    [Mt/day]       (',cd_routine,')  = ',(zvfx)
-      IF( ABS( zsfx ) > zs_sill ) WRITE(numout,*) 'violation sfx    [psu*Mt/day]   (',cd_routine,')  = ',(zsfx)
-      IF( ABS( zhfx ) > zh_sill ) WRITE(numout,*) 'violation hfx    [GW]           (',cd_routine,')  = ',(zhfx)
-
-   END SUBROUTINE lim_cons_final
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Empty module            NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-   !!======================================================================
-END MODULE limcons
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limctl.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limctl.F90	(revision 9018)
+++ 	(revision )
@@ -1,531 +1,0 @@
-MODULE limctl
-   !!======================================================================
-   !!                     ***  MODULE  limctl  ***
-   !!   LIM-3 : control and printing
-   !!======================================================================
-   !! History :  3.5  !  2015-01  (M. Vancoppenolle) Original code
-   !!            3.7  !  2016-10  (C. Rousset)       Add routine lim_prt3D
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!    lim_ctl   : control prints in case of crash
-   !!    lim_prt   : ice control print at a given grid point
-   !!    lim_prt3D : control prints of ice arrays
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE ice             ! LIM-3: ice variables
-   USE thd_ice         ! LIM-3: thermodynamical variables
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice   fields
-
-   USE phycst          ! Define parameters for the routines
-
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! work arrays
-   USE timing          ! Timing
-   USE in_out_manager  ! I/O manager
-   USE prtctl          ! Print control
-   USE lib_fortran     ! 
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_ctl
-   PUBLIC   lim_prt
-   PUBLIC   lim_prt3D
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limctl.F90 5043 2015-01-28 16:44:18Z clem $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE lim_ctl( kt )
-      !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_ctl *** 
-      !!                 
-      !! ** Purpose :   Alerts in case of model crash
-      !!-------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt      ! ocean time step
-      INTEGER  ::   ji, jj, jk,  jl   ! dummy loop indices
-      INTEGER  ::   inb_altests       ! number of alert tests (max 20)
-      INTEGER  ::   ialert_id         ! number of the current alert
-      REAL(wp) ::   ztmelts           ! ice layer melting point
-      CHARACTER (len=30), DIMENSION(20)      ::   cl_alname   ! name of alert
-      INTEGER           , DIMENSION(20)      ::   inb_alp     ! number of alerts positive
-      !!-------------------------------------------------------------------
-
-      inb_altests = 10
-      inb_alp(:)  =  0
-
-      ! Alert if incompatible volume and concentration
-      ialert_id = 2 ! reference number of this alert
-      cl_alname(ialert_id) = ' Incompat vol and con         '    ! name of the alert
-
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF(  v_i(ji,jj,jl) /= 0._wp   .AND.   a_i(ji,jj,jl) == 0._wp   ) THEN
-                  !WRITE(numout,*) ' ALERTE 2 :   Incompatible volume and concentration '
-                  !WRITE(numout,*) ' at_i     ', at_i(ji,jj)
-                  !WRITE(numout,*) ' Point - category', ji, jj, jl
-                  !WRITE(numout,*) ' a_i *** a_i_b   ', a_i      (ji,jj,jl), a_i_b  (ji,jj,jl)
-                  !WRITE(numout,*) ' v_i *** v_i_b   ', v_i      (ji,jj,jl), v_i_b  (ji,jj,jl)
-                  inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-               ENDIF
-            END DO
-         END DO
-      END DO
-
-      ! Alerte if very thick ice
-      ialert_id = 3 ! reference number of this alert
-      cl_alname(ialert_id) = ' Very thick ice               ' ! name of the alert
-      jl = jpl 
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF(   ht_i(ji,jj,jl)  >  50._wp   ) THEN
-               !CALL lim_prt( kt, ji, jj, 2, ' ALERTE 3 :   Very thick ice ' )
-               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-            ENDIF
-         END DO
-      END DO
-
-      ! Alert if very fast ice
-      ialert_id = 4 ! reference number of this alert
-      cl_alname(ialert_id) = ' Very fast ice               ' ! name of the alert
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF(   MAX( ABS( u_ice(ji,jj) ), ABS( v_ice(ji,jj) ) ) > 1.5  .AND.  &
-               &  at_i(ji,jj) > 0._wp   ) THEN
-               !CALL lim_prt( kt, ji, jj, 1, ' ALERTE 4 :   Very fast ice ' )
-               !WRITE(numout,*) ' ice strength             : ', strength(ji,jj)
-               !WRITE(numout,*) ' oceanic stress utau      : ', utau(ji,jj) 
-               !WRITE(numout,*) ' oceanic stress vtau      : ', vtau(ji,jj)
-               !WRITE(numout,*) ' sea-ice stress utau_ice  : ', utau_ice(ji,jj) 
-               !WRITE(numout,*) ' sea-ice stress vtau_ice  : ', vtau_ice(ji,jj)
-               !WRITE(numout,*) ' oceanic speed u          : ', u_oce(ji,jj)
-               !WRITE(numout,*) ' oceanic speed v          : ', v_oce(ji,jj)
-               !WRITE(numout,*) ' sst                      : ', sst_m(ji,jj)
-               !WRITE(numout,*) ' sss                      : ', sss_m(ji,jj)
-               !WRITE(numout,*) 
-               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-            ENDIF
-         END DO
-      END DO
-
-      ! Alert if there is ice on continents
-      ialert_id = 6 ! reference number of this alert
-      cl_alname(ialert_id) = ' Ice on continents           ' ! name of the alert
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF(   tmask(ji,jj,1) <= 0._wp   .AND.   at_i(ji,jj) > 0._wp   ) THEN 
-               !CALL lim_prt( kt, ji, jj, 1, ' ALERTE 6 :   Ice on continents ' )
-               !WRITE(numout,*) ' masks s, u, v        : ', tmask(ji,jj,1), umask(ji,jj,1), vmask(ji,jj,1) 
-               !WRITE(numout,*) ' sst                  : ', sst_m(ji,jj)
-               !WRITE(numout,*) ' sss                  : ', sss_m(ji,jj)
-               !WRITE(numout,*) ' at_i(ji,jj)          : ', at_i(ji,jj)
-               !WRITE(numout,*) ' v_ice(ji,jj)         : ', v_ice(ji,jj)
-               !WRITE(numout,*) ' v_ice(ji,jj-1)       : ', v_ice(ji,jj-1)
-               !WRITE(numout,*) ' u_ice(ji-1,jj)       : ', u_ice(ji-1,jj)
-               !WRITE(numout,*) ' u_ice(ji,jj)         : ', v_ice(ji,jj)
-               !
-               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-            ENDIF
-         END DO
-      END DO
-
-!
-!     ! Alert if very fresh ice
-      ialert_id = 7 ! reference number of this alert
-      cl_alname(ialert_id) = ' Very fresh ice               ' ! name of the alert
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( sm_i(ji,jj,jl) < 0.1 .AND. a_i(ji,jj,jl) > 0._wp ) THEN
-!                 CALL lim_prt(kt,ji,jj,1, ' ALERTE 7 :   Very fresh ice ' )
-!                 WRITE(numout,*) ' sst                  : ', sst_m(ji,jj)
-!                 WRITE(numout,*) ' sss                  : ', sss_m(ji,jj)
-!                 WRITE(numout,*) 
-                  inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-               ENDIF
-            END DO
-         END DO
-      END DO
-!
-
-!     ! Alert if too old ice
-      ialert_id = 9 ! reference number of this alert
-      cl_alname(ialert_id) = ' Very old   ice               ' ! name of the alert
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF ( ( ( ABS( o_i(ji,jj,jl) ) > rdt_ice ) .OR. &
-                      ( ABS( o_i(ji,jj,jl) ) < 0._wp) ) .AND. &
-                             ( a_i(ji,jj,jl) > 0._wp ) ) THEN
-                  !CALL lim_prt( kt, ji, jj, 1, ' ALERTE 9 :   Wrong ice age ')
-                  inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-               ENDIF
-            END DO
-         END DO
-      END DO
- 
-      ! Alert on salt flux
-      ialert_id = 5 ! reference number of this alert
-      cl_alname(ialert_id) = ' High salt flux               ' ! name of the alert
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( ABS( sfx (ji,jj) ) > 1.0e-2 ) THEN  ! = 1 psu/day for 1m ocean depth
-               !CALL lim_prt( kt, ji, jj, 3, ' ALERTE 5 :   High salt flux ' )
-               !DO jl = 1, jpl
-                  !WRITE(numout,*) ' Category no: ', jl
-                  !WRITE(numout,*) ' a_i        : ', a_i      (ji,jj,jl) , ' a_i_b      : ', a_i_b  (ji,jj,jl)   
-                  !WRITE(numout,*) ' v_i        : ', v_i      (ji,jj,jl) , ' v_i_b      : ', v_i_b  (ji,jj,jl)   
-                  !WRITE(numout,*) ' '
-               !END DO
-               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-            ENDIF
-         END DO
-      END DO
-
-      ! Alert if qns very big
-      ialert_id = 8 ! reference number of this alert
-      cl_alname(ialert_id) = ' fnsolar very big             ' ! name of the alert
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( ABS( qns(ji,jj) ) > 1500._wp .AND. at_i(ji,jj) > 0._wp ) THEN
-               !
-               !WRITE(numout,*) ' ALERTE 8 :   Very high non-solar heat flux'
-               !WRITE(numout,*) ' ji, jj    : ', ji, jj
-               !WRITE(numout,*) ' qns       : ', qns(ji,jj)
-               !WRITE(numout,*) ' sst       : ', sst_m(ji,jj)
-               !WRITE(numout,*) ' sss       : ', sss_m(ji,jj)
-               !
-               !CALL lim_prt( kt, ji, jj, 2, '   ')
-               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-               !
-            ENDIF
-         END DO
-      END DO
-      !+++++
- 
-      ! Alert if very warm ice
-      ialert_id = 10 ! reference number of this alert
-      cl_alname(ialert_id) = ' Very warm ice                ' ! name of the alert
-      inb_alp(ialert_id) = 0
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  ztmelts    =  -tmut * s_i(ji,jj,jk,jl) + rt0
-                  IF( t_i(ji,jj,jk,jl) >= ztmelts  .AND.  v_i(ji,jj,jl) > 1.e-10   &
-                     &                             .AND.  a_i(ji,jj,jl) > 0._wp   ) THEN
-                     !WRITE(numout,*) ' ALERTE 10 :   Very warm ice'
-                     !WRITE(numout,*) ' ji, jj, jk, jl : ', ji, jj, jk, jl
-                     !WRITE(numout,*) ' t_i : ', t_i(ji,jj,jk,jl)
-                     !WRITE(numout,*) ' e_i : ', e_i(ji,jj,jk,jl)
-                     !WRITE(numout,*) ' s_i : ', s_i(ji,jj,jk,jl)
-                     !WRITE(numout,*) ' ztmelts : ', ztmelts
-                     inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-                  ENDIF
-               END DO
-            END DO
-         END DO
-      END DO
-
-      ! sum of the alerts on all processors
-      IF( lk_mpp ) THEN
-         DO ialert_id = 1, inb_altests
-            CALL mpp_sum(inb_alp(ialert_id))
-         END DO
-      ENDIF
-
-      ! print alerts
-      IF( lwp ) THEN
-         ialert_id = 1                                 ! reference number of this alert
-         cl_alname(ialert_id) = ' NO alerte 1      '   ! name of the alert
-         WRITE(numout,*) ' time step ',kt
-         WRITE(numout,*) ' All alerts at the end of ice model '
-         DO ialert_id = 1, inb_altests
-            WRITE(numout,*) ialert_id, cl_alname(ialert_id)//' : ', inb_alp(ialert_id), ' times ! '
-         END DO
-      ENDIF
-     !
-   END SUBROUTINE lim_ctl
- 
-   
-   SUBROUTINE lim_prt( kt, ki, kj, kn, cd1 )
-      !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_prt *** 
-      !!                 
-      !! ** Purpose :   Writes global ice state on the (i,j) point 
-      !!                in ocean.ouput 
-      !!                3 possibilities exist 
-      !!                n = 1/-1 -> simple ice state (plus Mechanical Check if -1)
-      !!                n = 2    -> exhaustive state
-      !!                n = 3    -> ice/ocean salt fluxes
-      !!
-      !! ** input   :   point coordinates (i,j) 
-      !!                n : number of the option
-      !!-------------------------------------------------------------------
-      INTEGER         , INTENT(in) ::   kt            ! ocean time step
-      INTEGER         , INTENT(in) ::   ki, kj, kn    ! ocean gridpoint indices
-      CHARACTER(len=*), INTENT(in) ::   cd1           !
-      !!
-      INTEGER :: jl, ji, jj
-      !!-------------------------------------------------------------------
-
-      DO ji = mi0(ki), mi1(ki)
-         DO jj = mj0(kj), mj1(kj)
-
-            WRITE(numout,*) ' time step ',kt,' ',cd1             ! print title
-
-            !----------------
-            !  Simple state
-            !----------------
-            
-            IF ( kn == 1 .OR. kn == -1 ) THEN
-               WRITE(numout,*) ' lim_prt - Point : ',ji,jj
-               WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
-               WRITE(numout,*) ' Simple state '
-               WRITE(numout,*) ' masks s,u,v   : ', tmask(ji,jj,1), umask(ji,jj,1), vmask(ji,jj,1)
-               WRITE(numout,*) ' lat - long    : ', gphit(ji,jj), glamt(ji,jj)
-               WRITE(numout,*) ' Time step     : ', numit
-               WRITE(numout,*) ' - Ice drift   '
-               WRITE(numout,*) '   ~~~~~~~~~~~ '
-               WRITE(numout,*) ' u_ice(i-1,j)  : ', u_ice(ji-1,jj)
-               WRITE(numout,*) ' u_ice(i  ,j)  : ', u_ice(ji,jj)
-               WRITE(numout,*) ' v_ice(i  ,j-1): ', v_ice(ji,jj-1)
-               WRITE(numout,*) ' v_ice(i  ,j)  : ', v_ice(ji,jj)
-               WRITE(numout,*) ' strength      : ', strength(ji,jj)
-               WRITE(numout,*)
-               WRITE(numout,*) ' - Cell values '
-               WRITE(numout,*) '   ~~~~~~~~~~~ '
-               WRITE(numout,*) ' cell area     : ', e1e2t(ji,jj)
-               WRITE(numout,*) ' at_i          : ', at_i(ji,jj)       
-               WRITE(numout,*) ' vt_i          : ', vt_i(ji,jj)       
-               WRITE(numout,*) ' vt_s          : ', vt_s(ji,jj)       
-               DO jl = 1, jpl
-                  WRITE(numout,*) ' - Category (', jl,')'
-                  WRITE(numout,*) ' a_i           : ', a_i(ji,jj,jl)
-                  WRITE(numout,*) ' ht_i          : ', ht_i(ji,jj,jl)
-                  WRITE(numout,*) ' ht_s          : ', ht_s(ji,jj,jl)
-                  WRITE(numout,*) ' v_i           : ', v_i(ji,jj,jl)
-                  WRITE(numout,*) ' v_s           : ', v_s(ji,jj,jl)
-                  WRITE(numout,*) ' e_s           : ', e_s(ji,jj,1,jl)
-                  WRITE(numout,*) ' e_i           : ', e_i(ji,jj,1:nlay_i,jl)
-                  WRITE(numout,*) ' t_su          : ', t_su(ji,jj,jl)
-                  WRITE(numout,*) ' t_snow        : ', t_s(ji,jj,1,jl)
-                  WRITE(numout,*) ' t_i           : ', t_i(ji,jj,1:nlay_i,jl)
-                  WRITE(numout,*) ' sm_i          : ', sm_i(ji,jj,jl)
-                  WRITE(numout,*) ' smv_i         : ', smv_i(ji,jj,jl)
-                  WRITE(numout,*)
-               END DO
-            ENDIF
-            IF( kn == -1 ) THEN
-               WRITE(numout,*) ' Mechanical Check ************** '
-               WRITE(numout,*) ' Check what means ice divergence '
-               WRITE(numout,*) ' Total ice concentration ', at_i (ji,jj)
-               WRITE(numout,*) ' Total lead fraction     ', ato_i(ji,jj)
-               WRITE(numout,*) ' Sum of both             ', ato_i(ji,jj) + at_i(ji,jj)
-               WRITE(numout,*) ' Sum of both minus 1     ', ato_i(ji,jj) + at_i(ji,jj) - 1.00
-            ENDIF
-            
-
-            !--------------------
-            !  Exhaustive state
-            !--------------------
-            
-            IF ( kn .EQ. 2 ) THEN
-               WRITE(numout,*) ' lim_prt - Point : ',ji,jj
-               WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
-               WRITE(numout,*) ' Exhaustive state '
-               WRITE(numout,*) ' lat - long ', gphit(ji,jj), glamt(ji,jj)
-               WRITE(numout,*) ' Time step ', numit
-               WRITE(numout,*) 
-               WRITE(numout,*) ' - Cell values '
-               WRITE(numout,*) '   ~~~~~~~~~~~ '
-               WRITE(numout,*) ' cell area     : ', e1e2t(ji,jj)
-               WRITE(numout,*) ' at_i          : ', at_i(ji,jj)       
-               WRITE(numout,*) ' vt_i          : ', vt_i(ji,jj)       
-               WRITE(numout,*) ' vt_s          : ', vt_s(ji,jj)       
-               WRITE(numout,*) ' u_ice(i-1,j)  : ', u_ice(ji-1,jj)
-               WRITE(numout,*) ' u_ice(i  ,j)  : ', u_ice(ji,jj)
-               WRITE(numout,*) ' v_ice(i  ,j-1): ', v_ice(ji,jj-1)
-               WRITE(numout,*) ' v_ice(i  ,j)  : ', v_ice(ji,jj)
-               WRITE(numout,*) ' strength      : ', strength(ji,jj)
-               WRITE(numout,*) ' u_ice_b       : ', u_ice_b(ji,jj)    , ' v_ice_b       : ', v_ice_b(ji,jj)  
-               WRITE(numout,*)
-               
-               DO jl = 1, jpl
-                  WRITE(numout,*) ' - Category (',jl,')'
-                  WRITE(numout,*) '   ~~~~~~~~         ' 
-                  WRITE(numout,*) ' ht_i       : ', ht_i(ji,jj,jl)             , ' ht_s       : ', ht_s(ji,jj,jl)
-                  WRITE(numout,*) ' t_i        : ', t_i(ji,jj,1:nlay_i,jl)
-                  WRITE(numout,*) ' t_su       : ', t_su(ji,jj,jl)             , ' t_s        : ', t_s(ji,jj,1,jl)
-                  WRITE(numout,*) ' sm_i       : ', sm_i(ji,jj,jl)             , ' o_i        : ', o_i(ji,jj,jl)
-                  WRITE(numout,*) ' a_i        : ', a_i(ji,jj,jl)              , ' a_i_b      : ', a_i_b(ji,jj,jl)   
-                  WRITE(numout,*) ' v_i        : ', v_i(ji,jj,jl)              , ' v_i_b      : ', v_i_b(ji,jj,jl)   
-                  WRITE(numout,*) ' v_s        : ', v_s(ji,jj,jl)              , ' v_s_b      : ', v_s_b(ji,jj,jl)  
-                  WRITE(numout,*) ' e_i1       : ', e_i(ji,jj,1,jl)            , ' ei1        : ', e_i_b(ji,jj,1,jl) 
-                  WRITE(numout,*) ' e_i2       : ', e_i(ji,jj,2,jl)            , ' ei2_b      : ', e_i_b(ji,jj,2,jl)  
-                  WRITE(numout,*) ' e_snow     : ', e_s(ji,jj,1,jl)            , ' e_snow_b   : ', e_s_b(ji,jj,1,jl) 
-                  WRITE(numout,*) ' smv_i      : ', smv_i(ji,jj,jl)            , ' smv_i_b    : ', smv_i_b(ji,jj,jl)   
-                  WRITE(numout,*) ' oa_i       : ', oa_i(ji,jj,jl)             , ' oa_i_b     : ', oa_i_b(ji,jj,jl)
-               END DO !jl
-               
-               WRITE(numout,*)
-               WRITE(numout,*) ' - Heat / FW fluxes '
-               WRITE(numout,*) '   ~~~~~~~~~~~~~~~~ '
-               WRITE(numout,*) ' - Heat fluxes in and out the ice ***'
-               WRITE(numout,*) ' qsr_ini       : ', pfrld(ji,jj) * qsr(ji,jj) + SUM( a_i_b(ji,jj,:) * qsr_ice(ji,jj,:) )
-               WRITE(numout,*) ' qns_ini       : ', pfrld(ji,jj) * qns(ji,jj) + SUM( a_i_b(ji,jj,:) * qns_ice(ji,jj,:) )
-               WRITE(numout,*)
-               WRITE(numout,*) 
-               WRITE(numout,*) ' sst        : ', sst_m(ji,jj)  
-               WRITE(numout,*) ' sss        : ', sss_m(ji,jj)  
-               WRITE(numout,*) 
-               WRITE(numout,*) ' - Stresses '
-               WRITE(numout,*) '   ~~~~~~~~ '
-               WRITE(numout,*) ' utau_ice   : ', utau_ice(ji,jj) 
-               WRITE(numout,*) ' vtau_ice   : ', vtau_ice(ji,jj)
-               WRITE(numout,*) ' utau       : ', utau    (ji,jj) 
-               WRITE(numout,*) ' vtau       : ', vtau    (ji,jj)
-               WRITE(numout,*) ' oc. vel. u : ', u_oce   (ji,jj)
-               WRITE(numout,*) ' oc. vel. v : ', v_oce   (ji,jj)
-            ENDIF
-            
-            !---------------------
-            ! Salt / heat fluxes
-            !---------------------
-            
-            IF ( kn .EQ. 3 ) THEN
-               WRITE(numout,*) ' lim_prt - Point : ',ji,jj
-               WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
-               WRITE(numout,*) ' - Salt / Heat Fluxes '
-               WRITE(numout,*) '   ~~~~~~~~~~~~~~~~ '
-               WRITE(numout,*) ' lat - long ', gphit(ji,jj), glamt(ji,jj)
-               WRITE(numout,*) ' Time step ', numit
-               WRITE(numout,*)
-               WRITE(numout,*) ' - Heat fluxes at bottom interface ***'
-               WRITE(numout,*) ' qsr       : ', qsr(ji,jj)
-               WRITE(numout,*) ' qns       : ', qns(ji,jj)
-               WRITE(numout,*)
-               WRITE(numout,*) ' hfx_mass     : ', hfx_thd(ji,jj) + hfx_dyn(ji,jj) + hfx_snw(ji,jj) + hfx_res(ji,jj)
-               WRITE(numout,*) ' hfx_in       : ', hfx_in(ji,jj)
-               WRITE(numout,*) ' hfx_out      : ', hfx_out(ji,jj)
-               WRITE(numout,*) ' dhc          : ', diag_heat(ji,jj)              
-               WRITE(numout,*)
-               WRITE(numout,*) ' hfx_dyn      : ', hfx_dyn(ji,jj)
-               WRITE(numout,*) ' hfx_thd      : ', hfx_thd(ji,jj)
-               WRITE(numout,*) ' hfx_res      : ', hfx_res(ji,jj)
-               WRITE(numout,*) ' fhtur        : ', fhtur(ji,jj) 
-               WRITE(numout,*) ' qlead        : ', qlead(ji,jj) * r1_rdtice
-               WRITE(numout,*)
-               WRITE(numout,*) ' - Salt fluxes at bottom interface ***'
-               WRITE(numout,*) ' emp       : ', emp    (ji,jj)
-               WRITE(numout,*) ' sfx       : ', sfx    (ji,jj)
-               WRITE(numout,*) ' sfx_res   : ', sfx_res(ji,jj)
-               WRITE(numout,*) ' sfx_bri   : ', sfx_bri(ji,jj)
-               WRITE(numout,*) ' sfx_dyn   : ', sfx_dyn(ji,jj)
-               WRITE(numout,*)
-               WRITE(numout,*) ' - Momentum fluxes '
-               WRITE(numout,*) ' utau      : ', utau(ji,jj) 
-               WRITE(numout,*) ' vtau      : ', vtau(ji,jj)
-            ENDIF 
-            WRITE(numout,*) ' '
-            !
-         END DO
-      END DO
-      !
-   END SUBROUTINE lim_prt
-
-   SUBROUTINE lim_prt3D( cd_routine )
-      !!---------------------------------------------------------------------------------------------------------
-      !!                                   ***  ROUTINE lim_prt3D ***
-      !!
-      !! ** Purpose : CTL prints of ice arrays in case ln_ctl is activated 
-      !!
-      !!---------------------------------------------------------------------------------------------------------
-      CHARACTER(len=*), INTENT(in)  :: cd_routine    ! name of the routine
-      INTEGER                       :: jk, jl        ! dummy loop indices
-      
-      CALL prt_ctl_info(' ========== ')
-      CALL prt_ctl_info( cd_routine )
-      CALL prt_ctl_info(' ========== ')
-      CALL prt_ctl_info(' - Cell values : ')
-      CALL prt_ctl_info('   ~~~~~~~~~~~~~ ')
-      CALL prt_ctl(tab2d_1=e1e2t      , clinfo1=' cell area   :')
-      CALL prt_ctl(tab2d_1=at_i       , clinfo1=' at_i        :')
-      CALL prt_ctl(tab2d_1=ato_i      , clinfo1=' ato_i       :')
-      CALL prt_ctl(tab2d_1=vt_i       , clinfo1=' vt_i        :')
-      CALL prt_ctl(tab2d_1=vt_s       , clinfo1=' vt_s        :')
-      CALL prt_ctl(tab2d_1=divu_i     , clinfo1=' divu_i      :')
-      CALL prt_ctl(tab2d_1=delta_i    , clinfo1=' delta_i     :')
-      CALL prt_ctl(tab2d_1=stress1_i  , clinfo1=' stress1_i   :')
-      CALL prt_ctl(tab2d_1=stress2_i  , clinfo1=' stress2_i   :')
-      CALL prt_ctl(tab2d_1=stress12_i , clinfo1=' stress12_i  :')
-      CALL prt_ctl(tab2d_1=strength   , clinfo1=' strength    :')
-      CALL prt_ctl(tab2d_1=delta_i    , clinfo1=' delta_i     :')
-      CALL prt_ctl(tab2d_1=u_ice      , clinfo1=' u_ice       :', tab2d_2=v_ice      , clinfo2=' v_ice       :')
-       
-      DO jl = 1, jpl
-         CALL prt_ctl_info(' ')
-         CALL prt_ctl_info(' - Category : ', ivar1=jl)
-         CALL prt_ctl_info('   ~~~~~~~~~~')
-         CALL prt_ctl(tab2d_1=ht_i       (:,:,jl)        , clinfo1= ' ht_i        : ')
-         CALL prt_ctl(tab2d_1=ht_s       (:,:,jl)        , clinfo1= ' ht_s        : ')
-         CALL prt_ctl(tab2d_1=t_su       (:,:,jl)        , clinfo1= ' t_su        : ')
-         CALL prt_ctl(tab2d_1=t_s        (:,:,1,jl)      , clinfo1= ' t_snow      : ')
-         CALL prt_ctl(tab2d_1=sm_i       (:,:,jl)        , clinfo1= ' sm_i        : ')
-         CALL prt_ctl(tab2d_1=o_i        (:,:,jl)        , clinfo1= ' o_i         : ')
-         CALL prt_ctl(tab2d_1=a_i        (:,:,jl)        , clinfo1= ' a_i         : ')
-         CALL prt_ctl(tab2d_1=v_i        (:,:,jl)        , clinfo1= ' v_i         : ')
-         CALL prt_ctl(tab2d_1=v_s        (:,:,jl)        , clinfo1= ' v_s         : ')
-         CALL prt_ctl(tab2d_1=e_i        (:,:,1,jl)      , clinfo1= ' e_i1        : ')
-         CALL prt_ctl(tab2d_1=e_s        (:,:,1,jl)      , clinfo1= ' e_snow      : ')
-         CALL prt_ctl(tab2d_1=smv_i      (:,:,jl)        , clinfo1= ' smv_i       : ')
-         CALL prt_ctl(tab2d_1=oa_i       (:,:,jl)        , clinfo1= ' oa_i        : ')
-         
-         DO jk = 1, nlay_i
-            CALL prt_ctl_info(' - Layer : ', ivar1=jk)
-            CALL prt_ctl(tab2d_1=t_i(:,:,jk,jl) , clinfo1= ' t_i       : ')
-         END DO
-      END DO
-      
-      CALL prt_ctl_info(' ')
-      CALL prt_ctl_info(' - Heat / FW fluxes : ')
-      CALL prt_ctl_info('   ~~~~~~~~~~~~~~~~~~ ')
-      CALL prt_ctl(tab2d_1=sst_m  , clinfo1= ' sst   : ', tab2d_2=sss_m     , clinfo2= ' sss       : ')
-      CALL prt_ctl(tab2d_1=qsr    , clinfo1= ' qsr   : ', tab2d_2=qns       , clinfo2= ' qns       : ')
-      CALL prt_ctl(tab2d_1=emp    , clinfo1= ' emp   : ', tab2d_2=sfx       , clinfo2= ' sfx       : ')
-      
-      CALL prt_ctl_info(' ')
-      CALL prt_ctl_info(' - Stresses : ')
-      CALL prt_ctl_info('   ~~~~~~~~~~ ')
-      CALL prt_ctl(tab2d_1=utau       , clinfo1= ' utau      : ', tab2d_2=vtau       , clinfo2= ' vtau      : ')
-      CALL prt_ctl(tab2d_1=utau_ice   , clinfo1= ' utau_ice  : ', tab2d_2=vtau_ice   , clinfo2= ' vtau_ice  : ')
-      CALL prt_ctl(tab2d_1=u_oce      , clinfo1= ' u_oce     : ', tab2d_2=v_oce      , clinfo2= ' v_oce     : ')
-      
-   END SUBROUTINE lim_prt3D
-
-#else
-   !!--------------------------------------------------------------------------
-   !!   Default option         Empty Module               No LIM3 sea-ice model
-   !!--------------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_ctl     ! Empty routine
-   END SUBROUTINE lim_ctl
-   SUBROUTINE lim_prt     ! Empty routine
-   END SUBROUTINE lim_prt
-   SUBROUTINE lim_prt3D   ! Empty routine
-   END SUBROUTINE lim_prt3D
-#endif
-   !!======================================================================
-END MODULE limctl
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limdiahsb.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limdiahsb.F90	(revision 9018)
+++ 	(revision )
@@ -1,247 +1,0 @@
-MODULE limdiahsb
-   !!======================================================================
-   !!                       ***  MODULE limdia_hsb   ***
-   !!  LIM-3 sea ice model :   diagnostics of ice model 
-   !!======================================================================
-   !! History :  3.4  ! 2012-10  (C. Rousset)  original code
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                       LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_dia_hsb        : computation and output of the time evolution of keys variables
-   !!   lim_dia_hsb_init   : initialization and namelist read
-   !!----------------------------------------------------------------------
-   USE ice             ! LIM-3: sea-ice variable
-   USE dom_oce         ! ocean domain
-   USE sbc_oce         ! surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: sea-ice fields
-   USE daymod          ! model calendar
-   USE phycst          ! physical constant
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! MPP library
-   USE timing          ! preformance summary
-   USE iom             ! I/O manager
-   USE lib_fortran     ! glob_sum
-   USE limrst          ! ice restart
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_diahsb        ! routine called by ice_step.F90
-   PUBLIC   lim_diahsb_init   ! routine called in sbcice_lim.F90
-
-   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   vol_loc_ini, sal_loc_ini, tem_loc_ini ! initial volume, salt and heat contents
-   REAL(wp)                              ::   frc_sal, frc_voltop, frc_volbot, frc_temtop, frc_tembot  ! global forcing trends
-   
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.4 , NEMO Consortium (2012)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE lim_diahsb( kt )
-      !!---------------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_diahsb  ***
-      !!     
-      !! ** Purpose: Compute the ice global heat content, salt content and volume conservation
-      !!	
-      !!---------------------------------------------------------------------------
-      INTEGER, INTENT(in) :: kt    ! number of iteration
-      !!
-      real(wp)   ::   zbg_ivol, zbg_svol, zbg_area, zbg_isal, zbg_item ,zbg_stem
-      REAL(wp)   ::   z_frc_voltop, z_frc_volbot, z_frc_sal, z_frc_temtop, z_frc_tembot  
-      REAL(wp)   ::   zdiff_vol, zdiff_sal, zdiff_tem  
-      !!---------------------------------------------------------------------------
-      IF( nn_timing == 1 )   CALL timing_start('lim_diahsb')
-
-      ! ----------------------- !
-      ! 1 -  Contents !
-      ! ----------------------- !
-      zbg_ivol = glob_sum( vt_i(:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )                  ! ice volume (km3)
-      zbg_svol = glob_sum( vt_s(:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )                  ! snow volume (km3)
-      zbg_area = glob_sum( at_i(:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-6 )                  ! area (km2)
-      zbg_isal = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 ) ! salt content (pss*km3)
-      zbg_item = glob_sum( et_i * e1e2t(:,:) * tmask(:,:,1) * 1.e-20 )                      ! heat content (1.e20 J)
-      zbg_stem = glob_sum( et_s * e1e2t(:,:) * tmask(:,:,1) * 1.e-20 )                      ! heat content (1.e20 J)
-      
-      ! ---------------------------!
-      ! 2 - Trends due to forcing  !
-      ! ---------------------------!
-      z_frc_volbot = r1_rau0 * glob_sum( - ( wfx_ice(:,:) + wfx_snw(:,:) + wfx_err_sub(:,:) ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )  ! freshwater flux ice/snow-ocean 
-      z_frc_voltop = r1_rau0 * glob_sum( - ( wfx_sub(:,:) + wfx_spr(:,:) ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )                     ! freshwater flux ice/snow-atm
-      z_frc_sal    = r1_rau0 * glob_sum( - sfx(:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )                                            ! salt fluxes ice/snow-ocean
-      z_frc_tembot =           glob_sum( hfx_out(:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-20 )                                         ! heat on top of ocean (and below ice)
-      z_frc_temtop =           glob_sum( hfx_in (:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-20 )                                         ! heat on top of ice-coean
-      !
-      frc_voltop  = frc_voltop  + z_frc_voltop  * rdt_ice ! km3
-      frc_volbot  = frc_volbot  + z_frc_volbot  * rdt_ice ! km3
-      frc_sal     = frc_sal     + z_frc_sal     * rdt_ice ! km3*pss
-      frc_temtop  = frc_temtop  + z_frc_temtop  * rdt_ice ! 1.e20 J
-      frc_tembot  = frc_tembot  + z_frc_tembot  * rdt_ice ! 1.e20 J
-            
-      ! ----------------------- !
-      ! 3 -  Content variations !
-      ! ----------------------- !
-      zdiff_vol = r1_rau0 * glob_sum( ( rhoic * vt_i(:,:) + rhosn * vt_s(:,:) - vol_loc_ini(:,:)  &  ! freshwater trend (km3) 
-         &                            ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 ) 
-      zdiff_sal = r1_rau0 * glob_sum( ( rhoic * SUM( smv_i(:,:,:), dim=3 ) - sal_loc_ini(:,:)     &  ! salt content trend (km3*pss)
-         &                            ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )
-      zdiff_tem =           glob_sum( ( et_i(:,:) + et_s(:,:) - tem_loc_ini(:,:)                  &  ! heat content trend (1.e20 J)
-      !  &                            + SUM( qevap_ice * a_i_b, dim=3 ) &     !! clem: I think this line should be commented (but needs a check)
-         &                            ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-20 )
-
-      ! ----------------------- !
-      ! 4 -  Drifts             !
-      ! ----------------------- !
-      zdiff_vol = zdiff_vol - ( frc_voltop + frc_volbot )
-      zdiff_sal = zdiff_sal - frc_sal
-      zdiff_tem = zdiff_tem - ( frc_tembot - frc_temtop )
-
-      ! ----------------------- !
-      ! 5 - Diagnostics writing !
-      ! ----------------------- !
-      !
-      IF( iom_use('ibgvolume') )  CALL iom_put( 'ibgvolume' , zdiff_vol        )   ! ice/snow volume  drift            (km3 equivalent ocean water)         
-      IF( iom_use('ibgsaltco') )  CALL iom_put( 'ibgsaltco' , zdiff_sal        )   ! ice salt content drift            (psu*km3 equivalent ocean water)
-      IF( iom_use('ibgheatco') )  CALL iom_put( 'ibgheatco' , zdiff_tem        )   ! ice/snow heat content drift       (1.e20 J)
-      IF( iom_use('ibgheatfx') )  CALL iom_put( 'ibgheatfx' , zdiff_tem /      &   ! ice/snow heat flux drift          (W/m2)
-         &                                                    glob_sum( e1e2t(:,:) * tmask(:,:,1) * 1.e-20 * kt*rdt ) )
-
-      IF( iom_use('ibgfrcvoltop') )  CALL iom_put( 'ibgfrcvoltop' , frc_voltop )   ! vol  forcing ice/snw-atm          (km3 equivalent ocean water) 
-      IF( iom_use('ibgfrcvolbot') )  CALL iom_put( 'ibgfrcvolbot' , frc_volbot )   ! vol  forcing ice/snw-ocean        (km3 equivalent ocean water) 
-      IF( iom_use('ibgfrcsal') )     CALL iom_put( 'ibgfrcsal'    , frc_sal    )   ! sal - forcing                     (psu*km3 equivalent ocean water)   
-      IF( iom_use('ibgfrctemtop') )  CALL iom_put( 'ibgfrctemtop' , frc_temtop )   ! heat on top of ice/snw/ocean      (1.e20 J)   
-      IF( iom_use('ibgfrctembot') )  CALL iom_put( 'ibgfrctembot' , frc_tembot )   ! heat on top of ocean(below ice)   (1.e20 J)   
-      IF( iom_use('ibgfrchfxtop') )  CALL iom_put( 'ibgfrchfxtop' , frc_temtop / & ! heat on top of ice/snw/ocean      (W/m2) 
-         &                                                    glob_sum( e1e2t(:,:) * tmask(:,:,1) * 1.e-20 * kt*rdt ) )
-      IF( iom_use('ibgfrchfxbot') )  CALL iom_put( 'ibgfrchfxbot' , frc_tembot / & ! heat on top of ocean(below ice)   (W/m2) 
-         &                                                    glob_sum( e1e2t(:,:) * tmask(:,:,1) * 1.e-20 * kt*rdt ) )
-
-      IF( iom_use('ibgvol_tot' ) )  CALL iom_put( 'ibgvol_tot'  , zbg_ivol     )   ! ice volume                        (km3)
-      IF( iom_use('sbgvol_tot' ) )  CALL iom_put( 'sbgvol_tot'  , zbg_svol     )   ! snow volume                       (km3)
-      IF( iom_use('ibgarea_tot') )  CALL iom_put( 'ibgarea_tot' , zbg_area     )   ! ice area                          (km2)
-      IF( iom_use('ibgsalt_tot') )  CALL iom_put( 'ibgsalt_tot' , zbg_isal     )   ! ice salinity content              (pss*km3)
-      IF( iom_use('ibgheat_tot') )  CALL iom_put( 'ibgheat_tot' , zbg_item     )   ! ice heat content                  (1.e20 J)
-      IF( iom_use('sbgheat_tot') )  CALL iom_put( 'sbgheat_tot' , zbg_stem     )   ! snow heat content                 (1.e20 J)
-      !
-      IF( lrst_ice )   CALL lim_diahsb_rst( numit, 'WRITE' )
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('lim_diahsb')
-      !
-   END SUBROUTINE lim_diahsb
-
-
-   SUBROUTINE lim_diahsb_init
-      !!---------------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_diahsb_init  ***
-      !!     
-      !! ** Purpose: Initialization for the heat salt volume budgets
-      !!	
-      !! ** Method : Compute initial heat content, salt content and volume
-      !!
-      !! ** Action : - Compute initial heat content, salt content and volume
-      !!             - Initialize forcing trends
-      !!             - Compute coefficients for conversion
-      !!---------------------------------------------------------------------------
-      INTEGER            ::   ierror   ! local integer
-      !!
-      !!NAMELIST/namicehsb/ blabla
-      !!----------------------------------------------------------------------
-      !
-      !!REWIND ( numnam_ice )              ! Read Namelist namicehsb 
-      !!READ   ( numnam_ice, namicehsb )
-      !
-      IF(lwp) THEN                   ! Control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_diahsb_init : check the heat and salt budgets'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-      ENDIF
-      !      
-      ALLOCATE( vol_loc_ini(jpi,jpj), sal_loc_ini(jpi,jpj), tem_loc_ini(jpi,jpj), STAT=ierror )
-      IF( ierror > 0 )  THEN
-         CALL ctl_stop( 'lim_diahsb: unable to allocate vol_loc_ini' )
-         RETURN
-      ENDIF
-
-      CALL lim_diahsb_rst( nstart, 'READ' )  !* read or initialize all required files
-      !
-   END SUBROUTINE lim_diahsb_init
-
-   SUBROUTINE lim_diahsb_rst( kt, cdrw )
-     !!---------------------------------------------------------------------
-     !!                   ***  ROUTINE limdia_rst  ***
-     !!                     
-     !! ** Purpose :   Read or write DIA file in restart file
-     !!
-     !! ** Method  :   use of IOM library
-     !!----------------------------------------------------------------------
-     INTEGER         , INTENT(in) ::   kt     ! ice time-step
-     CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
-     !
-     !!----------------------------------------------------------------------
-     !
-     IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
-        IF( ln_rstart ) THEN                   !* Read the restart file
-           !
-           IF(lwp) WRITE(numout,*) '~~~~~~~'
-           IF(lwp) WRITE(numout,*) ' lim_diahsb_rst read at it= ', kt,' date= ', ndastp
-           IF(lwp) WRITE(numout,*) '~~~~~~~'
-           CALL iom_get( numrir, 'frc_voltop' , frc_voltop  )
-           CALL iom_get( numrir, 'frc_volbot' , frc_volbot  )
-           CALL iom_get( numrir, 'frc_temtop' , frc_temtop  )
-           CALL iom_get( numrir, 'frc_tembot' , frc_tembot  )
-           CALL iom_get( numrir, 'frc_sal'    , frc_sal     )
-           CALL iom_get( numrir, jpdom_autoglo, 'vol_loc_ini', vol_loc_ini )
-           CALL iom_get( numrir, jpdom_autoglo, 'tem_loc_ini', tem_loc_ini )
-           CALL iom_get( numrir, jpdom_autoglo, 'sal_loc_ini', sal_loc_ini )
-        ELSE
-           IF(lwp) WRITE(numout,*) '~~~~~~~'
-           IF(lwp) WRITE(numout,*) ' lim_diahsb at initial state '
-           IF(lwp) WRITE(numout,*) '~~~~~~~'
-           ! set trends to 0
-           frc_voltop  = 0._wp                                          
-           frc_volbot  = 0._wp                                          
-           frc_temtop  = 0._wp                                                 
-           frc_tembot  = 0._wp                                                 
-           frc_sal     = 0._wp                                                 
-           ! record initial ice volume, salt and temp
-           vol_loc_ini(:,:) = rhoic * vt_i(:,:) + rhosn * vt_s(:,:)  ! ice/snow volume (kg/m2)
-           tem_loc_ini(:,:) = et_i(:,:) + et_s(:,:)                  ! ice/snow heat content (J)
-           sal_loc_ini(:,:) = rhoic * SUM( smv_i(:,:,:), dim=3 )     ! ice salt content (pss*kg/m2)
-           
-       ENDIF
-
-     ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
-        !                                   ! -------------------
-        IF(lwp) WRITE(numout,*) '~~~~~~~'
-        IF(lwp) WRITE(numout,*) ' lim_diahsb_rst write at it= ', kt,' date= ', ndastp
-        IF(lwp) WRITE(numout,*) '~~~~~~~'
-        CALL iom_rstput( kt, nitrst, numriw, 'frc_voltop' , frc_voltop  )
-        CALL iom_rstput( kt, nitrst, numriw, 'frc_volbot' , frc_volbot  )
-        CALL iom_rstput( kt, nitrst, numriw, 'frc_temtop' , frc_temtop  )
-        CALL iom_rstput( kt, nitrst, numriw, 'frc_tembot' , frc_tembot  )
-        CALL iom_rstput( kt, nitrst, numriw, 'frc_sal'    , frc_sal     )
-        CALL iom_rstput( kt, nitrst, numriw, 'vol_loc_ini', vol_loc_ini )
-        CALL iom_rstput( kt, nitrst, numriw, 'tem_loc_ini', tem_loc_ini )
-        CALL iom_rstput( kt, nitrst, numriw, 'sal_loc_ini', sal_loc_ini )
-        !
-     ENDIF
-     !
-   END SUBROUTINE lim_diahsb_rst
- 
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :         Empty module          NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_diahsb          ! Empty routine
-   END SUBROUTINE lim_diahsb
-#endif
-   !!======================================================================
-END MODULE limdiahsb
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limdyn.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limdyn.F90	(revision 9018)
+++ 	(revision )
@@ -1,161 +1,0 @@
-MODULE limdyn
-   !!======================================================================
-   !!                     ***  MODULE  limdyn  ***
-   !!   Sea-Ice dynamics :  
-   !!======================================================================
-   !! history :  1.0  ! 2002-08  (C. Ethe, G. Madec)  original VP code 
-   !!            3.0  ! 2007-03  (MA Morales Maqueda, S. Bouillon, M. Vancoppenolle)  LIM3: EVP-Cgrid
-   !!            3.5  ! 2011-02  (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                 LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!    lim_dyn      : computes ice velocities
-   !!    lim_dyn_init : initialization and namelist read
-   !!----------------------------------------------------------------------
-   USE phycst           ! physical constants
-   USE dom_oce          ! ocean space and time domain
-   USE sbc_ice          ! Surface boundary condition: ice   fields
-   USE ice              ! LIM-3 variables
-   USE limrhg           ! LIM-3 rheology
-   USE lbclnk           ! lateral boundary conditions - MPP exchanges
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE in_out_manager   ! I/O manager
-   USE lib_fortran      ! glob_sum
-   USE timing           ! Timing
-   USE limcons          ! conservation tests
-   USE limctl           ! control prints
-   USE limvar
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_dyn        ! routine called by sbcice_lim.F90
-   PUBLIC   lim_dyn_init   ! routine called by sbcice_lim.F90
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_dyn( kt )
-      !!-------------------------------------------------------------------
-      !!               ***  ROUTINE lim_dyn  ***
-      !!               
-      !! ** Purpose :   compute ice velocity
-      !!                
-      !! ** Method  : 
-      !!
-      !! ** Action  : - Initialisation
-      !!              - Call of the dynamic routine for each hemisphere
-      !!------------------------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt     ! number of iteration
-      !!
-      INTEGER  :: jl, jk ! dummy loop indices
-      REAL(wp) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
-     !!---------------------------------------------------------------------
-
-      IF( nn_timing == 1 )  CALL timing_start('limdyn')
-
-      CALL lim_var_agg(1)                      ! aggregate ice categories
-      !
-      ! conservation test
-      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'limdyn', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-      
-      ! ice velocities before rheology
-      u_ice_b(:,:) = u_ice(:,:) * umask(:,:,1)
-      v_ice_b(:,:) = v_ice(:,:) * vmask(:,:,1)
-      
-      ! Landfast ice parameterization: define max bottom friction
-      tau_icebfr(:,:) = 0._wp
-      IF( ln_landfast ) THEN
-         DO jl = 1, jpl
-            WHERE( ht_i(:,:,jl) > ht_n(:,:) * rn_gamma )  tau_icebfr(:,:) = tau_icebfr(:,:) + a_i(:,:,jl) * rn_icebfr
-         END DO
-      ENDIF
-      
-      ! Rheology (ice dynamics)
-      ! ========     
-      CALL lim_rhg
-      !
-      ! conservation test
-      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'limdyn', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      ! Control prints
-      IF( ln_ctl )       CALL lim_prt3D( 'limdyn' )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('limdyn')
-
-   END SUBROUTINE lim_dyn
-
-
-   SUBROUTINE lim_dyn_init
-      !!-------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_dyn_init  ***
-      !!
-      !! ** Purpose : Physical constants and parameters linked to the ice
-      !!      dynamics
-      !!
-      !! ** Method  :  Read the namicedyn namelist and check the ice-dynamic
-      !!       parameter values called at the first timestep (nit000)
-      !!
-      !! ** input   :   Namelist namicedyn
-      !!-------------------------------------------------------------------
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namicedyn/ nn_limadv, nn_limadv_ord,  &
-         &                nn_icestr, ln_icestr_bvf, rn_pe_rdg, rn_pstar, rn_crhg, rn_cio, rn_creepl, rn_ecc, &
-         &                nn_nevp, rn_relast, ln_landfast, rn_gamma, rn_icebfr, rn_lfrelax
-      !!-------------------------------------------------------------------
-
-      REWIND( numnam_ice_ref )              ! Namelist namicedyn in reference namelist : Ice dynamics
-      READ  ( numnam_ice_ref, namicedyn, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicedyn in reference namelist', lwp )
-
-      REWIND( numnam_ice_cfg )              ! Namelist namicedyn in configuration namelist : Ice dynamics
-      READ  ( numnam_ice_cfg, namicedyn, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicedyn in configuration namelist', lwp )
-      IF(lwm) WRITE ( numoni, namicedyn )
-      
-      IF(lwp) THEN                        ! control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_dyn_init : ice parameters for ice dynamics '
-         WRITE(numout,*) '~~~~~~~~~~~~'
-         ! limtrp
-         WRITE(numout,*)'    choose the advection scheme (-1=Prather, 0=Ulimate-Macho)   nn_limadv     = ', nn_limadv 
-         WRITE(numout,*)'    choose the order of the scheme (if ultimate)                nn_limadv_ord = ', nn_limadv_ord  
-         ! limrhg
-         WRITE(numout,*)'    ice strength parameterization (0=Hibler 1=Rothrock)         nn_icestr     = ', nn_icestr 
-         WRITE(numout,*)'    Including brine volume in ice strength comp.                ln_icestr_bvf = ', ln_icestr_bvf
-         WRITE(numout,*)'    Ratio of ridging work to PotEner change in ridging          rn_pe_rdg     = ', rn_pe_rdg 
-         WRITE(numout,*) '   drag coefficient for oceanic stress                         rn_cio        = ', rn_cio
-         WRITE(numout,*) '   first bulk-rheology parameter                               rn_pstar      = ', rn_pstar
-         WRITE(numout,*) '   second bulk-rhelogy parameter                               rn_crhg       = ', rn_crhg
-         WRITE(numout,*) '   creep limit                                                 rn_creepl     = ', rn_creepl
-         WRITE(numout,*) '   eccentricity of the elliptical yield curve                  rn_ecc        = ', rn_ecc
-         WRITE(numout,*) '   number of iterations for subcycling                         nn_nevp       = ', nn_nevp
-         WRITE(numout,*) '   ratio of elastic timescale over ice time step               rn_relast     = ', rn_relast
-         WRITE(numout,*) '   Landfast: param (T or F)                                    ln_landfast   = ', ln_landfast
-         WRITE(numout,*) '   Landfast: fraction of ocean depth that ice must reach       rn_gamma      = ', rn_gamma
-         WRITE(numout,*) '   Landfast: maximum bottom stress per unit area of contact    rn_icebfr     = ', rn_icebfr
-         WRITE(numout,*) '   Landfast: relax time scale (s-1) to reach static friction   rn_lfrelax    = ', rn_lfrelax
-      ENDIF
-      !
-   END SUBROUTINE lim_dyn_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option          Empty module           NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_dyn         ! Empty routine
-   END SUBROUTINE lim_dyn
-#endif 
-
-   !!======================================================================
-END MODULE limdyn
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limhdf.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limhdf.F90	(revision 9018)
+++ 	(revision )
@@ -1,303 +1,0 @@
-MODULE limhdf
-   !!======================================================================
-   !!                    ***  MODULE limhdf   ***
-   !! LIM ice model : horizontal diffusion of sea-ice quantities
-   !!======================================================================
-   !! History :  LIM  !  2000-01 (LIM) Original code
-   !!             -   !  2001-05 (G. Madec, R. Hordoir) opa norm
-   !!            1.0  !  2002-08 (C. Ethe)  F90, free form
-   !!            3.6  !  2015-08 (O. Tintó and M. Castrillo)  added lim_hdf (multiple)
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_hdf       : diffusion trend on sea-ice variable
-   !!   lim_hdf_init  : initialisation of diffusion trend on sea-ice variable
-   !!----------------------------------------------------------------------
-   USE dom_oce        ! ocean domain
-   USE ice            ! LIM-3: ice variables
-   USE lbclnk         ! lateral boundary condition - MPP exchanges
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
-   USE prtctl         ! Print control
-   USE in_out_manager ! I/O manager
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_hdf         ! called by lim_trp
-   PUBLIC   lim_hdf_init    ! called by sbc_lim_init
-
-   LOGICAL  ::   linit = .TRUE.                             ! initialization flag (set to flase after the 1st call)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   efact   ! metric coefficient
-
-   !! * Substitution 
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_hdf( ptab, ihdf_vars )
-      !!-------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_hdf  ***
-      !!
-      !! ** purpose :   Compute and add the diffusive trend on sea-ice variables
-      !!
-      !! ** method  :   Second order diffusive operator evaluated using a
-      !!              Cranck-Nicholson time Scheme.
-      !!
-      !! ** Action  :    update ptab with the diffusive contribution
-      !!-------------------------------------------------------------------
-      INTEGER,                    INTENT( in )            ::  ihdf_vars ! number of fields to diffuse
-      REAL(wp), DIMENSION(:,:,:), INTENT( inout ), TARGET ::  ptab      ! Field on which the diffusion is applied
-      !
-      INTEGER                             ::  ji, jj, jk, jl, jm        ! dummy loop indices
-      INTEGER                             ::  iter, ierr, isize         ! local integers
-      REAL(wp)                            ::  zrlxint
-      CHARACTER(lc)                       ::  charout                   ! local character
-      REAL(wp), PARAMETER                 ::  zrelax = 0.5_wp           ! relaxation constant for iterative procedure
-      REAL(wp), PARAMETER                 ::  zalfa  = 0.5_wp           ! =1.0/0.5/0.0 = implicit/Cranck-Nicholson/explicit
-      INTEGER , PARAMETER                 ::  num_iter_max = 100        ! Maximum number of iteration
-      INTEGER , PARAMETER                 ::  num_convfrq  = 5          ! convergence check frequency of the Crant-Nicholson scheme (perf. optimization)
-      REAL(wp), POINTER, DIMENSION(:)     ::  zconv
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zrlx, zdiv0, ztab0
-      REAL(wp), POINTER, DIMENSION(:,:)   ::  zflu, zflv, zdiv
-      !!-------------------------------------------------------------------
-      TYPE(arrayptr)   , ALLOCATABLE, DIMENSION(:) ::   pt2d_array, zrlx_array
-      CHARACTER(len=1) , ALLOCATABLE, DIMENSION(:) ::   type_array      ! define the nature of ptab array grid-points
-      !                                                                 ! = T , U , V , F , W and I points
-      REAL(wp)         , ALLOCATABLE, DIMENSION(:) ::   psgn_array      ! =-1 the sign change across the north fold boundary
-      !!-------------------------------------------------------------------
-      
-      !                       !==  Initialisation  ==!
-      ! +1 open water diffusion
-      isize = jpl * ( ihdf_vars + nlay_i ) + 1
-      ALLOCATE( zconv (isize) )
-      ALLOCATE( pt2d_array(isize) , zrlx_array(isize) )
-      ALLOCATE( type_array(isize) )
-      ALLOCATE( psgn_array(isize) )
-
-      CALL wrk_alloc( jpi,jpj,       zflu, zflv, zdiv )
-      CALL wrk_alloc( jpi,jpj,isize, zrlx, zdiv0, ztab0 )
-      
-      DO jk= 1, isize
-         pt2d_array(jk)%pt2d => ptab(:,:,jk)
-         zrlx_array(jk)%pt2d => zrlx(:,:,jk)
-         type_array(jk) = 'T'
-         psgn_array(jk) = 1.
-      END DO
-
-      !
-      IF( linit ) THEN              ! Metric coefficient (compute at the first call and saved in efact)
-         ALLOCATE( efact(jpi,jpj) , STAT=ierr )
-         IF( lk_mpp    )   CALL mpp_sum( ierr )
-         IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'lim_hdf : unable to allocate arrays' )
-         DO jj = 2, jpjm1  
-            DO ji = fs_2 , fs_jpim1   ! vector opt.
-               efact(ji,jj) = ( e2u(ji,jj) + e2u(ji-1,jj) + e1v(ji,jj) + e1v(ji,jj-1) ) * r1_e1e2t(ji,jj)
-            END DO
-         END DO
-         linit = .FALSE.
-      ENDIF
-      !
-      ! Arrays initialization
-      zflu(jpi,:) = 0._wp   
-      zflv(jpi,:) = 0._wp
-      DO jk=1 , isize
-         ztab0(:, : , jk ) = ptab(:,:,jk)
-         zdiv0(:, 1 , jk ) = 0._wp
-         zdiv0(:,jpj, jk ) = 0._wp
-         zdiv0(1,  :, jk ) = 0._wp
-         zdiv0(jpi,:, jk ) = 0._wp
-      END DO
-
-      !                !==  horizontal diffusion using a Crant-Nicholson scheme  ==!
-      zconv(:) = 1._wp
-      iter     = 0
-      !
-      DO WHILE( MAXVAL( zconv(:) ) > ( 2._wp * 1.e-04 ) .AND. iter <= num_iter_max )   ! Sub-time step loop
-         !
-         iter = iter + 1                                 ! incrementation of the sub-time step number
-         !
-         DO jk = 1 , isize
-            jl = ( jk - 1 ) / ( ihdf_vars + nlay_i ) + 1
-            IF ( zconv(jk) > ( 2._wp * 1.e-04 ) ) THEN
-               DO jj = 1, jpjm1                                ! diffusive fluxes in U- and V- direction
-                  DO ji = 1 , fs_jpim1   ! vector opt.
-                     zflu(ji,jj) = pahu3D(ji,jj,jl) * e2u(ji,jj) * r1_e1u(ji,jj) * ( ptab(ji+1,jj,jk) - ptab(ji,jj,jk) )
-                     zflv(ji,jj) = pahv3D(ji,jj,jl) * e1v(ji,jj) * r1_e2v(ji,jj) * ( ptab(ji,jj+1,jk) - ptab(ji,jj,jk) )
-                  END DO
-               END DO
-               !
-               DO jj= 2, jpjm1                                 ! diffusive trend : divergence of the fluxes
-                  DO ji = fs_2 , fs_jpim1   ! vector opt. 
-                     zdiv(ji,jj) = ( zflu(ji,jj) - zflu(ji-1,jj) + zflv(ji,jj) - zflv(ji,jj-1) ) * r1_e1e2t(ji,jj)
-                  END DO
-               END DO
-               !
-               IF( iter == 1 )   zdiv0(:,:,jk) = zdiv(:,:)        ! save the 1st evaluation of the diffusive trend in zdiv0
-               !
-               DO jj = 2, jpjm1                                ! iterative evaluation
-                  DO ji = fs_2 , fs_jpim1   ! vector opt.
-                     zrlxint = (   ztab0(ji,jj,jk)    &
-                        &       +  rdt_ice * (           zalfa   * ( zdiv(ji,jj) + efact(ji,jj) * ptab(ji,jj,jk) )   &
-                        &                      + ( 1.0 - zalfa ) *   zdiv0(ji,jj,jk) )                               &
-                        &      ) / ( 1.0 + zalfa * rdt_ice * efact(ji,jj) )
-                     zrlx(ji,jj,jk) = ptab(ji,jj,jk) + zrelax * ( zrlxint - ptab(ji,jj,jk) )
-                  END DO
-               END DO
-            END IF
-
-         END DO
-
-         CALL lbc_lnk_multi( zrlx_array, type_array , psgn_array , isize ) ! Multiple interchange of all the variables
-         !
-
-         IF ( MOD( iter-1 , num_convfrq ) == 0 )  THEN   ! Convergence test every num_convfrq iterations (perf. optimization ) 
-            DO jk = 1, isize
-               zconv(jk) = 0._wp                                   ! convergence test
-               DO jj = 2, jpjm1
-                  DO ji = fs_2, fs_jpim1
-                     zconv(jk) = MAX( zconv(jk), ABS( zrlx(ji,jj,jk) - ptab(ji,jj,jk) )  )
-                  END DO
-               END DO
-            END DO
-            IF( lk_mpp ) CALL mpp_max_multiple( zconv , isize )            ! max over the global domain for all the variables
-         ENDIF
-         !
-         DO jk=1,isize
-            ptab(:,:,jk) = zrlx(:,:,jk)
-         END DO
-         !
-      END DO  ! end of sub-time step loop
-
-     ! --- final step --- !
-      DO jk = 1, isize
-         jl = ( jk - 1 ) / ( ihdf_vars + nlay_i ) + 1
-         DO jj = 1, jpjm1                                ! diffusive fluxes in U- and V- direction
-            DO ji = 1 , fs_jpim1   ! vector opt.
-               zflu(ji,jj) = pahu3D(ji,jj,jl) * e2u(ji,jj) * r1_e1u(ji,jj) * ( ptab(ji+1,jj,jk) - ptab(ji,jj,jk) )
-               zflv(ji,jj) = pahv3D(ji,jj,jl) * e1v(ji,jj) * r1_e2v(ji,jj) * ( ptab(ji,jj+1,jk) - ptab(ji,jj,jk) )
-            END DO
-         END DO
-         !
-         DO jj= 2, jpjm1                                 ! diffusive trend : divergence of the fluxes
-            DO ji = fs_2 , fs_jpim1   ! vector opt. 
-               zdiv(ji,jj) = ( zflu(ji,jj) - zflu(ji-1,jj) + zflv(ji,jj) - zflv(ji,jj-1) ) * r1_e1e2t(ji,jj)
-               ptab(ji,jj,jk) = ztab0(ji,jj,jk) + 0.5 * ( zdiv(ji,jj) + zdiv0(ji,jj,jk) )
-            END DO
-         END DO
-      END DO
-
-      CALL lbc_lnk_multi( pt2d_array, type_array , psgn_array , isize ) ! Multiple interchange of all the variables
-
-      !
-      IF(ln_ctl)   THEN
-         DO jk = 1 , isize
-            zrlx(:,:,jk) = ptab(:,:,jk) - ztab0(:,:,jk)
-            WRITE(charout,FMT="(' lim_hdf  : zconv =',D23.16, ' iter =',I4,2X)") zconv, iter
-            CALL prt_ctl( tab2d_1=zrlx(:,:,jk), clinfo1=charout )
-         END DO
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi,jpj,       zflu, zflv, zdiv )
-      CALL wrk_dealloc( jpi,jpj,isize, zrlx, zdiv0, ztab0 )
-      !
-      DEALLOCATE( zconv )
-      DEALLOCATE( pt2d_array , zrlx_array )
-      DEALLOCATE( type_array )
-      DEALLOCATE( psgn_array )
-      !
-   END SUBROUTINE lim_hdf
-
-   
-   SUBROUTINE lim_hdf_init
-      !!-------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_hdf_init  ***
-      !!
-      !! ** Purpose : Initialisation of horizontal diffusion of sea-ice 
-      !!
-      !! ** Method  : Read the namicehdf namelist
-      !!
-      !! ** input   : Namelist namicehdf
-      !!-------------------------------------------------------------------
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namicehdf/ nn_ahi0, rn_ahi0_ref
-      INTEGER  ::   ji, jj
-      REAL(wp) ::   za00, zd_max
-      !!-------------------------------------------------------------------
-      !
-      REWIND( numnam_ice_ref )              ! Namelist namicehdf in reference namelist : Ice horizontal diffusion
-      READ  ( numnam_ice_ref, namicehdf, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicehdf in reference namelist', lwp )
-
-      REWIND( numnam_ice_cfg )              ! Namelist namicehdf in configuration namelist : Ice horizontal diffusion
-      READ  ( numnam_ice_cfg, namicehdf, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicehdf in configuration namelist', lwp )
-      IF(lwm) WRITE ( numoni, namicehdf )
-      !
-      IF(lwp) THEN                          ! control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_hdf_init : Ice horizontal diffusion'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*) '   horizontal diffusivity calculation                          nn_ahi0      = ', nn_ahi0
-         WRITE(numout,*) '   horizontal diffusivity coeff. (orca2 grid)                  rn_ahi0_ref  = ', rn_ahi0_ref
-      ENDIF
-      !
-      !  Diffusion coefficients
-      SELECT CASE( nn_ahi0 )
-
-      CASE( 0 )
-         ahiu(:,:) = rn_ahi0_ref
-         ahiv(:,:) = rn_ahi0_ref
-
-         IF(lwp) WRITE(numout,*) ''
-         IF(lwp) WRITE(numout,*) '   laplacian operator: ahim constant = rn_ahi0_ref'
-
-      CASE( 1 ) 
-
-         zd_max = MAX( MAXVAL( e1t(:,:) ), MAXVAL( e2t(:,:) ) )
-         IF( lk_mpp )   CALL mpp_max( zd_max )          ! max over the global domain
-         
-         ahiu(:,:) = rn_ahi0_ref * zd_max * 1.e-05_wp   ! 1.e05 = 100km = max grid space at 60deg latitude in orca2
-                                                        !                    (60deg = min latitude for ice cover)  
-         ahiv(:,:) = rn_ahi0_ref * zd_max * 1.e-05_wp
-
-         IF(lwp) WRITE(numout,*) ''
-         IF(lwp) WRITE(numout,*) '   laplacian operator: ahim proportional to max of e1 e2 over the domain (', zd_max, ')'
-         IF(lwp) WRITE(numout,*) '   value for ahim = ', rn_ahi0_ref * zd_max * 1.e-05_wp 
-         
-      CASE( 2 ) 
-
-         zd_max = MAX( MAXVAL( e1t(:,:) ), MAXVAL( e2t(:,:) ) )
-         IF( lk_mpp )   CALL mpp_max( zd_max )   ! max over the global domain
-         
-         za00 = rn_ahi0_ref * 1.e-05_wp          ! 1.e05 = 100km = max grid space at 60deg latitude in orca2
-                                                 !                    (60deg = min latitude for ice cover)  
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ahiu(ji,jj) = za00 * MAX( e1t(ji,jj), e2t(ji,jj) ) * umask(ji,jj,1)
-               ahiv(ji,jj) = za00 * MAX( e1f(ji,jj), e2f(ji,jj) ) * vmask(ji,jj,1)
-            END DO
-         END DO
-         !
-         IF(lwp) WRITE(numout,*) ''
-         IF(lwp) WRITE(numout,*) '   laplacian operator: ahim proportional to e1'
-         IF(lwp) WRITE(numout,*) '   maximum grid-spacing = ', zd_max, ' maximum value for ahim = ', za00*zd_max
-         
-      END SELECT
-      !
-   END SUBROUTINE lim_hdf_init
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option          Dummy module           NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-
-   !!======================================================================
-END MODULE limhdf
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90	(revision 9018)
+++ 	(revision )
@@ -1,571 +1,0 @@
-MODULE limistate
-   !!======================================================================
-   !!                     ***  MODULE  limistate  ***
-   !!              Initialisation of diagnostics ice variables
-   !!======================================================================
-   !! History :  2.0  ! 2004-01 (C. Ethe, G. Madec)  Original code
-   !!            3.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!             -   ! 2014    (C. Rousset) add N/S initializations
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                    LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_istate      :  Initialisation of diagnostics ice variables
-   !!   lim_istate_init :  initialization of ice state and namelist read
-   !!----------------------------------------------------------------------
-   USE phycst           ! physical constant
-   USE oce              ! dynamics and tracers variables
-   USE dom_oce          ! ocean domain
-   USE sbc_oce          ! Surface boundary condition: ocean fields
-   USE sbc_ice          ! Surface boundary condition: ice fields
-   USE eosbn2           ! equation of state
-   USE ice              ! sea-ice variables
-   USE par_oce          ! ocean parameters
-   USE limvar           ! lim_var_salprof
-   !
-   USE in_out_manager   ! I/O manager
-   USE lib_mpp          ! MPP library
-   USE lib_fortran      ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE wrk_nemo         ! work arrays
-   USE fldread          ! read input fields
-   USE iom
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_istate      ! routine called by lim_init.F90
-
-   INTEGER , PARAMETER ::   jpfldi = 6           ! maximum number of files to read
-   INTEGER , PARAMETER ::   jp_hti = 1           ! index of ice thickness (m)    at T-point
-   INTEGER , PARAMETER ::   jp_hts = 2           ! index of snow thicknes (m)    at T-point
-   INTEGER , PARAMETER ::   jp_ati = 3           ! index of ice fraction (%) at T-point
-   INTEGER , PARAMETER ::   jp_tsu = 4           ! index of ice surface temp (K)    at T-point
-   INTEGER , PARAMETER ::   jp_tmi = 5           ! index of ice temp at T-point
-   INTEGER , PARAMETER ::   jp_smi = 6           ! index of ice sali at T-point
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   si  ! structure of input fields (file informations, fields read)
-   !!----------------------------------------------------------------------
-   !!   LIM 3.0,  UCL-LOCEAN-IPSL (2008)
-   !! $Id$
-   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_istate
-      !!-------------------------------------------------------------------
-      !!                    ***  ROUTINE lim_istate  ***
-      !!
-      !! ** Purpose :   defined the sea-ice initial state
-      !!
-      !! ** Method  :   This routine will put some ice where ocean
-      !!                is at the freezing point, then fill in ice 
-      !!                state variables using prescribed initial 
-      !!                values in the namelist            
-      !!
-      !! ** Steps   :   1) Read namelist
-      !!                2) Basal temperature; ice and hemisphere masks
-      !!                3) Fill in the ice thickness distribution using gaussian
-      !!                4) Fill in space-dependent arrays for state variables
-      !!                5) Diagnostic arrays
-      !!                6) Lateral boundary conditions
-      !!
-      !! ** Notes   : o_i, t_su, t_s, t_i, s_i must be filled everywhere, even
-      !!              where there is no ice (clem: I do not know why, is it mandatory?) 
-      !!
-      !! History :
-      !!   2.0  !  01-04  (C. Ethe, G. Madec)  Original code
-      !!   3.0  !  2007   (M. Vancoppenolle)   Rewrite for ice cats
-      !!   4.0  !  09-11  (M. Vancoppenolle)   Enhanced version for ice cats
-      !!--------------------------------------------------------------------
-      INTEGER  :: ji, jj, jk, jl   ! dummy loop indices
-      REAL(wp) :: ztmelts, zdh
-      INTEGER  :: i_hemis, i_fill, jl0  
-      REAL(wp)   :: zarg, zV, zconv, zdv 
-      REAL(wp), POINTER, DIMENSION(:,:)   :: zswitch    ! ice indicator
-      REAL(wp), POINTER, DIMENSION(:,:)   :: zht_i_ini, zat_i_ini, zvt_i_ini            !data from namelist or nc file
-      REAL(wp), POINTER, DIMENSION(:,:)   :: zts_u_ini, zht_s_ini, zsm_i_ini, ztm_i_ini !data from namelist or nc file
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zh_i_ini, za_i_ini                         !data by cattegories to fill
-      INTEGER , POINTER, DIMENSION(:)     :: itest
-      !--------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, jpl, zh_i_ini,  za_i_ini )
-      CALL wrk_alloc( jpi, jpj,      zht_i_ini, zat_i_ini, zvt_i_ini, zts_u_ini, zht_s_ini, zsm_i_ini, ztm_i_ini )
-      CALL wrk_alloc( jpi, jpj,      zswitch )
-      Call wrk_alloc( 4,             itest )
-
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'lim_istate : sea-ice initialization '
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~ '
-
-      !--------------------------------------------------------------------
-      ! 1) Read namelist
-      !--------------------------------------------------------------------
-      !
-      CALL lim_istate_init
-
-      ! init surface temperature
-      DO jl = 1, jpl
-         t_su  (:,:,jl) = rt0 * tmask(:,:,1)
-         tn_ice(:,:,jl) = rt0 * tmask(:,:,1)
-      END DO
-
-      ! init basal temperature (considered at freezing point)
-      CALL eos_fzp( sss_m(:,:), t_bo(:,:) )
-      t_bo(:,:) = ( t_bo(:,:) + rt0 ) * tmask(:,:,1) 
-
-
-      !--------------------------------------------------------------------
-      ! 2) Initialization of sea ice state variables
-      !--------------------------------------------------------------------
-      IF( ln_limini ) THEN
-         !
-         IF( ln_limini_file )THEN
-         !
-            zht_i_ini(:,:)  = si(jp_hti)%fnow(:,:,1)
-            zht_s_ini(:,:)  = si(jp_hts)%fnow(:,:,1)
-            zat_i_ini(:,:)  = si(jp_ati)%fnow(:,:,1)
-            zts_u_ini(:,:)  = si(jp_tsu)%fnow(:,:,1)
-            ztm_i_ini(:,:)  = si(jp_tmi)%fnow(:,:,1)
-            zsm_i_ini(:,:)  = si(jp_smi)%fnow(:,:,1)
-            !
-            WHERE( zat_i_ini(:,:) > 0._wp ) ; zswitch(:,:) = tmask(:,:,1) 
-            ELSEWHERE                       ; zswitch(:,:) = 0._wp
-            END WHERE
-            !
-         ELSE ! ln_limini_file = F
-
-            !--------------------------------------------------------------------
-            ! 3) Basal temperature, ice mask
-            !--------------------------------------------------------------------
-            ! no ice if sst <= t-freez + ttest
-            WHERE( ( sst_m(:,:) - (t_bo(:,:) - rt0) ) * tmask(:,:,1) >= rn_thres_sst ) ; zswitch(:,:) = 0._wp 
-            ELSEWHERE                                                                  ; zswitch(:,:) = tmask(:,:,1)
-            END WHERE
-
-            !-----------------------------
-            ! 3.1) Hemisphere-dependent arrays
-            !-----------------------------
-            ! assign initial thickness, concentration, snow depth and salinity to an hemisphere-dependent array
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  IF( ff_t(ji,jj) >= 0._wp ) THEN
-                     zht_i_ini(ji,jj) = rn_hti_ini_n * zswitch(ji,jj)
-                     zht_s_ini(ji,jj) = rn_hts_ini_n * zswitch(ji,jj)
-                     zat_i_ini(ji,jj) = rn_ati_ini_n * zswitch(ji,jj)
-                     zts_u_ini(ji,jj) = rn_tmi_ini_n * zswitch(ji,jj)
-                     zsm_i_ini(ji,jj) = rn_smi_ini_n * zswitch(ji,jj)
-                     ztm_i_ini(ji,jj) = rn_tmi_ini_n * zswitch(ji,jj)
-                  ELSE
-                     zht_i_ini(ji,jj) = rn_hti_ini_s * zswitch(ji,jj)
-                     zht_s_ini(ji,jj) = rn_hts_ini_s * zswitch(ji,jj)
-                     zat_i_ini(ji,jj) = rn_ati_ini_s * zswitch(ji,jj)
-                     zts_u_ini(ji,jj) = rn_tmi_ini_s * zswitch(ji,jj)
-                     zsm_i_ini(ji,jj) = rn_smi_ini_s * zswitch(ji,jj)
-                     ztm_i_ini(ji,jj) = rn_tmi_ini_s * zswitch(ji,jj)
-                  ENDIF
-               END DO
-            END DO
-            !
-         ENDIF ! ln_limini_file
-         
-         zvt_i_ini(:,:) = zht_i_ini(:,:) * zat_i_ini(:,:)   ! ice volume
-         !---------------------------------------------------------------------
-         ! 3.2) Distribute ice concentration and thickness into the categories
-         !---------------------------------------------------------------------
-         ! a gaussian distribution for ice concentration is used
-         ! then we check whether the distribution fullfills
-         ! volume and area conservation, positivity and ice categories bounds
-         zh_i_ini(:,:,:) = 0._wp 
-         za_i_ini(:,:,:) = 0._wp
-         !
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               !
-               IF( zat_i_ini(ji,jj) > 0._wp .AND. zht_i_ini(ji,jj) > 0._wp )THEN
-
-                  !--- jl0: most likely index where cc will be maximum
-                  jl0 = jpl
-                  DO jl = 1, jpl
-                     IF ( ( zht_i_ini(ji,jj) >  hi_max(jl-1) ) .AND. ( zht_i_ini(ji,jj) <= hi_max(jl) ) ) THEN
-                        jl0 = jl
-                        CYCLE
-                     ENDIF
-                  END DO
-                  !
-                  ! initialisation of tests
-                  itest(:)  = 0
-                  
-                  i_fill = jpl + 1                                             !====================================
-                  DO WHILE ( ( SUM( itest(:) ) /= 4 ) .AND. ( i_fill >= 2 ) )  ! iterative loop on i_fill categories
-                     ! iteration                                               !====================================
-                     i_fill = i_fill - 1
-
-                     ! initialisation of ice variables for each try
-                     zh_i_ini(ji,jj,:) = 0._wp 
-                     za_i_ini(ji,jj,:) = 0._wp
-                     itest(:) = 0
-                     !
-                     ! *** case very thin ice: fill only category 1
-                     IF ( i_fill == 1 ) THEN
-                        zh_i_ini(ji,jj,1) = zht_i_ini(ji,jj)
-                        za_i_ini(ji,jj,1) = zat_i_ini(ji,jj)
-
-                     ! *** case ice is thicker: fill categories >1
-                     ELSE
-
-                        ! Fill ice thicknesses in the (i_fill-1) cat by hmean 
-                        DO jl = 1, i_fill-1
-                           zh_i_ini(ji,jj,jl) = hi_mean(jl)
-                        END DO
-                        !
-                        !--- Concentrations
-                        za_i_ini(ji,jj,jl0) = zat_i_ini(ji,jj) / SQRT(REAL(jpl))
-                        DO jl = 1, i_fill - 1
-                           IF( jl /= jl0 )THEN
-                              zarg               = ( zh_i_ini(ji,jj,jl) - zht_i_ini(ji,jj) ) / ( 0.5_wp * zht_i_ini(ji,jj) )
-                              za_i_ini(ji,jj,jl) = za_i_ini(ji,jj,jl0) * EXP(-zarg**2)
-                           ENDIF
-                        END DO
-                        !
-                        ! Concentration in the last (i_fill) category
-                        za_i_ini(ji,jj,i_fill) = zat_i_ini(ji,jj) - SUM( za_i_ini(ji,jj,1:i_fill-1) )
-
-                        ! Ice thickness in the last (i_fill) category
-                        zV = SUM( za_i_ini(ji,jj,1:i_fill-1) * zh_i_ini(ji,jj,1:i_fill-1) )
-                        zh_i_ini(ji,jj,i_fill) = ( zvt_i_ini(ji,jj) - zV ) / MAX( za_i_ini(ji,jj,i_fill), epsi10 ) 
-
-                        ! clem: correction if concentration of upper cat is greater than lower cat
-                        !       (it should be a gaussian around jl0 but sometimes it is not)
-                        IF ( jl0 /= jpl ) THEN
-                           DO jl = jpl, jl0+1, -1
-                              IF ( za_i_ini(ji,jj,jl) > za_i_ini(ji,jj,jl-1) ) THEN
-                                 zdv = zh_i_ini(ji,jj,jl) * za_i_ini(ji,jj,jl)
-                                 zh_i_ini(ji,jj,jl    ) = 0._wp
-                                 za_i_ini(ji,jj,jl    ) = 0._wp
-                                 za_i_ini(ji,jj,1:jl-1) = za_i_ini(ji,jj,1:jl-1)  &
-                                    &                     + zdv / MAX( REAL(jl-1) * zht_i_ini(ji,jj), epsi10 )
-                              END IF
-                           ENDDO
-                        ENDIF
-                        !
-                     ENDIF ! case ice is thick or thin
-
-                     !---------------------
-                     ! Compatibility tests
-                     !---------------------
-                     ! Test 1: area conservation
-                     zconv = ABS( zat_i_ini(ji,jj) - SUM( za_i_ini(ji,jj,1:jpl) ) )
-                     IF ( zconv < epsi06 ) itest(1) = 1
-                     
-                     ! Test 2: volume conservation
-                     zconv = ABS(       zat_i_ini(ji,jj)       * zht_i_ini(ji,jj)   &
-                        &        - SUM( za_i_ini (ji,jj,1:jpl) * zh_i_ini (ji,jj,1:jpl) ) )
-                     IF ( zconv < epsi06 ) itest(2) = 1
-                     
-                     ! Test 3: thickness of the last category is in-bounds ?
-                     IF ( zh_i_ini(ji,jj,i_fill) >= hi_max(i_fill-1) ) itest(3) = 1
-                     
-                     ! Test 4: positivity of ice concentrations
-                     itest(4) = 1
-                     DO jl = 1, i_fill
-                        IF ( za_i_ini(ji,jj,jl) < 0._wp ) itest(4) = 0
-                     END DO
-                     !                                      !============================
-                  END DO                                    ! end iteration on categories
-                  !                                         !============================
-                  !
-                  IF( lwp .AND. SUM(itest) /= 4 ) THEN 
-                     WRITE(numout,*)
-                     WRITE(numout,*) ' !!!! ALERT itest is not equal to 4      !!! '
-                     WRITE(numout,*) ' !!!! Something is wrong in the LIM3 initialization procedure '
-                     WRITE(numout,*)
-                     WRITE(numout,*) ' *** itest_i (i=1,4) = ', itest(:)
-                     WRITE(numout,*) ' zat_i_ini : ', zat_i_ini(ji,jj)
-                     WRITE(numout,*) ' zht_i_ini : ', zht_i_ini(ji,jj)
-                  ENDIF
-               
-               ENDIF !  zat_i_ini(ji,jj) > 0._wp .AND. zht_i_ini(ji,jj) > 0._wp
-               !
-            END DO   
-         END DO   
-
-         !---------------------------------------------------------------------
-         ! 3.3) Space-dependent arrays for ice state variables
-         !---------------------------------------------------------------------
-
-         ! Ice concentration, thickness and volume, ice salinity, ice age, surface temperature
-         DO jl = 1, jpl ! loop over categories
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  a_i(ji,jj,jl)   = zswitch(ji,jj) * za_i_ini(ji,jj,jl)                       ! concentration
-                  ht_i(ji,jj,jl)  = zswitch(ji,jj) * zh_i_ini(ji,jj,jl)                       ! ice thickness
-                  sm_i(ji,jj,jl)  = zswitch(ji,jj) * zsm_i_ini(ji,jj)                         ! salinity
-                  o_i(ji,jj,jl)   = zswitch(ji,jj) * 1._wp                                    ! age (1 day)
-                  t_su(ji,jj,jl)  = zswitch(ji,jj) * zts_u_ini(ji,jj) + ( 1._wp - zswitch(ji,jj) ) * rt0 ! surf temp
-
-                  IF( zht_i_ini(ji,jj) > 0._wp )THEN
-                    ht_s(ji,jj,jl)= ht_i(ji,jj,jl) * ( zht_s_ini(ji,jj) / zht_i_ini(ji,jj) )  ! snow depth
-                  ELSE
-                    ht_s(ji,jj,jl)= 0._wp
-                  ENDIF
-
-                  ! This case below should not be used if (ht_s/ht_i) is ok in namelist
-                  ! In case snow load is in excess that would lead to transformation from snow to ice
-                  ! Then, transfer the snow excess into the ice (different from limthd_dh)
-                  zdh = MAX( 0._wp, ( rhosn * ht_s(ji,jj,jl) + ( rhoic - rau0 ) * ht_i(ji,jj,jl) ) * r1_rau0 ) 
-                  ! recompute ht_i, ht_s avoiding out of bounds values
-                  ht_i(ji,jj,jl) = MIN( hi_max(jl), ht_i(ji,jj,jl) + zdh )
-                  ht_s(ji,jj,jl) = MAX( 0._wp, ht_s(ji,jj,jl) - zdh * rhoic * r1_rhosn )
-
-                  ! ice volume, salt content, age content
-                  v_i(ji,jj,jl)   = ht_i(ji,jj,jl) * a_i(ji,jj,jl)              ! ice volume
-                  v_s(ji,jj,jl)   = ht_s(ji,jj,jl) * a_i(ji,jj,jl)              ! snow volume
-                  smv_i(ji,jj,jl) = MIN( sm_i(ji,jj,jl) , sss_m(ji,jj) ) * v_i(ji,jj,jl) ! salt content
-                  oa_i(ji,jj,jl)  = o_i(ji,jj,jl) * a_i(ji,jj,jl)               ! age content
-               END DO
-            END DO
-         END DO
-
-         ! for constant salinity in time
-         IF( nn_icesal == 1 .OR. nn_icesal == 3 )  THEN
-            CALL lim_var_salprof
-            smv_i = sm_i * v_i
-         ENDIF
-            
-         ! Snow temperature and heat content
-         DO jk = 1, nlay_s
-            DO jl = 1, jpl ! loop over categories
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     t_s(ji,jj,jk,jl) = zswitch(ji,jj) * ztm_i_ini(ji,jj) + ( 1._wp - zswitch(ji,jj) ) * rt0
-                     ! Snow energy of melting
-                     e_s(ji,jj,jk,jl) = zswitch(ji,jj) * rhosn * ( cpic * ( rt0 - t_s(ji,jj,jk,jl) ) + lfus )
-
-                     ! Mutliply by volume, and divide by number of layers to get heat content in J/m2
-                     e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) * v_s(ji,jj,jl) * r1_nlay_s
-                  END DO
-               END DO
-            END DO
-         END DO
-
-         ! Ice salinity, temperature and heat content
-         DO jk = 1, nlay_i
-            DO jl = 1, jpl ! loop over categories
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     t_i(ji,jj,jk,jl) = zswitch(ji,jj) * ztm_i_ini(ji,jj) + ( 1._wp - zswitch(ji,jj) ) * rt0 
-                     s_i(ji,jj,jk,jl) = zswitch(ji,jj) * zsm_i_ini(ji,jj) + ( 1._wp - zswitch(ji,jj) ) * rn_simin
-                     ztmelts          = - tmut * s_i(ji,jj,jk,jl) + rt0 !Melting temperature in K
-
-                     ! heat content per unit volume
-                     e_i(ji,jj,jk,jl) = zswitch(ji,jj) * rhoic * (   cpic    * ( ztmelts - t_i(ji,jj,jk,jl) ) &
-                        +   lfus    * ( 1._wp - (ztmelts-rt0) / MIN((t_i(ji,jj,jk,jl)-rt0),-epsi20) ) &
-                        -   rcp     * ( ztmelts - rt0 ) )
-
-                     ! Mutliply by ice volume, and divide by number of layers to get heat content in J/m2
-                     e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * v_i(ji,jj,jl) * r1_nlay_i
-                  END DO
-               END DO
-            END DO
-         END DO
-
-         tn_ice (:,:,:) = t_su (:,:,:)
-
-      ELSE ! if ln_limini=false
-         a_i  (:,:,:) = 0._wp
-         v_i  (:,:,:) = 0._wp
-         v_s  (:,:,:) = 0._wp
-         smv_i(:,:,:) = 0._wp
-         oa_i (:,:,:) = 0._wp
-         ht_i (:,:,:) = 0._wp
-         ht_s (:,:,:) = 0._wp
-         sm_i (:,:,:) = 0._wp
-         o_i  (:,:,:) = 0._wp
-
-         e_i(:,:,:,:) = 0._wp
-         e_s(:,:,:,:) = 0._wp
-
-         DO jl = 1, jpl
-            DO jk = 1, nlay_i
-               t_i(:,:,jk,jl) = rt0 * tmask(:,:,1)
-            END DO
-            DO jk = 1, nlay_s
-               t_s(:,:,jk,jl) = rt0 * tmask(:,:,1)
-            END DO
-         END DO
-
-      ENDIF ! ln_limini
-      
-      at_i (:,:) = 0.0_wp
-      DO jl = 1, jpl
-         at_i (:,:) = at_i (:,:) + a_i (:,:,jl)
-      END DO
-      !
-      !--------------------------------------------------------------------
-      ! 4) Global ice variables for output diagnostics                    | 
-      !--------------------------------------------------------------------
-      u_ice (:,:)     = 0._wp
-      v_ice (:,:)     = 0._wp
-      stress1_i(:,:)  = 0._wp
-      stress2_i(:,:)  = 0._wp
-      stress12_i(:,:) = 0._wp
-
-      !--------------------------------------------------------------------
-      ! 5) Moments for advection
-      !--------------------------------------------------------------------
-
-      sxopw (:,:) = 0._wp 
-      syopw (:,:) = 0._wp 
-      sxxopw(:,:) = 0._wp 
-      syyopw(:,:) = 0._wp 
-      sxyopw(:,:) = 0._wp
-
-      sxice (:,:,:)  = 0._wp   ;   sxsn (:,:,:)  = 0._wp   ;   sxa  (:,:,:)  = 0._wp
-      syice (:,:,:)  = 0._wp   ;   sysn (:,:,:)  = 0._wp   ;   sya  (:,:,:)  = 0._wp
-      sxxice(:,:,:)  = 0._wp   ;   sxxsn(:,:,:)  = 0._wp   ;   sxxa (:,:,:)  = 0._wp
-      syyice(:,:,:)  = 0._wp   ;   syysn(:,:,:)  = 0._wp   ;   syya (:,:,:)  = 0._wp
-      sxyice(:,:,:)  = 0._wp   ;   sxysn(:,:,:)  = 0._wp   ;   sxya (:,:,:)  = 0._wp
-
-      sxc0  (:,:,:)  = 0._wp   ;   sxe  (:,:,:,:)= 0._wp   
-      syc0  (:,:,:)  = 0._wp   ;   sye  (:,:,:,:)= 0._wp   
-      sxxc0 (:,:,:)  = 0._wp   ;   sxxe (:,:,:,:)= 0._wp   
-      syyc0 (:,:,:)  = 0._wp   ;   syye (:,:,:,:)= 0._wp   
-      sxyc0 (:,:,:)  = 0._wp   ;   sxye (:,:,:,:)= 0._wp   
-
-      sxsal  (:,:,:)  = 0._wp
-      sysal  (:,:,:)  = 0._wp
-      sxxsal (:,:,:)  = 0._wp
-      syysal (:,:,:)  = 0._wp
-      sxysal (:,:,:)  = 0._wp
-
-      sxage  (:,:,:)  = 0._wp
-      syage  (:,:,:)  = 0._wp
-      sxxage (:,:,:)  = 0._wp
-      syyage (:,:,:)  = 0._wp
-      sxyage (:,:,:)  = 0._wp
-
-      !------------------------------------
-      ! 6) store fields at before time-step
-      !------------------------------------
-      ! it is only necessary for the 1st interpolation by Agrif
-      a_i_b  (:,:,:)   = a_i  (:,:,:)
-      e_i_b  (:,:,:,:) = e_i  (:,:,:,:)
-      v_i_b  (:,:,:)   = v_i  (:,:,:)
-      v_s_b  (:,:,:)   = v_s  (:,:,:)
-      e_s_b  (:,:,:,:) = e_s  (:,:,:,:)
-      smv_i_b(:,:,:)   = smv_i(:,:,:)
-      oa_i_b (:,:,:)   = oa_i (:,:,:)
-      u_ice_b(:,:)     = u_ice(:,:)
-      v_ice_b(:,:)     = v_ice(:,:)
-
-!!!clem
-!!      ! Output the initial state and forcings
-!!      CALL dia_wri_state( 'output.init', nit000 )
-!!!      
-
-      CALL wrk_dealloc( jpi, jpj, jpl, zh_i_ini,  za_i_ini )
-      CALL wrk_dealloc( jpi, jpj,      zht_i_ini, zat_i_ini, zvt_i_ini, zts_u_ini, zht_s_ini, zsm_i_ini, ztm_i_ini )
-      CALL wrk_dealloc( jpi, jpj,      zswitch )
-      Call wrk_dealloc( 4,             itest )
-
-   END SUBROUTINE lim_istate
-
-   SUBROUTINE lim_istate_init
-      !!-------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_istate_init  ***
-      !!        
-      !! ** Purpose : Definition of initial state of the ice 
-      !!
-      !! ** Method : Read the namiceini namelist and check the parameter 
-      !!       values called at the first timestep (nit000)
-      !!
-      !! ** input : 
-      !!        Namelist namiceini
-      !!
-      !! history :
-      !!  8.5  ! 03-08 (C. Ethe) original code 
-      !!  8.5  ! 07-11 (M. Vancoppenolle) rewritten initialization
-      !!-----------------------------------------------------------------------------
-      !
-      INTEGER :: ios,ierr,inum_ice                 ! Local integer output status for namelist read
-      INTEGER :: ji,jj
-      INTEGER :: ifpr, ierror
-      !
-      CHARACTER(len=100) ::  cn_dir          ! Root directory for location of ice files
-      TYPE(FLD_N)                    ::   sn_hti, sn_hts, sn_ati, sn_tsu, sn_tmi, sn_smi
-      TYPE(FLD_N), DIMENSION(jpfldi) ::   slf_i                 ! array of namelist informations on the fields to read
-      !
-      NAMELIST/namiceini/ ln_limini, ln_limini_file, rn_thres_sst, rn_hts_ini_n, rn_hts_ini_s,  &
-         &                rn_hti_ini_n, rn_hti_ini_s, rn_ati_ini_n, rn_ati_ini_s, rn_smi_ini_n, &
-         &                rn_smi_ini_s, rn_tmi_ini_n, rn_tmi_ini_s,                             &
-         &                sn_hti, sn_hts, sn_ati, sn_tsu, sn_tmi, sn_smi, cn_dir
-      !!-----------------------------------------------------------------------------
-      !
-      REWIND( numnam_ice_ref )              ! Namelist namiceini in reference namelist : Ice initial state
-      READ  ( numnam_ice_ref, namiceini, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namiceini in reference namelist', lwp )
-
-      REWIND( numnam_ice_cfg )              ! Namelist namiceini in configuration namelist : Ice initial state
-      READ  ( numnam_ice_cfg, namiceini, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namiceini in configuration namelist', lwp )
-      IF(lwm) WRITE ( numoni, namiceini )
-
-      slf_i(jp_hti) = sn_hti  ;  slf_i(jp_hts) = sn_hts
-      slf_i(jp_ati) = sn_ati  ;  slf_i(jp_tsu) = sn_tsu
-      slf_i(jp_tmi) = sn_tmi  ;  slf_i(jp_smi) = sn_smi
-
-      ! Define the initial parameters
-      ! -------------------------
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_istate_init : ice parameters inititialisation '
-         WRITE(numout,*) '~~~~~~~~~~~~~~~'
-         WRITE(numout,*) '   initialization with ice (T) or not (F)       ln_limini     = ', ln_limini
-         WRITE(numout,*) '   ice initialization from a netcdf file      ln_limini_file  = ', ln_limini_file
-         WRITE(numout,*) '   threshold water temp. for initial sea-ice    rn_thres_sst  = ', rn_thres_sst
-         WRITE(numout,*) '   initial snow thickness in the north          rn_hts_ini_n  = ', rn_hts_ini_n
-         WRITE(numout,*) '   initial snow thickness in the south          rn_hts_ini_s  = ', rn_hts_ini_s 
-         WRITE(numout,*) '   initial ice thickness  in the north          rn_hti_ini_n  = ', rn_hti_ini_n
-         WRITE(numout,*) '   initial ice thickness  in the south          rn_hti_ini_s  = ', rn_hti_ini_s
-         WRITE(numout,*) '   initial ice concentr.  in the north          rn_ati_ini_n  = ', rn_ati_ini_n
-         WRITE(numout,*) '   initial ice concentr.  in the north          rn_ati_ini_s  = ', rn_ati_ini_s
-         WRITE(numout,*) '   initial  ice salinity  in the north          rn_smi_ini_n  = ', rn_smi_ini_n
-         WRITE(numout,*) '   initial  ice salinity  in the south          rn_smi_ini_s  = ', rn_smi_ini_s
-         WRITE(numout,*) '   initial  ice/snw temp  in the north          rn_tmi_ini_n  = ', rn_tmi_ini_n
-         WRITE(numout,*) '   initial  ice/snw temp  in the south          rn_tmi_ini_s  = ', rn_tmi_ini_s
-      ENDIF
-
-      IF( ln_limini_file ) THEN                      ! Ice initialization using input file
-         !
-         ! set si structure
-         ALLOCATE( si(jpfldi), STAT=ierror )
-         IF( ierror > 0 ) THEN
-            CALL ctl_stop( 'Ice_ini in limistate: unable to allocate si structure' )   ;   RETURN
-         ENDIF
-
-         DO ifpr = 1, jpfldi
-            ALLOCATE( si(ifpr)%fnow(jpi,jpj,1) )
-            ALLOCATE( si(ifpr)%fdta(jpi,jpj,1,2) )
-         END DO
-
-         ! fill si with slf_i and control print
-         CALL fld_fill( si, slf_i, cn_dir, 'lim_istate', 'lim istate ini', 'numnam_ice' )
-
-         CALL fld_read( nit000, 1, si )                ! input fields provided at the current time-step
-
-      ENDIF
-
-   END SUBROUTINE lim_istate_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :         Empty module          NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_istate          ! Empty routine
-   END SUBROUTINE lim_istate
-#endif
-
-   !!======================================================================
-END MODULE limistate
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limitd_me.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limitd_me.F90	(revision 9018)
+++ 	(revision )
@@ -1,962 +1,0 @@
-MODULE limitd_me
-   !!======================================================================
-   !!                       ***  MODULE limitd_me ***
-   !! LIM-3 : Mechanical impact on ice thickness distribution      
-   !!======================================================================
-   !! History :  LIM  ! 2006-02  (M. Vancoppenolle) Original code 
-   !!            3.2  ! 2009-07  (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in smsw & sfx_dyn
-   !!            4.0  ! 2011-02  (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-   USE par_oce          ! ocean parameters
-   USE dom_oce          ! ocean domain
-   USE phycst           ! physical constants (ocean directory) 
-   USE sbc_oce          ! surface boundary condition: ocean fields
-   USE thd_ice          ! LIM thermodynamics
-   USE ice              ! LIM variables
-   USE limvar           ! LIM
-   USE lbclnk           ! lateral boundary condition - MPP exchanges
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-
-   USE in_out_manager   ! I/O manager
-   USE iom              ! I/O manager
-   USE lib_fortran      ! glob_sum
-   USE timing           ! Timing
-   USE limcons          ! conservation tests
-   USE limctl           ! control prints
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_itd_me               ! called by ice_stp
-   PUBLIC   lim_itd_me_icestrength
-   PUBLIC   lim_itd_me_init
-   PUBLIC   lim_itd_me_alloc        ! called by sbc_lim_init 
-
-   !-----------------------------------------------------------------------
-   ! Variables shared among ridging subroutines
-   !-----------------------------------------------------------------------
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:)   ::   asum     ! sum of total ice and open water area
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:)   ::   aksum    ! ratio of area removed to area ridged
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   athorn   ! participation function; fraction of ridging/closing associated w/ category n
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   hrmin    ! minimum ridge thickness
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   hrmax    ! maximum ridge thickness
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   hraft    ! thickness of rafted ice
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   krdg     ! thickness of ridging ice / mean ridge thickness
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   aridge   ! participating ice ridging
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   araft    ! participating ice rafting
-
-   REAL(wp), PARAMETER ::   krdgmin = 1.1_wp    ! min ridge thickness multiplier
-   REAL(wp), PARAMETER ::   kraft   = 0.5_wp    ! rafting multipliyer
-
-   REAL(wp) ::   Cp                             ! 
-   !
-   !
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 3.3 , UCL - NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION lim_itd_me_alloc()
-      !!---------------------------------------------------------------------!
-      !!                ***  ROUTINE lim_itd_me_alloc ***
-      !!---------------------------------------------------------------------!
-      ALLOCATE(                                                                      &
-         !* Variables shared among ridging subroutines
-         &      asum (jpi,jpj)     , athorn(jpi,jpj,0:jpl) , aksum (jpi,jpj)     ,   &
-         &      hrmin(jpi,jpj,jpl) , hraft(jpi,jpj,jpl)    , aridge(jpi,jpj,jpl) ,   &
-         &      hrmax(jpi,jpj,jpl) , krdg (jpi,jpj,jpl)    , araft (jpi,jpj,jpl) , STAT=lim_itd_me_alloc )
-         !
-      IF( lim_itd_me_alloc /= 0 )   CALL ctl_warn( 'lim_itd_me_alloc: failed to allocate arrays' )
-      !
-   END FUNCTION lim_itd_me_alloc
-
-
-   SUBROUTINE lim_itd_me
-      !!---------------------------------------------------------------------!
-      !!                ***  ROUTINE lim_itd_me ***
-      !!
-      !! ** Purpose :   computes the mechanical redistribution of ice thickness
-      !!
-      !! ** Method  :   Steps :
-      !!       1) Thickness categories boundaries, ice / o.w. concentrations
-      !!          Ridge preparation
-      !!       2) Dynamical inputs (closing rate, divu_adv, opning)
-      !!       3) Ridging iteration
-      !!       4) Ridging diagnostics
-      !!       5) Heat, salt and freshwater fluxes
-      !!       6) Compute increments of tate variables and come back to old values
-      !!
-      !! References :   Flato, G. M., and W. D. Hibler III, 1995, JGR, 100, 18,611-18,626.
-      !!                Hibler, W. D. III, 1980, MWR, 108, 1943-1973, 1980.
-      !!                Rothrock, D. A., 1975: JGR, 80, 4514-4519.
-      !!                Thorndike et al., 1975, JGR, 80, 4501-4513. 
-      !!                Bitz et al., JGR, 2001
-      !!                Amundrud and Melling, JGR 2005
-      !!                Babko et al., JGR 2002 
-      !!
-      !!     This routine is based on CICE code and authors William H. Lipscomb,
-      !!  and Elizabeth C. Hunke, LANL are gratefully acknowledged
-      !!--------------------------------------------------------------------!
-      INTEGER  ::   ji, jj, jk, jl        ! dummy loop index
-      INTEGER  ::   niter                 ! local integer 
-      INTEGER  ::   iterate_ridging       ! if true, repeat the ridging
-      REAL(wp) ::   za, zfac              ! local scalar
-      CHARACTER (len = 15) ::   fieldid
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   closing_net     ! net rate at which area is removed    (1/s)
-                                                               ! (ridging ice area - area of new ridges) / dt
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   divu_adv        ! divu as implied by transport scheme  (1/s)
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   opning          ! rate of opening due to divergence/shear
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   closing_gross   ! rate at which area removed, not counting area of new ridges
-      !
-      INTEGER, PARAMETER ::   nitermax = 20    
-      !
-      REAL(wp) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
-      !!-----------------------------------------------------------------------------
-      IF( nn_timing == 1 )  CALL timing_start('limitd_me')
-
-      CALL wrk_alloc( jpi,jpj, closing_net, divu_adv, opning, closing_gross )
-
-      ! conservation test
-      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'limitd_me', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      !-----------------------------------------------------------------------------!
-      ! 1) Thickness categories boundaries, ice / o.w. concentrations, init_ons
-      !-----------------------------------------------------------------------------!
-      Cp = 0.5 * grav * (rau0-rhoic) * rhoic * r1_rau0             ! proport const for PE
-      !
-      CALL lim_itd_me_ridgeprep                                    ! prepare ridging
-      !
-
-      DO jj = 1, jpj                                     ! Initialize arrays.
-         DO ji = 1, jpi
-
-            !-----------------------------------------------------------------------------!
-            ! 2) Dynamical inputs (closing rate, divu_adv, opning)
-            !-----------------------------------------------------------------------------!
-            !
-            ! 2.1 closing_net
-            !-----------------
-            ! Compute the net rate of closing due to convergence 
-            ! and shear, based on Flato and Hibler (1995).
-            ! 
-            ! The energy dissipation rate is equal to the net closing rate
-            ! times the ice strength.
-            !
-            ! NOTE: The NET closing rate is equal to the rate that open water 
-            !  area is removed, plus the rate at which ice area is removed by 
-            !  ridging, minus the rate at which area is added in new ridges.
-            !  The GROSS closing rate is equal to the first two terms (open
-            !  water closing and thin ice ridging) without the third term
-            !  (thick, newly ridged ice).
-
-            closing_net(ji,jj) = rn_cs * 0.5 * ( delta_i(ji,jj) - ABS( divu_i(ji,jj) ) ) - MIN( divu_i(ji,jj), 0._wp )
-
-            ! 2.2 divu_adv
-            !--------------
-            ! Compute divu_adv, the divergence rate given by the transport/
-            ! advection scheme, which may not be equal to divu as computed 
-            ! from the velocity field.
-            !
-            ! If divu_adv < 0, make sure the closing rate is large enough
-            ! to give asum = 1.0 after ridging.
-            
-            divu_adv(ji,jj) = ( 1._wp - asum(ji,jj) ) * r1_rdtice  ! asum found in ridgeprep
-
-            IF( divu_adv(ji,jj) < 0._wp )   closing_net(ji,jj) = MAX( closing_net(ji,jj), -divu_adv(ji,jj) )
-
-            ! 2.3 opning
-            !------------
-            ! Compute the (non-negative) opening rate that will give asum = 1.0 after ridging.
-            opning(ji,jj) = closing_net(ji,jj) + divu_adv(ji,jj)
-         END DO
-      END DO
-
-      !-----------------------------------------------------------------------------!
-      ! 3) Ridging iteration
-      !-----------------------------------------------------------------------------!
-      niter           = 1                 ! iteration counter
-      iterate_ridging = 1
-
-      DO WHILE ( iterate_ridging > 0 .AND. niter < nitermax )
-
-         ! 3.2 closing_gross
-         !-----------------------------------------------------------------------------!
-         ! Based on the ITD of ridging and ridged ice, convert the net
-         !  closing rate to a gross closing rate.  
-         ! NOTE: 0 < aksum <= 1
-         closing_gross(:,:) = closing_net(:,:) / aksum(:,:)
-
-         ! correction to closing rate and opening if closing rate is excessive
-         !---------------------------------------------------------------------
-         ! Reduce the closing rate if more than 100% of the open water 
-         ! would be removed.  Reduce the opening rate proportionately.
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               za   = ( opning(ji,jj) - athorn(ji,jj,0) * closing_gross(ji,jj) ) * rdt_ice
-               IF    ( za < 0._wp .AND. za > - ato_i(ji,jj) ) THEN                  ! would lead to negative ato_i
-                  zfac          = - ato_i(ji,jj) / za
-                  opning(ji,jj) = athorn(ji,jj,0) * closing_gross(ji,jj) - ato_i(ji,jj) * r1_rdtice 
-               ELSEIF( za > 0._wp .AND. za > ( asum(ji,jj) - ato_i(ji,jj) ) ) THEN  ! would lead to ato_i > asum
-                  zfac          = ( asum(ji,jj) - ato_i(ji,jj) ) / za
-                  opning(ji,jj) = athorn(ji,jj,0) * closing_gross(ji,jj) + ( asum(ji,jj) - ato_i(ji,jj) ) * r1_rdtice 
-               ENDIF
-            END DO
-         END DO
-
-         ! correction to closing rate / opening if excessive ice removal
-         !---------------------------------------------------------------
-         ! Reduce the closing rate if more than 100% of any ice category 
-         ! would be removed.  Reduce the opening rate proportionately.
-         DO jl = 1, jpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  za = athorn(ji,jj,jl) * closing_gross(ji,jj) * rdt_ice
-                  IF( za  >  a_i(ji,jj,jl) ) THEN
-                     zfac = a_i(ji,jj,jl) / za
-                     closing_gross(ji,jj) = closing_gross(ji,jj) * zfac
-                  ENDIF
-               END DO
-            END DO
-         END DO
-
-         ! 3.3 Redistribute area, volume, and energy.
-         !-----------------------------------------------------------------------------!
-
-         CALL lim_itd_me_ridgeshift( opning, closing_gross )
-
-         
-         ! 3.4 Compute total area of ice plus open water after ridging.
-         !-----------------------------------------------------------------------------!
-         ! This is in general not equal to one because of divergence during transport
-         asum(:,:) = ato_i(:,:) + SUM( a_i, dim=3 )
-
-         ! 3.5 Do we keep on iterating ???
-         !-----------------------------------------------------------------------------!
-         ! Check whether asum = 1.  If not (because the closing and opening
-         ! rates were reduced above), ridge again with new rates.
-
-         iterate_ridging = 0
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( ABS( asum(ji,jj) - 1._wp ) < epsi10 ) THEN
-                  closing_net(ji,jj) = 0._wp
-                  opning     (ji,jj) = 0._wp
-                  ato_i      (ji,jj) = MAX( 0._wp, 1._wp - SUM( a_i(ji,jj,:) ) )
-               ELSE
-                  iterate_ridging    = 1
-                  divu_adv   (ji,jj) = ( 1._wp - asum(ji,jj) ) * r1_rdtice
-                  closing_net(ji,jj) = MAX( 0._wp, -divu_adv(ji,jj) )
-                  opning     (ji,jj) = MAX( 0._wp,  divu_adv(ji,jj) )
-               ENDIF
-            END DO
-         END DO
-
-         IF( lk_mpp )   CALL mpp_max( iterate_ridging )
-
-         ! Repeat if necessary.
-         ! NOTE: If strength smoothing is turned on, the ridging must be
-         ! iterated globally because of the boundary update in the 
-         ! smoothing.
-
-         niter = niter + 1
-
-         IF( iterate_ridging == 1 ) THEN
-            CALL lim_itd_me_ridgeprep
-            IF( niter  >  nitermax ) THEN
-               WRITE(numout,*) ' ALERTE : non-converging ridging scheme '
-               WRITE(numout,*) ' niter, iterate_ridging ', niter, iterate_ridging
-            ENDIF
-         ENDIF
-
-      END DO !! on the do while over iter
-
-      CALL lim_var_agg( 1 ) 
-
-      !-----------------------------------------------------------------------------!
-      ! control prints
-      !-----------------------------------------------------------------------------!
-      ! conservation test
-      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'limitd_me', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      ! control prints
-      IF( ln_ctl )       CALL lim_prt3D( 'limitd_me' )
-
-      CALL wrk_dealloc( jpi, jpj, closing_net, divu_adv, opning, closing_gross )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('limitd_me')
-   END SUBROUTINE lim_itd_me
-
-   SUBROUTINE lim_itd_me_ridgeprep
-      !!---------------------------------------------------------------------!
-      !!                ***  ROUTINE lim_itd_me_ridgeprep ***
-      !!
-      !! ** Purpose :   preparation for ridging and strength calculations
-      !!
-      !! ** Method  :   Compute the thickness distribution of the ice and open water 
-      !!              participating in ridging and of the resulting ridges.
-      !!---------------------------------------------------------------------!
-      INTEGER ::   ji,jj, jl    ! dummy loop indices
-      REAL(wp) ::   Gstari, astari, hrmean, zdummy   ! local scalar
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   Gsum      ! Gsum(n) = sum of areas in categories 0 to n
-      !------------------------------------------------------------------------------!
-
-      CALL wrk_alloc( jpi,jpj,jpl+2, Gsum, kkstart = -1 )
-
-      Gstari     = 1.0/rn_gstar    
-      astari     = 1.0/rn_astar    
-      aksum(:,:)    = 0.0
-      athorn(:,:,:) = 0.0
-      aridge(:,:,:) = 0.0
-      araft (:,:,:) = 0.0
-
-      ! Zero out categories with very small areas
-      CALL lim_var_zapsmall
-
-      ! Ice thickness needed for rafting
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               rswitch = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi20 ) )
-               ht_i(ji,jj,jl) = v_i (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-           END DO
-         END DO
-      END DO
-
-      !------------------------------------------------------------------------------!
-      ! 1) Participation function 
-      !------------------------------------------------------------------------------!
-
-      ! Compute total area of ice plus open water.
-      ! This is in general not equal to one because of divergence during transport
-      asum(:,:) = ato_i(:,:) + SUM( a_i, dim=3 )
-
-      ! Compute cumulative thickness distribution function
-      ! Compute the cumulative thickness distribution function Gsum,
-      ! where Gsum(n) is the fractional area in categories 0 to n.
-      ! initial value (in h = 0) equals open water area
-      Gsum(:,:,-1) = 0._wp
-      Gsum(:,:,0 ) = ato_i(:,:)
-      ! for each value of h, you have to add ice concentration then
-      DO jl = 1, jpl
-         Gsum(:,:,jl) = Gsum(:,:,jl-1) + a_i(:,:,jl)
-      END DO
-
-      ! Normalize the cumulative distribution to 1
-      DO jl = 0, jpl
-         Gsum(:,:,jl) = Gsum(:,:,jl) / asum(:,:)
-      END DO
-
-      ! 1.3 Compute participation function a(h) = b(h).g(h) (athorn)
-      !--------------------------------------------------------------------------------------------------
-      ! Compute the participation function athorn; this is analogous to
-      ! a(h) = b(h)g(h) as defined in Thorndike et al. (1975).
-      ! area lost from category n due to ridging/closing
-      ! athorn(n)   = total area lost due to ridging/closing
-      ! assume b(h) = (2/Gstar) * (1 - G(h)/Gstar). 
-      !
-      ! The expressions for athorn are found by integrating b(h)g(h) between
-      ! the category boundaries.
-      ! athorn is always >= 0 and SUM(athorn(0:jpl))=1
-      !-----------------------------------------------------------------
-
-      IF( nn_partfun == 0 ) THEN       !--- Linear formulation (Thorndike et al., 1975)
-         DO jl = 0, jpl    
-            DO jj = 1, jpj 
-               DO ji = 1, jpi
-                  IF    ( Gsum(ji,jj,jl)   < rn_gstar ) THEN
-                     athorn(ji,jj,jl) = Gstari * ( Gsum(ji,jj,jl) - Gsum(ji,jj,jl-1) ) * &
-                        &                        ( 2._wp - ( Gsum(ji,jj,jl-1) + Gsum(ji,jj,jl) ) * Gstari )
-                  ELSEIF( Gsum(ji,jj,jl-1) < rn_gstar ) THEN
-                     athorn(ji,jj,jl) = Gstari * ( rn_gstar       - Gsum(ji,jj,jl-1) ) *  &
-                        &                        ( 2._wp - ( Gsum(ji,jj,jl-1) + rn_gstar       ) * Gstari )
-                  ELSE
-                     athorn(ji,jj,jl) = 0._wp
-                  ENDIF
-               END DO
-            END DO
-         END DO
-
-      ELSE                             !--- Exponential, more stable formulation (Lipscomb et al, 2007)
-         !                        
-         zdummy = 1._wp / ( 1._wp - EXP(-astari) )        ! precompute exponential terms using Gsum as a work array
-         DO jl = -1, jpl
-            Gsum(:,:,jl) = EXP( -Gsum(:,:,jl) * astari ) * zdummy
-         END DO
-         DO jl = 0, jpl
-             athorn(:,:,jl) = Gsum(:,:,jl-1) - Gsum(:,:,jl)
-         END DO
-         !
-      ENDIF
-
-      ! --- Ridging and rafting participation concentrations --- !
-      IF( ln_rafting .AND. ln_ridging ) THEN
-         !
-         DO jl = 1, jpl
-            DO jj = 1, jpj 
-               DO ji = 1, jpi
-                  zdummy           = TANH ( rn_craft * ( ht_i(ji,jj,jl) - rn_hraft ) )
-                  aridge(ji,jj,jl) = ( 1._wp + zdummy ) * 0.5_wp * athorn(ji,jj,jl)
-                  araft (ji,jj,jl) = athorn(ji,jj,jl) - aridge(ji,jj,jl)
-               END DO
-            END DO
-         END DO
-         !
-      ELSEIF( ln_ridging .AND. .NOT. ln_rafting ) THEN
-         !
-         DO jl = 1, jpl
-            aridge(:,:,jl) = athorn(:,:,jl)
-         END DO
-         !
-      ELSEIF( ln_rafting .AND. .NOT. ln_ridging ) THEN
-         !
-         DO jl = 1, jpl
-            araft(:,:,jl) = athorn(:,:,jl)
-         END DO
-         !
-      ENDIF
-
-      !-----------------------------------------------------------------
-      ! 2) Transfer function
-      !-----------------------------------------------------------------
-      ! Compute max and min ridged ice thickness for each ridging category.
-      ! Assume ridged ice is uniformly distributed between hrmin and hrmax.
-      ! 
-      ! This parameterization is a modified version of Hibler (1980).
-      ! The mean ridging thickness, hrmean, is proportional to hi^(0.5)
-      !  and for very thick ridging ice must be >= krdgmin*hi
-      !
-      ! The minimum ridging thickness, hrmin, is equal to 2*hi 
-      !  (i.e., rafting) and for very thick ridging ice is
-      !  constrained by hrmin <= (hrmean + hi)/2.
-      ! 
-      ! The maximum ridging thickness, hrmax, is determined by
-      !  hrmean and hrmin.
-      !
-      ! These modifications have the effect of reducing the ice strength
-      ! (relative to the Hibler formulation) when very thick ice is
-      ! ridging.
-      !
-      ! aksum = net area removed/ total area removed
-      ! where total area removed = area of ice that ridges
-      !         net area removed = total area removed - area of new ridges
-      !-----------------------------------------------------------------
-
-      aksum(:,:) = athorn(:,:,0)
-      ! Transfer function
-      DO jl = 1, jpl !all categories have a specific transfer function
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               
-               IF( athorn(ji,jj,jl) > 0._wp ) THEN
-                  hrmean          = MAX( SQRT( rn_hstar * ht_i(ji,jj,jl) ), ht_i(ji,jj,jl) * krdgmin )
-                  hrmin(ji,jj,jl) = MIN( 2._wp * ht_i(ji,jj,jl), 0.5_wp * ( hrmean + ht_i(ji,jj,jl) ) )
-                  hrmax(ji,jj,jl) = 2._wp * hrmean - hrmin(ji,jj,jl)
-                  hraft(ji,jj,jl) = ht_i(ji,jj,jl) / kraft
-                  krdg(ji,jj,jl)  = ht_i(ji,jj,jl) / MAX( hrmean, epsi20 )
-
-                  ! Normalization factor : aksum, ensures mass conservation
-                  aksum(ji,jj) = aksum(ji,jj) + aridge(ji,jj,jl) * ( 1._wp - krdg(ji,jj,jl) )    &
-                     &                        + araft (ji,jj,jl) * ( 1._wp - kraft          )
-
-               ELSE
-                  hrmin(ji,jj,jl)  = 0._wp 
-                  hrmax(ji,jj,jl)  = 0._wp 
-                  hraft(ji,jj,jl)  = 0._wp 
-                  krdg (ji,jj,jl)  = 1._wp
-               ENDIF
-
-            END DO
-         END DO
-      END DO
-      !
-      CALL wrk_dealloc( jpi,jpj,jpl+2, Gsum, kkstart = -1 )
-      !
-   END SUBROUTINE lim_itd_me_ridgeprep
-
-
-   SUBROUTINE lim_itd_me_ridgeshift( opning, closing_gross )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_me_icestrength ***
-      !!
-      !! ** Purpose :   shift ridging ice among thickness categories of ice thickness
-      !!
-      !! ** Method  :   Remove area, volume, and energy from each ridging category
-      !!              and add to thicker ice categories.
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   opning         ! rate of opening due to divergence/shear
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   closing_gross  ! rate at which area removed, excluding area of new ridges
-      !
-      CHARACTER (len=80) ::   fieldid   ! field identifier
-      !
-      INTEGER ::   ji, jj, jl, jl1, jl2, jk   ! dummy loop indices
-      INTEGER ::   ij                ! horizontal index, combines i and j loops
-      INTEGER ::   icells            ! number of cells with a_i > puny
-      REAL(wp) ::   hL, hR, farea    ! left and right limits of integration
-
-      INTEGER , POINTER, DIMENSION(:) ::   indxi, indxj   ! compressed indices
-      REAL(wp), POINTER, DIMENSION(:) ::   zswitch, fvol   ! new ridge volume going to n2
-
-      REAL(wp), POINTER, DIMENSION(:) ::   afrac            ! fraction of category area ridged 
-      REAL(wp), POINTER, DIMENSION(:) ::   ardg1 , ardg2    ! area of ice ridged & new ridges
-      REAL(wp), POINTER, DIMENSION(:) ::   vsrdg , esrdg    ! snow volume & energy of ridging ice
-      REAL(wp), POINTER, DIMENSION(:) ::   dhr   , dhr2     ! hrmax - hrmin  &  hrmax^2 - hrmin^2
-
-      REAL(wp), POINTER, DIMENSION(:) ::   vrdg1   ! volume of ice ridged
-      REAL(wp), POINTER, DIMENSION(:) ::   vrdg2   ! volume of new ridges
-      REAL(wp), POINTER, DIMENSION(:) ::   vsw     ! volume of seawater trapped into ridges
-      REAL(wp), POINTER, DIMENSION(:) ::   srdg1   ! sal*volume of ice ridged
-      REAL(wp), POINTER, DIMENSION(:) ::   srdg2   ! sal*volume of new ridges
-      REAL(wp), POINTER, DIMENSION(:) ::   smsw    ! sal*volume of water trapped into ridges
-      REAL(wp), POINTER, DIMENSION(:) ::   oirdg1, oirdg2   ! ice age of ice ridged
-
-      REAL(wp), POINTER, DIMENSION(:) ::   afrft            ! fraction of category area rafted
-      REAL(wp), POINTER, DIMENSION(:) ::   arft1 , arft2    ! area of ice rafted and new rafted zone
-      REAL(wp), POINTER, DIMENSION(:) ::   virft , vsrft    ! ice & snow volume of rafting ice
-      REAL(wp), POINTER, DIMENSION(:) ::   esrft , smrft    ! snow energy & salinity of rafting ice
-      REAL(wp), POINTER, DIMENSION(:) ::   oirft1, oirft2   ! ice age of ice rafted
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   eirft      ! ice energy of rafting ice
-      REAL(wp), POINTER, DIMENSION(:,:) ::   erdg1      ! enth*volume of ice ridged
-      REAL(wp), POINTER, DIMENSION(:,:) ::   erdg2      ! enth*volume of new ridges
-      REAL(wp), POINTER, DIMENSION(:,:) ::   ersw       ! enth of water trapped into ridges
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( jpij,        indxi, indxj )
-      CALL wrk_alloc( jpij,        zswitch, fvol )
-      CALL wrk_alloc( jpij,        afrac, ardg1, ardg2, vsrdg, esrdg, dhr, dhr2 )
-      CALL wrk_alloc( jpij,        vrdg1, vrdg2, vsw  , srdg1, srdg2, smsw, oirdg1, oirdg2 )
-      CALL wrk_alloc( jpij,        afrft, arft1, arft2, virft, vsrft, esrft, smrft, oirft1, oirft2 )
-      CALL wrk_alloc( jpij,nlay_i, eirft, erdg1, erdg2, ersw )
-
-      !-------------------------------------------------------------------------------
-      ! 1) Compute change in open water area due to closing and opening.
-      !-------------------------------------------------------------------------------
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            ato_i(ji,jj) = MAX( 0._wp, ato_i(ji,jj) +  &
-               &                     ( opning(ji,jj) - athorn(ji,jj,0) * closing_gross(ji,jj) ) * rdt_ice )
-         END DO
-      END DO
-
-      !-----------------------------------------------------------------
-      ! 3) Pump everything from ice which is being ridged / rafted
-      !-----------------------------------------------------------------
-      ! Compute the area, volume, and energy of ice ridging in each
-      ! category, along with the area of the resulting ridge.
-
-      DO jl1 = 1, jpl !jl1 describes the ridging category
-
-         !------------------------------------------------
-         ! 3.1) Identify grid cells with nonzero ridging
-         !------------------------------------------------
-         icells = 0
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( athorn(ji,jj,jl1) > 0._wp .AND. closing_gross(ji,jj) > 0._wp ) THEN
-                  icells = icells + 1
-                  indxi(icells) = ji
-                  indxj(icells) = jj
-               ENDIF
-            END DO
-         END DO
-
-         DO ij = 1, icells
-            ji = indxi(ij) ; jj = indxj(ij)
-
-            !--------------------------------------------------------------------
-            ! 3.2) Compute area of ridging ice (ardg1) and of new ridge (ardg2)
-            !--------------------------------------------------------------------
-            ardg1(ij) = aridge(ji,jj,jl1) * closing_gross(ji,jj) * rdt_ice
-            arft1(ij) = araft (ji,jj,jl1) * closing_gross(ji,jj) * rdt_ice
-
-            !---------------------------------------------------------------
-            ! 3.3) Compute ridging /rafting fractions, make sure afrac <=1 
-            !---------------------------------------------------------------
-            afrac(ij) = ardg1(ij) / a_i(ji,jj,jl1) !ridging
-            afrft(ij) = arft1(ij) / a_i(ji,jj,jl1) !rafting
-            ardg2(ij) = ardg1(ij) * krdg(ji,jj,jl1)
-            arft2(ij) = arft1(ij) * kraft
-
-            !--------------------------------------------------------------------------
-            ! 3.4) Subtract area, volume, and energy from ridging 
-            !     / rafting category n1.
-            !--------------------------------------------------------------------------
-            vrdg1(ij) = v_i(ji,jj,jl1) * afrac(ij)
-            vrdg2(ij) = vrdg1(ij) * ( 1. + rn_por_rdg )
-            vsw  (ij) = vrdg1(ij) * rn_por_rdg
-
-            vsrdg (ij) = v_s  (ji,jj,  jl1) * afrac(ij)
-            esrdg (ij) = e_s  (ji,jj,1,jl1) * afrac(ij)
-            srdg1 (ij) = smv_i(ji,jj,  jl1) * afrac(ij)
-            oirdg1(ij) = oa_i (ji,jj,  jl1) * afrac(ij)
-            oirdg2(ij) = oa_i (ji,jj,  jl1) * afrac(ij) * krdg(ji,jj,jl1) 
-
-            ! rafting volumes, heat contents ...
-            virft (ij) = v_i  (ji,jj,  jl1) * afrft(ij)
-            vsrft (ij) = v_s  (ji,jj,  jl1) * afrft(ij)
-            esrft (ij) = e_s  (ji,jj,1,jl1) * afrft(ij)
-            smrft (ij) = smv_i(ji,jj,  jl1) * afrft(ij) 
-            oirft1(ij) = oa_i (ji,jj,  jl1) * afrft(ij) 
-            oirft2(ij) = oa_i (ji,jj,  jl1) * afrft(ij) * kraft 
-
-            !-----------------------------------------------------------------
-            ! 3.5) Compute properties of new ridges
-            !-----------------------------------------------------------------
-            smsw(ij)  = vsw(ij) * sss_m(ji,jj)                   ! salt content of seawater frozen in voids
-            srdg2(ij) = srdg1(ij) + smsw(ij)                     ! salt content of new ridge
-            
-            sfx_dyn(ji,jj) = sfx_dyn(ji,jj) - smsw(ij) * rhoic * r1_rdtice
-            wfx_dyn(ji,jj) = wfx_dyn(ji,jj) - vsw (ij) * rhoic * r1_rdtice   ! increase in ice volume due to seawater frozen in voids
-
-            ! virtual salt flux to keep salinity constant
-            IF( nn_icesal == 1 .OR. nn_icesal == 3 )  THEN
-               srdg2(ij)      = srdg2(ij) - vsw(ij) * ( sss_m(ji,jj) - sm_i(ji,jj,jl1) )           ! ridge salinity = sm_i
-               sfx_bri(ji,jj) = sfx_bri(ji,jj) + sss_m(ji,jj)    * vsw(ij) * rhoic * r1_rdtice  &  ! put back sss_m into the ocean
-                  &                            - sm_i(ji,jj,jl1) * vsw(ij) * rhoic * r1_rdtice     ! and get  sm_i  from the ocean 
-            ENDIF
-               
-            !------------------------------------------            
-            ! 3.7 Put the snow somewhere in the ocean
-            !------------------------------------------            
-            !  Place part of the snow lost by ridging into the ocean. 
-            !  Note that esrdg > 0; the ocean must cool to melt snow.
-            !  If the ocean temp = Tf already, new ice must grow.
-            !  During the next time step, thermo_rates will determine whether
-            !  the ocean cools or new ice grows.
-            wfx_snw(ji,jj) = wfx_snw(ji,jj) + ( rhosn * vsrdg(ij) * ( 1._wp - rn_fsnowrdg )   & 
-               &                              + rhosn * vsrft(ij) * ( 1._wp - rn_fsnowrft ) ) * r1_rdtice  ! fresh water source for ocean
-
-            hfx_dyn(ji,jj) = hfx_dyn(ji,jj) + ( - esrdg(ij) * ( 1._wp - rn_fsnowrdg )         & 
-               &                                - esrft(ij) * ( 1._wp - rn_fsnowrft ) ) * r1_rdtice        ! heat sink for ocean (<0, W.m-2)
-
-            !-----------------------------------------------------------------
-            ! 3.8 Compute quantities used to apportion ice among categories
-            ! in the n2 loop below
-            !-----------------------------------------------------------------
-            dhr (ij) = 1._wp / ( hrmax(ji,jj,jl1)                    - hrmin(ji,jj,jl1)                    )
-            dhr2(ij) = 1._wp / ( hrmax(ji,jj,jl1) * hrmax(ji,jj,jl1) - hrmin(ji,jj,jl1) * hrmin(ji,jj,jl1) )
-
-
-            ! update jl1 (removing ridged/rafted area)
-            a_i  (ji,jj,  jl1) = a_i  (ji,jj,  jl1) - ardg1 (ij) - arft1 (ij)
-            v_i  (ji,jj,  jl1) = v_i  (ji,jj,  jl1) - vrdg1 (ij) - virft (ij)
-            v_s  (ji,jj,  jl1) = v_s  (ji,jj,  jl1) - vsrdg (ij) - vsrft (ij)
-            e_s  (ji,jj,1,jl1) = e_s  (ji,jj,1,jl1) - esrdg (ij) - esrft (ij)
-            smv_i(ji,jj,  jl1) = smv_i(ji,jj,  jl1) - srdg1 (ij) - smrft (ij)
-            oa_i (ji,jj,  jl1) = oa_i (ji,jj,  jl1) - oirdg1(ij) - oirft1(ij)
-
-         END DO
-
-         !--------------------------------------------------------------------
-         ! 3.9 Compute ridging ice enthalpy, remove it from ridging ice and
-         !      compute ridged ice enthalpy 
-         !--------------------------------------------------------------------
-         DO jk = 1, nlay_i
-            DO ij = 1, icells
-               ji = indxi(ij) ; jj = indxj(ij)
-               ! heat content of ridged ice
-               erdg1(ij,jk) = e_i(ji,jj,jk,jl1) * afrac(ij) 
-               eirft(ij,jk) = e_i(ji,jj,jk,jl1) * afrft(ij)               
-               
-               ! enthalpy of the trapped seawater (J/m2, >0)
-               ! clem: if sst>0, then ersw <0 (is that possible?)
-               ersw(ij,jk)  = - rhoic * vsw(ij) * rcp * sst_m(ji,jj) * r1_nlay_i
-
-               ! heat flux to the ocean
-               hfx_dyn(ji,jj) = hfx_dyn(ji,jj) + ersw(ij,jk) * r1_rdtice  ! > 0 [W.m-2] ocean->ice flux 
-
-               ! it is added to sea ice because the sign convention is the opposite of the sign convention for the ocean
-               erdg2(ij,jk) = erdg1(ij,jk) + ersw(ij,jk)
-
-               ! update jl1
-               e_i  (ji,jj,jk,jl1) = e_i(ji,jj,jk,jl1) - erdg1(ij,jk) - eirft(ij,jk)
-
-            END DO
-         END DO
-
-         !-------------------------------------------------------------------------------
-         ! 4) Add area, volume, and energy of new ridge to each category jl2
-         !-------------------------------------------------------------------------------
-         DO jl2  = 1, jpl 
-            ! over categories to which ridged/rafted ice is transferred
-            DO ij = 1, icells
-               ji = indxi(ij) ; jj = indxj(ij)
-
-               ! Compute the fraction of ridged ice area and volume going to thickness category jl2.
-               IF( hrmin(ji,jj,jl1) <= hi_max(jl2) .AND. hrmax(ji,jj,jl1) > hi_max(jl2-1) ) THEN
-                  hL = MAX( hrmin(ji,jj,jl1), hi_max(jl2-1) )
-                  hR = MIN( hrmax(ji,jj,jl1), hi_max(jl2)   )
-                  farea    = ( hR      - hL      ) * dhr(ij) 
-                  fvol(ij) = ( hR * hR - hL * hL ) * dhr2(ij)
-               ELSE
-                  farea    = 0._wp 
-                  fvol(ij) = 0._wp                  
-               ENDIF
-
-               ! Compute the fraction of rafted ice area and volume going to thickness category jl2
-               IF( hraft(ji,jj,jl1) <= hi_max(jl2) .AND. hraft(ji,jj,jl1) >  hi_max(jl2-1) ) THEN
-                  zswitch(ij) = 1._wp
-               ELSE
-                  zswitch(ij) = 0._wp                  
-               ENDIF
-
-               a_i  (ji,jj  ,jl2) = a_i  (ji,jj  ,jl2) + ( ardg2 (ij) * farea    + arft2 (ij) * zswitch(ij) )
-               oa_i (ji,jj  ,jl2) = oa_i (ji,jj  ,jl2) + ( oirdg2(ij) * farea    + oirft2(ij) * zswitch(ij) )
-               v_i  (ji,jj  ,jl2) = v_i  (ji,jj  ,jl2) + ( vrdg2 (ij) * fvol(ij) + virft (ij) * zswitch(ij) )
-               smv_i(ji,jj  ,jl2) = smv_i(ji,jj  ,jl2) + ( srdg2 (ij) * fvol(ij) + smrft (ij) * zswitch(ij) )
-               v_s  (ji,jj  ,jl2) = v_s  (ji,jj  ,jl2) + ( vsrdg (ij) * rn_fsnowrdg * fvol(ij)  +  &
-                  &                                        vsrft (ij) * rn_fsnowrft * zswitch(ij) )
-               e_s  (ji,jj,1,jl2) = e_s  (ji,jj,1,jl2) + ( esrdg (ij) * rn_fsnowrdg * fvol(ij)  +  &
-                  &                                        esrft (ij) * rn_fsnowrft * zswitch(ij) )
-
-            END DO
-
-            ! Transfer ice energy to category jl2 by ridging
-            DO jk = 1, nlay_i
-               DO ij = 1, icells
-                  ji = indxi(ij) ; jj = indxj(ij)
-                  e_i(ji,jj,jk,jl2) = e_i(ji,jj,jk,jl2) + erdg2(ij,jk) * fvol(ij) + eirft(ij,jk) * zswitch(ij)                  
-               END DO
-            END DO
-            !
-         END DO ! jl2
-         
-      END DO ! jl1 (deforming categories)
-
-      !
-      CALL wrk_dealloc( jpij,        indxi, indxj )
-      CALL wrk_dealloc( jpij,        zswitch, fvol )
-      CALL wrk_dealloc( jpij,        afrac, ardg1, ardg2, vsrdg, esrdg, dhr, dhr2 )
-      CALL wrk_dealloc( jpij,        vrdg1, vrdg2, vsw  , srdg1, srdg2, smsw, oirdg1, oirdg2 )
-      CALL wrk_dealloc( jpij,        afrft, arft1, arft2, virft, vsrft, esrft, smrft, oirft1, oirft2 )
-      CALL wrk_dealloc( jpij,nlay_i, eirft, erdg1, erdg2, ersw )
-      !
-   END SUBROUTINE lim_itd_me_ridgeshift
-
-   SUBROUTINE lim_itd_me_icestrength( kstrngth )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_me_icestrength ***
-      !!
-      !! ** Purpose :   computes ice strength used in dynamics routines of ice thickness
-      !!
-      !! ** Method  :   Compute the strength of the ice pack, defined as the energy (J m-2) 
-      !!              dissipated per unit area removed from the ice pack under compression,
-      !!              and assumed proportional to the change in potential energy caused
-      !!              by ridging. Note that only Hibler's formulation is stable and that
-      !!              ice strength has to be smoothed
-      !!
-      !! ** Inputs / Ouputs : kstrngth (what kind of ice strength we are using)
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kstrngth    ! = 1 for Rothrock formulation, 0 for Hibler (1979)
-      INTEGER             ::   ji,jj, jl   ! dummy loop indices
-      INTEGER             ::   ksmooth     ! smoothing the resistance to deformation
-      INTEGER             ::   numts_rm    ! number of time steps for the P smoothing
-      REAL(wp)            ::   zp, z1_3    ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zworka           ! temporary array used here
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zstrp1, zstrp2   ! strength at previous time steps
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi,jpj, zworka, zstrp1, zstrp2 )
-
-      !------------------------------------------------------------------------------!
-      ! 1) Initialize
-      !------------------------------------------------------------------------------!
-      strength(:,:) = 0._wp
-
-      !------------------------------------------------------------------------------!
-      ! 2) Compute thickness distribution of ridging and ridged ice
-      !------------------------------------------------------------------------------!
-      CALL lim_itd_me_ridgeprep
-
-      !------------------------------------------------------------------------------!
-      ! 3) Rothrock(1975)'s method
-      !------------------------------------------------------------------------------!
-      IF( kstrngth == 1 ) THEN
-         z1_3 = 1._wp / 3._wp
-         DO jl = 1, jpl
-            DO jj= 1, jpj
-               DO ji = 1, jpi
-                  !
-                  IF( athorn(ji,jj,jl) > 0._wp ) THEN
-                     !----------------------------
-                     ! PE loss from deforming ice
-                     !----------------------------
-                     strength(ji,jj) = strength(ji,jj) - athorn(ji,jj,jl) * ht_i(ji,jj,jl) * ht_i(ji,jj,jl)
-
-                     !--------------------------
-                     ! PE gain from rafting ice
-                     !--------------------------
-                     strength(ji,jj) = strength(ji,jj) + 2._wp * araft(ji,jj,jl) * ht_i(ji,jj,jl) * ht_i(ji,jj,jl)
-
-                     !----------------------------
-                     ! PE gain from ridging ice
-                     !----------------------------
-                     strength(ji,jj) = strength(ji,jj) + aridge(ji,jj,jl) * krdg(ji,jj,jl) * z1_3 *  &
-                        &                              ( hrmax(ji,jj,jl) * hrmax(ji,jj,jl) +         &
-                        &                                hrmin(ji,jj,jl) * hrmin(ji,jj,jl) +         &
-                        &                                hrmax(ji,jj,jl) * hrmin(ji,jj,jl) )  
-                        !!(a**3-b**3)/(a-b) = a*a+ab+b*b                      
-                  ENDIF
-                  !
-               END DO
-            END DO
-         END DO
-   
-         strength(:,:) = rn_pe_rdg * Cp * strength(:,:) / aksum(:,:) * tmask(:,:,1)
-                         ! where Cp = (g/2)*(rhow-rhoi)*(rhoi/rhow) and rn_pe_rdg accounts for frictional dissipation
-         ksmooth = 1
-
-      !------------------------------------------------------------------------------!
-      ! 4) Hibler (1979)' method
-      !------------------------------------------------------------------------------!
-      ELSE                      ! kstrngth ne 1:  Hibler (1979) form
-         !
-         strength(:,:) = rn_pstar * vt_i(:,:) * EXP( - rn_crhg * ( 1._wp - at_i(:,:) )  ) * tmask(:,:,1)
-         !
-         ksmooth = 1
-         !
-      ENDIF                     ! kstrngth
-      !
-      !------------------------------------------------------------------------------!
-      ! 5) Impact of brine volume
-      !------------------------------------------------------------------------------!
-      ! CAN BE REMOVED
-      IF( ln_icestr_bvf ) THEN
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               strength(ji,jj) = strength(ji,jj) * exp(-5.88*SQRT(MAX(bvm_i(ji,jj),0.0)))
-            END DO
-         END DO
-      ENDIF
-      !
-      !------------------------------------------------------------------------------!
-      ! 6) Smoothing ice strength
-      !------------------------------------------------------------------------------!
-      !
-      !-------------------
-      ! Spatial smoothing
-      !-------------------
-      IF ( ksmooth == 1 ) THEN
-
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1
-               IF ( ( asum(ji,jj) - ato_i(ji,jj) ) > 0._wp ) THEN 
-                  zworka(ji,jj) = ( 4.0 * strength(ji,jj)              &
-                     &                  + strength(ji-1,jj) * tmask(ji-1,jj,1) + strength(ji+1,jj) * tmask(ji+1,jj,1) &  
-                     &                  + strength(ji,jj-1) * tmask(ji,jj-1,1) + strength(ji,jj+1) * tmask(ji,jj+1,1) &
-                     &            ) / ( 4.0 + tmask(ji-1,jj,1) + tmask(ji+1,jj,1) + tmask(ji,jj-1,1) + tmask(ji,jj+1,1) )
-               ELSE
-                  zworka(ji,jj) = 0._wp
-               ENDIF
-            END DO
-         END DO
-
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1
-               strength(ji,jj) = zworka(ji,jj)
-            END DO
-         END DO
-         CALL lbc_lnk( strength, 'T', 1. )
-
-      ENDIF
-
-      !--------------------
-      ! Temporal smoothing
-      !--------------------
-      IF ( ksmooth == 2 ) THEN
-
-         IF ( numit == nit000 + nn_fsbc - 1 ) THEN
-            zstrp1(:,:) = 0._wp
-            zstrp2(:,:) = 0._wp
-         ENDIF
-
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1
-               IF ( ( asum(ji,jj) - ato_i(ji,jj) ) > 0._wp ) THEN 
-                  numts_rm = 1 ! number of time steps for the running mean
-                  IF ( zstrp1(ji,jj) > 0._wp ) numts_rm = numts_rm + 1
-                  IF ( zstrp2(ji,jj) > 0._wp ) numts_rm = numts_rm + 1
-                  zp = ( strength(ji,jj) + zstrp1(ji,jj) + zstrp2(ji,jj) ) / numts_rm
-                  zstrp2(ji,jj) = zstrp1(ji,jj)
-                  zstrp1(ji,jj) = strength(ji,jj)
-                  strength(ji,jj) = zp
-               ENDIF
-            END DO
-         END DO
-
-         CALL lbc_lnk( strength, 'T', 1. )      ! Boundary conditions
-
-      ENDIF ! ksmooth
-
-      CALL wrk_dealloc( jpi,jpj, zworka, zstrp1, zstrp2 )
-      !
-   END SUBROUTINE lim_itd_me_icestrength
-
-   SUBROUTINE lim_itd_me_init
-      !!-------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_itd_me_init ***
-      !!
-      !! ** Purpose :   Physical constants and parameters linked 
-      !!                to the mechanical ice redistribution
-      !!
-      !! ** Method  :   Read the namiceitdme namelist 
-      !!                and check the parameters values 
-      !!                called at the first timestep (nit000)
-      !!
-      !! ** input   :   Namelist namiceitdme
-      !!-------------------------------------------------------------------
-      INTEGER :: ios                 ! Local integer output status for namelist read
-      NAMELIST/namiceitdme/ rn_cs, nn_partfun, rn_gstar, rn_astar,             & 
-        &                   ln_ridging, rn_hstar, rn_por_rdg, rn_fsnowrdg, ln_rafting, rn_hraft, rn_craft, rn_fsnowrft
-      !!-------------------------------------------------------------------
-      !
-      REWIND( numnam_ice_ref )              ! Namelist namicetdme in reference namelist : Ice mechanical ice redistribution
-      READ  ( numnam_ice_ref, namiceitdme, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namiceitdme in reference namelist', lwp )
-
-      REWIND( numnam_ice_cfg )              ! Namelist namiceitdme in configuration namelist : Ice mechanical ice redistribution
-      READ  ( numnam_ice_cfg, namiceitdme, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namiceitdme in configuration namelist', lwp )
-      IF(lwm) WRITE ( numoni, namiceitdme )
-      !
-      IF (lwp) THEN                          ! control print
-         WRITE(numout,*)
-         WRITE(numout,*)'lim_itd_me_init : ice parameters for mechanical ice redistribution '
-         WRITE(numout,*)'~~~~~~~~~~~~~~~'
-         WRITE(numout,*)'   Fraction of shear energy contributing to ridging        rn_cs       = ', rn_cs 
-         WRITE(numout,*)'   Switch for part. function (0) linear (1) exponential    nn_partfun  = ', nn_partfun
-         WRITE(numout,*)'   Fraction of total ice coverage contributing to ridging  rn_gstar    = ', rn_gstar
-         WRITE(numout,*)'   Equivalent to G* for an exponential part function       rn_astar    = ', rn_astar
-         WRITE(numout,*)'   Ridging of ice sheets or not                            ln_ridging  = ', ln_ridging
-         WRITE(numout,*)'   Quantity playing a role in max ridged ice thickness     rn_hstar    = ', rn_hstar
-         WRITE(numout,*)'   Initial porosity of ridges                              rn_por_rdg  = ', rn_por_rdg
-         WRITE(numout,*)'   Fraction of snow volume conserved during ridging        rn_fsnowrdg = ', rn_fsnowrdg 
-         WRITE(numout,*)'   Rafting of ice sheets or not                            ln_rafting  = ', ln_rafting
-         WRITE(numout,*)'   Parmeter thickness (threshold between ridge-raft)       rn_hraft    = ', rn_hraft
-         WRITE(numout,*)'   Rafting hyperbolic tangent coefficient                  rn_craft    = ', rn_craft  
-         WRITE(numout,*)'   Fraction of snow volume conserved during ridging        rn_fsnowrft = ', rn_fsnowrft 
-      ENDIF
-      !
-   END SUBROUTINE lim_itd_me_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Empty module          NO LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_itd_me           ! Empty routines
-   END SUBROUTINE lim_itd_me
-   SUBROUTINE lim_itd_me_icestrength
-   END SUBROUTINE lim_itd_me_icestrength
-   SUBROUTINE lim_itd_me_init
-   END SUBROUTINE lim_itd_me_init
-#endif
-   !!======================================================================
-END MODULE limitd_me
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limitd_th.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limitd_th.F90	(revision 9018)
+++ 	(revision )
@@ -1,795 +1,0 @@
-MODULE limitd_th
-   !!======================================================================
-   !!                       ***  MODULE limitd_th ***
-   !!   LIM3 ice model : ice thickness distribution: Thermodynamics
-   !!======================================================================
-   !! History :   -   !          (W. H. Lipscomb and E.C. Hunke) CICE (c) original code
-   !!            3.0  ! 2005-12  (M. Vancoppenolle) adaptation to LIM-3
-   !!             -   ! 2006-06  (M. Vancoppenolle) adaptation to include salt, age
-   !!             -   ! 2007-04  (M. Vancoppenolle) Mass conservation checked
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                   LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_itd_th_rem   :
-   !!   lim_itd_th_reb   :
-   !!   lim_itd_fitline  :
-   !!   lim_itd_shiftice :
-   !!----------------------------------------------------------------------
-   USE par_oce          ! ocean parameters
-   USE dom_oce          ! ocean domain
-   USE phycst           ! physical constants (ocean directory) 
-   USE thd_ice          ! LIM-3 thermodynamic variables
-   USE ice              ! LIM-3 variables
-   USE limvar           ! LIM-3 variables
-   USE prtctl           ! Print control
-   USE in_out_manager   ! I/O manager
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE lib_fortran      ! to use key_nosignedzero
-   USE limcons          ! conservation tests
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_itd_th_rem
-   PUBLIC   lim_itd_th_reb
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_itd_th_rem( klbnd, kubnd, kt )
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_th_rem ***
-      !!
-      !! ** Purpose :   computes the redistribution of ice thickness
-      !!              after thermodynamic growth of ice thickness
-      !!
-      !! ** Method  : Linear remapping 
-      !!
-      !! References : W.H. Lipscomb, JGR 2001
-      !!------------------------------------------------------------------
-      INTEGER , INTENT (in) ::   klbnd   ! Start thickness category index point
-      INTEGER , INTENT (in) ::   kubnd   ! End point on which the  the computation is applied
-      INTEGER , INTENT (in) ::   kt      ! Ocean time step 
-      !
-      INTEGER  ::   ji, jj, jl     ! dummy loop index
-      INTEGER  ::   ii, ij         ! 2D corresponding indices to ji
-      INTEGER  ::   nd             ! local integer
-      REAL(wp) ::   zx1, zwk1, zdh0, zetamin, zdamax   ! local scalars
-      REAL(wp) ::   zx2, zwk2, zda0, zetamax           !   -      -
-      REAL(wp) ::   zx3        
-      CHARACTER (len = 15) :: fieldid
-
-      INTEGER , POINTER, DIMENSION(:,:,:) ::   zdonor   ! donor category index
-
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zdhice      ! ice thickness increment
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   g0          ! coefficients for fitting the line of the ITD
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   g1          ! coefficients for fitting the line of the ITD
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   hL          ! left boundary for the ITD for each thickness
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   hR          ! left boundary for the ITD for each thickness
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zht_i_b     ! old ice thickness
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   dummy_es
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zdaice, zdvice          ! local increment of ice area and volume
-      REAL(wp), POINTER, DIMENSION(:)     ::   zvetamin, zvetamax      ! maximum values for etas
-      INTEGER , POINTER, DIMENSION(:)     ::   nind_i, nind_j          ! compressed indices for i/j directions
-      INTEGER                             ::   nbrem                   ! number of cells with ice to transfer
-      REAL(wp)                            ::   zslope                  ! used to compute local thermodynamic "speeds"
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zhb0, zhb1              ! category boundaries for thinnes categories
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   vt_i_init, vt_i_final   !  ice volume summed over categories
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   vt_s_init, vt_s_final   !  snow volume summed over categories
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   et_i_init, et_i_final   !  ice energy summed over categories
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   et_s_init, et_s_final   !  snow energy summed over categories
-      INTEGER , POINTER, DIMENSION(:,:)   ::   zremap_flag      ! compute remapping or not ????
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zhbnew           ! new boundaries of ice categories
-      !!------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi,jpj, zremap_flag )
-      CALL wrk_alloc( jpi,jpj,jpl-1, zdonor )
-      CALL wrk_alloc( jpi,jpj,jpl, zdhice, g0, g1, hL, hR, zht_i_b, dummy_es )
-      CALL wrk_alloc( jpi,jpj,jpl-1, zdaice, zdvice )   
-      CALL wrk_alloc( jpi,jpj,jpl+1, zhbnew, kkstart = 0 )   
-      CALL wrk_alloc( (jpi+1)*(jpj+1), zvetamin, zvetamax )   
-      CALL wrk_alloc( (jpi+1)*(jpj+1), nind_i, nind_j ) 
-      CALL wrk_alloc( jpi,jpj, zhb0,zhb1,vt_i_init,vt_i_final,vt_s_init,vt_s_final,et_i_init,et_i_final,et_s_init,et_s_final )
-
-      !!----------------------------------------------------------------------------------------------
-      !! 0) Conservation checkand changes in each ice category
-      !!----------------------------------------------------------------------------------------------
-      IF( con_i ) THEN
-         CALL lim_column_sum (jpl,   v_i, vt_i_init)
-         CALL lim_column_sum (jpl,   v_s, vt_s_init)
-         CALL lim_column_sum_energy (jpl, nlay_i,   e_i, et_i_init)
-         dummy_es(:,:,:) = e_s(:,:,1,:)
-         CALL lim_column_sum (jpl, dummy_es(:,:,:) , et_s_init)
-      ENDIF
-
-      !!----------------------------------------------------------------------------------------------
-      !! 1) Compute thickness and changes in each ice category
-      !!----------------------------------------------------------------------------------------------
-      IF( kt == nit000 .AND. lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_itd_th_rem  : Remapping the ice thickness distribution'
-         WRITE(numout,*) '~~~~~~~~~~~~~~~'
-         WRITE(numout,*) ' klbnd :       ', klbnd
-         WRITE(numout,*) ' kubnd :       ', kubnd
-      ENDIF
-
-      zdhice(:,:,:) = 0._wp
-      DO jl = klbnd, kubnd
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               rswitch           = MAX( 0.0, SIGN( 1.0, a_i(ji,jj,jl) - epsi10 ) )     !0 if no ice and 1 if yes
-               ht_i(ji,jj,jl)    = v_i(ji,jj,jl) / MAX( a_i(ji,jj,jl), epsi10 ) * rswitch
-               rswitch           = MAX( 0.0, SIGN( 1.0, a_i_b(ji,jj,jl) - epsi10) )
-               zht_i_b(ji,jj,jl) = v_i_b(ji,jj,jl) / MAX( a_i_b(ji,jj,jl), epsi10 ) * rswitch
-               IF( a_i(ji,jj,jl) > epsi10 )   zdhice(ji,jj,jl) = ht_i(ji,jj,jl) - zht_i_b(ji,jj,jl) ! clem: useless IF statement? 
-            END DO
-         END DO
-      END DO
-
-      !-----------------------------------------------------------------------------------------------
-      !  2) Compute fractional ice area in each grid cell
-      !-----------------------------------------------------------------------------------------------
-      at_i(:,:) = 0._wp
-      DO jl = klbnd, kubnd
-         at_i(:,:) = at_i(:,:) + a_i(:,:,jl)
-      END DO
-
-      !-----------------------------------------------------------------------------------------------
-      !  3) Identify grid cells with ice
-      !-----------------------------------------------------------------------------------------------
-      nbrem = 0
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF ( at_i(ji,jj) > epsi10 ) THEN
-               nbrem         = nbrem + 1
-               nind_i(nbrem) = ji
-               nind_j(nbrem) = jj
-               zremap_flag(ji,jj) = 1
-            ELSE
-               zremap_flag(ji,jj) = 0
-            ENDIF
-         END DO
-      END DO
-
-      !-----------------------------------------------------------------------------------------------
-      !  4) Compute new category boundaries
-      !-----------------------------------------------------------------------------------------------
-      !- 4.1 Compute category boundaries
-      zhbnew(:,:,:) = 0._wp
-
-      DO jl = klbnd, kubnd - 1
-         DO ji = 1, nbrem
-            ii = nind_i(ji)
-            ij = nind_j(ji)
-            !
-            zhbnew(ii,ij,jl) = hi_max(jl)
-            IF    ( a_i_b(ii,ij,jl) > epsi10 .AND. a_i_b(ii,ij,jl+1) > epsi10 ) THEN
-               !interpolate between adjacent category growth rates
-               zslope           = ( zdhice(ii,ij,jl+1) - zdhice(ii,ij,jl) ) / ( zht_i_b(ii,ij,jl+1) - zht_i_b(ii,ij,jl) )
-               zhbnew(ii,ij,jl) = hi_max(jl) + zdhice(ii,ij,jl) + zslope * ( hi_max(jl) - zht_i_b(ii,ij,jl) )
-            ELSEIF( a_i_b(ii,ij,jl) > epsi10) THEN
-               zhbnew(ii,ij,jl) = hi_max(jl) + zdhice(ii,ij,jl)
-            ELSEIF( a_i_b(ii,ij,jl+1) > epsi10) THEN
-               zhbnew(ii,ij,jl) = hi_max(jl) + zdhice(ii,ij,jl+1)
-            ENDIF
-         END DO
-
-         !- 4.2 Check that each zhbnew lies between adjacent values of ice thickness
-         DO ji = 1, nbrem
-            ii = nind_i(ji)
-            ij = nind_j(ji)
-
-            ! clem: we do not want ht_i to be too close to either HR or HL otherwise a division by nearly 0 is possible 
-            ! in lim_itd_fitline in the case (HR-HL) = 3(Hice - HL) or = 3(HR - Hice)
-            IF    ( a_i(ii,ij,jl  ) > epsi10 .AND. ht_i(ii,ij,jl  ) > ( zhbnew(ii,ij,jl) - epsi10 ) ) THEN
-               zremap_flag(ii,ij) = 0
-            ELSEIF( a_i(ii,ij,jl+1) > epsi10 .AND. ht_i(ii,ij,jl+1) < ( zhbnew(ii,ij,jl) + epsi10 ) ) THEN
-               zremap_flag(ii,ij) = 0
-            ENDIF
-
-            !- 4.3 Check that each zhbnew does not exceed maximal values hi_max  
-            IF( zhbnew(ii,ij,jl) < hi_max(jl-1) ) zremap_flag(ii,ij) = 0
-            IF( zhbnew(ii,ij,jl) > hi_max(jl+1) ) zremap_flag(ii,ij) = 0
-            ! clem bug: why is not the following instead?
-            !!IF( zhbnew(ii,ij,jl) < hi_max(jl-1) ) zremap_flag(ii,ij) = 0
-            !!IF( zhbnew(ii,ij,jl) > hi_max(jl  ) ) zremap_flag(ii,ij) = 0
- 
-         END DO
-
-      END DO
-
-      !-----------------------------------------------------------------------------------------------
-      !  5) Identify cells where ITD is to be remapped
-      !-----------------------------------------------------------------------------------------------
-      nbrem = 0
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( zremap_flag(ji,jj) == 1 ) THEN
-               nbrem         = nbrem + 1
-               nind_i(nbrem) = ji
-               nind_j(nbrem) = jj
-            ENDIF
-         END DO 
-      END DO 
-
-      !-----------------------------------------------------------------------------------------------
-      !  6) Fill arrays with lowermost / uppermost boundaries of 'new' categories
-      !-----------------------------------------------------------------------------------------------
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            zhb0(ji,jj) = hi_max(0)
-            zhb1(ji,jj) = hi_max(1)
-
-            IF( a_i(ji,jj,kubnd) > epsi10 ) THEN
-               zhbnew(ji,jj,kubnd) = MAX( hi_max(kubnd-1), 3._wp * ht_i(ji,jj,kubnd) - 2._wp * zhbnew(ji,jj,kubnd-1) )
-            ELSE
-!clem bug               zhbnew(ji,jj,kubnd) = hi_max(kubnd)  
-               zhbnew(ji,jj,kubnd) = hi_max(kubnd-1) ! not used anyway
-            ENDIF
-
-            ! clem: we do not want ht_i_b to be too close to either HR or HL otherwise a division by nearly 0 is possible 
-            ! in lim_itd_fitline in the case (HR-HL) = 3(Hice - HL) or = 3(HR - Hice)
-            IF    ( zht_i_b(ji,jj,klbnd) < ( zhb0(ji,jj) + epsi10 ) )  THEN
-               zremap_flag(ji,jj) = 0
-            ELSEIF( zht_i_b(ji,jj,klbnd) > ( zhb1(ji,jj) - epsi10 ) )  THEN
-               zremap_flag(ji,jj) = 0
-            ENDIF
-
-         END DO
-      END DO
-
-      !-----------------------------------------------------------------------------------------------
-      !  7) Compute g(h) 
-      !-----------------------------------------------------------------------------------------------
-      !- 7.1 g(h) for category 1 at start of time step
-      CALL lim_itd_fitline( klbnd, zhb0, zhb1, zht_i_b(:,:,klbnd), g0(:,:,klbnd), g1(:,:,klbnd), hL(:,:,klbnd),   &
-         &                  hR(:,:,klbnd), zremap_flag )
-
-      !- 7.2 Area lost due to melting of thin ice (first category,  klbnd)
-      DO ji = 1, nbrem
-         ii = nind_i(ji) 
-         ij = nind_j(ji) 
-
-         IF( a_i(ii,ij,klbnd) > epsi10 ) THEN
-
-            zdh0 = zdhice(ii,ij,klbnd) !decrease of ice thickness in the lower category
-
-            IF( zdh0 < 0.0 ) THEN      !remove area from category 1
-               zdh0 = MIN( -zdh0, hi_max(klbnd) )
-               !Integrate g(1) from 0 to dh0 to estimate area melted
-               zetamax = MIN( zdh0, hR(ii,ij,klbnd) ) - hL(ii,ij,klbnd)
-
-               IF( zetamax > 0.0 ) THEN
-                  zx1    = zetamax
-                  zx2    = 0.5 * zetamax * zetamax 
-                  zda0   = g1(ii,ij,klbnd) * zx2 + g0(ii,ij,klbnd) * zx1                        ! ice area removed
-                  zdamax = a_i(ii,ij,klbnd) * (1.0 - ht_i(ii,ij,klbnd) / zht_i_b(ii,ij,klbnd) ) ! Constrain new thickness <= ht_i                
-                  zda0   = MIN( zda0, zdamax )                                                  ! ice area lost due to melting 
-                                                                                                !     of thin ice (zdamax > 0)
-                  ! Remove area, conserving volume
-                  ht_i(ii,ij,klbnd) = ht_i(ii,ij,klbnd) * a_i(ii,ij,klbnd) / ( a_i(ii,ij,klbnd) - zda0 )
-                  a_i(ii,ij,klbnd)  = a_i(ii,ij,klbnd) - zda0
-                  v_i(ii,ij,klbnd)  = a_i(ii,ij,klbnd) * ht_i(ii,ij,klbnd) ! clem-useless ?
-               ENDIF
-
-            ELSE ! if ice accretion zdh0 > 0
-               ! zhbnew was 0, and is shifted to the right to account for thin ice growth in openwater (F0 = f1)
-               zhbnew(ii,ij,klbnd-1) = MIN( zdh0, hi_max(klbnd) ) 
-            ENDIF
-
-         ENDIF
-
-      END DO
-
-      !- 7.3 g(h) for each thickness category  
-      DO jl = klbnd, kubnd
-         CALL lim_itd_fitline( jl, zhbnew(:,:,jl-1), zhbnew(:,:,jl), ht_i(:,:,jl),  &
-            &                  g0(:,:,jl), g1(:,:,jl), hL(:,:,jl), hR(:,:,jl), zremap_flag )
-      END DO
-
-      !-----------------------------------------------------------------------------------------------
-      !  8) Compute area and volume to be shifted across each boundary
-      !-----------------------------------------------------------------------------------------------
-
-      DO jl = klbnd, kubnd - 1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zdonor(ji,jj,jl) = 0
-               zdaice(ji,jj,jl) = 0.0
-               zdvice(ji,jj,jl) = 0.0
-            END DO
-         END DO
-
-         DO ji = 1, nbrem
-            ii = nind_i(ji)
-            ij = nind_j(ji)
-
-            IF (zhbnew(ii,ij,jl) > hi_max(jl)) THEN ! transfer from jl to jl+1
-               ! left and right integration limits in eta space
-               zvetamin(ji) = MAX( hi_max(jl), hL(ii,ij,jl) ) - hL(ii,ij,jl)
-               zvetamax(ji) = MIN( zhbnew(ii,ij,jl), hR(ii,ij,jl) ) - hL(ii,ij,jl)
-               zdonor(ii,ij,jl) = jl
-
-            ELSE                                    ! zhbnew(jl) <= hi_max(jl) ; transfer from jl+1 to jl
-               ! left and right integration limits in eta space
-               zvetamin(ji) = 0.0
-               zvetamax(ji) = MIN( hi_max(jl), hR(ii,ij,jl+1) ) - hL(ii,ij,jl+1)
-               zdonor(ii,ij,jl) = jl + 1
-
-            ENDIF
-
-            zetamax = MAX( zvetamax(ji), zvetamin(ji) ) ! no transfer if etamax < etamin
-            zetamin = zvetamin(ji)
-
-            zx1  = zetamax - zetamin
-            zwk1 = zetamin * zetamin
-            zwk2 = zetamax * zetamax
-            zx2  = 0.5 * ( zwk2 - zwk1 )
-            zwk1 = zwk1 * zetamin
-            zwk2 = zwk2 * zetamax
-            zx3  = 1.0 / 3.0 * ( zwk2 - zwk1 )
-            nd   = zdonor(ii,ij,jl)
-            zdaice(ii,ij,jl) = g1(ii,ij,nd)*zx2 + g0(ii,ij,nd)*zx1
-            zdvice(ii,ij,jl) = g1(ii,ij,nd)*zx3 + g0(ii,ij,nd)*zx2 + zdaice(ii,ij,jl)*hL(ii,ij,nd)
-
-         END DO
-      END DO
-
-      !!----------------------------------------------------------------------------------------------
-      !! 9) Shift ice between categories
-      !!----------------------------------------------------------------------------------------------
-      CALL lim_itd_shiftice ( klbnd, kubnd, zdonor, zdaice, zdvice )
-
-      !!----------------------------------------------------------------------------------------------
-      !! 10) Make sure ht_i >= minimum ice thickness hi_min
-      !!----------------------------------------------------------------------------------------------
-
-      DO ji = 1, nbrem
-         ii = nind_i(ji)
-         ij = nind_j(ji)
-         IF ( a_i(ii,ij,1) > epsi10 .AND. ht_i(ii,ij,1) < rn_himin ) THEN
-            a_i (ii,ij,1) = a_i(ii,ij,1) * ht_i(ii,ij,1) / rn_himin 
-            ht_i(ii,ij,1) = rn_himin
-         ENDIF
-      END DO
-
-      !!----------------------------------------------------------------------------------------------
-      !! 11) Conservation check
-      !!----------------------------------------------------------------------------------------------
-      IF ( con_i ) THEN
-         CALL lim_column_sum (jpl,   v_i, vt_i_final)
-         fieldid = ' v_i : limitd_th '
-         CALL lim_cons_check (vt_i_init, vt_i_final, 1.0e-6, fieldid) 
-
-         CALL lim_column_sum_energy (jpl, nlay_i,  e_i, et_i_final)
-         fieldid = ' e_i : limitd_th '
-         CALL lim_cons_check (et_i_init, et_i_final, 1.0e-3, fieldid) 
-
-         CALL lim_column_sum (jpl,   v_s, vt_s_final)
-         fieldid = ' v_s : limitd_th '
-         CALL lim_cons_check (vt_s_init, vt_s_final, 1.0e-6, fieldid) 
-
-         dummy_es(:,:,:) = e_s(:,:,1,:)
-         CALL lim_column_sum (jpl, dummy_es(:,:,:) , et_s_final)
-         fieldid = ' e_s : limitd_th '
-         CALL lim_cons_check (et_s_init, et_s_final, 1.0e-3, fieldid) 
-      ENDIF
-
-      CALL wrk_dealloc( jpi,jpj, zremap_flag )
-      CALL wrk_dealloc( jpi,jpj,jpl-1, zdonor )
-      CALL wrk_dealloc( jpi,jpj,jpl, zdhice, g0, g1, hL, hR, zht_i_b, dummy_es )
-      CALL wrk_dealloc( jpi,jpj,jpl-1, zdaice, zdvice )   
-      CALL wrk_dealloc( jpi,jpj,jpl+1, zhbnew, kkstart = 0 )   
-      CALL wrk_dealloc( (jpi+1)*(jpj+1), zvetamin, zvetamax )   
-      CALL wrk_dealloc( (jpi+1)*(jpj+1), nind_i, nind_j ) 
-      CALL wrk_dealloc( jpi,jpj, zhb0,zhb1,vt_i_init,vt_i_final,vt_s_init,vt_s_final,et_i_init,et_i_final,et_s_init,et_s_final )
-
-   END SUBROUTINE lim_itd_th_rem
-
-
-   SUBROUTINE lim_itd_fitline( num_cat, HbL, Hbr, hice, g0, g1, hL, hR, zremap_flag )
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_fitline ***
-      !!
-      !! ** Purpose :   fit g(h) with a line using area, volume constraints
-      !!
-      !! ** Method  :   Fit g(h) with a line, satisfying area and volume constraints.
-      !!              To reduce roundoff errors caused by large values of g0 and g1,
-      !!              we actually compute g(eta), where eta = h - hL, and hL is the
-      !!              left boundary.
-      !!------------------------------------------------------------------
-      INTEGER                     , INTENT(in   ) ::   num_cat      ! category index
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   HbL, HbR     ! left and right category boundaries
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   hice         ! ice thickness
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   g0, g1       ! coefficients in linear equation for g(eta)
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   hL           ! min value of range over which g(h) > 0
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(  out) ::   hR           ! max value of range over which g(h) > 0
-      INTEGER , DIMENSION(jpi,jpj), INTENT(in   ) ::   zremap_flag  !
-      !
-      INTEGER  ::   ji,jj        ! horizontal indices
-      REAL(wp) ::   zh13         ! HbL + 1/3 * (HbR - HbL)
-      REAL(wp) ::   zh23         ! HbL + 2/3 * (HbR - HbL)
-      REAL(wp) ::   zdhr         ! 1 / (hR - hL)
-      REAL(wp) ::   zwk1, zwk2   ! temporary variables
-      !!------------------------------------------------------------------
-      !
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            !
-            IF( zremap_flag(ji,jj) == 1 .AND. a_i(ji,jj,num_cat) > epsi10   &
-               &                        .AND. hice(ji,jj)        > 0._wp )  THEN
-
-               ! Initialize hL and hR
-               hL(ji,jj) = HbL(ji,jj)
-               hR(ji,jj) = HbR(ji,jj)
-
-               ! Change hL or hR if hice falls outside central third of range
-               zh13 = 1.0 / 3.0 * ( 2.0 * hL(ji,jj) + hR(ji,jj) )
-               zh23 = 1.0 / 3.0 * ( hL(ji,jj) + 2.0 * hR(ji,jj) )
-
-               IF    ( hice(ji,jj) < zh13 ) THEN   ;   hR(ji,jj) = 3._wp * hice(ji,jj) - 2._wp * hL(ji,jj)
-               ELSEIF( hice(ji,jj) > zh23 ) THEN   ;   hL(ji,jj) = 3._wp * hice(ji,jj) - 2._wp * hR(ji,jj)
-               ENDIF
-
-               ! Compute coefficients of g(eta) = g0 + g1*eta
-               zdhr = 1._wp / (hR(ji,jj) - hL(ji,jj))
-               zwk1 = 6._wp * a_i(ji,jj,num_cat) * zdhr
-               zwk2 = ( hice(ji,jj) - hL(ji,jj) ) * zdhr
-               g0(ji,jj) = zwk1 * ( 2._wp / 3._wp - zwk2 )
-               g1(ji,jj) = 2._wp * zdhr * zwk1 * ( zwk2 - 0.5 )
-               !
-            ELSE  ! remap_flag = .false. or a_i < epsi10 
-               hL(ji,jj) = 0._wp
-               hR(ji,jj) = 0._wp
-               g0(ji,jj) = 0._wp
-               g1(ji,jj) = 0._wp
-            ENDIF
-            !
-         END DO
-      END DO
-      !
-   END SUBROUTINE lim_itd_fitline
-
-
-   SUBROUTINE lim_itd_shiftice( klbnd, kubnd, zdonor, zdaice, zdvice )
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_shiftice ***
-      !!
-      !! ** Purpose :   shift ice across category boundaries, conserving everything
-      !!              ( area, volume, energy, age*vol, and mass of salt )
-      !!
-      !! ** Method  :
-      !!------------------------------------------------------------------
-      INTEGER                           , INTENT(in   ) ::   klbnd    ! Start thickness category index point
-      INTEGER                           , INTENT(in   ) ::   kubnd    ! End point on which the  the computation is applied
-      INTEGER , DIMENSION(jpi,jpj,jpl-1), INTENT(in   ) ::   zdonor   ! donor category index
-      REAL(wp), DIMENSION(jpi,jpj,jpl-1), INTENT(inout) ::   zdaice   ! ice area transferred across boundary
-      REAL(wp), DIMENSION(jpi,jpj,jpl-1), INTENT(inout) ::   zdvice   ! ice volume transferred across boundary
-
-      INTEGER ::   ji, jj, jl, jl2, jl1, jk   ! dummy loop indices
-      INTEGER ::   ii, ij                     ! indices when changing from 2D-1D is done
-
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zaTsfn
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zworka            ! temporary array used here
-
-      REAL(wp) ::   zdvsnow, zdesnow   ! snow volume and energy transferred
-      REAL(wp) ::   zdeice             ! ice energy transferred
-      REAL(wp) ::   zdsm_vice          ! ice salinity times volume transferred
-      REAL(wp) ::   zdo_aice           ! ice age times volume transferred
-      REAL(wp) ::   zdaTsf             ! aicen*Tsfcn transferred
-
-      INTEGER, POINTER, DIMENSION(:) ::   nind_i, nind_j   ! compressed indices for i/j directions
-
-      INTEGER  ::   nbrem             ! number of cells with ice to transfer
-      !!------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi,jpj,jpl, zaTsfn )
-      CALL wrk_alloc( jpi,jpj, zworka )
-      CALL wrk_alloc( (jpi+1)*(jpj+1), nind_i, nind_j )
-
-      !----------------------------------------------------------------------------------------------
-      ! 1) Define a variable equal to a_i*T_su
-      !----------------------------------------------------------------------------------------------
-
-      DO jl = klbnd, kubnd
-         zaTsfn(:,:,jl) = a_i(:,:,jl) * t_su(:,:,jl)
-      END DO
-
-      !-------------------------------------------------------------------------------
-      ! 2) Transfer volume and energy between categories
-      !-------------------------------------------------------------------------------
-
-      DO jl = klbnd, kubnd - 1
-         nbrem = 0
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF (zdaice(ji,jj,jl) > 0.0 ) THEN ! daice(n) can be < puny
-                  nbrem = nbrem + 1
-                  nind_i(nbrem) = ji
-                  nind_j(nbrem) = jj
-               ENDIF
-            END DO
-         END DO
-
-         DO ji = 1, nbrem 
-            ii = nind_i(ji)
-            ij = nind_j(ji)
-
-            jl1 = zdonor(ii,ij,jl)
-            rswitch       = MAX( 0._wp , SIGN( 1._wp , v_i(ii,ij,jl1) - epsi10 ) )
-            zworka(ii,ij) = zdvice(ii,ij,jl) / MAX( v_i(ii,ij,jl1), epsi10 ) * rswitch
-            IF( jl1 == jl) THEN   ;   jl2 = jl1+1
-            ELSE                  ;   jl2 = jl 
-            ENDIF
-
-            !--------------
-            ! Ice areas
-            !--------------
-            a_i(ii,ij,jl1) = a_i(ii,ij,jl1) - zdaice(ii,ij,jl)
-            a_i(ii,ij,jl2) = a_i(ii,ij,jl2) + zdaice(ii,ij,jl)
-
-            !--------------
-            ! Ice volumes
-            !--------------
-            v_i(ii,ij,jl1) = v_i(ii,ij,jl1) - zdvice(ii,ij,jl) 
-            v_i(ii,ij,jl2) = v_i(ii,ij,jl2) + zdvice(ii,ij,jl)
-
-            !--------------
-            ! Snow volumes
-            !--------------
-            zdvsnow        = v_s(ii,ij,jl1) * zworka(ii,ij)
-            v_s(ii,ij,jl1) = v_s(ii,ij,jl1) - zdvsnow
-            v_s(ii,ij,jl2) = v_s(ii,ij,jl2) + zdvsnow 
-
-            !--------------------
-            ! Snow heat content  
-            !--------------------
-            zdesnow            = e_s(ii,ij,1,jl1) * zworka(ii,ij)
-            e_s(ii,ij,1,jl1)   = e_s(ii,ij,1,jl1) - zdesnow
-            e_s(ii,ij,1,jl2)   = e_s(ii,ij,1,jl2) + zdesnow
-
-            !--------------
-            ! Ice age 
-            !--------------
-            zdo_aice           = oa_i(ii,ij,jl1) * zdaice(ii,ij,jl)
-            oa_i(ii,ij,jl1)    = oa_i(ii,ij,jl1) - zdo_aice
-            oa_i(ii,ij,jl2)    = oa_i(ii,ij,jl2) + zdo_aice
-
-            !--------------
-            ! Ice salinity
-            !--------------
-            zdsm_vice          = smv_i(ii,ij,jl1) * zworka(ii,ij)
-            smv_i(ii,ij,jl1)   = smv_i(ii,ij,jl1) - zdsm_vice
-            smv_i(ii,ij,jl2)   = smv_i(ii,ij,jl2) + zdsm_vice
-
-            !---------------------
-            ! Surface temperature
-            !---------------------
-            zdaTsf             = t_su(ii,ij,jl1) * zdaice(ii,ij,jl)
-            zaTsfn(ii,ij,jl1)  = zaTsfn(ii,ij,jl1) - zdaTsf
-            zaTsfn(ii,ij,jl2)  = zaTsfn(ii,ij,jl2) + zdaTsf 
-
-         END DO
-
-         !------------------
-         ! Ice heat content
-         !------------------
-
-         DO jk = 1, nlay_i
-            DO ji = 1, nbrem
-               ii = nind_i(ji)
-               ij = nind_j(ji)
-
-               jl1 = zdonor(ii,ij,jl)
-               IF (jl1 == jl) THEN
-                  jl2 = jl+1
-               ELSE             ! n1 = n+1
-                  jl2 = jl 
-               ENDIF
-
-               zdeice = e_i(ii,ij,jk,jl1) * zworka(ii,ij)
-               e_i(ii,ij,jk,jl1) =  e_i(ii,ij,jk,jl1) - zdeice
-               e_i(ii,ij,jk,jl2) =  e_i(ii,ij,jk,jl2) + zdeice 
-            END DO
-         END DO
-
-      END DO                   ! boundaries, 1 to ncat-1
-
-      !-----------------------------------------------------------------
-      ! Update ice thickness and temperature
-      !-----------------------------------------------------------------
-
-      DO jl = klbnd, kubnd
-         DO jj = 1, jpj
-            DO ji = 1, jpi 
-               IF ( a_i(ji,jj,jl) > epsi10 ) THEN 
-                  ht_i(ji,jj,jl)  =  v_i   (ji,jj,jl) / a_i(ji,jj,jl) 
-                  t_su(ji,jj,jl)  =  zaTsfn(ji,jj,jl) / a_i(ji,jj,jl) 
-               ELSE
-                  ht_i(ji,jj,jl)  = 0._wp
-                  t_su(ji,jj,jl)  = rt0
-               ENDIF
-            END DO
-         END DO
-      END DO
-      !
-      CALL wrk_dealloc( jpi,jpj,jpl, zaTsfn )
-      CALL wrk_dealloc( jpi,jpj, zworka )
-      CALL wrk_dealloc( (jpi+1)*(jpj+1), nind_i, nind_j )
-      !
-   END SUBROUTINE lim_itd_shiftice
-   
-
-   SUBROUTINE lim_itd_th_reb( klbnd, kubnd )
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_th_reb ***
-      !!
-      !! ** Purpose : rebin - rebins thicknesses into defined categories
-      !!
-      !! ** Method  :
-      !!------------------------------------------------------------------
-      INTEGER , INTENT (in) ::   klbnd   ! Start thickness category index point
-      INTEGER , INTENT (in) ::   kubnd   ! End point on which the  the computation is applied
-      !
-      INTEGER ::   ji,jj, jl   ! dummy loop indices
-      INTEGER ::   zshiftflag          ! = .true. if ice must be shifted
-      CHARACTER (len = 15) :: fieldid
-
-      INTEGER , POINTER, DIMENSION(:,:,:) ::   zdonor           ! donor category index
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zdaice, zdvice   ! ice area and volume transferred
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   vt_i_init, vt_i_final   ! ice volume summed over categories
-      REAL(wp), POINTER, DIMENSION(:,:) ::   vt_s_init, vt_s_final   ! snow volume summed over categories
-      !!------------------------------------------------------------------
-      
-      CALL wrk_alloc( jpi,jpj,jpl, zdonor )   ! interger
-      CALL wrk_alloc( jpi,jpj,jpl, zdaice, zdvice )
-      CALL wrk_alloc( jpi,jpj, vt_i_init, vt_i_final, vt_s_init, vt_s_final )
-      !     
-      IF( con_i ) THEN                 ! conservation check
-         CALL lim_column_sum (jpl,   v_i, vt_i_init)
-         CALL lim_column_sum (jpl,   v_s, vt_s_init)
-      ENDIF
-
-      !
-      !------------------------------------------------------------------------------
-      ! 1) Compute ice thickness.
-      !------------------------------------------------------------------------------
-      DO jl = klbnd, kubnd
-         DO jj = 1, jpj
-            DO ji = 1, jpi 
-               rswitch = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi10 ) )
-               ht_i(ji,jj,jl) = v_i (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi10 ) * rswitch
-            END DO
-         END DO
-      END DO
-
-      !------------------------------------------------------------------------------
-      ! 2) If a category thickness is not in bounds, shift the
-      ! entire area, volume, and energy to the neighboring category
-      !------------------------------------------------------------------------------
-      !-------------------------
-      ! Initialize shift arrays
-      !-------------------------
-      DO jl = klbnd, kubnd
-         zdonor(:,:,jl) = 0
-         zdaice(:,:,jl) = 0._wp
-         zdvice(:,:,jl) = 0._wp
-      END DO
-
-      !-------------------------
-      ! Move thin categories up
-      !-------------------------
-
-      DO jl = klbnd, kubnd - 1  ! loop over category boundaries
-
-         !---------------------------------------
-         ! identify thicknesses that are too big
-         !---------------------------------------
-         zshiftflag = 0
-
-         DO jj = 1, jpj 
-            DO ji = 1, jpi 
-               IF( a_i(ji,jj,jl) > epsi10 .AND. ht_i(ji,jj,jl) > hi_max(jl) ) THEN 
-                  zshiftflag        = 1
-                  zdonor(ji,jj,jl)  = jl 
-                  ! begin TECLIM change
-                  !zdaice(ji,jj,jl)  = a_i(ji,jj,jl) * 0.5_wp
-                  !zdvice(ji,jj,jl)  = v_i(ji,jj,jl)-zdaice(ji,jj,jl)*(hi_max(jl)+hi_max(jl-1)) * 0.5_wp
-                  ! end TECLIM change 
-                  ! clem: how much of a_i you send in cat sup is somewhat arbitrary
-                  zdaice(ji,jj,jl)  = a_i(ji,jj,jl) * ( ht_i(ji,jj,jl) - hi_max(jl) + epsi20 ) / ht_i(ji,jj,jl)  
-                  zdvice(ji,jj,jl)  = v_i(ji,jj,jl) - ( a_i(ji,jj,jl) - zdaice(ji,jj,jl) ) * ( hi_max(jl) - epsi20 )
-               ENDIF
-            END DO
-         END DO
-         IF(lk_mpp)   CALL mpp_max( zshiftflag )
-
-         IF( zshiftflag == 1 ) THEN            ! Shift ice between categories
-            CALL lim_itd_shiftice( klbnd, kubnd, zdonor, zdaice, zdvice )
-            ! Reset shift parameters
-            zdonor(:,:,jl) = 0
-            zdaice(:,:,jl) = 0._wp
-            zdvice(:,:,jl) = 0._wp
-         ENDIF
-         !
-      END DO
-
-      !----------------------------
-      ! Move thick categories down
-      !----------------------------
-
-      DO jl = kubnd - 1, 1, -1       ! loop over category boundaries
-
-         !-----------------------------------------
-         ! Identify thicknesses that are too small
-         !-----------------------------------------
-         zshiftflag = 0
-
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( a_i(ji,jj,jl+1) > epsi10 .AND. ht_i(ji,jj,jl+1) <= hi_max(jl) ) THEN
-                  !
-                  zshiftflag = 1
-                  zdonor(ji,jj,jl) = jl + 1
-                  zdaice(ji,jj,jl) = a_i(ji,jj,jl+1) 
-                  zdvice(ji,jj,jl) = v_i(ji,jj,jl+1)
-               ENDIF
-            END DO
-         END DO
-
-         IF(lk_mpp)   CALL mpp_max( zshiftflag )
-         
-         IF( zshiftflag == 1 ) THEN            ! Shift ice between categories
-            CALL lim_itd_shiftice( klbnd, kubnd, zdonor, zdaice, zdvice )
-            ! Reset shift parameters
-            zdonor(:,:,jl) = 0
-            zdaice(:,:,jl) = 0._wp
-            zdvice(:,:,jl) = 0._wp
-         ENDIF
-
-      END DO
-
-      !------------------------------------------------------------------------------
-      ! 3) Conservation check
-      !------------------------------------------------------------------------------
-
-      IF( con_i ) THEN
-         CALL lim_column_sum (jpl,   v_i, vt_i_final)
-         fieldid = ' v_i : limitd_reb '
-         CALL lim_cons_check (vt_i_init, vt_i_final, 1.0e-6, fieldid) 
-
-         CALL lim_column_sum (jpl,   v_s, vt_s_final)
-         fieldid = ' v_s : limitd_reb '
-         CALL lim_cons_check (vt_s_init, vt_s_final, 1.0e-6, fieldid) 
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi,jpj,jpl, zdonor )
-      CALL wrk_dealloc( jpi,jpj,jpl, zdaice, zdvice )
-      CALL wrk_dealloc( jpi,jpj, vt_i_init, vt_i_final, vt_s_init, vt_s_final )
-
-   END SUBROUTINE lim_itd_th_reb
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option            Dummy module         NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_itd_th_rem
-   END SUBROUTINE lim_itd_th_rem
-   SUBROUTINE lim_itd_fitline
-   END SUBROUTINE lim_itd_fitline
-   SUBROUTINE lim_itd_shiftice
-   END SUBROUTINE lim_itd_shiftice
-   SUBROUTINE lim_itd_th_reb
-   END SUBROUTINE lim_itd_th_reb
-#endif
-   !!======================================================================
-END MODULE limitd_th
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limrhg.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limrhg.F90	(revision 9018)
+++ 	(revision )
@@ -1,719 +1,0 @@
-MODULE limrhg
-   !!======================================================================
-   !!                     ***  MODULE  limrhg  ***
-   !!   Ice rheology : sea ice rheology
-   !!======================================================================
-   !! History :   -   !  2007-03  (M.A. Morales Maqueda, S. Bouillon) Original code
-   !!            3.0  !  2008-03  (M. Vancoppenolle) LIM3
-   !!             -   !  2008-11  (M. Vancoppenolle, S. Bouillon, Y. Aksenov) add surface tilt in ice rheolohy 
-   !!            3.3  !  2009-05  (G.Garric) addition of the lim2_evp cas
-   !!            3.4  !  2011-01  (A. Porter)  dynamical allocation 
-   !!            3.5  !  2012-08  (R. Benshila)  AGRIF
-   !!            3.6  !  2016-06  (C. Rousset) Rewriting + landfast ice + possibility to use mEVP (Bouillon 2013)
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_rhg       : computes ice velocities
-   !!----------------------------------------------------------------------
-   USE phycst         ! Physical constant
-   USE oce     , ONLY :  snwice_mass, snwice_mass_b
-   USE par_oce        ! Ocean parameters
-   USE dom_oce        ! Ocean domain
-   USE sbc_oce        ! Surface boundary condition: ocean fields
-   USE sbc_ice        ! Surface boundary condition: ice fields
-   USE ice            ! ice variables
-   USE limitd_me      ! ice strength
-   USE lbclnk         ! Lateral Boundary Condition / MPP link
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
-   USE in_out_manager ! I/O manager
-   USE prtctl         ! Print control
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-#if defined key_agrif
-   USE agrif_lim3_interp
-#endif
-   USE bdy_oce   , ONLY: ln_bdy 
-   USE bdyice_lim 
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_rhg        ! routine called by lim_dyn
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_rhg
-      !!-------------------------------------------------------------------
-      !!                 ***  SUBROUTINE lim_rhg  ***
-      !!                          EVP-C-grid
-      !!
-      !! ** purpose : determines sea ice drift from wind stress, ice-ocean
-      !!  stress and sea-surface slope. Ice-ice interaction is described by 
-      !!  a non-linear elasto-viscous-plastic (EVP) law including shear 
-      !!  strength and a bulk rheology (Hunke and Dukowicz, 2002).	
-      !!
-      !!  The points in the C-grid look like this, dear reader
-      !!
-      !!                              (ji,jj)
-      !!                                 |
-      !!                                 |
-      !!                      (ji-1,jj)  |  (ji,jj)
-      !!                             ---------   
-      !!                            |         |
-      !!                            | (ji,jj) |------(ji,jj)
-      !!                            |         |
-      !!                             ---------   
-      !!                     (ji-1,jj-1)     (ji,jj-1)
-      !!
-      !! ** Inputs  : - wind forcing (stress), oceanic currents
-      !!                ice total volume (vt_i) per unit area
-      !!                snow total volume (vt_s) per unit area
-      !!
-      !! ** Action  : - compute u_ice, v_ice : the components of the 
-      !!                sea-ice velocity vector
-      !!              - compute delta_i, shear_i, divu_i, which are inputs
-      !!                of the ice thickness distribution
-      !!
-      !! ** Steps   : 1) Compute ice snow mass, ice strength 
-      !!              2) Compute wind, oceanic stresses, mass terms and
-      !!                 coriolis terms of the momentum equation
-      !!              3) Solve the momentum equation (iterative procedure)
-      !!              4) Prevent high velocities if the ice is thin
-      !!              5) Recompute invariants of the strain rate tensor
-      !!                 which are inputs of the ITD, store stress
-      !!                 for the next time step
-      !!              6) Control prints of residual (convergence)
-      !!                 and charge ellipse.
-      !!                 The user should make sure that the parameters
-      !!                 nn_nevp, elastic time scale and rn_creepl maintain stress state
-      !!                 on the charge ellipse for plastic flow
-      !!                 e.g. in the Canadian Archipelago
-      !!
-      !! ** Notes   : There is the possibility to use mEVP from Bouillon 2013
-      !!              (by uncommenting some lines in part 3 and changing alpha and beta parameters)
-      !!              but this solution appears very unstable (see Kimmritz et al 2016)
-      !!
-      !! References : Hunke and Dukowicz, JPO97
-      !!              Bouillon et al., Ocean Modelling 2009
-      !!              Bouillon et al., Ocean Modelling 2013
-      !!-------------------------------------------------------------------
-      INTEGER ::   ji, jj       ! dummy loop indices
-      INTEGER ::   jter         ! local integers
-      CHARACTER (len=50) ::   charout
-
-      REAL(wp) ::   zrhoco                                                   ! rau0 * rn_cio
-      REAL(wp) ::   zdtevp, z1_dtevp                                         ! time step for subcycling
-      REAL(wp) ::   ecc2, z1_ecc2                                            ! square of yield ellipse eccenticity
-      REAL(wp) ::   zbeta, zalph1, z1_alph1, zalph2, z1_alph2                ! alpha and beta from Bouillon 2009 and 2013
-      REAL(wp) ::   zm1, zm2, zm3, zmassU, zmassV                            ! ice/snow mass
-      REAL(wp) ::   zdelta, zp_delf, zds2, zdt, zdt2, zdiv, zdiv2            ! temporary scalars
-      REAL(wp) ::   zTauO, zTauB, zTauE, zCor, zvel                          ! temporary scalars
-
-      REAL(wp) ::   zsig1, zsig2                                             ! internal ice stress
-      REAL(wp) ::   zresm                                                    ! Maximal error on ice velocity
-      REAL(wp) ::   zintb, zintn                                             ! dummy argument
-      
-      REAL(wp), POINTER, DIMENSION(:,:) ::   z1_e1t0, z1_e2t0                ! scale factors
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zp_delt                         ! P/delta at T points
-      !
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zaU   , zaV                     ! ice fraction on U/V points
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zmU_t, zmV_t                    ! ice/snow mass/dt on U/V points
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zmf                             ! coriolis parameter at T points
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zTauU_ia , ztauV_ia             ! ice-atm. stress at U-V points
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zspgU , zspgV                   ! surface pressure gradient at U/V points
-      REAL(wp), POINTER, DIMENSION(:,:) ::   v_oceU, u_oceV, v_iceU, u_iceV  ! ocean/ice u/v component on V/U points                           
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zfU   , zfV                     ! internal stresses
-      
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zds                             ! shear
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zs1, zs2, zs12                  ! stress tensor components
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zu_ice, zv_ice, zresr           ! check convergence
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zpice                           ! array used for the calculation of ice surface slope:
-                                                                             !   ocean surface (ssh_m) if ice is not embedded
-                                                                             !   ice top surface if ice is embedded   
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zswitchU, zswitchV              ! dummy arrays
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zmaskU, zmaskV                  ! mask for ice presence
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zfmask, zwf                     ! mask at F points for the ice
-
-      REAL(wp), PARAMETER               ::   zepsi  = 1.0e-20_wp             ! tolerance parameter
-      REAL(wp), PARAMETER               ::   zmmin  = 1._wp                  ! ice mass (kg/m2) below which ice velocity equals ocean velocity
-      REAL(wp), PARAMETER               ::   zshlat = 2._wp                  ! boundary condition for sea-ice velocity (2=no slip ; 0=free slip)
-      !!-------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi,jpj, z1_e1t0, z1_e2t0, zp_delt )
-      CALL wrk_alloc( jpi,jpj, zaU, zaV, zmU_t, zmV_t, zmf, zTauU_ia, ztauV_ia )
-      CALL wrk_alloc( jpi,jpj, zspgU, zspgV, v_oceU, u_oceV, v_iceU, u_iceV, zfU, zfV )
-      CALL wrk_alloc( jpi,jpj, zds, zs1, zs2, zs12, zu_ice, zv_ice, zresr, zpice )
-      CALL wrk_alloc( jpi,jpj, zswitchU, zswitchV, zmaskU, zmaskV, zfmask, zwf )
-
-#if defined key_agrif 
-      CALL agrif_interp_lim3( 'U', 0, nn_nevp )   ! First interpolation of coarse values
-      CALL agrif_interp_lim3( 'V', 0, nn_nevp )
-#endif
-      !
-      !------------------------------------------------------------------------------!
-      ! 0) mask at F points for the ice
-      !------------------------------------------------------------------------------!
-      ! ocean/land mask
-      DO jj = 1, jpjm1
-         DO ji = 1, jpim1      ! NO vector opt.
-            zfmask(ji,jj) = tmask(ji,jj,1) * tmask(ji+1,jj,1) * tmask(ji,jj+1,1) * tmask(ji+1,jj+1,1)
-         END DO
-      END DO
-      CALL lbc_lnk( zfmask, 'F', 1._wp )
-
-      ! Lateral boundary conditions on velocity (modify zfmask)
-      zwf(:,:) = zfmask(:,:)
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1   ! vector opt.
-            IF( zfmask(ji,jj) == 0._wp ) THEN
-               zfmask(ji,jj) = zshlat * MIN( 1._wp , MAX( zwf(ji+1,jj), zwf(ji,jj+1), zwf(ji-1,jj), zwf(ji,jj-1) ) )
-            ENDIF
-         END DO
-      END DO
-      DO jj = 2, jpjm1
-         IF( zfmask(1,jj) == 0._wp ) THEN
-            zfmask(1  ,jj) = zshlat * MIN( 1._wp , MAX( zwf(2,jj), zwf(1,jj+1), zwf(1,jj-1) ) )
-         ENDIF
-         IF( zfmask(jpi,jj) == 0._wp ) THEN
-            zfmask(jpi,jj) = zshlat * MIN( 1._wp , MAX( zwf(jpi,jj+1), zwf(jpim1,jj), zwf(jpi,jj-1) ) )
-         ENDIF
-      END DO
-      DO ji = 2, jpim1
-         IF( zfmask(ji,1) == 0._wp ) THEN
-            zfmask(ji,1  ) = zshlat * MIN( 1._wp , MAX( zwf(ji+1,1), zwf(ji,2), zwf(ji-1,1) ) )
-         ENDIF
-         IF( zfmask(ji,jpj) == 0._wp ) THEN
-            zfmask(ji,jpj) = zshlat * MIN( 1._wp , MAX( zwf(ji+1,jpj), zwf(ji-1,jpj), zwf(ji,jpjm1) ) )
-         ENDIF
-      END DO
-      CALL lbc_lnk( zfmask, 'F', 1._wp )
-
-      !------------------------------------------------------------------------------!
-      ! 1) define some variables and initialize arrays
-      !------------------------------------------------------------------------------!
-      zrhoco = rau0 * rn_cio 
-
-      ! ecc2: square of yield ellipse eccenticrity
-      ecc2    = rn_ecc * rn_ecc
-      z1_ecc2 = 1._wp / ecc2
-
-      ! Time step for subcycling
-      zdtevp   = rdt_ice / REAL( nn_nevp )
-      z1_dtevp = 1._wp / zdtevp
-
-      ! alpha parameters (Bouillon 2009)
-      zalph1 = ( 2._wp * rn_relast * rdt_ice ) * z1_dtevp
-      zalph2 = zalph1 * z1_ecc2
-
-      ! alpha and beta parameters (Bouillon 2013)
-      !!zalph1 = 40.
-      !!zalph2 = 40.
-      !!zbeta  = 3000.
-      !!zbeta = REAL( nn_nevp )   ! close to classical EVP of Hunke (2001)
-
-      z1_alph1 = 1._wp / ( zalph1 + 1._wp )
-      z1_alph2 = 1._wp / ( zalph2 + 1._wp )
-
-      ! Initialise stress tensor 
-      zs1 (:,:) = stress1_i (:,:) 
-      zs2 (:,:) = stress2_i (:,:)
-      zs12(:,:) = stress12_i(:,:)
-
-      ! Ice strength
-      CALL lim_itd_me_icestrength( nn_icestr )
-
-      ! scale factors
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1
-            z1_e1t0(ji,jj) = 1._wp / ( e1t(ji+1,jj  ) + e1t(ji,jj  ) )
-            z1_e2t0(ji,jj) = 1._wp / ( e2t(ji  ,jj+1) + e2t(ji,jj  ) )
-         END DO
-      END DO
-            
-      !
-      !------------------------------------------------------------------------------!
-      ! 2) Wind / ocean stress, mass terms, coriolis terms
-      !------------------------------------------------------------------------------!
-
-      IF( nn_ice_embd == 2 ) THEN             !== embedded sea ice: compute representative ice top surface ==!
-         !                                            
-         ! average interpolation coeff as used in dynspg = (1/nn_fsbc) * {SUM[n/nn_fsbc], n=0,nn_fsbc-1}
-         !                                               = (1/nn_fsbc)^2 * {SUM[n], n=0,nn_fsbc-1}
-         zintn = REAL( nn_fsbc - 1 ) / REAL( nn_fsbc ) * 0.5_wp     
-         !
-         ! average interpolation coeff as used in dynspg = (1/nn_fsbc) * {SUM[1-n/nn_fsbc], n=0,nn_fsbc-1}
-         !                                               = (1/nn_fsbc)^2 * (nn_fsbc^2 - {SUM[n], n=0,nn_fsbc-1})
-         zintb = REAL( nn_fsbc + 1 ) / REAL( nn_fsbc ) * 0.5_wp
-         !
-         zpice(:,:) = ssh_m(:,:) + ( zintn * snwice_mass(:,:) + zintb * snwice_mass_b(:,:) ) * r1_rau0
-         !
-      ELSE                                    !== non-embedded sea ice: use ocean surface for slope calculation ==!
-         zpice(:,:) = ssh_m(:,:)
-      ENDIF
-
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1
-
-            ! ice fraction at U-V points
-            zaU(ji,jj) = 0.5_wp * ( at_i(ji,jj) * e1e2t(ji,jj) + at_i(ji+1,jj) * e1e2t(ji+1,jj) ) * r1_e1e2u(ji,jj) * umask(ji,jj,1)
-            zaV(ji,jj) = 0.5_wp * ( at_i(ji,jj) * e1e2t(ji,jj) + at_i(ji,jj+1) * e1e2t(ji,jj+1) ) * r1_e1e2v(ji,jj) * vmask(ji,jj,1)
-
-            ! Ice/snow mass at U-V points
-            zm1 = ( rhosn * vt_s(ji  ,jj  ) + rhoic * vt_i(ji  ,jj  ) )
-            zm2 = ( rhosn * vt_s(ji+1,jj  ) + rhoic * vt_i(ji+1,jj  ) )
-            zm3 = ( rhosn * vt_s(ji  ,jj+1) + rhoic * vt_i(ji  ,jj+1) )
-            zmassU = 0.5_wp * ( zm1 * e1e2t(ji,jj) + zm2 * e1e2t(ji+1,jj) ) * r1_e1e2u(ji,jj) * umask(ji,jj,1)
-            zmassV = 0.5_wp * ( zm1 * e1e2t(ji,jj) + zm3 * e1e2t(ji,jj+1) ) * r1_e1e2v(ji,jj) * vmask(ji,jj,1)
-
-            ! Ocean currents at U-V points
-            v_oceU(ji,jj)   = 0.5_wp * ( ( v_oce(ji  ,jj) + v_oce(ji  ,jj-1) ) * e1t(ji+1,jj)    &
-               &                       + ( v_oce(ji+1,jj) + v_oce(ji+1,jj-1) ) * e1t(ji  ,jj) ) * z1_e1t0(ji,jj) * umask(ji,jj,1)
-            
-            u_oceV(ji,jj)   = 0.5_wp * ( ( u_oce(ji,jj  ) + u_oce(ji-1,jj  ) ) * e2t(ji,jj+1)    &
-               &                       + ( u_oce(ji,jj+1) + u_oce(ji-1,jj+1) ) * e2t(ji,jj  ) ) * z1_e2t0(ji,jj) * vmask(ji,jj,1)
-
-            ! Coriolis at T points (m*f)
-            zmf(ji,jj)      = zm1 * ff_t(ji,jj)
-
-            ! m/dt
-            zmU_t(ji,jj)    = zmassU * z1_dtevp
-            zmV_t(ji,jj)    = zmassV * z1_dtevp
-
-            ! Drag ice-atm.
-            zTauU_ia(ji,jj) = zaU(ji,jj) * utau_ice(ji,jj)
-            zTauV_ia(ji,jj) = zaV(ji,jj) * vtau_ice(ji,jj)
-
-            ! Surface pressure gradient (- m*g*GRAD(ssh)) at U-V points
-            zspgU(ji,jj)    = - zmassU * grav * ( zpice(ji+1,jj) - zpice(ji,jj) ) * r1_e1u(ji,jj)
-            zspgV(ji,jj)    = - zmassV * grav * ( zpice(ji,jj+1) - zpice(ji,jj) ) * r1_e2v(ji,jj)
-
-            ! masks
-            zmaskU(ji,jj) = 1._wp - MAX( 0._wp, SIGN( 1._wp, -zmassU ) )  ! 0 if no ice
-            zmaskV(ji,jj) = 1._wp - MAX( 0._wp, SIGN( 1._wp, -zmassV ) )  ! 0 if no ice
-
-            ! switches
-            zswitchU(ji,jj) = MAX( 0._wp, SIGN( 1._wp, zmassU - zmmin ) ) ! 0 if ice mass < zmmin
-            zswitchV(ji,jj) = MAX( 0._wp, SIGN( 1._wp, zmassV - zmmin ) ) ! 0 if ice mass < zmmin
-
-         END DO
-      END DO
-      CALL lbc_lnk( zmf, 'T', 1. )
-      !
-      !------------------------------------------------------------------------------!
-      ! 3) Solution of the momentum equation, iterative procedure
-      !------------------------------------------------------------------------------!
-      !
-      !                                               !----------------------!
-      DO jter = 1 , nn_nevp                           !    loop over jter    !
-         !                                            !----------------------!        
-         IF(ln_ctl) THEN   ! Convergence test
-            DO jj = 1, jpjm1
-               zu_ice(:,jj) = u_ice(:,jj) ! velocity at previous time step
-               zv_ice(:,jj) = v_ice(:,jj)
-            END DO
-         ENDIF
-
-         ! --- divergence, tension & shear (Appendix B of Hunke & Dukowicz, 2002) --- !
-         DO jj = 1, jpjm1         ! loops start at 1 since there is no boundary condition (lbc_lnk) at i=1 and j=1 for F points
-            DO ji = 1, jpim1
-
-               ! shear at F points
-               zds(ji,jj) = ( ( u_ice(ji,jj+1) * r1_e1u(ji,jj+1) - u_ice(ji,jj) * r1_e1u(ji,jj) ) * e1f(ji,jj) * e1f(ji,jj)   &
-                  &         + ( v_ice(ji+1,jj) * r1_e2v(ji+1,jj) - v_ice(ji,jj) * r1_e2v(ji,jj) ) * e2f(ji,jj) * e2f(ji,jj)   &
-                  &         ) * r1_e1e2f(ji,jj) * zfmask(ji,jj)
-
-            END DO
-         END DO
-         CALL lbc_lnk( zds, 'F', 1. )
-
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1 ! no vector loop
-
-               ! shear**2 at T points (doc eq. A16)
-               zds2 = ( zds(ji,jj  ) * zds(ji,jj  ) * e1e2f(ji,jj  ) + zds(ji-1,jj  ) * zds(ji-1,jj  ) * e1e2f(ji-1,jj  )  &
-                  &   + zds(ji,jj-1) * zds(ji,jj-1) * e1e2f(ji,jj-1) + zds(ji-1,jj-1) * zds(ji-1,jj-1) * e1e2f(ji-1,jj-1)  &
-                  &   ) * 0.25_wp * r1_e1e2t(ji,jj)
-              
-               ! divergence at T points
-               zdiv  = ( e2u(ji,jj) * u_ice(ji,jj) - e2u(ji-1,jj) * u_ice(ji-1,jj)   &
-                  &    + e1v(ji,jj) * v_ice(ji,jj) - e1v(ji,jj-1) * v_ice(ji,jj-1)   &
-                  &    ) * r1_e1e2t(ji,jj)
-               zdiv2 = zdiv * zdiv
-               
-               ! tension at T points
-               zdt  = ( ( u_ice(ji,jj) * r1_e2u(ji,jj) - u_ice(ji-1,jj) * r1_e2u(ji-1,jj) ) * e2t(ji,jj) * e2t(ji,jj)   &
-                  &   - ( v_ice(ji,jj) * r1_e1v(ji,jj) - v_ice(ji,jj-1) * r1_e1v(ji,jj-1) ) * e1t(ji,jj) * e1t(ji,jj)   &
-                  &   ) * r1_e1e2t(ji,jj)
-               zdt2 = zdt * zdt
-               
-               ! delta at T points
-               zdelta = SQRT( zdiv2 + ( zdt2 + zds2 ) * z1_ecc2 )  
-
-               ! P/delta at T points
-               zp_delt(ji,jj) = strength(ji,jj) / ( zdelta + rn_creepl )
-               
-               ! stress at T points
-               zs1(ji,jj) = ( zs1(ji,jj) * zalph1 + zp_delt(ji,jj) * ( zdiv - zdelta ) ) * z1_alph1
-               zs2(ji,jj) = ( zs2(ji,jj) * zalph2 + zp_delt(ji,jj) * ( zdt * z1_ecc2 ) ) * z1_alph2
-             
-            END DO
-         END DO
-         CALL lbc_lnk( zp_delt, 'T', 1. )
-
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1
-
-               ! P/delta at F points
-               zp_delf = 0.25_wp * ( zp_delt(ji,jj) + zp_delt(ji+1,jj) + zp_delt(ji,jj+1) + zp_delt(ji+1,jj+1) )
-               
-               ! stress at F points
-               zs12(ji,jj)= ( zs12(ji,jj) * zalph2 + zp_delf * ( zds(ji,jj) * z1_ecc2 ) * 0.5_wp ) * z1_alph2
-
-            END DO
-         END DO
-         CALL lbc_lnk_multi( zs1, 'T', 1., zs2, 'T', 1., zs12, 'F', 1. )
- 
-
-         ! --- Ice internal stresses (Appendix C of Hunke and Dukowicz, 2002) --- !
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1               
-
-               ! U points
-               zfU(ji,jj) = 0.5_wp * ( ( zs1(ji+1,jj) - zs1(ji,jj) ) * e2u(ji,jj)                                             &
-                  &                  + ( zs2(ji+1,jj) * e2t(ji+1,jj) * e2t(ji+1,jj) - zs2(ji,jj) * e2t(ji,jj) * e2t(ji,jj)    &
-                  &                    ) * r1_e2u(ji,jj)                                                                      &
-                  &                  + ( zs12(ji,jj) * e1f(ji,jj) * e1f(ji,jj) - zs12(ji,jj-1) * e1f(ji,jj-1) * e1f(ji,jj-1)  &
-                  &                    ) * 2._wp * r1_e1u(ji,jj)                                                              &
-                  &                  ) * r1_e1e2u(ji,jj)
-
-               ! V points
-               zfV(ji,jj) = 0.5_wp * ( ( zs1(ji,jj+1) - zs1(ji,jj) ) * e1v(ji,jj)                                             &
-                  &                  - ( zs2(ji,jj+1) * e1t(ji,jj+1) * e1t(ji,jj+1) - zs2(ji,jj) * e1t(ji,jj) * e1t(ji,jj)    &
-                  &                    ) * r1_e1v(ji,jj)                                                                      &
-                  &                  + ( zs12(ji,jj) * e2f(ji,jj) * e2f(ji,jj) - zs12(ji-1,jj) * e2f(ji-1,jj) * e2f(ji-1,jj)  &
-                  &                    ) * 2._wp * r1_e2v(ji,jj)                                                              &
-                  &                  ) * r1_e1e2v(ji,jj)
-
-               ! u_ice at V point
-               u_iceV(ji,jj) = 0.5_wp * ( ( u_ice(ji,jj  ) + u_ice(ji-1,jj  ) ) * e2t(ji,jj+1)     &
-                  &                     + ( u_ice(ji,jj+1) + u_ice(ji-1,jj+1) ) * e2t(ji,jj  ) ) * z1_e2t0(ji,jj) * vmask(ji,jj,1)
-               
-               ! v_ice at U point
-               v_iceU(ji,jj) = 0.5_wp * ( ( v_ice(ji  ,jj) + v_ice(ji  ,jj-1) ) * e1t(ji+1,jj)     &
-                  &                     + ( v_ice(ji+1,jj) + v_ice(ji+1,jj-1) ) * e1t(ji  ,jj) ) * z1_e1t0(ji,jj) * umask(ji,jj,1)
-
-            END DO
-         END DO
-         !
-         ! --- Computation of ice velocity --- !
-         !  Bouillon et al. 2013 (eq 47-48) => unstable unless alpha, beta are chosen wisely and large nn_nevp
-         !  Bouillon et al. 2009 (eq 34-35) => stable
-         IF( MOD(jter,2) .EQ. 0 ) THEN ! even iterations
-            
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1
-
-                  ! tau_io/(v_oce - v_ice)
-                  zTauO = zaV(ji,jj) * zrhoco * SQRT( ( v_ice (ji,jj) - v_oce (ji,jj) ) * ( v_ice (ji,jj) - v_oce (ji,jj) )  &
-                     &                              + ( u_iceV(ji,jj) - u_oceV(ji,jj) ) * ( u_iceV(ji,jj) - u_oceV(ji,jj) ) )
-
-                  ! tau_bottom/v_ice
-                  zvel  = MAX( zepsi, SQRT( v_ice(ji,jj) * v_ice(ji,jj) + u_iceV(ji,jj) * u_iceV(ji,jj) ) )
-                  zTauB = - tau_icebfr(ji,jj) / zvel
-
-                  ! Coriolis at V-points (energy conserving formulation)
-                  zCor  = - 0.25_wp * r1_e2v(ji,jj) *  &
-                     &    ( zmf(ji,jj  ) * ( e2u(ji,jj  ) * u_ice(ji,jj  ) + e2u(ji-1,jj  ) * u_ice(ji-1,jj  ) )  &
-                     &    + zmf(ji,jj+1) * ( e2u(ji,jj+1) * u_ice(ji,jj+1) + e2u(ji-1,jj+1) * u_ice(ji-1,jj+1) ) )
-
-                  ! Sum of external forces (explicit solution) = F + tau_ia + Coriolis + spg + tau_io
-                  zTauE = zfV(ji,jj) + zTauV_ia(ji,jj) + zCor + zspgV(ji,jj) + zTauO * ( v_oce(ji,jj) - v_ice(ji,jj) )
-
-                  ! landfast switch => 0 = static friction ; 1 = sliding friction
-                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, ztauE - tau_icebfr(ji,jj) ) - SIGN( 1._wp, zTauE ) ) )
-                  
-                  ! ice velocity using implicit formulation (cf Madec doc & Bouillon 2009)
-                  v_ice(ji,jj) = ( (           rswitch   * ( zmV_t(ji,jj) * v_ice(ji,jj)                   &  ! previous velocity
-                     &                                     + zTauE + zTauO * v_ice(ji,jj)                  &  ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
-                     &                                     ) / MAX( zepsi, zmV_t(ji,jj) + zTauO - zTauB )  &  ! m/dt + tau_io(only ice part) + landfast
-                     &             + ( 1._wp - rswitch ) * v_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )  &  ! static friction => slow decrease to v=0
-                     &             ) * zswitchV(ji,jj) + v_oce(ji,jj) * ( 1._wp - zswitchV(ji,jj) )        &  ! v_ice = v_oce if mass < zmmin
-                     &           ) * zmaskV(ji,jj)
-                  ! Bouillon 2013
-                  !!v_ice(ji,jj) = ( zmV_t(ji,jj) * ( zbeta * v_ice(ji,jj) + v_ice_b(ji,jj) )                  &
-                  !!   &           + zfV(ji,jj) + zCor + zTauV_ia(ji,jj) + zTauO * v_oce(ji,jj) + zspgV(ji,jj)  &
-                  !!   &           ) / MAX( zmV_t(ji,jj) * ( zbeta + 1._wp ) + zTauO - zTauB, zepsi ) * zswitchV(ji,jj)
-
-               END DO
-            END DO
-            CALL lbc_lnk( v_ice, 'V', -1. )
-            
-#if defined key_agrif
-!!            CALL agrif_interp_lim3( 'V', jter, nn_nevp )
-            CALL agrif_interp_lim3( 'V' )
-#endif
-            IF( ln_bdy ) CALL bdy_ice_lim_dyn( 'V' )
-
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1
-                               
-                  ! tau_io/(u_oce - u_ice)
-                  zTauO = zaU(ji,jj) * zrhoco * SQRT( ( u_ice (ji,jj) - u_oce (ji,jj) ) * ( u_ice (ji,jj) - u_oce (ji,jj) )  &
-                     &                              + ( v_iceU(ji,jj) - v_oceU(ji,jj) ) * ( v_iceU(ji,jj) - v_oceU(ji,jj) ) )
-
-                  ! tau_bottom/u_ice
-                  zvel  = MAX( zepsi, SQRT( v_iceU(ji,jj) * v_iceU(ji,jj) + u_ice(ji,jj) * u_ice(ji,jj) ) )
-                  zTauB = - tau_icebfr(ji,jj) / zvel
-
-                  ! Coriolis at U-points (energy conserving formulation)
-                  zCor  =   0.25_wp * r1_e1u(ji,jj) *  &
-                     &    ( zmf(ji  ,jj) * ( e1v(ji  ,jj) * v_ice(ji  ,jj) + e1v(ji  ,jj-1) * v_ice(ji  ,jj-1) )  &
-                     &    + zmf(ji+1,jj) * ( e1v(ji+1,jj) * v_ice(ji+1,jj) + e1v(ji+1,jj-1) * v_ice(ji+1,jj-1) ) )
-                  
-                  ! Sum of external forces (explicit solution) = F + tau_ia + Coriolis + spg + tau_io
-                  zTauE = zfU(ji,jj) + zTauU_ia(ji,jj) + zCor + zspgU(ji,jj) + zTauO * ( u_oce(ji,jj) - u_ice(ji,jj) )
-
-                  ! landfast switch => 0 = static friction ; 1 = sliding friction
-                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, ztauE - tau_icebfr(ji,jj) ) - SIGN( 1._wp, zTauE ) ) )
-
-                  ! ice velocity using implicit formulation (cf Madec doc & Bouillon 2009)
-                  u_ice(ji,jj) = ( (           rswitch   * ( zmU_t(ji,jj) * u_ice(ji,jj)                   &  ! previous velocity
-                     &                                     + zTauE + zTauO * u_ice(ji,jj)                  &  ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
-                     &                                     ) / MAX( zepsi, zmU_t(ji,jj) + zTauO - zTauB )  &  ! m/dt + tau_io(only ice part) + landfast
-                     &             + ( 1._wp - rswitch ) * u_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )  &  ! static friction => slow decrease to v=0
-                     &             ) * zswitchU(ji,jj) + u_oce(ji,jj) * ( 1._wp - zswitchU(ji,jj) )        &  ! v_ice = v_oce if mass < zmmin 
-                     &           ) * zmaskU(ji,jj)
-                  ! Bouillon 2013
-                  !!u_ice(ji,jj) = ( zmU_t(ji,jj) * ( zbeta * u_ice(ji,jj) + u_ice_b(ji,jj) )                  &
-                  !!   &           + zfU(ji,jj) + zCor + zTauU_ia(ji,jj) + zTauO * u_oce(ji,jj) + zspgU(ji,jj)  &
-                  !!   &           ) / MAX( zmU_t(ji,jj) * ( zbeta + 1._wp ) + zTauO - zTauB, zepsi ) * zswitchU(ji,jj)
-               END DO
-            END DO
-            CALL lbc_lnk( u_ice, 'U', -1. )
-            
-#if defined key_agrif
-!!            CALL agrif_interp_lim3( 'U', jter, nn_nevp )
-            CALL agrif_interp_lim3( 'U' )
-#endif
-            IF( ln_bdy ) CALL bdy_ice_lim_dyn( 'U' )
-
-         ELSE ! odd iterations
-
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1
-
-                  ! tau_io/(u_oce - u_ice)
-                  zTauO = zaU(ji,jj) * zrhoco * SQRT( ( u_ice (ji,jj) - u_oce (ji,jj) ) * ( u_ice (ji,jj) - u_oce (ji,jj) )  &
-                     &                              + ( v_iceU(ji,jj) - v_oceU(ji,jj) ) * ( v_iceU(ji,jj) - v_oceU(ji,jj) ) )
-
-                  ! tau_bottom/u_ice
-                  zvel  = MAX( zepsi, SQRT( v_iceU(ji,jj) * v_iceU(ji,jj) + u_ice(ji,jj) * u_ice(ji,jj) ) )
-                  zTauB = - tau_icebfr(ji,jj) / zvel
-
-                  ! Coriolis at U-points (energy conserving formulation)
-                  zCor  =   0.25_wp * r1_e1u(ji,jj) *  &
-                     &    ( zmf(ji  ,jj) * ( e1v(ji  ,jj) * v_ice(ji  ,jj) + e1v(ji  ,jj-1) * v_ice(ji  ,jj-1) )  &
-                     &    + zmf(ji+1,jj) * ( e1v(ji+1,jj) * v_ice(ji+1,jj) + e1v(ji+1,jj-1) * v_ice(ji+1,jj-1) ) )
-
-                  ! Sum of external forces (explicit solution) = F + tau_ia + Coriolis + spg + tau_io
-                  zTauE = zfU(ji,jj) + zTauU_ia(ji,jj) + zCor + zspgU(ji,jj) + zTauO * ( u_oce(ji,jj) - u_ice(ji,jj) )
-
-                  ! landfast switch => 0 = static friction ; 1 = sliding friction
-                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, ztauE - tau_icebfr(ji,jj) ) - SIGN( 1._wp, zTauE ) ) )
-
-                  ! ice velocity using implicit formulation (cf Madec doc & Bouillon 2009)
-                  u_ice(ji,jj) = ( (           rswitch   * ( zmU_t(ji,jj) * u_ice(ji,jj)                   &  ! previous velocity
-                     &                                     + zTauE + zTauO * u_ice(ji,jj)                  &  ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
-                     &                                     ) / MAX( zepsi, zmU_t(ji,jj) + zTauO - zTauB )  &  ! m/dt + tau_io(only ice part) + landfast
-                     &             + ( 1._wp - rswitch ) * u_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )  &  ! static friction => slow decrease to v=0
-                     &             ) * zswitchU(ji,jj) + u_oce(ji,jj) * ( 1._wp - zswitchU(ji,jj) )        &  ! v_ice = v_oce if mass < zmmin
-                     &           ) * zmaskU(ji,jj)
-                  ! Bouillon 2013
-                  !!u_ice(ji,jj) = ( zmU_t(ji,jj) * ( zbeta * u_ice(ji,jj) + u_ice_b(ji,jj) )                  &
-                  !!   &           + zfU(ji,jj) + zCor + zTauU_ia(ji,jj) + zTauO * u_oce(ji,jj) + zspgU(ji,jj)  &
-                  !!   &           ) / MAX( zmU_t(ji,jj) * ( zbeta + 1._wp ) + zTauO - zTauB, zepsi ) * zswitchU(ji,jj)
-               END DO
-            END DO
-            CALL lbc_lnk( u_ice, 'U', -1. )
-            
-#if defined key_agrif
-!!            CALL agrif_interp_lim3( 'U', jter, nn_nevp )
-            CALL agrif_interp_lim3( 'U' )
-#endif
-            IF( ln_bdy ) CALL bdy_ice_lim_dyn( 'U' )
-
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1
-         
-                  ! tau_io/(v_oce - v_ice)
-                  zTauO = zaV(ji,jj) * zrhoco * SQRT( ( v_ice (ji,jj) - v_oce (ji,jj) ) * ( v_ice (ji,jj) - v_oce (ji,jj) )  &
-                     &                              + ( u_iceV(ji,jj) - u_oceV(ji,jj) ) * ( u_iceV(ji,jj) - u_oceV(ji,jj) ) )
-
-                  ! tau_bottom/v_ice
-                  zvel  = MAX( zepsi, SQRT( v_ice(ji,jj) * v_ice(ji,jj) + u_iceV(ji,jj) * u_iceV(ji,jj) ) )
-                  ztauB = - tau_icebfr(ji,jj) / zvel
-                  
-                  ! Coriolis at V-points (energy conserving formulation)
-                  zCor  = - 0.25_wp * r1_e2v(ji,jj) *  &
-                     &    ( zmf(ji,jj  ) * ( e2u(ji,jj  ) * u_ice(ji,jj  ) + e2u(ji-1,jj  ) * u_ice(ji-1,jj  ) )  &
-                     &    + zmf(ji,jj+1) * ( e2u(ji,jj+1) * u_ice(ji,jj+1) + e2u(ji-1,jj+1) * u_ice(ji-1,jj+1) ) )
-
-                  ! Sum of external forces (explicit solution) = F + tau_ia + Coriolis + spg + tau_io
-                  zTauE = zfV(ji,jj) + zTauV_ia(ji,jj) + zCor + zspgV(ji,jj) + zTauO * ( v_oce(ji,jj) - v_ice(ji,jj) )
-
-                  ! landfast switch => 0 = static friction (tau_icebfr > zTauE); 1 = sliding friction
-                  rswitch = 1._wp - MIN( 1._wp, ABS( SIGN( 1._wp, zTauE - tau_icebfr(ji,jj) ) - SIGN( 1._wp, zTauE ) ) )
-                  
-                  ! ice velocity using implicit formulation (cf Madec doc & Bouillon 2009)
-                  v_ice(ji,jj) = ( (           rswitch   * ( zmV_t(ji,jj) * v_ice(ji,jj)                   &  ! previous velocity
-                     &                                     + zTauE + zTauO * v_ice(ji,jj)                  &  ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
-                     &                                     ) / MAX( zepsi, zmV_t(ji,jj) + zTauO - zTauB )  &  ! m/dt + tau_io(only ice part) + landfast
-                     &             + ( 1._wp - rswitch ) * v_ice(ji,jj) * MAX( 0._wp, 1._wp - zdtevp * rn_lfrelax )  &  ! static friction => slow decrease to v=0
-                     &             ) * zswitchV(ji,jj) + v_oce(ji,jj) * ( 1._wp - zswitchV(ji,jj) )        &  ! v_ice = v_oce if mass < zmmin
-                     &           ) * zmaskV(ji,jj)
-                  ! Bouillon 2013
-                  !!v_ice(ji,jj) = ( zmV_t(ji,jj) * ( zbeta * v_ice(ji,jj) + v_ice_b(ji,jj) )                  &
-                  !!   &           + zfV(ji,jj) + zCor + zTauV_ia(ji,jj) + zTauO * v_oce(ji,jj) + zspgV(ji,jj)  &
-                  !!   &           ) / MAX( zmV_t(ji,jj) * ( zbeta + 1._wp ) + zTauO - zTauB, zepsi ) * zswitchV(ji,jj)
-               END DO
-            END DO
-            CALL lbc_lnk( v_ice, 'V', -1. )
-            
-#if defined key_agrif
-!!            CALL agrif_interp_lim3( 'V', jter, nn_nevp )
-            CALL agrif_interp_lim3( 'V' )
-#endif
-            IF( ln_bdy ) CALL bdy_ice_lim_dyn( 'V' )
-
-         ENDIF
-         
-         IF(ln_ctl) THEN   ! Convergence test
-            DO jj = 2 , jpjm1
-               zresr(:,jj) = MAX( ABS( u_ice(:,jj) - zu_ice(:,jj) ), ABS( v_ice(:,jj) - zv_ice(:,jj) ) )
-            END DO
-            zresm = MAXVAL( zresr( 1:jpi, 2:jpjm1 ) )
-            IF( lk_mpp )   CALL mpp_max( zresm )   ! max over the global domain
-         ENDIF
-         !
-         !                                                ! ==================== !
-      END DO                                              !  end loop over jter  !
-      !                                                   ! ==================== !
-      !
-      !------------------------------------------------------------------------------!
-      ! 4) Recompute delta, shear and div (inputs for mechanical redistribution) 
-      !------------------------------------------------------------------------------!
-      DO jj = 1, jpjm1
-         DO ji = 1, jpim1
-
-            ! shear at F points
-            zds(ji,jj) = ( ( u_ice(ji,jj+1) * r1_e1u(ji,jj+1) - u_ice(ji,jj) * r1_e1u(ji,jj) ) * e1f(ji,jj) * e1f(ji,jj)   &
-               &         + ( v_ice(ji+1,jj) * r1_e2v(ji+1,jj) - v_ice(ji,jj) * r1_e2v(ji,jj) ) * e2f(ji,jj) * e2f(ji,jj)   &
-               &         ) * r1_e1e2f(ji,jj) * zfmask(ji,jj)
-
-         END DO
-      END DO           
-      CALL lbc_lnk( zds, 'F', 1. )
-      
-      DO jj = 2, jpjm1
-         DO ji = 2, jpim1 ! no vector loop
-            
-            ! tension**2 at T points
-            zdt  = ( ( u_ice(ji,jj) * r1_e2u(ji,jj) - u_ice(ji-1,jj) * r1_e2u(ji-1,jj) ) * e2t(ji,jj) * e2t(ji,jj)   &
-               &   - ( v_ice(ji,jj) * r1_e1v(ji,jj) - v_ice(ji,jj-1) * r1_e1v(ji,jj-1) ) * e1t(ji,jj) * e1t(ji,jj)   &
-               &   ) * r1_e1e2t(ji,jj)
-            zdt2 = zdt * zdt
-            
-            ! shear**2 at T points (doc eq. A16)
-            zds2 = ( zds(ji,jj  ) * zds(ji,jj  ) * e1e2f(ji,jj  ) + zds(ji-1,jj  ) * zds(ji-1,jj  ) * e1e2f(ji-1,jj  )  &
-               &   + zds(ji,jj-1) * zds(ji,jj-1) * e1e2f(ji,jj-1) + zds(ji-1,jj-1) * zds(ji-1,jj-1) * e1e2f(ji-1,jj-1)  &
-               &   ) * 0.25_wp * r1_e1e2t(ji,jj)
-            
-            ! shear at T points
-            shear_i(ji,jj) = SQRT( zdt2 + zds2 )
-
-            ! divergence at T points
-            divu_i(ji,jj) = ( e2u(ji,jj) * u_ice(ji,jj) - e2u(ji-1,jj) * u_ice(ji-1,jj)   &
-               &            + e1v(ji,jj) * v_ice(ji,jj) - e1v(ji,jj-1) * v_ice(ji,jj-1)   &
-               &            ) * r1_e1e2t(ji,jj)
-            
-            ! delta at T points
-            zdelta         = SQRT( divu_i(ji,jj) * divu_i(ji,jj) + ( zdt2 + zds2 ) * z1_ecc2 )  
-            rswitch        = 1._wp - MAX( 0._wp, SIGN( 1._wp, -zdelta ) ) ! 0 if delta=0
-            delta_i(ji,jj) = zdelta + rn_creepl * rswitch
-
-         END DO
-      END DO
-      CALL lbc_lnk_multi( shear_i, 'T', 1., divu_i, 'T', 1., delta_i, 'T', 1. )
-      
-      ! --- Store the stress tensor for the next time step --- !
-      stress1_i (:,:) = zs1 (:,:)
-      stress2_i (:,:) = zs2 (:,:)
-      stress12_i(:,:) = zs12(:,:)
-      !
-
-      !------------------------------------------------------------------------------!
-      ! 5) Control prints of residual and charge ellipse
-      !------------------------------------------------------------------------------!
-      !
-      ! print the residual for convergence
-      IF(ln_ctl) THEN
-         WRITE(charout,FMT="('lim_rhg  : res =',D23.16, ' iter =',I4)") zresm, jter
-         CALL prt_ctl_info(charout)
-         CALL prt_ctl(tab2d_1=u_ice, clinfo1=' lim_rhg  : u_ice :', tab2d_2=v_ice, clinfo2=' v_ice :')
-      ENDIF
-
-      ! print charge ellipse
-      ! This can be desactivated once the user is sure that the stress state
-      ! lie on the charge ellipse. See Bouillon et al. 08 for more details
-      IF(ln_ctl) THEN
-         CALL prt_ctl_info('lim_rhg  : numit  :',ivar1=numit)
-         CALL prt_ctl_info('lim_rhg  : nwrite :',ivar1=nwrite)
-         CALL prt_ctl_info('lim_rhg  : MOD    :',ivar1=MOD(numit,nwrite))
-         IF( MOD(numit,nwrite) .EQ. 0 ) THEN
-            WRITE(charout,FMT="('lim_rhg  :', I4, I6, I1, I1, A10)") 1000, numit, 0, 0, ' ch. ell. '
-            CALL prt_ctl_info(charout)
-            DO jj = 2, jpjm1
-               DO ji = 2, jpim1
-                  IF (strength(ji,jj) > 1.0) THEN
-                     zsig1 = ( zs1(ji,jj) + SQRT(zs2(ji,jj)**2 + 4*zs12(ji,jj)**2 ) ) / ( 2*strength(ji,jj) ) 
-                     zsig2 = ( zs1(ji,jj) - SQRT(zs2(ji,jj)**2 + 4*zs12(ji,jj)**2 ) ) / ( 2*strength(ji,jj) )
-                     WRITE(charout,FMT="('lim_rhg  :', I4, I4, D23.16, D23.16, D23.16, D23.16, A10)")
-                     CALL prt_ctl_info(charout)
-                  ENDIF
-               END DO
-            END DO
-            WRITE(charout,FMT="('lim_rhg  :', I4, I6, I1, I1, A10)") 2000, numit, 0, 0, ' ch. ell. '
-            CALL prt_ctl_info(charout)
-         ENDIF
-      ENDIF
-      !     
-      
-      CALL wrk_dealloc( jpi,jpj, z1_e1t0, z1_e2t0, zp_delt )
-      CALL wrk_dealloc( jpi,jpj, zaU, zaV, zmU_t, zmV_t, zmf, zTauU_ia, ztauV_ia )
-      CALL wrk_dealloc( jpi,jpj, zspgU, zspgV, v_oceU, u_oceV, v_iceU, u_iceV, zfU, zfV )
-      CALL wrk_dealloc( jpi,jpj, zds, zs1, zs2, zs12, zu_ice, zv_ice, zresr, zpice )
-      CALL wrk_dealloc( jpi,jpj, zswitchU, zswitchV, zmaskU, zmaskV, zfmask, zwf )
-
-   END SUBROUTINE lim_rhg
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option          Dummy module           NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_rhg         ! Dummy routine
-      WRITE(*,*) 'lim_rhg: You should not have seen this print! error?'
-   END SUBROUTINE lim_rhg
-#endif
-
-   !!==============================================================================
-END MODULE limrhg
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limrst.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limrst.F90	(revision 9018)
+++ 	(revision )
@@ -1,546 +1,0 @@
-MODULE limrst
-   !!======================================================================
-   !!                     ***  MODULE  limrst  ***
-   !! Ice restart :  write the ice restart file
-   !!======================================================================
-   !! History:   -   ! 2005-04 (M. Vancoppenolle) Original code
-   !!           3.0  ! 2008-03 (C. Ethe) restart files in using IOM interface
-   !!           4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                   LIM sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_rst_opn   : open ice restart file
-   !!   lim_rst_write : write of the restart file 
-   !!   lim_rst_read  : read  the restart file 
-   !!----------------------------------------------------------------------
-   USE ice            ! sea-ice variables
-   USE oce     , ONLY :  snwice_mass, snwice_mass_b
-   USE dom_oce        ! ocean domain
-   USE sbc_oce        ! Surface boundary condition: ocean fields
-   USE sbc_ice        ! Surface boundary condition: ice fields
-   USE in_out_manager ! I/O manager
-   USE iom            ! I/O library
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE limctl
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_rst_opn    ! routine called by icestep.F90
-   PUBLIC   lim_rst_write  ! routine called by icestep.F90
-   PUBLIC   lim_rst_read   ! routine called by sbc_lim_init
-
-   LOGICAL, PUBLIC ::   lrst_ice         !: logical to control the ice restart write 
-   INTEGER, PUBLIC ::   numrir, numriw   !: logical unit for ice restart (read and write)
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_rst_opn( kt )
-      !!----------------------------------------------------------------------
-      !!                    ***  lim_rst_opn  ***
-      !!
-      !! ** purpose  :   output of sea-ice variable in a netcdf file
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt       ! number of iteration
-      !
-      CHARACTER(len=20)   ::   clkt     ! ocean time-step define as a character
-      CHARACTER(len=50)   ::   clname   ! ice output restart file name
-      CHARACTER(len=256)  ::   clpath   ! full path to ice output restart file 
-      !!----------------------------------------------------------------------
-      !
-      IF( kt == nit000 )   lrst_ice = .FALSE.   ! default definition
-
-      ! in order to get better performances with NetCDF format, we open and define the ice restart file 
-      ! one ice time step before writing the data (-> at nitrst - 2*nn_fsbc + 1), except if we write ice 
-      ! restart files every ice time step or if an ice restart file was writen at nitend - 2*nn_fsbc + 1
-      IF( kt == nitrst - 2*nn_fsbc + 1 .OR. nstock == nn_fsbc    &
-         &                             .OR. ( kt == nitend - nn_fsbc + 1 .AND. .NOT. lrst_ice ) ) THEN
-         IF( nitrst <= nitend .AND. nitrst > 0 ) THEN
-            ! beware of the format used to write kt (default is i8.8, that should be large enough...)
-            IF( nitrst > 99999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
-            ELSE                           ;   WRITE(clkt, '(i8.8)') nitrst
-            ENDIF
-            ! create the file
-            clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_icerst_out)
-            clpath = TRIM(cn_icerst_outdir) 
-            IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath)//'/'
-            IF(lwp) THEN
-               WRITE(numout,*)
-               SELECT CASE ( jprstlib )
-               CASE DEFAULT
-                  WRITE(numout,*) '             open ice restart NetCDF file: ',TRIM(clpath)//clname
-               END SELECT
-               IF( kt == nitrst - 2*nn_fsbc + 1 ) THEN   
-                  WRITE(numout,*)         '             kt = nitrst - 2*nn_fsbc + 1 = ', kt,' date= ', ndastp
-               ELSE   ;   WRITE(numout,*) '             kt = '                         , kt,' date= ', ndastp
-               ENDIF
-            ENDIF
-            !
-            CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kiolib = jprstlib )
-            lrst_ice = .TRUE.
-         ENDIF
-      ENDIF
-      !
-      IF( ln_limctl )   CALL lim_prt( kt, iiceprt, jiceprt, 1, ' - Beginning the time step - ' )   ! control print
-   END SUBROUTINE lim_rst_opn
-
-
-   SUBROUTINE lim_rst_write( kt )
-      !!----------------------------------------------------------------------
-      !!                    ***  lim_rst_write  ***
-      !!
-      !! ** purpose  :   output of sea-ice variable in a netcdf file
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt     ! number of iteration
-      !!
-      INTEGER ::   ji, jj, jk ,jl   ! dummy loop indices
-      INTEGER ::   iter
-      CHARACTER(len=25) ::   znam
-      CHARACTER(len=2)  ::   zchar, zchar1
-      REAL(wp), POINTER, DIMENSION(:,:) :: z2d
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, z2d )
-
-      iter = kt + nn_fsbc - 1   ! ice restarts are written at kt == nitrst - nn_fsbc + 1
-
-      IF( iter == nitrst ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'lim_rst_write : write ice restart file  kt =', kt
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'         
-      ENDIF
-
-      ! Write in numriw (if iter == nitrst)
-      ! ------------------ 
-      !                                                                        ! calendar control
-      CALL iom_rstput( iter, nitrst, numriw, 'nn_fsbc', REAL( nn_fsbc, wp ) )      ! time-step 
-      CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter   , wp ) )      ! date
-
-      ! Prognostic variables 
-      DO jl = 1, jpl 
-         WRITE(zchar,'(I2.2)') jl
-         znam = 'v_i'//'_htc'//zchar
-         z2d(:,:) = v_i(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'v_s'//'_htc'//zchar
-         z2d(:,:) = v_s(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'smv_i'//'_htc'//zchar
-         z2d(:,:) = smv_i(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'oa_i'//'_htc'//zchar
-         z2d(:,:) = oa_i(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'a_i'//'_htc'//zchar
-         z2d(:,:) = a_i(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 't_su'//'_htc'//zchar
-         z2d(:,:) = t_su(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         znam = 'tempt_sl1'//'_htc'//zchar
-         z2d(:,:) = e_s(:,:,1,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         DO jk = 1, nlay_i 
-            WRITE(zchar1,'(I2.2)') jk
-            znam = 'tempt'//'_il'//zchar1//'_htc'//zchar
-            z2d(:,:) = e_i(:,:,jk,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         END DO
-      END DO
-
-      CALL iom_rstput( iter, nitrst, numriw, 'u_ice'        , u_ice      )
-      CALL iom_rstput( iter, nitrst, numriw, 'v_ice'        , v_ice      )
-      CALL iom_rstput( iter, nitrst, numriw, 'stress1_i'    , stress1_i  )
-      CALL iom_rstput( iter, nitrst, numriw, 'stress2_i'    , stress2_i  )
-      CALL iom_rstput( iter, nitrst, numriw, 'stress12_i'   , stress12_i )
-      CALL iom_rstput( iter, nitrst, numriw, 'snwice_mass'  , snwice_mass )
-      CALL iom_rstput( iter, nitrst, numriw, 'snwice_mass_b', snwice_mass_b )
-
-      ! In case Prather scheme is used for advection, write second order moments
-      ! ------------------------------------------------------------------------
-      IF( nn_limadv == -1 ) THEN
-         
-         DO jl = 1, jpl 
-            WRITE(zchar,'(I2.2)') jl
-            znam = 'sxice'//'_htc'//zchar
-            z2d(:,:) = sxice(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'syice'//'_htc'//zchar
-            z2d(:,:) = syice(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxxice'//'_htc'//zchar
-            z2d(:,:) = sxxice(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'syyice'//'_htc'//zchar
-            z2d(:,:) = syyice(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxyice'//'_htc'//zchar
-            z2d(:,:) = sxyice(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxsn'//'_htc'//zchar
-            z2d(:,:) = sxsn(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sysn'//'_htc'//zchar
-            z2d(:,:) = sysn(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxxsn'//'_htc'//zchar
-            z2d(:,:) = sxxsn(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'syysn'//'_htc'//zchar
-            z2d(:,:) = syysn(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxysn'//'_htc'//zchar
-            z2d(:,:) = sxysn(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxa'//'_htc'//zchar
-            z2d(:,:) = sxa(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sya'//'_htc'//zchar
-            z2d(:,:) = sya(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxxa'//'_htc'//zchar
-            z2d(:,:) = sxxa(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'syya'//'_htc'//zchar
-            z2d(:,:) = syya(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxya'//'_htc'//zchar
-            z2d(:,:) = sxya(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxc0'//'_htc'//zchar
-            z2d(:,:) = sxc0(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'syc0'//'_htc'//zchar
-            z2d(:,:) = syc0(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxxc0'//'_htc'//zchar
-            z2d(:,:) = sxxc0(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'syyc0'//'_htc'//zchar
-            z2d(:,:) = syyc0(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxyc0'//'_htc'//zchar
-            z2d(:,:) = sxyc0(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxsal'//'_htc'//zchar
-            z2d(:,:) = sxsal(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sysal'//'_htc'//zchar
-            z2d(:,:) = sysal(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxxsal'//'_htc'//zchar
-            z2d(:,:) = sxxsal(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'syysal'//'_htc'//zchar
-            z2d(:,:) = syysal(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxysal'//'_htc'//zchar
-            z2d(:,:) = sxysal(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxage'//'_htc'//zchar
-            z2d(:,:) = sxage(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'syage'//'_htc'//zchar
-            z2d(:,:) = syage(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxxage'//'_htc'//zchar
-            z2d(:,:) = sxxage(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'syyage'//'_htc'//zchar
-            z2d(:,:) = syyage(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            znam = 'sxyage'//'_htc'//zchar
-            z2d(:,:) = sxyage(:,:,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-         END DO
-
-         CALL iom_rstput( iter, nitrst, numriw, 'sxopw ' ,  sxopw  )
-         CALL iom_rstput( iter, nitrst, numriw, 'syopw ' ,  syopw  )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxxopw' ,  sxxopw )
-         CALL iom_rstput( iter, nitrst, numriw, 'syyopw' ,  syyopw )
-         CALL iom_rstput( iter, nitrst, numriw, 'sxyopw' ,  sxyopw )
-         
-         DO jl = 1, jpl 
-            WRITE(zchar,'(I2.2)') jl
-            DO jk = 1, nlay_i 
-               WRITE(zchar1,'(I2.2)') jk
-               znam = 'sxe'//'_il'//zchar1//'_htc'//zchar
-               z2d(:,:) = sxe(:,:,jk,jl)
-               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-               znam = 'sye'//'_il'//zchar1//'_htc'//zchar
-               z2d(:,:) = sye(:,:,jk,jl)
-               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-               znam = 'sxxe'//'_il'//zchar1//'_htc'//zchar
-               z2d(:,:) = sxxe(:,:,jk,jl)
-               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-               znam = 'syye'//'_il'//zchar1//'_htc'//zchar
-               z2d(:,:) = syye(:,:,jk,jl)
-               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-               znam = 'sxye'//'_il'//zchar1//'_htc'//zchar
-               z2d(:,:) = sxye(:,:,jk,jl)
-               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            END DO
-         END DO
-
-      ENDIF
-      
-      ! close restart file
-      ! ------------------
-      IF( iter == nitrst ) THEN
-         CALL iom_close( numriw )
-         lrst_ice = .FALSE.
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj, z2d )
-      !
-   END SUBROUTINE lim_rst_write
-
-
-   SUBROUTINE lim_rst_read
-      !!----------------------------------------------------------------------
-      !!                    ***  lim_rst_read  ***
-      !!
-      !! ** purpose  :   read of sea-ice variable restart in a netcdf file
-      !!----------------------------------------------------------------------
-      INTEGER :: ji, jj, jk, jl
-      REAL(wp) ::   zfice, ziter
-      REAL(wp), POINTER, DIMENSION(:,:) ::   z2d
-      CHARACTER(len=25) ::   znam
-      CHARACTER(len=2)  ::   zchar, zchar1
-      INTEGER           ::   jlibalt = jprstlib
-      LOGICAL           ::   llok
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, z2d )
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_rst_read : read ice NetCDF restart file'
-         WRITE(numout,*) '~~~~~~~~~~~~~'
-      ENDIF
-
-      CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir, kiolib = jprstlib )
-
-      CALL iom_get( numrir, 'nn_fsbc', zfice )
-      CALL iom_get( numrir, 'kt_ice' , ziter )    
-      IF(lwp) WRITE(numout,*) '   read ice restart file at time step    : ', ziter
-      IF(lwp) WRITE(numout,*) '   in any case we force it to nit000 - 1 : ', nit000 - 1
-
-      !Control of date
-
-      IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 )   &
-         &     CALL ctl_stop( 'lim_rst_read ===>>>> : problem with nit000 in ice restart',  &
-         &                   '   verify the file or rerun with the value 0 for the',        &
-         &                   '   control of time parameter  nrstdt' )
-      IF( NINT(zfice) /= nn_fsbc          .AND. ABS( nrstdt ) == 1 )   &
-         &     CALL ctl_stop( 'lim_rst_read ===>>>> : problem with nn_fsbc in ice restart',  &
-         &                   '   verify the file or rerun with the value 0 for the',         &
-         &                   '   control of time parameter  nrstdt' )
-
-      ! Prognostic variables 
-      DO jl = 1, jpl 
-         WRITE(zchar,'(I2.2)') jl
-         znam = 'v_i'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         v_i(:,:,jl) = z2d(:,:)
-         znam = 'v_s'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         v_s(:,:,jl) = z2d(:,:) 
-         znam = 'smv_i'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         smv_i(:,:,jl) = z2d(:,:)
-         znam = 'oa_i'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         oa_i(:,:,jl) = z2d(:,:)
-         znam = 'a_i'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         a_i(:,:,jl) = z2d(:,:)
-         znam = 't_su'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         t_su(:,:,jl) = z2d(:,:)
-         znam = 'tempt_sl1'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         e_s(:,:,1,jl) = z2d(:,:)
-         DO jk = 1, nlay_i 
-            WRITE(zchar1,'(I2.2)') jk
-            znam = 'tempt'//'_il'//zchar1//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            e_i(:,:,jk,jl) = z2d(:,:)
-         END DO
-      END DO
-
-      CALL iom_get( numrir, jpdom_autoglo, 'u_ice'     , u_ice      )
-      CALL iom_get( numrir, jpdom_autoglo, 'v_ice'     , v_ice      )
-      CALL iom_get( numrir, jpdom_autoglo, 'stress1_i' , stress1_i  )
-      CALL iom_get( numrir, jpdom_autoglo, 'stress2_i' , stress2_i  )
-      CALL iom_get( numrir, jpdom_autoglo, 'stress12_i', stress12_i )
-      CALL iom_get( numrir, jpdom_autoglo, 'snwice_mass'  , snwice_mass )
-      CALL iom_get( numrir, jpdom_autoglo, 'snwice_mass_b', snwice_mass_b )
-
-      ! In case Prather scheme is used for advection, read second order moments
-      ! ------------------------------------------------------------------------
-      IF( nn_limadv == -1 ) THEN
-
-         DO jl = 1, jpl 
-            WRITE(zchar,'(I2.2)') jl
-            znam = 'sxice'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxice(:,:,jl) = z2d(:,:)
-            znam = 'syice'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            syice(:,:,jl) = z2d(:,:)
-            znam = 'sxxice'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxxice(:,:,jl) = z2d(:,:)
-            znam = 'syyice'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            syyice(:,:,jl) = z2d(:,:)
-            znam = 'sxyice'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxyice(:,:,jl) = z2d(:,:)
-            znam = 'sxsn'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxsn(:,:,jl) = z2d(:,:)
-            znam = 'sysn'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sysn(:,:,jl) = z2d(:,:)
-            znam = 'sxxsn'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxxsn(:,:,jl) = z2d(:,:)
-            znam = 'syysn'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            syysn(:,:,jl) = z2d(:,:)
-            znam = 'sxysn'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxysn(:,:,jl) = z2d(:,:)
-            znam = 'sxa'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxa(:,:,jl) = z2d(:,:)
-            znam = 'sya'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sya(:,:,jl) = z2d(:,:)
-            znam = 'sxxa'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxxa(:,:,jl) = z2d(:,:)
-            znam = 'syya'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            syya(:,:,jl) = z2d(:,:)
-            znam = 'sxya'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxya(:,:,jl) = z2d(:,:)
-            znam = 'sxc0'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxc0(:,:,jl) = z2d(:,:)
-            znam = 'syc0'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            syc0(:,:,jl) = z2d(:,:)
-            znam = 'sxxc0'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxxc0(:,:,jl) = z2d(:,:)
-            znam = 'syyc0'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            syyc0(:,:,jl) = z2d(:,:)
-            znam = 'sxyc0'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxyc0(:,:,jl) = z2d(:,:)
-            znam = 'sxsal'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxsal(:,:,jl) = z2d(:,:)
-            znam = 'sysal'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sysal(:,:,jl) = z2d(:,:)
-            znam = 'sxxsal'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxxsal(:,:,jl) = z2d(:,:)
-            znam = 'syysal'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            syysal(:,:,jl) = z2d(:,:)
-            znam = 'sxysal'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxysal(:,:,jl) = z2d(:,:)
-            znam = 'sxage'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxage(:,:,jl) = z2d(:,:)
-            znam = 'syage'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            syage(:,:,jl) = z2d(:,:)
-            znam = 'sxxage'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxxage(:,:,jl) = z2d(:,:)
-            znam = 'syyage'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            syyage(:,:,jl) = z2d(:,:)
-            znam = 'sxyage'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            sxyage(:,:,jl)= z2d(:,:)
-         END DO
-
-         CALL iom_get( numrir, jpdom_autoglo, 'sxopw ' ,  sxopw  )
-         CALL iom_get( numrir, jpdom_autoglo, 'syopw ' ,  syopw  )
-         CALL iom_get( numrir, jpdom_autoglo, 'sxxopw' ,  sxxopw )
-         CALL iom_get( numrir, jpdom_autoglo, 'syyopw' ,  syyopw )
-         CALL iom_get( numrir, jpdom_autoglo, 'sxyopw' ,  sxyopw )
-
-         DO jl = 1, jpl 
-            WRITE(zchar,'(I2.2)') jl
-            DO jk = 1, nlay_i 
-               WRITE(zchar1,'(I2.2)') jk
-               znam = 'sxe'//'_il'//zchar1//'_htc'//zchar
-               CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-               sxe(:,:,jk,jl) = z2d(:,:)
-               znam = 'sye'//'_il'//zchar1//'_htc'//zchar
-               CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-               sye(:,:,jk,jl) = z2d(:,:)
-               znam = 'sxxe'//'_il'//zchar1//'_htc'//zchar
-               CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-               sxxe(:,:,jk,jl) = z2d(:,:)
-               znam = 'syye'//'_il'//zchar1//'_htc'//zchar
-               CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-               syye(:,:,jk,jl) = z2d(:,:)
-               znam = 'sxye'//'_il'//zchar1//'_htc'//zchar
-               CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-               sxye(:,:,jk,jl) = z2d(:,:)
-            END DO
-         END DO
-         !
-      END IF
-      
-      ! clem: I do not understand why the following IF is needed
-      !       I suspect something inconsistent in the main code with option nn_icesal=1
-      IF( nn_icesal == 1 ) THEN
-         DO jl = 1, jpl 
-            sm_i(:,:,jl) = rn_icesal
-            DO jk = 1, nlay_i 
-               s_i(:,:,jk,jl) = rn_icesal
-            END DO
-         END DO
-      ENDIF
-      !
-      !CALL iom_close( numrir ) !clem: closed in sbcice_lim.F90
-      !
-      CALL wrk_dealloc( jpi, jpj, z2d )
-      !
-   END SUBROUTINE lim_rst_read
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :       Empty module            NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_rst_read             ! Empty routine
-   END SUBROUTINE lim_rst_read
-   SUBROUTINE lim_rst_write            ! Empty routine
-   END SUBROUTINE lim_rst_write
-#endif
-
-   !!======================================================================
-END MODULE limrst
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limsbc.F90	(revision 9018)
+++ 	(revision )
@@ -1,394 +1,0 @@
-MODULE limsbc
-   !!======================================================================
-   !!                       ***  MODULE limsbc   ***
-   !!           computation of the flux at the sea ice/ocean interface
-   !!======================================================================
-   !! History :   -   ! 2006-07 (M. Vancoppelle)  LIM3 original code
-   !!            3.0  ! 2008-03 (C. Tallandier)  surface module
-   !!             -   ! 2008-04 (C. Tallandier)  split in 2 + new ice-ocean coupling
-   !!            3.3  ! 2010-05 (G. Madec) decrease ocean & ice reference salinities in the Baltic sea
-   !!                 !                  + simplification of the ice-ocean stress calculation
-   !!            3.4  ! 2011-02 (G. Madec) dynamical allocation
-   !!             -   ! 2012    (D. Iovino) salt flux change
-   !!             -   ! 2012-05 (C. Rousset) add penetration solar flux
-   !!            3.5  ! 2012-10 (A. Coward, G. Madec) salt fluxes ; ice+snow mass
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                    LIM 3.0 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_sbc_alloc : allocate the limsbc arrays
-   !!   lim_sbc_init  : initialisation
-   !!   lim_sbc_flx   : updates mass, heat and salt fluxes at the ocean surface
-   !!   lim_sbc_tau   : update i- and j-stresses, and its modulus at the ocean surface
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-   USE oce     , ONLY : sshn, sshb, snwice_mass, snwice_mass_b, snwice_fmass
-   USE phycst         ! physical constants
-   USE dom_oce        ! ocean domain
-   USE ice            ! LIM sea-ice variables
-   USE sbc_ice        ! Surface boundary condition: sea-ice fields
-   USE sbc_oce        ! Surface boundary condition: ocean fields
-   USE sbccpl         ! Surface boundary condition: coupled interface
-   USE albedo         ! albedo parameters
-   USE traqsr         ! add penetration of solar flux in the calculation of heat budget
-   USE domvvl         ! Variable volume
-   USE limctl         !
-   USE limcons        !
-   USE bdy_oce  , ONLY: ln_bdy
-   !
-   USE in_out_manager ! I/O manager
-   USE iom            ! xIO server
-   USE lbclnk         ! ocean lateral boundary condition - MPP exchanges
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_sbc_init   ! called by sbc_lim_init
-   PUBLIC   lim_sbc_flx    ! called by sbc_ice_lim
-   PUBLIC   lim_sbc_tau    ! called by sbc_ice_lim
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   utau_oce, vtau_oce   ! air-ocean surface i- & j-stress     [N/m2]
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tmod_io              ! modulus of the ice-ocean velocity   [m/s]
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   soce_0  , sice_0     ! cst SSS and ice salinity (levitating sea-ice) 
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION lim_sbc_alloc()
-      !!-------------------------------------------------------------------
-      !!             ***  ROUTINE lim_sbc_alloc ***
-      !!-------------------------------------------------------------------
-      ALLOCATE( soce_0(jpi,jpj) , utau_oce(jpi,jpj) ,                       &
-         &      sice_0(jpi,jpj) , vtau_oce(jpi,jpj) , tmod_io(jpi,jpj), STAT=lim_sbc_alloc)
-         !
-      IF( lk_mpp             )   CALL mpp_sum( lim_sbc_alloc )
-      IF( lim_sbc_alloc /= 0 )   CALL ctl_warn('lim_sbc_alloc: failed to allocate arrays')
-   END FUNCTION lim_sbc_alloc
-
-
-   SUBROUTINE lim_sbc_flx( kt )
-      !!-------------------------------------------------------------------
-      !!                ***  ROUTINE lim_sbc_flx ***
-      !!  
-      !! ** Purpose :   Update the surface ocean boundary condition for heat 
-      !!              salt and mass over areas where sea-ice is non-zero
-      !!         
-      !! ** Action  : - computes the heat and freshwater/salt fluxes
-      !!              at the ice-ocean interface.
-      !!              - Update the ocean sbc
-      !!     
-      !! ** Outputs : - qsr     : sea heat flux:     solar 
-      !!              - qns     : sea heat flux: non solar
-      !!              - emp     : freshwater budget: volume flux 
-      !!              - sfx     : salt flux 
-      !!              - fr_i    : ice fraction
-      !!              - tn_ice  : sea-ice surface temperature
-      !!              - alb_ice : sea-ice albedo (recomputed only for coupled mode)
-      !!
-      !! References : Goosse, H. et al. 1996, Bul. Soc. Roy. Sc. Liege, 65, 87-90.
-      !!              Tartinville et al. 2001 Ocean Modelling, 3, 95-108.
-      !!              These refs are now obsolete since everything has been revised
-      !!              The ref should be Rousset et al., 2015
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! number of iteration
-      !
-      INTEGER  ::   ji, jj, jl, jk   ! dummy loop indices
-      REAL(wp) ::   zqmass           ! Heat flux associated with mass exchange ice->ocean (W.m-2)
-      REAL(wp) ::   zqsr             ! New solar flux received by the ocean
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zalb_cs, zalb_os     ! 3D workspace
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zalb                 ! 2D workspace
-      !!---------------------------------------------------------------------
-
-      ! --- case we bypass ice thermodynamics --- !
-      IF( .NOT. ln_limthd ) THEN   ! we suppose ice is impermeable => ocean is isolated from atmosphere
-         hfx_in   (:,:)   = pfrld(:,:) * ( qns_oce(:,:) + qsr_oce(:,:) ) + qemp_oce(:,:)
-         hfx_out  (:,:)   = pfrld(:,:) *   qns_oce(:,:)                  + qemp_oce(:,:)
-         ftr_ice  (:,:,:) = 0._wp
-         emp_ice  (:,:)   = 0._wp
-         qemp_ice (:,:)   = 0._wp
-         qevap_ice(:,:,:) = 0._wp
-      ENDIF
-      
-      ! albedo output
-      CALL wrk_alloc( jpi,jpj, zalb )    
-
-      zalb(:,:) = 0._wp
-      WHERE     ( at_i_b <= epsi06 )  ;  zalb(:,:) = 0.066_wp
-      ELSEWHERE                       ;  zalb(:,:) = SUM( alb_ice * a_i_b, dim=3 ) / at_i_b
-      END WHERE
-      IF( iom_use('alb_ice' ) )  CALL iom_put( "alb_ice"  , zalb(:,:) )           ! ice albedo output
-
-      zalb(:,:) = SUM( alb_ice * a_i_b, dim=3 ) + 0.066_wp * ( 1._wp - at_i_b )      
-      IF( iom_use('albedo'  ) )  CALL iom_put( "albedo"  , zalb(:,:) )           ! ice albedo output
-
-      CALL wrk_dealloc( jpi,jpj, zalb )    
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-
-            !------------------------------------------!
-            !      heat flux at the ocean surface      !
-            !------------------------------------------!
-            ! Solar heat flux reaching the ocean = zqsr (W.m-2) 
-            !---------------------------------------------------
-            zqsr = qsr_tot(ji,jj)
-            DO jl = 1, jpl
-               zqsr = zqsr - a_i_b(ji,jj,jl) * (  qsr_ice(ji,jj,jl) - ftr_ice(ji,jj,jl) ) 
-            END DO
-
-            ! Total heat flux reaching the ocean = hfx_out (W.m-2) 
-            !---------------------------------------------------
-            zqmass         = hfx_thd(ji,jj) + hfx_dyn(ji,jj) + hfx_res(ji,jj) ! heat flux from snow is 0 (T=0 degC)
-            hfx_out(ji,jj) = hfx_out(ji,jj) + zqmass + zqsr
-
-            ! Add the residual from heat diffusion equation and sublimation (W.m-2)
-            !----------------------------------------------------------------------
-            hfx_out(ji,jj) = hfx_out(ji,jj) + hfx_err_dif(ji,jj) +   &
-               &           ( hfx_sub(ji,jj) - SUM( qevap_ice(ji,jj,:) * a_i_b(ji,jj,:) ) )
-
-            ! New qsr and qns used to compute the oceanic heat flux at the next time step
-            !----------------------------------------------------------------------------
-            qsr(ji,jj) = zqsr                                      
-            qns(ji,jj) = hfx_out(ji,jj) - zqsr              
-
-            !------------------------------------------!
-            !      mass flux at the ocean surface      !
-            !------------------------------------------!
-            !  case of realistic freshwater flux (Tartinville et al., 2001) (presently ACTIVATED)
-            !  ------------------------------------------------------------------------------------- 
-            !  The idea of this approach is that the system that we consider is the ICE-OCEAN system
-            !  Thus  FW  flux  =  External ( E-P+snow melt)
-            !       Salt flux  =  Exchanges in the ice-ocean system then converted into FW
-            !                     Associated to Ice formation AND Ice melting
-            !                     Even if i see Ice melting as a FW and SALT flux
-            !        
-            ! mass flux from ice/ocean
-            wfx_ice(ji,jj) = wfx_bog(ji,jj) + wfx_bom(ji,jj) + wfx_sum(ji,jj) + wfx_sni(ji,jj)   &
-                           + wfx_opw(ji,jj) + wfx_dyn(ji,jj) + wfx_res(ji,jj) + wfx_lam(ji,jj) 
-
-            ! mass flux at the ocean/ice interface
-            fmmflx(ji,jj) = - ( wfx_ice(ji,jj) + wfx_snw(ji,jj) + wfx_err_sub(ji,jj) )              ! F/M mass flux save at least for biogeochemical model
-            emp(ji,jj)    = emp_oce(ji,jj) - wfx_ice(ji,jj) - wfx_snw(ji,jj) - wfx_err_sub(ji,jj)   ! mass flux + F/M mass flux (always ice/ocean mass exchange)
-         END DO
-      END DO
-
-      !------------------------------------------!
-      !      salt flux at the ocean surface      !
-      !------------------------------------------!
-      sfx(:,:) = sfx_bog(:,:) + sfx_bom(:,:) + sfx_sum(:,:) + sfx_sni(:,:) + sfx_opw(:,:)   &
-         &     + sfx_res(:,:) + sfx_dyn(:,:) + sfx_bri(:,:) + sfx_sub(:,:) + sfx_lam(:,:)
-
-      !-------------------------------------------------------------!
-      !   mass of snow and ice per unit area for embedded sea-ice   !
-      !-------------------------------------------------------------!
-      IF( nn_ice_embd /= 0 ) THEN
-         ! save mass from the previous ice time step
-         snwice_mass_b(:,:) = snwice_mass(:,:)                  
-         ! new mass per unit area
-         snwice_mass  (:,:) = tmask(:,:,1) * ( rhosn * vt_s(:,:) + rhoic * vt_i(:,:)  ) 
-         ! time evolution of snow+ice mass
-         snwice_fmass (:,:) = ( snwice_mass(:,:) - snwice_mass_b(:,:) ) * r1_rdtice
-      ENDIF
-
-      !-----------------------------------------------!
-      !   Storing the transmitted variables           !
-      !-----------------------------------------------!
-      fr_i  (:,:)   = at_i(:,:)             ! Sea-ice fraction            
-      tn_ice(:,:,:) = t_su(:,:,:)           ! Ice surface temperature                      
-
-      !------------------------------------------------------------------------!
-      !    Snow/ice albedo (only if sent to coupler, useless in forced mode)   !
-      !------------------------------------------------------------------------!
-      CALL wrk_alloc( jpi,jpj,jpl,   zalb_cs, zalb_os )    
-      CALL albedo_ice( t_su, ht_i, ht_s, zalb_cs, zalb_os )  ! cloud-sky and overcast-sky ice albedos
-      alb_ice(:,:,:) = ( 1. - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:)
-      CALL wrk_dealloc( jpi,jpj,jpl,   zalb_cs, zalb_os )
-
-      ! conservation test
-      IF( ln_limdiachk .AND. .NOT. ln_bdy)  CALL lim_cons_final( 'limsbc' )
-
-      ! control prints
-      IF( ln_limctl )   CALL lim_prt( kt, iiceprt, jiceprt, 3, ' - Final state lim_sbc - ' )
-      IF( ln_ctl )      CALL lim_prt3D( 'limsbc' )
-
-   END SUBROUTINE lim_sbc_flx
-
-
-   SUBROUTINE lim_sbc_tau( kt , pu_oce, pv_oce )
-      !!-------------------------------------------------------------------
-      !!                ***  ROUTINE lim_sbc_tau ***
-      !!  
-      !! ** Purpose : Update the ocean surface stresses due to the ice
-      !!         
-      !! ** Action  : * at each ice time step (every nn_fsbc time step):
-      !!                - compute the modulus of ice-ocean relative velocity 
-      !!                  (*rho*Cd) at T-point (C-grid) or I-point (B-grid)
-      !!                      tmod_io = rhoco * | U_ice-U_oce |
-      !!                - update the modulus of stress at ocean surface
-      !!                      taum = frld * taum + (1-frld) * tmod_io * | U_ice-U_oce |
-      !!              * at each ocean time step (every kt): 
-      !!                  compute linearized ice-ocean stresses as
-      !!                      Utau = tmod_io * | U_ice - pU_oce |
-      !!                using instantaneous current ocean velocity (usually before)
-      !!
-      !!    NB: - ice-ocean rotation angle no more allowed
-      !!        - here we make an approximation: taum is only computed every ice time step
-      !!          This avoids mutiple average to pass from T -> U,V grids and next from U,V grids 
-      !!          to T grid. taum is used in TKE and GLS, which should not be too sensitive to this approximaton...
-      !!
-      !! ** Outputs : - utau, vtau   : surface ocean i- and j-stress (u- & v-pts) updated with ice-ocean fluxes
-      !!              - taum         : modulus of the surface ocean stress (T-point) updated with ice-ocean fluxes
-      !!---------------------------------------------------------------------
-      INTEGER ,                     INTENT(in) ::   kt               ! ocean time-step index
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pu_oce, pv_oce   ! surface ocean currents
-      !
-      INTEGER  ::   ji, jj   ! dummy loop indices
-      REAL(wp) ::   zat_u, zutau_ice, zu_t, zmodt   ! local scalar
-      REAL(wp) ::   zat_v, zvtau_ice, zv_t, zrhoco  !   -      -
-      !!---------------------------------------------------------------------
-      zrhoco = rau0 * rn_cio
-      !
-      IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN     !==  Ice time-step only  ==!   (i.e. surface module time-step)
-         DO jj = 2, jpjm1                             !* update the modulus of stress at ocean surface (T-point)
-            DO ji = fs_2, fs_jpim1
-               !                                               ! 2*(U_ice-U_oce) at T-point
-               zu_t = u_ice(ji,jj) + u_ice(ji-1,jj) - u_oce(ji,jj) - u_oce(ji-1,jj)   
-               zv_t = v_ice(ji,jj) + v_ice(ji,jj-1) - v_oce(ji,jj) - v_oce(ji,jj-1) 
-               !                                              ! |U_ice-U_oce|^2
-               zmodt =  0.25_wp * (  zu_t * zu_t + zv_t * zv_t  )
-               !                                               ! update the ocean stress modulus
-               taum(ji,jj) = ( 1._wp - at_i(ji,jj) ) * taum(ji,jj) + at_i(ji,jj) * zrhoco * zmodt
-               tmod_io(ji,jj) = zrhoco * SQRT( zmodt )          ! rhoco * |U_ice-U_oce| at T-point
-            END DO
-         END DO
-         CALL lbc_lnk_multi( taum, 'T', 1., tmod_io, 'T', 1. )
-         !
-         utau_oce(:,:) = utau(:,:)                    !* save the air-ocean stresses at ice time-step
-         vtau_oce(:,:) = vtau(:,:)
-         !
-      ENDIF
-      !
-      !                                      !==  every ocean time-step  ==!
-      !
-      DO jj = 2, jpjm1                                !* update the stress WITHOUT a ice-ocean rotation angle
-         DO ji = fs_2, fs_jpim1   ! Vect. Opt.
-            zat_u  = ( at_i(ji,jj) + at_i(ji+1,jj) ) * 0.5_wp   ! ice area at u and V-points
-            zat_v  = ( at_i(ji,jj) + at_i(ji,jj+1) ) * 0.5_wp
-            !                                                   ! linearized quadratic drag formulation
-            zutau_ice   = 0.5_wp * ( tmod_io(ji,jj) + tmod_io(ji+1,jj) ) * ( u_ice(ji,jj) - pu_oce(ji,jj) )
-            zvtau_ice   = 0.5_wp * ( tmod_io(ji,jj) + tmod_io(ji,jj+1) ) * ( v_ice(ji,jj) - pv_oce(ji,jj) )
-            !                                                   ! stresses at the ocean surface
-            utau(ji,jj) = ( 1._wp - zat_u ) * utau_oce(ji,jj) + zat_u * zutau_ice
-            vtau(ji,jj) = ( 1._wp - zat_v ) * vtau_oce(ji,jj) + zat_v * zvtau_ice
-         END DO
-      END DO
-      CALL lbc_lnk_multi( utau, 'U', -1., vtau, 'V', -1. )   ! lateral boundary condition
-      !
-      !  
-   END SUBROUTINE lim_sbc_tau
-
-
-   SUBROUTINE lim_sbc_init
-      !!-------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_sbc_init  ***
-      !!             
-      !! ** Purpose : Preparation of the file ice_evolu for the output of
-      !!      the temporal evolution of key variables
-      !!
-      !! ** input   : Namelist namicedia
-      !!-------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk               ! dummy loop indices
-      REAL(wp) ::   zcoefu, zcoefv, zcoeff   ! local scalar
-      !!-------------------------------------------------------------------
-      !
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'lim_sbc_init : LIM-3 sea-ice - surface boundary condition'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~   '
-
-      !                                      ! allocate lim_sbc array
-      IF( lim_sbc_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'lim_sbc_init : unable to allocate standard arrays' )
-      !
-      soce_0(:,:) = soce                     ! constant SSS and ice salinity used in levitating sea-ice case
-      sice_0(:,:) = sice
-      !                                      ! decrease ocean & ice reference salinities in the Baltic Sea area
-      WHERE( 14._wp <= glamt(:,:) .AND. glamt(:,:) <= 32._wp .AND.   &
-         &   54._wp <= gphit(:,:) .AND. gphit(:,:) <= 66._wp         ) 
-         soce_0(:,:) = 4._wp
-         sice_0(:,:) = 2._wp
-      END WHERE
-      !
-      IF( .NOT. ln_rstart ) THEN
-         !                                      ! embedded sea ice
-         IF( nn_ice_embd /= 0 ) THEN            ! mass exchanges between ice and ocean (case 1 or 2) set the snow+ice mass
-            snwice_mass  (:,:) = tmask(:,:,1) * ( rhosn * vt_s(:,:) + rhoic * vt_i(:,:)  )
-            snwice_mass_b(:,:) = snwice_mass(:,:)
-         ELSE
-            snwice_mass  (:,:) = 0._wp          ! no mass exchanges
-            snwice_mass_b(:,:) = 0._wp          ! no mass exchanges
-         ENDIF
-         IF( nn_ice_embd == 2 ) THEN            ! full embedment (case 2) deplete the initial ssh below sea-ice area
-            sshn(:,:) = sshn(:,:) - snwice_mass(:,:) * r1_rau0
-            sshb(:,:) = sshb(:,:) - snwice_mass(:,:) * r1_rau0
-
-!!gm I really don't like this stuff here...  Find a way to put that elsewhere or differently
-!!gm
-            IF( .NOT.ln_linssh ) THEN
-               DO jk = 1,jpkm1                     ! adjust initial vertical scale factors
-                  e3t_n(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshn(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
-                  e3t_b(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshb(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
-               END DO
-               e3t_a(:,:,:) = e3t_b(:,:,:)
-               ! Reconstruction of all vertical scale factors at now and before time-steps
-               ! =========================================================================
-               ! Horizontal scale factor interpolations
-               ! --------------------------------------
-               CALL dom_vvl_interpol( e3t_b(:,:,:), e3u_b(:,:,:), 'U' )
-               CALL dom_vvl_interpol( e3t_b(:,:,:), e3v_b(:,:,:), 'V' )
-               CALL dom_vvl_interpol( e3t_n(:,:,:), e3u_n(:,:,:), 'U' )
-               CALL dom_vvl_interpol( e3t_n(:,:,:), e3v_n(:,:,:), 'V' )
-               CALL dom_vvl_interpol( e3u_n(:,:,:), e3f_n(:,:,:), 'F' )
-               ! Vertical scale factor interpolations
-                 ! ------------------------------------
-               CALL dom_vvl_interpol( e3t_n(:,:,:), e3w_n (:,:,:), 'W'  )
-               CALL dom_vvl_interpol( e3u_n(:,:,:), e3uw_n(:,:,:), 'UW' )
-               CALL dom_vvl_interpol( e3v_n(:,:,:), e3vw_n(:,:,:), 'VW' )
-               CALL dom_vvl_interpol( e3u_b(:,:,:), e3uw_b(:,:,:), 'UW' )
-               CALL dom_vvl_interpol( e3v_b(:,:,:), e3vw_b(:,:,:), 'VW' )
-               ! t- and w- points depth
-               ! ----------------------
-!!gm not sure of that....
-               gdept_n(:,:,1) = 0.5_wp * e3w_n(:,:,1)
-               gdepw_n(:,:,1) = 0.0_wp
-               gde3w_n(:,:,1) = gdept_n(:,:,1) - sshn(:,:)
-               DO jk = 2, jpk
-                  gdept_n(:,:,jk) = gdept_n(:,:,jk-1) + e3w_n(:,:,jk)
-                  gdepw_n(:,:,jk) = gdepw_n(:,:,jk-1) + e3t_n(:,:,jk-1)
-                  gde3w_n(:,:,jk) = gdept_n(:,:,jk  ) - sshn   (:,:)
-               END DO
-            ENDIF
-         ENDIF
-      ENDIF ! .NOT. ln_rstart
-      !
-   END SUBROUTINE lim_sbc_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :        Dummy module       NO LIM 3.0 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_sbc           ! Dummy routine
-   END SUBROUTINE lim_sbc
-#endif 
-
-   !!======================================================================
-END MODULE limsbc
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limtab.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limtab.F90	(revision 9018)
+++ 	(revision )
@@ -1,71 +1,0 @@
-MODULE limtab
-   !!======================================================================
-   !!                       ***  MODULE limtab   ***
-   !!   LIM ice model : transform 1D (2D) array to a 2D (1D) table
-   !!======================================================================
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   tab_2d_1d  : 2-D <==> 1-D
-   !!   tab_1d_2d  : 1-D <==> 2-D
-   !!----------------------------------------------------------------------
-   USE par_kind
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   tab_2d_1d   ! called by limthd
-   PUBLIC   tab_1d_2d   ! called by limthd
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE tab_2d_1d( ndim1d, tab1d, tab2d, ndim2d_x, ndim2d_y, tab_ind )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE tab_2d_1d  ***
-      !!----------------------------------------------------------------------
-      INTEGER                               , INTENT(in   ) ::   ndim1d, ndim2d_x, ndim2d_y   ! 1d & 2D sizes
-      REAL(wp), DIMENSION(ndim2d_x,ndim2d_y), INTENT(in   ) ::   tab2d                        ! input 2D field
-      INTEGER , DIMENSION(ndim1d)           , INTENT(in   ) ::   tab_ind                      ! input index
-      REAL(wp), DIMENSION(ndim1d)           , INTENT(  out) ::   tab1d                        ! output 1D field
-      !
-      INTEGER ::   jn , jid, jjd
-      !!----------------------------------------------------------------------
-      DO jn = 1, ndim1d
-         jid        = MOD( tab_ind(jn) - 1 , ndim2d_x ) + 1
-         jjd        =    ( tab_ind(jn) - 1 ) / ndim2d_x + 1
-         tab1d( jn) = tab2d( jid, jjd)
-      END DO
-   END SUBROUTINE tab_2d_1d
-
-
-   SUBROUTINE tab_1d_2d( ndim1d, tab2d, tab_ind, tab1d, ndim2d_x, ndim2d_y )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE tab_2d_1d  ***
-      !!----------------------------------------------------------------------
-      INTEGER                               , INTENT(in   ) ::   ndim1d, ndim2d_x, ndim2d_y   ! 1d & 2D sizes
-      REAL(wp), DIMENSION(ndim1d)           , INTENT(in   ) ::   tab1d                        ! input 1D field
-      INTEGER , DIMENSION(ndim1d)           , INTENT(in   ) ::   tab_ind                      ! input index
-      REAL(wp), DIMENSION(ndim2d_x,ndim2d_y), INTENT(  out) ::   tab2d                        ! output 2D field
-      !
-      INTEGER ::   jn , jid, jjd
-      !!----------------------------------------------------------------------
-      DO jn = 1, ndim1d
-         jid             = MOD( tab_ind(jn) - 1 ,  ndim2d_x ) + 1
-         jjd             =    ( tab_ind(jn) - 1 ) / ndim2d_x  + 1
-         tab2d(jid, jjd) = tab1d( jn)
-      END DO
-   END SUBROUTINE tab_1d_2d
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option        Dummy module             NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-   !!======================================================================
-END MODULE limtab
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90	(revision 9018)
+++ 	(revision )
@@ -1,636 +1,0 @@
-MODULE limthd
-   !!======================================================================
-   !!                  ***  MODULE limthd   ***
-   !!  LIM-3 :   ice thermodynamic
-   !!======================================================================
-   !! History :  LIM  ! 2000-01 (M.A. Morales Maqueda, H. Goosse, T. Fichefet) LIM-1
-   !!            2.0  ! 2002-07 (C. Ethe, G. Madec)  LIM-2 (F90 rewriting)
-   !!            3.0  ! 2005-11 (M. Vancoppenolle)  LIM-3 : Multi-layer thermodynamics + salinity variations
-   !!             -   ! 2007-04 (M. Vancoppenolle) add lim_thd_glohec, lim_thd_con_dh and lim_thd_con_dif
-   !!            3.2  ! 2009-07 (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in wfx_snw
-   !!            3.3  ! 2010-11 (G. Madec) corrected snow melting heat (due to factor betas)
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!             -   ! 2012-05 (C. Rousset) add penetration solar flux
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_thd       : thermodynamic of sea ice
-   !!   lim_thd_init  : initialisation of sea-ice thermodynamic
-   !!----------------------------------------------------------------------
-   USE phycst         ! physical constants
-   USE dom_oce        ! ocean space and time domain variables
-   USE ice            ! sea-ice variables
-   USE sbc_oce        ! Surface boundary condition: ocean fields
-   USE sbc_ice        ! Surface boundary condition: ice fields
-   USE thd_ice        ! thermodynamic sea-ice variables
-   USE limthd_dif     ! vertical diffusion
-   USE limthd_dh      ! ice-snow growth and melt
-   USE limthd_da      ! lateral melting
-   USE limthd_sal     ! ice salinity
-   USE limthd_ent     ! ice enthalpy redistribution
-   USE limthd_lac     ! lateral accretion
-   USE limitd_th      ! remapping thickness distribution
-   USE limtab         ! 1D <==> 2D transformation
-   USE limvar         !
-   USE limcons        ! conservation tests
-   USE limctl         ! control print
-   !
-   USE in_out_manager ! I/O manager
-   USE lbclnk         ! lateral boundary condition - MPP links
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE timing         ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_thd         ! called by limstp module
-   PUBLIC   lim_thd_init    ! called by sbc_lim_init
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 3.3 , UCL - NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_thd( kt )
-      !!-------------------------------------------------------------------
-      !!                ***  ROUTINE lim_thd  ***       
-      !!  
-      !! ** Purpose : This routine manages ice thermodynamics
-      !!         
-      !! ** Action : - Initialisation of some variables
-      !!             - Some preliminary computation (oceanic heat flux
-      !!               at the ice base, snow acc.,heat budget of the leads)
-      !!             - selection of the icy points and put them in an array
-      !!             - call lim_thd_dif  for vertical heat diffusion
-      !!             - call lim_thd_dh   for vertical ice growth and melt
-      !!             - call lim_thd_ent  for enthalpy remapping
-      !!             - call lim_thd_sal  for ice desalination
-      !!             - call lim_thd_temp to  retrieve temperature from ice enthalpy
-      !!             - back to the geographic grid
-      !!     
-      !! ** References : 
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) :: kt    ! number of iteration
-      !
-      INTEGER  :: ji, jj, jk, jl   ! dummy loop indices
-      INTEGER  :: nbpb             ! nb of icy pts for vertical thermo calculations
-      REAL(wp) :: zfric_u, zqld, zqfr
-      REAL(wp) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
-      REAL(wp), PARAMETER :: zfric_umin = 0._wp           ! lower bound for the friction velocity (cice value=5.e-04)
-      REAL(wp), PARAMETER :: zch        = 0.0057_wp       ! heat transfer coefficient
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zu_io, zv_io, zfric   ! ice-ocean velocity (m/s) and frictional velocity (m2/s2)
-      !
-      !!-------------------------------------------------------------------
-
-      IF( nn_timing == 1 )   CALL timing_start('limthd')
-
-      CALL wrk_alloc( jpi,jpj, zu_io, zv_io, zfric )
-
-      IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*)'' 
-         WRITE(numout,*)' lim_thd '
-         WRITE(numout,*)' ~~~~~~~~'
-      ENDIF
-      
-      ! conservation test
-      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'limthd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      CALL lim_var_glo2eqv
-
-      !---------------------------------------------!
-      ! computation of friction velocity at T points
-      !---------------------------------------------!
-      IF( ln_limdyn ) THEN
-         zu_io(:,:) = u_ice(:,:) - ssu_m(:,:)
-         zv_io(:,:) = v_ice(:,:) - ssv_m(:,:)
-         DO jj = 2, jpjm1 
-            DO ji = fs_2, fs_jpim1
-               zfric(ji,jj) = rn_cio * ( 0.5_wp *  &
-                  &                    (  zu_io(ji,jj) * zu_io(ji,jj) + zu_io(ji-1,jj) * zu_io(ji-1,jj)   &
-                  &                     + zv_io(ji,jj) * zv_io(ji,jj) + zv_io(ji,jj-1) * zv_io(ji,jj-1) ) ) * tmask(ji,jj,1)
-            END DO
-         END DO
-      ELSE      !  if no ice dynamics => transmit directly the atmospheric stress to the ocean
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1
-               zfric(ji,jj) = r1_rau0 * SQRT( 0.5_wp *  &
-                  &                         (  utau(ji,jj) * utau(ji,jj) + utau(ji-1,jj) * utau(ji-1,jj)   &
-                  &                          + vtau(ji,jj) * vtau(ji,jj) + vtau(ji,jj-1) * vtau(ji,jj-1) ) ) * tmask(ji,jj,1)
-            END DO
-         END DO
-      ENDIF
-      CALL lbc_lnk( zfric, 'T',  1. )
-      !
-      !----------------------------------!
-      ! Initialization and units change
-      !----------------------------------!
-      ftr_ice(:,:,:) = 0._wp  ! part of solar radiation transmitted through the ice
-
-      ! Change the units of heat content; from J/m2 to J/m3
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  rswitch = MAX(  0._wp , SIGN( 1._wp , v_i(ji,jj,jl) - epsi20 )  )
-                  !Energy of melting q(S,T) [J.m-3]
-                  e_i(ji,jj,jk,jl) = rswitch * e_i(ji,jj,jk,jl) / MAX( v_i(ji,jj,jl) , epsi20 ) * REAL( nlay_i )
-               END DO
-            END DO
-         END DO
-         DO jk = 1, nlay_s
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  rswitch = MAX(  0._wp , SIGN( 1._wp , v_s(ji,jj,jl) - epsi20 )  )
-                  !Energy of melting q(S,T) [J.m-3]
-                  e_s(ji,jj,jk,jl) = rswitch * e_s(ji,jj,jk,jl) / MAX( v_s(ji,jj,jl) , epsi20 ) * REAL( nlay_s )
-               END DO
-            END DO
-         END DO
-      END DO
-
-      !--------------------------------------------------------------------!
-      ! Partial computation of forcing for the thermodynamic sea ice model
-      !--------------------------------------------------------------------!
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            rswitch  = tmask(ji,jj,1) * MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi10 ) ) ! 0 if no ice
-            !
-            !           !  solar irradiance transmission at the mixed layer bottom and used in the lead heat budget
-            !           !  practically no "direct lateral ablation"
-            !           
-            !           !  net downward heat flux from the ice to the ocean, expressed as a function of ocean 
-            !           !  temperature and turbulent mixing (McPhee, 1992)
-            !
-            ! --- Energy received in the lead, zqld is defined everywhere (J.m-2) --- !
-            zqld =  tmask(ji,jj,1) * rdt_ice *  &
-               &    ( pfrld(ji,jj) * qsr_oce(ji,jj) * frq_m(ji,jj) + pfrld(ji,jj) * qns_oce(ji,jj) + qemp_oce(ji,jj) )
-
-            ! --- Energy needed to bring ocean surface layer until its freezing (<0, J.m-2) --- !
-            zqfr = tmask(ji,jj,1) * rau0 * rcp * e3t_m(ji,jj) * ( t_bo(ji,jj) - ( sst_m(ji,jj) + rt0 ) )
-
-            ! --- Energy from the turbulent oceanic heat flux (W/m2) --- !
-            zfric_u      = MAX( SQRT( zfric(ji,jj) ), zfric_umin ) 
-            fhtur(ji,jj) = MAX( 0._wp, rswitch * rau0 * rcp * zch  * zfric_u * ( ( sst_m(ji,jj) + rt0 ) - t_bo(ji,jj) ) ) ! W.m-2
-            fhtur(ji,jj) = rswitch * MIN( fhtur(ji,jj), - zqfr * r1_rdtice / MAX( at_i(ji,jj), epsi10 ) )
-            ! upper bound for fhtur: the heat retrieved from the ocean must be smaller than the heat necessary to reach 
-            !                        the freezing point, so that we do not have SST < T_freeze
-            !                        This implies: - ( fhtur(ji,jj) * at_i(ji,jj) * rtdice ) - zqfr >= 0
-
-            !-- Energy Budget of the leads (J.m-2). Must be < 0 to form ice
-            qlead(ji,jj) = MIN( 0._wp , zqld - ( fhtur(ji,jj) * at_i(ji,jj) * rdt_ice ) - zqfr )
-
-            ! If there is ice and leads are warming, then transfer energy from the lead budget and use it for bottom melting 
-            IF( zqld > 0._wp ) THEN
-               fhld (ji,jj) = rswitch * zqld * r1_rdtice / MAX( at_i(ji,jj), epsi10 ) ! divided by at_i since this is (re)multiplied by a_i in limthd_dh.F90
-               qlead(ji,jj) = 0._wp
-            ELSE
-               fhld (ji,jj) = 0._wp
-            ENDIF
-            !
-            ! Net heat flux on top of the ice-ocean [W.m-2]
-            ! ---------------------------------------------
-            hfx_in(ji,jj) = qns_tot(ji,jj) + qsr_tot(ji,jj) 
-         END DO
-      END DO
-      
-      ! In case we bypass open-water ice formation
-      IF( .NOT. ln_limdO )  qlead(:,:) = 0._wp
-      ! In case we bypass growing/melting from top and bottom: we suppose ice is impermeable => ocean is isolated from atmosphere
-      IF( .NOT. ln_limdH ) THEN
-         hfx_in(:,:) = pfrld(:,:) * ( qns_oce(:,:) + qsr_oce(:,:) ) + qemp_oce(:,:)
-         fhtur (:,:) = 0._wp
-         fhld  (:,:) = 0._wp
-      ENDIF
-
-      ! ---------------------------------------------------------------------
-      ! Net heat flux on top of the ocean after ice thermo (1st step) [W.m-2]
-      ! ---------------------------------------------------------------------
-      !     First  step here              :  non solar + precip - qlead - qturb
-      !     Second step in limthd_dh      :  heat remaining if total melt (zq_rema) 
-      !     Third  step in limsbc         :  heat from ice-ocean mass exchange (zf_mass) + solar
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            hfx_out(ji,jj) =   pfrld(ji,jj) * qns_oce(ji,jj) + qemp_oce(ji,jj)  &  ! Non solar heat flux received by the ocean               
-               &             - qlead(ji,jj) * r1_rdtice                         &  ! heat flux taken from the ocean where there is open water ice formation
-               &             - at_i(ji,jj) * fhtur(ji,jj)                       &  ! heat flux taken by turbulence
-               &             - at_i(ji,jj) *  fhld(ji,jj)                          ! heat flux taken during bottom growth/melt 
-                                                                                   !    (fhld should be 0 while bott growth)
-         END DO
-      END DO
-
-      !------------------------------------------------------------------------------!
-      ! Thermodynamic computation (only on grid points covered by ice)
-      !------------------------------------------------------------------------------!
-
-      DO jl = 1, jpl      !loop over ice categories
-
-         ! select ice covered grid points
-         nbpb = 0
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF ( a_i(ji,jj,jl) > epsi10 ) THEN     
-                  nbpb      = nbpb  + 1
-                  npb(nbpb) = (jj - 1) * jpi + ji
-               ENDIF
-            END DO
-         END DO
-
-         ! debug point to follow
-         jiindex_1d = 0
-         IF( ln_limctl ) THEN
-            DO ji = mi0(iiceprt), mi1(iiceprt)
-               DO jj = mj0(jiceprt), mj1(jiceprt)
-                  jiindex_1d = (jj - 1) * jpi + ji
-                  WRITE(numout,*) ' lim_thd : Category no : ', jl 
-               END DO
-            END DO
-         ENDIF
-
-         IF( lk_mpp )         CALL mpp_ini_ice( nbpb , numout )
-
-         IF( nbpb > 0 ) THEN  ! If there is no ice, do nothing.
-            !                                                                
-            s_i_new   (:) = 0._wp ; dh_s_tot (:) = 0._wp                     ! --- some init --- !
-            dh_i_surf (:) = 0._wp ; dh_i_bott(:) = 0._wp
-            dh_snowice(:) = 0._wp ; dh_i_sub (:) = 0._wp
-
-                              CALL lim_thd_1d2d( nbpb, jl, 1 )               ! --- Move to 1D arrays --- !
-            !
-            IF( ln_limdH )    CALL lim_thd_dif( 1, nbpb )                    ! --- Ice/Snow Temperature profile --- !
-            !
-            IF( ln_limdH )    CALL lim_thd_dh( 1, nbpb )                     ! --- Ice/Snow thickness --- !    
-            !
-            IF( ln_limdH )    CALL lim_thd_ent( 1, nbpb, q_i_1d(1:nbpb,:) )  ! --- Ice enthalpy remapping --- !
-            !
-                              CALL lim_thd_sal( 1, nbpb )                    ! --- Ice salinity --- !    
-            !
-                              CALL lim_thd_temp( 1, nbpb )                   ! --- temperature update --- !
-            !
-            IF( ln_limdH ) THEN
-               IF ( ( nn_monocat == 1 .OR. nn_monocat == 4 ) .AND. jpl == 1 ) THEN
-                              CALL lim_thd_lam( 1, nbpb )                    ! --- extra lateral melting if monocat --- !
-               END IF
-            END IF
-            !
-                              CALL lim_thd_1d2d( nbpb, jl, 2 )               ! --- Move to 2D arrays --- !
-            !
-            IF( lk_mpp )      CALL mpp_comm_free( ncomm_ice ) !RB necessary ??
-         ENDIF
-         !
-      END DO !jl
-
-      IF( ln_limdA)           CALL lim_thd_da                                ! --- lateral melting --- !
-
-      ! Enthalpies are global variables we have to readjust the units (heat content in J/m2)
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            e_i(:,:,jk,jl) = e_i(:,:,jk,jl) * a_i(:,:,jl) * ht_i(:,:,jl) * r1_nlay_i
-         END DO
-         DO jk = 1, nlay_s
-            e_s(:,:,jk,jl) = e_s(:,:,jk,jl) * a_i(:,:,jl) * ht_s(:,:,jl) * r1_nlay_s
-         END DO
-      END DO
- 
-      ! Change thickness to volume
-      v_i(:,:,:)   = ht_i(:,:,:) * a_i(:,:,:)
-      v_s(:,:,:)   = ht_s(:,:,:) * a_i(:,:,:)
-      smv_i(:,:,:) = sm_i(:,:,:) * v_i(:,:,:)
-
-      ! update ice age (in case a_i changed, i.e. becomes 0 or lateral melting in monocat)
-      DO jl  = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               rswitch = MAX( 0._wp , SIGN( 1._wp, a_i_b(ji,jj,jl) - epsi10 ) )
-               oa_i(ji,jj,jl) = rswitch * oa_i(ji,jj,jl) * a_i(ji,jj,jl) / MAX( a_i_b(ji,jj,jl), epsi10 )
-            END DO
-         END DO
-      END DO
-
-      CALL lim_var_zapsmall
-
-      ! control checks
-      IF( ln_limctl )    CALL lim_prt( kt, iiceprt, jiceprt, 1, ' - ice thermodyn. - ' )   ! control print
-      !
-      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'limthd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      !------------------------------------------------!
-      !  Transport ice between thickness categories
-      !------------------------------------------------!
-      ! Given thermodynamic growth rates, transport ice between thickness categories.
-      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'limitd_th_rem', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      IF( jpl > 1 )      CALL lim_itd_th_rem( 1, jpl, kt )
-
-      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'limitd_th_rem', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      !------------------------------------------------!
-      !  Add frazil ice growing in leads
-      !------------------------------------------------!
-      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'limthd_lac', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      IF( ln_limdO )     CALL lim_thd_lac
-      
-      ! conservation test
-      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'limthd_lac', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      ! Control print
-      IF( ln_ctl )       CALL lim_prt3D( 'limthd' )
-      !
-      CALL wrk_dealloc( jpi,jpj, zu_io, zv_io, zfric )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('limthd')
-
-   END SUBROUTINE lim_thd 
-
- 
-   SUBROUTINE lim_thd_temp( kideb, kiut )
-      !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_thd_temp *** 
-      !!                 
-      !! ** Purpose :   Computes sea ice temperature (Kelvin) from enthalpy
-      !!
-      !! ** Method  :   Formula (Bitz and Lipscomb, 1999)
-      !!-------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kideb, kiut   ! bounds for the spatial loop
-      !
-      INTEGER  ::   ji, jk   ! dummy loop indices
-      REAL(wp) ::   ztmelts, zaaa, zbbb, zccc, zdiscrim  ! local scalar 
-      !!-------------------------------------------------------------------
-      ! Recover ice temperature
-      DO jk = 1, nlay_i
-         DO ji = kideb, kiut
-            ztmelts       =  -tmut * s_i_1d(ji,jk) + rt0
-            ! Conversion q(S,T) -> T (second order equation)
-            zaaa          =  cpic
-            zbbb          =  ( rcp - cpic ) * ( ztmelts - rt0 ) + q_i_1d(ji,jk) * r1_rhoic - lfus
-            zccc          =  lfus * ( ztmelts - rt0 )
-            zdiscrim      =  SQRT( MAX( zbbb * zbbb - 4._wp * zaaa * zccc, 0._wp ) )
-            t_i_1d(ji,jk) =  rt0 - ( zbbb + zdiscrim ) / ( 2._wp * zaaa )
-            
-            ! mask temperature
-            rswitch       =  1._wp - MAX( 0._wp , SIGN( 1._wp , - ht_i_1d(ji) ) ) 
-            t_i_1d(ji,jk) =  rswitch * t_i_1d(ji,jk) + ( 1._wp - rswitch ) * rt0
-         END DO 
-      END DO 
-      !
-   END SUBROUTINE lim_thd_temp
-
-
-   SUBROUTINE lim_thd_lam( kideb, kiut )
-      !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_thd_lam *** 
-      !!                 
-      !! ** Purpose :   Lateral melting in case monocategory
-      !!                          ( dA = A/2h dh )
-      !!-----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kideb, kiut        ! bounds for the spatial loop
-      !
-      INTEGER  ::   ji                 ! dummy loop indices
-      REAL(wp) ::   zhi_bef            ! ice thickness before thermo
-      REAL(wp) ::   zdh_mel, zda_mel   ! net melting
-      REAL(wp) ::   zvi, zvs           ! ice/snow volumes 
-      !!-----------------------------------------------------------------------
-      !
-      DO ji = kideb, kiut
-         zdh_mel = MIN( 0._wp, dh_i_surf(ji) + dh_i_bott(ji) + dh_snowice(ji) + dh_i_sub(ji) )
-         IF( zdh_mel < 0._wp .AND. a_i_1d(ji) > 0._wp )  THEN
-            zvi          = a_i_1d(ji) * ht_i_1d(ji)
-            zvs          = a_i_1d(ji) * ht_s_1d(ji)
-            ! lateral melting = concentration change
-            zhi_bef     = ht_i_1d(ji) - zdh_mel
-            rswitch     = MAX( 0._wp , SIGN( 1._wp , zhi_bef - epsi20 ) )
-            zda_mel     = rswitch * a_i_1d(ji) * zdh_mel / ( 2._wp * MAX( zhi_bef, epsi20 ) )
-            a_i_1d(ji)  = MAX( epsi20, a_i_1d(ji) + zda_mel ) 
-            ! adjust thickness
-            ht_i_1d(ji) = zvi / a_i_1d(ji)            
-            ht_s_1d(ji) = zvs / a_i_1d(ji)            
-            ! retrieve total concentration
-            at_i_1d(ji) = a_i_1d(ji)
-         END IF
-      END DO
-      !
-   END SUBROUTINE lim_thd_lam
-
-
-   SUBROUTINE lim_thd_1d2d( nbpb, jl, kn )
-      !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_thd_1d2d *** 
-      !!                 
-      !! ** Purpose :   move arrays from 1d to 2d and the reverse
-      !!-----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kn       ! 1= from 2D to 1D   ;   2= from 1D to 2D
-      INTEGER, INTENT(in) ::   nbpb     ! size of 1D arrays
-      INTEGER, INTENT(in) ::   jl       ! ice cat
-      !
-      INTEGER             ::   jk       ! dummy loop indices
-      !!-----------------------------------------------------------------------
-      !
-      SELECT CASE( kn )
-      !
-      CASE( 1 )            ! from 2D to 1D
-         !
-         CALL tab_2d_1d( nbpb, at_i_1d     (1:nbpb), at_i            , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, a_i_1d      (1:nbpb), a_i(:,:,jl)     , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, ht_i_1d     (1:nbpb), ht_i(:,:,jl)    , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, ht_s_1d     (1:nbpb), ht_s(:,:,jl)    , jpi, jpj, npb(1:nbpb) )
-         !
-         CALL tab_2d_1d( nbpb, t_su_1d     (1:nbpb), t_su(:,:,jl)    , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, sm_i_1d     (1:nbpb), sm_i(:,:,jl)    , jpi, jpj, npb(1:nbpb) )
-         DO jk = 1, nlay_s
-            CALL tab_2d_1d( nbpb, t_s_1d(1:nbpb,jk), t_s(:,:,jk,jl)  , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, q_s_1d(1:nbpb,jk), e_s(:,:,jk,jl)  , jpi, jpj, npb(1:nbpb) )
-         END DO
-         DO jk = 1, nlay_i
-            CALL tab_2d_1d( nbpb, t_i_1d(1:nbpb,jk), t_i(:,:,jk,jl)  , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, q_i_1d(1:nbpb,jk), e_i(:,:,jk,jl)  , jpi, jpj, npb(1:nbpb) )
-            CALL tab_2d_1d( nbpb, s_i_1d(1:nbpb,jk), s_i(:,:,jk,jl)  , jpi, jpj, npb(1:nbpb) )
-         END DO
-         !
-         CALL tab_2d_1d( nbpb, qprec_ice_1d(1:nbpb), qprec_ice(:,:) , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, qevap_ice_1d(1:nbpb), qevap_ice(:,:,jl) , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, qsr_ice_1d (1:nbpb), qsr_ice(:,:,jl) , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, fr1_i0_1d  (1:nbpb), fr1_i0          , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, fr2_i0_1d  (1:nbpb), fr2_i0          , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, qns_ice_1d (1:nbpb), qns_ice(:,:,jl) , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, ftr_ice_1d (1:nbpb), ftr_ice(:,:,jl) , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, evap_ice_1d (1:nbpb), evap_ice(:,:,jl), jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, dqns_ice_1d(1:nbpb), dqns_ice(:,:,jl), jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, t_bo_1d     (1:nbpb), t_bo            , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, sprecip_1d (1:nbpb), sprecip         , jpi, jpj, npb(1:nbpb) ) 
-         CALL tab_2d_1d( nbpb, fhtur_1d   (1:nbpb), fhtur           , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, qlead_1d   (1:nbpb), qlead           , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, fhld_1d    (1:nbpb), fhld            , jpi, jpj, npb(1:nbpb) )
-         !
-         CALL tab_2d_1d( nbpb, wfx_snw_1d (1:nbpb), wfx_snw         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, wfx_sub_1d (1:nbpb), wfx_sub         , jpi, jpj, npb(1:nbpb) )
-         !
-         CALL tab_2d_1d( nbpb, wfx_bog_1d (1:nbpb), wfx_bog         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, wfx_bom_1d (1:nbpb), wfx_bom         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, wfx_sum_1d (1:nbpb), wfx_sum         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, wfx_sni_1d (1:nbpb), wfx_sni         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, wfx_res_1d (1:nbpb), wfx_res         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, wfx_spr_1d (1:nbpb), wfx_spr         , jpi, jpj, npb(1:nbpb) )
-         !
-         CALL tab_2d_1d( nbpb, sfx_bog_1d (1:nbpb), sfx_bog         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, sfx_bom_1d (1:nbpb), sfx_bom         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, sfx_sum_1d (1:nbpb), sfx_sum         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, sfx_sni_1d (1:nbpb), sfx_sni         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, sfx_bri_1d (1:nbpb), sfx_bri         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, sfx_res_1d (1:nbpb), sfx_res         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, sfx_sub_1d (1:nbpb), sfx_sub         , jpi, jpj,npb(1:nbpb) )
-         !
-         CALL tab_2d_1d( nbpb, hfx_thd_1d (1:nbpb), hfx_thd         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, hfx_spr_1d (1:nbpb), hfx_spr         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, hfx_sum_1d (1:nbpb), hfx_sum         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, hfx_bom_1d (1:nbpb), hfx_bom         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, hfx_bog_1d (1:nbpb), hfx_bog         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, hfx_dif_1d (1:nbpb), hfx_dif         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, hfx_opw_1d (1:nbpb), hfx_opw         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, hfx_snw_1d (1:nbpb), hfx_snw         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, hfx_sub_1d (1:nbpb), hfx_sub         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, hfx_err_1d (1:nbpb), hfx_err         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, hfx_res_1d (1:nbpb), hfx_res         , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, hfx_err_dif_1d (1:nbpb), hfx_err_dif , jpi, jpj, npb(1:nbpb) )
-         CALL tab_2d_1d( nbpb, hfx_err_rem_1d (1:nbpb), hfx_err_rem , jpi, jpj, npb(1:nbpb) )
-         !
-      CASE( 2 )            ! from 1D to 2D
-         !
-         CALL tab_1d_2d( nbpb, at_i          , npb, at_i_1d    (1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, ht_i(:,:,jl)  , npb, ht_i_1d    (1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, ht_s(:,:,jl)  , npb, ht_s_1d    (1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, a_i (:,:,jl)  , npb, a_i_1d     (1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, t_su(:,:,jl)  , npb, t_su_1d    (1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, sm_i(:,:,jl)  , npb, sm_i_1d    (1:nbpb)   , jpi, jpj )
-         DO jk = 1, nlay_s
-            CALL tab_1d_2d( nbpb, t_s(:,:,jk,jl), npb, t_s_1d     (1:nbpb,jk), jpi, jpj)
-            CALL tab_1d_2d( nbpb, e_s(:,:,jk,jl), npb, q_s_1d     (1:nbpb,jk), jpi, jpj)
-         END DO
-         DO jk = 1, nlay_i
-            CALL tab_1d_2d( nbpb, t_i(:,:,jk,jl), npb, t_i_1d     (1:nbpb,jk), jpi, jpj)
-            CALL tab_1d_2d( nbpb, e_i(:,:,jk,jl), npb, q_i_1d     (1:nbpb,jk), jpi, jpj)
-            CALL tab_1d_2d( nbpb, s_i(:,:,jk,jl), npb, s_i_1d     (1:nbpb,jk), jpi, jpj)
-         END DO
-         CALL tab_1d_2d( nbpb, qlead         , npb, qlead_1d  (1:nbpb)   , jpi, jpj )
-         !
-         CALL tab_1d_2d( nbpb, wfx_snw       , npb, wfx_snw_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, wfx_sub       , npb, wfx_sub_1d(1:nbpb)   , jpi, jpj )
-         !
-         CALL tab_1d_2d( nbpb, wfx_bog       , npb, wfx_bog_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, wfx_bom       , npb, wfx_bom_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, wfx_sum       , npb, wfx_sum_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, wfx_sni       , npb, wfx_sni_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, wfx_res       , npb, wfx_res_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, wfx_spr       , npb, wfx_spr_1d(1:nbpb)   , jpi, jpj )
-         !
-         CALL tab_1d_2d( nbpb, sfx_bog       , npb, sfx_bog_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, sfx_bom       , npb, sfx_bom_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, sfx_sum       , npb, sfx_sum_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, sfx_sni       , npb, sfx_sni_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, sfx_res       , npb, sfx_res_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, sfx_bri       , npb, sfx_bri_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, sfx_sub       , npb, sfx_sub_1d(1:nbpb)   , jpi, jpj )        
-         !
-         CALL tab_1d_2d( nbpb, hfx_thd       , npb, hfx_thd_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, hfx_spr       , npb, hfx_spr_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, hfx_sum       , npb, hfx_sum_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, hfx_bom       , npb, hfx_bom_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, hfx_bog       , npb, hfx_bog_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, hfx_dif       , npb, hfx_dif_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, hfx_opw       , npb, hfx_opw_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, hfx_snw       , npb, hfx_snw_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, hfx_sub       , npb, hfx_sub_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, hfx_err       , npb, hfx_err_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, hfx_res       , npb, hfx_res_1d(1:nbpb)   , jpi, jpj )
-         CALL tab_1d_2d( nbpb, hfx_err_rem   , npb, hfx_err_rem_1d(1:nbpb), jpi, jpj )
-         CALL tab_1d_2d( nbpb, hfx_err_dif   , npb, hfx_err_dif_1d(1:nbpb), jpi, jpj )
-         !
-         CALL tab_1d_2d( nbpb, qns_ice(:,:,jl), npb, qns_ice_1d(1:nbpb) , jpi, jpj)
-         CALL tab_1d_2d( nbpb, ftr_ice(:,:,jl), npb, ftr_ice_1d(1:nbpb) , jpi, jpj )
-         !         
-      END SELECT
-      !
-   END SUBROUTINE lim_thd_1d2d
-
-
-   SUBROUTINE lim_thd_init
-      !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_thd_init *** 
-      !!                 
-      !! ** Purpose :   Physical constants and parameters linked to the ice 
-      !!              thermodynamics
-      !!
-      !! ** Method  :   Read the namicethd namelist and check the ice-thermo
-      !!              parameter values called at the first timestep (nit000)
-      !!
-      !! ** input   :   Namelist namicether
-      !!-------------------------------------------------------------------
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namicethd/ rn_kappa_i, nn_conv_dif, rn_terr_dif, nn_ice_thcon, ln_it_qnsice, nn_monocat, rn_cdsn,  &
-         &                ln_limdH, rn_betas,                                                                     &
-         &                ln_limdA, rn_beta, rn_dmin,                                                             &
-         &                ln_limdO, rn_hnewice, ln_frazil, rn_maxfrazb, rn_vfrazb, rn_Cfrazb, rn_himin
-      !!-------------------------------------------------------------------
-      !
-      REWIND( numnam_ice_ref )              ! Namelist namicethd in reference namelist : Ice thermodynamics
-      READ  ( numnam_ice_ref, namicethd, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicethd in reference namelist', lwp )
-
-      REWIND( numnam_ice_cfg )              ! Namelist namicethd in configuration namelist : Ice thermodynamics
-      READ  ( numnam_ice_cfg, namicethd, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicethd in configuration namelist', lwp )
-      IF(lwm) WRITE ( numoni, namicethd )
-      !
-      IF ( ( jpl > 1 ) .AND. ( nn_monocat == 1 ) ) THEN 
-         nn_monocat = 0
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) '   nn_monocat forced to 0 as jpl>1, i.e. multi-category case is chosen'
-      ENDIF
-      !
-      IF(lwp) THEN                          ! control print
-         WRITE(numout,*) 'lim_thd_init : Ice Thermodynamics'
-         WRITE(numout,*) '~~~~~~~~~~~~~'
-         WRITE(numout,*)'   -- limthd_dif --'
-         WRITE(numout,*)'      extinction radiation parameter in sea ice               rn_kappa_i   = ', rn_kappa_i
-         WRITE(numout,*)'      maximal n. of iter. for heat diffusion computation      nn_conv_dif  = ', nn_conv_dif
-         WRITE(numout,*)'      maximal err. on T for heat diffusion computation        rn_terr_dif  = ', rn_terr_dif
-         WRITE(numout,*)'      switch for comp. of thermal conductivity in the ice     nn_ice_thcon = ', nn_ice_thcon
-         WRITE(numout,*)'      iterate the surface non-solar flux (T) or not (F)       ln_it_qnsice = ', ln_it_qnsice
-         WRITE(numout,*)'      virtual ITD mono-category parameterizations (1) or not  nn_monocat   = ', nn_monocat
-         WRITE(numout,*)'      thermal conductivity of the snow                        rn_cdsn      = ', rn_cdsn
-         WRITE(numout,*)'   -- limthd_dh --'
-         WRITE(numout,*)'      activate ice thick change from top/bot (T) or not (F)   ln_limdH     = ', ln_limdH
-         WRITE(numout,*)'      coefficient for ice-lead partition of snowfall          rn_betas     = ', rn_betas
-         WRITE(numout,*)'   -- limthd_da --'
-         WRITE(numout,*)'      activate lateral melting (T) or not (F)                 ln_limdA     = ', ln_limdA
-         WRITE(numout,*)'      Coef. beta for lateral melting param.                   rn_beta      = ', rn_beta
-         WRITE(numout,*)'      Minimum floe diameter for lateral melting param.        rn_dmin      = ', rn_dmin
-         WRITE(numout,*)'   -- limthd_lac --'
-         WRITE(numout,*)'      activate ice growth in open-water (T) or not (F)        ln_limdO     = ', ln_limdO
-         WRITE(numout,*)'      ice thick. for lateral accretion                        rn_hnewice   = ', rn_hnewice
-         WRITE(numout,*)'      Frazil ice thickness as a function of wind or not       ln_frazil    = ', ln_frazil
-         WRITE(numout,*)'      Maximum proportion of frazil ice collecting at bottom   rn_maxfrazb  = ', rn_maxfrazb
-         WRITE(numout,*)'      Thresold relative drift speed for collection of frazil  rn_vfrazb    = ', rn_vfrazb
-         WRITE(numout,*)'      Squeezing coefficient for collection of frazil          rn_Cfrazb    = ', rn_Cfrazb
-         WRITE(numout,*)'   -- limitd_th --'
-         WRITE(numout,*)'      minimum ice thickness                                   rn_himin     = ', rn_himin 
-         WRITE(numout,*)'      check heat conservation in the ice/snow                 con_i        = ', con_i
-      ENDIF
-      !
-   END SUBROUTINE lim_thd_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Dummy module          NO  LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-
-   !!======================================================================
-END MODULE limthd
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limthd_da.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limthd_da.F90	(revision 9018)
+++ 	(revision )
@@ -1,183 +1,0 @@
-MODULE limthd_da
-   !!======================================================================
-   !!                       ***  MODULE limthd_da ***
-   !! LIM-3 sea-ice :  computation of lateral melting in the ice
-   !!======================================================================
-   !! History :   4.0   ! 2016-03 (C. Rousset) original code
-   !!---------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_thd_da   : sea ice lateral melting
-   !!----------------------------------------------------------------------
-   USE par_oce                ! ocean parameters
-   USE phycst                 ! physical constants (ocean directory)
-   USE sbc_oce, ONLY: sst_m   ! Surface boundary condition: ocean fields
-   USE ice                    ! LIM variables
-   USE lib_mpp                ! MPP library
-   USE wrk_nemo               ! work arrays
-   USE lib_fortran            ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_thd_da        ! called by limthd module
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limthd_da.F90 5123 2015-03-04 16:06:03Z clem $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_thd_da
-      !!-------------------------------------------------------------------
-      !!                ***  ROUTINE lim_thd_da  ***    
-      !!   
-      !! ** Purpose :   computes sea ice lateral melting
-      !!
-      !! ** Method  :   dA/dt = - P * W   [s-1]
-      !!                   W = melting velocity [m.s-1]
-      !!                   P = perimeter of ice-ocean lateral interface normalized by grid cell area [m.m-2]
-      !!
-      !!                   W = m1 * (Tw -Tf)**m2                    --- originally from Josberger 1979 ---
-      !!                      (Tw - Tf) = elevation of water temp above freezing
-      !!                      m1 and m2 = (1.6e-6 , 1.36) best fit from field experiment near the coast of Prince Patrick Island (Perovich 1983) => static ice
-      !!                      m1 and m2 = (3.0e-6 , 1.36) best fit from MIZEX 84 experiment (Maykut and Perovich 1987) => moving ice
-      !!
-      !!                   P = N * pi * D                           --- from Rothrock and Thorndike 1984 ---
-      !!                      D = mean floe caliper diameter
-      !!                      N = number of floes = ice area / floe area(average) = A / (Cs * D**2)
-      !!                         A = ice concentration
-      !!                         Cs = deviation from a square (square:Cs=1 ; circle:Cs=pi/4 ; floe:Cs=0.66)
-      !!
-      !!                   D = Dmin * ( Astar / (Astar-A) )**beta   --- from Lupkes et al., 2012 (eq. 26-27) ---
-      !!                                                             
-      !!                      Astar = 1 / ( 1 - (Dmin/Dmax)**(1/beta) )
-      !!                      Dmin = minimum floe diameter (recommended to be 8m +- 20%)
-      !!                      Dmax = maximum floe diameter (recommended to be 300m, but it does not impact melting much except for Dmax<100m)
-      !!                      beta = 1.0 +-20% (recommended value)
-      !!                           = 0.3 best fit for western Fram Strait and Antarctica
-      !!                           = 1.4 best fit for eastern Fram Strait
-      !!
-      !! ** Tunable parameters  :   We propose to tune the lateral melting via 2 parameters
-      !!                               Dmin [6-10m]   => 6  vs 8m = +40% melting at the peak (A~0.5)
-      !!                                                 10 vs 8m = -20% melting
-      !!                               beta [0.8-1.2] => decrease = more melt and melt peaks toward higher concentration
-      !!                                                                  (A~0.5 for beta=1 ; A~0.8 for beta=0.2)
-      !!                                                 0.3 = best fit for western Fram Strait and Antarctica
-      !!                                                 1.4 = best fit for eastern Fram Strait
-      !!
-      !! ** Note   :   Former and more simple formulations for floe diameters can be found in Mai (1995), 
-      !!               Birnbaum and Lupkes (2002), Lupkes and Birnbaum (2005). They are reviewed in Lupkes et al 2012
-      !!               A simpler implementation for CICE can be found in Bitz et al (2001) and Tsamados et al (2015)
-      !!
-      !! ** References
-      !!    Bitz, C. M., Holland, M. M., Weaver, A. J., & Eby, M. (2001).
-      !!              Simulating the ice‐thickness distribution in a coupled climate model.
-      !!              Journal of Geophysical Research: Oceans, 106(C2), 2441-2463.
-      !!    Josberger, E. G. (1979).
-      !!              Laminar and turbulent boundary layers adjacent to melting vertical ice walls in salt water
-      !!              (No. SCIENTIFIC-16). WASHINGTON UNIV SEATTLE DEPT OF ATMOSPHERIC SCIENCES.
-      !!    Lüpkes, C., Gryanik, V. M., Hartmann, J., & Andreas, E. L. (2012).
-      !!              A parametrization, based on sea ice morphology, of the neutral atmospheric drag coefficients
-      !!              for weather prediction and climate models.
-      !!              Journal of Geophysical Research: Atmospheres, 117(D13).
-      !!    Maykut, G. A., & Perovich, D. K. (1987).
-      !!              The role of shortwave radiation in the summer decay of a sea ice cover.
-      !!              Journal of Geophysical Research: Oceans, 92(C7), 7032-7044.
-      !!    Perovich, D. K. (1983).
-      !!              On the summer decay of a sea ice cover. (Doctoral dissertation, University of Washington).
-      !!    Rothrock, D. A., & Thorndike, A. S. (1984).
-      !!              Measuring the sea ice floe size distribution.
-      !!              Journal of Geophysical Research: Oceans, 89(C4), 6477-6486.
-      !!    Tsamados, M., Feltham, D., Petty, A., Schroeder, D., & Flocco, D. (2015).
-      !!              Processes controlling surface, bottom and lateral melt of Arctic sea ice in a state of the art sea ice model.
-      !!              Phil. Trans. R. Soc. A, 373(2052), 20140167.
-      !!---------------------------------------------------------------------
-      INTEGER             ::   ji, jj, jl      ! dummy loop indices
-      REAL(wp)            ::   zastar, zdfloe, zperi, zwlat, zda
-      REAL(wp), PARAMETER ::   zdmax = 300._wp
-      REAL(wp), PARAMETER ::   zcs   = 0.66_wp
-      REAL(wp), PARAMETER ::   zm1   = 3.e-6_wp
-      REAL(wp), PARAMETER ::   zm2   = 1.36_wp
-      !
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zda_tot
-      !!---------------------------------------------------------------------
-      CALL wrk_alloc( jpi,jpj, zda_tot )
-
-      !------------------------------------------------------------!
-      ! --- Calculate reduction of total sea ice concentration --- !
-      !------------------------------------------------------------!
-      zastar = 1._wp / ( 1._wp - (rn_dmin / zdmax)**(1._wp/rn_beta) )
-      
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            
-            ! Mean floe caliper diameter [m]
-            zdfloe = rn_dmin * ( zastar / ( zastar - at_i(ji,jj) ) )**rn_beta
-            
-            ! Mean perimeter of the floe = N*pi*D = (A/cs*D^2)*pi*D [m.m-2]
-            zperi = at_i(ji,jj) * rpi / ( zcs * zdfloe )
-            
-            ! Melt speed rate [m/s]
-            zwlat = zm1 * ( MAX( 0._wp, sst_m(ji,jj) - ( t_bo(ji,jj) - rt0 ) ) )**zm2
-            
-            ! sea ice concentration decrease
-            zda_tot(ji,jj) = - MIN( zwlat * zperi * rdt_ice, at_i(ji,jj) )
-            
-         END DO
-      END DO
-      
-      !---------------------------------------------------------------------------------------------!
-      ! --- Distribute reduction among ice categories and calculate associated ice-ocean fluxes --- !
-      !---------------------------------------------------------------------------------------------!
-      DO jl = jpl, 1, -1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               
-               ! decrease of concentration for the category jl
-               !    1st option: each category contributes to melting in proportion to its concentration
-               rswitch = MAX( 0._wp , SIGN( 1._wp, at_i(ji,jj) - epsi10 ) )
-               zda     = rswitch * zda_tot(ji,jj) * a_i(ji,jj,jl) / MAX( at_i(ji,jj), epsi10 )
-               !    2d option: melting of the upper cat first
-               !!zda = MAX( zda_tot(ji,jj), - a_i(ji,jj,jl) )
-               !!zda_tot(ji,jj) = zda_tot(ji,jj) + zda
-               
-               ! Contribution to salt flux
-               sfx_lam(ji,jj) = sfx_lam(ji,jj) - rhoic *  ht_i(ji,jj,jl) * zda * sm_i(ji,jj,jl) * r1_rdtice
-               
-               ! Contribution to heat flux into the ocean [W.m-2], <0  
-               hfx_thd(ji,jj) = hfx_thd(ji,jj) + zda * r1_rdtice * ( ht_i(ji,jj,jl) * SUM( e_i(ji,jj,:,jl) ) * r1_nlay_i  &
-                  &                                                + ht_s(ji,jj,jl) *      e_s(ji,jj,1,jl)   * r1_nlay_s )
-               
-               ! Contribution to mass flux
-               wfx_lam(ji,jj) =  wfx_lam(ji,jj) - zda * r1_rdtice * ( rhoic * ht_i(ji,jj,jl) + rhosn * ht_s(ji,jj,jl) )
-               
-               ! new concentration
-               a_i(ji,jj,jl) = a_i(ji,jj,jl) + zda
-            END DO
-         END DO
-      END DO
-      
-      ! total concentration
-      at_i(:,:) = SUM( a_i(:,:,:), dim=3 )
-      
-      ! --- ensure that ht_i = 0 where a_i = 0 ---
-      WHERE( a_i == 0._wp ) ht_i = 0._wp
-      !
-      CALL wrk_dealloc( jpi,jpj, zda_tot )
-      !
-   END SUBROUTINE lim_thd_da
-   
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Dummy Module          No LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_thd_da          ! Empty routine
-   END SUBROUTINE lim_thd_da
-#endif
-   !!======================================================================
-END MODULE limthd_da
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90	(revision 9018)
+++ 	(revision )
@@ -1,719 +1,0 @@
-MODULE limthd_dh
-   !!======================================================================
-   !!                       ***  MODULE limthd_dh ***
-   !!  LIM-3 :   thermodynamic growth and decay of the ice 
-   !!======================================================================
-   !! History :  LIM  ! 2003-05 (M. Vancoppenolle) Original code in 1D
-   !!                 ! 2005-06 (M. Vancoppenolle) 3D version 
-   !!            3.2  ! 2009-07 (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in wfx_snw & wfx_ice
-   !!            3.4  ! 2011-02 (G. Madec) dynamical allocation
-   !!            3.5  ! 2012-10 (G. Madec & co) salt flux + bug fixes 
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_thd_dh    : vertical accr./abl. and lateral ablation of sea ice
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-   USE phycst         ! physical constants (OCE directory) 
-   USE sbc_oce        ! Surface boundary condition: ocean fields
-   USE ice            ! LIM variables
-   USE thd_ice        ! LIM thermodynamics
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_thd_dh      ! called by lim_thd
-   PUBLIC   lim_thd_snwblow ! called in sbcblk/sbcclio/sbccpl and here
-
-   INTERFACE lim_thd_snwblow
-      MODULE PROCEDURE lim_thd_snwblow_1d, lim_thd_snwblow_2d
-   END INTERFACE
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_thd_dh( kideb, kiut )
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_thd_dh  ***
-      !!
-      !! ** Purpose :   determines variations of ice and snow thicknesses.
-      !!
-      !! ** Method  :   Ice/Snow surface melting arises from imbalance in surface fluxes
-      !!              Bottom accretion/ablation arises from flux budget
-      !!              Snow thickness can increase by precipitation and decrease by sublimation
-      !!              If snow load excesses Archmiede limit, snow-ice is formed by
-      !!              the flooding of sea-water in the snow
-      !!
-      !!                 1) Compute available flux of heat for surface ablation
-      !!                 2) Compute snow and sea ice enthalpies
-      !!                 3) Surface ablation and sublimation
-      !!                 4) Bottom accretion/ablation
-      !!                 5) Case of Total ablation
-      !!                 6) Snow ice formation
-      !!
-      !! References : Bitz and Lipscomb, 1999, J. Geophys. Res.
-      !!              Fichefet T. and M. Maqueda 1997, J. Geophys. Res., 102(C6), 12609-12646   
-      !!              Vancoppenolle, Fichefet and Bitz, 2005, Geophys. Res. Let. 
-      !!              Vancoppenolle et al.,2009, Ocean Modelling
-      !!------------------------------------------------------------------
-      INTEGER , INTENT(in) ::   kideb, kiut   ! Start/End point on which the  the computation is applied
-      !! 
-      INTEGER  ::   ji , jk        ! dummy loop indices
-      INTEGER  ::   ii, ij         ! 2D corresponding indices to ji
-      INTEGER  ::   iter
-
-      REAL(wp) ::   ztmelts             ! local scalar
-      REAL(wp) ::   zdum       
-      REAL(wp) ::   zfracs       ! fractionation coefficient for bottom salt entrapment
-      REAL(wp) ::   zswi1        ! switch for computation of bottom salinity
-      REAL(wp) ::   zswi12       ! switch for computation of bottom salinity
-      REAL(wp) ::   zswi2        ! switch for computation of bottom salinity
-      REAL(wp) ::   zgrr         ! bottom growth rate
-      REAL(wp) ::   zt_i_new     ! bottom formation temperature
-
-      REAL(wp) ::   zQm          ! enthalpy exchanged with the ocean (J/m2), >0 towards the ocean
-      REAL(wp) ::   zEi          ! specific enthalpy of sea ice (J/kg)
-      REAL(wp) ::   zEw          ! specific enthalpy of exchanged water (J/kg)
-      REAL(wp) ::   zdE          ! specific enthalpy difference (J/kg)
-      REAL(wp) ::   zfmdt        ! exchange mass flux x time step (J/m2), >0 towards the ocean
-      REAL(wp) ::   zsstK        ! SST in Kelvin
-
-      REAL(wp), POINTER, DIMENSION(:) ::   zqprec      ! energy of fallen snow                       (J.m-3)
-      REAL(wp), POINTER, DIMENSION(:) ::   zq_su       ! heat for surface ablation                   (J.m-2)
-      REAL(wp), POINTER, DIMENSION(:) ::   zq_bo       ! heat for bottom ablation                    (J.m-2)
-      REAL(wp), POINTER, DIMENSION(:) ::   zq_rema     ! remaining heat at the end of the routine    (J.m-2)
-      REAL(wp), POINTER, DIMENSION(:) ::   zf_tt       ! Heat budget to determine melting or freezing(W.m-2)
-      REAL(wp), POINTER, DIMENSION(:) ::   zevap_rema  ! remaining mass flux from sublimation        (kg.m-2)
-
-      REAL(wp), POINTER, DIMENSION(:) ::   zdh_s_mel   ! snow melt 
-      REAL(wp), POINTER, DIMENSION(:) ::   zdh_s_pre   ! snow precipitation 
-      REAL(wp), POINTER, DIMENSION(:) ::   zdh_s_sub   ! snow sublimation
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zdeltah
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zh_i      ! ice layer thickness
-      INTEGER , POINTER, DIMENSION(:,:) ::   icount    ! number of layers vanished by melting 
-
-      REAL(wp), POINTER, DIMENSION(:) ::   zqh_i       ! total ice heat content  (J.m-2)
-      REAL(wp), POINTER, DIMENSION(:) ::   zsnw        ! distribution of snow after wind blowing
-
-      REAL(wp) :: zswitch_sal
-
-      ! Heat conservation 
-      INTEGER  ::   num_iter_max
-
-      !!------------------------------------------------------------------
-
-      ! Discriminate between varying salinity (nn_icesal=2) and prescribed cases (other values)
-      SELECT CASE( nn_icesal )                  ! varying salinity or not
-         CASE( 1, 3 ) ;   zswitch_sal = 0       ! prescribed salinity profile
-         CASE( 2 )    ;   zswitch_sal = 1       ! varying salinity profile
-      END SELECT
-
-      CALL wrk_alloc( jpij, zqprec, zq_su, zq_bo, zf_tt, zq_rema, zsnw, zevap_rema )
-      CALL wrk_alloc( jpij, zdh_s_mel, zdh_s_pre, zdh_s_sub, zqh_i )
-      CALL wrk_alloc( jpij, nlay_i, zdeltah, zh_i )
-      CALL wrk_alloc( jpij, nlay_i, icount )
-       
-      zqprec   (:) = 0._wp ; zq_su    (:) = 0._wp ; zq_bo    (:) = 0._wp ; zf_tt(:) = 0._wp
-      zq_rema  (:) = 0._wp ; zsnw     (:) = 0._wp ; zevap_rema(:) = 0._wp ;
-      zdh_s_mel(:) = 0._wp ; zdh_s_pre(:) = 0._wp ; zdh_s_sub(:) = 0._wp ; zqh_i(:) = 0._wp
-
-      zdeltah(:,:) = 0._wp ; zh_i(:,:) = 0._wp       
-      icount (:,:) = 0
-
-      ! Initialize enthalpy at nlay_i+1
-      DO ji = kideb, kiut
-         q_i_1d(ji,nlay_i+1) = 0._wp
-      END DO
-
-      ! initialize layer thicknesses and enthalpies
-      h_i_old (:,0:nlay_i+1) = 0._wp
-      qh_i_old(:,0:nlay_i+1) = 0._wp
-      DO jk = 1, nlay_i
-         DO ji = kideb, kiut
-            h_i_old (ji,jk) = ht_i_1d(ji) * r1_nlay_i
-            qh_i_old(ji,jk) = q_i_1d(ji,jk) * h_i_old(ji,jk)
-         ENDDO
-      ENDDO
-      !
-      !------------------------------------------------------------------------------!
-      !  1) Calculate available heat for surface and bottom ablation                 !
-      !------------------------------------------------------------------------------!
-      !
-      DO ji = kideb, kiut
-         zdum       = qns_ice_1d(ji) + ( 1._wp - i0(ji) ) * qsr_ice_1d(ji) - fc_su(ji) 
-         zf_tt(ji)  = fc_bo_i(ji) + fhtur_1d(ji) + fhld_1d(ji) 
-
-         zq_su (ji) = MAX( 0._wp, zdum      * rdt_ice ) * MAX( 0._wp , SIGN( 1._wp, t_su_1d(ji) - rt0 ) )
-         zq_bo (ji) = MAX( 0._wp, zf_tt(ji) * rdt_ice )
-      END DO
-
-      !
-      !------------------------------------------------------------------------------!
-      ! If snow temperature is above freezing point, then snow melts 
-      ! (should not happen but sometimes it does)
-      !------------------------------------------------------------------------------!
-      DO ji = kideb, kiut
-         IF( t_s_1d(ji,1) > rt0 ) THEN !!! Internal melting
-            ! Contribution to heat flux to the ocean [W.m-2], < 0  
-            hfx_res_1d(ji) = hfx_res_1d(ji) + q_s_1d(ji,1) * ht_s_1d(ji) * a_i_1d(ji) * r1_rdtice
-            ! Contribution to mass flux
-            wfx_snw_1d(ji) = wfx_snw_1d(ji) + rhosn * ht_s_1d(ji) * a_i_1d(ji) * r1_rdtice
-            ! updates
-            ht_s_1d(ji)   = 0._wp
-            q_s_1d (ji,1) = 0._wp
-            t_s_1d (ji,1) = rt0
-         END IF
-      END DO
-
-      !------------------------------------------------------------!
-      !  2) Computing layer thicknesses and enthalpies.            !
-      !------------------------------------------------------------!
-      !
-      DO jk = 1, nlay_i
-         DO ji = kideb, kiut
-            zh_i(ji,jk) = ht_i_1d(ji) * r1_nlay_i
-            zqh_i(ji)   = zqh_i(ji) + q_i_1d(ji,jk) * zh_i(ji,jk)
-         END DO
-      END DO
-      !
-      !------------------------------------------------------------------------------|
-      !  3) Surface ablation and sublimation                                         |
-      !------------------------------------------------------------------------------|
-      !
-      !-------------------------
-      ! 3.1 Snow precips / melt
-      !-------------------------
-      ! Snow accumulation in one thermodynamic time step
-      ! snowfall is partitionned between leads and ice
-      ! if snow fall was uniform, a fraction (1-at_i) would fall into leads
-      ! but because of the winds, more snow falls on leads than on sea ice
-      ! and a greater fraction (1-at_i)^beta of the total mass of snow 
-      ! (beta < 1) falls in leads.
-      ! In reality, beta depends on wind speed, 
-      ! and should decrease with increasing wind speed but here, it is 
-      ! considered as a constant. an average value is 0.66
-      ! Martin Vancoppenolle, December 2006
-
-      CALL lim_thd_snwblow( 1. - at_i_1d(kideb:kiut), zsnw(kideb:kiut) ) ! snow distribution over ice after wind blowing
-
-      zdeltah(:,:) = 0._wp
-      DO ji = kideb, kiut
-         !-----------
-         ! Snow fall
-         !-----------
-         ! thickness change
-         zdh_s_pre(ji) = zsnw(ji) * sprecip_1d(ji) * rdt_ice * r1_rhosn / at_i_1d(ji)
-         ! enthalpy of the precip (>0, J.m-3)
-         zqprec   (ji) = - qprec_ice_1d(ji)   
-         IF( sprecip_1d(ji) == 0._wp ) zqprec(ji) = 0._wp
-         ! heat flux from snow precip (>0, W.m-2)
-         hfx_spr_1d(ji) = hfx_spr_1d(ji) + zdh_s_pre(ji) * a_i_1d(ji) * zqprec(ji) * r1_rdtice
-         ! mass flux, <0
-         wfx_spr_1d(ji) = wfx_spr_1d(ji) - rhosn * a_i_1d(ji) * zdh_s_pre(ji) * r1_rdtice
-
-         !---------------------
-         ! Melt of falling snow
-         !---------------------
-         ! thickness change
-         rswitch        = MAX( 0._wp , SIGN( 1._wp , zqprec(ji) - epsi20 ) )
-         zdeltah (ji,1) = - rswitch * zq_su(ji) / MAX( zqprec(ji) , epsi20 )
-         zdeltah (ji,1) = MAX( - zdh_s_pre(ji), zdeltah(ji,1) ) ! bound melting 
-         ! heat used to melt snow (W.m-2, >0)
-         hfx_snw_1d(ji) = hfx_snw_1d(ji) - zdeltah(ji,1) * a_i_1d(ji) * zqprec(ji) * r1_rdtice
-         ! snow melting only = water into the ocean (then without snow precip), >0
-         wfx_snw_1d(ji) = wfx_snw_1d(ji) - rhosn * a_i_1d(ji) * zdeltah(ji,1) * r1_rdtice    
-         ! updates available heat + precipitations after melting
-         zq_su     (ji) = MAX( 0._wp , zq_su (ji) + zdeltah(ji,1) * zqprec(ji) )      
-         zdh_s_pre (ji) = zdh_s_pre(ji) + zdeltah(ji,1)
-
-         ! update thickness
-         ht_s_1d(ji) = MAX( 0._wp , ht_s_1d(ji) + zdh_s_pre(ji) )
-      END DO
-
-      ! If heat still available (zq_su > 0), then melt more snow
-      zdeltah(:,:) = 0._wp
-      DO jk = 1, nlay_s
-         DO ji = kideb, kiut
-            ! thickness change
-            rswitch          = 1._wp - MAX( 0._wp, SIGN( 1._wp, - ht_s_1d(ji) ) ) 
-            rswitch          = rswitch * ( MAX( 0._wp, SIGN( 1._wp, q_s_1d(ji,jk) - epsi20 ) ) ) 
-            zdeltah  (ji,jk) = - rswitch * zq_su(ji) / MAX( q_s_1d(ji,jk), epsi20 )
-            zdeltah  (ji,jk) = MAX( zdeltah(ji,jk) , - ht_s_1d(ji) ) ! bound melting
-            zdh_s_mel(ji)    = zdh_s_mel(ji) + zdeltah(ji,jk)    
-            ! heat used to melt snow(W.m-2, >0)
-            hfx_snw_1d(ji)   = hfx_snw_1d(ji) - zdeltah(ji,jk) * a_i_1d(ji) * q_s_1d(ji,jk) * r1_rdtice 
-            ! snow melting only = water into the ocean (then without snow precip)
-            wfx_snw_1d(ji)   = wfx_snw_1d(ji) - rhosn * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
-            ! updates available heat + thickness
-            zq_su (ji)  = MAX( 0._wp , zq_su (ji) + zdeltah(ji,jk) * q_s_1d(ji,jk) )
-            ht_s_1d(ji) = MAX( 0._wp , ht_s_1d(ji) + zdeltah(ji,jk) )
-         END DO
-      END DO
-
-      !------------------------------
-      ! 3.2 Sublimation (part1: snow) 
-      !------------------------------
-      ! qla_ice is always >=0 (upwards), heat goes to the atmosphere, therefore snow sublimates
-      ! clem comment: not counted in mass/heat exchange in limsbc since this is an exchange with atm. (not ocean)
-      zdeltah(:,:) = 0._wp
-      DO ji = kideb, kiut
-         zdh_s_sub(ji)  = MAX( - ht_s_1d(ji) , - evap_ice_1d(ji) * r1_rhosn * rdt_ice )
-         ! remaining evap in kg.m-2 (used for ice melting later on)
-         zevap_rema(ji)  = evap_ice_1d(ji) * rdt_ice + zdh_s_sub(ji) * rhosn
-         ! Heat flux by sublimation [W.m-2], < 0 (sublimate first snow that had fallen, then pre-existing snow)
-         zdeltah(ji,1)  = MAX( zdh_s_sub(ji), - zdh_s_pre(ji) )
-         hfx_sub_1d(ji) = hfx_sub_1d(ji) + ( zdeltah(ji,1) * zqprec(ji) + ( zdh_s_sub(ji) - zdeltah(ji,1) ) * q_s_1d(ji,1)  &
-            &                              ) * a_i_1d(ji) * r1_rdtice
-         ! Mass flux by sublimation
-         wfx_sub_1d(ji) =  wfx_sub_1d(ji) - rhosn * a_i_1d(ji) * zdh_s_sub(ji) * r1_rdtice
-         ! new snow thickness
-         ht_s_1d(ji)    =  MAX( 0._wp , ht_s_1d(ji) + zdh_s_sub(ji) )
-         ! update precipitations after sublimation and correct sublimation
-         zdh_s_pre(ji) = zdh_s_pre(ji) + zdeltah(ji,1)
-         zdh_s_sub(ji) = zdh_s_sub(ji) - zdeltah(ji,1)
-      END DO
-      
-      ! --- Update snow diags --- !
-      DO ji = kideb, kiut
-         dh_s_tot(ji) = zdh_s_mel(ji) + zdh_s_pre(ji) + zdh_s_sub(ji)
-      END DO
-
-      !-------------------------------------------
-      ! 3.3 Update temperature, energy
-      !-------------------------------------------
-      ! new temp and enthalpy of the snow (remaining snow precip + remaining pre-existing snow)
-      DO jk = 1, nlay_s
-         DO ji = kideb,kiut
-            rswitch       = MAX( 0._wp , SIGN( 1._wp, ht_s_1d(ji) - epsi20 ) )
-            q_s_1d(ji,jk) = rswitch / MAX( ht_s_1d(ji), epsi20 ) *           &
-              &            ( ( zdh_s_pre(ji)               ) * zqprec(ji) +  &
-              &              ( ht_s_1d(ji) - zdh_s_pre(ji) ) * rhosn * ( cpic * ( rt0 - t_s_1d(ji,jk) ) + lfus ) )
-         END DO
-      END DO
-
-      !--------------------------
-      ! 3.4 Surface ice ablation 
-      !--------------------------
-      zdeltah(:,:) = 0._wp ! important
-      DO jk = 1, nlay_i
-         DO ji = kideb, kiut
-            ztmelts           = - tmut * s_i_1d(ji,jk) + rt0          ! Melting point of layer k [K]
-            
-            IF( t_i_1d(ji,jk) >= ztmelts ) THEN !!! Internal melting
-
-               zEi            = - q_i_1d(ji,jk) * r1_rhoic            ! Specific enthalpy of layer k [J/kg, <0]       
-               zdE            = 0._wp                                 ! Specific enthalpy difference   (J/kg, <0)
-                                                                      ! set up at 0 since no energy is needed to melt water...(it is already melted)
-               zdeltah(ji,jk) = MIN( 0._wp , - zh_i(ji,jk) )          ! internal melting occurs when the internal temperature is above freezing     
-                                                                      ! this should normally not happen, but sometimes, heat diffusion leads to this
-               zfmdt          = - zdeltah(ji,jk) * rhoic              ! Mass flux x time step > 0
-                         
-               dh_i_surf(ji)  = dh_i_surf(ji) + zdeltah(ji,jk)        ! Cumulate surface melt
-               
-               zfmdt          = - rhoic * zdeltah(ji,jk)              ! Recompute mass flux [kg/m2, >0]
-
-               ! Contribution to heat flux to the ocean [W.m-2], <0 (ice enthalpy zEi is "sent" to the ocean) 
-               hfx_res_1d(ji) = hfx_res_1d(ji) + zfmdt * a_i_1d(ji) * zEi * r1_rdtice
-               
-               ! Contribution to salt flux (clem: using sm_i_1d and not s_i_1d(jk) is ok)
-               sfx_res_1d(ji) = sfx_res_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * sm_i_1d(ji) * r1_rdtice
-               
-               ! Contribution to mass flux
-               wfx_res_1d(ji) =  wfx_res_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
-
-            ELSE                                !!! Surface melting
-               
-               zEi            = - q_i_1d(ji,jk) * r1_rhoic            ! Specific enthalpy of layer k [J/kg, <0]
-               zEw            =    rcp * ( ztmelts - rt0 )            ! Specific enthalpy of resulting meltwater [J/kg, <0]
-               zdE            =    zEi - zEw                          ! Specific enthalpy difference < 0
-               
-               zfmdt          = - zq_su(ji) / zdE                     ! Mass flux to the ocean [kg/m2, >0]
-               
-               zdeltah(ji,jk) = - zfmdt * r1_rhoic                    ! Melt of layer jk [m, <0]
-               
-               zdeltah(ji,jk) = MIN( 0._wp , MAX( zdeltah(ji,jk) , - zh_i(ji,jk) ) )    ! Melt of layer jk cannot exceed the layer thickness [m, <0]
-               
-               zq_su(ji)      = MAX( 0._wp , zq_su(ji) - zdeltah(ji,jk) * rhoic * zdE ) ! update available heat
-               
-               dh_i_surf(ji)  = dh_i_surf(ji) + zdeltah(ji,jk)        ! Cumulate surface melt
-               
-               zfmdt          = - rhoic * zdeltah(ji,jk)              ! Recompute mass flux [kg/m2, >0]
-               
-               zQm            = zfmdt * zEw                           ! Energy of the melt water sent to the ocean [J/m2, <0]
-               
-               ! Contribution to salt flux >0 (clem: using sm_i_1d and not s_i_1d(jk) is ok)
-               sfx_sum_1d(ji) = sfx_sum_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * sm_i_1d(ji) * r1_rdtice
-               
-               ! Contribution to heat flux [W.m-2], < 0
-               hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice
-               
-               ! Total heat flux used in this process [W.m-2], > 0  
-               hfx_sum_1d(ji) = hfx_sum_1d(ji) - zfmdt * a_i_1d(ji) * zdE * r1_rdtice
-               
-               ! Contribution to mass flux
-               wfx_sum_1d(ji) =  wfx_sum_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
-               
-            END IF
-            ! ----------------------
-            ! Sublimation part2: ice
-            ! ----------------------
-            zdum      = MAX( - ( zh_i(ji,jk) + zdeltah(ji,jk) ) , - zevap_rema(ji) * r1_rhoic )
-            zdeltah(ji,jk) = zdeltah(ji,jk) + zdum
-            dh_i_sub(ji)  = dh_i_sub(ji) + zdum
-            ! Salt flux > 0 (clem2016: flux is sent to the ocean for simplicity but salt should remain in the ice except if all ice is melted.
-            !                          It must be corrected at some point)
-            sfx_sub_1d(ji) = sfx_sub_1d(ji) - rhoic * a_i_1d(ji) * zdum * sm_i_1d(ji) * r1_rdtice
-            ! Heat flux [W.m-2], < 0
-            hfx_sub_1d(ji) = hfx_sub_1d(ji) + zdum * q_i_1d(ji,jk) * a_i_1d(ji) * r1_rdtice
-            ! Mass flux > 0
-            wfx_sub_1d(ji) =  wfx_sub_1d(ji) - rhoic * a_i_1d(ji) * zdum * r1_rdtice
-            ! update remaining mass flux
-            zevap_rema(ji)  = zevap_rema(ji) + zdum * rhoic
-            
-            ! record which layers have disappeared (for bottom melting) 
-            !    => icount=0 : no layer has vanished
-            !    => icount=5 : 5 layers have vanished
-            rswitch       = MAX( 0._wp , SIGN( 1._wp , - ( zh_i(ji,jk) + zdeltah(ji,jk) ) ) ) 
-            icount(ji,jk) = NINT( rswitch )
-            zh_i(ji,jk)   = MAX( 0._wp , zh_i(ji,jk) + zdeltah(ji,jk) )
-                        
-            ! update heat content (J.m-2) and layer thickness
-            qh_i_old(ji,jk) = qh_i_old(ji,jk) + zdeltah(ji,jk) * q_i_1d(ji,jk)
-            h_i_old (ji,jk) = h_i_old (ji,jk) + zdeltah(ji,jk)
-         END DO
-      END DO
-      ! update ice thickness
-      DO ji = kideb, kiut
-         ht_i_1d(ji) =  MAX( 0._wp , ht_i_1d(ji) + dh_i_surf(ji) + dh_i_sub(ji) )
-      END DO
-
-      ! remaining "potential" evap is sent to ocean
-      DO ji = kideb, kiut
-         ii = MOD( npb(ji) - 1, jpi ) + 1 ; ij = ( npb(ji) - 1 ) / jpi + 1
-         wfx_err_sub(ii,ij) = wfx_err_sub(ii,ij) - zevap_rema(ji) * a_i_1d(ji) * r1_rdtice  ! <=0 (net evap for the ocean in kg.m-2.s-1)
-      END DO
-
-      !
-      !------------------------------------------------------------------------------!
-      ! 4) Basal growth / melt                                                       !
-      !------------------------------------------------------------------------------!
-      !
-      !------------------
-      ! 4.1 Basal growth 
-      !------------------
-      ! Basal growth is driven by heat imbalance at the ice-ocean interface,
-      ! between the inner conductive flux  (fc_bo_i), from the open water heat flux 
-      ! (fhld) and the turbulent ocean flux (fhtur). 
-      ! fc_bo_i is positive downwards. fhtur and fhld are positive to the ice 
-
-      ! If salinity varies in time, an iterative procedure is required, because
-      ! the involved quantities are inter-dependent.
-      ! Basal growth (dh_i_bott) depends upon new ice specific enthalpy (zEi),
-      ! which depends on forming ice salinity (s_i_new), which depends on dh/dt (dh_i_bott)
-      ! -> need for an iterative procedure, which converges quickly
-
-      num_iter_max = 1
-      IF( nn_icesal == 2 ) num_iter_max = 5
-
-      ! Iterative procedure
-      DO iter = 1, num_iter_max
-         DO ji = kideb, kiut
-            IF(  zf_tt(ji) < 0._wp  ) THEN
-
-               ! New bottom ice salinity (Cox & Weeks, JGR88 )
-               !--- zswi1  if dh/dt < 2.0e-8
-               !--- zswi12 if 2.0e-8 < dh/dt < 3.6e-7 
-               !--- zswi2  if dh/dt > 3.6e-7
-               zgrr               = MIN( 1.0e-3, MAX ( dh_i_bott(ji) * r1_rdtice , epsi10 ) )
-               zswi2              = MAX( 0._wp , SIGN( 1._wp , zgrr - 3.6e-7 ) )
-               zswi12             = MAX( 0._wp , SIGN( 1._wp , zgrr - 2.0e-8 ) ) * ( 1.0 - zswi2 )
-               zswi1              = 1. - zswi2 * zswi12
-               zfracs             = MIN ( zswi1  * 0.12 + zswi12 * ( 0.8925 + 0.0568 * LOG( 100.0 * zgrr ) )   &
-                  &               + zswi2  * 0.26 / ( 0.26 + 0.74 * EXP ( - 724300.0 * zgrr ) )  , 0.5 )
-
-               ii = MOD( npb(ji) - 1, jpi ) + 1 ; ij = ( npb(ji) - 1 ) / jpi + 1
-
-               s_i_new(ji)        = zswitch_sal * zfracs * sss_m(ii,ij)  &  ! New ice salinity
-                                  + ( 1. - zswitch_sal ) * sm_i_1d(ji) 
-               ! New ice growth
-               ztmelts            = - tmut * s_i_new(ji) + rt0          ! New ice melting point (K)
-
-               zt_i_new           = zswitch_sal * t_bo_1d(ji) + ( 1. - zswitch_sal) * t_i_1d(ji, nlay_i)
-               
-               zEi                = cpic * ( zt_i_new - ztmelts ) &     ! Specific enthalpy of forming ice (J/kg, <0)      
-                  &               - lfus * ( 1.0 - ( ztmelts - rt0 ) / ( zt_i_new - rt0 ) )   &
-                  &               + rcp  * ( ztmelts-rt0 )          
-
-               zEw                = rcp  * ( t_bo_1d(ji) - rt0 )         ! Specific enthalpy of seawater (J/kg, < 0)
-
-               zdE                = zEi - zEw                           ! Specific enthalpy difference (J/kg, <0)
-
-               dh_i_bott(ji)      = rdt_ice * MAX( 0._wp , zf_tt(ji) / ( zdE * rhoic ) )
-
-               q_i_1d(ji,nlay_i+1) = -zEi * rhoic                        ! New ice energy of melting (J/m3, >0)
-               
-            ENDIF
-         END DO
-      END DO
-
-      ! Contribution to Energy and Salt Fluxes
-      DO ji = kideb, kiut
-         IF(  zf_tt(ji) < 0._wp  ) THEN
-            ! New ice growth
-                                    
-            zfmdt          = - rhoic * dh_i_bott(ji)             ! Mass flux x time step (kg/m2, < 0)
-
-            ztmelts        = - tmut * s_i_new(ji) + rt0          ! New ice melting point (K)
-            
-            zt_i_new       = zswitch_sal * t_bo_1d(ji) + ( 1. - zswitch_sal) * t_i_1d(ji, nlay_i)
-            
-            zEi            = cpic * ( zt_i_new - ztmelts ) &     ! Specific enthalpy of forming ice (J/kg, <0)      
-               &               - lfus * ( 1.0 - ( ztmelts - rt0 ) / ( zt_i_new - rt0 ) )   &
-               &               + rcp  * ( ztmelts-rt0 )          
-            
-            zEw            = rcp  * ( t_bo_1d(ji) - rt0 )         ! Specific enthalpy of seawater (J/kg, < 0)
-            
-            zdE            = zEi - zEw                           ! Specific enthalpy difference (J/kg, <0)
-            
-            ! Contribution to heat flux to the ocean [W.m-2], >0  
-            hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice
-
-            ! Total heat flux used in this process [W.m-2], <0  
-            hfx_bog_1d(ji) = hfx_bog_1d(ji) - zfmdt * a_i_1d(ji) * zdE * r1_rdtice
-            
-            ! Contribution to salt flux, <0
-            sfx_bog_1d(ji) = sfx_bog_1d(ji) - rhoic * a_i_1d(ji) * dh_i_bott(ji) * s_i_new(ji) * r1_rdtice
-
-            ! Contribution to mass flux, <0
-            wfx_bog_1d(ji) =  wfx_bog_1d(ji) - rhoic * a_i_1d(ji) * dh_i_bott(ji) * r1_rdtice
-
-            ! update heat content (J.m-2) and layer thickness
-            qh_i_old(ji,nlay_i+1) = qh_i_old(ji,nlay_i+1) + dh_i_bott(ji) * q_i_1d(ji,nlay_i+1)
-            h_i_old (ji,nlay_i+1) = h_i_old (ji,nlay_i+1) + dh_i_bott(ji)
-         ENDIF
-      END DO
-
-      !----------------
-      ! 4.2 Basal melt
-      !----------------
-      zdeltah(:,:) = 0._wp ! important
-      DO jk = nlay_i, 1, -1
-         DO ji = kideb, kiut
-            IF(  zf_tt(ji)  >  0._wp  .AND. jk > icount(ji,jk) ) THEN   ! do not calculate where layer has already disappeared by surface melting 
-
-               ztmelts = - tmut * s_i_1d(ji,jk) + rt0  ! Melting point of layer jk (K)
-
-               IF( t_i_1d(ji,jk) >= ztmelts ) THEN !!! Internal melting
-
-                  zEi               = - q_i_1d(ji,jk) * r1_rhoic    ! Specific enthalpy of melting ice (J/kg, <0)
-                  zdE               = 0._wp                         ! Specific enthalpy difference   (J/kg, <0)
-                                                                    ! set up at 0 since no energy is needed to melt water...(it is already melted)
-                  zdeltah   (ji,jk) = MIN( 0._wp , - zh_i(ji,jk) )  ! internal melting occurs when the internal temperature is above freezing     
-                                                                    ! this should normally not happen, but sometimes, heat diffusion leads to this
-
-                  dh_i_bott (ji)    = dh_i_bott(ji) + zdeltah(ji,jk)
-
-                  zfmdt             = - zdeltah(ji,jk) * rhoic      ! Mass flux x time step > 0
-
-                  ! Contribution to heat flux to the ocean [W.m-2], <0 (ice enthalpy zEi is "sent" to the ocean) 
-                  hfx_res_1d(ji) = hfx_res_1d(ji) + zfmdt * a_i_1d(ji) * zEi * r1_rdtice
-
-                  ! Contribution to salt flux (clem: using sm_i_1d and not s_i_1d(jk) is ok)
-                  sfx_res_1d(ji) = sfx_res_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * sm_i_1d(ji) * r1_rdtice
-                                    
-                  ! Contribution to mass flux
-                  wfx_res_1d(ji) =  wfx_res_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
-
-                  ! update heat content (J.m-2) and layer thickness
-                  qh_i_old(ji,jk) = qh_i_old(ji,jk) + zdeltah(ji,jk) * q_i_1d(ji,jk)
-                  h_i_old (ji,jk) = h_i_old (ji,jk) + zdeltah(ji,jk)
-
-               ELSE                               !!! Basal melting
-
-                  zEi             = - q_i_1d(ji,jk) * r1_rhoic ! Specific enthalpy of melting ice (J/kg, <0)
-                  zEw             = rcp * ( ztmelts - rt0 )    ! Specific enthalpy of meltwater (J/kg, <0)
-                  zdE             = zEi - zEw                  ! Specific enthalpy difference   (J/kg, <0)
-
-                  zfmdt           = - zq_bo(ji) / zdE          ! Mass flux x time step (kg/m2, >0)
-
-                  zdeltah(ji,jk)  = - zfmdt * r1_rhoic         ! Gross thickness change
-
-                  zdeltah(ji,jk)  = MIN( 0._wp , MAX( zdeltah(ji,jk), - zh_i(ji,jk) ) ) ! bound thickness change
-                  
-                  zq_bo(ji)       = MAX( 0._wp , zq_bo(ji) - zdeltah(ji,jk) * rhoic * zdE ) ! update available heat. MAX is necessary for roundup errors
-
-                  dh_i_bott(ji)   = dh_i_bott(ji) + zdeltah(ji,jk)    ! Update basal melt
-
-                  zfmdt           = - zdeltah(ji,jk) * rhoic          ! Mass flux x time step > 0
-
-                  zQm             = zfmdt * zEw         ! Heat exchanged with ocean
-
-                  ! Contribution to heat flux to the ocean [W.m-2], <0  
-                  hfx_thd_1d(ji)  = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice
-
-                  ! Contribution to salt flux (clem: using sm_i_1d and not s_i_1d(jk) is ok)
-                  sfx_bom_1d(ji)  = sfx_bom_1d(ji) - rhoic *  a_i_1d(ji) * zdeltah(ji,jk) * sm_i_1d(ji) * r1_rdtice
-                  
-                  ! Total heat flux used in this process [W.m-2], >0  
-                  hfx_bom_1d(ji)  = hfx_bom_1d(ji) - zfmdt * a_i_1d(ji) * zdE * r1_rdtice
-                  
-                  ! Contribution to mass flux
-                  wfx_bom_1d(ji)  =  wfx_bom_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
-
-                  ! update heat content (J.m-2) and layer thickness
-                  qh_i_old(ji,jk) = qh_i_old(ji,jk) + zdeltah(ji,jk) * q_i_1d(ji,jk)
-                  h_i_old (ji,jk) = h_i_old (ji,jk) + zdeltah(ji,jk)
-               ENDIF
-           
-            ENDIF
-         END DO
-      END DO
-
-      !-------------------------------------------
-      ! Update temperature, energy
-      !-------------------------------------------
-      DO ji = kideb, kiut
-         ht_i_1d(ji) =  MAX( 0._wp , ht_i_1d(ji) + dh_i_bott(ji) )
-      END DO  
-
-      !-------------------------------------------
-      ! 5. What to do with remaining energy
-      !-------------------------------------------
-      ! If heat still available for melting and snow remains, then melt more snow
-      !-------------------------------------------
-      zdeltah(:,:) = 0._wp ! important
-      DO ji = kideb, kiut
-         zq_rema(ji)     = zq_su(ji) + zq_bo(ji) 
-         rswitch         = 1._wp - MAX( 0._wp, SIGN( 1._wp, - ht_s_1d(ji) ) )   ! =1 if snow
-         rswitch         = rswitch * MAX( 0._wp, SIGN( 1._wp, q_s_1d(ji,1) - epsi20 ) )
-         zdeltah  (ji,1) = - rswitch * zq_rema(ji) / MAX( q_s_1d(ji,1), epsi20 )
-         zdeltah  (ji,1) = MIN( 0._wp , MAX( zdeltah(ji,1) , - ht_s_1d(ji) ) ) ! bound melting
-         dh_s_tot (ji)   = dh_s_tot(ji)  + zdeltah(ji,1)
-         ht_s_1d   (ji)  = ht_s_1d(ji)   + zdeltah(ji,1)
-        
-         zq_rema(ji)     = zq_rema(ji) + zdeltah(ji,1) * q_s_1d(ji,1)                ! update available heat (J.m-2)
-         ! heat used to melt snow
-         hfx_snw_1d(ji)  = hfx_snw_1d(ji) - zdeltah(ji,1) * a_i_1d(ji) * q_s_1d(ji,1) * r1_rdtice ! W.m-2 (>0)
-         ! Contribution to mass flux
-         wfx_snw_1d(ji)  =  wfx_snw_1d(ji) - rhosn * a_i_1d(ji) * zdeltah(ji,1) * r1_rdtice
-         !    
-         ii = MOD( npb(ji) - 1, jpi ) + 1 ; ij = ( npb(ji) - 1 ) / jpi + 1
-         ! Remaining heat flux (W.m-2) is sent to the ocean heat budget
-         hfx_out(ii,ij)  = hfx_out(ii,ij) + ( zq_rema(ji) * a_i_1d(ji) ) * r1_rdtice
-
-         IF( ln_limctl .AND. zq_rema(ji) < 0. .AND. lwp ) WRITE(numout,*) 'ALERTE zq_rema <0 = ', zq_rema(ji)
-      END DO
-      
-      !
-      !------------------------------------------------------------------------------|
-      !  6) Snow-Ice formation                                                       |
-      !------------------------------------------------------------------------------|
-      ! When snow load excesses Archimede's limit, snow-ice interface goes down under sea-level, 
-      ! flooding of seawater transforms snow into ice dh_snowice is positive for the ice
-      DO ji = kideb, kiut
-         !
-         dh_snowice(ji) = MAX(  0._wp , ( rhosn * ht_s_1d(ji) + (rhoic-rau0) * ht_i_1d(ji) ) / ( rhosn+rau0-rhoic )  )
-
-         ht_i_1d(ji)    = ht_i_1d(ji) + dh_snowice(ji)
-         ht_s_1d(ji)    = ht_s_1d(ji) - dh_snowice(ji)
-
-         ! Contribution to energy flux to the ocean [J/m2], >0 (if sst<0)
-         ii = MOD( npb(ji) - 1, jpi ) + 1 ; ij = ( npb(ji) - 1 ) / jpi + 1
-         zfmdt          = ( rhosn - rhoic ) * dh_snowice(ji)    ! <0
-         zsstK          = sst_m(ii,ij) + rt0                                
-         zEw            = rcp * ( zsstK - rt0 )
-         zQm            = zfmdt * zEw 
-         
-         ! Contribution to heat flux
-         hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice 
-
-         ! Contribution to salt flux
-         sfx_sni_1d(ji) = sfx_sni_1d(ji) + sss_m(ii,ij) * a_i_1d(ji) * zfmdt * r1_rdtice 
-
-         ! virtual salt flux to keep salinity constant
-         IF( nn_icesal == 1 .OR. nn_icesal == 3 )  THEN
-            sfx_bri_1d(ji) = sfx_bri_1d(ji) - sss_m(ii,ij) * a_i_1d(ji) * zfmdt                  * r1_rdtice  & ! put back sss_m     into the ocean
-               &                            - sm_i_1d(ji)  * a_i_1d(ji) * dh_snowice(ji) * rhoic * r1_rdtice    ! and get  rn_icesal from the ocean 
-         ENDIF
-
-         ! Contribution to mass flux
-         ! All snow is thrown in the ocean, and seawater is taken to replace the volume
-         wfx_sni_1d(ji) = wfx_sni_1d(ji) - a_i_1d(ji) * dh_snowice(ji) * rhoic * r1_rdtice
-         wfx_snw_1d(ji) = wfx_snw_1d(ji) + a_i_1d(ji) * dh_snowice(ji) * rhosn * r1_rdtice
-
-         ! update heat content (J.m-2) and layer thickness
-         qh_i_old(ji,0) = qh_i_old(ji,0) + dh_snowice(ji) * q_s_1d(ji,1) + zfmdt * zEw
-         h_i_old (ji,0) = h_i_old (ji,0) + dh_snowice(ji)
-         
-      END DO
-
-      !
-      !-------------------------------------------
-      ! Update temperature, energy
-      !-------------------------------------------
-      DO ji = kideb, kiut
-         rswitch     =  1.0 - MAX( 0._wp , SIGN( 1._wp , - ht_i_1d(ji) ) ) 
-         t_su_1d(ji) =  rswitch * t_su_1d(ji) + ( 1.0 - rswitch ) * rt0
-      END DO
-
-      DO jk = 1, nlay_s
-         DO ji = kideb,kiut
-            ! mask enthalpy
-            rswitch       = 1._wp - MAX(  0._wp , SIGN( 1._wp, - ht_s_1d(ji) )  )
-            q_s_1d(ji,jk) = rswitch * q_s_1d(ji,jk)
-            ! recalculate t_s_1d from q_s_1d
-            t_s_1d(ji,jk) = rt0 + rswitch * ( - q_s_1d(ji,jk) / ( rhosn * cpic ) + lfus / cpic )
-         END DO
-      END DO
-
-      ! --- ensure that a_i = 0 where ht_i = 0 ---
-      WHERE( ht_i_1d == 0._wp ) a_i_1d = 0._wp
-      
-      CALL wrk_dealloc( jpij, zqprec, zq_su, zq_bo, zf_tt, zq_rema, zsnw, zevap_rema )
-      CALL wrk_dealloc( jpij, zdh_s_mel, zdh_s_pre, zdh_s_sub, zqh_i )
-      CALL wrk_dealloc( jpij, nlay_i, zdeltah, zh_i )
-      CALL wrk_dealloc( jpij, nlay_i, icount )
-      !
-      !
-   END SUBROUTINE lim_thd_dh
-
-
-   !!--------------------------------------------------------------------------
-   !! INTERFACE lim_thd_snwblow
-   !! ** Purpose :   Compute distribution of precip over the ice
-   !!--------------------------------------------------------------------------
-   SUBROUTINE lim_thd_snwblow_2d( pin, pout )
-      REAL(wp), DIMENSION(:,:), INTENT(in   ) :: pin   ! previous fraction lead ( pfrld or (1. - a_i_b) )
-      REAL(wp), DIMENSION(:,:), INTENT(inout) :: pout
-      pout = ( 1._wp - ( pin )**rn_betas )
-   END SUBROUTINE lim_thd_snwblow_2d
-
-   SUBROUTINE lim_thd_snwblow_1d( pin, pout )
-      REAL(wp), DIMENSION(:), INTENT(in   ) :: pin
-      REAL(wp), DIMENSION(:), INTENT(inout) :: pout
-      pout = ( 1._wp - ( pin )**rn_betas )
-   END SUBROUTINE lim_thd_snwblow_1d
-
-   
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                               NO  LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_thd_dh          ! Empty routine
-   END SUBROUTINE lim_thd_dh
-#endif
-
-   !!======================================================================
-END MODULE limthd_dh
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limthd_dif.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limthd_dif.F90	(revision 9018)
+++ 	(revision )
@@ -1,846 +1,0 @@
-MODULE limthd_dif
-   !!======================================================================
-   !!                       ***  MODULE limthd_dif ***
-   !!                       heat diffusion in sea ice 
-   !!                   computation of surface and inner T  
-   !!======================================================================
-   !! History :  LIM  ! 02-2003 (M. Vancoppenolle) original 1D code
-   !!                 ! 06-2005 (M. Vancoppenolle) 3d version
-   !!                 ! 11-2006 (X Fettweis) Vectorization by Xavier
-   !!                 ! 04-2007 (M. Vancoppenolle) Energy conservation
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!             -   ! 2012-05 (C. Rousset) add penetration solar flux
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-   USE phycst         ! physical constants (ocean directory) 
-   USE ice            ! LIM-3 variables
-   USE thd_ice        ! LIM-3: thermodynamics
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_thd_dif   ! called by lim_thd
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_thd_dif( kideb , kiut )
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_thd_dif  ***
-      !! ** Purpose :
-      !!           This routine determines the time evolution of snow and sea-ice 
-      !!           temperature profiles.
-      !! ** Method  :
-      !!           This is done by solving the heat equation diffusion with
-      !!           a Neumann boundary condition at the surface and a Dirichlet one
-      !!           at the bottom. Solar radiation is partially absorbed into the ice.
-      !!           The specific heat and thermal conductivities depend on ice salinity
-      !!           and temperature to take into account brine pocket melting. The 
-      !!           numerical
-      !!           scheme is an iterative Crank-Nicolson on a non-uniform multilayer grid 
-      !!           in the ice and snow system.
-      !!
-      !!           The successive steps of this routine are
-      !!           1.  Thermal conductivity at the interfaces of the ice layers
-      !!           2.  Internal absorbed radiation
-      !!           3.  Scale factors due to non-uniform grid
-      !!           4.  Kappa factors
-      !!           Then iterative procedure begins
-      !!           5.  specific heat in the ice
-      !!           6.  eta factors
-      !!           7.  surface flux computation
-      !!           8.  tridiagonal system terms
-      !!           9.  solving the tridiagonal system with Gauss elimination
-      !!           Iterative procedure ends according to a criterion on evolution
-      !!           of temperature
-      !!
-      !! ** Arguments :
-      !!           kideb , kiut : Starting and ending points on which the 
-      !!                         the computation is applied
-      !!
-      !! ** Inputs / Ouputs : (global commons)
-      !!           surface temperature : t_su_1d
-      !!           ice/snow temperatures   : t_i_1d, t_s_1d
-      !!           ice salinities          : s_i_1d
-      !!           number of layers in the ice/snow: nlay_i, nlay_s
-      !!           profile of the ice/snow layers : z_i, z_s
-      !!           total ice/snow thickness : ht_i_1d, ht_s_1d
-      !!
-      !! ** External : 
-      !!
-      !! ** References :
-      !!
-      !! ** History :
-      !!           (02-2003) Martin Vancoppenolle, Louvain-la-Neuve, Belgium
-      !!           (06-2005) Martin Vancoppenolle, 3d version
-      !!           (11-2006) Vectorized by Xavier Fettweis (UCL-ASTR)
-      !!           (04-2007) Energy conservation tested by M. Vancoppenolle
-      !!------------------------------------------------------------------
-      INTEGER , INTENT(in) ::   kideb, kiut   ! Start/End point on which the  the computation is applied
-
-      !! * Local variables
-      INTEGER ::   ji          ! spatial loop index
-      INTEGER ::   ii, ij      ! temporary dummy loop index
-      INTEGER ::   numeq       ! current reference number of equation
-      INTEGER ::   jk       ! vertical dummy loop index 
-      INTEGER ::   nconv       ! number of iterations in iterative procedure
-      INTEGER ::   minnumeqmin, maxnumeqmax
-      
-      INTEGER, POINTER, DIMENSION(:) ::   numeqmin   ! reference number of top equation
-      INTEGER, POINTER, DIMENSION(:) ::   numeqmax   ! reference number of bottom equation
-      
-      REAL(wp) ::   zg1s      =  2._wp        ! for the tridiagonal system
-      REAL(wp) ::   zg1       =  2._wp        !
-      REAL(wp) ::   zgamma    =  18009._wp    ! for specific heat
-      REAL(wp) ::   zbeta     =  0.117_wp     ! for thermal conductivity (could be 0.13)
-      REAL(wp) ::   zraext_s  =  10._wp       ! extinction coefficient of radiation in the snow
-      REAL(wp) ::   zkimin    =  0.10_wp      ! minimum ice thermal conductivity
-      REAL(wp) ::   ztsu_err  =  1.e-5_wp     ! range around which t_su is considered as 0°C 
-      REAL(wp) ::   ztmelt_i    ! ice melting temperature
-      REAL(wp) ::   zerritmax   ! current maximal error on temperature 
-      REAL(wp) ::   zhsu
-      
-      REAL(wp), POINTER, DIMENSION(:)     ::   isnow       ! switch for presence (1) or absence (0) of snow
-      REAL(wp), POINTER, DIMENSION(:)     ::   ztsub       ! old surface temperature (before the iterative procedure )
-      REAL(wp), POINTER, DIMENSION(:)     ::   ztsubit     ! surface temperature at previous iteration
-      REAL(wp), POINTER, DIMENSION(:)     ::   zh_i        ! ice layer thickness
-      REAL(wp), POINTER, DIMENSION(:)     ::   zh_s        ! snow layer thickness
-      REAL(wp), POINTER, DIMENSION(:)     ::   zfsw        ! solar radiation absorbed at the surface
-      REAL(wp), POINTER, DIMENSION(:)     ::   zqns_ice_b  ! solar radiation absorbed at the surface
-      REAL(wp), POINTER, DIMENSION(:)     ::   zf          ! surface flux function
-      REAL(wp), POINTER, DIMENSION(:)     ::   dzf         ! derivative of the surface flux function
-      REAL(wp), POINTER, DIMENSION(:)     ::   zerrit      ! current error on temperature
-      REAL(wp), POINTER, DIMENSION(:)     ::   zdifcase    ! case of the equation resolution (1->4)
-      REAL(wp), POINTER, DIMENSION(:)     ::   zftrice     ! solar radiation transmitted through the ice
-      REAL(wp), POINTER, DIMENSION(:)     ::   zihic
-      
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   ztcond_i    ! Ice thermal conductivity
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zradtr_i    ! Radiation transmitted through the ice
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zradab_i    ! Radiation absorbed in the ice
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zkappa_i    ! Kappa factor in the ice
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   ztib        ! Old temperature in the ice
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zeta_i      ! Eta factor in the ice
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   ztitemp     ! Temporary temperature in the ice to check the convergence
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zspeche_i   ! Ice specific heat
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   z_i         ! Vertical cotes of the layers in the ice
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zradtr_s    ! Radiation transmited through the snow
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zradab_s    ! Radiation absorbed in the snow
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zkappa_s    ! Kappa factor in the snow
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zeta_s      ! Eta factor in the snow
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   ztstemp     ! Temporary temperature in the snow to check the convergence
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   ztsb        ! Temporary temperature in the snow
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   z_s         ! Vertical cotes of the layers in the snow
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zindterm    ! 'Ind'ependent term
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zindtbis    ! Temporary 'ind'ependent term
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zdiagbis    ! Temporary 'dia'gonal term
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrid       ! Tridiagonal system terms
-      
-      ! diag errors on heat
-      REAL(wp), POINTER, DIMENSION(:)     :: zdq, zq_ini, zhfx_err
-      
-      ! Mono-category
-      REAL(wp)                            :: zepsilon      ! determines thres. above which computation of G(h) is done
-      REAL(wp)                            :: zratio_s      ! dummy factor
-      REAL(wp)                            :: zratio_i      ! dummy factor
-      REAL(wp)                            :: zh_thres      ! thickness thres. for G(h) computation
-      REAL(wp)                            :: zhe           ! dummy factor
-      REAL(wp)                            :: zkimean       ! mean sea ice thermal conductivity
-      REAL(wp)                            :: zfac          ! dummy factor
-      REAL(wp)                            :: zihe          ! dummy factor
-      REAL(wp)                            :: zheshth       ! dummy factor
-      
-      REAL(wp), POINTER, DIMENSION(:)     :: zghe          ! G(he), th. conduct enhancement factor, mono-cat
-      
-      !!------------------------------------------------------------------     
-      ! 
-      CALL wrk_alloc( jpij, numeqmin, numeqmax )
-      CALL wrk_alloc( jpij, isnow, ztsub, ztsubit, zh_i, zh_s, zfsw )
-      CALL wrk_alloc( jpij, zf, dzf, zqns_ice_b, zerrit, zdifcase, zftrice, zihic, zghe )
-      CALL wrk_alloc( jpij,nlay_i+1, ztcond_i, zradtr_i, zradab_i, zkappa_i, ztib, zeta_i, ztitemp, z_i, zspeche_i, kjstart=0 )
-      CALL wrk_alloc( jpij,nlay_s+1,           zradtr_s, zradab_s, zkappa_s, ztsb, zeta_s, ztstemp, z_s, kjstart=0 )
-      CALL wrk_alloc( jpij,nlay_i+3, zindterm, zindtbis, zdiagbis  )
-      CALL wrk_alloc( jpij,nlay_i+3,3, ztrid )
-
-      CALL wrk_alloc( jpij, zdq, zq_ini, zhfx_err )
-
-      ! --- diag error on heat diffusion - PART 1 --- !
-      zdq(:) = 0._wp ; zq_ini(:) = 0._wp      
-      DO ji = kideb, kiut
-         zq_ini(ji) = ( SUM( q_i_1d(ji,1:nlay_i) ) * ht_i_1d(ji) * r1_nlay_i +  &
-            &           SUM( q_s_1d(ji,1:nlay_s) ) * ht_s_1d(ji) * r1_nlay_s ) 
-      END DO
-
-      !------------------------------------------------------------------------------!
-      ! 1) Initialization                                                            !
-      !------------------------------------------------------------------------------!
-      DO ji = kideb , kiut
-         isnow(ji)= 1._wp - MAX( 0._wp , SIGN(1._wp, - ht_s_1d(ji) ) )  ! is there snow or not
-         ! layer thickness
-         zh_i(ji) = ht_i_1d(ji) * r1_nlay_i
-         zh_s(ji) = ht_s_1d(ji) * r1_nlay_s
-      END DO
-
-      !--------------------
-      ! Ice / snow layers
-      !--------------------
-
-      z_s(:,0) = 0._wp   ! vert. coord. of the up. lim. of the 1st snow layer
-      z_i(:,0) = 0._wp   ! vert. coord. of the up. lim. of the 1st ice layer
-
-      DO jk = 1, nlay_s            ! vert. coord of the up. lim. of the layer-th snow layer
-         DO ji = kideb , kiut
-            z_s(ji,jk) = z_s(ji,jk-1) + ht_s_1d(ji) * r1_nlay_s
-         END DO
-      END DO
-
-      DO jk = 1, nlay_i            ! vert. coord of the up. lim. of the layer-th ice layer
-         DO ji = kideb , kiut
-            z_i(ji,jk) = z_i(ji,jk-1) + ht_i_1d(ji) * r1_nlay_i
-         END DO
-      END DO
-      !
-      !------------------------------------------------------------------------------|
-      ! 2) Radiation								                                 |
-      !------------------------------------------------------------------------------|
-      !
-      !-------------------
-      ! Computation of i0
-      !-------------------
-      ! i0 describes the fraction of solar radiation which does not contribute
-      ! to the surface energy budget but rather penetrates inside the ice.
-      ! We assume that no radiation is transmitted through the snow
-      ! If there is no no snow
-      ! zfsw    = (1-i0).qsr_ice   is absorbed at the surface 
-      ! zftrice = io.qsr_ice       is below the surface 
-      ! ftr_ice = io.qsr_ice.exp(-k(h_i)) transmitted below the ice 
-      ! fr1_i0_1d = i0 for a thin ice cover, fr1_i0_2d = i0 for a thick ice cover
-      zhsu = 0.1_wp ! threshold for the computation of i0
-      DO ji = kideb , kiut
-         ! switches
-         isnow(ji) = 1._wp - MAX( 0._wp , SIGN( 1._wp , - ht_s_1d(ji) ) ) 
-         ! hs > 0, isnow = 1
-         zihic(ji) = MAX( 0._wp , 1._wp - ( ht_i_1d(ji) / zhsu ) )     
-
-         i0(ji)    = ( 1._wp - isnow(ji) ) * ( fr1_i0_1d(ji) + zihic(ji) * fr2_i0_1d(ji) )
-      END DO
-
-      !-------------------------------------------------------
-      ! Solar radiation absorbed / transmitted at the surface
-      ! Derivative of the non solar flux
-      !-------------------------------------------------------
-      DO ji = kideb , kiut
-         zfsw   (ji)    =  qsr_ice_1d(ji) * ( 1 - i0(ji) )   ! Shortwave radiation absorbed at surface
-         zftrice(ji)    =  qsr_ice_1d(ji) *       i0(ji)     ! Solar radiation transmitted below the surface layer
-         dzf    (ji)    = dqns_ice_1d(ji)                    ! derivative of incoming nonsolar flux 
-         zqns_ice_b(ji) = qns_ice_1d(ji)                     ! store previous qns_ice_1d value
-      END DO
-
-      !---------------------------------------------------------
-      ! Transmission - absorption of solar radiation in the ice
-      !---------------------------------------------------------
-
-      DO ji = kideb, kiut           ! snow initialization
-         zradtr_s(ji,0) = zftrice(ji)     ! radiation penetrating through snow
-      END DO
-
-      DO jk = 1, nlay_s          ! Radiation through snow
-         DO ji = kideb, kiut
-            !                             ! radiation transmitted below the layer-th snow layer
-            zradtr_s(ji,jk) = zradtr_s(ji,0) * EXP( - zraext_s * ( MAX ( 0._wp , z_s(ji,jk) ) ) )
-            !                             ! radiation absorbed by the layer-th snow layer
-            zradab_s(ji,jk) = zradtr_s(ji,jk-1) - zradtr_s(ji,jk)
-         END DO
-      END DO
-
-      DO ji = kideb, kiut           ! ice initialization
-         zradtr_i(ji,0) = zradtr_s(ji,nlay_s) * isnow(ji) + zftrice(ji) * ( 1._wp - isnow(ji) )
-      END DO
-
-      DO jk = 1, nlay_i          ! Radiation through ice
-         DO ji = kideb, kiut
-            !                             ! radiation transmitted below the layer-th ice layer
-            zradtr_i(ji,jk) = zradtr_i(ji,0) * EXP( - rn_kappa_i * ( MAX ( 0._wp , z_i(ji,jk) ) ) )
-            !                             ! radiation absorbed by the layer-th ice layer
-            zradab_i(ji,jk) = zradtr_i(ji,jk-1) - zradtr_i(ji,jk)
-         END DO
-      END DO
-
-      DO ji = kideb, kiut           ! Radiation transmitted below the ice
-         ftr_ice_1d(ji) = zradtr_i(ji,nlay_i) 
-      END DO
-
-      !------------------------------------------------------------------------------|
-      !  3) Iterative procedure begins                                               |
-      !------------------------------------------------------------------------------|
-      !
-      DO ji = kideb, kiut        ! Old surface temperature
-         ztsub  (ji) =  t_su_1d(ji)                              ! temperature at the beg of iter pr.
-         ztsubit(ji) =  t_su_1d(ji)                              ! temperature at the previous iter
-         t_su_1d(ji) =  MIN( t_su_1d(ji), rt0 - ztsu_err )       ! necessary
-         zerrit (ji) =  1000._wp                                 ! initial value of error
-      END DO
-
-      DO jk = 1, nlay_s       ! Old snow temperature
-         DO ji = kideb , kiut
-            ztsb(ji,jk) =  t_s_1d(ji,jk)
-         END DO
-      END DO
-
-      DO jk = 1, nlay_i       ! Old ice temperature
-         DO ji = kideb , kiut
-            ztib(ji,jk) =  t_i_1d(ji,jk)
-         END DO
-      END DO
-
-      nconv     =  0           ! number of iterations
-      zerritmax =  1000._wp    ! maximal value of error on all points
-
-      DO WHILE ( zerritmax > rn_terr_dif .AND. nconv < nn_conv_dif )
-         !
-         nconv = nconv + 1
-         !
-         !------------------------------------------------------------------------------|
-         ! 4) Sea ice thermal conductivity                                              |
-         !------------------------------------------------------------------------------|
-         !
-         IF( nn_ice_thcon == 0 ) THEN      ! Untersteiner (1964) formula
-            DO ji = kideb , kiut
-               ztcond_i(ji,0) = rcdic + zbeta * s_i_1d(ji,1) / MIN( -epsi10, t_i_1d(ji,1) - rt0 )
-               ztcond_i(ji,0) = MAX( ztcond_i(ji,0), zkimin )
-            END DO
-            DO jk = 1, nlay_i-1
-               DO ji = kideb , kiut
-                  ztcond_i(ji,jk) = rcdic + zbeta * ( s_i_1d(ji,jk) + s_i_1d(ji,jk+1) ) /  &
-                     MIN(-2.0_wp * epsi10, t_i_1d(ji,jk) + t_i_1d(ji,jk+1) - 2.0_wp * rt0)
-                  ztcond_i(ji,jk) = MAX( ztcond_i(ji,jk), zkimin )
-               END DO
-            END DO
-         ENDIF
-
-         IF( nn_ice_thcon == 1 ) THEN      ! Pringle et al formula included: 2.11 + 0.09 S/T - 0.011.T
-            DO ji = kideb , kiut
-               ztcond_i(ji,0) = rcdic + 0.090_wp * s_i_1d(ji,1) / MIN( -epsi10, t_i_1d(ji,1) - rt0 )   &
-                  &                   - 0.011_wp * ( t_i_1d(ji,1) - rt0 )  
-               ztcond_i(ji,0) = MAX( ztcond_i(ji,0), zkimin )
-            END DO
-            DO jk = 1, nlay_i-1
-               DO ji = kideb , kiut
-                  ztcond_i(ji,jk) = rcdic +                                                                       & 
-                     &                 0.09_wp * ( s_i_1d(ji,jk) + s_i_1d(ji,jk+1) )                              &
-                     &                 / MIN( -2._wp * epsi10, t_i_1d(ji,jk) + t_i_1d(ji,jk+1) - 2.0_wp * rt0 )   &
-                     &               - 0.0055_wp * ( t_i_1d(ji,jk) + t_i_1d(ji,jk+1) - 2.0 * rt0 )  
-                  ztcond_i(ji,jk) = MAX( ztcond_i(ji,jk), zkimin )
-               END DO
-            END DO
-            DO ji = kideb , kiut
-               ztcond_i(ji,nlay_i) = rcdic + 0.090_wp * s_i_1d(ji,nlay_i) / MIN( -epsi10, t_bo_1d(ji) - rt0 )   &
-                  &                        - 0.011_wp * ( t_bo_1d(ji) - rt0 )  
-               ztcond_i(ji,nlay_i) = MAX( ztcond_i(ji,nlay_i), zkimin )
-            END DO
-         ENDIF
-         
-         !
-         !------------------------------------------------------------------------------|
-         !  5) G(he) - enhancement of thermal conductivity in mono-category case        |
-         !------------------------------------------------------------------------------|
-         !
-         ! Computation of effective thermal conductivity G(h)
-         ! Used in mono-category case only to simulate an ITD implicitly
-         ! Fichefet and Morales Maqueda, JGR 1997
-
-         zghe(:) = 1._wp
-
-         SELECT CASE ( nn_monocat )
-
-         CASE (1,3) ! LIM3
-
-            zepsilon = 0.1_wp
-            zh_thres = EXP( 1._wp ) * zepsilon * 0.5_wp
-
-            DO ji = kideb, kiut
-   
-               ! Mean sea ice thermal conductivity
-               zkimean  = SUM( ztcond_i(ji,0:nlay_i) ) / REAL( nlay_i+1, wp )
-
-               ! Effective thickness he (zhe)
-               zfac     = 1._wp / ( rn_cdsn + zkimean )
-               zratio_s = rn_cdsn   * zfac
-               zratio_i = zkimean * zfac
-               zhe      = zratio_s * ht_i_1d(ji) + zratio_i * ht_s_1d(ji)
-
-               ! G(he)
-               rswitch  = MAX( 0._wp , SIGN( 1._wp , zhe - zh_thres ) )  ! =0 if zhe < zh_thres, if >
-               zghe(ji) = ( 1._wp - rswitch ) + rswitch * 0.5_wp * ( 1._wp + LOG( 2._wp * zhe / zepsilon ) )
-   
-               ! Impose G(he) < 2.
-               zghe(ji) = MIN( zghe(ji), 2._wp )
-
-            END DO
-
-         END SELECT
-
-         !
-         !------------------------------------------------------------------------------|
-         !  6) kappa factors                                                            |
-         !------------------------------------------------------------------------------|
-         !
-         !--- Snow
-         DO ji = kideb, kiut
-            zfac                  =  1. / MAX( epsi10 , zh_s(ji) )
-            zkappa_s(ji,0)        = zghe(ji) * rn_cdsn * zfac
-            zkappa_s(ji,nlay_s)   = zghe(ji) * rn_cdsn * zfac
-         END DO
-
-         DO jk = 1, nlay_s-1
-            DO ji = kideb , kiut
-               zkappa_s(ji,jk)    = zghe(ji) * 2.0 * rn_cdsn / MAX( epsi10, 2.0 * zh_s(ji) )
-            END DO
-         END DO
-
-         !--- Ice
-         DO jk = 1, nlay_i-1
-            DO ji = kideb , kiut
-               zkappa_i(ji,jk)    = zghe(ji) * 2.0 * ztcond_i(ji,jk) / MAX( epsi10 , 2.0 * zh_i(ji) )
-            END DO
-         END DO
-
-         !--- Snow-ice interface
-         DO ji = kideb , kiut
-            zfac                  = 1./ MAX( epsi10 , zh_i(ji) )
-            zkappa_i(ji,0)        = zghe(ji) * ztcond_i(ji,0) * zfac
-            zkappa_i(ji,nlay_i)   = zghe(ji) * ztcond_i(ji,nlay_i) * zfac
-            zkappa_s(ji,nlay_s)   = zghe(ji) * zghe(ji) * 2.0 * rn_cdsn * ztcond_i(ji,0) / & 
-           &                        MAX( epsi10, ( zghe(ji) * ztcond_i(ji,0) * zh_s(ji) + zghe(ji) * rn_cdsn * zh_i(ji) ) )
-            zkappa_i(ji,0)        = zkappa_s(ji,nlay_s) * isnow(ji) + zkappa_i(ji,0) * ( 1._wp - isnow(ji) )
-         END DO
-
-         !
-         !------------------------------------------------------------------------------|
-         ! 7) Sea ice specific heat, eta factors                                        |
-         !------------------------------------------------------------------------------|
-         !
-         DO jk = 1, nlay_i
-            DO ji = kideb , kiut
-               ztitemp(ji,jk)   = t_i_1d(ji,jk)
-               zspeche_i(ji,jk) = cpic + zgamma * s_i_1d(ji,jk) / MAX( ( t_i_1d(ji,jk) - rt0 ) * ( ztib(ji,jk) - rt0 ), epsi10 )
-               zeta_i(ji,jk)    = rdt_ice / MAX( rhoic * zspeche_i(ji,jk) * zh_i(ji), epsi10 )
-            END DO
-         END DO
-
-         DO jk = 1, nlay_s
-            DO ji = kideb , kiut
-               ztstemp(ji,jk) = t_s_1d(ji,jk)
-               zeta_s(ji,jk)  = rdt_ice / MAX( rhosn * cpic * zh_s(ji), epsi10 )
-            END DO
-         END DO
-
-         !
-         !------------------------------------------------------------------------------|
-         ! 8) surface flux computation                                                  |
-         !------------------------------------------------------------------------------|
-         !
-         IF ( ln_it_qnsice ) THEN 
-            DO ji = kideb , kiut
-               ! update of the non solar flux according to the update in T_su
-               qns_ice_1d(ji) = qns_ice_1d(ji) + dqns_ice_1d(ji) * ( t_su_1d(ji) - ztsubit(ji) )
-            END DO
-         ENDIF
-
-         ! Update incoming flux
-         DO ji = kideb , kiut
-            ! update incoming flux
-            zf(ji)    =          zfsw(ji)              & ! net absorbed solar radiation
-               &         + qns_ice_1d(ji)                ! non solar total flux (LWup, LWdw, SH, LH)
-         END DO
-
-         !
-         !------------------------------------------------------------------------------|
-         ! 9) tridiagonal system terms                                                  |
-         !------------------------------------------------------------------------------|
-         !
-         !!layer denotes the number of the layer in the snow or in the ice
-         !!numeq denotes the reference number of the equation in the tridiagonal
-         !!system, terms of tridiagonal system are indexed as following :
-         !!1 is subdiagonal term, 2 is diagonal and 3 is superdiagonal one
-
-         !!ice interior terms (top equation has the same form as the others)
-
-         DO numeq=1,nlay_i+3
-            DO ji = kideb , kiut
-               ztrid(ji,numeq,1) = 0.
-               ztrid(ji,numeq,2) = 0.
-               ztrid(ji,numeq,3) = 0.
-               zindterm(ji,numeq)= 0.
-               zindtbis(ji,numeq)= 0.
-               zdiagbis(ji,numeq)= 0.
-            ENDDO
-         ENDDO
-
-         DO numeq = nlay_s + 2, nlay_s + nlay_i 
-            DO ji = kideb , kiut
-               jk                 = numeq - nlay_s - 1
-               ztrid(ji,numeq,1)  =  - zeta_i(ji,jk) * zkappa_i(ji,jk-1)
-               ztrid(ji,numeq,2)  =  1.0 + zeta_i(ji,jk) * ( zkappa_i(ji,jk-1) + zkappa_i(ji,jk) )
-               ztrid(ji,numeq,3)  =  - zeta_i(ji,jk) * zkappa_i(ji,jk)
-               zindterm(ji,numeq) =  ztib(ji,jk) + zeta_i(ji,jk) * zradab_i(ji,jk)
-            END DO
-         ENDDO
-
-         numeq =  nlay_s + nlay_i + 1
-         DO ji = kideb , kiut
-            !!ice bottom term
-            ztrid(ji,numeq,1)  =  - zeta_i(ji,nlay_i)*zkappa_i(ji,nlay_i-1)   
-            ztrid(ji,numeq,2)  =  1.0 + zeta_i(ji,nlay_i) * ( zkappa_i(ji,nlay_i) * zg1 + zkappa_i(ji,nlay_i-1) )
-            ztrid(ji,numeq,3)  =  0.0
-            zindterm(ji,numeq) =  ztib(ji,nlay_i) + zeta_i(ji,nlay_i) *  &
-               &                  ( zradab_i(ji,nlay_i) + zkappa_i(ji,nlay_i) * zg1 *  t_bo_1d(ji) ) 
-         ENDDO
-
-
-         DO ji = kideb , kiut
-            IF ( ht_s_1d(ji) > 0.0 ) THEN
-               !
-               !------------------------------------------------------------------------------|
-               !  snow-covered cells                                                          |
-               !------------------------------------------------------------------------------|
-               !
-               !!snow interior terms (bottom equation has the same form as the others)
-               DO numeq = 3, nlay_s + 1
-                  jk                  =  numeq - 1
-                  ztrid(ji,numeq,1)   =  - zeta_s(ji,jk) * zkappa_s(ji,jk-1)
-                  ztrid(ji,numeq,2)   =  1.0 + zeta_s(ji,jk) * ( zkappa_s(ji,jk-1) + zkappa_s(ji,jk) )
-                  ztrid(ji,numeq,3)   =  - zeta_s(ji,jk)*zkappa_s(ji,jk)
-                  zindterm(ji,numeq)  =  ztsb(ji,jk) + zeta_s(ji,jk) * zradab_s(ji,jk)
-               END DO
-
-               !!case of only one layer in the ice (ice equation is altered)
-               IF ( nlay_i.eq.1 ) THEN
-                  ztrid(ji,nlay_s+2,3)    =  0.0
-                  zindterm(ji,nlay_s+2)   =  zindterm(ji,nlay_s+2) + zkappa_i(ji,1) * t_bo_1d(ji) 
-               ENDIF
-
-               IF ( t_su_1d(ji) < rt0 ) THEN
-
-                  !------------------------------------------------------------------------------|
-                  !  case 1 : no surface melting - snow present                                  |
-                  !------------------------------------------------------------------------------|
-                  zdifcase(ji)    =  1.0
-                  numeqmin(ji)    =  1
-                  numeqmax(ji)    =  nlay_i + nlay_s + 1
-
-                  !!surface equation
-                  ztrid(ji,1,1)  = 0.0
-                  ztrid(ji,1,2)  = dzf(ji) - zg1s * zkappa_s(ji,0)
-                  ztrid(ji,1,3)  = zg1s * zkappa_s(ji,0)
-                  zindterm(ji,1) = dzf(ji) * t_su_1d(ji) - zf(ji)
-
-                  !!first layer of snow equation
-                  ztrid(ji,2,1)  =  - zkappa_s(ji,0) * zg1s * zeta_s(ji,1)
-                  ztrid(ji,2,2)  =  1.0 + zeta_s(ji,1) * ( zkappa_s(ji,1) + zkappa_s(ji,0) * zg1s )
-                  ztrid(ji,2,3)  =  - zeta_s(ji,1)* zkappa_s(ji,1)
-                  zindterm(ji,2) =  ztsb(ji,1) + zeta_s(ji,1) * zradab_s(ji,1)
-
-               ELSE 
-                  !
-                  !------------------------------------------------------------------------------|
-                  !  case 2 : surface is melting - snow present                                  |
-                  !------------------------------------------------------------------------------|
-                  !
-                  zdifcase(ji)    =  2.0
-                  numeqmin(ji)    =  2
-                  numeqmax(ji)    =  nlay_i + nlay_s + 1
-
-                  !!first layer of snow equation
-                  ztrid(ji,2,1)  =  0.0
-                  ztrid(ji,2,2)  =  1.0 + zeta_s(ji,1) * ( zkappa_s(ji,1) + zkappa_s(ji,0) * zg1s )
-                  ztrid(ji,2,3)  =  - zeta_s(ji,1)*zkappa_s(ji,1) 
-                  zindterm(ji,2) = ztsb(ji,1) + zeta_s(ji,1) *  &
-                     &             ( zradab_s(ji,1) + zkappa_s(ji,0) * zg1s * t_su_1d(ji) ) 
-               ENDIF
-            ELSE
-               !
-               !------------------------------------------------------------------------------|
-               !  cells without snow                                                          |
-               !------------------------------------------------------------------------------|
-               !
-               IF ( t_su_1d(ji) < rt0 ) THEN
-                  !
-                  !------------------------------------------------------------------------------|
-                  !  case 3 : no surface melting - no snow                                       |
-                  !------------------------------------------------------------------------------|
-                  !
-                  zdifcase(ji)      =  3.0
-                  numeqmin(ji)      =  nlay_s + 1
-                  numeqmax(ji)      =  nlay_i + nlay_s + 1
-
-                  !!surface equation	
-                  ztrid(ji,numeqmin(ji),1)   =  0.0
-                  ztrid(ji,numeqmin(ji),2)   =  dzf(ji) - zkappa_i(ji,0)*zg1    
-                  ztrid(ji,numeqmin(ji),3)   =  zkappa_i(ji,0)*zg1
-                  zindterm(ji,numeqmin(ji))  =  dzf(ji)*t_su_1d(ji) - zf(ji)
-
-                  !!first layer of ice equation
-                  ztrid(ji,numeqmin(ji)+1,1) =  - zkappa_i(ji,0) * zg1 * zeta_i(ji,1)
-                  ztrid(ji,numeqmin(ji)+1,2) =  1.0 + zeta_i(ji,1) * ( zkappa_i(ji,1) + zkappa_i(ji,0) * zg1 )
-                  ztrid(ji,numeqmin(ji)+1,3) =  - zeta_i(ji,1) * zkappa_i(ji,1)  
-                  zindterm(ji,numeqmin(ji)+1)=  ztib(ji,1) + zeta_i(ji,1) * zradab_i(ji,1)  
-
-                  !!case of only one layer in the ice (surface & ice equations are altered)
-
-                  IF ( nlay_i == 1 ) THEN
-                     ztrid(ji,numeqmin(ji),1)    =  0.0
-                     ztrid(ji,numeqmin(ji),2)    =  dzf(ji) - zkappa_i(ji,0) * 2.0
-                     ztrid(ji,numeqmin(ji),3)    =  zkappa_i(ji,0) * 2.0
-                     ztrid(ji,numeqmin(ji)+1,1)  =  -zkappa_i(ji,0) * 2.0 * zeta_i(ji,1)
-                     ztrid(ji,numeqmin(ji)+1,2)  =  1.0 + zeta_i(ji,1) * ( zkappa_i(ji,0) * 2.0 + zkappa_i(ji,1) )
-                     ztrid(ji,numeqmin(ji)+1,3)  =  0.0
-
-                     zindterm(ji,numeqmin(ji)+1) =  ztib(ji,1) + zeta_i(ji,1) *  &
-                        &                          ( zradab_i(ji,1) + zkappa_i(ji,1) * t_bo_1d(ji) )
-                  ENDIF
-
-               ELSE
-
-                  !
-                  !------------------------------------------------------------------------------|
-                  ! case 4 : surface is melting - no snow                                        |
-                  !------------------------------------------------------------------------------|
-                  !
-                  zdifcase(ji)    =  4.0
-                  numeqmin(ji)    =  nlay_s + 2
-                  numeqmax(ji)    =  nlay_i + nlay_s + 1
-
-                  !!first layer of ice equation
-                  ztrid(ji,numeqmin(ji),1)      =  0.0
-                  ztrid(ji,numeqmin(ji),2)      =  1.0 + zeta_i(ji,1) * ( zkappa_i(ji,1) + zkappa_i(ji,0) * zg1 )  
-                  ztrid(ji,numeqmin(ji),3)      =  - zeta_i(ji,1) * zkappa_i(ji,1)
-                  zindterm(ji,numeqmin(ji))     =  ztib(ji,1) + zeta_i(ji,1) *  &
-                     &                             ( zradab_i(ji,1) + zkappa_i(ji,0) * zg1 * t_su_1d(ji) ) 
-
-                  !!case of only one layer in the ice (surface & ice equations are altered)
-                  IF ( nlay_i == 1 ) THEN
-                     ztrid(ji,numeqmin(ji),1)  =  0.0
-                     ztrid(ji,numeqmin(ji),2)  =  1.0 + zeta_i(ji,1) * ( zkappa_i(ji,0) * 2.0 + zkappa_i(ji,1) )
-                     ztrid(ji,numeqmin(ji),3)  =  0.0
-                     zindterm(ji,numeqmin(ji)) =  ztib(ji,1) + zeta_i(ji,1) * ( zradab_i(ji,1) + zkappa_i(ji,1) * t_bo_1d(ji) )  &
-                        &                       + t_su_1d(ji) * zeta_i(ji,1) * zkappa_i(ji,0) * 2.0
-                  ENDIF
-
-               ENDIF
-            ENDIF
-
-         END DO
-
-         !
-         !------------------------------------------------------------------------------|
-         ! 10) tridiagonal system solving                                               |
-         !------------------------------------------------------------------------------|
-         !
-
-         ! Solve the tridiagonal system with Gauss elimination method.
-         ! Thomas algorithm, from Computational fluid Dynamics, J.D. ANDERSON, 
-         ! McGraw-Hill 1984.	
-
-         maxnumeqmax = 0
-         minnumeqmin = nlay_i+5
-
-         DO ji = kideb , kiut
-            zindtbis(ji,numeqmin(ji)) =  zindterm(ji,numeqmin(ji))
-            zdiagbis(ji,numeqmin(ji)) =  ztrid(ji,numeqmin(ji),2)
-            minnumeqmin               =  MIN(numeqmin(ji),minnumeqmin)
-            maxnumeqmax               =  MAX(numeqmax(ji),maxnumeqmax)
-         END DO
-
-         DO jk = minnumeqmin+1, maxnumeqmax
-            DO ji = kideb , kiut
-               numeq               =  min(max(numeqmin(ji)+1,jk),numeqmax(ji))
-               zdiagbis(ji,numeq)  =  ztrid(ji,numeq,2)  - ztrid(ji,numeq,1) * ztrid(ji,numeq-1,3)  / zdiagbis(ji,numeq-1)
-               zindtbis(ji,numeq)  =  zindterm(ji,numeq) - ztrid(ji,numeq,1) * zindtbis(ji,numeq-1) / zdiagbis(ji,numeq-1)
-            END DO
-         END DO
-
-         DO ji = kideb , kiut
-            ! ice temperatures
-            t_i_1d(ji,nlay_i)    =  zindtbis(ji,numeqmax(ji)) / zdiagbis(ji,numeqmax(ji))
-         END DO
-
-         DO numeq = nlay_i + nlay_s, nlay_s + 2, -1
-            DO ji = kideb , kiut
-               jk    =  numeq - nlay_s - 1
-               t_i_1d(ji,jk)  =  ( zindtbis(ji,numeq) - ztrid(ji,numeq,3) * t_i_1d(ji,jk+1) ) / zdiagbis(ji,numeq)
-            END DO
-         END DO
-
-         DO ji = kideb , kiut
-            ! snow temperatures      
-            IF (ht_s_1d(ji) > 0._wp) &
-               t_s_1d(ji,nlay_s)     =  ( zindtbis(ji,nlay_s+1) - ztrid(ji,nlay_s+1,3) * t_i_1d(ji,1) )  &
-               &                        / zdiagbis(ji,nlay_s+1) * MAX( 0.0, SIGN( 1.0, ht_s_1d(ji) ) ) 
-
-            ! surface temperature
-            isnow(ji)   = 1._wp - MAX( 0._wp , SIGN( 1._wp , -ht_s_1d(ji) ) )
-            ztsubit(ji) = t_su_1d(ji)
-            IF( t_su_1d(ji) < rt0 ) &
-               t_su_1d(ji) = ( zindtbis(ji,numeqmin(ji)) - ztrid(ji,numeqmin(ji),3) *  &
-               &             ( isnow(ji) * t_s_1d(ji,1) + ( 1._wp - isnow(ji) ) * t_i_1d(ji,1) ) ) / zdiagbis(ji,numeqmin(ji))  
-         END DO
-         !
-         !--------------------------------------------------------------------------
-         !  11) Has the scheme converged ?, end of the iterative procedure         |
-         !--------------------------------------------------------------------------
-         !
-         ! check that nowhere it has started to melt
-         ! zerrit(ji) is a measure of error, it has to be under terr_dif
-         DO ji = kideb , kiut
-            t_su_1d(ji) =  MAX(  MIN( t_su_1d(ji) , rt0 ) , 190._wp  )
-            zerrit(ji)  =  ABS( t_su_1d(ji) - ztsubit(ji) )     
-         END DO
-
-         DO jk  =  1, nlay_s
-            DO ji = kideb , kiut
-               t_s_1d(ji,jk) = MAX(  MIN( t_s_1d(ji,jk), rt0 ), 190._wp  )
-               zerrit(ji)    = MAX( zerrit(ji), ABS( t_s_1d(ji,jk) - ztstemp(ji,jk) ) )
-            END DO
-         END DO
-
-         DO jk  =  1, nlay_i
-            DO ji = kideb , kiut
-               ztmelt_i      = -tmut * s_i_1d(ji,jk) + rt0 
-               t_i_1d(ji,jk) =  MAX( MIN( t_i_1d(ji,jk), ztmelt_i ), 190._wp )
-               zerrit(ji)    =  MAX( zerrit(ji), ABS( t_i_1d(ji,jk) - ztitemp(ji,jk) ) )
-            END DO
-         END DO
-
-         ! Compute spatial maximum over all errors
-         ! note that this could be optimized substantially by iterating only the non-converging points
-         zerritmax = 0._wp
-         DO ji = kideb, kiut
-            zerritmax = MAX( zerritmax, zerrit(ji) )   
-         END DO
-         IF( lk_mpp ) CALL mpp_max( zerritmax, kcom=ncomm_ice )
-
-      END DO  ! End of the do while iterative procedure
-
-      IF( ln_limctl .AND. lwp ) THEN
-         WRITE(numout,*) ' zerritmax : ', zerritmax
-         WRITE(numout,*) ' nconv     : ', nconv
-      ENDIF
-
-      !
-      !-------------------------------------------------------------------------!
-      !   12) Fluxes at the interfaces                                          !
-      !-------------------------------------------------------------------------!
-      DO ji = kideb, kiut
-         !                                ! surface ice conduction flux
-         isnow(ji)       = 1._wp - MAX( 0._wp, SIGN( 1._wp, -ht_s_1d(ji) ) )
-         fc_su(ji)       =  -           isnow(ji)   * zkappa_s(ji,0) * zg1s * (t_s_1d(ji,1) - t_su_1d(ji))   &
-            &               - ( 1._wp - isnow(ji) ) * zkappa_i(ji,0) * zg1  * (t_i_1d(ji,1) - t_su_1d(ji))
-         !                                ! bottom ice conduction flux
-         fc_bo_i(ji)     =  - zkappa_i(ji,nlay_i) * ( zg1*(t_bo_1d(ji) - t_i_1d(ji,nlay_i)) )
-      END DO
-
-      ! --- computes sea ice energy of melting compulsory for limthd_dh --- !
-      CALL lim_thd_enmelt( kideb, kiut )
-
-      ! --- diagnose the change in non-solar flux due to surface temperature change --- !
-      IF ( ln_it_qnsice ) THEN
-         DO ji = kideb, kiut
-            hfx_err_dif_1d(ji) = hfx_err_dif_1d(ji) - ( qns_ice_1d(ji)  - zqns_ice_b(ji) ) * a_i_1d(ji) 
-         END DO
-      END IF
-
-      ! --- diag conservation imbalance on heat diffusion - PART 2 --- !
-      DO ji = kideb, kiut
-         zdq(ji)        = - zq_ini(ji) + ( SUM( q_i_1d(ji,1:nlay_i) ) * ht_i_1d(ji) * r1_nlay_i +  &
-            &                              SUM( q_s_1d(ji,1:nlay_s) ) * ht_s_1d(ji) * r1_nlay_s )
-         IF( t_su_1d(ji) < rt0 ) THEN  ! case T_su < 0degC
-            zhfx_err(ji) = qns_ice_1d(ji) + qsr_ice_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) + zdq(ji) * r1_rdtice 
-         ELSE                          ! case T_su = 0degC
-            zhfx_err(ji) = fc_su(ji) + i0(ji) * qsr_ice_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) + zdq(ji) * r1_rdtice 
-         ENDIF
-         hfx_err_1d(ji) = hfx_err_1d(ji) + zhfx_err(ji) * a_i_1d(ji)
-
-         ! total heat that is sent to the ocean (i.e. not used in the heat diffusion equation)
-         hfx_err_dif_1d(ji) = hfx_err_dif_1d(ji) + zhfx_err(ji) * a_i_1d(ji)
-      END DO 
-
-      !-----------------------------------------
-      ! Heat flux used to warm/cool ice in W.m-2
-      !-----------------------------------------
-      DO ji = kideb, kiut
-         IF( t_su_1d(ji) < rt0 ) THEN  ! case T_su < 0degC
-            hfx_dif_1d(ji) = hfx_dif_1d(ji)  +   &
-               &            ( qns_ice_1d(ji) + qsr_ice_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) ) * a_i_1d(ji)
-         ELSE                          ! case T_su = 0degC
-            hfx_dif_1d(ji) = hfx_dif_1d(ji) +    &
-               &             ( fc_su(ji) + i0(ji) * qsr_ice_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) ) * a_i_1d(ji)
-         ENDIF
-         ! correction on the diagnosed heat flux due to non-convergence of the algorithm used to solve heat equation
-         hfx_dif_1d(ji) = hfx_dif_1d(ji) - zhfx_err(ji) * a_i_1d(ji)
-      END DO   
-      !
-      CALL wrk_dealloc( jpij, numeqmin, numeqmax )
-      CALL wrk_dealloc( jpij, isnow, ztsub, ztsubit, zh_i, zh_s, zfsw )
-      CALL wrk_dealloc( jpij, zf, dzf, zqns_ice_b, zerrit, zdifcase, zftrice, zihic, zghe )
-      CALL wrk_dealloc( jpij,nlay_i+1, ztcond_i, zradtr_i, zradab_i, zkappa_i, ztib, zeta_i, ztitemp, z_i, zspeche_i, kjstart = 0 )
-      CALL wrk_dealloc( jpij,nlay_s+1,           zradtr_s, zradab_s, zkappa_s, ztsb, zeta_s, ztstemp, z_s, kjstart = 0 )
-      CALL wrk_dealloc( jpij,nlay_i+3, zindterm, zindtbis, zdiagbis )
-      CALL wrk_dealloc( jpij,nlay_i+3,3, ztrid )
-      CALL wrk_dealloc( jpij, zdq, zq_ini, zhfx_err )
-
-   END SUBROUTINE lim_thd_dif
-
-   SUBROUTINE lim_thd_enmelt( kideb, kiut )
-      !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_thd_enmelt *** 
-      !!                 
-      !! ** Purpose :   Computes sea ice energy of melting q_i (J.m-3) from temperature
-      !!
-      !! ** Method  :   Formula (Bitz and Lipscomb, 1999)
-      !!-------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kideb, kiut   ! bounds for the spatial loop
-      !
-      INTEGER  ::   ji, jk   ! dummy loop indices
-      REAL(wp) ::   ztmelts  ! local scalar 
-      !!-------------------------------------------------------------------
-      !
-      DO jk = 1, nlay_i             ! Sea ice energy of melting
-         DO ji = kideb, kiut
-            ztmelts      = - tmut  * s_i_1d(ji,jk) + rt0
-            t_i_1d(ji,jk) = MIN( t_i_1d(ji,jk), ztmelts ) ! Force t_i_1d to be lower than melting point
-                                                          !   (sometimes dif scheme produces abnormally high temperatures)   
-            q_i_1d(ji,jk) = rhoic * ( cpic * ( ztmelts - t_i_1d(ji,jk) )                           &
-               &                    + lfus * ( 1.0 - ( ztmelts-rt0 ) / ( t_i_1d(ji,jk) - rt0 ) )   &
-               &                    - rcp  *         ( ztmelts-rt0 )  ) 
-         END DO
-      END DO
-      DO jk = 1, nlay_s             ! Snow energy of melting
-         DO ji = kideb, kiut
-            q_s_1d(ji,jk) = rhosn * ( cpic * ( rt0 - t_s_1d(ji,jk) ) + lfus )
-         END DO
-      END DO
-      !
-   END SUBROUTINE lim_thd_enmelt
-
-#else
-   !!----------------------------------------------------------------------
-   !!                   Dummy Module                 No LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_thd_dif          ! Empty routine
-   END SUBROUTINE lim_thd_dif
-#endif
-   !!======================================================================
-END MODULE limthd_dif
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limthd_ent.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limthd_ent.F90	(revision 9018)
+++ 	(revision )
@@ -1,164 +1,0 @@
-MODULE limthd_ent
-   !!======================================================================
-   !!                       ***  MODULE limthd_ent   ***
-   !!                  Redistribution of Enthalpy in the ice
-   !!                        on the new vertical grid
-   !!                       after vertical growth/decay
-   !!======================================================================
-   !! History :  LIM  ! 2003-05 (M. Vancoppenolle) Original code in 1D
-   !!                 ! 2005-07 (M. Vancoppenolle) 3D version 
-   !!                 ! 2006-11 (X. Fettweis) Vectorized 
-   !!            3.0  ! 2008-03 (M. Vancoppenolle) Energy conservation and clean code
-   !!            3.4  ! 2011-02 (G. Madec) dynamical allocation
-   !!             -   ! 2014-05 (C. Rousset) complete rewriting
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_thd_ent   : ice redistribution of enthalpy
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-   USE dom_oce        ! domain variables
-   USE domain         !
-   USE phycst         ! physical constants
-   USE sbc_oce        ! Surface boundary condition: ocean fields
-   USE ice            ! LIM variables
-   USE thd_ice        ! LIM thermodynamics
-   USE limvar         ! LIM variables
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_thd_ent         ! called by limthd and limthd_lac
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
- 
-   SUBROUTINE lim_thd_ent( kideb, kiut, qnew )
-      !!-------------------------------------------------------------------
-      !!               ***   ROUTINE lim_thd_ent  ***
-      !!
-      !! ** Purpose :
-      !!           This routine computes new vertical grids in the ice, 
-      !!           and consistently redistributes temperatures. 
-      !!           Redistribution is made so as to ensure to energy conservation
-      !!
-      !!
-      !! ** Method  : linear conservative remapping
-      !!           
-      !! ** Steps : 1) cumulative integrals of old enthalpies/thicknesses
-      !!            2) linear remapping on the new layers
-      !!
-      !! ------------ cum0(0)                        ------------- cum1(0)
-      !!                                    NEW      -------------
-      !! ------------ cum0(1)               ==>      -------------
-      !!     ...                                     -------------
-      !! ------------                                -------------
-      !! ------------ cum0(nlay_i+2)                 ------------- cum1(nlay_i)
-      !!
-      !!
-      !! References : Bitz & Lipscomb, JGR 99; Vancoppenolle et al., GRL, 2005
-      !!-------------------------------------------------------------------
-      INTEGER , INTENT(in) ::   kideb, kiut   ! Start/End point on which the  the computation is applied
-
-      REAL(wp), INTENT(inout), DIMENSION(:,:) :: qnew          ! new enthlapies (J.m-3, remapped)
-
-      INTEGER  :: ji         !  dummy loop indices
-      INTEGER  :: jk0, jk1   !  old/new layer indices
-      !
-      REAL(wp), POINTER, DIMENSION(:,:) :: zqh_cum0, zh_cum0   ! old cumulative enthlapies and layers interfaces
-      REAL(wp), POINTER, DIMENSION(:,:) :: zqh_cum1, zh_cum1   ! new cumulative enthlapies and layers interfaces
-      REAL(wp), POINTER, DIMENSION(:)   :: zhnew               ! new layers thicknesses
-      !!-------------------------------------------------------------------
-
-      CALL wrk_alloc( jpij, nlay_i+3, zqh_cum0, zh_cum0, kjstart = 0 )
-      CALL wrk_alloc( jpij, nlay_i+1, zqh_cum1, zh_cum1, kjstart = 0 )
-      CALL wrk_alloc( jpij, zhnew )
-
-      !--------------------------------------------------------------------------
-      !  1) Cumulative integral of old enthalpy * thickness and layers interfaces
-      !--------------------------------------------------------------------------
-      zqh_cum0(:,0:nlay_i+2) = 0._wp 
-      zh_cum0 (:,0:nlay_i+2) = 0._wp
-      DO jk0 = 1, nlay_i+2
-         DO ji = kideb, kiut
-            zqh_cum0(ji,jk0) = zqh_cum0(ji,jk0-1) + qh_i_old(ji,jk0-1)
-            zh_cum0 (ji,jk0) = zh_cum0 (ji,jk0-1) + h_i_old (ji,jk0-1)
-         ENDDO
-      ENDDO
-
-      !------------------------------------
-      !  2) Interpolation on the new layers
-      !------------------------------------
-      ! new layer thickesses
-      DO ji = kideb, kiut
-         zhnew(ji) = SUM( h_i_old(ji,0:nlay_i+1) ) * r1_nlay_i  
-      ENDDO
-
-      ! new layers interfaces
-      zh_cum1(:,0:nlay_i) = 0._wp
-      DO jk1 = 1, nlay_i
-         DO ji = kideb, kiut
-            zh_cum1(ji,jk1) = zh_cum1(ji,jk1-1) + zhnew(ji)
-         ENDDO
-      ENDDO
-
-      zqh_cum1(:,0:nlay_i) = 0._wp 
-      ! new cumulative q*h => linear interpolation
-      DO jk0 = 1, nlay_i+1
-         DO jk1 = 1, nlay_i-1
-            DO ji = kideb, kiut
-               IF( zh_cum1(ji,jk1) <= zh_cum0(ji,jk0) .AND. zh_cum1(ji,jk1) > zh_cum0(ji,jk0-1) ) THEN
-                  zqh_cum1(ji,jk1) = ( zqh_cum0(ji,jk0-1) * ( zh_cum0(ji,jk0) - zh_cum1(ji,jk1  ) ) +  &
-                     &                 zqh_cum0(ji,jk0  ) * ( zh_cum1(ji,jk1) - zh_cum0(ji,jk0-1) ) )  &
-                     &             / ( zh_cum0(ji,jk0) - zh_cum0(ji,jk0-1) )
-               ENDIF
-            ENDDO
-         ENDDO
-      ENDDO
-      ! to ensure that total heat content is strictly conserved, set:
-      zqh_cum1(:,nlay_i) = zqh_cum0(:,nlay_i+2) 
-
-      ! new enthalpies
-      DO jk1 = 1, nlay_i
-         DO ji = kideb, kiut
-            rswitch      = MAX( 0._wp , SIGN( 1._wp , zhnew(ji) - epsi20 ) ) 
-            qnew(ji,jk1) = rswitch * ( zqh_cum1(ji,jk1) - zqh_cum1(ji,jk1-1) ) / MAX( zhnew(ji), epsi20 )
-         ENDDO
-      ENDDO
-
-      ! --- diag error on heat remapping --- !
-      ! comment: if input h_i_old and qh_i_old are already multiplied by a_i (as in limthd_lac), 
-      ! then we should not (* a_i) again but not important since this is just to check that remap error is ~0
-      DO ji = kideb, kiut
-         hfx_err_rem_1d(ji) = hfx_err_rem_1d(ji) + a_i_1d(ji) * r1_rdtice *  &
-            &               ( SUM( qnew(ji,1:nlay_i) ) * zhnew(ji) - SUM( qh_i_old(ji,0:nlay_i+1) ) ) 
-      END DO
-      
-      !
-      CALL wrk_dealloc( jpij, nlay_i+3, zqh_cum0, zh_cum0, kjstart = 0 )
-      CALL wrk_dealloc( jpij, nlay_i+1, zqh_cum1, zh_cum1, kjstart = 0 )
-      CALL wrk_dealloc( jpij, zhnew )
-      !
-   END SUBROUTINE lim_thd_ent
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                               NO  LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_thd_ent          ! Empty routine
-   END SUBROUTINE lim_thd_ent
-#endif
-
-   !!======================================================================
-END MODULE limthd_ent
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limthd_lac.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limthd_lac.F90	(revision 9018)
+++ 	(revision )
@@ -1,533 +1,0 @@
-MODULE limthd_lac
-   !!======================================================================
-   !!                       ***  MODULE limthd_lac   ***
-   !!                lateral thermodynamic growth of the ice 
-   !!======================================================================
-   !! History :  LIM  ! 2005-12 (M. Vancoppenolle)  Original code
-   !!             -   ! 2006-01 (M. Vancoppenolle)  add ITD
-   !!            3.0  ! 2007-07 (M. Vancoppenolle)  Mass and energy conservation tested
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_lat_acr   : lateral accretion of ice
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-   USE dom_oce        ! domain variables
-   USE phycst         ! physical constants
-   USE sbc_oce        ! Surface boundary condition: ocean fields
-   USE sbc_ice        ! Surface boundary condition: ice fields
-   USE thd_ice        ! LIM thermodynamics
-   USE ice            ! LIM variables
-   USE limtab         ! LIM 2D <==> 1D
-   USE limcons        ! LIM conservation
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE limthd_ent
-   USE limvar
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC lim_thd_lac     ! called by lim_thd
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_thd_lac
-      !!-------------------------------------------------------------------
-      !!               ***   ROUTINE lim_thd_lac  ***
-      !!  
-      !! ** Purpose : Computation of the evolution of the ice thickness and 
-      !!      concentration as a function of the heat balance in the leads.
-      !!      It is only used for lateral accretion
-      !!       
-      !! ** Method  : Ice is formed in the open water when ocean lose heat
-      !!      (heat budget of open water Bl is negative) .
-      !!      Computation of the increase of 1-A (ice concentration) fol-
-      !!      lowing the law :
-      !!      (dA/dt)acc = F[ (1-A)/(1-a) ] * [ Bl / (Li*h0) ]
-      !!       where - h0 is the thickness of ice created in the lead
-      !!             - a is a minimum fraction for leads
-      !!             - F is a monotonic non-increasing function defined as:
-      !!                  F(X)=( 1 - X**exld )**(1.0/exld)
-      !!             - exld is the exponent closure rate (=2 default val.)
-      !! 
-      !! ** Action : - Adjustment of snow and ice thicknesses and heat
-      !!                content in brine pockets
-      !!             - Updating ice internal temperature
-      !!             - Computation of variation of ice volume and mass
-      !!             - Computation of frldb after lateral accretion and 
-      !!               update ht_s_1d, ht_i_1d and tbif_1d(:,:)      
-      !!------------------------------------------------------------------------
-      INTEGER  ::   ji,jj,jk,jl      ! dummy loop indices
-      INTEGER  ::   nbpac            ! local integers 
-      INTEGER  ::   ii, ij, iter     !   -       -
-      REAL(wp) ::   ztmelts, zdv, zfrazb, zweight, zde                          ! local scalars
-      REAL(wp) ::   zgamafr, zvfrx, zvgx, ztaux, ztwogp, zf                     !   -      -
-      REAL(wp) ::   ztenagm, zvfry, zvgy, ztauy, zvrel2, zfp, zsqcd , zhicrit   !   -      -
-      CHARACTER (len = 15) :: fieldid
-
-      REAL(wp) ::   zQm          ! enthalpy exchanged with the ocean (J/m2, >0 towards ocean)
-      REAL(wp) ::   zEi          ! sea ice specific enthalpy (J/kg)
-      REAL(wp) ::   zEw          ! seawater specific enthalpy (J/kg)
-      REAL(wp) ::   zfmdt        ! mass flux x time step (kg/m2, >0 towards ocean)
-     
-      REAL(wp) ::   zv_newfra
-  
-      INTEGER , POINTER, DIMENSION(:) ::   jcat        ! indexes of categories where new ice grows
-      REAL(wp), POINTER, DIMENSION(:) ::   zswinew     ! switch for new ice or not
-
-      REAL(wp), POINTER, DIMENSION(:) ::   zv_newice   ! volume of accreted ice
-      REAL(wp), POINTER, DIMENSION(:) ::   za_newice   ! fractional area of accreted ice
-      REAL(wp), POINTER, DIMENSION(:) ::   zh_newice   ! thickness of accreted ice
-      REAL(wp), POINTER, DIMENSION(:) ::   ze_newice   ! heat content of accreted ice
-      REAL(wp), POINTER, DIMENSION(:) ::   zs_newice   ! salinity of accreted ice
-      REAL(wp), POINTER, DIMENSION(:) ::   zo_newice   ! age of accreted ice
-      REAL(wp), POINTER, DIMENSION(:) ::   zdv_res     ! residual volume in case of excessive heat budget
-      REAL(wp), POINTER, DIMENSION(:) ::   zda_res     ! residual area in case of excessive heat budget
-      REAL(wp), POINTER, DIMENSION(:) ::   zat_i_1d    ! total ice fraction    
-      REAL(wp), POINTER, DIMENSION(:) ::   zv_frazb    ! accretion of frazil ice at the ice bottom
-      REAL(wp), POINTER, DIMENSION(:) ::   zvrel_1d    ! relative ice / frazil velocity (1D vector)
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zv_b      ! old volume of ice in category jl
-      REAL(wp), POINTER, DIMENSION(:,:) ::   za_b      ! old area of ice in category jl
-      REAL(wp), POINTER, DIMENSION(:,:) ::   za_i_1d   ! 1-D version of a_i
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zv_i_1d   ! 1-D version of v_i
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zsmv_i_1d ! 1-D version of smv_i
-
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ze_i_1d !: 1-D version of e_i
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zvrel     ! relative ice / frazil velocity
-
-      REAL(wp) :: zcai = 1.4e-3_wp                     ! ice-air drag (clem: should be dependent on coupling/forcing used)
-      !!-----------------------------------------------------------------------!
-
-      CALL wrk_alloc( jpij, jcat )   ! integer
-      CALL wrk_alloc( jpij, zswinew, zv_newice, za_newice, zh_newice, ze_newice, zs_newice, zo_newice )
-      CALL wrk_alloc( jpij, zdv_res, zda_res, zat_i_1d, zv_frazb, zvrel_1d )
-      CALL wrk_alloc( jpij,jpl, zv_b, za_b, za_i_1d, zv_i_1d, zsmv_i_1d )
-      CALL wrk_alloc( jpij,nlay_i,jpl, ze_i_1d )
-      CALL wrk_alloc( jpi,jpj, zvrel )
-
-      CALL lim_var_agg(1)
-      CALL lim_var_glo2eqv
-      !------------------------------------------------------------------------------|
-      ! 2) Convert units for ice internal energy
-      !------------------------------------------------------------------------------|
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  !Energy of melting q(S,T) [J.m-3]
-                  rswitch          = MAX(  0._wp , SIGN( 1._wp , v_i(ji,jj,jl) - epsi20 )  )   !0 if no ice
-                  e_i(ji,jj,jk,jl) = rswitch * e_i(ji,jj,jk,jl) / MAX( v_i(ji,jj,jl), epsi20 ) * REAL( nlay_i, wp )
-               END DO
-            END DO
-         END DO
-      END DO
-
-      !------------------------------------------------------------------------------!
-      ! 3) Collection thickness of ice formed in leads and polynyas
-      !------------------------------------------------------------------------------!    
-      ! hicol is the thickness of new ice formed in open water
-      ! hicol can be either prescribed (frazswi = 0) or computed (frazswi = 1)
-      ! Frazil ice forms in open water, is transported by wind
-      ! accumulates at the edge of the consolidated ice edge
-      ! where it forms aggregates of a specific thickness called
-      ! collection thickness.
-
-      ! Note : the following algorithm currently breaks vectorization
-      ! 
-
-      zvrel(:,:) = 0._wp
-
-      ! Default new ice thickness
-      WHERE( qlead(:,:) < 0._wp ) ; hicol(:,:) = rn_hnewice
-      ELSEWHERE                   ; hicol(:,:) = 0._wp
-      END WHERE
-
-      IF( ln_frazil ) THEN
-
-         !--------------------
-         ! Physical constants
-         !--------------------
-         hicol(:,:) = 0._wp
-
-         zhicrit = 0.04 ! frazil ice thickness
-         ztwogp  = 2. * rau0 / ( grav * 0.3 * ( rau0 - rhoic ) ) ! reduced grav
-         zsqcd   = 1.0 / SQRT( 1.3 * zcai ) ! 1/SQRT(airdensity*drag)
-         zgamafr = 0.03
-
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1
-               IF ( qlead(ji,jj) < 0._wp .AND. tau_icebfr(ji,jj) == 0._wp ) THEN ! activated if cooling and no landfast
-                  !-------------
-                  ! Wind stress
-                  !-------------
-                  ! C-grid wind stress components
-                  ztaux         = ( utau_ice(ji-1,jj  ) * umask(ji-1,jj  ,1)   &
-                     &          +   utau_ice(ji  ,jj  ) * umask(ji  ,jj  ,1) ) * 0.5_wp
-                  ztauy         = ( vtau_ice(ji  ,jj-1) * vmask(ji  ,jj-1,1)   &
-                     &          +   vtau_ice(ji  ,jj  ) * vmask(ji  ,jj  ,1) ) * 0.5_wp
-                  ! Square root of wind stress
-                  ztenagm       =  SQRT( SQRT( ztaux * ztaux + ztauy * ztauy ) )
-
-                  !---------------------
-                  ! Frazil ice velocity
-                  !---------------------
-                  rswitch = MAX( 0._wp, SIGN( 1._wp , ztenagm - epsi10 ) )
-                  zvfrx   = rswitch * zgamafr * zsqcd * ztaux / MAX( ztenagm, epsi10 )
-                  zvfry   = rswitch * zgamafr * zsqcd * ztauy / MAX( ztenagm, epsi10 )
-
-                  !-------------------
-                  ! Pack ice velocity
-                  !-------------------
-                  ! C-grid ice velocity
-                  zvgx    = ( u_ice(ji-1,jj  ) * umask(ji-1,jj  ,1)  + u_ice(ji,jj) * umask(ji,jj,1) ) * 0.5_wp
-                  zvgy    = ( v_ice(ji  ,jj-1) * vmask(ji  ,jj-1,1)  + v_ice(ji,jj) * vmask(ji,jj,1) ) * 0.5_wp
-
-                  !-----------------------------------
-                  ! Relative frazil/pack ice velocity
-                  !-----------------------------------
-                  ! absolute relative velocity
-                  rswitch      = MAX( 0._wp, SIGN( 1._wp , at_i(ji,jj) - epsi10 ) )
-                  zvrel2       = MAX(  ( zvfrx - zvgx ) * ( zvfrx - zvgx )   &
-                     &               + ( zvfry - zvgy ) * ( zvfry - zvgy ) , 0.15 * 0.15 ) * rswitch
-                  zvrel(ji,jj) = SQRT( zvrel2 )
-
-                  !---------------------
-                  ! Iterative procedure
-                  !---------------------
-                  hicol(ji,jj) = zhicrit +   ( zhicrit + 0.1 )    &
-                     &                   / ( ( zhicrit + 0.1 ) * ( zhicrit + 0.1 ) -  zhicrit * zhicrit ) * ztwogp * zvrel2
-
-                  iter = 1
-                  DO WHILE ( iter < 20 ) 
-                     zf  = ( hicol(ji,jj) - zhicrit ) * ( hicol(ji,jj) * hicol(ji,jj) - zhicrit * zhicrit ) -   &
-                        &    hicol(ji,jj) * zhicrit * ztwogp * zvrel2
-                     zfp = ( hicol(ji,jj) - zhicrit ) * ( 3.0 * hicol(ji,jj) + zhicrit ) - zhicrit * ztwogp * zvrel2
-
-                     hicol(ji,jj) = hicol(ji,jj) - zf / MAX( zfp, epsi20 )
-                     iter = iter + 1
-                  END DO
-
-               ENDIF ! end of selection of pixels where ice forms
-
-            END DO 
-         END DO 
-         ! 
-         CALL lbc_lnk( zvrel, 'T', 1. )
-         CALL lbc_lnk( hicol, 'T', 1. )
-
-      ENDIF ! End of computation of frazil ice collection thickness
-
-      !------------------------------------------------------------------------------!
-      ! 4) Identify grid points where new ice forms
-      !------------------------------------------------------------------------------!
-
-      !-------------------------------------
-      ! Select points for new ice formation
-      !-------------------------------------
-      ! This occurs if open water energy budget is negative (cooling) and there is no landfast ice
-      nbpac = 0
-      npac(:) = 0
-      !
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF ( qlead(ji,jj)  <  0._wp .AND. tau_icebfr(ji,jj) == 0._wp ) THEN
-               nbpac = nbpac + 1
-               npac( nbpac ) = (jj - 1) * jpi + ji
-            ENDIF
-         END DO
-      END DO
-
-      ! debug point to follow
-      jiindex_1d = 0
-      IF( ln_limctl ) THEN
-         DO ji = mi0(iiceprt), mi1(iiceprt)
-            DO jj = mj0(jiceprt), mj1(jiceprt)
-               IF ( qlead(ji,jj)  <  0._wp ) THEN
-                  jiindex_1d = (jj - 1) * jpi + ji
-               ENDIF
-            END DO
-         END DO
-      ENDIF
-   
-      IF( ln_limctl ) WRITE(numout,*) 'lim_thd_lac : nbpac = ', nbpac
-
-      !------------------------------
-      ! Move from 2-D to 1-D vectors
-      !------------------------------
-      ! If ocean gains heat do nothing. Otherwise compute new ice formation
-
-      IF ( nbpac > 0 ) THEN
-
-         CALL tab_2d_1d( nbpac, zat_i_1d  (1:nbpac)     , at_i         , jpi, jpj, npac(1:nbpac) )
-         DO jl = 1, jpl
-            CALL tab_2d_1d( nbpac, za_i_1d  (1:nbpac,jl), a_i  (:,:,jl), jpi, jpj, npac(1:nbpac) )
-            CALL tab_2d_1d( nbpac, zv_i_1d  (1:nbpac,jl), v_i  (:,:,jl), jpi, jpj, npac(1:nbpac) )
-            CALL tab_2d_1d( nbpac, zsmv_i_1d(1:nbpac,jl), smv_i(:,:,jl), jpi, jpj, npac(1:nbpac) )
-            DO jk = 1, nlay_i
-               CALL tab_2d_1d( nbpac, ze_i_1d(1:nbpac,jk,jl), e_i(:,:,jk,jl) , jpi, jpj, npac(1:nbpac) )
-            END DO
-         END DO
-
-         CALL tab_2d_1d( nbpac, qlead_1d  (1:nbpac)     , qlead     , jpi, jpj, npac(1:nbpac) )
-         CALL tab_2d_1d( nbpac, t_bo_1d   (1:nbpac)     , t_bo      , jpi, jpj, npac(1:nbpac) )
-         CALL tab_2d_1d( nbpac, sfx_opw_1d(1:nbpac)     , sfx_opw   , jpi, jpj, npac(1:nbpac) )
-         CALL tab_2d_1d( nbpac, wfx_opw_1d(1:nbpac)     , wfx_opw   , jpi, jpj, npac(1:nbpac) )
-         CALL tab_2d_1d( nbpac, hicol_1d  (1:nbpac)     , hicol     , jpi, jpj, npac(1:nbpac) )
-         CALL tab_2d_1d( nbpac, zvrel_1d  (1:nbpac)     , zvrel     , jpi, jpj, npac(1:nbpac) )
-
-         CALL tab_2d_1d( nbpac, hfx_thd_1d(1:nbpac)     , hfx_thd   , jpi, jpj, npac(1:nbpac) )
-         CALL tab_2d_1d( nbpac, hfx_opw_1d(1:nbpac)     , hfx_opw   , jpi, jpj, npac(1:nbpac) )
-         CALL tab_2d_1d( nbpac, rn_amax_1d(1:nbpac)     , rn_amax_2d, jpi, jpj, npac(1:nbpac) )
-
-         !------------------------------------------------------------------------------!
-         ! 5) Compute thickness, salinity, enthalpy, age, area and volume of new ice
-         !------------------------------------------------------------------------------!
-
-         !-----------------------------------------
-         ! Keep old ice areas and volume in memory
-         !-----------------------------------------
-         zv_b(1:nbpac,:) = zv_i_1d(1:nbpac,:) 
-         za_b(1:nbpac,:) = za_i_1d(1:nbpac,:)
-
-         !----------------------
-         ! Thickness of new ice
-         !----------------------
-         zh_newice(1:nbpac) = hicol_1d(1:nbpac)
-
-         !----------------------
-         ! Salinity of new ice 
-         !----------------------
-         SELECT CASE ( nn_icesal )
-         CASE ( 1 )                    ! Sice = constant 
-            zs_newice(1:nbpac) = rn_icesal
-         CASE ( 2 )                    ! Sice = F(z,t) [Vancoppenolle et al (2005)]
-            DO ji = 1, nbpac
-               ii =   MOD( npac(ji) - 1 , jpi ) + 1
-               ij =      ( npac(ji) - 1 ) / jpi + 1
-               zs_newice(ji) = MIN(  4.606 + 0.91 / zh_newice(ji) , rn_simax , 0.5 * sss_m(ii,ij)  )
-            END DO
-         CASE ( 3 )                    ! Sice = F(z) [multiyear ice]
-            zs_newice(1:nbpac) =   2.3
-         END SELECT
-
-         !-------------------------
-         ! Heat content of new ice
-         !-------------------------
-         ! We assume that new ice is formed at the seawater freezing point
-         DO ji = 1, nbpac
-            ztmelts       = - tmut * zs_newice(ji) + rt0                  ! Melting point (K)
-            ze_newice(ji) =   rhoic * (  cpic * ( ztmelts - t_bo_1d(ji) )                                         &
-               &                       + lfus * ( 1.0 - ( ztmelts - rt0 ) / MIN( t_bo_1d(ji) - rt0, -epsi10 ) )   &
-               &                       - rcp  *         ( ztmelts - rt0 )  )
-         END DO
-
-         !----------------
-         ! Age of new ice
-         !----------------
-         DO ji = 1, nbpac
-            zo_newice(ji) = 0._wp
-         END DO
-
-         !-------------------
-         ! Volume of new ice
-         !-------------------
-         DO ji = 1, nbpac
-
-            zEi           = - ze_newice(ji) * r1_rhoic             ! specific enthalpy of forming ice [J/kg]
-
-            zEw           = rcp * ( t_bo_1d(ji) - rt0 )            ! specific enthalpy of seawater at t_bo_1d [J/kg]
-                                                                   ! clem: we suppose we are already at the freezing point (condition qlead<0 is satisfyied) 
-                                                                   
-            zdE           = zEi - zEw                              ! specific enthalpy difference [J/kg]
-                                              
-            zfmdt         = - qlead_1d(ji) / zdE                   ! Fm.dt [kg/m2] (<0) 
-                                                                   ! clem: we use qlead instead of zqld (limthd) because we suppose we are at the freezing point   
-            zv_newice(ji) = - zfmdt * r1_rhoic
-
-            zQm           = zfmdt * zEw                            ! heat to the ocean >0 associated with mass flux  
-
-            ! Contribution to heat flux to the ocean [W.m-2], >0  
-            hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * zEw * r1_rdtice
-            ! Total heat flux used in this process [W.m-2]  
-            hfx_opw_1d(ji) = hfx_opw_1d(ji) - zfmdt * zdE * r1_rdtice
-            ! mass flux
-            wfx_opw_1d(ji) = wfx_opw_1d(ji) - zv_newice(ji) * rhoic * r1_rdtice
-            ! salt flux
-            sfx_opw_1d(ji) = sfx_opw_1d(ji) - zv_newice(ji) * rhoic * zs_newice(ji) * r1_rdtice
-         END DO
-         
-         zv_frazb(:) = 0._wp
-         IF( ln_frazil ) THEN
-            ! A fraction zfrazb of frazil ice is accreted at the ice bottom
-            DO ji = 1, nbpac
-               rswitch       = 1._wp - MAX( 0._wp, SIGN( 1._wp , - zat_i_1d(ji) ) )
-               zfrazb        = rswitch * ( TANH( rn_Cfrazb * ( zvrel_1d(ji) - rn_vfrazb ) ) + 1.0 ) * 0.5 * rn_maxfrazb
-               zv_frazb(ji)  =         zfrazb   * zv_newice(ji)
-               zv_newice(ji) = ( 1.0 - zfrazb ) * zv_newice(ji)
-            END DO
-         END IF
-         
-         !-----------------
-         ! Area of new ice
-         !-----------------
-         DO ji = 1, nbpac
-            za_newice(ji) = zv_newice(ji) / zh_newice(ji)
-         END DO
-
-         !------------------------------------------------------------------------------!
-         ! 6) Redistribute new ice area and volume into ice categories                  !
-         !------------------------------------------------------------------------------!
-
-         !------------------------
-         ! 6.1) lateral ice growth
-         !------------------------
-         ! If lateral ice growth gives an ice concentration gt 1, then
-         ! we keep the excessive volume in memory and attribute it later to bottom accretion
-         DO ji = 1, nbpac
-            IF ( za_newice(ji) >  ( rn_amax_1d(ji) - zat_i_1d(ji) ) ) THEN
-               zda_res(ji)   = za_newice(ji) - ( rn_amax_1d(ji) - zat_i_1d(ji) )
-               zdv_res(ji)   = zda_res  (ji) * zh_newice(ji) 
-               za_newice(ji) = za_newice(ji) - zda_res  (ji)
-               zv_newice(ji) = zv_newice(ji) - zdv_res  (ji)
-            ELSE
-               zda_res(ji) = 0._wp
-               zdv_res(ji) = 0._wp
-            ENDIF
-         END DO
-
-         ! find which category to fill
-         zat_i_1d(:) = 0._wp
-         DO jl = 1, jpl
-            DO ji = 1, nbpac
-               IF( zh_newice(ji) > hi_max(jl-1) .AND. zh_newice(ji) <= hi_max(jl) ) THEN
-                  za_i_1d (ji,jl) = za_i_1d (ji,jl) + za_newice(ji)
-                  zv_i_1d (ji,jl) = zv_i_1d (ji,jl) + zv_newice(ji)
-                  jcat    (ji)    = jl
-               ENDIF
-               zat_i_1d(ji) = zat_i_1d(ji) + za_i_1d  (ji,jl)
-            END DO
-         END DO
-
-         ! Heat content
-         DO ji = 1, nbpac
-            jl = jcat(ji)                                                    ! categroy in which new ice is put
-            zswinew  (ji) = MAX( 0._wp , SIGN( 1._wp , - za_b(ji,jl) ) )   ! 0 if old ice
-         END DO
-
-         DO jk = 1, nlay_i
-            DO ji = 1, nbpac
-               jl = jcat(ji)
-               rswitch = MAX( 0._wp, SIGN( 1._wp , zv_i_1d(ji,jl) - epsi20 ) )
-               ze_i_1d(ji,jk,jl) = zswinew(ji)   *   ze_newice(ji) +                                                    &
-                  &        ( 1.0 - zswinew(ji) ) * ( ze_newice(ji) * zv_newice(ji) + ze_i_1d(ji,jk,jl) * zv_b(ji,jl) )  &
-                  &        * rswitch / MAX( zv_i_1d(ji,jl), epsi20 )
-            END DO
-         END DO
-
-         !------------------------------------------------
-         ! 6.2) bottom ice growth + ice enthalpy remapping
-         !------------------------------------------------
-         DO jl = 1, jpl
-
-            ! for remapping
-            h_i_old (1:nbpac,0:nlay_i+1) = 0._wp
-            qh_i_old(1:nbpac,0:nlay_i+1) = 0._wp
-            DO jk = 1, nlay_i
-               DO ji = 1, nbpac
-                  h_i_old (ji,jk) = zv_i_1d(ji,jl) * r1_nlay_i
-                  qh_i_old(ji,jk) = ze_i_1d(ji,jk,jl) * h_i_old(ji,jk)
-               END DO
-            END DO
-
-            ! new volumes including lateral/bottom accretion + residual
-            DO ji = 1, nbpac
-               rswitch        = MAX( 0._wp, SIGN( 1._wp , zat_i_1d(ji) - epsi20 ) )
-               zv_newfra      = rswitch * ( zdv_res(ji) + zv_frazb(ji) ) * za_i_1d(ji,jl) / MAX( zat_i_1d(ji) , epsi20 )
-               za_i_1d(ji,jl) = rswitch * za_i_1d(ji,jl)               
-               zv_i_1d(ji,jl) = zv_i_1d(ji,jl) + zv_newfra
-               ! for remapping
-               h_i_old (ji,nlay_i+1) = zv_newfra
-               qh_i_old(ji,nlay_i+1) = ze_newice(ji) * zv_newfra
-            ENDDO
-            ! --- Ice enthalpy remapping --- !
-            CALL lim_thd_ent( 1, nbpac, ze_i_1d(1:nbpac,:,jl) ) 
-         ENDDO
-
-         !-----------------
-         ! Update salinity
-         !-----------------
-         DO jl = 1, jpl
-            DO ji = 1, nbpac
-               zdv   = zv_i_1d(ji,jl) - zv_b(ji,jl)
-               zsmv_i_1d(ji,jl) = zsmv_i_1d(ji,jl) + zdv * zs_newice(ji)
-            END DO
-         END DO
-
-         !------------------------------------------------------------------------------!
-         ! 7) Change 2D vectors to 1D vectors 
-         !------------------------------------------------------------------------------!
-         DO jl = 1, jpl
-            CALL tab_1d_2d( nbpac, a_i (:,:,jl), npac(1:nbpac), za_i_1d (1:nbpac,jl), jpi, jpj )
-            CALL tab_1d_2d( nbpac, v_i (:,:,jl), npac(1:nbpac), zv_i_1d (1:nbpac,jl), jpi, jpj )
-            CALL tab_1d_2d( nbpac, smv_i (:,:,jl), npac(1:nbpac), zsmv_i_1d(1:nbpac,jl) , jpi, jpj )
-            DO jk = 1, nlay_i
-               CALL tab_1d_2d( nbpac, e_i(:,:,jk,jl), npac(1:nbpac), ze_i_1d(1:nbpac,jk,jl), jpi, jpj )
-            END DO
-         END DO
-         CALL tab_1d_2d( nbpac, sfx_opw, npac(1:nbpac), sfx_opw_1d(1:nbpac), jpi, jpj )
-         CALL tab_1d_2d( nbpac, wfx_opw, npac(1:nbpac), wfx_opw_1d(1:nbpac), jpi, jpj )
-
-         CALL tab_1d_2d( nbpac, hfx_thd, npac(1:nbpac), hfx_thd_1d(1:nbpac), jpi, jpj )
-         CALL tab_1d_2d( nbpac, hfx_opw, npac(1:nbpac), hfx_opw_1d(1:nbpac), jpi, jpj )
-         !
-      ENDIF ! nbpac > 0
-
-      !------------------------------------------------------------------------------!
-      ! 8) Change units for e_i
-      !------------------------------------------------------------------------------!    
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  ! heat content in J/m2
-                  e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * v_i(ji,jj,jl) * r1_nlay_i 
-               END DO
-            END DO
-         END DO
-      END DO
-
-      !
-      CALL wrk_dealloc( jpij, jcat )   ! integer
-      CALL wrk_dealloc( jpij, zswinew, zv_newice, za_newice, zh_newice, ze_newice, zs_newice, zo_newice )
-      CALL wrk_dealloc( jpij, zdv_res, zda_res, zat_i_1d, zv_frazb, zvrel_1d )
-      CALL wrk_dealloc( jpij,jpl, zv_b, za_b, za_i_1d, zv_i_1d, zsmv_i_1d )
-      CALL wrk_dealloc( jpij,nlay_i,jpl, ze_i_1d )
-      CALL wrk_dealloc( jpi,jpj, zvrel )
-      !
-   END SUBROUTINE lim_thd_lac
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                               NO  LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_thd_lac           ! Empty routine
-   END SUBROUTINE lim_thd_lac
-#endif
-
-   !!======================================================================
-END MODULE limthd_lac
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limthd_sal.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limthd_sal.F90	(revision 9018)
+++ 	(revision )
@@ -1,161 +1,0 @@
-MODULE limthd_sal
-   !!======================================================================
-   !!                       ***  MODULE limthd_sal ***
-   !! LIM-3 sea-ice :  computation of salinity variations in the ice
-   !!======================================================================
-   !! History :   -   ! 2003-05 (M. Vancoppenolle) UCL-ASTR first coding for LIM3-1D
-   !!            3.0  ! 2005-12 (M. Vancoppenolle) adapted to the 3-D version
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!---------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_thd_sal   : salinity variations in the ice
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-   USE phycst         ! physical constants (ocean directory)
-   USE sbc_oce        ! Surface boundary condition: ocean fields
-   USE ice            ! LIM variables
-   USE thd_ice        ! LIM thermodynamics
-   USE limvar         ! LIM variables
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_thd_sal        ! called by limthd module
-   PUBLIC   lim_thd_sal_init   ! called by sbc_lim_init
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_thd_sal( kideb, kiut )
-      !!-------------------------------------------------------------------
-      !!                ***  ROUTINE lim_thd_sal  ***    
-      !!   
-      !! ** Purpose :   computes new salinities in the ice
-      !!
-      !! ** Method  :  3 possibilities
-      !!               -> nn_icesal = 1 -> Sice = cst    [ice salinity constant in both time & space] 
-      !!               -> nn_icesal = 2 -> Sice = S(z,t) [Vancoppenolle et al. 2005]
-      !!               -> nn_icesal = 3 -> Sice = S(z)   [multiyear ice]
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kideb, kiut   ! thickness category index
-      !
-      INTEGER  ::   ii, ij, ji, jk               ! dummy loop indices 
-      REAL(wp) ::   iflush, igravdr              ! local scalars
-      REAL(wp) ::   zs_sni, zsm_i_gd, zsm_i_fl, zsm_i_si, zsm_i_bg   ! local scalars
-      !!---------------------------------------------------------------------
-
-      !--------------------------------------------------------------------|
-      ! 1) salinity constant in time                                       |
-      !--------------------------------------------------------------------|
-      ! do nothing
-
-      !----------------------------------------------------------------------|
-      !  2) salinity varying in time                                         |
-      !----------------------------------------------------------------------|
-      IF(  nn_icesal == 2  ) THEN
-
-         DO ji = kideb, kiut
-
-            ii = MOD( npb(ji) - 1, jpi ) + 1 ; ij = ( npb(ji) - 1 ) / jpi + 1
-            !---------------------------------------------------------
-            !  Update ice salinity from snow-ice and bottom growth
-            !---------------------------------------------------------
-            zs_sni   = sss_m(ii,ij) * ( rhoic - rhosn ) * r1_rhoic   ! Salinity of snow ice
-            rswitch  = MAX( 0._wp , SIGN( 1._wp , ht_i_1d(ji) - epsi20 ) )
-            zsm_i_si = ( zs_sni      - sm_i_1d(ji) ) *             dh_snowice(ji)  / MAX( ht_i_1d(ji), epsi20 ) * rswitch ! snow-ice    
-            zsm_i_bg = ( s_i_new(ji) - sm_i_1d(ji) ) * MAX( 0._wp, dh_i_bott(ji) ) / MAX( ht_i_1d(ji), epsi20 ) * rswitch ! bottom growth
-
-            ! Update salinity (nb: salt flux already included in limthd_dh)
-            sm_i_1d(ji) = sm_i_1d(ji) + zsm_i_bg + zsm_i_si
-
-            IF( ln_limdS ) THEN
-               !---------------------------------------------------------
-               !  Update ice salinity from brine drainage and flushing
-               !---------------------------------------------------------
-               iflush   = MAX( 0._wp , SIGN( 1._wp , t_su_1d(ji) - rt0         ) )  ! =1 if summer 
-               igravdr  = MAX( 0._wp , SIGN( 1._wp , t_bo_1d(ji) - t_su_1d(ji) ) )  ! =1 if t_su < t_bo
-               zsm_i_gd = - igravdr * MAX( sm_i_1d(ji) - rn_sal_gd , 0._wp ) / rn_time_gd * rdt_ice  ! gravity drainage 
-               zsm_i_fl = - iflush  * MAX( sm_i_1d(ji) - rn_sal_fl , 0._wp ) / rn_time_fl * rdt_ice  ! flushing
-               
-               ! Update salinity   
-               sm_i_1d(ji) = sm_i_1d(ji) + zsm_i_fl + zsm_i_gd
-               
-               ! Salt flux
-               sfx_bri_1d(ji) = sfx_bri_1d(ji) - rhoic * a_i_1d(ji) * ht_i_1d(ji) * ( zsm_i_fl + zsm_i_gd ) * r1_rdtice
-            ENDIF
-         END DO
-
-         ! Salinity profile
-         CALL lim_var_salprof1d( kideb, kiut )
-         !
-      ENDIF 
-
-      !------------------------------------------------------------------------------|
-      !  3) vertical profile of salinity, constant in time                           |
-      !------------------------------------------------------------------------------|
-      IF(  nn_icesal == 3  )   CALL lim_var_salprof1d( kideb, kiut )
-
-      !
-   END SUBROUTINE lim_thd_sal
-
-
-   SUBROUTINE lim_thd_sal_init
-      !!-------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_thd_sal_init  ***
-      !!
-      !! ** Purpose :   initialization of ice salinity parameters
-      !!
-      !! ** Method  :   Read the namicesal namelist and check the parameter
-      !!              values called at the first timestep (nit000)
-      !!
-      !! ** input   :   Namelist namicesal
-      !!-------------------------------------------------------------------
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namicesal/ ln_limdS, nn_icesal, rn_icesal, rn_sal_gd, rn_time_gd,   &
-         &                rn_sal_fl, rn_time_fl, rn_simax, rn_simin 
-      !!-------------------------------------------------------------------
-      !
-      REWIND( numnam_ice_ref )              ! Namelist namicesal in reference namelist : Ice salinity
-      READ  ( numnam_ice_ref, namicesal, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicesal in reference namelist', lwp )
-
-      REWIND( numnam_ice_cfg )              ! Namelist namicesal in configuration namelist : Ice salinity
-      READ  ( numnam_ice_cfg, namicesal, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicesal in configuration namelist', lwp )
-      IF(lwm) WRITE ( numoni, namicesal )
-      !
-      IF(lwp) THEN                           ! control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_thd_sal_init : Ice parameters for salinity '
-         WRITE(numout,*) '~~~~~~~~~~~~~~~~'
-         WRITE(numout,*) '   activate gravity drainage and flushing (T) or not (F)   ln_limdS   = ', ln_limdS
-         WRITE(numout,*) '   switch for salinity                                     nn_icesal  = ', nn_icesal
-         WRITE(numout,*) '   bulk salinity value if nn_icesal = 1                    rn_icesal  = ', rn_icesal
-         WRITE(numout,*) '   restoring salinity for gravity drainage                 rn_sal_gd  = ', rn_sal_gd
-         WRITE(numout,*) '   restoring time for for gravity drainage                 rn_time_gd = ', rn_time_gd
-         WRITE(numout,*) '   restoring salinity for flushing                         rn_sal_fl  = ', rn_sal_fl
-         WRITE(numout,*) '   restoring time for flushing                             rn_time_fl = ', rn_time_fl
-         WRITE(numout,*) '   Maximum tolerated ice salinity                          rn_simax   = ', rn_simax
-         WRITE(numout,*) '   Minimum tolerated ice salinity                          rn_simin   = ', rn_simin
-      ENDIF
-      !
-   END SUBROUTINE lim_thd_sal_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Dummy Module          No LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-   !!======================================================================
-END MODULE limthd_sal
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limtrp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limtrp.F90	(revision 9018)
+++ 	(revision )
@@ -1,545 +1,0 @@
-MODULE limtrp
-   !!======================================================================
-   !!                       ***  MODULE limtrp   ***
-   !! LIM transport ice model : sea-ice advection/diffusion
-   !!======================================================================
-   !! History : LIM-2 ! 2000-01 (M.A. Morales Maqueda, H. Goosse, and T. Fichefet)  Original code
-   !!            3.0  ! 2005-11 (M. Vancoppenolle)   Multi-layer sea ice, salinity variations
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_trp      : advection/diffusion process of sea ice
-   !!----------------------------------------------------------------------
-   USE phycst         ! physical constant
-   USE dom_oce        ! ocean domain
-   USE sbc_oce        ! ocean surface boundary condition
-   USE ice            ! ice variables
-   USE limhdf         ! ice horizontal diffusion
-   USE limvar         ! 
-   USE limadv_prather ! advection scheme (Prather)
-   USE limadv_umx     ! advection scheme (ultimate-macho)
-   !
-   USE in_out_manager ! I/O manager
-   USE lbclnk         ! lateral boundary conditions -- MPP exchanges
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
-   USE prtctl         ! Print control
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE timing         ! Timing
-   USE limcons        ! conservation tests
-   USE limctl         ! control prints
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_trp    ! called by sbcice_lim
-
-   INTEGER  ::   ncfl                 ! number of ice time step with CFL>1/2  
-
-   !! * Substitution
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_trp( kt ) 
-      !!-------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_trp ***
-      !!                    
-      !! ** purpose : advection/diffusion process of sea ice
-      !!
-      !! ** method  : variables included in the process are scalar,   
-      !!     other values are considered as second order. 
-      !!     For advection, one can choose between
-      !!     a) an Ultimate-Macho scheme (whose order is defined by nn_limadv_ord) => nn_limadv=0
-      !!     b) and a second order Prather scheme => nn_limadv=-1
-      !!
-      !! ** action :
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! number of iteration
-      !
-      INTEGER  ::   ji, jj, jk, jm, jl, jt  ! dummy loop indices
-      INTEGER  ::   initad                  ! number of sub-timestep for the advection
-      REAL(wp) ::   zcfl , zusnit           !   -      -
-      CHARACTER(len=80) :: cltmp
-      !
-      REAL(wp) ::    zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b
-      REAL(wp) ::    zdv, zda
-      REAL(wp), POINTER, DIMENSION(:,:)      ::   zatold, zeiold, zesold, zsmvold 
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   zhimax, zviold, zvsold
-      ! --- diffusion --- !
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   zhdfptab
-      INTEGER , PARAMETER                    ::   ihdf_vars  = 6 ! Number of variables in which we apply horizontal diffusion
-                                                                 !  inside limtrp for each ice category , not counting the 
-                                                                 !  variables corresponding to ice_layers 
-      ! --- ultimate macho only --- !
-      REAL(wp)                               ::   zdt
-      REAL(wp), POINTER, DIMENSION(:,:)      ::   zudy, zvdx, zcu_box, zcv_box
-      ! --- prather only --- !
-      REAL(wp), POINTER, DIMENSION(:,:)      ::   zarea
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   z0opw
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   z0ice, z0snw, z0ai, z0es , z0smi , z0oi
-      REAL(wp), POINTER, DIMENSION(:,:,:,:)  ::   z0ei
-      !!
-      !!---------------------------------------------------------------------
-      IF( nn_timing == 1 )  CALL timing_start('limtrp')
-
-      CALL wrk_alloc( jpi,jpj,                            zatold, zeiold, zesold, zsmvold )
-      CALL wrk_alloc( jpi,jpj,jpl,                        zhimax, zviold, zvsold )
-      CALL wrk_alloc( jpi,jpj,jpl*(ihdf_vars + nlay_i)+1, zhdfptab)
- 
-      IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*)''
-         WRITE(numout,*)'limtrp'
-         WRITE(numout,*)'~~~~~~'
-         ncfl = 0                ! nb of time step with CFL > 1/2
-      ENDIF
-      
-      CALL lim_var_agg( 1 ) ! integrated values + ato_i
-
-      !-------------------------------------!
-      !   Advection of sea ice properties   !
-      !-------------------------------------!
-
-      ! conservation test
-      IF( ln_limdiachk )   CALL lim_cons_hsm(0, 'limtrp', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-      
-      ! store old values for diag
-      zviold = v_i
-      zvsold = v_s
-      zsmvold(:,:) = SUM( smv_i(:,:,:), dim=3 )
-      zeiold (:,:) = et_i
-      zesold (:,:) = et_s 
-
-      !--- Thickness correction init. --- !
-      zatold(:,:) = at_i
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               rswitch          = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi20 ) )
-               ht_i  (ji,jj,jl) = v_i (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-               ht_s  (ji,jj,jl) = v_s (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-            END DO
-         END DO
-      END DO
-      ! --- Record max of the surrounding ice thicknesses for correction in case advection creates ice too thick --- !
-      zhimax(:,:,:) = ht_i(:,:,:) + ht_s(:,:,:)
-      DO jl = 1, jpl
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1
-               zhimax(ji,jj,jl) = MAXVAL( ht_i(ji-1:ji+1,jj-1:jj+1,jl) + ht_s(ji-1:ji+1,jj-1:jj+1,jl) )
-            END DO
-         END DO
-         CALL lbc_lnk(zhimax(:,:,jl),'T',1.)
-      END DO
-         
-      ! --- If ice drift field is too fast, use an appropriate time step for advection --- !        
-      zcfl  =            MAXVAL( ABS( u_ice(:,:) ) * rdt_ice * r1_e1u(:,:) )    ! CFL test for stability
-      zcfl  = MAX( zcfl, MAXVAL( ABS( v_ice(:,:) ) * rdt_ice * r1_e2v(:,:) ) )
-      IF( lk_mpp )   CALL mpp_max( zcfl )
-      
-      IF( zcfl > 0.5 ) THEN   ;   initad = 2   ;   zusnit = 0.5_wp
-      ELSE                    ;   initad = 1   ;   zusnit = 1.0_wp
-      ENDIF
-      
-!!      IF( zcfl > 0.5_wp .AND. lwp ) THEN
-!!         ncfl = ncfl + 1
-!!         IF( ncfl > 0 ) THEN   
-!!            WRITE(cltmp,'(i6.1)') ncfl
-!!            CALL ctl_warn( 'lim_trp: ncfl= ', TRIM(cltmp), 'advective ice time-step using a split in sub-time-step ')
-!!         ENDIF
-!!      ENDIF
-
-      SELECT CASE ( nn_limadv )
-         
-                       !=============================!
-      CASE ( 0 )       !==  Ultimate-MACHO scheme  ==!                   
-                       !=============================!
-      
-         CALL wrk_alloc( jpi,jpj, zudy, zvdx, zcu_box, zcv_box )
-      
-         IF( kt == nit000 .AND. lwp ) THEN
-            WRITE(numout,*)''
-            WRITE(numout,*)'lim_adv_umx : Ultimate-MACHO advection scheme'
-            WRITE(numout,*)'~~~~~~~~~~~'
-         ENDIF
-         !
-         zdt = rdt_ice / REAL(initad)
-         
-         ! transport
-         zudy(:,:) = u_ice(:,:) * e2u(:,:)
-         zvdx(:,:) = v_ice(:,:) * e1v(:,:)
-         
-         ! define velocity for advection: u*grad(H)
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1
-               IF    ( u_ice(ji,jj) * u_ice(ji-1,jj) <= 0._wp ) THEN   ;   zcu_box(ji,jj) = 0._wp
-               ELSEIF( u_ice(ji,jj)                  >  0._wp ) THEN   ;   zcu_box(ji,jj) = u_ice(ji-1,jj)
-               ELSE                                                    ;   zcu_box(ji,jj) = u_ice(ji  ,jj)
-               ENDIF
-               
-               IF    ( v_ice(ji,jj) * v_ice(ji,jj-1) <= 0._wp ) THEN   ;   zcv_box(ji,jj) = 0._wp
-               ELSEIF( v_ice(ji,jj)                  >  0._wp ) THEN   ;   zcv_box(ji,jj) = v_ice(ji,jj-1)
-               ELSE                                                    ;   zcv_box(ji,jj) = v_ice(ji,jj  )
-               ENDIF
-            END DO
-         END DO
-         
-         ! advection
-         DO jt = 1, initad
-            CALL lim_adv_umx( kt, zdt, zudy, zvdx, zcu_box, zcv_box, ato_i(:,:) )       ! Open water area 
-            DO jl = 1, jpl
-               CALL lim_adv_umx( kt, zdt, zudy, zvdx, zcu_box, zcv_box, a_i(:,:,jl) )      ! Ice area
-               CALL lim_adv_umx( kt, zdt, zudy, zvdx, zcu_box, zcv_box, v_i(:,:,jl) )      ! Ice  volume
-               CALL lim_adv_umx( kt, zdt, zudy, zvdx, zcu_box, zcv_box, smv_i(:,:,jl) )    ! Salt content
-               CALL lim_adv_umx( kt, zdt, zudy, zvdx, zcu_box, zcv_box, oa_i (:,:,jl) )    ! Age content
-               DO jk = 1, nlay_i
-                  CALL lim_adv_umx( kt, zdt, zudy, zvdx, zcu_box, zcv_box, e_i(:,:,jk,jl) )   ! Ice  heat content
-               END DO
-               CALL lim_adv_umx( kt, zdt, zudy, zvdx, zcu_box, zcv_box, v_s(:,:,jl) )      ! Snow volume
-               CALL lim_adv_umx( kt, zdt, zudy, zvdx, zcu_box, zcv_box, e_s(:,:,1,jl) )    ! Snow heat content
-            END DO
-         END DO
-         !
-         at_i(:,:) = a_i(:,:,1)      ! total ice fraction
-         DO jl = 2, jpl
-            at_i(:,:) = at_i(:,:) + a_i(:,:,jl)
-         END DO
-         !
-         CALL wrk_dealloc( jpi,jpj, zudy, zvdx, zcu_box, zcv_box )
-         
-                       !=============================!
-      CASE ( -1 )      !==     Prather scheme      ==!                   
-                       !=============================!
-
-         CALL wrk_alloc( jpi,jpj,            zarea )
-         CALL wrk_alloc( jpi,jpj,1,          z0opw )
-         CALL wrk_alloc( jpi,jpj,jpl,        z0ice, z0snw, z0ai, z0es , z0smi , z0oi )
-         CALL wrk_alloc( jpi,jpj,nlay_i,jpl, z0ei )
-         
-         IF( kt == nit000 .AND. lwp ) THEN
-            WRITE(numout,*)''
-            WRITE(numout,*)'lim_adv_xy : Prather advection scheme'
-            WRITE(numout,*)'~~~~~~~~~~~'
-         ENDIF
-         
-         zarea(:,:) = e1e2t(:,:)
-         
-         !-------------------------
-         ! transported fields                                        
-         !-------------------------
-         z0opw(:,:,1) = ato_i(:,:) * e1e2t(:,:)             ! Open water area 
-         DO jl = 1, jpl
-            z0snw (:,:,jl)  = v_s  (:,:,  jl) * e1e2t(:,:)  ! Snow volume
-            z0ice(:,:,jl)   = v_i  (:,:,  jl) * e1e2t(:,:)  ! Ice  volume
-            z0ai  (:,:,jl)  = a_i  (:,:,  jl) * e1e2t(:,:)  ! Ice area
-            z0smi (:,:,jl)  = smv_i(:,:,  jl) * e1e2t(:,:)  ! Salt content
-            z0oi (:,:,jl)   = oa_i (:,:,  jl) * e1e2t(:,:)  ! Age content
-            z0es (:,:,jl)   = e_s  (:,:,1,jl) * e1e2t(:,:)  ! Snow heat content
-            DO jk = 1, nlay_i
-               z0ei  (:,:,jk,jl) = e_i  (:,:,jk,jl) * e1e2t(:,:) ! Ice  heat content
-            END DO
-         END DO
-
-
-         IF( MOD( ( kt - 1) / nn_fsbc , 2 ) == 0 ) THEN       !==  odd ice time step:  adv_x then adv_y  ==!
-            DO jt = 1, initad
-               CALL lim_adv_x( zusnit, u_ice, 1._wp, zarea, z0opw (:,:,1), sxopw(:,:),   &             !--- ice open water area
-                  &                                         sxxopw(:,:)  , syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
-               CALL lim_adv_y( zusnit, v_ice, 0._wp, zarea, z0opw (:,:,1), sxopw(:,:),   &
-                  &                                         sxxopw(:,:)  , syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
-               DO jl = 1, jpl
-                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zarea, z0ice (:,:,jl), sxice(:,:,jl),   &    !--- ice volume  ---
-                     &                                         sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zarea, z0ice (:,:,jl), sxice(:,:,jl),   &
-                     &                                         sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zarea, z0snw (:,:,jl), sxsn (:,:,jl),   &    !--- snow volume  ---
-                     &                                         sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zarea, z0snw (:,:,jl), sxsn (:,:,jl),   &
-                     &                                         sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zarea, z0smi (:,:,jl), sxsal(:,:,jl),   &    !--- ice salinity ---
-                     &                                         sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zarea, z0smi (:,:,jl), sxsal(:,:,jl),   &
-                     &                                         sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zarea, z0oi  (:,:,jl), sxage(:,:,jl),   &    !--- ice age      ---     
-                     &                                         sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zarea, z0oi  (:,:,jl), sxage(:,:,jl),   &
-                     &                                         sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zarea, z0ai  (:,:,jl), sxa  (:,:,jl),   &    !--- ice concentrations ---
-                     &                                         sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zarea, z0ai  (:,:,jl), sxa  (:,:,jl),   & 
-                     &                                         sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 1._wp, zarea, z0es  (:,:,jl), sxc0 (:,:,jl),   &    !--- snow heat contents ---
-                     &                                         sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 0._wp, zarea, z0es  (:,:,jl), sxc0 (:,:,jl),   &
-                     &                                         sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
-                  DO jk = 1, nlay_i                                                                !--- ice heat contents ---
-                     CALL lim_adv_x( zusnit, u_ice, 1._wp, zarea, z0ei(:,:,jk,jl), sxe (:,:,jk,jl),   & 
-                        &                                         sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
-                        &                                         syye(:,:,jk,jl), sxye(:,:,jk,jl) )
-                     CALL lim_adv_y( zusnit, v_ice, 0._wp, zarea, z0ei(:,:,jk,jl), sxe (:,:,jk,jl),   & 
-                        &                                         sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
-                        &                                         syye(:,:,jk,jl), sxye(:,:,jk,jl) )
-                  END DO
-               END DO
-            END DO
-         ELSE
-            DO jt = 1, initad
-               CALL lim_adv_y( zusnit, v_ice, 1._wp, zarea, z0opw (:,:,1), sxopw(:,:),   &             !--- ice open water area
-                  &                                         sxxopw(:,:)  , syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
-               CALL lim_adv_x( zusnit, u_ice, 0._wp, zarea, z0opw (:,:,1), sxopw(:,:),   &
-                  &                                         sxxopw(:,:)  , syopw(:,:), syyopw(:,:), sxyopw(:,:)  )
-               DO jl = 1, jpl
-                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zarea, z0ice (:,:,jl), sxice(:,:,jl),   &    !--- ice volume  ---
-                     &                                         sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zarea, z0ice (:,:,jl), sxice(:,:,jl),   &
-                     &                                         sxxice(:,:,jl), syice(:,:,jl), syyice(:,:,jl), sxyice(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zarea, z0snw (:,:,jl), sxsn (:,:,jl),   &    !--- snow volume  ---
-                     &                                         sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zarea, z0snw (:,:,jl), sxsn (:,:,jl),   &
-                     &                                         sxxsn (:,:,jl), sysn (:,:,jl), syysn (:,:,jl), sxysn (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zarea, z0smi (:,:,jl), sxsal(:,:,jl),   &    !--- ice salinity ---
-                     &                                         sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zarea, z0smi (:,:,jl), sxsal(:,:,jl),   &
-                     &                                         sxxsal(:,:,jl), sysal(:,:,jl), syysal(:,:,jl), sxysal(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zarea, z0oi  (:,:,jl), sxage(:,:,jl),   &   !--- ice age      ---
-                     &                                         sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zarea, z0oi  (:,:,jl), sxage(:,:,jl),   &
-                     &                                         sxxage(:,:,jl), syage(:,:,jl), syyage(:,:,jl), sxyage(:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zarea, z0ai  (:,:,jl), sxa  (:,:,jl),   &   !--- ice concentrations ---
-                     &                                         sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zarea, z0ai  (:,:,jl), sxa  (:,:,jl),   &
-                     &                                         sxxa  (:,:,jl), sya  (:,:,jl), syya  (:,:,jl), sxya  (:,:,jl)  )
-                  CALL lim_adv_y( zusnit, v_ice, 1._wp, zarea, z0es  (:,:,jl), sxc0 (:,:,jl),   &  !--- snow heat contents ---
-                     &                                         sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
-                  CALL lim_adv_x( zusnit, u_ice, 0._wp, zarea, z0es  (:,:,jl), sxc0 (:,:,jl),   &
-                     &                                         sxxc0 (:,:,jl), syc0 (:,:,jl), syyc0 (:,:,jl), sxyc0 (:,:,jl)  )
-                  DO jk = 1, nlay_i                                                           !--- ice heat contents ---
-                     CALL lim_adv_y( zusnit, v_ice, 1._wp, zarea, z0ei(:,:,jk,jl), sxe (:,:,jk,jl),   & 
-                        &                                         sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
-                        &                                         syye(:,:,jk,jl), sxye(:,:,jk,jl) )
-                     CALL lim_adv_x( zusnit, u_ice, 0._wp, zarea, z0ei(:,:,jk,jl), sxe (:,:,jk,jl),   & 
-                        &                                         sxxe(:,:,jk,jl), sye (:,:,jk,jl),   &
-                        &                                         syye(:,:,jk,jl), sxye(:,:,jk,jl) )
-                  END DO
-               END DO
-            END DO
-         ENDIF
-
-         !-------------------------------------------
-         ! Recover the properties from their contents
-         !-------------------------------------------
-         ato_i(:,:) = z0opw(:,:,1) * r1_e1e2t(:,:)
-         DO jl = 1, jpl
-            v_i  (:,:,  jl) = z0ice(:,:,jl) * r1_e1e2t(:,:)
-            v_s  (:,:,  jl) = z0snw(:,:,jl) * r1_e1e2t(:,:)
-            smv_i(:,:,  jl) = z0smi(:,:,jl) * r1_e1e2t(:,:)
-            oa_i (:,:,  jl) = z0oi (:,:,jl) * r1_e1e2t(:,:)
-            a_i  (:,:,  jl) = z0ai (:,:,jl) * r1_e1e2t(:,:)
-            e_s  (:,:,1,jl) = z0es (:,:,jl) * r1_e1e2t(:,:)
-            DO jk = 1, nlay_i
-               e_i(:,:,jk,jl) = z0ei(:,:,jk,jl) * r1_e1e2t(:,:)
-            END DO
-         END DO
-
-         at_i(:,:) = a_i(:,:,1)      ! total ice fraction
-         DO jl = 2, jpl
-            at_i(:,:) = at_i(:,:) + a_i(:,:,jl)
-         END DO
-         
-         CALL wrk_dealloc( jpi,jpj,            zarea )
-         CALL wrk_dealloc( jpi,jpj,1,          z0opw )
-         CALL wrk_dealloc( jpi,jpj,jpl,        z0ice, z0snw, z0ai, z0es , z0smi , z0oi )
-         CALL wrk_dealloc( jpi,jpj,nlay_i,jpl, z0ei )
-
-      END SELECT
-      
-      !------------------------------!
-      ! Diffusion of Ice fields                  
-      !------------------------------!
-      IF( nn_ahi0 /= -1 .AND. nn_limdyn == 2 ) THEN
-         !
-         ! --- Prepare diffusion for variables with categories --- !
-         !     mask eddy diffusivity coefficient at ocean U- and V-points
-         jm=1
-         DO jl = 1, jpl
-            DO jj = 1, jpjm1                 ! NB: has not to be defined on jpj line and jpi row
-               DO ji = 1 , fs_jpim1
-                  pahu3D(ji,jj,jl) = ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -a_i(ji  ,jj,  jl ) ) ) )   &
-                  &                * ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -a_i(ji+1,jj,  jl ) ) ) ) * ahiu(ji,jj)
-                  pahv3D(ji,jj,jl) = ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -a_i(ji,  jj,  jl ) ) ) )   &
-                  &                * ( 1._wp - MAX( 0._wp, SIGN( 1._wp,- a_i(ji,  jj+1,jl ) ) ) ) * ahiv(ji,jj)
-               END DO
-            END DO
-
-            zhdfptab(:,:,jm)= a_i  (:,:,  jl); jm = jm + 1
-            zhdfptab(:,:,jm)= v_i  (:,:,  jl); jm = jm + 1
-            zhdfptab(:,:,jm)= v_s  (:,:,  jl); jm = jm + 1
-            zhdfptab(:,:,jm)= smv_i(:,:,  jl); jm = jm + 1
-            zhdfptab(:,:,jm)= oa_i (:,:,  jl); jm = jm + 1
-            zhdfptab(:,:,jm)= e_s  (:,:,1,jl); jm = jm + 1
-            ! Sample of adding more variables to apply lim_hdf (ihdf_vars must be increased)
-            !   zhdfptab(:,:,jm) = variable_1 (:,:,1,jl); jm = jm + 1  
-            !   zhdfptab(:,:,jm) = variable_2 (:,:,1,jl); jm = jm + 1 
-            DO jk = 1, nlay_i
-              zhdfptab(:,:,jm)=e_i(:,:,jk,jl); jm= jm+1
-            END DO
-         END DO
-
-         ! --- Prepare diffusion for open water area --- !
-         !     mask eddy diffusivity coefficient at ocean U- and V-points
-         DO jj = 1, jpjm1                    ! NB: has not to be defined on jpj line and jpi row
-            DO ji = 1 , fs_jpim1
-               pahu3D(ji,jj,jpl+1) = ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -at_i(ji  ,jj) ) ) )   &
-                  &                * ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -at_i(ji+1,jj) ) ) ) * ahiu(ji,jj)
-               pahv3D(ji,jj,jpl+1) = ( 1._wp - MAX( 0._wp, SIGN( 1._wp, -at_i(ji,jj  ) ) ) )   &
-                  &                * ( 1._wp - MAX( 0._wp, SIGN( 1._wp,- at_i(ji,jj+1) ) ) ) * ahiv(ji,jj)
-            END DO
-         END DO
-         !
-         zhdfptab(:,:,jm)= ato_i  (:,:);
-
-         ! --- Apply diffusion --- !
-         CALL lim_hdf( zhdfptab, ihdf_vars )
-
-         ! --- Recover properties --- !
-         jm=1
-         DO jl = 1, jpl
-            a_i  (:,:,  jl) = zhdfptab(:,:,jm); jm = jm + 1
-            v_i  (:,:,  jl) = zhdfptab(:,:,jm); jm = jm + 1
-            v_s  (:,:,  jl) = zhdfptab(:,:,jm); jm = jm + 1
-            smv_i(:,:,  jl) = zhdfptab(:,:,jm); jm = jm + 1
-            oa_i (:,:,  jl) = zhdfptab(:,:,jm); jm = jm + 1
-            e_s  (:,:,1,jl) = zhdfptab(:,:,jm); jm = jm + 1
-            ! Sample of adding more variables to apply lim_hdf
-            !   variable_1  (:,:,1,jl) = zhdfptab(:,:, jm  ) ; jm + 1 
-            !   variable_2  (:,:,1,jl) = zhdfptab(:,:, jm  ) ; jm + 1
-            DO jk = 1, nlay_i
-               e_i(:,:,jk,jl) = zhdfptab(:,:,jm);jm= jm + 1
-            END DO
-         END DO
-         ato_i  (:,:) = zhdfptab(:,:,jm)
-              
-      ENDIF
-
-      ! --- diags ---
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            diag_trp_ei (ji,jj) = ( SUM( e_i  (ji,jj,1:nlay_i,:) ) -  zeiold(ji,jj) ) * r1_rdtice
-            diag_trp_es (ji,jj) = ( SUM( e_s  (ji,jj,1:nlay_s,:) ) -  zesold(ji,jj) ) * r1_rdtice
-            diag_trp_smv(ji,jj) = ( SUM( smv_i(ji,jj,:)          ) - zsmvold(ji,jj) ) * r1_rdtice
-            diag_trp_vi (ji,jj) =   SUM(   v_i(ji,jj,:)            -  zviold(ji,jj,:) ) * r1_rdtice
-            diag_trp_vs (ji,jj) =   SUM(   v_s(ji,jj,:)            -  zvsold(ji,jj,:) ) * r1_rdtice
-         END DO
-      END DO
-      
-      IF( nn_limdyn == 2) THEN
-
-         ! zap small areas
-         CALL lim_var_zapsmall
-           
-         !--- Thickness correction in case too high --- !
-         DO jl = 1, jpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  
-                  IF ( v_i(ji,jj,jl) > 0._wp ) THEN
-                     
-                     rswitch          = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi20 ) )
-                     ht_i  (ji,jj,jl) = v_i (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-                     ht_s  (ji,jj,jl) = v_s (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-                     
-                     zdv  = v_i(ji,jj,jl) + v_s(ji,jj,jl) - zviold(ji,jj,jl) - zvsold(ji,jj,jl)  
-                     
-                     IF ( ( zdv >  0.0 .AND. (ht_i(ji,jj,jl)+ht_s(ji,jj,jl)) > zhimax(ji,jj,jl) .AND. zatold(ji,jj) < 0.80 ) .OR. &
-                        & ( zdv <= 0.0 .AND. (ht_i(ji,jj,jl)+ht_s(ji,jj,jl)) > zhimax(ji,jj,jl) ) ) THEN
-                        
-                        rswitch        = MAX( 0._wp, SIGN( 1._wp, zhimax(ji,jj,jl) - epsi20 ) )
-                        a_i(ji,jj,jl)  = rswitch * ( v_i(ji,jj,jl) + v_s(ji,jj,jl) ) / MAX( zhimax(ji,jj,jl), epsi20 )
-                        
-                        ! small correction due to *rswitch for a_i
-                        v_i  (ji,jj,jl)        = rswitch * v_i  (ji,jj,jl)
-                        v_s  (ji,jj,jl)        = rswitch * v_s  (ji,jj,jl)
-                        smv_i(ji,jj,jl)        = rswitch * smv_i(ji,jj,jl)
-                        e_s(ji,jj,1,jl)        = rswitch * e_s(ji,jj,1,jl)
-                        e_i(ji,jj,1:nlay_i,jl) = rswitch * e_i(ji,jj,1:nlay_i,jl)
-                                                
-                     ENDIF
-                     
-                  ENDIF
-                
-               END DO
-            END DO
-         END DO
-         ! -------------------------------------------------
-         
-         ! Force the upper limit of ht_i to always be < hi_max (99 m).
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               rswitch         = MAX( 0._wp , SIGN( 1._wp, ht_i(ji,jj,jpl) - epsi20 ) )
-               ht_i(ji,jj,jpl) = MIN( ht_i(ji,jj,jpl) , hi_max(jpl) )
-               a_i (ji,jj,jpl) = v_i(ji,jj,jpl) / MAX( ht_i(ji,jj,jpl) , epsi20 ) * rswitch
-            END DO
-         END DO
-
-      ENDIF
-         
-      !------------------------------------------------------------
-      ! Impose a_i < amax if no ridging/rafting or in mono-category
-      !------------------------------------------------------------
-      !
-      at_i(:,:) = SUM( a_i(:,:,:), dim=3 )
-      IF ( nn_limdyn == 1 .OR. ( ( nn_monocat == 2 ) .AND. ( jpl == 1 ) ) ) THEN ! simple conservative piling, comparable with LIM2
-         DO jl = 1, jpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  rswitch       = MAX( 0._wp, SIGN( 1._wp, at_i(ji,jj) - epsi20 ) )
-                  zda           = rswitch * MIN( rn_amax_2d(ji,jj) - at_i(ji,jj), 0._wp )  &
-                     &                    * a_i(ji,jj,jl) / MAX( at_i(ji,jj), epsi20 )
-                  a_i(ji,jj,jl) = a_i(ji,jj,jl) + zda
-               END DO
-            END DO
-         END DO
-      ENDIF
-      
-      ! --- agglomerate variables -----------------
-      vt_i(:,:) = SUM( v_i(:,:,:), dim=3 )
-      vt_s(:,:) = SUM( v_s(:,:,:), dim=3 )
-      at_i(:,:) = SUM( a_i(:,:,:), dim=3 )
-      
-      ! --- open water = 1 if at_i=0 --------------------------------
-      WHERE( at_i == 0._wp ) ato_i = 1._wp 
-      
-      ! conservation test
-      IF( ln_limdiachk )   CALL lim_cons_hsm(1, 'limtrp', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-        
-      ! -------------------------------------------------
-      ! control prints
-      ! -------------------------------------------------
-      IF( ln_limctl )   CALL lim_prt( kt, iiceprt, jiceprt,-1, ' - ice dyn & trp - ' )
-      !
-      CALL wrk_dealloc( jpi,jpj,                            zatold, zeiold, zesold, zsmvold )
-      CALL wrk_dealloc( jpi,jpj,jpl,                        zhimax, zviold, zvsold )
-      CALL wrk_dealloc( jpi,jpj,jpl*(ihdf_vars + nlay_i)+1, zhdfptab)
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('limtrp')
-      !
-   END SUBROUTINE lim_trp
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Empty Module                No sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_trp        ! Empty routine
-   END SUBROUTINE lim_trp
-#endif
-   !!======================================================================
-END MODULE limtrp
-
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limupdate1.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limupdate1.F90	(revision 9018)
+++ 	(revision )
@@ -1,156 +1,0 @@
-MODULE limupdate1
-   !!======================================================================
-   !!                     ***  MODULE  limupdate1  ***
-   !!   LIM-3 : Update of sea-ice global variables at the end of the time step
-   !!======================================================================
-   !! History :  3.0  !  2006-04  (M. Vancoppenolle) Original code
-   !!            3.5  !  2014-06  (C. Rousset)       Complete rewriting/cleaning
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!    lim_update1   : computes update of sea-ice global variables from trend terms
-   !!----------------------------------------------------------------------
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice fields
-   USE dom_oce
-   USE phycst          ! physical constants
-   USE ice
-   USE thd_ice         ! LIM thermodynamic sea-ice variables
-   USE limitd_th
-   USE limvar
-   USE wrk_nemo        ! work arrays
-   USE timing          ! Timing
-   USE limcons         ! conservation tests
-   USE limctl          ! control prints
-   USE lib_mpp         ! MPP library
-   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE in_out_manager  ! I/O manager
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_update1
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_update1( kt )
-      !!-------------------------------------------------------------------
-      !!               ***  ROUTINE lim_update1  ***
-      !!               
-      !! ** Purpose :  Computes update of sea-ice global variables at 
-      !!               the end of the dynamics.
-      !!                
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt    ! number of iteration
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      REAL(wp) ::   zsal
-      REAL(wp) ::   zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
-      !!-------------------------------------------------------------------
-      IF( nn_timing == 1 )  CALL timing_start('limupdate1')
-
-      IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*)'' 
-         WRITE(numout,*)' lim_update1 ' 
-         WRITE(numout,*)' ~~~~~~~~~~~ '
-      ENDIF
-
-      ! conservation test
-      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'limupdate1', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      !----------------------------------------------------
-      ! ice concentration should not exceed amax 
-      !-----------------------------------------------------
-      at_i(:,:) = 0._wp
-      DO jl = 1, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-      DO jl  = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( at_i(ji,jj) > rn_amax_2d(ji,jj) .AND. a_i(ji,jj,jl) > 0._wp ) THEN
-                  a_i (ji,jj,jl) = a_i (ji,jj,jl) * ( 1._wp - ( 1._wp - rn_amax_2d(ji,jj) / at_i(ji,jj) ) )
-                  oa_i(ji,jj,jl) = oa_i(ji,jj,jl) * ( 1._wp - ( 1._wp - rn_amax_2d(ji,jj) / at_i(ji,jj) ) )
-               ENDIF
-            END DO
-         END DO
-      END DO
-    
-      !---------------------
-      ! Ice salinity bounds
-      !---------------------
-      IF (  nn_icesal == 2  ) THEN 
-         DO jl = 1, jpl
-            DO jj = 1, jpj 
-               DO ji = 1, jpi
-                  zsal            = smv_i(ji,jj,jl)
-                  ! salinity stays in bounds
-                  rswitch         = 1._wp - MAX( 0._wp, SIGN( 1._wp, - v_i(ji,jj,jl) ) )
-                  smv_i(ji,jj,jl) = rswitch * MAX( MIN( rn_simax * v_i(ji,jj,jl), smv_i(ji,jj,jl) ), rn_simin * v_i(ji,jj,jl) )
-                  ! associated salt flux
-                  sfx_res(ji,jj) = sfx_res(ji,jj) - ( smv_i(ji,jj,jl) - zsal ) * rhoic * r1_rdtice
-               END DO
-            END DO
-         END DO
-      ENDIF
-
-      !----------------------------------------------------
-      ! Rebin categories with thickness out of bounds
-      !----------------------------------------------------
-      IF ( jpl > 1 ) CALL lim_itd_th_reb(1, jpl)
-
-      !-----------------
-      ! zap small values
-      !-----------------
-      CALL lim_var_zapsmall
-
-      ! -------------------------------------------------
-      ! Diagnostics
-      ! -------------------------------------------------
-      DO jl  = 1, jpl
-         afx_dyn(:,:) = afx_dyn(:,:) + ( a_i(:,:,jl) - a_i_b(:,:,jl) ) * r1_rdtice
-      END DO
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi            
-            ! heat content variation (W.m-2)
-            diag_heat(ji,jj) = - ( SUM( e_i(ji,jj,1:nlay_i,:) - e_i_b(ji,jj,1:nlay_i,:) ) +  & 
-               &                   SUM( e_s(ji,jj,1:nlay_s,:) - e_s_b(ji,jj,1:nlay_s,:) )    &
-               &                 ) * r1_rdtice
-            ! salt, volume
-            diag_smvi(ji,jj) = SUM( smv_i(ji,jj,:) - smv_i_b(ji,jj,:) ) * rhoic * r1_rdtice
-            diag_vice(ji,jj) = SUM( v_i  (ji,jj,:) - v_i_b  (ji,jj,:) ) * rhoic * r1_rdtice
-            diag_vsnw(ji,jj) = SUM( v_s  (ji,jj,:) - v_s_b  (ji,jj,:) ) * rhosn * r1_rdtice
-         END DO
-      END DO
-
-      ! conservation test
-      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'limupdate1', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      ! control prints
-      IF( ln_ctl )       CALL lim_prt3D( 'limupdate1' )
-   
-      IF( nn_timing == 1 )  CALL timing_stop('limupdate1')
-
-   END SUBROUTINE lim_update1
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Empty Module               No sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_update1     ! Empty routine
-   END SUBROUTINE lim_update1
-
-#endif
-
-END MODULE limupdate1
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limupdate2.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limupdate2.F90	(revision 9018)
+++ 	(revision )
@@ -1,197 +1,0 @@
-MODULE limupdate2
-   !!======================================================================
-   !!                     ***  MODULE  limupdate2  ***
-   !!   LIM-3 : Update of sea-ice global variables at the end of the time step
-   !!======================================================================
-   !! History :  3.0  !  2006-04  (M. Vancoppenolle) Original code
-   !!            3.5  !  2014-06  (C. Rousset)       Complete rewriting/cleaning
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!    lim_update2   : computes update of sea-ice global variables from trend terms
-   !!----------------------------------------------------------------------
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice fields
-   USE dom_oce
-   USE phycst          ! physical constants
-   USE ice
-   USE thd_ice         ! LIM thermodynamic sea-ice variables
-   USE limitd_th
-   USE limvar
-   USE lbclnk          ! lateral boundary condition - MPP exchanges
-   USE wrk_nemo        ! work arrays
-   USE timing          ! Timing
-   USE limcons         ! conservation tests
-   USE limctl
-   USE lib_mpp         ! MPP library
-   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE in_out_manager
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_update2   ! routine called by ice_step
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_update2( kt )
-      !!-------------------------------------------------------------------
-      !!               ***  ROUTINE lim_update2  ***
-      !!               
-      !! ** Purpose :  Computes update of sea-ice global variables at 
-      !!               the end of the time step.
-      !!
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt    ! number of iteration
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      REAL(wp) ::   zsal
-      REAL(wp) ::   zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
-      !!-------------------------------------------------------------------
-      IF( nn_timing == 1 )  CALL timing_start('limupdate2')
-
-      IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*)''
-         WRITE(numout,*)' lim_update2 '
-         WRITE(numout,*)' ~~~~~~~~~~~ '
-      ENDIF
-
-      ! conservation test
-      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'limupdate2', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      !----------------------------------------------------------------------
-      ! Constrain the thickness of the smallest category above himin
-      !----------------------------------------------------------------------
-      DO jj = 1, jpj 
-         DO ji = 1, jpi
-            rswitch = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,1) - epsi20 ) )   !0 if no ice and 1 if yes
-            ht_i(ji,jj,1) = v_i (ji,jj,1) / MAX( a_i(ji,jj,1) , epsi20 ) * rswitch
-            IF( v_i(ji,jj,1) > 0._wp .AND. ht_i(ji,jj,1) < rn_himin ) THEN
-               a_i (ji,jj,1) = a_i (ji,jj,1) * ht_i(ji,jj,1) / rn_himin
-               oa_i(ji,jj,1) = oa_i(ji,jj,1) * ht_i(ji,jj,1) / rn_himin
-            ENDIF
-         END DO
-      END DO
-      
-      !-----------------------------------------------------
-      ! ice concentration should not exceed amax 
-      !-----------------------------------------------------
-      at_i(:,:) = 0._wp
-      DO jl = 1, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-      DO jl  = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( at_i(ji,jj) > rn_amax_2d(ji,jj) .AND. a_i(ji,jj,jl) > 0._wp ) THEN
-                  a_i (ji,jj,jl) = a_i (ji,jj,jl) * ( 1._wp - ( 1._wp - rn_amax_2d(ji,jj) / at_i(ji,jj) ) )
-                  oa_i(ji,jj,jl) = oa_i(ji,jj,jl) * ( 1._wp - ( 1._wp - rn_amax_2d(ji,jj) / at_i(ji,jj) ) )
-               ENDIF
-            END DO
-         END DO
-      END DO
-
-      !---------------------
-      ! Ice salinity
-      !---------------------
-      IF (  nn_icesal == 2  ) THEN 
-         DO jl = 1, jpl
-            DO jj = 1, jpj 
-               DO ji = 1, jpi
-                  zsal            = smv_i(ji,jj,jl)
-                  ! salinity stays in bounds
-                  rswitch         = 1._wp - MAX( 0._wp, SIGN( 1._wp, - v_i(ji,jj,jl) ) )
-                  smv_i(ji,jj,jl) = rswitch * MAX( MIN( rn_simax * v_i(ji,jj,jl), smv_i(ji,jj,jl) ), rn_simin * v_i(ji,jj,jl) )
-                  ! associated salt flux
-                  sfx_res(ji,jj) = sfx_res(ji,jj) - ( smv_i(ji,jj,jl) - zsal ) * rhoic * r1_rdtice
-               END DO
-            END DO
-         END DO
-      ENDIF
-
-      !----------------------------------------------------
-      ! Rebin categories with thickness out of bounds
-      !----------------------------------------------------
-      IF ( jpl > 1 ) CALL lim_itd_th_reb( 1, jpl )
-
-      !-----------------
-      ! zap small values
-      !-----------------
-      CALL lim_var_zapsmall
-
-      !------------------------------------------------------------------------------
-      ! Corrections to avoid wrong values                                        |
-      !------------------------------------------------------------------------------
-      ! Ice drift
-      !------------
-      DO jj = 2, jpjm1
-         DO ji = 2, jpim1
-            IF ( at_i(ji,jj) == 0._wp ) THEN ! what to do if there is no ice
-               IF ( at_i(ji+1,jj) == 0._wp ) u_ice(ji,jj)   = 0._wp ! right side
-               IF ( at_i(ji-1,jj) == 0._wp ) u_ice(ji-1,jj) = 0._wp ! left side
-               IF ( at_i(ji,jj+1) == 0._wp ) v_ice(ji,jj)   = 0._wp ! upper side
-               IF ( at_i(ji,jj-1) == 0._wp ) v_ice(ji,jj-1) = 0._wp ! bottom side
-            ENDIF
-         END DO
-      END DO
-      !lateral boundary conditions
-      CALL lbc_lnk( u_ice(:,:), 'U', -1. )
-      CALL lbc_lnk( v_ice(:,:), 'V', -1. )
-      !mask velocities
-      u_ice(:,:) = u_ice(:,:) * umask(:,:,1)
-      v_ice(:,:) = v_ice(:,:) * vmask(:,:,1)
- 
-      ! -------------------------------------------------
-      ! Diagnostics
-      ! -------------------------------------------------
-      DO jl  = 1, jpl
-         oa_i(:,:,jl) = oa_i(:,:,jl) + a_i(:,:,jl) * rdt_ice / rday   ! ice natural aging
-         afx_thd(:,:) = afx_thd(:,:) + ( a_i(:,:,jl) - a_i_b(:,:,jl) ) * r1_rdtice
-      END DO
-      afx_tot = afx_thd + afx_dyn
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi            
-            ! heat content variation (W.m-2)
-            diag_heat(ji,jj) = diag_heat(ji,jj) -  &
-               &               ( SUM( e_i(ji,jj,1:nlay_i,:) - e_i_b(ji,jj,1:nlay_i,:) ) +  & 
-               &                 SUM( e_s(ji,jj,1:nlay_s,:) - e_s_b(ji,jj,1:nlay_s,:) )    &
-               &               ) * r1_rdtice   
-            ! salt, volume
-            diag_smvi(ji,jj) = diag_smvi(ji,jj) + SUM( smv_i(ji,jj,:) - smv_i_b(ji,jj,:) ) * rhoic * r1_rdtice
-            diag_vice(ji,jj) = diag_vice(ji,jj) + SUM( v_i  (ji,jj,:) - v_i_b  (ji,jj,:) ) * rhoic * r1_rdtice
-            diag_vsnw(ji,jj) = diag_vsnw(ji,jj) + SUM( v_s  (ji,jj,:) - v_s_b  (ji,jj,:) ) * rhosn * r1_rdtice
-         END DO
-      END DO
-
-      ! conservation test
-      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'limupdate2', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      ! control prints
-      IF( ln_limctl )    CALL lim_prt( kt, iiceprt, jiceprt, 2, ' - Final state - ' )
-      IF( ln_ctl )       CALL lim_prt3D( 'limupdate2' )
-   
-      IF( nn_timing == 1 )  CALL timing_stop('limupdate2')
-
-   END SUBROUTINE lim_update2
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Empty Module               No sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_update2     ! Empty routine
-   END SUBROUTINE lim_update2
-
-#endif
-
-END MODULE limupdate2
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limvar.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limvar.F90	(revision 9018)
+++ 	(revision )
@@ -1,796 +1,0 @@
-MODULE limvar
-   !!======================================================================
-   !!                       ***  MODULE limvar ***
-   !!                 Different sets of ice model variables 
-   !!                   how to switch from one to another
-   !!
-   !!                 There are three sets of variables
-   !!                 VGLO : global variables of the model
-   !!                        - v_i (jpi,jpj,jpl)
-   !!                        - v_s (jpi,jpj,jpl)
-   !!                        - a_i (jpi,jpj,jpl)
-   !!                        - t_s (jpi,jpj,jpl)
-   !!                        - e_i (jpi,jpj,nlay_i,jpl)
-   !!                        - smv_i(jpi,jpj,jpl)
-   !!                        - oa_i (jpi,jpj,jpl)
-   !!                 VEQV : equivalent variables sometimes used in the model
-   !!                        - ht_i(jpi,jpj,jpl)
-   !!                        - ht_s(jpi,jpj,jpl)
-   !!                        - t_i (jpi,jpj,nlay_i,jpl)
-   !!                        ...
-   !!                 VAGG : aggregate variables, averaged/summed over all
-   !!                        thickness categories
-   !!                        - vt_i(jpi,jpj)
-   !!                        - vt_s(jpi,jpj)
-   !!                        - at_i(jpi,jpj)
-   !!                        - et_s(jpi,jpj)  !total snow heat content
-   !!                        - et_i(jpi,jpj)  !total ice thermal content 
-   !!                        - smt_i(jpi,jpj) !mean ice salinity
-   !!                        - tm_i (jpi,jpj) !mean ice temperature
-   !!======================================================================
-   !! History :   -   ! 2006-01 (M. Vancoppenolle) Original code
-   !!            3.4  ! 2011-02 (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-   USE phycst         ! physical constants (ocean directory) 
-   USE sbc_oce        ! Surface boundary condition: ocean fields
-   USE ice            ! ice variables
-   USE thd_ice        ! ice variables (thermodynamics)
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_var_agg          
-   PUBLIC   lim_var_glo2eqv      
-   PUBLIC   lim_var_eqv2glo      
-   PUBLIC   lim_var_salprof      
-   PUBLIC   lim_var_bv           
-   PUBLIC   lim_var_salprof1d    
-   PUBLIC   lim_var_zapsmall
-   PUBLIC   lim_var_itd
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 3.5 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_var_agg( kn )
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_var_agg  ***
-      !!
-      !! ** Purpose :   aggregates ice-thickness-category variables to all-ice variables
-      !!              i.e. it turns VGLO into VAGG
-      !! ** Method  :
-      !!
-      !! ** Arguments : n = 1, at_i vt_i only
-      !!                n = 2 everything
-      !!
-      !! note : you could add an argument when you need only at_i, vt_i
-      !!        and when you need everything
-      !!------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kn     ! =1 at_i & vt only ; = what is needed
-      !
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      !!------------------------------------------------------------------
-
-      ! integrated values
-      vt_i (:,:) = SUM( v_i, dim=3 )
-      vt_s (:,:) = SUM( v_s, dim=3 )
-      at_i (:,:) = SUM( a_i, dim=3 )
-      et_s(:,:)  = SUM( SUM( e_s(:,:,:,:), dim=4 ), dim=3 )
-      et_i(:,:)  = SUM( SUM( e_i(:,:,:,:), dim=4 ), dim=3 )
-
-      ! open water fraction
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            ato_i(ji,jj) = MAX( 1._wp - at_i(ji,jj), 0._wp )   
-         END DO
-      END DO
-
-      IF( kn > 1 ) THEN
-
-         ! mean ice/snow thickness
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               rswitch      = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi10 ) ) 
-               htm_i(ji,jj) = vt_i(ji,jj) / MAX( at_i(ji,jj) , epsi10 ) * rswitch
-               htm_s(ji,jj) = vt_s(ji,jj) / MAX( at_i(ji,jj) , epsi10 ) * rswitch
-            ENDDO
-         ENDDO
-
-         ! mean temperature (K), salinity and age
-         smt_i(:,:) = 0._wp
-         tm_i(:,:)  = 0._wp
-         tm_su(:,:) = 0._wp
-         om_i (:,:) = 0._wp
-         DO jl = 1, jpl
-            
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  rswitch      = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi10 ) )
-                  tm_su(ji,jj) = tm_su(ji,jj) + rswitch * ( t_su(ji,jj,jl) - rt0 ) * a_i(ji,jj,jl) / MAX( at_i(ji,jj) , epsi10 )
-                  om_i (ji,jj) = om_i (ji,jj) + rswitch *   oa_i(ji,jj,jl)                         / MAX( at_i(ji,jj) , epsi10 )
-               END DO
-            END DO
-            
-            DO jk = 1, nlay_i
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     rswitch = MAX( 0._wp , SIGN( 1._wp , vt_i(ji,jj) - epsi10 ) )
-                     tm_i(ji,jj)  = tm_i(ji,jj)  + r1_nlay_i * rswitch * ( t_i(ji,jj,jk,jl) - rt0 ) * v_i(ji,jj,jl)  &
-                        &            / MAX( vt_i(ji,jj) , epsi10 )
-                     smt_i(ji,jj) = smt_i(ji,jj) + r1_nlay_i * rswitch * s_i(ji,jj,jk,jl) * v_i(ji,jj,jl)  &
-                        &            / MAX( vt_i(ji,jj) , epsi10 )
-                  END DO
-               END DO
-            END DO
-         END DO
-         tm_i  = tm_i  + rt0
-         tm_su = tm_su + rt0
-         !
-      ENDIF
-      !
-   END SUBROUTINE lim_var_agg
-
-
-   SUBROUTINE lim_var_glo2eqv
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_var_glo2eqv ***
-      !!
-      !! ** Purpose :   computes equivalent variables as function of global variables 
-      !!              i.e. it turns VGLO into VEQV
-      !!------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      REAL(wp) ::   zq_i, zaaa, zbbb, zccc, zdiscrim     ! local scalars
-      REAL(wp) ::   ztmelts, zq_s, zfac1, zfac2   !   -      -
-      !!------------------------------------------------------------------
-
-      !-------------------------------------------------------
-      ! Ice thickness, snow thickness, ice salinity, ice age
-      !-------------------------------------------------------
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               rswitch = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi20 ) )   !0 if no ice and 1 if yes
-               ht_i(ji,jj,jl) = v_i (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-            END DO
-         END DO
-      END DO
-      ! Force the upper limit of ht_i to always be < hi_max (99 m).
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            rswitch = MAX( 0._wp , SIGN( 1._wp, ht_i(ji,jj,jpl) - epsi20 ) )
-            ht_i(ji,jj,jpl) = MIN( ht_i(ji,jj,jpl) , hi_max(jpl) )
-            a_i (ji,jj,jpl) = v_i(ji,jj,jpl) / MAX( ht_i(ji,jj,jpl) , epsi20 ) * rswitch
-         END DO
-      END DO
-
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               rswitch = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi20 ) )   !0 if no ice and 1 if yes
-               ht_s(ji,jj,jl) = v_s (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-               o_i(ji,jj,jl)  = oa_i(ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-            END DO
-         END DO
-      END DO
-      
-      IF(  nn_icesal == 2  )THEN
-         DO jl = 1, jpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  rswitch = MAX( 0._wp , SIGN( 1._wp, v_i(ji,jj,jl) - epsi20 ) )   !0 if no ice and 1 if yes
-                  sm_i(ji,jj,jl) = smv_i(ji,jj,jl) / MAX( v_i(ji,jj,jl) , epsi20 ) * rswitch
-                  !                                      ! bounding salinity
-                  sm_i(ji,jj,jl) = MAX( sm_i(ji,jj,jl), rn_simin )
-               END DO
-            END DO
-         END DO
-      ENDIF
-
-      CALL lim_var_salprof      ! salinity profile
-
-      !-------------------
-      ! Ice temperatures
-      !-------------------
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  !                                                              ! Energy of melting q(S,T) [J.m-3]
-                  rswitch = MAX( 0.0 , SIGN( 1.0 , v_i(ji,jj,jl) - epsi20 ) )     ! rswitch = 0 if no ice and 1 if yes
-                  zq_i    = rswitch * e_i(ji,jj,jk,jl) / MAX( v_i(ji,jj,jl) , epsi20 ) * REAL(nlay_i,wp) 
-                  ztmelts = -tmut * s_i(ji,jj,jk,jl) + rt0              ! Ice layer melt temperature
-                  !
-                  zaaa       =  cpic                  ! Conversion q(S,T) -> T (second order equation)
-                  zbbb       =  ( rcp - cpic ) * ( ztmelts - rt0 ) + zq_i * r1_rhoic - lfus
-                  zccc       =  lfus * (ztmelts-rt0)
-                  zdiscrim   =  SQRT( MAX(zbbb*zbbb - 4._wp*zaaa*zccc , 0._wp) )
-                  t_i(ji,jj,jk,jl) = rt0 + rswitch *( - zbbb - zdiscrim ) / ( 2.0 *zaaa )
-                  t_i(ji,jj,jk,jl) = MIN( ztmelts, MAX( rt0 - 100._wp, t_i(ji,jj,jk,jl) ) )  ! -100 < t_i < ztmelts
-               END DO
-            END DO
-         END DO
-      END DO
-
-      !--------------------
-      ! Snow temperatures
-      !--------------------
-      zfac1 = 1._wp / ( rhosn * cpic )
-      zfac2 = lfus / cpic  
-      DO jl = 1, jpl
-         DO jk = 1, nlay_s
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  !Energy of melting q(S,T) [J.m-3]
-                  rswitch = MAX( 0._wp , SIGN( 1._wp , v_s(ji,jj,jl) - epsi20 ) )     ! rswitch = 0 if no ice and 1 if yes
-                  zq_s  = rswitch * e_s(ji,jj,jk,jl) / MAX( v_s(ji,jj,jl) , epsi20 ) * REAL(nlay_s,wp)
-                  !
-                  t_s(ji,jj,jk,jl) = rt0 + rswitch * ( - zfac1 * zq_s + zfac2 )
-                  t_s(ji,jj,jk,jl) = MIN( rt0, MAX( rt0 - 100._wp , t_s(ji,jj,jk,jl) ) )     ! -100 < t_s < rt0
-               END DO
-            END DO
-         END DO
-      END DO
-
-      ! integrated values
-      vt_i (:,:) = SUM( v_i, dim=3 )
-      vt_s (:,:) = SUM( v_s, dim=3 )
-      at_i (:,:) = SUM( a_i, dim=3 )
-
-      !
-   END SUBROUTINE lim_var_glo2eqv
-
-
-   SUBROUTINE lim_var_eqv2glo
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_var_eqv2glo ***
-      !!
-      !! ** Purpose :   computes global variables as function of equivalent variables
-      !!                i.e. it turns VEQV into VGLO
-      !! ** Method  :
-      !!
-      !! ** History :  (01-2006) Martin Vancoppenolle, UCL-ASTR
-      !!------------------------------------------------------------------
-      !
-      v_i(:,:,:)   = ht_i(:,:,:) * a_i(:,:,:)
-      v_s(:,:,:)   = ht_s(:,:,:) * a_i(:,:,:)
-      smv_i(:,:,:) = sm_i(:,:,:) * v_i(:,:,:)
-      !
-   END SUBROUTINE lim_var_eqv2glo
-
-
-   SUBROUTINE lim_var_salprof
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_var_salprof ***
-      !!
-      !! ** Purpose :   computes salinity profile in function of bulk salinity     
-      !!
-      !! ** Method  : If bulk salinity greater than zsi1, 
-      !!              the profile is assumed to be constant (S_inf)
-      !!              If bulk salinity lower than zsi0,
-      !!              the profile is linear with 0 at the surface (S_zero)
-      !!              If it is between zsi0 and zsi1, it is a
-      !!              alpha-weighted linear combination of s_inf and s_zero
-      !!
-      !! ** References : Vancoppenolle et al., 2007
-      !!------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop index
-      REAL(wp) ::   zfac0, zfac1, zsal
-      REAL(wp) ::   zswi0, zswi01, zargtemp , zs_zero   
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   z_slope_s, zalpha
-      REAL(wp), PARAMETER :: zsi0 = 3.5_wp
-      REAL(wp), PARAMETER :: zsi1 = 4.5_wp
-      !!------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, jpl, z_slope_s, zalpha )
-
-      !---------------------------------------
-      ! Vertically constant, constant in time
-      !---------------------------------------
-      IF(  nn_icesal == 1  )  THEN
-         s_i (:,:,:,:) = rn_icesal
-         sm_i(:,:,:)   = rn_icesal
-      ENDIF
-
-      !-----------------------------------
-      ! Salinity profile, varying in time
-      !-----------------------------------
-      IF(  nn_icesal == 2  ) THEN
-         !
-         DO jk = 1, nlay_i
-            s_i(:,:,jk,:)  = sm_i(:,:,:)
-         END DO
-         !
-         DO jl = 1, jpl                               ! Slope of the linear profile 
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  rswitch = MAX( 0._wp , SIGN( 1._wp , ht_i(ji,jj,jl) - epsi20 ) )
-                  z_slope_s(ji,jj,jl) = rswitch * 2._wp * sm_i(ji,jj,jl) / MAX( epsi20 , ht_i(ji,jj,jl) )
-               END DO
-            END DO
-         END DO
-         !
-         zfac0 = 1._wp / ( zsi0 - zsi1 )       ! Weighting factor between zs_zero and zs_inf
-         zfac1 = zsi1  / ( zsi1 - zsi0 )
-         !
-         zalpha(:,:,:) = 0._wp
-         DO jl = 1, jpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  ! zswi0 = 1 if sm_i le zsi0 and 0 otherwise
-                  zswi0  = MAX( 0._wp   , SIGN( 1._wp  , zsi0 - sm_i(ji,jj,jl) ) ) 
-                  ! zswi01 = 1 if sm_i is between zsi0 and zsi1 and 0 othws 
-                  zswi01 = ( 1._wp - zswi0 ) * MAX( 0._wp   , SIGN( 1._wp  , zsi1 - sm_i(ji,jj,jl) ) ) 
-                  ! If 2.sm_i GE sss_m then rswitch = 1
-                  ! this is to force a constant salinity profile in the Baltic Sea
-                  rswitch = MAX( 0._wp , SIGN( 1._wp , 2._wp * sm_i(ji,jj,jl) - sss_m(ji,jj) ) )
-                  zalpha(ji,jj,jl) = zswi0  + zswi01 * ( sm_i(ji,jj,jl) * zfac0 + zfac1 )
-                  zalpha(ji,jj,jl) = zalpha(ji,jj,jl) * ( 1._wp - rswitch )
-               END DO
-            END DO
-         END DO
-
-         ! Computation of the profile
-         DO jl = 1, jpl
-            DO jk = 1, nlay_i
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     !                                      ! linear profile with 0 at the surface
-                     zs_zero = z_slope_s(ji,jj,jl) * ( REAL(jk,wp) - 0.5_wp ) * ht_i(ji,jj,jl) * r1_nlay_i
-                     !                                      ! weighting the profile
-                     s_i(ji,jj,jk,jl) = zalpha(ji,jj,jl) * zs_zero + ( 1._wp - zalpha(ji,jj,jl) ) * sm_i(ji,jj,jl)
-                     !                                      ! bounding salinity
-                     s_i(ji,jj,jk,jl) = MIN( rn_simax, MAX( s_i(ji,jj,jk,jl), rn_simin ) )
-                  END DO
-               END DO
-            END DO
-         END DO
-         !
-      ENDIF ! nn_icesal
-
-      !-------------------------------------------------------
-      ! Vertically varying salinity profile, constant in time
-      !-------------------------------------------------------
-
-      IF(  nn_icesal == 3  ) THEN      ! Schwarzacher (1959) multiyear salinity profile (mean = 2.30)
-         !
-         sm_i(:,:,:) = 2.30_wp
-         !
-         DO jl = 1, jpl
-            DO jk = 1, nlay_i
-               zargtemp  = ( REAL(jk,wp) - 0.5_wp ) * r1_nlay_i
-               zsal =  1.6_wp * (  1._wp - COS( rpi * zargtemp**(0.407_wp/(0.573_wp+zargtemp)) )  )
-               s_i(:,:,jk,jl) =  zsal
-            END DO
-         END DO
-         !
-      ENDIF ! nn_icesal
-      !
-      CALL wrk_dealloc( jpi, jpj, jpl, z_slope_s, zalpha )
-      !
-   END SUBROUTINE lim_var_salprof
-
-
-   SUBROUTINE lim_var_bv
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_var_bv ***
-      !!
-      !! ** Purpose :   computes mean brine volume (%) in sea ice
-      !!
-      !! ** Method  : e = - 0.054 * S (ppt) / T (C)
-      !!
-      !! References : Vancoppenolle et al., JGR, 2007
-      !!------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      !!------------------------------------------------------------------
-      !
-      bvm_i(:,:)   = 0._wp
-      bv_i (:,:,:) = 0._wp
-      DO jl = 1, jpl
-         DO jk = 1, nlay_i
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  rswitch        = ( 1._wp - MAX( 0._wp , SIGN( 1._wp , (t_i(ji,jj,jk,jl) - rt0) + epsi10 ) )  )
-                  bv_i(ji,jj,jl) = bv_i(ji,jj,jl) - rswitch * tmut * s_i(ji,jj,jk,jl) * r1_nlay_i  &
-                     &                            / MIN( t_i(ji,jj,jk,jl) - rt0, - epsi10 )
-               END DO
-            END DO
-         END DO
-         
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               rswitch      = MAX( 0._wp , SIGN( 1._wp , vt_i(ji,jj) - epsi10 ) )
-               bvm_i(ji,jj) = bvm_i(ji,jj) + rswitch * bv_i(ji,jj,jl) * v_i(ji,jj,jl) / MAX( vt_i(ji,jj), epsi10 )
-            END DO
-         END DO
-      END DO
-      !
-   END SUBROUTINE lim_var_bv
-
-
-   SUBROUTINE lim_var_salprof1d( kideb, kiut )
-      !!-------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_thd_salprof1d  ***
-      !!
-      !! ** Purpose :   1d computation of the sea ice salinity profile
-      !!                Works with 1d vectors and is used by thermodynamic modules
-      !!-------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kideb, kiut   ! thickness category index
-      !
-      INTEGER  ::   ji, jk    ! dummy loop indices
-      INTEGER  ::   ii, ij    ! local integers
-      REAL(wp) ::   zfac0, zfac1, zargtemp, zsal   ! local scalars
-      REAL(wp) ::   zalpha, zswi0, zswi01, zs_zero              !   -      -
-      !
-      REAL(wp), POINTER, DIMENSION(:) ::   z_slope_s
-      REAL(wp), PARAMETER :: zsi0 = 3.5_wp
-      REAL(wp), PARAMETER :: zsi1 = 4.5_wp
-      !!---------------------------------------------------------------------
-
-      CALL wrk_alloc( jpij, z_slope_s )
-
-      !---------------------------------------
-      ! Vertically constant, constant in time
-      !---------------------------------------
-      IF( nn_icesal == 1 )   s_i_1d(:,:) = rn_icesal
-
-      !------------------------------------------------------
-      ! Vertically varying salinity profile, varying in time
-      !------------------------------------------------------
-
-      IF(  nn_icesal == 2  ) THEN
-         !
-         DO ji = kideb, kiut          ! Slope of the linear profile zs_zero
-            rswitch = MAX( 0._wp , SIGN( 1._wp , ht_i_1d(ji) - epsi20 ) )
-            z_slope_s(ji) = rswitch * 2._wp * sm_i_1d(ji) / MAX( epsi20 , ht_i_1d(ji) )
-         END DO
-
-         ! Weighting factor between zs_zero and zs_inf
-         !---------------------------------------------
-         zfac0 = 1._wp / ( zsi0 - zsi1 )
-         zfac1 = zsi1 / ( zsi1 - zsi0 )
-         DO jk = 1, nlay_i
-            DO ji = kideb, kiut
-               ii =  MOD( npb(ji) - 1 , jpi ) + 1
-               ij =     ( npb(ji) - 1 ) / jpi + 1
-               ! zswi0 = 1 if sm_i le zsi0 and 0 otherwise
-               zswi0  = MAX( 0._wp , SIGN( 1._wp  , zsi0 - sm_i_1d(ji) ) ) 
-               ! zswi01 = 1 if sm_i is between zsi0 and zsi1 and 0 othws 
-               zswi01 = ( 1._wp - zswi0 ) * MAX( 0._wp , SIGN( 1._wp , zsi1 - sm_i_1d(ji) ) ) 
-               ! if 2.sm_i GE sss_m then rswitch = 1
-               ! this is to force a constant salinity profile in the Baltic Sea
-               rswitch = MAX( 0._wp , SIGN( 1._wp , 2._wp * sm_i_1d(ji) - sss_m(ii,ij) ) )
-               !
-               zalpha = (  zswi0 + zswi01 * ( sm_i_1d(ji) * zfac0 + zfac1 )  ) * ( 1._wp - rswitch )
-               !
-               zs_zero = z_slope_s(ji) * ( REAL(jk,wp) - 0.5_wp ) * ht_i_1d(ji) * r1_nlay_i
-               ! weighting the profile
-               s_i_1d(ji,jk) = zalpha * zs_zero + ( 1._wp - zalpha ) * sm_i_1d(ji)
-               ! bounding salinity
-               s_i_1d(ji,jk) = MIN( rn_simax, MAX( s_i_1d(ji,jk), rn_simin ) )
-            END DO 
-         END DO 
-
-      ENDIF 
-
-      !-------------------------------------------------------
-      ! Vertically varying salinity profile, constant in time
-      !-------------------------------------------------------
-
-      IF( nn_icesal == 3 ) THEN      ! Schwarzacher (1959) multiyear salinity profile (mean = 2.30)
-         !
-         sm_i_1d(:) = 2.30_wp
-         !
-         DO jk = 1, nlay_i
-            zargtemp  = ( REAL(jk,wp) - 0.5_wp ) * r1_nlay_i
-            zsal =  1.6_wp * ( 1._wp - COS( rpi * zargtemp**( 0.407_wp / ( 0.573_wp + zargtemp ) ) ) )
-            DO ji = kideb, kiut
-               s_i_1d(ji,jk) = zsal
-            END DO
-         END DO
-         !
-      ENDIF
-      !
-      CALL wrk_dealloc( jpij, z_slope_s )
-      !
-   END SUBROUTINE lim_var_salprof1d
-
-   SUBROUTINE lim_var_zapsmall
-      !!-------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_var_zapsmall ***
-      !!
-      !! ** Purpose :   Remove too small sea ice areas and correct fluxes
-      !!
-      !! history : LIM3.5 - 01-2014 (C. Rousset) original code
-      !!-------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jl, jk   ! dummy loop indices
-      REAL(wp) ::   zsal, zvi, zvs, zei, zes
-      !!-------------------------------------------------------------------
-      at_i (:,:) = 0._wp
-      DO jl = 1, jpl
-         at_i(:,:) = at_i(:,:) + a_i(:,:,jl)
-      END DO
-
-      DO jl = 1, jpl
-
-         !-----------------------------------------------------------------
-         ! Zap ice energy and use ocean heat to melt ice
-         !-----------------------------------------------------------------
-         DO jk = 1, nlay_i
-            DO jj = 1 , jpj
-               DO ji = 1 , jpi
-                  rswitch          = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi10 ) )
-                  rswitch          = MAX( 0._wp , SIGN( 1._wp, at_i(ji,jj  ) - epsi10 ) ) * rswitch
-                  rswitch          = MAX( 0._wp , SIGN( 1._wp, v_i(ji,jj,jl) - epsi10 ) ) * rswitch
-                  rswitch          = MAX( 0._wp , SIGN( 1._wp, v_i(ji,jj,jl) * rswitch  &
-                     &                                       / MAX( a_i(ji,jj,jl), epsi10 ) - epsi10 ) ) * rswitch
-                  zei              = e_i(ji,jj,jk,jl)
-                  e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * rswitch
-                  t_i(ji,jj,jk,jl) = t_i(ji,jj,jk,jl) * rswitch + rt0 * ( 1._wp - rswitch )
-                  ! update exchanges with ocean
-                  hfx_res(ji,jj)   = hfx_res(ji,jj) + ( e_i(ji,jj,jk,jl) - zei ) * r1_rdtice ! W.m-2 <0
-               END DO
-            END DO
-         END DO
-
-         DO jj = 1 , jpj
-            DO ji = 1 , jpi
-               rswitch = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi10 ) )
-               rswitch = MAX( 0._wp , SIGN( 1._wp, at_i(ji,jj  ) - epsi10 ) ) * rswitch
-               rswitch = MAX( 0._wp , SIGN( 1._wp, v_i(ji,jj,jl) - epsi10 ) ) * rswitch
-               rswitch = MAX( 0._wp , SIGN( 1._wp, v_i(ji,jj,jl) * rswitch  &
-                  &                              / MAX( a_i(ji,jj,jl), epsi10 ) - epsi10 ) ) * rswitch
-               zsal = smv_i(ji,jj,  jl)
-               zvi  = v_i  (ji,jj,  jl)
-               zvs  = v_s  (ji,jj,  jl)
-               zes  = e_s  (ji,jj,1,jl)
-               !-----------------------------------------------------------------
-               ! Zap snow energy 
-               !-----------------------------------------------------------------
-               t_s(ji,jj,1,jl) = t_s(ji,jj,1,jl) * rswitch + rt0 * ( 1._wp - rswitch )
-               e_s(ji,jj,1,jl) = e_s(ji,jj,1,jl) * rswitch
-
-               !-----------------------------------------------------------------
-               ! zap ice and snow volume, add water and salt to ocean
-               !-----------------------------------------------------------------
-               ato_i(ji,jj)    = a_i  (ji,jj,jl) * ( 1._wp - rswitch ) + ato_i(ji,jj)
-               a_i  (ji,jj,jl) = a_i  (ji,jj,jl) * rswitch
-               v_i  (ji,jj,jl) = v_i  (ji,jj,jl) * rswitch
-               v_s  (ji,jj,jl) = v_s  (ji,jj,jl) * rswitch
-               t_su (ji,jj,jl) = t_su (ji,jj,jl) * rswitch + t_bo(ji,jj) * ( 1._wp - rswitch )
-               oa_i (ji,jj,jl) = oa_i (ji,jj,jl) * rswitch
-               smv_i(ji,jj,jl) = smv_i(ji,jj,jl) * rswitch
-
-               ! update exchanges with ocean
-               sfx_res(ji,jj)  = sfx_res(ji,jj) - ( smv_i(ji,jj,jl) - zsal ) * rhoic * r1_rdtice
-               wfx_res(ji,jj)  = wfx_res(ji,jj) - ( v_i(ji,jj,jl)   - zvi  ) * rhoic * r1_rdtice
-               wfx_snw(ji,jj)  = wfx_snw(ji,jj) - ( v_s(ji,jj,jl)   - zvs  ) * rhosn * r1_rdtice
-               hfx_res(ji,jj)  = hfx_res(ji,jj) + ( e_s(ji,jj,1,jl) - zes ) * r1_rdtice ! W.m-2 <0
-            END DO
-         END DO
-      END DO 
-
-      ! to be sure that at_i is the sum of a_i(jl)
-      at_i (:,:) = 0._wp
-      DO jl = 1, jpl
-         at_i(:,:) = at_i(:,:) + a_i(:,:,jl)
-      END DO
-
-      ! open water = 1 if at_i=0
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            rswitch      = MAX( 0._wp , SIGN( 1._wp, - at_i(ji,jj) ) )
-            ato_i(ji,jj) = rswitch + (1._wp - rswitch ) * ato_i(ji,jj)
-         END DO
-      END DO
-
-      !
-   END SUBROUTINE lim_var_zapsmall
-
-   SUBROUTINE lim_var_itd( zhti, zhts, zai, zht_i, zht_s, za_i )
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_var_itd   ***
-      !!
-      !! ** Purpose :  converting 1-cat ice to multiple ice categories
-      !!
-      !!                  ice thickness distribution follows a gaussian law
-      !!               around the concentration of the most likely ice thickness
-      !!                           (similar as limistate.F90)
-      !!
-      !! ** Method:   Iterative procedure
-      !!                
-      !!               1) Try to fill the jpl ice categories (bounds hi_max(0:jpl)) with a gaussian
-      !!
-      !!               2) Check whether the distribution conserves area and volume, positivity and
-      !!                  category boundaries
-      !!              
-      !!               3) If not (input ice is too thin), the last category is empty and
-      !!                  the number of categories is reduced (jpl-1)
-      !!
-      !!               4) Iterate until ok (SUM(itest(:) = 4)
-      !!
-      !! ** Arguments : zhti: 1-cat ice thickness
-      !!                zhts: 1-cat snow depth
-      !!                zai : 1-cat ice concentration
-      !!
-      !! ** Output    : jpl-cat 
-      !!
-      !!  (Example of application: BDY forcings when input are cell averaged)  
-      !!
-      !!-------------------------------------------------------------------
-      !! History : LIM3.5 - 2012    (M. Vancoppenolle)  Original code
-      !!                    2014    (C. Rousset)        Rewriting
-      !!-------------------------------------------------------------------
-      !! Local variables
-      INTEGER  :: ji, jk, jl             ! dummy loop indices
-      INTEGER  :: ijpij, i_fill, jl0  
-      REAL(wp) :: zarg, zV, zconv, zdh, zdv
-      REAL(wp), DIMENSION(:),   INTENT(in)    ::   zhti, zhts, zai    ! input ice/snow variables
-      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   zht_i, zht_s, za_i ! output ice/snow variables
-      INTEGER , POINTER, DIMENSION(:)         ::   itest
- 
-      CALL wrk_alloc( 4, itest )
-      !--------------------------------------------------------------------
-      ! initialisation of variables
-      !--------------------------------------------------------------------
-      ijpij = SIZE(zhti,1)
-      zht_i(1:ijpij,1:jpl) = 0._wp
-      zht_s(1:ijpij,1:jpl) = 0._wp
-      za_i (1:ijpij,1:jpl) = 0._wp
-
-      ! ----------------------------------------
-      ! distribution over the jpl ice categories
-      ! ----------------------------------------
-      DO ji = 1, ijpij
-         
-         IF( zhti(ji) > 0._wp ) THEN
-
-            ! find which category (jl0) the input ice thickness falls into
-            jl0 = jpl
-            DO jl = 1, jpl
-               IF ( ( zhti(ji) >= hi_max(jl-1) ) .AND. ( zhti(ji) < hi_max(jl) ) ) THEN
-                  jl0 = jl
-                  CYCLE
-               ENDIF
-            END DO
-
-            ! initialisation of tests
-            itest(:)  = 0
-         
-            i_fill = jpl + 1                                             !====================================
-            DO WHILE ( ( SUM( itest(:) ) /= 4 ) .AND. ( i_fill >= 2 ) )  ! iterative loop on i_fill categories
-               ! iteration                                               !====================================
-               i_fill = i_fill - 1
-               
-               ! initialisation of ice variables for each try
-               zht_i(ji,1:jpl) = 0._wp
-               za_i (ji,1:jpl) = 0._wp
-               itest(:)        = 0      
-               
-               ! *** case very thin ice: fill only category 1
-               IF ( i_fill == 1 ) THEN
-                  zht_i(ji,1) = zhti(ji)
-                  za_i (ji,1) = zai (ji)
-                  
-               ! *** case ice is thicker: fill categories >1
-               ELSE
-
-                  ! Fill ice thicknesses in the (i_fill-1) cat by hmean 
-                  DO jl = 1, i_fill - 1
-                     zht_i(ji,jl) = hi_mean(jl)
-                  END DO
-                  
-                  ! Concentrations in the (i_fill-1) categories 
-                  za_i(ji,jl0) = zai(ji) / SQRT(REAL(jpl))
-                  DO jl = 1, i_fill - 1
-                     IF ( jl /= jl0 ) THEN
-                        zarg        = ( zht_i(ji,jl) - zhti(ji) ) / ( zhti(ji) * 0.5_wp )
-                        za_i(ji,jl) =   za_i (ji,jl0) * EXP(-zarg**2)
-                     ENDIF
-                  END DO
-                  
-                  ! Concentration in the last (i_fill) category
-                  za_i(ji,i_fill) = zai(ji) - SUM( za_i(ji,1:i_fill-1) )
-                  
-                  ! Ice thickness in the last (i_fill) category
-                  zV = SUM( za_i(ji,1:i_fill-1) * zht_i(ji,1:i_fill-1) )
-                  zht_i(ji,i_fill) = ( zhti(ji) * zai(ji) - zV ) / MAX( za_i(ji,i_fill), epsi10 ) 
-                  
-                  ! clem: correction if concentration of upper cat is greater than lower cat
-                  !       (it should be a gaussian around jl0 but sometimes it is not)
-                  IF ( jl0 /= jpl ) THEN
-                     DO jl = jpl, jl0+1, -1
-                        IF ( za_i(ji,jl) > za_i(ji,jl-1) ) THEN
-                           zdv = zht_i(ji,jl) * za_i(ji,jl)
-                           zht_i(ji,jl    ) = 0._wp
-                           za_i (ji,jl    ) = 0._wp
-                           za_i (ji,1:jl-1) = za_i(ji,1:jl-1) + zdv / MAX( REAL(jl-1) * zhti(ji), epsi10 )
-                        END IF
-                     ENDDO
-                  ENDIF
-               
-               ENDIF ! case ice is thick or thin
-            
-               !---------------------
-               ! Compatibility tests
-               !--------------------- 
-               ! Test 1: area conservation
-               zconv = ABS( zai(ji) - SUM( za_i(ji,1:jpl) ) )
-               IF ( zconv < epsi06 ) itest(1) = 1
-            
-               ! Test 2: volume conservation
-               zconv = ABS( zhti(ji)*zai(ji) - SUM( za_i(ji,1:jpl)*zht_i(ji,1:jpl) ) )
-               IF ( zconv < epsi06 ) itest(2) = 1
-               
-               ! Test 3: thickness of the last category is in-bounds ?
-               IF ( zht_i(ji,i_fill) >= hi_max(i_fill-1) ) itest(3) = 1
-               
-               ! Test 4: positivity of ice concentrations
-               itest(4) = 1
-               DO jl = 1, i_fill
-                  IF ( za_i(ji,jl) < 0._wp ) itest(4) = 0
-               END DO
-               !                                         !============================
-            END DO                                       ! end iteration on categories
-               !                                         !============================
-         ENDIF ! if zhti > 0
-      END DO ! i loop
-
-      ! ------------------------------------------------
-      ! Adding Snow in each category where za_i is not 0
-      ! ------------------------------------------------ 
-      DO jl = 1, jpl
-         DO ji = 1, ijpij
-            IF( za_i(ji,jl) > 0._wp ) THEN
-               zht_s(ji,jl) = zht_i(ji,jl) * ( zhts(ji) / zhti(ji) )
-               ! In case snow load is in excess that would lead to transformation from snow to ice
-               ! Then, transfer the snow excess into the ice (different from limthd_dh)
-               zdh = MAX( 0._wp, ( rhosn * zht_s(ji,jl) + ( rhoic - rau0 ) * zht_i(ji,jl) ) * r1_rau0 ) 
-               ! recompute ht_i, ht_s avoiding out of bounds values
-               zht_i(ji,jl) = MIN( hi_max(jl), zht_i(ji,jl) + zdh )
-               zht_s(ji,jl) = MAX( 0._wp, zht_s(ji,jl) - zdh * rhoic * r1_rhosn )
-            ENDIF
-         ENDDO
-      ENDDO
-
-      CALL wrk_dealloc( 4, itest )
-      !
-    END SUBROUTINE lim_var_itd
-
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Dummy module          NO  LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_var_agg          ! Empty routines
-   END SUBROUTINE lim_var_agg
-   SUBROUTINE lim_var_glo2eqv      ! Empty routines
-   END SUBROUTINE lim_var_glo2eqv
-   SUBROUTINE lim_var_eqv2glo      ! Empty routines
-   END SUBROUTINE lim_var_eqv2glo
-   SUBROUTINE lim_var_salprof      ! Empty routines
-   END SUBROUTINE lim_var_salprof
-   SUBROUTINE lim_var_bv           ! Emtpy routines
-   END SUBROUTINE lim_var_bv
-   SUBROUTINE lim_var_salprof1d    ! Emtpy routines
-   END SUBROUTINE lim_var_salprof1d
-   SUBROUTINE lim_var_zapsmall
-   END SUBROUTINE lim_var_zapsmall
-   SUBROUTINE lim_var_itd
-   END SUBROUTINE lim_var_itd
-#endif
-
-   !!======================================================================
-END MODULE limvar
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limwri.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/limwri.F90	(revision 9018)
+++ 	(revision )
@@ -1,364 +1,0 @@
-MODULE limwri
-   !!======================================================================
-   !!                     ***  MODULE  limwri  ***
-   !!         Ice diagnostics :  write ice output files
-   !!======================================================================
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_wri      : write of the diagnostics variables in ouput file 
-   !!   lim_wri_state : write for initial state or/and abandon
-   !!----------------------------------------------------------------------
-   USE ioipsl
-   USE dianam          ! build name of file (routine)
-   USE phycst
-   USE dom_oce
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice fields
-   USE ice
-   USE limvar
-   USE in_out_manager
-   USE lbclnk
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! work arrays
-   USE iom
-   USE timing          ! Timing
-   USE lib_fortran     ! Fortran utilities
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC lim_wri        ! routine called by lim_step.F90
-   PUBLIC lim_wri_state  ! called by dia_wri_state 
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-
-   SUBROUTINE lim_wri( kindic )
-      !!-------------------------------------------------------------------
-      !!  This routine computes the average of some variables and write it
-      !!  on the ouput files.
-      !!  ATTENTION cette routine n'est valable que si le pas de temps est
-      !!  egale a une fraction entiere de 1 jours.
-      !!  Diff 1-D 3-D : suppress common also included in etat
-      !!                 suppress cmoymo 11-18
-      !!  modif : 03/06/98
-      !!-------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kindic   ! if kindic < 0 there has been an error somewhere
-      !
-      INTEGER  ::  ji, jj, jk, jl  ! dummy loop indices
-      REAL(wp) ::  z1_365
-      REAL(wp) ::  z2da, z2db, ztmp
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zswi2
-      REAL(wp), POINTER, DIMENSION(:,:)   ::  z2d, zswi    ! 2D workspace
-      !!-------------------------------------------------------------------
-
-      IF( nn_timing == 1 )  CALL timing_start('limwri')
-
-      CALL wrk_alloc( jpi,jpj,jpl, zswi2 )
-      CALL wrk_alloc( jpi,jpj    , z2d, zswi )
-
-      !-----------------------------
-      ! Mean category values
-      !-----------------------------
-      z1_365 = 1._wp / 365._wp
-
-      ! brine volume
-      CALL lim_var_bv 
-
-      ! tresholds for outputs
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            zswi(ji,jj)  = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi06 ) )
-         END DO
-      END DO
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zswi2(ji,jj,jl)  = MAX( 0._wp , SIGN( 1._wp , a_i(ji,jj,jl) - epsi06 ) )
-            END DO
-         END DO
-      END DO
-      !
-      ! fluxes
-      ! pfrld is the lead fraction at the previous time step (actually between TRP and THD)
-      IF( iom_use('qsr_oce') )   CALL iom_put( "qsr_oce" , qsr_oce(:,:) * pfrld(:,:) )                                   !     solar flux at ocean surface
-      IF( iom_use('qns_oce') )   CALL iom_put( "qns_oce" , qns_oce(:,:) * pfrld(:,:) + qemp_oce(:,:) )                   ! non-solar flux at ocean surface
-      IF( iom_use('qsr_ice') )   CALL iom_put( "qsr_ice" , SUM( qsr_ice(:,:,:) * a_i_b(:,:,:), dim=3 ) )                 !     solar flux at ice surface
-      IF( iom_use('qns_ice') )   CALL iom_put( "qns_ice" , SUM( qns_ice(:,:,:) * a_i_b(:,:,:), dim=3 ) + qemp_ice(:,:) ) ! non-solar flux at ice surface
-      IF( iom_use('qtr_ice') )   CALL iom_put( "qtr_ice" , SUM( ftr_ice(:,:,:) * a_i_b(:,:,:), dim=3 ) )                 !     solar flux transmitted thru ice
-      IF( iom_use('qt_oce' ) )   CALL iom_put( "qt_oce"  , ( qsr_oce(:,:) + qns_oce(:,:) ) * pfrld(:,:) + qemp_oce(:,:) )  
-      IF( iom_use('qt_ice' ) )   CALL iom_put( "qt_ice"  , SUM( ( qns_ice(:,:,:) + qsr_ice(:,:,:) )   &
-         &                                                      * a_i_b(:,:,:), dim=3 ) + qemp_ice(:,:) )
-      IF( iom_use('qemp_oce') )  CALL iom_put( "qemp_oce" , qemp_oce(:,:) )  
-      IF( iom_use('qemp_ice') )  CALL iom_put( "qemp_ice" , qemp_ice(:,:) )  
-      IF( iom_use('emp_oce' ) )  CALL iom_put( "emp_oce"  , emp_oce(:,:) )   ! emp over ocean (taking into account the snow blown away from the ice)
-      IF( iom_use('emp_ice' ) )  CALL iom_put( "emp_ice"  , emp_ice(:,:) )   ! emp over ice   (taking into account the snow blown away from the ice)
-
-      ! velocity
-      IF ( iom_use( "uice_ipa" ) .OR. iom_use( "vice_ipa" ) .OR. iom_use( "icevel" ) ) THEN 
-         DO jj = 2 , jpjm1
-            DO ji = 2 , jpim1
-               z2da  = ( u_ice(ji,jj) * umask(ji,jj,1) + u_ice(ji-1,jj) * umask(ji-1,jj,1) ) * 0.5_wp
-               z2db  = ( v_ice(ji,jj) * vmask(ji,jj,1) + v_ice(ji,jj-1) * vmask(ji,jj-1,1) ) * 0.5_wp
-               z2d(ji,jj) = SQRT( z2da * z2da + z2db * z2db )
-           END DO
-         END DO
-         CALL lbc_lnk( z2d, 'T', 1. )
-         CALL iom_put( "uice_ipa"     , u_ice      )       ! ice velocity u component
-         CALL iom_put( "vice_ipa"     , v_ice      )       ! ice velocity v component
-         CALL iom_put( "icevel"       , z2d        )       ! ice velocity module
-      ENDIF
-
-      IF ( iom_use( "tau_icebfr" ) )    CALL iom_put( "tau_icebfr"  , tau_icebfr             )  ! ice friction with ocean bottom (landfast ice)  
-      !
-      IF ( iom_use( "miceage" ) )       CALL iom_put( "miceage"     , om_i * zswi * z1_365   )  ! mean ice age
-      IF ( iom_use( "icethic_cea" ) )   CALL iom_put( "icethic_cea" , htm_i * zswi           )  ! ice thickness mean
-      IF ( iom_use( "snowthic_cea" ) )  CALL iom_put( "snowthic_cea", htm_s * zswi           )  ! snow thickness mean
-      IF ( iom_use( "micet" ) )         CALL iom_put( "micet"       , ( tm_i  - rt0 ) * zswi )  ! ice mean    temperature
-      IF ( iom_use( "icest" ) )         CALL iom_put( "icest"       , ( tm_su - rt0 ) * zswi )  ! ice surface temperature
-      IF ( iom_use( "icecolf" ) )       CALL iom_put( "icecolf"     , hicol                  )  ! frazil ice collection thickness
-      !
-      CALL iom_put( "isst"        , sst_m               )        ! sea surface temperature
-      CALL iom_put( "isss"        , sss_m               )        ! sea surface salinity
-      CALL iom_put( "iceconc"     , at_i  * zswi        )        ! ice concentration
-      CALL iom_put( "icevolu"     , vt_i  * zswi        )        ! ice volume = mean ice thickness over the cell
-      CALL iom_put( "icehc"       , et_i  * zswi        )        ! ice total heat content
-      CALL iom_put( "isnowhc"     , et_s  * zswi        )        ! snow total heat content
-      CALL iom_put( "ibrinv"      , bvm_i * zswi * 100. )        ! brine volume
-      CALL iom_put( "utau_ice"    , utau_ice            )        ! wind stress over ice along i-axis at I-point
-      CALL iom_put( "vtau_ice"    , vtau_ice            )        ! wind stress over ice along j-axis at I-point
-      CALL iom_put( "snowpre"     , sprecip * 86400.    )        ! snow precipitation 
-      CALL iom_put( "micesalt"    , smt_i   * zswi      )        ! mean ice salinity
-
-      CALL iom_put( "icestr"      , strength * zswi )    ! ice strength
-      CALL iom_put( "idive"       , divu_i * 1.0e8      )    ! divergence
-      CALL iom_put( "ishear"      , shear_i * 1.0e8     )    ! shear
-      CALL iom_put( "snowvol"     , vt_s   * zswi       )        ! snow volume
-      
-      CALL iom_put( "icetrp"      , diag_trp_vi * rday  )        ! ice volume transport
-      CALL iom_put( "snwtrp"      , diag_trp_vs * rday  )        ! snw volume transport
-      CALL iom_put( "saltrp"      , diag_trp_smv * rday * rhoic ) ! salt content transport
-      CALL iom_put( "deitrp"      , diag_trp_ei         )        ! advected ice enthalpy (W/m2)
-      CALL iom_put( "destrp"      , diag_trp_es         )        ! advected snw enthalpy (W/m2)
-
-      CALL iom_put( "sfxbog"      , sfx_bog * rday      )        ! salt flux from bottom growth
-      CALL iom_put( "sfxbom"      , sfx_bom * rday      )        ! salt flux from bottom melting
-      CALL iom_put( "sfxsum"      , sfx_sum * rday      )        ! salt flux from surface melting
-      CALL iom_put( "sfxlam"      , sfx_lam * rday      )        ! salt flux from lateral melting
-      CALL iom_put( "sfxsni"      , sfx_sni * rday      )        ! salt flux from snow ice formation
-      CALL iom_put( "sfxopw"      , sfx_opw * rday      )        ! salt flux from open water formation
-      CALL iom_put( "sfxdyn"      , sfx_dyn * rday      )        ! salt flux from ridging rafting
-      CALL iom_put( "sfxres"      , sfx_res * rday      )        ! salt flux from limupdate (resultant)
-      CALL iom_put( "sfxbri"      , sfx_bri * rday      )        ! salt flux from brines
-      CALL iom_put( "sfxsub"      , sfx_sub * rday      )        ! salt flux from sublimation
-      CALL iom_put( "sfx"         , sfx     * rday      )        ! total salt flux
-
-      ztmp = rday / rhoic
-      CALL iom_put( "vfxres"     , wfx_res * ztmp       )        ! daily prod./melting due to limupdate 
-      CALL iom_put( "vfxopw"     , wfx_opw * ztmp       )        ! daily lateral thermodynamic ice production
-      CALL iom_put( "vfxsni"     , wfx_sni * ztmp       )        ! daily snowice ice production
-      CALL iom_put( "vfxbog"     , wfx_bog * ztmp       )        ! daily bottom thermodynamic ice production
-      CALL iom_put( "vfxdyn"     , wfx_dyn * ztmp       )        ! daily dynamic ice production (rid/raft)
-      CALL iom_put( "vfxsum"     , wfx_sum * ztmp       )        ! surface melt 
-      CALL iom_put( "vfxbom"     , wfx_bom * ztmp       )        ! bottom melt 
-      CALL iom_put( "vfxlam"     , wfx_lam * ztmp       )        ! lateral melt 
-      CALL iom_put( "vfxice"     , wfx_ice * ztmp       )        ! total ice growth/melt 
-
-      IF ( iom_use( "vfxthin" ) ) THEN   ! ice production for open water + thin ice (<20cm) => comparable to observations  
-         WHERE( htm_i(:,:) < 0.2 .AND. htm_i(:,:) > 0. ) ; z2d = wfx_bog
-         ELSEWHERE                                       ; z2d = 0._wp
-         END WHERE
-         CALL iom_put( "vfxthin", ( wfx_opw + z2d ) * ztmp )
-      ENDIF
-
-      ztmp = rday / rhosn
-      CALL iom_put( "vfxspr"     , wfx_spr * ztmp       )        ! precip (snow)
-      CALL iom_put( "vfxsnw"     , wfx_snw * ztmp       )        ! total snw growth/melt 
-      CALL iom_put( "vfxsub"     , wfx_sub * ztmp       )        ! sublimation (snow/ice) 
-      CALL iom_put( "vfxsub_err" , wfx_err_sub * ztmp   )        ! "excess" of sublimation sent to ocean 
-      
-      CALL iom_put( "afxtot"     , afx_tot * rday       )        ! concentration tendency (total)
-      CALL iom_put( "afxdyn"     , afx_dyn * rday       )        ! concentration tendency (dynamics)
-      CALL iom_put( "afxthd"     , afx_thd * rday       )        ! concentration tendency (thermo)
-
-      CALL iom_put ('hfxthd'     , hfx_thd(:,:)         )   !  
-      CALL iom_put ('hfxdyn'     , hfx_dyn(:,:)         )   !  
-      CALL iom_put ('hfxres'     , hfx_res(:,:)         )   !  
-      CALL iom_put ('hfxout'     , hfx_out(:,:)         )   !  
-      CALL iom_put ('hfxin'      , hfx_in(:,:)          )   !  
-      CALL iom_put ('hfxsnw'     , hfx_snw(:,:)         )   !  
-      CALL iom_put ('hfxsub'     , hfx_sub(:,:)         )   !  
-      CALL iom_put ('hfxerr'     , hfx_err(:,:)         )   !  
-      CALL iom_put ('hfxerr_rem' , hfx_err_rem(:,:)     )   !  
-      
-      CALL iom_put ('hfxsum'     , hfx_sum(:,:)         )   !  
-      CALL iom_put ('hfxbom'     , hfx_bom(:,:)         )   !  
-      CALL iom_put ('hfxbog'     , hfx_bog(:,:)         )   !  
-      CALL iom_put ('hfxdif'     , hfx_dif(:,:)         )   !  
-      CALL iom_put ('hfxopw'     , hfx_opw(:,:)         )   !  
-      CALL iom_put ('hfxtur'     , fhtur(:,:) * at_i_b(:,:) ) ! turbulent heat flux at ice base 
-      CALL iom_put ('hfxdhc'     , diag_heat(:,:)       )   ! Heat content variation in snow and ice 
-      CALL iom_put ('hfxspr'     , hfx_spr(:,:)         )   ! Heat content of snow precip 
-
-      
-      !--------------------------------
-      ! Output values for each category
-      !--------------------------------
-      IF ( iom_use( "iceconc_cat"  ) )  CALL iom_put( "iceconc_cat"      , a_i   * zswi2   )        ! area for categories
-      IF ( iom_use( "icethic_cat"  ) )  CALL iom_put( "icethic_cat"      , ht_i  * zswi2   )        ! thickness for categories
-      IF ( iom_use( "snowthic_cat" ) )  CALL iom_put( "snowthic_cat"     , ht_s  * zswi2   )        ! snow depth for categories
-      IF ( iom_use( "salinity_cat" ) )  CALL iom_put( "salinity_cat"     , sm_i  * zswi2   )        ! salinity for categories
-      ! ice temperature
-      IF ( iom_use( "icetemp_cat"  ) )  CALL iom_put( "icetemp_cat", ( SUM( t_i(:,:,:,:), dim=3 ) * r1_nlay_i - rt0 ) * zswi2 )
-      ! snow temperature
-      IF ( iom_use( "snwtemp_cat"  ) )  CALL iom_put( "snwtemp_cat", ( SUM( t_s(:,:,:,:), dim=3 ) * r1_nlay_s - rt0 ) * zswi2 )
-      ! ice age
-      IF ( iom_use( "iceage_cat"   ) )  CALL iom_put( "iceage_cat" , o_i * zswi2 * z1_365 )
-      ! brine volume
-      IF ( iom_use( "brinevol_cat" ) )  CALL iom_put( "brinevol_cat", bv_i * 100. * zswi2 )
-
-      !     !  Create an output files (output.lim.abort.nc) if S < 0 or u > 20 m/s
-      !     IF( kindic < 0 )   CALL lim_wri_state( 'output.abort' )
-      !     not yet implemented
-      
-      CALL wrk_dealloc( jpi, jpj, jpl, zswi2 )
-      CALL wrk_dealloc( jpi, jpj     , z2d, zswi )
-
-      IF( nn_timing == 1 )  CALL timing_stop('limwri')
-      
-   END SUBROUTINE lim_wri
-
- 
-   SUBROUTINE lim_wri_state( kt, kid, kh_i )
-      !!---------------------------------------------------------------------
-      !!                 ***  ROUTINE lim_wri_state  ***
-      !!        
-      !! ** Purpose :   create a NetCDF file named cdfile_name which contains 
-      !!      the instantaneous ice state and forcing fields for ice model
-      !!        Used to find errors in the initial state or save the last
-      !!      ocean state in case of abnormal end of a simulation
-      !!
-      !! History :
-      !!   4.0  !  2013-06  (C. Rousset)
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in )   ::   kt               ! ocean time-step index)
-      INTEGER, INTENT( in )   ::   kid , kh_i
-      INTEGER                 ::   nz_i, jl
-      REAL(wp), DIMENSION(jpl) :: jcat
-      !!----------------------------------------------------------------------
-      DO jl = 1, jpl
-         jcat(jl) = REAL(jl)
-      ENDDO
-      
-      CALL histvert( kid, "ncatice", "Ice Categories","", jpl, jcat, nz_i, "up")
-
-      CALL histdef( kid, "sithic", "Ice thickness"           , "m"      ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "siconc", "Ice concentration"       , "%"      ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "sitemp", "Ice temperature"         , "C"      ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "sivelu", "i-Ice speed "            , "m/s"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "sivelv", "j-Ice speed "            , "m/s"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "sistru", "i-Wind stress over ice " , "Pa"     ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "sistrv", "j-Wind stress over ice " , "Pa"     ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "sisflx", "Solar flux over ocean"     , "w/m2" ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "sinflx", "Non-solar flux over ocean" , "w/m2" ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "isnowpre", "Snow precipitation"      , "kg/m2/s",   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "sisali", "Ice salinity"            , "PSU"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "sivolu", "Ice volume"              , "m"      ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-      CALL histdef( kid, "sidive", "Ice divergence"          , "10-8s-1",   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt ) 
-
-      CALL histdef( kid, "vfxbog", "Ice bottom production"   , "m/s"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "vfxdyn", "Ice dynamic production"  , "m/s"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "vfxopw", "Ice open water prod"     , "m/s"    ,   &
-      &       jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "vfxsni", "Snow ice production "    , "m/s"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "vfxres", "Ice prod from limupdate" , "m/s"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "vfxbom", "Ice bottom melt"         , "m/s"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "vfxsum", "Ice surface melt"        , "m/s"    ,   &
-      &      jpi, jpj, kh_i, 1, 1, 1, -99, 32, "inst(x)", rdt, rdt )
-
-      CALL histdef( kid, "sithicat", "Ice thickness"         , "m"      ,   &
-      &      jpi, jpj, kh_i, jpl, 1, jpl, nz_i, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "siconcat", "Ice concentration"     , "%"      ,   &
-      &      jpi, jpj, kh_i, jpl, 1, jpl, nz_i, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "sisalcat", "Ice salinity"           , ""      ,   &
-      &      jpi, jpj, kh_i, jpl, 1, jpl, nz_i, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "sitemcat", "Ice temperature"       , "C"      ,   &
-      &      jpi, jpj, kh_i, jpl, 1, jpl, nz_i, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "snthicat", "Snw thickness"         , "m"      ,   &
-      &      jpi, jpj, kh_i, jpl, 1, jpl, nz_i, 32, "inst(x)", rdt, rdt )
-      CALL histdef( kid, "sntemcat", "Snw temperature"       , "C"      ,   &
-      &      jpi, jpj, kh_i, jpl, 1, jpl, nz_i, 32, "inst(x)", rdt, rdt )
-
-      CALL histend( kid, snc4set )   ! end of the file definition
-
-      CALL histwrite( kid, "sithic", kt, htm_i         , jpi*jpj, (/1/) )    
-      CALL histwrite( kid, "siconc", kt, at_i          , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "sitemp", kt, tm_i - rt0    , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "sivelu", kt, u_ice          , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "sivelv", kt, v_ice          , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "sistru", kt, utau_ice       , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "sistrv", kt, vtau_ice       , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "sisflx", kt, qsr , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "sinflx", kt, qns , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "isnowpre", kt, sprecip        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "sisali", kt, smt_i          , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "sivolu", kt, vt_i           , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "sidive", kt, divu_i*1.0e8   , jpi*jpj, (/1/) )
-
-      CALL histwrite( kid, "vfxbog", kt, wfx_bog        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "vfxdyn", kt, wfx_dyn        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "vfxopw", kt, wfx_opw        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "vfxsni", kt, wfx_sni        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "vfxres", kt, wfx_res        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "vfxbom", kt, wfx_bom        , jpi*jpj, (/1/) )
-      CALL histwrite( kid, "vfxsum", kt, wfx_sum        , jpi*jpj, (/1/) )
-
-      CALL histwrite( kid, "sithicat", kt, ht_i        , jpi*jpj*jpl, (/1/) )    
-      CALL histwrite( kid, "siconcat", kt, a_i         , jpi*jpj*jpl, (/1/) )    
-      CALL histwrite( kid, "sisalcat", kt, sm_i        , jpi*jpj*jpl, (/1/) )    
-      CALL histwrite( kid, "sitemcat", kt, tm_i - rt0  , jpi*jpj*jpl, (/1/) )    
-      CALL histwrite( kid, "snthicat", kt, ht_s        , jpi*jpj*jpl, (/1/) )    
-      CALL histwrite( kid, "sntemcat", kt, tm_su - rt0 , jpi*jpj*jpl, (/1/) )    
-
-      ! Close the file
-      ! -----------------
-      !CALL histclo( kid )
-
-    END SUBROUTINE lim_wri_state
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :         Empty module          NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_wri          ! Empty routine
-   END SUBROUTINE lim_wri
-#endif
-
-   !!======================================================================
-END MODULE limwri
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/thd_ice.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/LIM_SRC_3/thd_ice.F90	(revision 9018)
+++ 	(revision )
@@ -1,184 +1,0 @@
-MODULE thd_ice
-   !!======================================================================
-   !!                       ***  MODULE thd_ice  ***
-   !! LIM sea-ice :   Ice thermodynamics in 1D
-   !!=====================================================================
-   !! History :  3.0  !  2002-11  (C. Ethe)  F90: Free form and module
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE ice, ONLY :   nlay_i, nlay_s
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC thd_ice_alloc ! Routine called by nemogcm.F90
-
-   !!-----------------------------
-   !! * Share 1D Module variables
-   !!-----------------------------
-   !: In ice thermodynamics, to spare memory, the vectors are folded
-   !: from 1D to 2D vectors. The following variables, with ending _1d
-   !: are the variables corresponding to 2d vectors
-
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   npb    !: address vector for 1d vertical thermo computations
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   nplm   !: address vector for mono-category lateral melting
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   npac   !: address vector for new ice formation
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qlead_1d     
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ftr_ice_1d   
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qsr_ice_1d  
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fr1_i0_1d   
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fr2_i0_1d   
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qns_ice_1d  
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   t_bo_1d     
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   rn_amax_1d
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_sum_1d
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_bom_1d
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_bog_1d
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_dif_1d
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_opw_1d
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_snw_1d
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_err_1d
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_err_rem_1d
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_err_dif_1d
-
-   ! heat flux associated with ice-atmosphere mass exchange
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_sub_1d
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_spr_1d
-
-   ! heat flux associated with ice-ocean mass exchange
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_thd_1d
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hfx_res_1d
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_snw_1d 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_sub_1d
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_bog_1d    
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_bom_1d   
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_sum_1d  
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_sni_1d 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_opw_1d
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_res_1d 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   wfx_spr_1d
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_bri_1d
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_bog_1d    
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_bom_1d    
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_sum_1d    
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_sni_1d    
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_opw_1d   
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_res_1d  
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sfx_sub_1d
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sprecip_1d    !: <==> the 2D  sprecip
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   frld_1d       !: <==> the 2D  frld
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   at_i_1d        !: <==> the 2D  at_i
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fhtur_1d      !: <==> the 2D  fhtur
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fhld_1d       !: <==> the 2D  fhld
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dqns_ice_1d   !: <==> the 2D  dqns_ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   evap_ice_1d   !: <==> the 2D  evap_ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qprec_ice_1d  !: <==> the 2D  qprec_ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   qevap_ice_1d  !: <==> the 3D  qevap_ice
-   !                                                     ! to reintegrate longwave flux inside the ice thermodynamics
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   i0            !: fraction of radiation transmitted to the ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   hicol_1d      !: Ice collection thickness accumulated in leads
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   t_su_1d       !: <==> the 2D  t_su
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   a_i_1d        !: <==> the 2D  a_i
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ht_i_1d       !: <==> the 2D  ht_s
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ht_s_1d       !: <==> the 2D  ht_i
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fc_su         !: Surface Conduction flux 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   fc_bo_i       !: Bottom  Conduction flux 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_s_tot      !: Snow accretion/ablation        [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_i_surf     !: Ice surface accretion/ablation [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_i_sub      !: Ice surface sublimation [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_i_bott     !: Ice bottom accretion/ablation  [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   dh_snowice    !: Snow ice formation             [m of ice]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   sm_i_1d       !: Ice bulk salinity [ppt]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   s_i_new       !: Salinity of new ice at the bottom
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_s_1d   !: corresponding to the 2D var  t_s
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_i_1d   !: corresponding to the 2D var  t_i
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   s_i_1d   !: profiled ice salinity
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   q_i_1d   !:    Ice  enthalpy per unit volume
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   q_s_1d   !:    Snow enthalpy per unit volume
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qh_i_old !: ice heat content (q*h, J.m-2)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   h_i_old  !: ice thickness layer (m)
-
-   INTEGER , PUBLIC ::   jiindex_1d   ! 1D index of debugging point
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   FUNCTION thd_ice_alloc()
-      !!---------------------------------------------------------------------!
-      !!                ***  ROUTINE thd_ice_alloc ***
-      !!---------------------------------------------------------------------!
-      INTEGER ::   thd_ice_alloc   ! return value
-      INTEGER ::   ierr(4), ii
-      !!---------------------------------------------------------------------!
-      ierr(:) = 0
-
-      ii = 1
-      ALLOCATE( npb      (jpij) , nplm      (jpij) , npac       (jpij) ,   &
-         &      qlead_1d (jpij) , ftr_ice_1d(jpij) , qsr_ice_1d (jpij) ,   &
-         &      fr1_i0_1d(jpij) , fr2_i0_1d (jpij) , qns_ice_1d(jpij)  ,   &
-         &      t_bo_1d   (jpij) ,                                         &
-         &      hfx_sum_1d(jpij) , hfx_bom_1d(jpij) ,hfx_bog_1d(jpij) ,    & 
-         &      hfx_dif_1d(jpij) , hfx_opw_1d(jpij) ,                      &
-         &      rn_amax_1d(jpij) ,                                         &
-         &      hfx_thd_1d(jpij) , hfx_spr_1d(jpij) ,                      &
-         &      hfx_snw_1d(jpij) , hfx_sub_1d(jpij) , hfx_err_1d(jpij) ,   &
-         &      hfx_res_1d(jpij) , hfx_err_rem_1d(jpij) , hfx_err_dif_1d(jpij) , STAT=ierr(ii) )
-      !
-      ii = ii + 1
-      ALLOCATE( sprecip_1d (jpij) , frld_1d    (jpij) , at_i_1d    (jpij) ,                     &
-         &      fhtur_1d   (jpij) , wfx_snw_1d (jpij) , wfx_spr_1d (jpij) ,                     &
-         &      fhld_1d    (jpij) , wfx_sub_1d (jpij) , wfx_bog_1d (jpij) , wfx_bom_1d(jpij) ,  &
-         &      wfx_sum_1d(jpij)  , wfx_sni_1d (jpij) , wfx_opw_1d (jpij) , wfx_res_1d(jpij) ,  &
-         &      dqns_ice_1d(jpij) , evap_ice_1d (jpij),                                         &
-         &      qprec_ice_1d(jpij), qevap_ice_1d(jpij), i0         (jpij) ,                     &  
-         &      sfx_bri_1d (jpij) , sfx_bog_1d (jpij) , sfx_bom_1d (jpij) , sfx_sum_1d (jpij),  &
-         &      sfx_sni_1d (jpij) , sfx_opw_1d (jpij) , sfx_res_1d (jpij) , sfx_sub_1d (jpij),  &
-         &      hicol_1d   (jpij) , STAT=ierr(ii) )
-      !
-      ii = ii + 1
-      ALLOCATE( t_su_1d   (jpij) , a_i_1d    (jpij) , ht_i_1d  (jpij) ,                      &
-         &      ht_s_1d   (jpij) , fc_su     (jpij) , fc_bo_i  (jpij) ,                      &    
-         &      dh_s_tot  (jpij) , dh_i_surf (jpij) , dh_i_sub (jpij) ,                      &    
-         &      dh_i_bott (jpij) , dh_snowice(jpij) , sm_i_1d  (jpij) , s_i_new  (jpij) ,    &
-         &      STAT=ierr(ii) )
-      !
-      ii = ii + 1
-      ALLOCATE( t_s_1d  (jpij,nlay_s)     , t_i_1d (jpij,nlay_i)     , s_i_1d(jpij,nlay_i) ,  &            
-         &      q_i_1d  (jpij,nlay_i+1)   , q_s_1d (jpij,nlay_s)     ,                        &
-         &      qh_i_old(jpij,0:nlay_i+1) , h_i_old(jpij,0:nlay_i+1) , STAT=ierr(ii) )
-      !
-      thd_ice_alloc = MAXVAL( ierr(:) )
-      IF( thd_ice_alloc /= 0 )   CALL ctl_warn( 'thd_ice_alloc: failed to allocate arrays.' )
-      !
-   END FUNCTION thd_ice_alloc
-   
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :         Empty module          NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE thd_ice_alloc          ! Empty routine
-   END SUBROUTINE thd_ice_alloc
-#endif
- 
-   !!======================================================================
-END MODULE thd_ice
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_ice.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_ice.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_ice.F90	(revision 9019)
@@ -7,60 +7,8 @@
    !!            3.6  ! 2016-05  (C. Rousset)   Add LIM3 compatibility
    !!----------------------------------------------------------------------
-#if defined key_agrif && defined key_lim2
+#if defined key_agrif && defined key_lim3
    !!----------------------------------------------------------------------
    !!   'key_agrif'                                              AGRIF zoom
-   !!----------------------------------------------------------------------
-   USE par_oce      ! ocean parameters
-   
-   IMPLICIT NONE
-   PRIVATE 
-
-   PUBLIC agrif_ice_alloc ! routine called by nemo_init in nemogcm.F90
-
-   INTEGER, PUBLIC :: u_ice_id, v_ice_id, adv_ice_id
-   REAL(wp), PUBLIC :: lim_nbstep = 0.    ! child time position in sea-ice model
-#if defined key_lim2_vp
-   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:)     :: u_ice_nst, v_ice_nst   
-#else
-   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:)   :: u_ice_oe, u_ice_sn     !: boundaries arrays
-   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:)   :: v_ice_oe, v_ice_sn     !:  "          " 
-#endif
-   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:,:) :: adv_ice_oe, adv_ice_sn !:  "          "
-
-   !!----------------------------------------------------------------------
-   !! NEMO/NST 3.3.4 , NEMO Consortium (2012)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS 
-
-   INTEGER FUNCTION agrif_ice_alloc()
-      !!----------------------------------------------------------------------
-      !!                ***  FUNCTION agrif_ice_alloc  ***
-      !!----------------------------------------------------------------------
-#if defined key_lim2_vp
-      ALLOCATE( u_ice_nst(jpi,jpj), v_ice_nst(jpi,jpj) ,   &
-#else
-      ALLOCATE( u_ice_oe(4,jpj,2) , v_ice_oe(4,jpj,2) ,    &
-         &      u_ice_sn(jpi,4,2) , v_ice_sn(jpi,4,2) ,    &
-#endif
-         &      adv_ice_oe (4,jpj,7,2) , adv_ice_sn (jpi,4,7,2) ,   &
-         &      STAT = agrif_ice_alloc)
-
-#if ! defined key_lim2_vp
-      u_ice_oe(:,:,:) =  0.e0
-      v_ice_oe(:,:,:) =  0.e0
-      u_ice_sn(:,:,:) =  0.e0
-      v_ice_sn(:,:,:) =  0.e0
-#endif
-      adv_ice_oe (:,:,:,:) = 0.e0 
-      adv_ice_sn (:,:,:,:) = 0.e0 
-      !
-   END FUNCTION agrif_ice_alloc
-
-#elif defined key_agrif && defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_agrif'                                              AGRIF zoom
+   !!   'key_lim3'                                       LIM3 sea-ice model
    !!----------------------------------------------------------------------   
    IMPLICIT NONE
@@ -71,5 +19,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.6 , NEMO Consortium (2016)
+   !! NEMO/NST 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_lim2_interp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_lim2_interp.F90	(revision 9018)
+++ 	(revision )
@@ -1,662 +1,0 @@
-MODULE agrif_lim2_interp
-   !!======================================================================
-   !!                       ***  MODULE agrif_lim2_update ***
-   !! Nesting module :  update surface ocean boundary condition over ice
-   !!                   from a child grif
-   !! Sea-Ice model  :  LIM 2.0 Sea ice model time-stepping
-   !!======================================================================
-   !! History :  2.0   !  04-2008  (F. Dupont)  initial version
-   !!            3.4   !  09-2012  (R. Benshila, C. Herbaut) update and EVP
-   !!----------------------------------------------------------------------
-#if defined key_agrif && defined key_lim2 
-   !!----------------------------------------------------------------------
-   !!   'key_lim2'  :                                 LIM 2.0 sea-ice model
-   !!   'key_agrif' :                                 AGRIF library
-   !!----------------------------------------------------------------------
-   !!   agrif_interp_lim2   : update sea-ice model on boundaries or total
-   !!                         sea-ice area
-   !!  agrif_rhg_lim2_load  : interpolcation of ice velocities using Agrif
-   !!  agrif_rhg_lim2       : sub-interpolation of ice velocities for both 
-   !!                         splitting time and sea-ice time step
-   !!  agrif_interp_u_ice   : atomic routine to interpolate u_ice 
-   !!  agrif_interp_u_ice   : atomic routine to interpolate v_ice 
-   !!  agrif_trp_lim2_load  : interpolcation of ice properties using Agrif
-   !!  agrif_trp_lim2       : sub-interpolation of ice properties for  
-   !!                         sea-ice time step
-   !!  agrif_interp_u_ice   : atomic routine to interpolate ice properties 
-   !!----------------------------------------------------------------------
-   USE par_oce
-   USE dom_oce
-   USE sbc_oce
-   USE ice_2
-   USE dom_ice_2
-   USE agrif_ice
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC agrif_rhg_lim2_load, agrif_rhg_lim2
-   PUBLIC agrif_trp_lim2_load, agrif_trp_lim2
-   PUBLIC interp_u_ice, interp_v_ice
-   PUBLIC interp_adv_ice
-
-   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE, PRIVATE :: uice_agr, vice_agr
-   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE, PRIVATE :: tabice_agr 
-
-
-   !!----------------------------------------------------------------------
-   !! NEMO/NST 3.4 , NEMO Consortium (2012)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-# if defined key_lim2_vp
-   SUBROUTINE agrif_rhg_lim2_load
-      !!-----------------------------------------------------------------------
-      !!              *** ROUTINE agrif_rhg_lim2_load ***
-      !!
-      !!  ** Method  : need a special routine for dealing with exchanging data
-      !! between the child and parent grid during ice step
-      !!
-      !!-----------------------------------------------------------------------
-      !
-      IF (Agrif_Root()) RETURN
-
-      Agrif_SpecialValue=0.
-      Agrif_UseSpecialValue = .FALSE.
-      u_ice_nst(:,:) = 0.
-      v_ice_nst(:,:) = 0.
-      CALL Agrif_Bc_variable( u_ice_id ,procname=interp_u_ice, calledweight=1. )
-      CALL Agrif_Bc_variable( v_ice_id ,procname=interp_v_ice, calledweight=1. )
-      Agrif_SpecialValue=0.
-      Agrif_UseSpecialValue = .FALSE.
-      !
-   END SUBROUTINE agrif_rhg_lim2_load
-
-
-   SUBROUTINE agrif_rhg_lim2(pu_n,pv_n)
-      !!-----------------------------------------------------------------------
-      !!                 *** ROUTINE agrif_rhg_lim2 ***
-      !!
-      !!  ** Method  : we feel the boundaries with values stored above
-      !!-----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,0:jpj+1), INTENT(inout) :: pu_n, pv_n
-      !!
-      REAL(wp) :: zrhox, zrhoy
-      INTEGER :: ji,jj
-      !!-----------------------------------------------------------------------
-      !
-      IF (Agrif_Root()) RETURN
-
-      zrhox = Agrif_Rhox()
-      zrhoy = Agrif_Rhoy()
-
-      IF((nbondi == -1).OR.(nbondi == 2)) THEN
-         DO jj=2,jpj
-            pu_n(3,jj) = u_ice_nst(3,jj)/(zrhoy*e2f(2,jj-1))*tmu(3,jj)
-         END DO
-         DO jj=2,jpj
-            pv_n(3,jj) = v_ice_nst(3,jj)/(zrhox*e1f(2,jj-1))*tmu(3,jj)
-         END DO
-      ENDIF
-
-      IF((nbondi == 1).OR.(nbondi == 2)) THEN
-         DO jj=2,jpj
-            pu_n(nlci-1,jj) = u_ice_nst(nlci-1,jj)/(zrhoy*e2f(nlci-2,jj-1))*tmu(nlci-1,jj)
-         END DO
-         DO jj=2,jpj
-            pv_n(nlci-1,jj) = v_ice_nst(nlci-1,jj)/(zrhox*e1f(nlci-2,jj-1))*tmu(nlci-1,jj)
-         END DO
-      ENDIF
-
-      IF((nbondj == -1).OR.(nbondj == 2)) THEN
-         DO ji=2,jpi
-            pv_n(ji,3) = v_ice_nst(ji,3)/(zrhox*e1f(ji-1,2))*tmu(ji,3)
-         END DO
-         DO ji=2,jpi
-            pu_n(ji,3) = u_ice_nst(ji,3)/(zrhoy*e2f(ji-1,2))*tmu(ji,3)
-         END DO
-      ENDIF
-
-      IF((nbondj == 1).OR.(nbondj == 2)) THEN
-         DO ji=2,jpi
-            pv_n(ji,nlcj-1) = v_ice_nst(ji,nlcj-1)/(zrhox*e1f(ji-1,nlcj-2))*tmu(ji,nlcj-1)
-         END DO
-         DO ji=2,jpi
-            pu_n(ji,nlcj-1) = u_ice_nst(ji,nlcj-1)/(zrhoy*e2f(ji-1,nlcj-2))*tmu(ji,nlcj-1)
-         END DO
-      ENDIF
-      !
-   END SUBROUTINE agrif_rhg_lim2
-
-#else
-   SUBROUTINE agrif_rhg_lim2_load
-      !!-----------------------------------------------------------------------
-      !!              *** ROUTINE agrif_rhg_lim2_load ***
-      !!
-      !!  ** Method  : need a special routine for dealing with exchanging data
-      !!  between the child and parent grid during ice step
-      !!               we interpolate and store the boundary if needed, ie if
-      !!  we are in inside a new parent ice time step
-      !!-----------------------------------------------------------------------
-      INTEGER :: ji,jj
-      REAL(wp) :: zrhox, zrhoy
-      !!-----------------------------------------------------------------------
-      !
-      IF (Agrif_Root()) RETURN
-
-      IF( lim_nbstep == 1. ) THEN
-         !
-         ! switch old values by hand
-         u_ice_oe(:,:,1) =  u_ice_oe(:,:,2)
-         v_ice_oe(:,:,1) =  v_ice_oe(:,:,2)
-         u_ice_sn(:,:,1) =  u_ice_sn(:,:,2)
-         v_ice_sn(:,:,1) =  v_ice_sn(:,:,2)
-         ! interpolation of boundaries (called weight prevents AGRIF interpolation)
-         Agrif_SpecialValue=-9999.
-         Agrif_UseSpecialValue = .TRUE.
-         IF( .NOT. ALLOCATED(uice_agr) )THEN
-            ALLOCATE(uice_agr(jpi,jpj), vice_agr(jpi,jpj))
-         ENDIF
-         uice_agr = 0.
-         vice_agr = 0.
-         CALL Agrif_Bc_variable(u_ice_id,procname=interp_u_ice, calledweight=1.)
-         CALL Agrif_Bc_variable(v_ice_id,procname=interp_v_ice, calledweight=1.)
-         Agrif_SpecialValue=0.
-         Agrif_UseSpecialValue = .FALSE.
-         !  
-         zrhox = agrif_rhox() ;    zrhoy = agrif_rhoy()      
-         uice_agr(:,:) =  uice_agr(:,:)/(zrhoy*e2u(:,:))*umask(:,:,1)
-         vice_agr(:,:) =  vice_agr(:,:)/(zrhox*e1v(:,:))*vmask(:,:,1)
-         ! fill  boundaries
-         DO jj = 1, jpj
-            DO ji = 1, 2
-               u_ice_oe(ji,  jj,2) = uice_agr(ji       ,jj) 
-               u_ice_oe(ji+2,jj,2) = uice_agr(nlci+ji-3,jj)
-            END DO
-         END DO
-         DO jj = 1, jpj
-            v_ice_oe(2,jj,2) = vice_agr(2     ,jj) 
-            v_ice_oe(4,jj,2) = vice_agr(nlci-1,jj)
-         END DO
-         DO ji = 1, jpi
-            u_ice_sn(ji,2,2) = uice_agr(ji,2     ) 
-            u_ice_sn(ji,4,2) = uice_agr(ji,nlcj-1)
-         END DO
-         DO jj = 1, 2
-            DO ji = 1, jpi
-               v_ice_sn(ji,jj  ,2) = vice_agr(ji,jj       ) 
-               v_ice_sn(ji,jj+2,2) = vice_agr(ji,nlcj+jj-3)
-            END DO
-         END DO
-         !
-      ENDIF
-      !
-   END SUBROUTINE agrif_rhg_lim2_load
-
-
-   SUBROUTINE agrif_rhg_lim2( kiter, kitermax, cd_type)
-      !!-----------------------------------------------------------------------
-      !!                 *** ROUTINE agrif_rhg_lim2  ***
-      !!
-      !!  ** Method  : simple call to atomic routines using stored values to
-      !!  fill the boundaries depending of the position of the point and 
-      !!  computing factor for time interpolation 
-      !!-----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: kiter, kitermax
-      CHARACTER(len=1), INTENT( in ) :: cd_type
-      !!    
-      REAL(wp) :: zalpha, zbeta
-      !!-----------------------------------------------------------------------
-      !
-      IF (Agrif_Root()) RETURN
-      zalpha = REAL(lim_nbstep,wp) / (Agrif_Rhot()*Agrif_PArent(nn_fsbc)/REAL(nn_fsbc))
-      zbeta  = REAL(kiter,wp) / kitermax
-      zbeta = zalpha * zbeta
-      SELECT CASE(cd_type)
-      CASE('U')
-         CALL ParcoursU( zbeta )
-      CASE('V')
-         CALL ParcoursV( zbeta )
-      END SELECT
-      !
-   END SUBROUTINE agrif_rhg_lim2
-
-
-   SUBROUTINE ParcoursU( pbeta )
-      !!-----------------------------------------------------------------------
-      !!                    *** ROUTINE parcoursU ***
-      !!
-      !!  ** Method  : time and spatial interpolation for U-point using values
-      !!  interpolated from the coarse grid and inside dvalues     
-      !!-----------------------------------------------------------------------
-      REAL(wp), INTENT(in) :: pbeta
-      !!
-      INTEGER :: ji, jj
-      !!-----------------------------------------------------------------------
-      !
-      IF((nbondi == -1).OR.(nbondi == 2)) THEN
-         DO jj=1,jpj
-            DO ji=1,2
-               u_ice(ji,jj) = (1-pbeta) * u_ice_oe(ji,jj,1) + pbeta * u_ice_oe(ji,jj,2)
-            END DO
-         END DO
-         DO jj=1,jpj
-            u_ice(2,jj) = 0.25*(u_ice(1,jj)+2.*u_ice(2,jj)+u_ice(3,jj))
-            u_ice(2,jj) = u_ice(2,jj) * umask(2,jj,1)
-         END DO
-      ENDIF
-
-      IF((nbondi == 1).OR.(nbondi == 2)) THEN
-         DO jj=1,jpj
-            DO ji=1,2
-               u_ice(nlci+ji-3,jj) = (1-pbeta) * u_ice_oe(ji+2,jj,1) + pbeta * u_ice_oe(ji+2,jj,2)
-            END DO
-         END DO
-         DO jj=1,jpj
-            u_ice(nlci-2,jj) = 0.25*(u_ice(nlci-3,jj)+2.*u_ice(nlci-2,jj)+u_ice(nlci-1,jj))
-            u_ice(nlci-2,jj) = u_ice(nlci-2,jj) * umask(nlci-2,jj,1)
-         END DO
-      ENDIF
-
-      IF((nbondj == -1).OR.(nbondj == 2)) THEN
-         DO ji=1,jpi
-            u_ice(ji,2) = (1-pbeta) * u_ice_sn(ji,2,1) + pbeta * u_ice_sn(ji,2,2)
-            u_ice(ji,2) = u_ice(ji,2)*umask(ji,2,1)
-         END DO
-      ENDIF
-
-      IF((nbondj == 1).OR.(nbondj == 2)) THEN
-         DO ji=1,jpi
-            u_ice(ji,nlcj-1) = (1-pbeta) * u_ice_sn(ji,4,1) + pbeta * u_ice_sn(ji,4,2)
-            u_ice(ji,nlcj-1) = u_ice(ji,nlcj-1)*umask(ji,nlcj-1,1)
-         END DO
-      ENDIF
-      !
-   END SUBROUTINE ParcoursU
-
-
-   SUBROUTINE ParcoursV( pbeta )
-      !!-----------------------------------------------------------------------
-      !!                    *** ROUTINE parcoursV ***
-      !! 
-      !!  ** Method  : time and spatial interpolation for V-point using values
-      !!  interpolated from the coarse grid and inside dvalues     
-      !!-----------------------------------------------------------------------
-      REAL(wp), INTENT(in) :: pbeta
-      !!
-      INTEGER :: ji, jj
-      !!-----------------------------------------------------------------------
-      !
-      IF((nbondi == -1).OR.(nbondi == 2)) THEN
-         DO jj=1,jpj
-            v_ice(2,jj) = (1-pbeta) * v_ice_oe(2,jj,1) + pbeta * v_ice_oe(2,jj,2)
-            v_ice(2,jj) = v_ice(2,jj) * vmask(2,jj,1)
-         END DO
-      ENDIF
-
-      IF((nbondi == 1).OR.(nbondi == 2)) THEN
-         DO jj=1,jpj
-            v_ice(nlci-1,jj) = (1-pbeta) * v_ice_oe(4,jj,1) + pbeta * v_ice_oe(4,jj,2)
-            v_ice(nlci-1,jj) = v_ice(nlci-1,jj)*vmask(nlci-1,jj,1)
-         END DO
-      ENDIF
-
-      IF((nbondj == -1).OR.(nbondj == 2)) THEN
-         DO jj=1,2
-            DO ji=1,jpi
-               v_ice(ji,jj) = (1-pbeta) * v_ice_sn(ji,jj,1) + pbeta * v_ice_sn(ji,jj,2)
-            END DO
-         END DO
-         DO ji=1,jpi
-            v_ice(ji,2)=0.25*(v_ice(ji,1)+2.*v_ice(ji,2)+v_ice(ji,3))
-            v_ice(ji,2)=v_ice(ji,2)*vmask(ji,2,1)
-         END DO
-      ENDIF
-
-      IF((nbondj == 1).OR.(nbondj == 2)) THEN
-         DO jj=1,2
-            DO ji=1,jpi
-               v_ice(ji,nlcj+jj-3) = (1-pbeta) * v_ice_sn(ji,jj+2,1) + pbeta * v_ice_sn(ji,jj+2,2)
-            END DO
-         END DO
-         DO ji=1,jpi
-            v_ice(ji,nlcj-2)=0.25*(v_ice(ji,nlcj-3)+2.*v_ice(ji,nlcj-2)+v_ice(ji,nlcj-1))
-            v_ice(ji,nlcj-2) = v_ice(ji,nlcj-2) * vmask(ji,nlcj-2,1)
-         END DO
-      ENDIF
-      !
-   END SUBROUTINE ParcoursV
-# endif
-   SUBROUTINE agrif_trp_lim2_load
-      !!-----------------------------------------------------------------------
-      !!                 *** ROUTINE agrif_trp_lim2_load ***
-      !!
-      !!  ** Method  : need a special routine for dealing with exchanging data
-      !!  between the child and parent grid during ice step
-      !!               we interpolate and store the boundary if needed, ie if
-      !!  we are in inside a new parent ice time step
-     !!-----------------------------------------------------------------------
-      INTEGER :: ji,jj,jn
-      !!-----------------------------------------------------------------------
-      !
-      IF (Agrif_Root()) RETURN
-      IF( lim_nbstep == 1. ) THEN
-         !
-         ! switch old values
-         adv_ice_oe(:,:,:,1) =  adv_ice_oe(:,:,:,2)
-         adv_ice_sn(:,:,:,1) =  adv_ice_sn(:,:,:,2)
-         ! interpolation of boundaries
-         IF(.NOT.ALLOCATED(tabice_agr))THEN
-            ALLOCATE(tabice_agr(jpi,jpj,7))   
-         ENDIF
-         tabice_agr(:,:,:) = 0.
-         Agrif_SpecialValue=-9999.
-         Agrif_UseSpecialValue = .TRUE.
-         CALL Agrif_Bc_variable( adv_ice_id ,procname=interp_adv_ice,calledweight=1. )
-         Agrif_SpecialValue=0.
-         Agrif_UseSpecialValue = .FALSE.
-         !  
-         ! fill  boundaries
-         DO jn =1,7
-            DO jj = 1, jpj
-               DO ji=1,2
-                  adv_ice_oe(ji  ,jj,jn,2) = tabice_agr(ji       ,jj,jn) 
-                  adv_ice_oe(ji+2,jj,jn,2) = tabice_agr(nlci-2+ji,jj,jn)
-               END DO
-            END DO
-         END DO
-
-         Do jn =1,7
-            Do jj =1,2
-               DO ji = 1, jpi
-                  adv_ice_sn(ji,jj  ,jn,2) = tabice_agr(ji,jj       ,jn) 
-                  adv_ice_sn(ji,jj+2,jn,2) = tabice_agr(ji,nlcj-2+jj,jn)
-               END DO
-            END DO
-         END DO
-         !
-      ENDIF
-      !
-   END SUBROUTINE agrif_trp_lim2_load
-
-
-   SUBROUTINE agrif_trp_lim2
-      !!-----------------------------------------------------------------------
-      !!                  *** ROUTINE agrif_trp_lim2 ***
-      !!
-      !!  ** Method  : time coefficient and call to atomic routines
-      !!-----------------------------------------------------------------------
-      INTEGER :: ji,jj,jn
-      REAL(wp) :: zalpha
-      !!-----------------------------------------------------------------------      
-      !
-      IF (Agrif_Root()) RETURN
-
-      zalpha = REAL(lim_nbstep,wp) / (Agrif_Rhot()*Agrif_PArent(nn_fsbc)/REAL(nn_fsbc))
-      !
-      tabice_agr(:,:,:) = 0.e0
-      DO jn =1,7
-         DO jj =1,2
-            DO ji = 1, jpi
-               tabice_agr(ji,jj        ,jn) = (1-zalpha)*adv_ice_sn(ji,jj  ,jn,1) + zalpha*adv_ice_sn(ji,jj  ,jn,2) 
-               tabice_agr(ji,nlcj-2+jj ,jn) = (1-zalpha)*adv_ice_sn(ji,jj+2,jn,1) + zalpha*adv_ice_sn(ji,jj+2,jn,2) 
-            END DO
-         END DO
-      END DO
-
-      DO jn =1,7
-         DO jj = 1, jpj
-            DO ji=1,2
-               tabice_agr(ji       ,jj,jn) = (1-zalpha)*adv_ice_oe(ji  ,jj,jn,1) + zalpha*adv_ice_oe(ji  ,jj,jn,2) 
-               tabice_agr(nlci-2+ji,jj,jn) = (1-zalpha)*adv_ice_oe(ji+2,jj,jn,1) + zalpha*adv_ice_oe(ji+2,jj,jn,2) 
-            END DO
-         END DO
-      END DO
-      !
-      CALL parcoursT( tabice_agr(:,:, 1), frld  )
-      CALL parcoursT( tabice_agr(:,:, 2), hicif )
-      CALL parcoursT( tabice_agr(:,:, 3), hsnif )
-      CALL parcoursT( tabice_agr(:,:, 4), tbif(:,:,1) )
-      CALL parcoursT( tabice_agr(:,:, 5), tbif(:,:,2) )
-      CALL parcoursT( tabice_agr(:,:, 6), tbif(:,:,3) )
-      CALL parcoursT( tabice_agr(:,:, 7), qstoif )
-      !
-   END SUBROUTINE agrif_trp_lim2
-
-
-   SUBROUTINE parcoursT ( pinterp, pfinal )
-      !!-----------------------------------------------------------------------
-      !!                    *** ROUTINE parcoursT ***
-      !!
-      !!  ** Method  : fill boundaries for T points
-      !!-----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in)    :: pinterp
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) :: pfinal
-      !!
-      REAL(wp) :: zbound, zvbord
-      REAL(wp), DIMENSION(jpi,jpj) ::  zui_u, zvi_v
-      INTEGER :: ji, jj
-      !!-----------------------------------------------------------------------
-      !
-      zui_u = 0.e0
-      zvi_v = 0.e0
-      ! zvbord factor between 1 and 2 to take into account slip or no-slip boundary conditions.
-      zbound=0.
-      zvbord = 1.0 + ( 1.0 - zbound )
-#if defined key_lim2_vp
-      DO jj = 1, jpjm1
-         DO ji = 1, jpim1
-            zui_u(ji,jj) = ( u_ice(ji+1,jj  ) + u_ice(ji+1,jj+1) ) / ( MAX( tmu(ji+1,jj  ) + tmu(ji+1,jj+1), zvbord ) )
-            zvi_v(ji,jj) = ( v_ice(ji  ,jj+1) + v_ice(ji+1,jj+1) ) / ( MAX( tmu(ji  ,jj+1) + tmu(ji+1,jj+1), zvbord ) )
-         END DO
-      END DO
-#else
-      zui_u(:,:) = u_ice(:,:)
-      zvi_v(:,:) = v_ice(:,:)
-#endif
-
-      IF((nbondi == -1).OR.(nbondi == 2)) THEN
-         DO jj=1,jpj
-            !            IF (zui_u(2,jj).EQ.0.) THEN
-            !               pfinal (2,jj) = pfinal (1,jj) * tms(2,jj)
-            !            ELSE
-            pfinal(2,jj) = 0.25* pinterp(1,jj) + 0.5 *  pinterp(2,jj) + 0.25 *pfinal(3,jj)
-            !            ENDIF
-         END DO
-      ENDIF
-
-      IF((nbondj == -1).OR.(nbondj == 2)) THEN
-         DO ji=1,jpi
-            !            IF (zvi_v(ji,2).EQ.0.) THEN
-            !               pfinal (ji,2) = pfinal (ji,1) * tms(ji,2)
-            !            ELSE
-            pfinal(ji,2) = 0.25* pinterp(ji,1) + 0.5 *  pinterp(ji,2) + 0.25 *pfinal(ji,3)
-            !            ENDIF 
-         END DO
-      ENDIF
-
-
-      IF((nbondi == 1).OR.(nbondi == 2)) THEN
-         DO jj=1,jpj
-            !            IF (zui_u(nlci-2,jj).EQ.0.) THEN
-            !               pfinal(nlci-1,jj) = pfinal (nlci,jj) * tms(nlci-1,jj)
-            !            ELSE
-            pfinal(nlci-1,jj) = 0.25* pinterp(nlci,jj) + 0.5 *  pinterp(nlci-1,jj) + 0.25 *pfinal(nlci-2,jj)
-            !           ENDIF
-         END DO
-      ENDIF
-
-      IF((nbondj == 1).OR.(nbondj == 2)) THEN
-         DO ji=1,jpi
-            !            IF (zvi_v(ji,nlcj-2).EQ.0.) THEN
-            !               pfinal (ji,nlcj-1) =  pfinal(ji,nlcj) * tms(ji,nlcj-1)
-            !            ELSE
-            pfinal(ji,nlcj-1) = 0.25* pinterp(ji,nlcj) + 0.5 *  pinterp(ji,nlcj-1) + 0.25 *pfinal(ji,nlcj-2)
-            !            ENDIF
-         END DO
-      ENDIF
-
-
-      pfinal (:,:) = pfinal (:,:) * tms(:,:)
-      ! 
-   END SUBROUTINE parcoursT
-
-
-   SUBROUTINE interp_u_ice( tabres, i1, i2, j1, j2, before )
-      !!-----------------------------------------------------------------------
-      !!                     *** ROUTINE interp_u_ice ***
-      !!-----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-      !!
-      INTEGER :: ji,jj
-      !!-----------------------------------------------------------------------
-      !
-#if defined key_lim2_vp
-      IF( before ) THEN
-         DO jj=MAX(j1,2),j2
-            DO ji=MAX(i1,2),i2
-               IF( tmu(ji,jj) == 0. ) THEN
-                  tabres(ji,jj) = -9999.
-               ELSE
-                  tabres(ji,jj) = e2f(ji-1,jj-1) * u_ice(ji,jj)
-               ENDIF
-            END DO
-         END DO
-      ELSE
-         DO jj=MAX(j1,2),j2
-            DO ji=MAX(i1,2),i2
-               uice_agr(ji,jj) = tabres(ji,jj)
-            END DO
-         END DO
-      ENDIF
-#else
-      IF( before ) THEN
-         DO jj= j1, j2
-            DO ji= i1, i2
-               IF( umask(ji,jj,1) == 0. ) THEN
-                  tabres(ji,jj) = -9999.
-               ELSE
-                  tabres(ji,jj) = e2u(ji,jj) * u_ice(ji,jj)
-               ENDIF
-            END DO
-         END DO
-      ELSE
-         DO jj= j1, j2
-            DO ji= i1, i2
-               uice_agr(ji,jj) = tabres(ji,jj)
-            END DO
-         END DO
-      ENDIF
-#endif
-   END SUBROUTINE interp_u_ice
-
-
-   SUBROUTINE interp_v_ice( tabres, i1, i2, j1, j2, before )
-      !!-----------------------------------------------------------------------
-      !!                    *** ROUTINE interp_v_ice ***
-      !!-----------------------------------------------------------------------      
-      INTEGER, INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-      !!
-      INTEGER :: ji, jj
-      !!-----------------------------------------------------------------------
-      !
-#if defined key_lim2_vp
-      IF( before ) THEN
-         DO jj=MAX(j1,2),j2
-            DO ji=MAX(i1,2),i2
-               IF( tmu(ji,jj) == 0. ) THEN
-                  tabres(ji,jj) = -9999.
-               ELSE
-                  tabres(ji,jj) = e1f(ji-1,jj-1) * v_ice(ji,jj)
-               ENDIF
-            END DO
-         END DO
-      ELSE
-         DO jj=MAX(j1,2),j2
-            DO ji=MAX(i1,2),i2
-               vice_agr(ji,jj) = tabres(ji,jj)
-            END DO
-         END DO
-      ENDIF   
-#else
-      IF( before ) THEN
-	      DO jj= j1 ,j2
-	         DO ji = i1, i2
-	            IF( vmask(ji,jj,1) == 0. ) THEN
-	               tabres(ji,jj) = -9999.
-	            ELSE
-	               tabres(ji,jj) = e1v(ji,jj) * v_ice(ji,jj)
-	            ENDIF
-	         END DO
-	      END DO
-      ELSE
-	      DO jj= j1 ,j2
-	         DO ji = i1, i2
-	            vice_agr(ji,jj) = tabres(ji,jj)
-	         END DO
-	      END DO
-      ENDIF
-#endif
-   END SUBROUTINE interp_v_ice
-
-
-   SUBROUTINE interp_adv_ice( tabres, i1, i2, j1, j2, k1, k2, before )
-      !!-----------------------------------------------------------------------
-      !!                    *** ROUTINE interp_adv_ice ***                           
-      !!
-      !! ** Purpose : fill an array with  ice variables
-      !!              to be advected
-      !!              put -9999 where no ice for correct extrapolation             
-      !!-----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2, k1, k2
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-      !!
-      INTEGER :: ji, jj, jk
-      !!-----------------------------------------------------------------------
-      !
-      IF( before ) THEN
-         DO jj=j1,j2
-	    DO ji=i1,i2
-	       IF( tms(ji,jj) == 0. ) THEN
-	          tabres(ji,jj,:) = -9999 
-	       ELSE
-	          tabres(ji,jj, 1) = frld  (ji,jj)
-	          tabres(ji,jj, 2) = hicif (ji,jj)
-	          tabres(ji,jj, 3) = hsnif (ji,jj)
-	          tabres(ji,jj, 4) = tbif  (ji,jj,1)
-	          tabres(ji,jj, 5) = tbif  (ji,jj,2)
-	          tabres(ji,jj, 6) = tbif  (ji,jj,3)
-	          tabres(ji,jj, 7) = qstoif(ji,jj)
-	       ENDIF
-	    END DO
-         END DO
-      ELSE
-	 DO jj=j1,j2
-	    DO ji=i1,i2
-               DO jk=k1, k2
-	          tabice_agr(ji,jj,jk) = tabres(ji,jj,jk)
-               END DO
-	    END DO
-	 END DO
-      ENDIF
-      !
-   END SUBROUTINE interp_adv_ice
-
-#else
-CONTAINS
-   SUBROUTINE agrif_lim2_interp_empty
-      !!---------------------------------------------
-      !!   *** ROUTINE agrif_lim2_interp_empty ***
-      !!---------------------------------------------
-      WRITE(*,*)  'agrif_lim2_interp : You should not have seen this print! error?'
-   END SUBROUTINE agrif_lim2_interp_empty
-#endif
-END MODULE agrif_lim2_interp
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_lim2_update.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_lim2_update.F90	(revision 9018)
+++ 	(revision )
@@ -1,264 +1,0 @@
-#define TWO_WAY
-
-MODULE agrif_lim2_update
-   !!======================================================================
-   !!                       ***  MODULE agrif_lim2_update ***
-   !! Nesting module :  update surface ocean boundary condition over ice
-   !!                   from a child grif
-   !! Sea-Ice model  :  LIM 2.0 Sea ice model time-stepping
-   !!======================================================================
-   !! History :  2.0   !  04-2008  (F. Dupont)  initial version
-   !!            3.4   !  08-2012  (R. Benshila, C. Herbaut) update and EVP
-   !!----------------------------------------------------------------------
-#if defined key_agrif && defined key_lim2
-   !!----------------------------------------------------------------------
-   !!   'key_lim2'  :                                 LIM 2.0 sea-ice model
-   !!   'key_agrif' :                                 AGRIF library 
-   !!----------------------------------------------------------------------
-   !!   agrif_update_lim2  : update sea-ice model on boundaries or total
-   !!                        sea-ice area for velocities and ice properties
-   !!   update_adv_ice     : sea-ice properties
-   !!   update_u_ice       : zonal ice velocity
-   !!   update_v_ice       : meridional ice velocity
-   !!----------------------------------------------------------------------
-   USE ice_2
-   USE dom_ice_2
-   USE sbc_oce
-   USE dom_oce
-   USE agrif_oce
-   USE agrif_ice 
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC agrif_update_lim2
-
-   !!----------------------------------------------------------------------
-   !! NEMO/NST 3.4 , LOCEAN-IPSL (2012)
-   !! $Id$
-   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE agrif_update_lim2 ( kt )
-      !!----------------------------------------------------------------------
-      !!                     *** ROUTINE agrif_update_lim2 ***
-      !! ** Method  :   Call the hydrostaticupdate pressure at the boundary or
-      !!                the entire domain 
-      !!
-      !! ** Action : - Update (u_ice,v_ice) and ice tracers
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: kt
-      !!
-      !!----------------------------------------------------------------------
-      !
-      IF((Agrif_NbStepint() .NE. (Agrif_irhot()-1)).AND.(kt /= 0)) RETURN
-
-      Agrif_UseSpecialValueInUpdate = .TRUE.
-      Agrif_SpecialValueFineGrid = 0.
-# if defined TWO_WAY
-      IF( MOD(nbcline,nbclineupdate) == 0) THEN
-         CALL Agrif_Update_Variable( adv_ice_id , procname = update_adv_ice  )
-         CALL Agrif_Update_Variable( u_ice_id   , procname = update_u_ice    )
-         CALL Agrif_Update_Variable( v_ice_id   , procname = update_v_ice    )
-      ELSE
-         CALL Agrif_Update_Variable( adv_ice_id , locupdate=(/0,2/), procname = update_adv_ice  )
-         CALL Agrif_Update_Variable( u_ice_id   , locupdate=(/0,1/), procname = update_u_ice    )
-         CALL Agrif_Update_Variable( v_ice_id   , locupdate=(/0,1/), procname = update_v_ice    )
-      ENDIF
-# endif
-      !
-   END SUBROUTINE agrif_update_lim2
-
-
-   SUBROUTINE update_adv_ice( tabres, i1, i2, j1, j2, before )
-      !!-----------------------------------------------------------------------
-      !!                        *** ROUTINE update_adv_ice ***
-      !! ** Method  : Compute the mass properties on the fine grid and recover
-      !!              the properties per mass on the coarse grid
-      !!-----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2,7), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-      !!
-      INTEGER :: ji, jj
-      REAL(wp) :: zrhox, zrhoy
-      REAL(wp) :: z1_area
-      !!-----------------------------------------------------------------------
-      !
-      IF( before ) THEN
-         zrhox = Agrif_Rhox()
-         zrhoy = Agrif_Rhoy()
-         DO jj=j1,j2
-            DO ji=i1,i2
-               tabres(ji,jj, 1) = frld  (ji,jj  ) * area(ji,jj)
-               tabres(ji,jj, 2) = hicif (ji,jj  ) * area(ji,jj)
-               tabres(ji,jj, 3) = hsnif (ji,jj  ) * area(ji,jj)
-               tabres(ji,jj, 4) = tbif  (ji,jj,1) * area(ji,jj)
-               tabres(ji,jj, 5) = tbif  (ji,jj,2) * area(ji,jj)
-               tabres(ji,jj, 6) = tbif  (ji,jj,3) * area(ji,jj)
-               tabres(ji,jj, 7) = qstoif(ji,jj  ) * area(ji,jj)
-            END DO
-         END DO
-         tabres = zrhox * zrhoy * tabres
-      ELSE
-         DO jj=j1,j2
-            DO ji=i1,i2
-               z1_area = 1. / area(ji,jj) * tms(ji,jj)
-               frld  (ji,jj)   = tabres(ji,jj, 1) * z1_area
-               hicif (ji,jj)   = tabres(ji,jj, 2) * z1_area
-               hsnif (ji,jj)   = tabres(ji,jj, 3) * z1_area
-               tbif  (ji,jj,1) = tabres(ji,jj, 4) * z1_area
-               tbif  (ji,jj,2) = tabres(ji,jj, 5) * z1_area
-               tbif  (ji,jj,3) = tabres(ji,jj, 6) * z1_area
-               qstoif(ji,jj)   = tabres(ji,jj, 7) * z1_area
-            END DO
-         END DO
-      ENDIF
-      !
-   END SUBROUTINE update_adv_ice
-
-
-# if defined key_lim2_vp
-   SUBROUTINE update_u_ice( tabres, i1, i2, j1, j2, before )
-      !!-----------------------------------------------------------------------
-      !!                        *** ROUTINE update_u_ice ***
-      !! ** Method  : Update the fluxes and recover the properties (B-grid)
-      !!-----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-      !!
-      INTEGER :: ji, jj
-      REAL(wp) :: zrhoy
-      !!-----------------------------------------------------------------------
-      !
-      IF( before ) THEN
-         zrhoy = Agrif_Rhoy()
-         DO jj=MAX(j1,2),j2
-            DO ji=MAX(i1,2),i2
-               tabres(ji,jj) = e2f(ji-1,jj-1) * u_ice(ji,jj)
-            END DO
-         END DO
-         tabres = zrhoy * tabres
-      ELSE
-         DO jj= MAX(j1,2),j2
-            DO ji=MAX(i1,2),i2
-               u_ice(ji,jj) = tabres(ji,jj) / (e2f(ji-1,jj-1))
-               u_ice(ji,jj) = u_ice(ji,jj) * tmu(ji,jj)
-            END DO
-         END DO
-      ENDIF
-      !
-   END SUBROUTINE update_u_ice
-
-
-   SUBROUTINE update_v_ice( tabres, i1, i2, j1, j2, before )
-      !!-----------------------------------------------------------------------
-      !!                    *** ROUTINE update_v_ice ***
-      !! ** Method  : Update the fluxes and recover the properties (B-grid)
-      !!-----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: i1,i2,j1,j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2),  INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-      !!
-      INTEGER :: ji, jj
-      REAL(wp) :: zrhox
-      !!-----------------------------------------------------------------------
-      !
-      IF( before ) THEN
-         zrhox = Agrif_Rhox()
-         DO jj=MAX(j1,2),j2
-            DO ji=MAX(i1,2),i2
-               tabres(ji,jj) = e1f(ji-1,jj-1) * v_ice(ji,jj)
-            END DO
-         END DO
-         tabres = zrhox * tabres
-      ELSE
-         DO jj=j1,j2
-            DO ji=i1,i2
-               v_ice(ji,jj) = tabres(ji,jj) / (e1f(ji-1,jj-1))
-               v_ice(ji,jj) = v_ice(ji,jj) * tmu(ji,jj)
-            END DO
-         END DO
-      ENDIF
-      !
-   END SUBROUTINE update_v_ice
-# else
-   SUBROUTINE update_u_ice( tabres, i1, i2, j1, j2, before )
-      !!-----------------------------------------------------------------------
-      !!                        *** ROUTINE update_u_ice ***
-      !! ** Method  : Update the fluxes and recover the properties (C-grid)
-      !!-----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-      !!
-      INTEGER :: ji, jj
-      REAL(wp) :: zrhoy
-      !!-----------------------------------------------------------------------
-      !
-      IF( before ) THEN
-         zrhoy = Agrif_Rhoy()
-         DO jj=MAX(j1,2),j2
-            DO ji=MAX(i1,2),i2
-               tabres(ji,jj) = e2u(ji,jj) * u_ice(ji,jj)
-            END DO
-         END DO
-         tabres = zrhoy * tabres
-      ELSE
-         DO jj=MAX(j1,2),j2
-            DO ji=MAX(i1,2),i2
-               u_ice(ji,jj) = tabres(ji,jj) / (e2u(ji,jj))
-               u_ice(ji,jj) = u_ice(ji,jj) * tmu(ji,jj)
-            END DO
-         END DO
-      ENDIF
-      ! 
-   END SUBROUTINE update_u_ice
-
-
-   SUBROUTINE update_v_ice( tabres, i1, i2, j1, j2, before )
-      !!-----------------------------------------------------------------------
-      !!                    *** ROUTINE update_v_ice ***
-      !! ** Method  : Update the fluxes and recover the properties (C-grid)
-      !!-----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: i1,i2,j1,j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2),  INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-      !!
-      INTEGER :: ji, jj
-      REAL(wp) :: zrhox
-      !!-----------------------------------------------------------------------
-      !
-      IF( before ) THEN
-         zrhox = Agrif_Rhox()
-         DO jj=MAX(j1,2),j2
-            DO ji=MAX(i1,2),i2
-               tabres(ji,jj) = e1v(ji,jj) * v_ice(ji,jj)
-            END DO
-         END DO
-         tabres = zrhox * tabres
-      ELSE
-         DO jj=j1,j2
-            DO ji=i1,i2
-               v_ice(ji,jj) = tabres(ji,jj) / (e1v(ji,jj))
-               v_ice(ji,jj) = v_ice(ji,jj) * tmv(ji,jj)
-            END DO
-         END DO
-      ENDIF
-      !
-   END SUBROUTINE update_v_ice
-# endif
-
-#else
-CONTAINS
-   SUBROUTINE agrif_lim2_update_empty
-      !!---------------------------------------------
-      !!   *** ROUTINE agrif_lim2_update_empty ***
-      !!---------------------------------------------
-      WRITE(*,*)  'agrif_lim2_update : You should not have seen this print! error?'
-   END SUBROUTINE agrif_lim2_update_empty
-#endif
-END MODULE agrif_lim2_update
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_lim3_interp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_lim3_interp.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_lim3_interp.F90	(revision 9019)
@@ -28,5 +28,5 @@
    PRIVATE
 
-   PUBLIC agrif_interp_lim3
+   PUBLIC   agrif_interp_lim3   ! called by agrif_user.F90
 
    !!----------------------------------------------------------------------
@@ -46,13 +46,13 @@
       !!  computing factor for time interpolation
       !!-----------------------------------------------------------------------
-      CHARACTER(len=1), INTENT( in )           :: cd_type
-      INTEGER         , INTENT( in ), OPTIONAL :: kiter, kitermax
-      !!
-      REAL(wp) :: zbeta
-      !!-----------------------------------------------------------------------
-      !
-      IF( Agrif_Root() )  RETURN
-      !
-      SELECT CASE(cd_type)
+      CHARACTER(len=1), INTENT(in   )           ::   cd_type
+      INTEGER         , INTENT(in   ), OPTIONAL ::   kiter, kitermax
+      !!
+      REAL(wp) ::   zbeta   ! local scalar
+      !!-----------------------------------------------------------------------
+      !
+      IF( Agrif_Root() .OR. nn_ice==0 )  RETURN   ! do not interpolate if inside Parent domain or if child domain does not have ice
+      !
+      SELECT CASE( cd_type )
       CASE('U','V')
          IF( PRESENT( kiter ) ) THEN  ! interpolation at the child sub-time step (only for ice rheology)
@@ -66,22 +66,17 @@
       END SELECT
       !
-      Agrif_SpecialValue=-9999.
+      Agrif_SpecialValue    = -9999.
       Agrif_UseSpecialValue = .TRUE.
-      SELECT CASE(cd_type)
-      CASE('U')
-         CALL Agrif_Bc_variable( u_ice_id  , procname=interp_u_ice  , calledweight=zbeta )
-      CASE('V')
-         CALL Agrif_Bc_variable( v_ice_id  , procname=interp_v_ice  , calledweight=zbeta )
-      CASE('T')
-         CALL Agrif_Bc_variable( tra_ice_id, procname=interp_tra_ice, calledweight=zbeta )
+      SELECT CASE( cd_type )
+      CASE('U')   ;   CALL Agrif_Bc_variable( u_ice_id  , procname=interp_u_ice  , calledweight=zbeta )
+      CASE('V')   ;   CALL Agrif_Bc_variable( v_ice_id  , procname=interp_v_ice  , calledweight=zbeta )
+      CASE('T')   ;   CALL Agrif_Bc_variable( tra_ice_id, procname=interp_tra_ice, calledweight=zbeta )
       END SELECT
-      Agrif_SpecialValue=0.
+      Agrif_SpecialValue    = 0._wp
       Agrif_UseSpecialValue = .FALSE.
       !
    END SUBROUTINE agrif_interp_lim3
 
-   !!------------------
-   !! Local subroutines
-   !!------------------
+
    SUBROUTINE interp_u_ice( ptab, i1, i2, j1, j2, before )
       !!-----------------------------------------------------------------------
@@ -89,20 +84,21 @@
       !!
       !! i1 i2 j1 j2 are the index of the boundaries parent(when before) and child (when after)
-      !! To solve issues when parent grid is "land" masked but not all the corresponding child grid points,
-      !! put -9999 WHERE the parent grid is masked. The child solution will be found in the 9(?) points around
-      !!-----------------------------------------------------------------------
-      INTEGER , INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: ptab
-      LOGICAL , INTENT(in) :: before
-      !!
-      REAL(wp) :: zrhoy
+      !! To solve issues when parent grid is "land" masked but not all the corresponding child 
+      !! grid points, put Agrif_SpecialValue WHERE the parent grid is masked. 
+      !! The child solution will be found in the 9(?) points around
+      !!-----------------------------------------------------------------------
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
+      LOGICAL                         , INTENT(in   ) ::   before
+      !!
+      REAL(wp) ::   zrhoy   ! local scalar
       !!-----------------------------------------------------------------------
       !
       IF( before ) THEN  ! parent grid
          ptab(:,:) = e2u(i1:i2,j1:j2) * u_ice_b(i1:i2,j1:j2)
-         WHERE( umask(i1:i2,j1:j2,1) == 0. )  ptab(:,:) = -9999.
+         WHERE( umask(i1:i2,j1:j2,1) == 0. )   ptab(i1:i2,j1:j2) = Agrif_SpecialValue
       ELSE               ! child grid
          zrhoy = Agrif_Rhoy()
-         u_ice(i1:i2,j1:j2) = ptab(:,:) / ( e2u(i1:i2,j1:j2) * zrhoy ) * umask(i1:i2,j1:j2,1)
+         u_ice(i1:i2,j1:j2) = ptab(i1:i2,j1:j2) / ( e2u(i1:i2,j1:j2) * zrhoy ) * umask(i1:i2,j1:j2,1)
       ENDIF
       !
@@ -115,20 +111,21 @@
       !!
       !! i1 i2 j1 j2 are the index of the boundaries parent(when before) and child (when after)
-      !! To solve issues when parent grid is "land" masked but not all the corresponding child grid points,
-      !! put -9999 WHERE the parent grid is masked. The child solution will be found in the 9(?) points around
+      !! To solve issues when parent grid is "land" masked but not all the corresponding child 
+      !! grid points, put Agrif_SpecialValue WHERE the parent grid is masked. 
+      !! The child solution will be found in the 9(?) points around
       !!-----------------------------------------------------------------------      
-      INTEGER , INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: ptab
-      LOGICAL , INTENT(in) :: before
-      !!
-      REAL(wp) :: zrhox
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
+      LOGICAL                         , INTENT(in   ) ::   before
+      !!
+      REAL(wp) ::   zrhox   ! local scalar
       !!-----------------------------------------------------------------------
       !
       IF( before ) THEN  ! parent grid
          ptab(:,:) = e1v(i1:i2,j1:j2) * v_ice_b(i1:i2,j1:j2)
-         WHERE( vmask(i1:i2,j1:j2,1) == 0. )  ptab(:,:) = -9999.
+         WHERE( vmask(i1:i2,j1:j2,1) == 0. )   ptab(i1:i2,j1:j2) = Agrif_SpecialValue
       ELSE               ! child grid
          zrhox = Agrif_Rhox()
-         v_ice(i1:i2,j1:j2) = ptab(:,:) / ( e1v(i1:i2,j1:j2) * zrhox ) * vmask(i1:i2,j1:j2,1)
+         v_ice(i1:i2,j1:j2) = ptab(i1:i2,j1:j2) / ( e1v(i1:i2,j1:j2) * zrhox ) * vmask(i1:i2,j1:j2,1)
       ENDIF
       !
@@ -141,176 +138,209 @@
       !!
       !! i1 i2 j1 j2 are the index of the boundaries parent(when before) and child (when after)
-      !! To solve issues when parent grid is "land" masked but not all the corresponding child grid points,
-      !! put -9999 WHERE the parent grid is masked. The child solution will be found in the 9(?) points around
-      !!-----------------------------------------------------------------------
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab
-      INTEGER , INTENT(in) :: i1, i2, j1, j2, k1, k2
-      LOGICAL , INTENT(in) :: before
-      INTEGER , INTENT(in) :: nb, ndir
-      !!
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: ztab
+      !! To solve issues when parent grid is "land" masked but not all the corresponding child 
+      !! grid points, put Agrif_SpecialValue WHERE the parent grid is masked. 
+      !! The child solution will be found in the 9(?) points around
+      !!-----------------------------------------------------------------------
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) ::   ptab
+      INTEGER                               , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
+      LOGICAL                               , INTENT(in   ) ::   before
+      INTEGER                               , INTENT(in   ) ::   nb, ndir
+      !!
       INTEGER  ::   ji, jj, jk, jl, jm
       INTEGER  ::   imin, imax, jmin, jmax
+      LOGICAL  ::   western_side, eastern_side, northern_side, southern_side
       REAL(wp) ::   zrhox, z1, z2, z3, z4, z5, z6, z7
-      LOGICAL  ::   western_side, eastern_side, northern_side, southern_side
-
-      !!-----------------------------------------------------------------------
-      ! tracers are not multiplied by grid cell here => before: * e12t ; after: * r1_e12t / rhox / rhoy
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ztab
+      !!-----------------------------------------------------------------------
+      ! tracers are not multiplied by grid cell here => before: * e1e2t ; after: * r1_e1e2t / rhox / rhoy
       ! and it is ok since we conserve tracers (same as in the ocean).
-      ALLOCATE( ztab(SIZE(a_i_b,1),SIZE(a_i_b,2),SIZE(ptab,3)) )
+      ALLOCATE( ztab(SIZE(a_i,1),SIZE(a_i,2),SIZE(ptab,3)) )
      
       IF( before ) THEN  ! parent grid
          jm = 1
          DO jl = 1, jpl
-            ptab(i1:i2,j1:j2,jm) = a_i_b  (i1:i2,j1:j2,jl) ; jm = jm + 1
-            ptab(i1:i2,j1:j2,jm) = v_i_b  (i1:i2,j1:j2,jl) ; jm = jm + 1
-            ptab(i1:i2,j1:j2,jm) = v_s_b  (i1:i2,j1:j2,jl) ; jm = jm + 1
-            ptab(i1:i2,j1:j2,jm) = smv_i_b(i1:i2,j1:j2,jl) ; jm = jm + 1
-            ptab(i1:i2,j1:j2,jm) = oa_i_b (i1:i2,j1:j2,jl) ; jm = jm + 1
+            ptab(i1:i2,j1:j2,jm  ) = a_i_b (i1:i2,j1:j2,jl)
+            ptab(i1:i2,j1:j2,jm+1) = v_i_b (i1:i2,j1:j2,jl)
+            ptab(i1:i2,j1:j2,jm+2) = v_s_b (i1:i2,j1:j2,jl)
+            ptab(i1:i2,j1:j2,jm+3) = sv_i_b(i1:i2,j1:j2,jl)
+            ptab(i1:i2,j1:j2,jm+4) = oa_i_b(i1:i2,j1:j2,jl)
+            jm = jm + 5
             DO jk = 1, nlay_s
-               ptab(i1:i2,j1:j2,jm) = e_s_b(i1:i2,j1:j2,jk,jl) ; jm = jm + 1
-            ENDDO
+               ptab(i1:i2,j1:j2,jm) = e_s_b(i1:i2,j1:j2,jk,jl)   ;   jm = jm + 1
+            END DO
             DO jk = 1, nlay_i
-               ptab(i1:i2,j1:j2,jm) = e_i_b(i1:i2,j1:j2,jk,jl) ; jm = jm + 1
-            ENDDO
-         ENDDO
+               ptab(i1:i2,j1:j2,jm) = e_i_b(i1:i2,j1:j2,jk,jl)   ;   jm = jm + 1
+            END DO
+         END DO
          
          DO jk = k1, k2
-            WHERE( tmask(i1:i2,j1:j2,1) == 0. )  ptab(i1:i2,j1:j2,jk) = -9999.
-         ENDDO
+            WHERE( tmask(i1:i2,j1:j2,1) == 0._wp )   ptab(i1:i2,j1:j2,jk) = Agrif_SpecialValue
+         END DO
+         !
+      ELSE               ! child grid
+         !
+         IF( nbghostcells > 1 ) THEN   ! ==> The easiest interpolation is used
+            !
+            jm = 1
+            DO jl = 1, jpl
+               !
+               DO jj = j1, j2
+                  DO ji = i1, i2
+                     a_i (ji,jj,jl) = ptab(ji,jj,jm  ) * tmask(ji,jj,1)
+                     v_i (ji,jj,jl) = ptab(ji,jj,jm+1) * tmask(ji,jj,1)
+                     v_s (ji,jj,jl) = ptab(ji,jj,jm+2) * tmask(ji,jj,1)
+                     sv_i(ji,jj,jl) = ptab(ji,jj,jm+3) * tmask(ji,jj,1)
+                     oa_i(ji,jj,jl) = ptab(ji,jj,jm+4) * tmask(ji,jj,1)
+                  END DO
+               END DO
+               jm = jm + 5
+               !
+               DO jk = 1, nlay_s
+                  e_s(i1:i2,j1:j2,jk,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1)
+                  jm = jm + 1
+               END DO
+               !
+               DO jk = 1, nlay_i
+                  e_i(i1:i2,j1:j2,jk,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1)
+                  jm = jm + 1
+               END DO
+               !
+            END DO
+            !
+         ELSE                          ! ==> complex interpolation (only one ghost cell available)
+            !! Use a more complex interpolation since we mix solutions over a couple of grid points
+            !! it is advised to use it for fields modified by high order schemes (e.g. advection UM5...)
+            !! clem: for some reason (I don't know why), the following lines do not work 
+            !!       with mpp (or in realistic configurations?). It makes the model crash
+            !        I think there is an issue with Agrif_SpecialValue here (not taken into account properly)
+            ! record ztab
+            jm = 1
+            DO jl = 1, jpl
+               ztab(:,:,jm  ) = a_i  (:,:,jl)
+               ztab(:,:,jm+1) = v_i  (:,:,jl)
+               ztab(:,:,jm+2) = v_s  (:,:,jl)
+               ztab(:,:,jm+3) = sv_i(:,:,jl)
+               ztab(:,:,jm+4) = oa_i(:,:,jl)
+               jm = jm + 5
+               DO jk = 1, nlay_s
+                  ztab(:,:,jm) = e_s(:,:,jk,jl)
+                  jm = jm + 1
+               END DO
+               DO jk = 1, nlay_i
+                  ztab(:,:,jm) = e_i(:,:,jk,jl)
+                  jm = jm + 1
+               END DO
+               !
+            END DO
+            !
+            ! borders of the domain
+            western_side  = (nb == 1).AND.(ndir == 1)  ;  eastern_side  = (nb == 1).AND.(ndir == 2)
+            southern_side = (nb == 2).AND.(ndir == 1)  ;  northern_side = (nb == 2).AND.(ndir == 2)
+            !
+            ! spatial smoothing
+            zrhox = Agrif_Rhox()
+            z1 =      ( zrhox - 1. ) * 0.5 
+            z3 =      ( zrhox - 1. ) / ( zrhox + 1. )
+            z6 = 2. * ( zrhox - 1. ) / ( zrhox + 1. )
+            z7 =    - ( zrhox - 1. ) / ( zrhox + 3. )
+            z2 = 1. - z1
+            z4 = 1. - z3
+            z5 = 1. - z6 - z7
+            !
+            ! Remove corners
+            imin = i1  ;  imax = i2  ;  jmin = j1  ;  jmax = j2
+            IF( (nbondj == -1) .OR. (nbondj == 2) )   jmin = 3
+            IF( (nbondj == +1) .OR. (nbondj == 2) )   jmax = nlcj-2
+            IF( (nbondi == -1) .OR. (nbondi == 2) )   imin = 3
+            IF( (nbondi == +1) .OR. (nbondi == 2) )   imax = nlci-2
+
+            ! smoothed fields
+            IF( eastern_side ) THEN
+               ztab(nlci,j1:j2,:) = z1 * ptab(nlci,j1:j2,:) + z2 * ptab(nlci-1,j1:j2,:)
+               DO jj = jmin, jmax
+                  rswitch = 0.
+                  IF( u_ice(nlci-2,jj) > 0._wp ) rswitch = 1.
+                  ztab(nlci-1,jj,:) = ( 1. - umask(nlci-2,jj,1) ) * ztab(nlci,jj,:)  &
+                     &                +      umask(nlci-2,jj,1)   *  &
+                     &                ( ( 1. - rswitch ) * ( z4 * ztab(nlci,jj,:)   + z3 * ztab(nlci-2,jj,:) )  &
+                     &                  +      rswitch   * ( z6 * ztab(nlci-2,jj,:) + z5 * ztab(nlci,jj,:) + z7 * ztab(nlci-3,jj,:) ) )
+                  ztab(nlci-1,jj,:) = ztab(nlci-1,jj,:) * tmask(nlci-1,jj,1)
+               END DO
+            ENDIF
+            ! 
+            IF( northern_side ) THEN
+               ztab(i1:i2,nlcj,:) = z1 * ptab(i1:i2,nlcj,:) + z2 * ptab(i1:i2,nlcj-1,:)
+               DO ji = imin, imax
+                  rswitch = 0.
+                  IF( v_ice(ji,nlcj-2) > 0._wp ) rswitch = 1.
+                  ztab(ji,nlcj-1,:) = ( 1. - vmask(ji,nlcj-2,1) ) * ztab(ji,nlcj,:)  &
+                     &                +      vmask(ji,nlcj-2,1)   *  &
+                     &                ( ( 1. - rswitch ) * ( z4 * ztab(ji,nlcj,:)   + z3 * ztab(ji,nlcj-2,:) ) &
+                     &                  +      rswitch   * ( z6 * ztab(ji,nlcj-2,:) + z5 * ztab(ji,nlcj,:) + z7 * ztab(ji,nlcj-3,:) ) )
+                  ztab(ji,nlcj-1,:) = ztab(ji,nlcj-1,:) * tmask(ji,nlcj-1,1)
+               END DO
+            END IF
+            !
+            IF( western_side) THEN
+               ztab(1,j1:j2,:) = z1 * ptab(1,j1:j2,:) + z2 * ptab(2,j1:j2,:)
+               DO jj = jmin, jmax
+                  rswitch = 0.
+                  IF( u_ice(2,jj) < 0._wp ) rswitch = 1.
+                  ztab(2,jj,:) = ( 1. - umask(2,jj,1) ) * ztab(1,jj,:)  &
+                     &           +      umask(2,jj,1)   *   &
+                     &           ( ( 1. - rswitch ) * ( z4 * ztab(1,jj,:) + z3 * ztab(3,jj,:) ) &
+                     &             +      rswitch   * ( z6 * ztab(3,jj,:) + z5 * ztab(1,jj,:) + z7 * ztab(4,jj,:) ) )
+                  ztab(2,jj,:) = ztab(2,jj,:) * tmask(2,jj,1)
+               END DO
+            ENDIF
+            !
+            IF( southern_side ) THEN
+               ztab(i1:i2,1,:) = z1 * ptab(i1:i2,1,:) + z2 * ptab(i1:i2,2,:)
+               DO ji = imin, imax
+                  rswitch = 0.
+                  IF( v_ice(ji,2) < 0._wp ) rswitch = 1.
+                  ztab(ji,2,:) = ( 1. - vmask(ji,2,1) ) * ztab(ji,1,:)  &
+                     &           +      vmask(ji,2,1)   *  &
+                     &           ( ( 1. - rswitch ) * ( z4 * ztab(ji,1,:) + z3 * ztab(ji,3,:) ) &
+                     &             +      rswitch   * ( z6 * ztab(ji,3,:) + z5 * ztab(ji,1,:) + z7 * ztab(ji,4,:) ) )
+                  ztab(ji,2,:) = ztab(ji,2,:) * tmask(ji,2,1)
+               END DO
+            END IF
+            !
+            ! Treatment of corners
+            IF( (eastern_side) .AND. ((nbondj == -1).OR.(nbondj == 2)) )  ztab(nlci-1,2,:)      = ptab(nlci-1,2,:)      ! East south
+            IF( (eastern_side) .AND. ((nbondj ==  1).OR.(nbondj == 2)) )  ztab(nlci-1,nlcj-1,:) = ptab(nlci-1,nlcj-1,:) ! East north
+            IF( (western_side) .AND. ((nbondj == -1).OR.(nbondj == 2)) )  ztab(2,2,:)           = ptab(2,2,:)           ! West south
+            IF( (western_side) .AND. ((nbondj ==  1).OR.(nbondj == 2)) )  ztab(2,nlcj-1,:)      = ptab(2,nlcj-1,:)      ! West north
+            
+            ! retrieve ice tracers
+            jm = 1
+            DO jl = 1, jpl
+               !
+               DO jj = j1, j2
+                  DO ji = i1, i2
+                     a_i (ji,jj,jl) = ztab(ji,jj,jm  ) * tmask(ji,jj,1)
+                     v_i (ji,jj,jl) = ztab(ji,jj,jm+1) * tmask(ji,jj,1)
+                     v_s (ji,jj,jl) = ztab(ji,jj,jm+2) * tmask(ji,jj,1)
+                     sv_i(ji,jj,jl) = ztab(ji,jj,jm+3) * tmask(ji,jj,1)
+                     oa_i (ji,jj,jl) = ztab(ji,jj,jm+4) * tmask(ji,jj,1)
+                  END DO
+               END DO
+               jm = jm + 5
+               !
+               DO jk = 1, nlay_s
+                  e_s(i1:i2,j1:j2,jk,jl) = ztab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1)
+                  jm = jm + 1
+               END DO
+               !
+               DO jk = 1, nlay_i
+                  e_i(i1:i2,j1:j2,jk,jl) = ztab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1)
+                  jm = jm + 1
+               END DO
+               !
+            END DO
+          
+         ENDIF  ! nbghostcells=1
          
-      ELSE               ! child grid
-!! ==> The easiest interpolation is the following commented lines
-         jm = 1
-         DO jl = 1, jpl
-            a_i  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            v_i  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            v_s  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            smv_i(i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            oa_i (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            DO jk = 1, nlay_s
-               e_s(i1:i2,j1:j2,jk,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            ENDDO
-            DO jk = 1, nlay_i
-               e_i(i1:i2,j1:j2,jk,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            ENDDO
-         ENDDO
-
-!! ==> this is a more complex interpolation since we mix solutions over a couple of grid points
-!!     it is advised to use it for fields modified by high order schemes (e.g. advection UM5...)
-!!        clem: for some reason (I don't know why), the following lines do not work 
-!!              with mpp (or in realistic configurations?). It makes the model crash
-!         ! record ztab
-!         jm = 1
-!         DO jl = 1, jpl
-!            ztab(:,:,jm) = a_i  (:,:,jl) ; jm = jm + 1
-!            ztab(:,:,jm) = v_i  (:,:,jl) ; jm = jm + 1
-!            ztab(:,:,jm) = v_s  (:,:,jl) ; jm = jm + 1
-!            ztab(:,:,jm) = smv_i(:,:,jl) ; jm = jm + 1
-!            ztab(:,:,jm) = oa_i (:,:,jl) ; jm = jm + 1
-!            DO jk = 1, nlay_s
-!               ztab(:,:,jm) = e_s(:,:,jk,jl) ; jm = jm + 1
-!            ENDDO
-!            DO jk = 1, nlay_i
-!               ztab(:,:,jm) = e_i(:,:,jk,jl) ; jm = jm + 1
-!            ENDDO
-!         ENDDO
-!         !
-!         ! borders of the domain
-!         western_side  = (nb == 1).AND.(ndir == 1)  ;  eastern_side  = (nb == 1).AND.(ndir == 2)
-!         southern_side = (nb == 2).AND.(ndir == 1)  ;  northern_side = (nb == 2).AND.(ndir == 2)
-!         !
-!         ! spatial smoothing
-!         zrhox = Agrif_Rhox()
-!         z1 =      ( zrhox - 1. ) * 0.5 
-!         z3 =      ( zrhox - 1. ) / ( zrhox + 1. )
-!         z6 = 2. * ( zrhox - 1. ) / ( zrhox + 1. )
-!         z7 =    - ( zrhox - 1. ) / ( zrhox + 3. )
-!         z2 = 1. - z1
-!         z4 = 1. - z3
-!         z5 = 1. - z6 - z7
-!         !
-!         ! Remove corners
-!         imin = i1  ;  imax = i2  ;  jmin = j1  ;  jmax = j2
-!         IF( (nbondj == -1) .OR. (nbondj == 2) )   jmin = 3
-!         IF( (nbondj == +1) .OR. (nbondj == 2) )   jmax = nlcj-2
-!         IF( (nbondi == -1) .OR. (nbondi == 2) )   imin = 3
-!         IF( (nbondi == +1) .OR. (nbondi == 2) )   imax = nlci-2
-!
-!         ! smoothed fields
-!         IF( eastern_side ) THEN
-!            ztab(nlci,j1:j2,:) = z1 * ptab(nlci,j1:j2,:) + z2 * ptab(nlci-1,j1:j2,:)
-!            DO jj = jmin, jmax
-!               rswitch = 0.
-!               IF( u_ice(nlci-2,jj) > 0._wp ) rswitch = 1.
-!               ztab(nlci-1,jj,:) = ( 1. - umask(nlci-2,jj,1) ) * ztab(nlci,jj,:)  &
-!                  &                +      umask(nlci-2,jj,1)   *  &
-!                  &                ( ( 1. - rswitch ) * ( z4 * ztab(nlci,jj,:)   + z3 * ztab(nlci-2,jj,:) )  &
-!                  &                  +      rswitch   * ( z6 * ztab(nlci-2,jj,:) + z5 * ztab(nlci,jj,:) + z7 * ztab(nlci-3,jj,:) ) )
-!               ztab(nlci-1,jj,:) = ztab(nlci-1,jj,:) * tmask(nlci-1,jj,1)
-!            END DO
-!         ENDIF
-!         ! 
-!         IF( northern_side ) THEN
-!            ztab(i1:i2,nlcj,:) = z1 * ptab(i1:i2,nlcj,:) + z2 * ptab(i1:i2,nlcj-1,:)
-!            DO ji = imin, imax
-!               rswitch = 0.
-!               IF( v_ice(ji,nlcj-2) > 0._wp ) rswitch = 1.
-!               ztab(ji,nlcj-1,:) = ( 1. - vmask(ji,nlcj-2,1) ) * ztab(ji,nlcj,:)  &
-!                  &                +      vmask(ji,nlcj-2,1)   *  &
-!                  &                ( ( 1. - rswitch ) * ( z4 * ztab(ji,nlcj,:)   + z3 * ztab(ji,nlcj-2,:) ) &
-!                  &                  +      rswitch   * ( z6 * ztab(ji,nlcj-2,:) + z5 * ztab(ji,nlcj,:) + z7 * ztab(ji,nlcj-3,:) ) )
-!               ztab(ji,nlcj-1,:) = ztab(ji,nlcj-1,:) * tmask(ji,nlcj-1,1)
-!            END DO
-!         END IF
-!         !
-!         IF( western_side) THEN
-!            ztab(1,j1:j2,:) = z1 * ptab(1,j1:j2,:) + z2 * ptab(2,j1:j2,:)
-!            DO jj = jmin, jmax
-!               rswitch = 0.
-!               IF( u_ice(2,jj) < 0._wp ) rswitch = 1.
-!               ztab(2,jj,:) = ( 1. - umask(2,jj,1) ) * ztab(1,jj,:)  &
-!                  &           +      umask(2,jj,1)   *   &
-!                  &           ( ( 1. - rswitch ) * ( z4 * ztab(1,jj,:) + z3 * ztab(3,jj,:) ) &
-!                  &             +      rswitch   * ( z6 * ztab(3,jj,:) + z5 * ztab(1,jj,:) + z7 * ztab(4,jj,:) ) )
-!               ztab(2,jj,:) = ztab(2,jj,:) * tmask(2,jj,1)
-!            END DO
-!         ENDIF
-!         !
-!         IF( southern_side ) THEN
-!            ztab(i1:i2,1,:) = z1 * ptab(i1:i2,1,:) + z2 * ptab(i1:i2,2,:)
-!            DO ji = imin, imax
-!               rswitch = 0.
-!               IF( v_ice(ji,2) < 0._wp ) rswitch = 1.
-!               ztab(ji,2,:) = ( 1. - vmask(ji,2,1) ) * ztab(ji,1,:)  &
-!                  &           +      vmask(ji,2,1)   *  &
-!                  &           ( ( 1. - rswitch ) * ( z4 * ztab(ji,1,:) + z3 * ztab(ji,3,:) ) &
-!                  &             +      rswitch   * ( z6 * ztab(ji,3,:) + z5 * ztab(ji,1,:) + z7 * ztab(ji,4,:) ) )
-!               ztab(ji,2,:) = ztab(ji,2,:) * tmask(ji,2,1)
-!            END DO
-!         END IF
-!         !
-!         ! Treatment of corners
-!         IF( (eastern_side) .AND. ((nbondj == -1).OR.(nbondj == 2)) )  ztab(nlci-1,2,:)      = ptab(nlci-1,2,:)      ! East south
-!         IF( (eastern_side) .AND. ((nbondj ==  1).OR.(nbondj == 2)) )  ztab(nlci-1,nlcj-1,:) = ptab(nlci-1,nlcj-1,:) ! East north
-!         IF( (western_side) .AND. ((nbondj == -1).OR.(nbondj == 2)) )  ztab(2,2,:)           = ptab(2,2,:)           ! West south
-!         IF( (western_side) .AND. ((nbondj ==  1).OR.(nbondj == 2)) )  ztab(2,nlcj-1,:)      = ptab(2,nlcj-1,:)      ! West north
-!
-!         ! retrieve ice tracers
-!         jm = 1
-!         DO jl = 1, jpl
-!            a_i  (i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) ; jm = jm + 1
-!            v_i  (i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) ; jm = jm + 1
-!            v_s  (i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) ; jm = jm + 1
-!            smv_i(i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) ; jm = jm + 1
-!            oa_i (i1:i2,j1:j2,jl) = ztab(i1:i2,j1:j2,jm) ; jm = jm + 1
-!            DO jk = 1, nlay_s
-!               e_s(i1:i2,j1:j2,jk,jl) = ztab(i1:i2,j1:j2,jm) ; jm = jm + 1
-!            ENDDO
-!            DO jk = 1, nlay_i
-!               e_i(i1:i2,j1:j2,jk,jl) = ztab(i1:i2,j1:j2,jm) ; jm = jm + 1
-!            ENDDO
-!         ENDDO
-       
          ! integrated values
          vt_i (i1:i2,j1:j2) = SUM( v_i(i1:i2,j1:j2,:), dim=3 )
@@ -319,5 +349,5 @@
          et_s(i1:i2,j1:j2)  = SUM( SUM( e_s(i1:i2,j1:j2,:,:), dim=4 ), dim=3 )
          et_i(i1:i2,j1:j2)  = SUM( SUM( e_i(i1:i2,j1:j2,:,:), dim=4 ), dim=3 )
-
+         !
       ENDIF
       
@@ -327,11 +357,13 @@
 
 #else
+   !!----------------------------------------------------------------------
+   !!   Empty module                                             no sea-ice
+   !!----------------------------------------------------------------------
 CONTAINS
    SUBROUTINE agrif_lim3_interp_empty
-      !!---------------------------------------------
-      !!   *** ROUTINE agrif_lim3_interp_empty ***
-      !!---------------------------------------------
       WRITE(*,*)  'agrif_lim3_interp : You should not have seen this print! error?'
    END SUBROUTINE agrif_lim3_interp_empty
 #endif
+
+   !!======================================================================
 END MODULE agrif_lim3_interp
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_lim3_update.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_lim3_update.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_lim3_update.F90	(revision 9019)
@@ -31,12 +31,11 @@
    PRIVATE
 
-   PUBLIC agrif_update_lim3
-
-   !!----------------------------------------------------------------------
-   !! NEMO/NST 3.6 , LOCEAN-IPSL (2016)
+   PUBLIC   agrif_update_lim3   ! called by agrif_user.F90
+
+   !!----------------------------------------------------------------------
+   !! NEMO/NST 4.0 , LOCEAN-IPSL (2017)
    !! $Id: agrif_lim3_update.F90 6204 2016-01-04 13:47:06Z cetlod $
    !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -49,5 +48,4 @@
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) :: kt
-      !!
       !!----------------------------------------------------------------------
       !
@@ -56,6 +54,8 @@
       IF( ( MOD( (kt-nit000)/nn_fsbc + 1, Agrif_irhot() * Agrif_Parent(nn_fsbc) / nn_fsbc ) /=0 ) .AND. (kt /= 0) ) RETURN ! do not update if nb of child time steps differ from time refinement
                                                                                                                            ! i.e. update only at the parent time step
+      IF( nn_ice == 0 ) RETURN   ! do not update if child domain does not have ice
+      !
+      Agrif_SpecialValueFineGrid    = -9999.
       Agrif_UseSpecialValueInUpdate = .TRUE.
-      Agrif_SpecialValueFineGrid = -9999.
 # if defined TWO_WAY
       IF( MOD(nbcline,nbclineupdate) == 0) THEN ! update the whole basin at each nbclineupdate (=nn_cln_update) baroclinic parent time steps
@@ -70,4 +70,5 @@
       ENDIF
 # endif
+      Agrif_SpecialValueFineGrid    = 0.
       Agrif_UseSpecialValueInUpdate = .FALSE.
       !
@@ -75,7 +76,4 @@
 
 
-   !!------------------
-   !! Local subroutines
-   !!------------------
    SUBROUTINE update_tra_ice( ptab, i1, i2, j1, j2, k1, k2, before )
       !!-----------------------------------------------------------------------
@@ -84,9 +82,9 @@
       !!              the properties per mass on the coarse grid
       !!-----------------------------------------------------------------------
-      INTEGER , INTENT(in) :: i1, i2, j1, j2, k1, k2
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab
-      LOGICAL , INTENT(in) :: before
-      !!
-      INTEGER  :: jk, jl, jm
+      INTEGER                               , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) ::   ptab
+      LOGICAL                               , INTENT(in   ) ::   before
+      !!
+      INTEGER  :: ji, jj, jk, jl, jm
       !!-----------------------------------------------------------------------
       ! it is ok not to multiply by e1*e2 since we conserve tracers here (same as in the ocean).
@@ -94,41 +92,60 @@
          jm = 1
          DO jl = 1, jpl
-            ptab(:,:,jm) = a_i  (i1:i2,j1:j2,jl) ; jm = jm + 1
-            ptab(:,:,jm) = v_i  (i1:i2,j1:j2,jl) ; jm = jm + 1
-            ptab(:,:,jm) = v_s  (i1:i2,j1:j2,jl) ; jm = jm + 1
-            ptab(:,:,jm) = smv_i(i1:i2,j1:j2,jl) ; jm = jm + 1
-            ptab(:,:,jm) = oa_i (i1:i2,j1:j2,jl) ; jm = jm + 1
+            ptab(i1:i2,j1:j2,jm  ) = a_i (i1:i2,j1:j2,jl)
+            ptab(i1:i2,j1:j2,jm+1) = v_i (i1:i2,j1:j2,jl)
+            ptab(i1:i2,j1:j2,jm+2) = v_s (i1:i2,j1:j2,jl)
+            ptab(i1:i2,j1:j2,jm+3) = sv_i(i1:i2,j1:j2,jl)
+            ptab(i1:i2,j1:j2,jm+4) = oa_i (i1:i2,j1:j2,jl)
+            jm = jm + 5
             DO jk = 1, nlay_s
-               ptab(:,:,jm) = e_s(i1:i2,j1:j2,jk,jl) ; jm = jm + 1
-            ENDDO
+               ptab(i1:i2,j1:j2,jm) = e_s(i1:i2,j1:j2,jk,jl)   ;   jm = jm + 1
+            END DO
             DO jk = 1, nlay_i
-               ptab(:,:,jm) = e_i(i1:i2,j1:j2,jk,jl) ; jm = jm + 1
-            ENDDO
-         ENDDO
-
+               ptab(i1:i2,j1:j2,jm) = e_i(i1:i2,j1:j2,jk,jl)   ;   jm = jm + 1
+            END DO
+         END DO
+         !
          DO jk = k1, k2
-            WHERE( tmask(i1:i2,j1:j2,1) == 0. )  ptab(:,:,jk) = -9999.
-         ENDDO
-                  
+            WHERE( tmask(i1:i2,j1:j2,1) == 0. )   ptab(i1:i2,j1:j2,jk) = Agrif_SpecialValueFineGrid 
+         END DO
+         !
       ELSE
+         !
          jm = 1
          DO jl = 1, jpl
-            a_i  (i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            v_i  (i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            v_s  (i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            smv_i(i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            oa_i (i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            !
+            DO jj = j1, j2
+               DO ji = i1, i2
+                  IF( ptab(ji,jj,jm) /= Agrif_SpecialValueFineGrid ) THEN
+                     a_i (ji,jj,jl) = ptab(ji,jj,jm  ) * tmask(ji,jj,1)
+                     v_i (ji,jj,jl) = ptab(ji,jj,jm+1) * tmask(ji,jj,1)
+                     v_s (ji,jj,jl) = ptab(ji,jj,jm+2) * tmask(ji,jj,1)
+                     sv_i(ji,jj,jl) = ptab(ji,jj,jm+3) * tmask(ji,jj,1)
+                     oa_i(ji,jj,jl) = ptab(ji,jj,jm+4) * tmask(ji,jj,1)
+                  ENDIF
+               END DO
+            END DO
+            jm = jm + 5
+            !
             DO jk = 1, nlay_s
-               e_s(i1:i2,j1:j2,jk,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            ENDDO
+               WHERE( ptab(i1:i2,j1:j2,jm) /= Agrif_SpecialValueFineGrid )
+                  e_s(i1:i2,j1:j2,jk,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1)
+               ENDWHERE
+               jm = jm + 1
+            END DO
+            !
             DO jk = 1, nlay_i
-               e_i(i1:i2,j1:j2,jk,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            ENDDO
-         ENDDO
-
+               WHERE( ptab(i1:i2,j1:j2,jm) /= Agrif_SpecialValueFineGrid )
+                  e_i(i1:i2,j1:j2,jk,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1)
+               ENDWHERE
+               jm = jm + 1
+            END DO
+            !
+         END DO
+         !
          ! integrated values
-         vt_i (i1:i2,j1:j2) = SUM( v_i(i1:i2,j1:j2,:), dim=3 )
-         vt_s (i1:i2,j1:j2) = SUM( v_s(i1:i2,j1:j2,:), dim=3 )
-         at_i (i1:i2,j1:j2) = SUM( a_i(i1:i2,j1:j2,:), dim=3 )
+         vt_i (i1:i2,j1:j2) = SUM(      v_i(i1:i2,j1:j2,:)           , dim=3 )
+         vt_s (i1:i2,j1:j2) = SUM(      v_s(i1:i2,j1:j2,:)           , dim=3 )
+         at_i (i1:i2,j1:j2) = SUM(      a_i(i1:i2,j1:j2,:)           , dim=3 )
          et_s(i1:i2,j1:j2)  = SUM( SUM( e_s(i1:i2,j1:j2,:,:), dim=4 ), dim=3 )
          et_i(i1:i2,j1:j2)  = SUM( SUM( e_i(i1:i2,j1:j2,:,:), dim=4 ), dim=3 )
@@ -144,9 +161,9 @@
       !! ** Method  : Update the fluxes and recover the properties (C-grid)
       !!-----------------------------------------------------------------------
-      INTEGER , INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: ptab
-      LOGICAL , INTENT(in) :: before
-      !!
-      REAL(wp) :: zrhoy
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
+      LOGICAL                         , INTENT(in   ) ::   before
+      !!
+      REAL(wp) ::   zrhoy   ! local scalar
       !!-----------------------------------------------------------------------
       !
@@ -154,7 +171,9 @@
          zrhoy = Agrif_Rhoy()
          ptab(:,:) = e2u(i1:i2,j1:j2) * u_ice(i1:i2,j1:j2) * zrhoy
-         WHERE( umask(i1:i2,j1:j2,1) == 0. )  ptab(:,:) = -9999.
+         WHERE( umask(i1:i2,j1:j2,1) == 0._wp )   ptab(:,:) = Agrif_SpecialValueFineGrid
       ELSE
-         u_ice(i1:i2,j1:j2) = ptab(:,:) / e2u(i1:i2,j1:j2) * umask(i1:i2,j1:j2,1)
+         WHERE( ptab(i1:i2,j1:j2) /= Agrif_SpecialValueFineGrid )
+            u_ice(i1:i2,j1:j2) = ptab(i1:i2,j1:j2) / e2u(i1:i2,j1:j2) * umask(i1:i2,j1:j2,1)
+         ENDWHERE
       ENDIF
       ! 
@@ -167,9 +186,9 @@
       !! ** Method  : Update the fluxes and recover the properties (C-grid)
       !!-----------------------------------------------------------------------
-      INTEGER , INTENT(in) :: i1,i2,j1,j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2),  INTENT(inout) :: ptab
-      LOGICAL , INTENT(in) :: before
-      !!
-      REAL(wp) :: zrhox
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
+      LOGICAL                         , INTENT(in   ) ::   before
+      !!
+      REAL(wp) ::   zrhox   ! local scalar
       !!-----------------------------------------------------------------------
       !
@@ -177,7 +196,9 @@
          zrhox = Agrif_Rhox()
          ptab(:,:) = e1v(i1:i2,j1:j2) * v_ice(i1:i2,j1:j2) * zrhox
-         WHERE( vmask(i1:i2,j1:j2,1) == 0. )  ptab(:,:) = -9999.
+         WHERE( vmask(i1:i2,j1:j2,1) == 0._wp )   ptab(:,:) = Agrif_SpecialValueFineGrid
       ELSE
-         v_ice(i1:i2,j1:j2) = ptab(:,:) / e1v(i1:i2,j1:j2) * vmask(i1:i2,j1:j2,1)
+         WHERE( ptab(i1:i2,j1:j2) /= Agrif_SpecialValueFineGrid )
+            v_ice(i1:i2,j1:j2) = ptab(i1:i2,j1:j2) / e1v(i1:i2,j1:j2) * vmask(i1:i2,j1:j2,1)
+         ENDWHERE
       ENDIF
       !
@@ -185,11 +206,13 @@
 
 #else
+   !!----------------------------------------------------------------------
+   !!   Empty module                                             no sea-ice
+   !!----------------------------------------------------------------------
 CONTAINS
    SUBROUTINE agrif_lim3_update_empty
-      !!---------------------------------------------
-      !!   *** ROUTINE agrif_lim3_update_empty ***
-      !!---------------------------------------------
       WRITE(*,*)  'agrif_lim3_update : You should not have seen this print! error?'
    END SUBROUTINE agrif_lim3_update_empty
 #endif
+
+   !!======================================================================
 END MODULE agrif_lim3_update
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90	(revision 9019)
@@ -44,33 +44,31 @@
    LOGICAL , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: tabspongedone_u
    LOGICAL , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: tabspongedone_v
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,  DIMENSION(:,:) :: fsaht_spu, fsaht_spv !: sponge diffusivities
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE,  DIMENSION(:,:) :: fsahm_spt, fsahm_spf !: sponge viscosities
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: fsaht_spu, fsaht_spv !: sponge diffusivities
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: fsahm_spt, fsahm_spf !: sponge viscosities
 
-   ! Barotropic arrays used to store open boundary data during
-   ! time-splitting loop:
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::  ubdy_w, vbdy_w, hbdy_w
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::  ubdy_e, vbdy_e, hbdy_e
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::  ubdy_n, vbdy_n, hbdy_n
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::  ubdy_s, vbdy_s, hbdy_s
+   ! Barotropic arrays used to store open boundary data during time-splitting loop:
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::  ubdy_w, vbdy_w, hbdy_w
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::  ubdy_e, vbdy_e, hbdy_e
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::  ubdy_n, vbdy_n, hbdy_n
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::  ubdy_s, vbdy_s, hbdy_s
 
-   INTEGER :: tsn_id                                                  ! AGRIF profile for tracers interpolation and update
-   INTEGER :: un_interp_id, vn_interp_id                              ! AGRIF profiles for interpolations
-   INTEGER :: un_update_id, vn_update_id                              ! AGRIF profiles for udpates
-   INTEGER :: tsn_sponge_id, un_sponge_id, vn_sponge_id               ! AGRIF profiles for sponge layers
+
+   INTEGER, PUBLIC :: tsn_id                                                  ! AGRIF profile for tracers interpolation and update
+   INTEGER, PUBLIC :: un_interp_id, vn_interp_id                              ! AGRIF profiles for interpolations
+   INTEGER, PUBLIC :: un_update_id, vn_update_id                              ! AGRIF profiles for udpates
+   INTEGER, PUBLIC :: tsn_sponge_id, un_sponge_id, vn_sponge_id               ! AGRIF profiles for sponge layers
 # if defined key_top
-   INTEGER :: trn_id, trn_sponge_id
+   INTEGER, PUBLIC :: trn_id, trn_sponge_id
 # endif  
-   INTEGER :: unb_id, vnb_id, ub2b_interp_id, vb2b_interp_id
-   INTEGER :: ub2b_update_id, vb2b_update_id
-   INTEGER :: e3t_id, e1u_id, e2v_id, sshn_id
-   INTEGER :: scales_t_id
-# if defined key_zdftke
-   INTEGER :: avt_id, avm_id, en_id
-# endif  
-   INTEGER :: umsk_id, vmsk_id
-   INTEGER :: kindic_agr
-
+   INTEGER, PUBLIC :: unb_id, vnb_id, ub2b_interp_id, vb2b_interp_id
+   INTEGER, PUBLIC :: ub2b_update_id, vb2b_update_id
+   INTEGER, PUBLIC :: e3t_id, e1u_id, e2v_id, sshn_id
+   INTEGER, PUBLIC :: scales_t_id
+   INTEGER, PUBLIC :: avt_id, avm_id, en_id                ! TKE related identificators
+   INTEGER, PUBLIC :: umsk_id, vmsk_id
+   INTEGER, PUBLIC :: kindic_agr
+   
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.3.1 , NEMO Consortium (2011)
+   !! NEMO/NST 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 9019)
@@ -2,8 +2,7 @@
    !!======================================================================
    !!                   ***  MODULE  agrif_opa_interp  ***
-   !! AGRIF: interpolation package
+   !! AGRIF: interpolation package for the ocean dynamics (OPA)
    !!======================================================================
-   !! History :  2.0  !  2002-06  (XXX)  Original cade
-   !!             -   !  2005-11  (XXX) 
+   !! History :  2.0  !  2002-06  (L. Debreu)  Original cade
    !!            3.2  !  2009-04  (R. Benshila) 
    !!            3.6  !  2014-09  (R. Benshila) 
@@ -15,4 +14,9 @@
    !!   Agrif_tra     :
    !!   Agrif_dyn     : 
+   !!   Agrif_ssh     :
+   !!   Agrif_dyn_ts  :
+   !!   Agrif_dta_ts  :
+   !!   Agrif_ssh_ts  :
+   !!   Agrif_avm     : 
    !!   interpu       :
    !!   interpv       :
@@ -28,5 +32,4 @@
    USE agrif_opa_sponge
    USE lib_mpp
-   USE wrk_nemo
  
    IMPLICIT NONE
@@ -34,11 +37,9 @@
 
    PUBLIC   Agrif_tra, Agrif_dyn, Agrif_ssh, Agrif_dyn_ts, Agrif_ssh_ts, Agrif_dta_ts
-   PUBLIC   interpun, interpvn
-   PUBLIC   interptsn,  interpsshn
-   PUBLIC   interpunb, interpvnb, interpub2b, interpvb2b
+   PUBLIC   interpun , interpvn
+   PUBLIC   interptsn, interpsshn
+   PUBLIC   interpunb, interpvnb , interpub2b, interpvb2b
    PUBLIC   interpe3t, interpumsk, interpvmsk
-# if defined key_zdftke
-   PUBLIC   Agrif_tke, interpavm
-# endif
+   PUBLIC   Agrif_avm, interpavm
 
    INTEGER ::   bdy_tinterp = 0
@@ -46,5 +47,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.7 , NEMO Consortium (2015)
+   !! NEMO/NST 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -77,10 +78,8 @@
       INTEGER ::   ji, jj, jk       ! dummy loop indices
       INTEGER ::   j1, j2, i1, i2
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zub, zvb
+      REAL(wp), DIMENSION(jpi,jpj) ::   zub, zvb
       !!----------------------------------------------------------------------  
       !
       IF( Agrif_Root() )   RETURN
-      !
-      CALL wrk_alloc( jpi,jpj,   zub, zvb )
       !
       Agrif_SpecialValue    = 0._wp
@@ -105,276 +104,285 @@
          ! ---------
          IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
-            ua_b(2,:) = 0._wp
+            ua_b(2:1+nbghostcells,:) = 0._wp
             DO jk = 1, jpkm1
                DO jj = 1, jpj
-                  ua_b(2,jj) = ua_b(2,jj) + e3u_a(2,jj,jk) * ua(2,jj,jk)
+                  ua_b(2:1+nbghostcells,jj) = ua_b(2:1+nbghostcells,jj) + e3u_a(2:1+nbghostcells,jj,jk) * ua(2:1+nbghostcells,jj,jk)
                END DO
             END DO
             DO jj = 1, jpj
-               ua_b(2,jj) = ua_b(2,jj) * r1_hu_a(2,jj)            
-            END DO
-         ENDIF
-         !
-         DO jk=1,jpkm1                 ! Smooth
-            DO jj=j1,j2
-               ua(2,jj,jk) = 0.25_wp*(ua(1,jj,jk)+2._wp*ua(2,jj,jk)+ua(3,jj,jk))
-               ua(2,jj,jk) = ua(2,jj,jk) * umask(2,jj,jk)
-            END DO
-         END DO
-         !
-         zub(2,:) = 0._wp              ! Correct transport
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               zub(2,jj) = zub(2,jj) + e3u_a(2,jj,jk) * ua(2,jj,jk)
-            END DO
-         END DO
-         DO jj=1,jpj
-            zub(2,jj) = zub(2,jj) * r1_hu_a(2,jj)
-         END DO
-
-         DO jk=1,jpkm1
-            DO jj=1,jpj
-               ua(2,jj,jk) = (ua(2,jj,jk)+ua_b(2,jj)-zub(2,jj))*umask(2,jj,jk)
-            END DO
-         END DO
-
-         ! Set tangential velocities to time splitting estimate
-         !-----------------------------------------------------
-         IF( ln_dynspg_ts ) THEN
-            zvb(2,:) = 0._wp
+               ua_b(2:1+nbghostcells,jj) = ua_b(2:1+nbghostcells,jj) * r1_hu_a(2:1+nbghostcells,jj)
+            END DO
+         ENDIF
+         !
+         ! Smoothing if only 1 ghostcell
+         ! -----------------------------
+         IF( nbghostcells == 1 ) THEN
+            DO jk=1,jpkm1                 ! Smooth
+               DO jj=j1,j2
+                  ua(2,jj,jk) = 0.25_wp*(ua(1,jj,jk)+2._wp*ua(2,jj,jk)+ua(3,jj,jk))
+                  ua(2,jj,jk) = ua(2,jj,jk) * umask(2,jj,jk)
+               END DO
+            END DO
+            !
+            zub(2,:) = 0._wp              ! Correct transport
             DO jk = 1, jpkm1
                DO jj = 1, jpj
-                  zvb(2,jj) = zvb(2,jj) + e3v_a(2,jj,jk) * va(2,jj,jk)
-               END DO
-            END DO
-            DO jj = 1, jpj
-               zvb(2,jj) = zvb(2,jj) * r1_hv_a(2,jj)
-            END DO
+                  zub(2,jj) = zub(2,jj) + e3u_a(2,jj,jk) * ua(2,jj,jk)
+               END DO
+            END DO
+            DO jj=1,jpj
+               zub(2,jj) = zub(2,jj) * r1_hu_a(2,jj)
+            END DO
+            
             DO jk = 1, jpkm1
                DO jj = 1, jpj
-                  va(2,jj,jk) = (va(2,jj,jk)+va_b(2,jj)-zvb(2,jj)) * vmask(2,jj,jk)
-               END DO
-            END DO
+                  ua(2,jj,jk) = (ua(2,jj,jk)+ua_b(2,jj)-zub(2,jj))*umask(2,jj,jk)
+               END DO
+            END DO
+            
+            IF( ln_dynspg_ts ) THEN       ! Set tangential velocities to time splitting estimate
+               zvb(2,:) = 0._wp
+               DO jk = 1, jpkm1
+                  DO jj = 1, jpj
+                     zvb(2,jj) = zvb(2,jj) + e3v_a(2,jj,jk) * va(2,jj,jk)
+                  END DO
+               END DO
+               DO jj = 1, jpj
+                  zvb(2,jj) = zvb(2,jj) * r1_hv_a(2,jj)
+               END DO
+               DO jk = 1, jpkm1
+                  DO jj = 1, jpj
+                     va(2,jj,jk) = (va(2,jj,jk)+va_b(2,jj)-zvb(2,jj)) * vmask(2,jj,jk)
+                  END DO
+               END DO
+            ENDIF
+            !
          ENDIF
          !
          ! Mask domain edges:
          !-------------------
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               ua(1,jj,jk) = 0._wp
-               va(1,jj,jk) = 0._wp
-            END DO
-         END DO         
-         !
-      ENDIF
-
+!         DO jk = 1, jpkm1
+!            DO jj = 1, jpj
+!               ua(1,jj,jk) = 0._wp
+!               va(1,jj,jk) = 0._wp
+!            END DO
+!         END DO
+         !
+      ENDIF
+
+      ! --- East --- !
       IF( nbondi == 1 .OR. nbondi == 2 ) THEN
 
-         ! Smoothing
-         ! ---------
          IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
-            ua_b(nlci-2,:) = 0._wp
+            ua_b(nlci-nbghostcells-1:nlci-2,:) = 0._wp
             DO jk=1,jpkm1
                DO jj=1,jpj
-                  ua_b(nlci-2,jj) = ua_b(nlci-2,jj) + e3u_a(nlci-2,jj,jk) * ua(nlci-2,jj,jk)
+                  ua_b(nlci-nbghostcells-1:nlci-2,jj) = ua_b(nlci-nbghostcells-1:nlci-2,jj) + e3u_a(nlci-nbghostcells-1:nlci-2,jj,jk)  &
+                     &                                                                         * ua(nlci-nbghostcells-1:nlci-2,jj,jk)
                END DO
             END DO
             DO jj=1,jpj
-               ua_b(nlci-2,jj) = ua_b(nlci-2,jj) * r1_hu_a(nlci-2,jj)            
-            END DO
-         ENDIF
-
-         DO jk = 1, jpkm1              ! Smooth
-            DO jj = j1, j2
-               ua(nlci-2,jj,jk) = 0.25_wp * umask(nlci-2,jj,jk)      &
-                  &             * ( ua(nlci-3,jj,jk) + 2._wp*ua(nlci-2,jj,jk) + ua(nlci-1,jj,jk) )
-            END DO
-         END DO
-
-         zub(nlci-2,:) = 0._wp        ! Correct transport
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               zub(nlci-2,jj) = zub(nlci-2,jj) + e3u_a(nlci-2,jj,jk) * ua(nlci-2,jj,jk)
-            END DO
-         END DO
-         DO jj = 1, jpj
-            zub(nlci-2,jj) = zub(nlci-2,jj) * r1_hu_a(nlci-2,jj)
-         END DO
-
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               ua(nlci-2,jj,jk) = ( ua(nlci-2,jj,jk) + ua_b(nlci-2,jj) - zub(nlci-2,jj) ) * umask(nlci-2,jj,jk)
-            END DO
-         END DO
-         !
-         ! Set tangential velocities to time splitting estimate
-         !-----------------------------------------------------
-         IF( ln_dynspg_ts ) THEN
-            zvb(nlci-1,:) = 0._wp
+               ua_b(nlci-nbghostcells-1:nlci-2,jj) = ua_b(nlci-nbghostcells-1:nlci-2,jj) * r1_hu_a(nlci-nbghostcells-1:nlci-2,jj) 
+            END DO
+         ENDIF
+         !
+         ! Smoothing if only 1 ghostcell
+         ! -----------------------------
+         IF( nbghostcells == 1 ) THEN
+            DO jk = 1, jpkm1              ! Smooth
+               DO jj = j1, j2
+                  ua(nlci-2,jj,jk) = 0.25_wp * umask(nlci-2,jj,jk)      &
+                     &             * ( ua(nlci-3,jj,jk) + 2._wp*ua(nlci-2,jj,jk) + ua(nlci-1,jj,jk) )
+               END DO
+            END DO
+            
+            zub(nlci-2,:) = 0._wp        ! Correct transport
             DO jk = 1, jpkm1
                DO jj = 1, jpj
-                  zvb(nlci-1,jj) = zvb(nlci-1,jj) + e3v_a(nlci-1,jj,jk) * va(nlci-1,jj,jk)
-               END DO
-            END DO
-            DO jj=1,jpj
-               zvb(nlci-1,jj) = zvb(nlci-1,jj) * r1_hv_a(nlci-1,jj)
-            END DO
+                  zub(nlci-2,jj) = zub(nlci-2,jj) + e3u_a(nlci-2,jj,jk) * ua(nlci-2,jj,jk)
+               END DO
+            END DO
+            DO jj = 1, jpj
+               zub(nlci-2,jj) = zub(nlci-2,jj) * r1_hu_a(nlci-2,jj)
+            END DO
+            
             DO jk = 1, jpkm1
                DO jj = 1, jpj
-                  va(nlci-1,jj,jk) = ( va(nlci-1,jj,jk) + va_b(nlci-1,jj) - zvb(nlci-1,jj) ) * vmask(nlci-1,jj,jk)
-               END DO
-            END DO
+                  ua(nlci-2,jj,jk) = ( ua(nlci-2,jj,jk) + ua_b(nlci-2,jj) - zub(nlci-2,jj) ) * umask(nlci-2,jj,jk)
+               END DO
+            END DO
+            !
+            IF( ln_dynspg_ts ) THEN       ! Set tangential velocities to time splitting estimate
+               zvb(nlci-1,:) = 0._wp
+               DO jk = 1, jpkm1
+                  DO jj = 1, jpj
+                     zvb(nlci-1,jj) = zvb(nlci-1,jj) + e3v_a(nlci-1,jj,jk) * va(nlci-1,jj,jk)
+                  END DO
+               END DO
+               DO jj=1,jpj
+                  zvb(nlci-1,jj) = zvb(nlci-1,jj) * r1_hv_a(nlci-1,jj)
+               END DO
+               DO jk = 1, jpkm1
+                  DO jj = 1, jpj
+                     va(nlci-1,jj,jk) = ( va(nlci-1,jj,jk) + va_b(nlci-1,jj) - zvb(nlci-1,jj) ) * vmask(nlci-1,jj,jk)
+                  END DO
+               END DO
+            ENDIF
+            !
          ENDIF
          !
          ! Mask domain edges:
          !-------------------
-         DO jk = 1, jpkm1
-            DO jj = 1, jpj
-               ua(nlci-1,jj,jk) = 0._wp
-               va(nlci  ,jj,jk) = 0._wp
-            END DO
-         END DO 
-         !
-      ENDIF
-
+!         DO jk = 1, jpkm1
+!            DO jj = 1, jpj
+!               ua(nlci-1,jj,jk) = 0._wp
+!               va(nlci  ,jj,jk) = 0._wp
+!            END DO
+!         END DO
+         !
+      ENDIF
+
+      ! --- South --- !
       IF( nbondj == -1 .OR. nbondj == 2 ) THEN
 
-         ! Smoothing
-         ! ---------
          IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
-            va_b(:,2) = 0._wp
+            va_b(:,2:nbghostcells+1) = 0._wp
             DO jk = 1, jpkm1
                DO ji = 1, jpi
-                  va_b(ji,2) = va_b(ji,2) + e3v_a(ji,2,jk) * va(ji,2,jk)
+                  va_b(ji,2:nbghostcells+1) = va_b(ji,2:nbghostcells+1) + e3v_a(ji,2:nbghostcells+1,jk) * va(ji,2:nbghostcells+1,jk)
                END DO
             END DO
             DO ji=1,jpi
-               va_b(ji,2) = va_b(ji,2) * r1_hv_a(ji,2)            
-            END DO
-         ENDIF
-         !
-         DO jk = 1, jpkm1              ! Smooth
-            DO ji = i1, i2
-               va(ji,2,jk) = 0.25_wp * vmask(ji,2,jk)    &
-                  &        * ( va(ji,1,jk) + 2._wp*va(ji,2,jk) + va(ji,3,jk) )
-            END DO
-         END DO
-         !
-         zvb(:,2) = 0._wp              ! Correct transport
-         DO jk=1,jpkm1
-            DO ji=1,jpi
-               zvb(ji,2) = zvb(ji,2) + e3v_a(ji,2,jk) * va(ji,2,jk) * vmask(ji,2,jk)
-            END DO
-         END DO
-         DO ji = 1, jpi
-            zvb(ji,2) = zvb(ji,2) * r1_hv_a(ji,2)
-         END DO
-         DO jk = 1, jpkm1
+               va_b(ji,2:nbghostcells+1) = va_b(ji,2:nbghostcells+1) * r1_hv_a(ji,2:nbghostcells+1)
+            END DO
+         ENDIF
+         !
+         ! Smoothing if only 1 ghostcell
+         ! -----------------------------
+         IF( nbghostcells == 1 ) THEN
+            DO jk = 1, jpkm1              ! Smooth
+               DO ji = i1, i2
+                  va(ji,2,jk) = 0.25_wp * vmask(ji,2,jk)    &
+                     &        * ( va(ji,1,jk) + 2._wp*va(ji,2,jk) + va(ji,3,jk) )
+               END DO
+            END DO
+            !
+            zvb(:,2) = 0._wp              ! Correct transport
+            DO jk=1,jpkm1
+               DO ji=1,jpi
+                  zvb(ji,2) = zvb(ji,2) + e3v_a(ji,2,jk) * va(ji,2,jk) * vmask(ji,2,jk)
+               END DO
+            END DO
             DO ji = 1, jpi
-               va(ji,2,jk) = ( va(ji,2,jk) + va_b(ji,2) - zvb(ji,2) ) * vmask(ji,2,jk)
-            END DO
-         END DO
-
-         ! Set tangential velocities to time splitting estimate
-         !-----------------------------------------------------
-         IF( ln_dynspg_ts ) THEN
-            zub(:,2) = 0._wp
+               zvb(ji,2) = zvb(ji,2) * r1_hv_a(ji,2)
+            END DO
             DO jk = 1, jpkm1
                DO ji = 1, jpi
-                  zub(ji,2) = zub(ji,2) + e3u_a(ji,2,jk) * ua(ji,2,jk) * umask(ji,2,jk)
-               END DO
-            END DO
-            DO ji = 1, jpi
-               zub(ji,2) = zub(ji,2) * r1_hu_a(ji,2)
-            END DO
-
+                  va(ji,2,jk) = ( va(ji,2,jk) + va_b(ji,2) - zvb(ji,2) ) * vmask(ji,2,jk)
+               END DO
+            END DO
+            
+            IF( ln_dynspg_ts ) THEN       ! Set tangential velocities to time splitting estimate
+               zub(:,2) = 0._wp
+               DO jk = 1, jpkm1
+                  DO ji = 1, jpi
+                     zub(ji,2) = zub(ji,2) + e3u_a(ji,2,jk) * ua(ji,2,jk) * umask(ji,2,jk)
+                  END DO
+               END DO
+               DO ji = 1, jpi
+                  zub(ji,2) = zub(ji,2) * r1_hu_a(ji,2)
+               END DO
+               
+               DO jk = 1, jpkm1
+                  DO ji = 1, jpi
+                     ua(ji,2,jk) = ( ua(ji,2,jk) + ua_b(ji,2) - zub(ji,2) ) * umask(ji,2,jk)
+                  END DO
+               END DO
+            ENDIF
+            !
+         ENDIF
+         !
+         ! Mask domain edges:
+         !-------------------
+!         DO jk = 1, jpkm1
+!            DO ji = 1, jpi
+!               ua(ji,1,jk) = 0._wp
+!               va(ji,1,jk) = 0._wp
+!            END DO
+!         END DO
+         !
+      ENDIF
+
+      ! --- North --- !
+      IF( nbondj == 1 .OR. nbondj == 2 ) THEN
+         !
+         IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
+            va_b(:,nlcj-nbghostcells-1:nlcj-2) = 0._wp
             DO jk = 1, jpkm1
                DO ji = 1, jpi
-                  ua(ji,2,jk) = ( ua(ji,2,jk) + ua_b(ji,2) - zub(ji,2) ) * umask(ji,2,jk)
-               END DO
-            END DO
-         ENDIF
-
+                  va_b(ji,nlcj-nbghostcells-1:nlcj-2) = va_b(ji,nlcj-nbghostcells-1:nlcj-2) + e3v_a(ji,nlcj-nbghostcells-1:nlcj-2,jk)  &
+                     &                                                                         * va(ji,nlcj-nbghostcells-1:nlcj-2,jk)
+               END DO
+            END DO
+            DO ji = 1, jpi
+               va_b(ji,nlcj-nbghostcells-1:nlcj-2) = va_b(ji,nlcj-nbghostcells-1:nlcj-2) * r1_hv_a(ji,nlcj-nbghostcells-1:nlcj-2)
+            END DO
+         ENDIF
+         !
+         ! Smoothing if only 1 ghostcell
+         ! -----------------------------
+         IF( nbghostcells == 1 ) THEN
+            DO jk = 1, jpkm1              ! Smooth
+               DO ji = i1, i2
+                  va(ji,nlcj-2,jk) = 0.25_wp * vmask(ji,nlcj-2,jk)   &
+                     &             * ( va(ji,nlcj-3,jk) + 2._wp * va(ji,nlcj-2,jk) + va(ji,nlcj-1,jk) )
+               END DO
+            END DO
+            !
+            zvb(:,nlcj-2) = 0._wp         ! Correct transport
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  zvb(ji,nlcj-2) = zvb(ji,nlcj-2) + e3v_a(ji,nlcj-2,jk) * va(ji,nlcj-2,jk) * vmask(ji,nlcj-2,jk)
+               END DO
+            END DO
+            DO ji = 1, jpi
+               zvb(ji,nlcj-2) = zvb(ji,nlcj-2) * r1_hv_a(ji,nlcj-2)
+            END DO
+            DO jk = 1, jpkm1
+               DO ji = 1, jpi
+                  va(ji,nlcj-2,jk) = ( va(ji,nlcj-2,jk) + va_b(ji,nlcj-2) - zvb(ji,nlcj-2) ) * vmask(ji,nlcj-2,jk)
+               END DO
+            END DO
+            !
+            IF( ln_dynspg_ts ) THEN       ! Set tangential velocities to time splitting estimate
+               zub(:,nlcj-1) = 0._wp
+               DO jk = 1, jpkm1
+                  DO ji = 1, jpi
+                     zub(ji,nlcj-1) = zub(ji,nlcj-1) + e3u_a(ji,nlcj-1,jk) * ua(ji,nlcj-1,jk) * umask(ji,nlcj-1,jk)
+                  END DO
+               END DO
+               DO ji = 1, jpi
+                  zub(ji,nlcj-1) = zub(ji,nlcj-1) * r1_hu_a(ji,nlcj-1)
+               END DO
+               !
+               DO jk = 1, jpkm1
+                  DO ji = 1, jpi
+                     ua(ji,nlcj-1,jk) = ( ua(ji,nlcj-1,jk) + ua_b(ji,nlcj-1) - zub(ji,nlcj-1) ) * umask(ji,nlcj-1,jk)
+                  END DO
+               END DO
+            ENDIF
+            !
+         ENDIF
+         !
          ! Mask domain edges:
          !-------------------
-         DO jk = 1, jpkm1
-            DO ji = 1, jpi
-               ua(ji,1,jk) = 0._wp
-               va(ji,1,jk) = 0._wp
-            END DO
-         END DO 
-
-      ENDIF
-
-      IF( nbondj == 1 .OR. nbondj == 2 ) THEN
-         !
-         ! Smoothing
-         ! ---------
-         IF( .NOT.ln_dynspg_ts ) THEN  ! Store transport
-            va_b(:,nlcj-2) = 0._wp
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  va_b(ji,nlcj-2) = va_b(ji,nlcj-2) + e3v_a(ji,nlcj-2,jk) * va(ji,nlcj-2,jk)
-               END DO
-            END DO
-            DO ji = 1, jpi
-               va_b(ji,nlcj-2) = va_b(ji,nlcj-2) * r1_hv_a(ji,nlcj-2)            
-            END DO
-         ENDIF
-         !
-         DO jk = 1, jpkm1              ! Smooth
-            DO ji = i1, i2
-               va(ji,nlcj-2,jk) = 0.25_wp * vmask(ji,nlcj-2,jk)   &
-                  &             * ( va(ji,nlcj-3,jk) + 2._wp * va(ji,nlcj-2,jk) + va(ji,nlcj-1,jk) )
-            END DO
-         END DO
-         !
-         zvb(:,nlcj-2) = 0._wp         ! Correct transport
-         DO jk = 1, jpkm1
-            DO ji = 1, jpi
-               zvb(ji,nlcj-2) = zvb(ji,nlcj-2) + e3v_a(ji,nlcj-2,jk) * va(ji,nlcj-2,jk) * vmask(ji,nlcj-2,jk)
-            END DO
-         END DO
-         DO ji = 1, jpi
-            zvb(ji,nlcj-2) = zvb(ji,nlcj-2) * r1_hv_a(ji,nlcj-2)
-         END DO
-         DO jk = 1, jpkm1
-            DO ji = 1, jpi
-               va(ji,nlcj-2,jk) = ( va(ji,nlcj-2,jk) + va_b(ji,nlcj-2) - zvb(ji,nlcj-2) ) * vmask(ji,nlcj-2,jk)
-            END DO
-         END DO
-         !
-         ! Set tangential velocities to time splitting estimate
-         !-----------------------------------------------------
-         IF( ln_dynspg_ts ) THEN
-            zub(:,nlcj-1) = 0._wp
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  zub(ji,nlcj-1) = zub(ji,nlcj-1) + e3u_a(ji,nlcj-1,jk) * ua(ji,nlcj-1,jk) * umask(ji,nlcj-1,jk)
-               END DO
-            END DO
-            DO ji = 1, jpi
-               zub(ji,nlcj-1) = zub(ji,nlcj-1) * r1_hu_a(ji,nlcj-1)
-            END DO
-            !
-            DO jk = 1, jpkm1
-               DO ji = 1, jpi
-                  ua(ji,nlcj-1,jk) = ( ua(ji,nlcj-1,jk) + ua_b(ji,nlcj-1) - zub(ji,nlcj-1) ) * umask(ji,nlcj-1,jk)
-               END DO
-            END DO
-         ENDIF
-         !
-         ! Mask domain edges:
-         !-------------------
-         DO jk = 1, jpkm1
-            DO ji = 1, jpi
-               ua(ji,nlcj  ,jk) = 0._wp
-               va(ji,nlcj-1,jk) = 0._wp
-            END DO
-         END DO 
-         !
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi,jpj,   zub, zvb )
+!         DO jk = 1, jpkm1
+!            DO ji = 1, jpi
+!               ua(ji,nlcj  ,jk) = 0._wp
+!               va(ji,nlcj-1,jk) = 0._wp
+!            END DO
+!         END DO
+         !
+      ENDIF
       !
    END SUBROUTINE Agrif_dyn
@@ -385,5 +393,4 @@
       !!                  ***  ROUTINE Agrif_dyn_ts  ***
       !!----------------------------------------------------------------------  
-      !! 
       INTEGER, INTENT(in) ::   jn
       !!
@@ -392,11 +399,11 @@
       !
       IF( Agrif_Root() )   RETURN
-      !
+      !! clem ghost
       IF((nbondi == -1).OR.(nbondi == 2)) THEN
          DO jj=1,jpj
-            va_e(2,jj) = vbdy_w(jj) * hvr_e(2,jj)
+            va_e(2:nbghostcells+1,jj) = vbdy_w(jj) * hvr_e(2:nbghostcells+1,jj)
             ! Specified fluxes:
-            ua_e(2,jj) = ubdy_w(jj) * hur_e(2,jj)
-            ! Characteristics method:
+            ua_e(2:nbghostcells+1,jj) = ubdy_w(jj) * hur_e(2:nbghostcells+1,jj)
+            ! Characteristics method (only if ghostcells=1):
             !alt            ua_e(2,jj) = 0.5_wp * ( ubdy_w(jj) * hur_e(2,jj) + ua_e(3,jj) &
             !alt                       &           - sqrt(grav * hur_e(2,jj)) * (sshn_e(3,jj) - hbdy_w(jj)) )
@@ -406,8 +413,8 @@
       IF((nbondi == 1).OR.(nbondi == 2)) THEN
          DO jj=1,jpj
-            va_e(nlci-1,jj) = vbdy_e(jj) * hvr_e(nlci-1,jj)
+            va_e(nlci-nbghostcells:nlci-1,jj)   = vbdy_e(jj) * hvr_e(nlci-nbghostcells:nlci-1,jj)
             ! Specified fluxes:
-            ua_e(nlci-2,jj) = ubdy_e(jj) * hur_e(nlci-2,jj)
-            ! Characteristics method:
+            ua_e(nlci-nbghostcells-1:nlci-2,jj) = ubdy_e(jj) * hur_e(nlci-nbghostcells-1:nlci-2,jj)
+            ! Characteristics method (only if ghostcells=1):
             !alt            ua_e(nlci-2,jj) = 0.5_wp * ( ubdy_e(jj) * hur_e(nlci-2,jj) + ua_e(nlci-3,jj) &
             !alt                            &           + sqrt(grav * hur_e(nlci-2,jj)) * (sshn_e(nlci-2,jj) - hbdy_e(jj)) )
@@ -417,8 +424,8 @@
       IF((nbondj == -1).OR.(nbondj == 2)) THEN
          DO ji=1,jpi
-            ua_e(ji,2) = ubdy_s(ji) * hur_e(ji,2)
+            ua_e(ji,2:nbghostcells+1) = ubdy_s(ji) * hur_e(ji,2:nbghostcells+1)
             ! Specified fluxes:
-            va_e(ji,2) = vbdy_s(ji) * hvr_e(ji,2)
-            ! Characteristics method:
+            va_e(ji,2:nbghostcells+1) = vbdy_s(ji) * hvr_e(ji,2:nbghostcells+1)
+            ! Characteristics method (only if ghostcells=1):
             !alt            va_e(ji,2) = 0.5_wp * ( vbdy_s(ji) * hvr_e(ji,2) + va_e(ji,3) &
             !alt                       &           - sqrt(grav * hvr_e(ji,2)) * (sshn_e(ji,3) - hbdy_s(ji)) )
@@ -428,8 +435,8 @@
       IF((nbondj == 1).OR.(nbondj == 2)) THEN
          DO ji=1,jpi
-            ua_e(ji,nlcj-1) = ubdy_n(ji) * hur_e(ji,nlcj-1)
+            ua_e(ji,nlcj-nbghostcells:nlcj-1)   = ubdy_n(ji) * hur_e(ji,nlcj-nbghostcells:nlcj-1)
             ! Specified fluxes:
-            va_e(ji,nlcj-2) = vbdy_n(ji) * hvr_e(ji,nlcj-2)
-            ! Characteristics method:
+            va_e(ji,nlcj-nbghostcells-1:nlcj-2) = vbdy_n(ji) * hvr_e(ji,nlcj-nbghostcells-1:nlcj-2)
+            ! Characteristics method (only if ghostcells=1):
             !alt            va_e(ji,nlcj-2) = 0.5_wp * ( vbdy_n(ji) * hvr_e(ji,nlcj-2)  + va_e(ji,nlcj-3) &
             !alt                            &           + sqrt(grav * hvr_e(ji,nlcj-2)) * (sshn_e(ji,nlcj-2) - hbdy_n(ji)) )
@@ -444,5 +451,4 @@
       !!                  ***  ROUTINE Agrif_dta_ts  ***
       !!----------------------------------------------------------------------  
-      !! 
       INTEGER, INTENT(in) ::   kt
       !!
@@ -476,5 +482,5 @@
       !
       IF( ll_int_cons ) THEN  ! Conservative interpolation
-         ! orders matters here !!!!!!
+         ! order matters here !!!!!!
          CALL Agrif_Bc_variable( ub2b_interp_id, calledweight=1._wp, procname=interpub2b ) ! Time integrated
          CALL Agrif_Bc_variable( vb2b_interp_id, calledweight=1._wp, procname=interpvb2b )
@@ -504,27 +510,52 @@
       !!----------------------------------------------------------------------  
       INTEGER, INTENT(in) ::   kt
-      !!
+      !
+      INTEGER  :: ji, jj, indx
       !!----------------------------------------------------------------------  
       !
       IF( Agrif_Root() )   RETURN
-      !
+      !! clem ghost
+      ! --- West --- !
       IF((nbondi == -1).OR.(nbondi == 2)) THEN
-         ssha(2,:)=ssha(3,:)
-         sshn(2,:)=sshn(3,:)
-      ENDIF
-      !
+         indx = 1+nbghostcells
+         DO jj = 1, jpj
+            DO ji = 2, indx
+               ssha(ji,jj)=ssha(indx+1,jj)
+               sshn(ji,jj)=sshn(indx+1,jj)
+            ENDDO
+         ENDDO
+      ENDIF
+      !
+      ! --- East --- !
       IF((nbondi == 1).OR.(nbondi == 2)) THEN
-         ssha(nlci-1,:)=ssha(nlci-2,:)
-         sshn(nlci-1,:)=sshn(nlci-2,:)
-      ENDIF
-      !
+         indx = nlci-nbghostcells
+         DO jj = 1, jpj
+            DO ji = indx, nlci-1
+               ssha(ji,jj)=ssha(indx-1,jj)
+               sshn(ji,jj)=sshn(indx-1,jj)
+            ENDDO
+         ENDDO
+      ENDIF
+      !
+      ! --- South --- !
       IF((nbondj == -1).OR.(nbondj == 2)) THEN
-         ssha(:,2)=ssha(:,3)
-         sshn(:,2)=sshn(:,3)
-      ENDIF
-      !
+         indx = 1+nbghostcells
+         DO jj = 2, indx
+            DO ji = 1, jpi
+               ssha(ji,jj)=ssha(ji,indx+1)
+               sshn(ji,jj)=sshn(ji,indx+1)
+            ENDDO
+         ENDDO
+      ENDIF
+      !
+      ! --- North --- !
       IF((nbondj == 1).OR.(nbondj == 2)) THEN
-         ssha(:,nlcj-1)=ssha(:,nlcj-2)
-         sshn(:,nlcj-1)=sshn(:,nlcj-2)
+         indx = nlcj-nbghostcells
+         DO jj = indx, nlcj-1
+            DO ji = 1, jpi
+               ssha(ji,jj)=ssha(ji,indx-1)
+               sshn(ji,jj)=sshn(ji,indx-1)
+            ENDDO
+         ENDDO
       ENDIF
       !
@@ -538,10 +569,10 @@
       INTEGER, INTENT(in) ::   jn
       !!
-      INTEGER :: ji,jj
-      !!----------------------------------------------------------------------  
-      !
+      INTEGER :: ji, jj
+      !!----------------------------------------------------------------------  
+      !! clem ghost (starting at i,j=1 is important I think otherwise you introduce a grad(ssh)/=0 at point 2)
       IF((nbondi == -1).OR.(nbondi == 2)) THEN
          DO jj = 1, jpj
-            ssha_e(2,jj) = hbdy_w(jj)
+            ssha_e(2:nbghostcells+1,jj) = hbdy_w(jj)
          END DO
       ENDIF
@@ -549,5 +580,5 @@
       IF((nbondi == 1).OR.(nbondi == 2)) THEN
          DO jj = 1, jpj
-            ssha_e(nlci-1,jj) = hbdy_e(jj)
+            ssha_e(nlci-nbghostcells:nlci-1,jj) = hbdy_e(jj)
          END DO
       ENDIF
@@ -555,5 +586,5 @@
       IF((nbondj == -1).OR.(nbondj == 2)) THEN
          DO ji = 1, jpi
-            ssha_e(ji,2) = hbdy_s(ji)
+            ssha_e(ji,2:nbghostcells+1) = hbdy_s(ji)
          END DO
       ENDIF
@@ -561,5 +592,5 @@
       IF((nbondj == 1).OR.(nbondj == 2)) THEN
          DO ji = 1, jpi
-            ssha_e(ji,nlcj-1) = hbdy_n(ji)
+            ssha_e(ji,nlcj-nbghostcells:nlcj-1) = hbdy_n(ji)
          END DO
       ENDIF
@@ -567,30 +598,27 @@
    END SUBROUTINE Agrif_ssh_ts
 
-# if defined key_zdftke
-
-   SUBROUTINE Agrif_tke
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE Agrif_tke  ***
+
+   SUBROUTINE Agrif_avm
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE Agrif_avm  ***
       !!----------------------------------------------------------------------  
       REAL(wp) ::   zalpha
       !!----------------------------------------------------------------------  
       !
-      zalpha = REAL( Agrif_NbStepint() + Agrif_IRhot() - 1, wp ) / REAL( Agrif_IRhot(), wp )
-      IF( zalpha > 1. )   zalpha = 1.
-      !
-      Agrif_SpecialValue    = 0.e0
+      zalpha = 1._wp   ! proper time interpolation impossible  ==> use last available value from parent 
+      !
+      Agrif_SpecialValue    = 0._wp
       Agrif_UseSpecialValue = .TRUE.
       !
-      CALL Agrif_Bc_variable(avm_id ,calledweight=zalpha, procname=interpavm)       
+      CALL Agrif_Bc_variable( avm_id, calledweight=zalpha, procname=interpavm )       
       !
       Agrif_UseSpecialValue = .FALSE.
       !
-   END SUBROUTINE Agrif_tke
+   END SUBROUTINE Agrif_avm
    
-# endif
 
    SUBROUTINE interptsn( ptab, i1, i2, j1, j2, k1, k2, n1, n2, before, nb, ndir )
       !!----------------------------------------------------------------------
-      !!   *** ROUTINE interptsn ***
+      !!                  *** ROUTINE interptsn ***
       !!----------------------------------------------------------------------
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) ::   ptab
@@ -601,138 +629,123 @@
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
       INTEGER  ::   imin, imax, jmin, jmax
-      REAL(wp) ::   zrhox , zalpha1, zalpha2, zalpha3
-      REAL(wp) ::   zalpha4, zalpha5, zalpha6, zalpha7
+      REAL(wp) ::   zrhox, z1, z2, z3, z4, z5, z6, z7
       LOGICAL  ::   western_side, eastern_side,northern_side,southern_side
       !!----------------------------------------------------------------------
       !
-      IF (before) THEN         
+      IF( before ) THEN         
          ptab(i1:i2,j1:j2,k1:k2,n1:n2) = tsn(i1:i2,j1:j2,k1:k2,n1:n2)
       ELSE
          !
-         western_side  = (nb == 1).AND.(ndir == 1)
-         eastern_side  = (nb == 1).AND.(ndir == 2)
-         southern_side = (nb == 2).AND.(ndir == 1)
-         northern_side = (nb == 2).AND.(ndir == 2)
-         !
-         zrhox = Agrif_Rhox()
-         ! 
-         zalpha1 = ( zrhox - 1. ) * 0.5
-         zalpha2 = 1. - zalpha1
-         ! 
-         zalpha3 = ( zrhox - 1. ) / ( zrhox + 1. )
-         zalpha4 = 1. - zalpha3
-         ! 
-         zalpha6 = 2. * ( zrhox - 1. ) / ( zrhox + 1. )
-         zalpha7 =    - ( zrhox - 1. ) / ( zrhox + 3. )
-         zalpha5 = 1. - zalpha6 - zalpha7
-         !
-         imin = i1
-         imax = i2
-         jmin = j1
-         jmax = j2
-         ! 
-         ! Remove CORNERS
-         IF((nbondj == -1).OR.(nbondj == 2)) jmin = 3
-         IF((nbondj == +1).OR.(nbondj == 2)) jmax = nlcj-2
-         IF((nbondi == -1).OR.(nbondi == 2)) imin = 3
-         IF((nbondi == +1).OR.(nbondi == 2)) imax = nlci-2        
-         !
-         IF( eastern_side ) THEN
-            DO jn = 1, jpts
-               tsa(nlci,j1:j2,k1:k2,jn) = zalpha1 * ptab(nlci,j1:j2,k1:k2,jn) + zalpha2 * ptab(nlci-1,j1:j2,k1:k2,jn)
-               DO jk = 1, jpkm1
-                  DO jj = jmin,jmax
-                     IF( umask(nlci-2,jj,jk) == 0._wp ) THEN
-                        tsa(nlci-1,jj,jk,jn) = tsa(nlci,jj,jk,jn) * tmask(nlci-1,jj,jk)
-                     ELSE
-                        tsa(nlci-1,jj,jk,jn)=(zalpha4*tsa(nlci,jj,jk,jn)+zalpha3*tsa(nlci-2,jj,jk,jn))*tmask(nlci-1,jj,jk)
-                        IF( un(nlci-2,jj,jk) > 0._wp ) THEN
-                           tsa(nlci-1,jj,jk,jn)=( zalpha6*tsa(nlci-2,jj,jk,jn)+zalpha5*tsa(nlci,jj,jk,jn) & 
-                                 + zalpha7*tsa(nlci-3,jj,jk,jn) ) * tmask(nlci-1,jj,jk)
+         western_side  = (nb == 1).AND.(ndir == 1)   ;   eastern_side  = (nb == 1).AND.(ndir == 2)
+         southern_side = (nb == 2).AND.(ndir == 1)   ;   northern_side = (nb == 2).AND.(ndir == 2)
+         !
+         IF( nbghostcells > 1 ) THEN  ! no smoothing
+            tsa(i1:i2,j1:j2,k1:k2,n1:n2) = ptab(i1:i2,j1:j2,k1:k2,n1:n2)
+         ELSE                         ! smoothing
+            !
+            zrhox = Agrif_Rhox()
+            z1 = ( zrhox - 1. ) * 0.5
+            z3 = ( zrhox - 1. ) / ( zrhox + 1. )
+            z6 = 2. * ( zrhox - 1. ) / ( zrhox + 1. )
+            z7 =    - ( zrhox - 1. ) / ( zrhox + 3. )
+            !
+            z2 = 1. - z1
+            z4 = 1. - z3
+            z5 = 1. - z6 - z7
+            !
+            imin = i1 ; imax = i2
+            jmin = j1 ; jmax = j2
+            ! 
+            ! Remove CORNERS
+            IF((nbondj == -1).OR.(nbondj == 2)) jmin = 3
+            IF((nbondj == +1).OR.(nbondj == 2)) jmax = nlcj-2
+            IF((nbondi == -1).OR.(nbondi == 2)) imin = 3
+            IF((nbondi == +1).OR.(nbondi == 2)) imax = nlci-2        
+            !
+            IF( eastern_side ) THEN
+               DO jn = 1, jpts
+                  tsa(nlci,j1:j2,k1:k2,jn) = z1 * ptab(nlci,j1:j2,k1:k2,jn) + z2 * ptab(nlci-1,j1:j2,k1:k2,jn)
+                  DO jk = 1, jpkm1
+                     DO jj = jmin,jmax
+                        IF( umask(nlci-2,jj,jk) == 0._wp ) THEN
+                           tsa(nlci-1,jj,jk,jn) = tsa(nlci,jj,jk,jn) * tmask(nlci-1,jj,jk)
+                        ELSE
+                           tsa(nlci-1,jj,jk,jn)=(z4*tsa(nlci,jj,jk,jn)+z3*tsa(nlci-2,jj,jk,jn))*tmask(nlci-1,jj,jk)
+                           IF( un(nlci-2,jj,jk) > 0._wp ) THEN
+                              tsa(nlci-1,jj,jk,jn)=( z6*tsa(nlci-2,jj,jk,jn)+z5*tsa(nlci,jj,jk,jn) & 
+                                                   + z7*tsa(nlci-3,jj,jk,jn) ) * tmask(nlci-1,jj,jk)
+                           ENDIF
                         ENDIF
-                     ENDIF
+                     END DO
                   END DO
-               END DO
-               tsa(nlci,j1:j2,k1:k2,jn) = 0._wp
-            END DO
-         ENDIF
-         ! 
-         IF( northern_side ) THEN            
-            DO jn = 1, jpts
-               tsa(i1:i2,nlcj,k1:k2,jn) = zalpha1 * ptab(i1:i2,nlcj,k1:k2,jn) + zalpha2 * ptab(i1:i2,nlcj-1,k1:k2,jn)
-               DO jk = 1, jpkm1
-                  DO ji = imin,imax
-                     IF( vmask(ji,nlcj-2,jk) == 0._wp ) THEN
-                        tsa(ji,nlcj-1,jk,jn) = tsa(ji,nlcj,jk,jn) * tmask(ji,nlcj-1,jk)
-                     ELSE
-                        tsa(ji,nlcj-1,jk,jn)=(zalpha4*tsa(ji,nlcj,jk,jn)+zalpha3*tsa(ji,nlcj-2,jk,jn))*tmask(ji,nlcj-1,jk)        
-                        IF (vn(ji,nlcj-2,jk) > 0._wp ) THEN
-                           tsa(ji,nlcj-1,jk,jn)=( zalpha6*tsa(ji,nlcj-2,jk,jn)+zalpha5*tsa(ji,nlcj,jk,jn)  &
-                                 + zalpha7*tsa(ji,nlcj-3,jk,jn) ) * tmask(ji,nlcj-1,jk)
+                  tsa(nlci,j1:j2,k1:k2,jn) = 0._wp
+               END DO
+            ENDIF
+            ! 
+            IF( northern_side ) THEN            
+               DO jn = 1, jpts
+                  tsa(i1:i2,nlcj,k1:k2,jn) = z1 * ptab(i1:i2,nlcj,k1:k2,jn) + z2 * ptab(i1:i2,nlcj-1,k1:k2,jn)
+                  DO jk = 1, jpkm1
+                     DO ji = imin,imax
+                        IF( vmask(ji,nlcj-2,jk) == 0._wp ) THEN
+                           tsa(ji,nlcj-1,jk,jn) = tsa(ji,nlcj,jk,jn) * tmask(ji,nlcj-1,jk)
+                        ELSE
+                           tsa(ji,nlcj-1,jk,jn)=(z4*tsa(ji,nlcj,jk,jn)+z3*tsa(ji,nlcj-2,jk,jn))*tmask(ji,nlcj-1,jk)        
+                           IF (vn(ji,nlcj-2,jk) > 0._wp ) THEN
+                              tsa(ji,nlcj-1,jk,jn)=( z6*tsa(ji,nlcj-2,jk,jn)+z5*tsa(ji,nlcj,jk,jn)  &
+                                                   + z7*tsa(ji,nlcj-3,jk,jn) ) * tmask(ji,nlcj-1,jk)
+                           ENDIF
                         ENDIF
-                     ENDIF
+                     END DO
                   END DO
-               END DO
-               tsa(i1:i2,nlcj,k1:k2,jn) = 0._wp
-            END DO
-         ENDIF
-         !
-         IF( western_side ) THEN            
-            DO jn = 1, jpts
-               tsa(1,j1:j2,k1:k2,jn) = zalpha1 * ptab(1,j1:j2,k1:k2,jn) + zalpha2 * ptab(2,j1:j2,k1:k2,jn)
-               DO jk = 1, jpkm1
-                  DO jj = jmin,jmax
-                     IF( umask(2,jj,jk) == 0._wp ) THEN
-                        tsa(2,jj,jk,jn) = tsa(1,jj,jk,jn) * tmask(2,jj,jk)
-                     ELSE
-                        tsa(2,jj,jk,jn)=(zalpha4*tsa(1,jj,jk,jn)+zalpha3*tsa(3,jj,jk,jn))*tmask(2,jj,jk)        
-                        IF( un(2,jj,jk) < 0._wp ) THEN
-                           tsa(2,jj,jk,jn)=(zalpha6*tsa(3,jj,jk,jn)+zalpha5*tsa(1,jj,jk,jn)+zalpha7*tsa(4,jj,jk,jn))*tmask(2,jj,jk)
+                  tsa(i1:i2,nlcj,k1:k2,jn) = 0._wp
+               END DO
+            ENDIF
+            !
+            IF( western_side ) THEN            
+               DO jn = 1, jpts
+                  tsa(1,j1:j2,k1:k2,jn) = z1 * ptab(1,j1:j2,k1:k2,jn) + z2 * ptab(2,j1:j2,k1:k2,jn)
+                  DO jk = 1, jpkm1
+                     DO jj = jmin,jmax
+                        IF( umask(2,jj,jk) == 0._wp ) THEN
+                           tsa(2,jj,jk,jn) = tsa(1,jj,jk,jn) * tmask(2,jj,jk)
+                        ELSE
+                           tsa(2,jj,jk,jn)=(z4*tsa(1,jj,jk,jn)+z3*tsa(3,jj,jk,jn))*tmask(2,jj,jk)        
+                           IF( un(2,jj,jk) < 0._wp ) THEN
+                              tsa(2,jj,jk,jn)=(z6*tsa(3,jj,jk,jn)+z5*tsa(1,jj,jk,jn)+z7*tsa(4,jj,jk,jn))*tmask(2,jj,jk)
+                           ENDIF
                         ENDIF
-                     ENDIF
+                     END DO
                   END DO
-               END DO
-               tsa(1,j1:j2,k1:k2,jn) = 0._wp
-            END DO
-         ENDIF
-         !
-         IF( southern_side ) THEN           
-            DO jn = 1, jpts
-               tsa(i1:i2,1,k1:k2,jn) = zalpha1 * ptab(i1:i2,1,k1:k2,jn) + zalpha2 * ptab(i1:i2,2,k1:k2,jn)
-               DO jk = 1, jpk      
-                  DO ji=imin,imax
-                     IF( vmask(ji,2,jk) == 0._wp ) THEN
-                        tsa(ji,2,jk,jn)=tsa(ji,1,jk,jn) * tmask(ji,2,jk)
-                     ELSE
-                        tsa(ji,2,jk,jn)=(zalpha4*tsa(ji,1,jk,jn)+zalpha3*tsa(ji,3,jk,jn))*tmask(ji,2,jk)
-                        IF( vn(ji,2,jk) < 0._wp ) THEN
-                           tsa(ji,2,jk,jn)=(zalpha6*tsa(ji,3,jk,jn)+zalpha5*tsa(ji,1,jk,jn)+zalpha7*tsa(ji,4,jk,jn))*tmask(ji,2,jk)
+                  tsa(1,j1:j2,k1:k2,jn) = 0._wp
+               END DO
+            ENDIF
+            !
+            IF( southern_side ) THEN           
+               DO jn = 1, jpts
+                  tsa(i1:i2,1,k1:k2,jn) = z1 * ptab(i1:i2,1,k1:k2,jn) + z2 * ptab(i1:i2,2,k1:k2,jn)
+                  DO jk = 1, jpk      
+                     DO ji=imin,imax
+                        IF( vmask(ji,2,jk) == 0._wp ) THEN
+                           tsa(ji,2,jk,jn)=tsa(ji,1,jk,jn) * tmask(ji,2,jk)
+                        ELSE
+                           tsa(ji,2,jk,jn)=(z4*tsa(ji,1,jk,jn)+z3*tsa(ji,3,jk,jn))*tmask(ji,2,jk)
+                           IF( vn(ji,2,jk) < 0._wp ) THEN
+                              tsa(ji,2,jk,jn)=(z6*tsa(ji,3,jk,jn)+z5*tsa(ji,1,jk,jn)+z7*tsa(ji,4,jk,jn))*tmask(ji,2,jk)
+                           ENDIF
                         ENDIF
-                     ENDIF
+                     END DO
                   END DO
-               END DO
-               tsa(i1:i2,1,k1:k2,jn) = 0._wp
-            END DO
-         ENDIF
-         !
-         ! Treatment of corners
-         ! 
-         ! East south
-         IF ((eastern_side).AND.((nbondj == -1).OR.(nbondj == 2))) THEN
-            tsa(nlci-1,2,:,:) = ptab(nlci-1,2,:,:)
-         ENDIF
-         ! East north
-         IF ((eastern_side).AND.((nbondj == 1).OR.(nbondj == 2))) THEN
-            tsa(nlci-1,nlcj-1,:,:) = ptab(nlci-1,nlcj-1,:,:)
-         ENDIF
-         ! West south
-         IF ((western_side).AND.((nbondj == -1).OR.(nbondj == 2))) THEN
-            tsa(2,2,:,:) = ptab(2,2,:,:)
-         ENDIF
-         ! West north
-         IF ((western_side).AND.((nbondj == 1).OR.(nbondj == 2))) THEN
-            tsa(2,nlcj-1,:,:) = ptab(2,nlcj-1,:,:)
-         ENDIF
-         !
+                  tsa(i1:i2,1,k1:k2,jn) = 0._wp
+               END DO
+            ENDIF
+            !
+            ! Treatment of corners
+            IF ((eastern_side).AND.((nbondj == -1).OR.(nbondj == 2)))   tsa(nlci-1,2,:,:) = ptab(nlci-1,2,:,:)            ! East south
+            IF ((eastern_side).AND.((nbondj ==  1).OR.(nbondj == 2)))   tsa(nlci-1,nlcj-1,:,:) = ptab(nlci-1,nlcj-1,:,:)  ! East north
+            IF ((western_side).AND.((nbondj == -1).OR.(nbondj == 2)))   tsa(2,2,:,:) = ptab(2,2,:,:)                      ! West south
+            IF ((western_side).AND.((nbondj ==  1).OR.(nbondj == 2)))   tsa(2,nlcj-1,:,:) = ptab(2,nlcj-1,:,:)            ! West north
+            !
+         ENDIF
       ENDIF
       !
@@ -759,7 +772,8 @@
          southern_side = (nb == 2).AND.(ndir == 1)
          northern_side = (nb == 2).AND.(ndir == 2)
-         IF(western_side)  hbdy_w(j1:j2) = ptab(i1,j1:j2) * tmask(i1,j1:j2,1)
-         IF(eastern_side)  hbdy_e(j1:j2) = ptab(i1,j1:j2) * tmask(i1,j1:j2,1)
-         IF(southern_side) hbdy_s(i1:i2) = ptab(i1:i2,j1) * tmask(i1:i2,j1,1)
+         !! clem ghost
+         IF(western_side)  hbdy_w(j1:j2) = ptab(i2,j1:j2) * tmask(i2,j1:j2,1)
+         IF(eastern_side)  hbdy_e(j1:j2) = ptab(i1,j1:j2) * tmask(i1,j1:j2,1) !clem previously i1
+         IF(southern_side) hbdy_s(i1:i2) = ptab(i1:i2,j2) * tmask(i1:i2,j2,1) !clem previously j1
          IF(northern_side) hbdy_n(i1:i2) = ptab(i1:i2,j1) * tmask(i1:i2,j1,1)
       ENDIF
@@ -770,5 +784,5 @@
    SUBROUTINE interpun( ptab, i1, i2, j1, j2, k1, k2, before )
       !!----------------------------------------------------------------------
-      !!   *** ROUTINE interpun ***
+      !!                  *** ROUTINE interpun ***
       !!----------------------------------------------------------------------
       INTEGER                               , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
@@ -798,5 +812,5 @@
    SUBROUTINE interpvn( ptab, i1, i2, j1, j2, k1, k2, before )
       !!----------------------------------------------------------------------
-      !!   *** ROUTINE interpvn ***
+      !!                  *** ROUTINE interpvn ***
       !!----------------------------------------------------------------------
       INTEGER                               , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
@@ -854,36 +868,19 @@
          ELSEIF( bdy_tinterp == 2 ) THEN
             ztcoeff = zrhot * (  zt1        * (       zt1 - 1._wp)**2._wp &
-               &               - zt0        * (       zt0 - 1._wp)**2._wp ) 
-
+               &               - zt0        * (       zt0 - 1._wp)**2._wp )
          ELSE
             ztcoeff = 1
          ENDIF
-         !   
-         IF(western_side) THEN
-            ubdy_w(j1:j2) = ubdy_w(j1:j2) + ztcoeff * ptab(i1,j1:j2)  
-         ENDIF
-         IF(eastern_side) THEN
-            ubdy_e(j1:j2) = ubdy_e(j1:j2) + ztcoeff * ptab(i1,j1:j2)  
-         ENDIF
-         IF(southern_side) THEN
-            ubdy_s(i1:i2) = ubdy_s(i1:i2) + ztcoeff * ptab(i1:i2,j1) 
-         ENDIF
-         IF(northern_side) THEN
-            ubdy_n(i1:i2) = ubdy_n(i1:i2) + ztcoeff * ptab(i1:i2,j1) 
-         ENDIF
+         !! clem ghost   
+         IF(western_side)   ubdy_w(j1:j2) = ubdy_w(j1:j2) + ztcoeff * ptab(i2,j1:j2)  
+         IF(eastern_side)   ubdy_e(j1:j2) = ubdy_e(j1:j2) + ztcoeff * ptab(i1,j1:j2) !clem previously i1  
+         IF(southern_side)  ubdy_s(i1:i2) = ubdy_s(i1:i2) + ztcoeff * ptab(i1:i2,j2) !clem previously j1
+         IF(northern_side)  ubdy_n(i1:i2) = ubdy_n(i1:i2) + ztcoeff * ptab(i1:i2,j1) 
          !            
          IF( bdy_tinterp == 0 .OR. bdy_tinterp == 2) THEN
-            IF(western_side) THEN
-               ubdy_w(j1:j2) = ubdy_w(j1:j2) / (zrhoy*e2u(i1,j1:j2)) * umask(i1,j1:j2,1)
-            ENDIF
-            IF(eastern_side) THEN
-               ubdy_e(j1:j2) = ubdy_e(j1:j2) / (zrhoy*e2u(i1,j1:j2)) * umask(i1,j1:j2,1)
-            ENDIF
-            IF(southern_side) THEN
-               ubdy_s(i1:i2) = ubdy_s(i1:i2) / (zrhoy*e2u(i1:i2,j1)) * umask(i1:i2,j1,1)
-            ENDIF
-            IF(northern_side) THEN
-               ubdy_n(i1:i2) = ubdy_n(i1:i2) / (zrhoy*e2u(i1:i2,j1)) * umask(i1:i2,j1,1)
-            ENDIF
+            IF(western_side)   ubdy_w(j1:j2) = ubdy_w(j1:j2) / (zrhoy*e2u(i2,j1:j2)) * umask(i2,j1:j2,1)
+            IF(eastern_side)   ubdy_e(j1:j2) = ubdy_e(j1:j2) / (zrhoy*e2u(i1,j1:j2)) * umask(i1,j1:j2,1)
+            IF(southern_side)  ubdy_s(i1:i2) = ubdy_s(i1:i2) / (zrhoy*e2u(i1:i2,j2)) * umask(i1:i2,j2,1)
+            IF(northern_side)  ubdy_n(i1:i2) = ubdy_n(i1:i2) / (zrhoy*e2u(i1:i2,j1)) * umask(i1:i2,j1,1)
          ENDIF
       ENDIF
@@ -927,35 +924,15 @@
             ztcoeff = 1
          ENDIF
-         !
-         IF(western_side) THEN
-            vbdy_w(j1:j2) = vbdy_w(j1:j2) + ztcoeff * ptab(i1,j1:j2)  
-         ENDIF
-         IF(eastern_side) THEN
-            vbdy_e(j1:j2) = vbdy_e(j1:j2) + ztcoeff * ptab(i1,j1:j2)  
-         ENDIF
-         IF(southern_side) THEN
-            vbdy_s(i1:i2) = vbdy_s(i1:i2) + ztcoeff * ptab(i1:i2,j1)
-         ENDIF
-         IF(northern_side) THEN
-            vbdy_n(i1:i2) = vbdy_n(i1:i2) + ztcoeff * ptab(i1:i2,j1) 
-         ENDIF
+         !! clem ghost
+         IF(western_side)   vbdy_w(j1:j2) = vbdy_w(j1:j2) + ztcoeff * ptab(i2,j1:j2)  
+         IF(eastern_side)   vbdy_e(j1:j2) = vbdy_e(j1:j2) + ztcoeff * ptab(i1,j1:j2) !clem previously i1  
+         IF(southern_side)  vbdy_s(i1:i2) = vbdy_s(i1:i2) + ztcoeff * ptab(i1:i2,j2) !clem previously j1
+         IF(northern_side)  vbdy_n(i1:i2) = vbdy_n(i1:i2) + ztcoeff * ptab(i1:i2,j1) 
          !            
          IF( bdy_tinterp == 0 .OR. bdy_tinterp == 2) THEN
-            IF(western_side) THEN
-               vbdy_w(j1:j2) = vbdy_w(j1:j2) / (zrhox*e1v(i1,j1:j2))   &
-                     &                                  * vmask(i1,j1:j2,1)
-            ENDIF
-            IF(eastern_side) THEN
-               vbdy_e(j1:j2) = vbdy_e(j1:j2) / (zrhox*e1v(i1,j1:j2))   &
-                     &                                  * vmask(i1,j1:j2,1)
-            ENDIF
-            IF(southern_side) THEN
-               vbdy_s(i1:i2) = vbdy_s(i1:i2) / (zrhox*e1v(i1:i2,j1))   &
-                     &                                  * vmask(i1:i2,j1,1)
-            ENDIF
-            IF(northern_side) THEN
-               vbdy_n(i1:i2) = vbdy_n(i1:i2) / (zrhox*e1v(i1:i2,j1))   &
-                     &                                  * vmask(i1:i2,j1,1)
-            ENDIF
+            IF(western_side)   vbdy_w(j1:j2) = vbdy_w(j1:j2) / (zrhox*e1v(i2,j1:j2)) * vmask(i2,j1:j2,1)
+            IF(eastern_side)   vbdy_e(j1:j2) = vbdy_e(j1:j2) / (zrhox*e1v(i1,j1:j2)) * vmask(i1,j1:j2,1)
+            IF(southern_side)  vbdy_s(i1:i2) = vbdy_s(i1:i2) / (zrhox*e1v(i1:i2,j2)) * vmask(i1:i2,j2,1)
+            IF(northern_side)  vbdy_n(i1:i2) = vbdy_n(i1:i2) / (zrhox*e1v(i1:i2,j1)) * vmask(i1:i2,j1,1)
          ENDIF
       ENDIF
@@ -991,8 +968,8 @@
          zat = zrhot * (  zt1**2._wp * (-2._wp*zt1 + 3._wp)    &
             &           - zt0**2._wp * (-2._wp*zt0 + 3._wp)    ) 
-         ! 
-         IF(western_side ) ubdy_w(j1:j2) = zat * ptab(i1,j1:j2)  
-         IF(eastern_side ) ubdy_e(j1:j2) = zat * ptab(i1,j1:j2)  
-         IF(southern_side) ubdy_s(i1:i2) = zat * ptab(i1:i2,j1) 
+         !! clem ghost
+         IF(western_side ) ubdy_w(j1:j2) = zat * ptab(i2,j1:j2)  
+         IF(eastern_side ) ubdy_e(j1:j2) = zat * ptab(i1,j1:j2) !clem previously i1  
+         IF(southern_side) ubdy_s(i1:i2) = zat * ptab(i1:i2,j2) !clem previously j1
          IF(northern_side) ubdy_n(i1:i2) = zat * ptab(i1:i2,j1) 
       ENDIF
@@ -1030,7 +1007,7 @@
             &           - zt0**2._wp * (-2._wp*zt0 + 3._wp)    ) 
          !
-         IF(western_side )   vbdy_w(j1:j2) = zat * ptab(i1,j1:j2)  
-         IF(eastern_side )   vbdy_e(j1:j2) = zat * ptab(i1,j1:j2)  
-         IF(southern_side)   vbdy_s(i1:i2) = zat * ptab(i1:i2,j1) 
+         IF(western_side )   vbdy_w(j1:j2) = zat * ptab(i2,j1:j2)  
+         IF(eastern_side )   vbdy_e(j1:j2) = zat * ptab(i1,j1:j2) !clem previously i1  
+         IF(southern_side)   vbdy_s(i1:i2) = zat * ptab(i1:i2,j2) !clem previously j1 
          IF(northern_side)   vbdy_n(i1:i2) = zat * ptab(i1:i2,j1) 
       ENDIF
@@ -1050,5 +1027,4 @@
       INTEGER :: ji, jj, jk
       LOGICAL :: western_side, eastern_side, northern_side, southern_side
-      REAL(wp) :: ztmpmsk      
       !!----------------------------------------------------------------------  
       !    
@@ -1060,15 +1036,10 @@
          southern_side = (nb == 2).AND.(ndir == 1)
          northern_side = (nb == 2).AND.(ndir == 2)
-
+         !
          DO jk = k1, k2
             DO jj = j1, j2
                DO ji = i1, i2
-                  ! Get velocity mask at boundary edge points:
-                  IF( western_side )   ztmpmsk = umask(ji    ,jj    ,1)
-                  IF( eastern_side )   ztmpmsk = umask(nlci-2,jj    ,1)
-                  IF( northern_side)   ztmpmsk = vmask(ji    ,nlcj-2,1)
-                  IF( southern_side)   ztmpmsk = vmask(ji    ,2     ,1)
                   !
-                  IF( ABS( ptab(ji,jj,jk) - tmask(ji,jj,jk) * e3t_0(ji,jj,jk) )*ztmpmsk > 1.D-2) THEN
+                  IF( ABS( ptab(ji,jj,jk) - tmask(ji,jj,jk) * e3t_0(ji,jj,jk) ) > 1.D-2) THEN
                      IF (western_side) THEN
                         WRITE(numout,*) 'ERROR bathymetry merge at the western border ji,jj,jk ', ji+nimpp-1,jj+njmpp-1,jk
@@ -1175,5 +1146,4 @@
    END SUBROUTINE interpvmsk
 
-# if defined key_zdftke
 
    SUBROUTINE interpavm( ptab, i1, i2, j1, j2, k1, k2, before )
@@ -1186,13 +1156,9 @@
       !!----------------------------------------------------------------------  
       !      
-      IF( before ) THEN
-         ptab (i1:i2,j1:j2,k1:k2) = avm_k(i1:i2,j1:j2,k1:k2)
-      ELSE
-         avm_k(i1:i2,j1:j2,k1:k2) = ptab (i1:i2,j1:j2,k1:k2)
+      IF( before ) THEN   ;   ptab (i1:i2,j1:j2,k1:k2) = avm_k(i1:i2,j1:j2,k1:k2)
+      ELSE                ;   avm_k(i1:i2,j1:j2,k1:k2) = ptab (i1:i2,j1:j2,k1:k2)
       ENDIF
       !
    END SUBROUTINE interpavm
-
-# endif /* key_zdftke */
 
 #else
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90	(revision 9019)
@@ -3,16 +3,22 @@
 MODULE agrif_opa_sponge
    !!======================================================================
-   !!                ***  MODULE agrif_opa_update  ***
-   !! AGRIF :   
+   !!                   ***  MODULE  agrif_opa_interp  ***
+   !! AGRIF: sponge package for the ocean dynamics (OPA)
    !!======================================================================
-   !! History :  
+   !! History :  2.0  !  2002-06  (XXX)  Original cade
+   !!             -   !  2005-11  (XXX) 
+   !!            3.2  !  2009-04  (R. Benshila) 
+   !!            3.6  !  2014-09  (R. Benshila) 
    !!----------------------------------------------------------------------
 #if defined key_agrif
+   !!----------------------------------------------------------------------
+   !!   'key_agrif'                                              AGRIF zoom
+   !!----------------------------------------------------------------------
    USE par_oce
    USE oce
    USE dom_oce
+   !
    USE in_out_manager
    USE agrif_oce
-   USE wrk_nemo  
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
 
@@ -24,5 +30,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.7 , NEMO Consortium (2015)
+   !! NEMO/NST 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -31,20 +37,20 @@
 
    SUBROUTINE Agrif_Sponge_Tra
-      !!---------------------------------------------
-      !!   *** ROUTINE Agrif_Sponge_Tra ***
-      !!---------------------------------------------
-      REAL(wp) :: timecoeff
-      !!---------------------------------------------
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE Agrif_Sponge_Tra ***
+      !!----------------------------------------------------------------------
+      REAL(wp) ::   zcoef   ! local scalar
+      !!----------------------------------------------------------------------
       !
 #if defined SPONGE
-      timecoeff = REAL(Agrif_NbStepint(),wp)/Agrif_rhot()
-
+      zcoef = REAL( Agrif_NbStepint(), wp ) / Agrif_rhot()
+      !
       CALL Agrif_Sponge
-      Agrif_SpecialValue=0.
+      Agrif_SpecialValue    = 0._wp
       Agrif_UseSpecialValue = .TRUE.
-      tabspongedone_tsn = .FALSE.
-
-      CALL Agrif_Bc_Variable(tsn_sponge_id,calledweight=timecoeff,procname=interptsn_sponge)
-
+      tabspongedone_tsn     = .FALSE.
+      !
+      CALL Agrif_Bc_Variable( tsn_sponge_id, calledweight=zcoef, procname=interptsn_sponge )
+      !
       Agrif_UseSpecialValue = .FALSE.
 #endif
@@ -54,24 +60,24 @@
 
    SUBROUTINE Agrif_Sponge_dyn
-      !!---------------------------------------------
-      !!   *** ROUTINE Agrif_Sponge_dyn ***
-      !!---------------------------------------------
-      REAL(wp) :: timecoeff
-      !!---------------------------------------------
-
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE Agrif_Sponge_dyn ***
+      !!----------------------------------------------------------------------
+      REAL(wp) ::   zcoef   ! local scalar
+      !!----------------------------------------------------------------------
+      !
 #if defined SPONGE
-      timecoeff = REAL(Agrif_NbStepint(),wp)/Agrif_rhot()
-
-      Agrif_SpecialValue=0.
+      zcoef = REAL( Agrif_NbStepint(), wp ) / Agrif_rhot()
+      !
+      Agrif_SpecialValue    = 0._wp
       Agrif_UseSpecialValue = ln_spc_dyn
-
+      !
       tabspongedone_u = .FALSE.
       tabspongedone_v = .FALSE.         
-      CALL Agrif_Bc_Variable(un_sponge_id,calledweight=timecoeff,procname=interpun_sponge)
-
+      CALL Agrif_Bc_Variable( un_sponge_id, calledweight=zcoef, procname=interpun_sponge )
+      !
       tabspongedone_u = .FALSE.
       tabspongedone_v = .FALSE.
-      CALL Agrif_Bc_Variable(vn_sponge_id,calledweight=timecoeff,procname=interpvn_sponge)
-
+      CALL Agrif_Bc_Variable( vn_sponge_id, calledweight=zcoef, procname=interpvn_sponge )
+      !
       Agrif_UseSpecialValue = .FALSE.
 #endif
@@ -81,70 +87,64 @@
 
    SUBROUTINE Agrif_Sponge
-      !!---------------------------------------------
-      !!   *** ROUTINE  Agrif_Sponge ***
-      !!---------------------------------------------
-      INTEGER  :: ji,jj,jk
-      INTEGER  :: ispongearea, ilci, ilcj
-      LOGICAL  :: ll_spdone
-      REAL(wp) :: z1spongearea, zramp
-      REAL(wp), POINTER, DIMENSION(:,:) :: ztabramp
-
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE  Agrif_Sponge ***
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, ind1, ind2
+      INTEGER  ::   ispongearea
+      REAL(wp) ::   z1_spongearea
+      REAL(wp), DIMENSION(jpi,jpj) :: ztabramp
+      !!----------------------------------------------------------------------
+      !
 #if defined SPONGE || defined SPONGE_TOP
-      ll_spdone=.TRUE.
       IF (( .NOT. spongedoneT ).OR.( .NOT. spongedoneU )) THEN
-         ! Define ramp from boundaries towards domain interior
-         ! at T-points
+         ! Define ramp from boundaries towards domain interior at T-points
          ! Store it in ztabramp
-         ll_spdone=.FALSE.
-
-         CALL wrk_alloc( jpi, jpj, ztabramp )
 
          ispongearea  = 2 + nn_sponge_len * Agrif_irhox()
-         ilci = nlci - ispongearea
-         ilcj = nlcj - ispongearea 
-         z1spongearea = 1._wp / REAL( ispongearea - 2 )
-
+         z1_spongearea = 1._wp / REAL( ispongearea - 1 )
+         
          ztabramp(:,:) = 0._wp
 
+         ! --- West --- !
          IF( (nbondi == -1) .OR. (nbondi == 2) ) THEN
+            ind1 = 1+nbghostcells
+            ind2 = 1+nbghostcells + (ispongearea-1)
             DO jj = 1, jpj
-               IF ( umask(2,jj,1) == 1._wp ) THEN
-                 DO ji = 2, ispongearea                  
-                    ztabramp(ji,jj) = ( ispongearea-ji ) * z1spongearea
-                 END DO
-               ENDIF
+               DO ji = ind1, ind2                  
+                  ztabramp(ji,jj) = REAL( ind2 - ji ) * z1_spongearea * umask(ind1,jj,1)
+               END DO
             ENDDO
          ENDIF
 
+         ! --- East --- !
          IF( (nbondi == 1) .OR. (nbondi == 2) ) THEN
+            ind1 = nlci - (1+nbghostcells) - (ispongearea-1)
+            ind2 = nlci - (1+nbghostcells)
             DO jj = 1, jpj
-               IF ( umask(nlci-2,jj,1) == 1._wp ) THEN
-                  DO ji = ilci+1,nlci-1
-                     zramp = (ji - (ilci+1) ) * z1spongearea
-                     ztabramp(ji,jj) = MAX( ztabramp(ji,jj), zramp )
-                  ENDDO
-               ENDIF
+               DO ji = ind1, ind2
+                  ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( ji - ind2 ) * z1_spongearea * umask(ind2-1,jj,1) )
+               ENDDO
             ENDDO
          ENDIF
 
+         ! --- South --- !
          IF( (nbondj == -1) .OR. (nbondj == 2) ) THEN
-            DO ji = 1, jpi
-               IF ( vmask(ji,2,1) == 1._wp ) THEN
-                  DO jj = 2, ispongearea
-                     zramp = ( ispongearea-jj ) * z1spongearea
-                     ztabramp(ji,jj) = MAX( ztabramp(ji,jj), zramp )
-                  END DO
-               ENDIF
+            ind1 = 1+nbghostcells
+            ind2 = 1+nbghostcells + (ispongearea-1)
+            DO jj = ind1, ind2
+               DO ji = 1, jpi
+                  ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( ind2 - jj ) * z1_spongearea * vmask(ji,ind1,1) )
+               END DO
             ENDDO
          ENDIF
 
+         ! --- North --- !
          IF( (nbondj == 1) .OR. (nbondj == 2) ) THEN
-            DO ji = 1, jpi
-               IF ( vmask(ji,nlcj-2,1) == 1._wp ) THEN
-                  DO jj = ilcj+1,nlcj-1
-                     zramp = (jj - (ilcj+1) ) * z1spongearea
-                     ztabramp(ji,jj) = MAX( ztabramp(ji,jj), zramp )
-                  END DO
-               ENDIF
+            ind1 = nlcj - (1+nbghostcells) - (ispongearea-1)
+            ind2 = nlcj - (1+nbghostcells)
+            DO jj = ind1, ind2
+               DO ji = 1, jpi
+                  ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( jj - ind2 ) * z1_spongearea * vmask(ji,ind2-1,1) )
+               END DO
             ENDDO
          ENDIF
@@ -158,11 +158,11 @@
          DO jj = 2, jpjm1
             DO ji = 2, jpim1   ! vector opt.
-               fsaht_spu(ji,jj) = 0.5_wp * visc_tra * (ztabramp(ji,jj) + ztabramp(ji+1,jj  ))
-               fsaht_spv(ji,jj) = 0.5_wp * visc_tra * (ztabramp(ji,jj) + ztabramp(ji  ,jj+1))
-            END DO
-         END DO
-
+               fsaht_spu(ji,jj) = 0.5_wp * visc_tra * ( ztabramp(ji,jj) + ztabramp(ji+1,jj  ) )
+               fsaht_spv(ji,jj) = 0.5_wp * visc_tra * ( ztabramp(ji,jj) + ztabramp(ji  ,jj+1) )
+            END DO
+         END DO
          CALL lbc_lnk( fsaht_spu, 'U', 1. )   ! Lateral boundary conditions
          CALL lbc_lnk( fsaht_spv, 'V', 1. )
+         
          spongedoneT = .TRUE.
       ENDIF
@@ -179,12 +179,10 @@
             END DO
          END DO
-
          CALL lbc_lnk( fsahm_spt, 'T', 1. )   ! Lateral boundary conditions
          CALL lbc_lnk( fsahm_spf, 'F', 1. )
+         
          spongedoneU = .TRUE.
       ENDIF
       !
-      IF (.NOT.ll_spdone) CALL wrk_dealloc( jpi, jpj, ztabramp )
-      !
 #endif
       !
@@ -192,11 +190,11 @@
 
 
-   SUBROUTINE interptsn_sponge(tabres,i1,i2,j1,j2,k1,k2,n1,n2,before)
-      !!---------------------------------------------
-      !!   *** ROUTINE interptsn_sponge ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2,n1,n2
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
+   SUBROUTINE interptsn_sponge( tabres, i1, i2, j1, j2, k1, k2, n1, n2, before )
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE interptsn_sponge ***
+      !!----------------------------------------------------------------------
+      INTEGER                                     , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2, n1, n2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) ::   tabres
+      LOGICAL                                     , INTENT(in   ) ::   before
       !
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
@@ -205,4 +203,5 @@
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: ztu, ztv
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2) ::tsbdiff
+      !!----------------------------------------------------------------------
       !
       IF( before ) THEN
@@ -241,5 +240,5 @@
                         zbtr = r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
                         ! horizontal diffusive trends
-                        ztsa = zbtr * (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk) + ztv(ji,jj,jk) - ztv(ji  ,jj-1,jk)  )
+                        ztsa = zbtr * (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk) + ztv(ji,jj,jk) - ztv(ji,jj-1,jk)  )
                         ! add it to the general tracer trends
                         tsa(ji,jj,jk,jn) = tsa(ji,jj,jk,jn) + ztsa
@@ -258,25 +257,24 @@
 
 
-   SUBROUTINE interpun_sponge(tabres,i1,i2,j1,j2,k1,k2, before)
-      !!---------------------------------------------
-      !!   *** ROUTINE interpun_sponge ***
-      !!---------------------------------------------    
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-
-      INTEGER :: ji,jj,jk
-
+   SUBROUTINE interpun_sponge( tabres, i1, i2, j1, j2, k1, k2, before )
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE interpun_sponge ***
+      !!----------------------------------------------------------------------
+      INTEGER                               , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) ::   tabres
+      LOGICAL                               , INTENT(in   ) ::   before
+      !!
+      INTEGER :: ji, jj, jk
       ! sponge parameters 
+      INTEGER :: jmax
       REAL(wp) :: ze2u, ze1v, zua, zva, zbtr
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: ubdiff
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: rotdiff, hdivdiff
-      INTEGER :: jmax
-      !!---------------------------------------------    
+      !!----------------------------------------------------------------------
       !
       IF( before ) THEN
          tabres = un(i1:i2,j1:j2,:)
       ELSE
-         ubdiff(i1:i2,j1:j2,:) = (ub(i1:i2,j1:j2,:) - tabres(:,:,:))*umask(i1:i2,j1:j2,:)
+         ubdiff(i1:i2,j1:j2,:) = ( ub(i1:i2,j1:j2,:) - tabres(:,:,:) )*umask(i1:i2,j1:j2,:)
          !
          DO jk = 1, jpkm1                                 ! Horizontal slab
@@ -297,7 +295,6 @@
                DO ji = i1,i2   ! vector opt.
                   zbtr = r1_e1e2f(ji,jj) * e3f_n(ji,jj,jk) * fsahm_spf(ji,jj)
-                  rotdiff(ji,jj,jk) = (-e1u(ji,jj+1) * ubdiff(ji,jj+1,jk) &
-                                       +e1u(ji,jj  ) * ubdiff(ji,jj  ,jk) & 
-                                    & ) * fmask(ji,jj,jk) * zbtr 
+                  rotdiff(ji,jj,jk) = ( -e1u(ji,jj+1) * ubdiff(ji,jj+1,jk)   &
+                                    &   +e1u(ji,jj  ) * ubdiff(ji,jj  ,jk) ) * fmask(ji,jj,jk) * zbtr 
                END DO
             END DO
@@ -312,6 +309,6 @@
                      ze1v = hdivdiff(ji,jj,jk)
                      ! horizontal diffusive trends
-                     zua = - ( ze2u - rotdiff (ji,jj-1,jk)) / ( e2u(ji,jj) * e3u_n(ji,jj,jk) )   &
-                           + ( hdivdiff(ji+1,jj,jk) - ze1v  ) / e1u(ji,jj)
+                     zua = - ( ze2u - rotdiff (ji,jj-1,jk) ) / ( e2u(ji,jj) * e3u_n(ji,jj,jk) )   &
+                           + ( hdivdiff(ji+1,jj,jk) - ze1v ) * r1_e1u(ji,jj)
 
                      ! add it to the general momentum trends
@@ -327,5 +324,5 @@
 
          jmax = j2-1
-         IF ((nbondj == 1).OR.(nbondj == 2)) jmax = MIN(jmax,nlcj-3)
+         IF ((nbondj == 1).OR.(nbondj == 2)) jmax = MIN(jmax,nlcj-nbghostcells-2)   ! North
 
          DO jj = j1+1, jmax
@@ -338,6 +335,6 @@
 
                      ! horizontal diffusive trends
-                     zva = + ( ze2u - rotdiff (ji-1,jj,jk)) / ( e1v(ji,jj) * e3v_n(ji,jj,jk) )   &
-                           + ( hdivdiff(ji,jj+1,jk) - ze1v  ) / e2v(ji,jj)
+                     zva = + ( ze2u - rotdiff (ji-1,jj,jk) ) / ( e1v(ji,jj) * e3v_n(ji,jj,jk) )   &
+                           + ( hdivdiff(ji,jj+1,jk) - ze1v ) * r1_e2v(ji,jj)
 
                      ! add it to the general momentum trends
@@ -356,19 +353,18 @@
 
 
-   SUBROUTINE interpvn_sponge(tabres,i1,i2,j1,j2,k1,k2, before,nb,ndir)
-      !!---------------------------------------------
-      !!   *** ROUTINE interpvn_sponge ***
-      !!--------------------------------------------- 
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-      INTEGER, INTENT(in) :: nb , ndir
-      !
-      INTEGER  ::   ji, jj, jk
-      REAL(wp) ::   ze2u, ze1v, zua, zva, zbtr
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: vbdiff
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: rotdiff, hdivdiff
-      INTEGER :: imax
-      !!--------------------------------------------- 
+   SUBROUTINE interpvn_sponge( tabres, i1, i2, j1, j2, k1, k2, before, nb, ndir )
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE interpvn_sponge ***
+      !!----------------------------------------------------------------------
+      INTEGER                               , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) ::   tabres
+      LOGICAL                               , INTENT(in   ) ::   before
+      INTEGER                               , INTENT(in   ) ::   nb , ndir
+      !
+      INTEGER ::   ji, jj, jk
+      INTEGER ::   imax
+      REAL(wp)::   ze2u, ze1v, zua, zva, zbtr
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) ::   vbdiff, rotdiff, hdivdiff
+      !!----------------------------------------------------------------------
 
       IF( before ) THEN 
@@ -376,5 +372,5 @@
       ELSE
          !
-         vbdiff(i1:i2,j1:j2,:) = (vb(i1:i2,j1:j2,:) - tabres(:,:,:))*vmask(i1:i2,j1:j2,:)
+         vbdiff(i1:i2,j1:j2,:) = ( vb(i1:i2,j1:j2,:) - tabres(:,:,:) ) * vmask(i1:i2,j1:j2,:)
          !
          DO jk = 1, jpkm1                                 ! Horizontal slab
@@ -403,6 +399,6 @@
          !                                                
 
-         imax = i2-1
-         IF ((nbondi == 1).OR.(nbondi == 2))   imax = MIN(imax,nlci-3)
+         imax = i2 - 1
+         IF ((nbondi == 1).OR.(nbondi == 2))   imax = MIN(imax,nlci-nbghostcells-2)   ! East
 
          DO jj = j1+1, j2
@@ -437,9 +433,9 @@
 
 #else
+   !!----------------------------------------------------------------------
+   !!   Empty module                                          no AGRIF zoom
+   !!----------------------------------------------------------------------
 CONTAINS
    SUBROUTINE agrif_opa_sponge_empty
-      !!---------------------------------------------
-      !!   *** ROUTINE agrif_OPA_sponge_empty ***
-      !!---------------------------------------------
       WRITE(*,*)  'agrif_opa_sponge : You should not have seen this print! error?'
    END SUBROUTINE agrif_opa_sponge_empty
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 9019)
@@ -3,23 +3,32 @@
  
 MODULE agrif_opa_update
+   !!======================================================================
+   !!                   ***  MODULE  agrif_opa_interp  ***
+   !! AGRIF: update package for the ocean dynamics (OPA)
+   !!======================================================================
+   !! History :  2.0  !  2002-06  (L. Debreu)  Original code
+   !!            3.2  !  2009-04  (R. Benshila) 
+   !!            3.6  !  2014-09  (R. Benshila) 
+   !!----------------------------------------------------------------------
 #if defined key_agrif 
+   !!----------------------------------------------------------------------
+   !!   'key_agrif'                                              AGRIF zoom
+   !!----------------------------------------------------------------------
    USE par_oce
    USE oce
    USE dom_oce
+   USE zdf_oce        ! vertical physics: ocean variables 
    USE agrif_oce
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp
-   USE wrk_nemo  
-   USE zdf_oce        ! vertical physics: ocean variables 
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC Agrif_Update_Tra, Agrif_Update_Dyn,Update_Scales
-# if defined key_zdftke
-   PUBLIC Agrif_Update_Tke
-# endif
+   PUBLIC   Agrif_Update_Tra, Agrif_Update_Dyn, Update_Scales
+
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.6 , NEMO Consortium (2010)
+   !! NEMO/NST 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -28,7 +37,7 @@
 
    RECURSIVE SUBROUTINE Agrif_Update_Tra( )
-      !!---------------------------------------------
-      !!   *** ROUTINE Agrif_Update_Tra ***
-      !!---------------------------------------------
+      !!----------------------------------------------------------------------
+      !!                   *** ROUTINE Agrif_Update_Tra ***
+      !!----------------------------------------------------------------------
       ! 
       IF (Agrif_Root()) RETURN
@@ -38,5 +47,5 @@
 
       Agrif_UseSpecialValueInUpdate = .TRUE.
-      Agrif_SpecialValueFineGrid = 0.
+      Agrif_SpecialValueFineGrid    = 0._wp
       ! 
       IF (MOD(nbcline,nbclineupdate) == 0) THEN
@@ -68,7 +77,7 @@
 
    RECURSIVE SUBROUTINE Agrif_Update_Dyn( )
-      !!---------------------------------------------
-      !!   *** ROUTINE Agrif_Update_Dyn ***
-      !!---------------------------------------------
+      !!----------------------------------------------------------------------
+      !!                   *** ROUTINE Agrif_Update_Dyn ***
+      !!----------------------------------------------------------------------
       ! 
       IF (Agrif_Root()) RETURN
@@ -106,5 +115,5 @@
 # endif
 
-      IF ( ln_dynspg_ts.AND.ln_bt_fw ) THEN
+      IF ( ln_dynspg_ts .AND. ln_bt_fw ) THEN
          ! Update time integrated transports
          IF (mod(nbcline,nbclineupdate) == 0) THEN
@@ -149,47 +158,21 @@
    END SUBROUTINE Agrif_Update_Dyn
 
-# if defined key_zdftke
-
-   SUBROUTINE Agrif_Update_Tke( kt )
-      !!---------------------------------------------
-      !!   *** ROUTINE Agrif_Update_Tke ***
-      !!---------------------------------------------
-      !!
-      INTEGER, INTENT(in) :: kt
-      !       
-      IF( ( Agrif_NbStepint() .NE. 0 ) .AND. (kt /= 0) ) RETURN
-#  if defined TWO_WAY
-
-      Agrif_UseSpecialValueInUpdate = .TRUE.
-      Agrif_SpecialValueFineGrid = 0.
-
-      CALL Agrif_Update_Variable( en_id, locupdate=(/0,0/), procname=updateEN  )
-      CALL Agrif_Update_Variable(avt_id, locupdate=(/0,0/), procname=updateAVT )
-      CALL Agrif_Update_Variable(avm_id, locupdate=(/0,0/), procname=updateAVM )
-
-      Agrif_UseSpecialValueInUpdate = .FALSE.
-
-#  endif
-      
-   END SUBROUTINE Agrif_Update_Tke
-   
-# endif /* key_zdftke */
 
    SUBROUTINE updateTS( tabres, i1, i2, j1, j2, k1, k2, n1, n2, before )
-      !!---------------------------------------------
+      !!----------------------------------------------------------------------
       !!           *** ROUTINE updateT ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2,n1,n2
-      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-      !!
-      INTEGER :: ji,jj,jk,jn
-      !!---------------------------------------------
-      !
-      IF (before) THEN
-         DO jn = n1,n2
-            DO jk=k1,k2
-               DO jj=j1,j2
-                  DO ji=i1,i2
+      !!----------------------------------------------------------------------
+      INTEGER                                    , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2, n1, n2
+      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) ::   tabres
+      LOGICAL                                    , INTENT(in   ) ::   before
+      !
+      INTEGER :: ji, jj, jk, jn
+      !!----------------------------------------------------------------------
+      !
+      IF( before ) THEN
+         DO jn = n1, n2
+            DO jk = k1, k2
+               DO jj = j1, j2
+                  DO ji = i1, i2
                      tabres(ji,jj,jk,jn) = tsn(ji,jj,jk,jn)
                   END DO
@@ -201,16 +184,15 @@
             ! Add asselin part
             DO jn = n1,n2
-               DO jk=k1,k2
-                  DO jj=j1,j2
-                     DO ji=i1,i2
-                        IF( tabres(ji,jj,jk,jn) .NE. 0. ) THEN
+               DO jk = k1, k2
+                  DO jj = j1, j2
+                     DO ji = i1, i2
+                        IF( tabres(ji,jj,jk,jn) /= 0._wp ) THEN
                            tsb(ji,jj,jk,jn) = tsb(ji,jj,jk,jn) & 
-                                 & + atfp * ( tabres(ji,jj,jk,jn) &
-                                 &             - tsn(ji,jj,jk,jn) ) * tmask(ji,jj,jk)
+                              &             + atfp * ( tabres(ji,jj,jk,jn) - tsn(ji,jj,jk,jn) ) * tmask(ji,jj,jk)
                         ENDIF
-                     ENDDO
-                  ENDDO
-               ENDDO
-            ENDDO
+                     END DO
+                  END DO
+               END DO
+            END DO
          ENDIF
          DO jn = n1,n2
@@ -218,5 +200,5 @@
                DO jj=j1,j2
                   DO ji=i1,i2
-                     IF( tabres(ji,jj,jk,jn) .NE. 0. ) THEN 
+                     IF( tabres(ji,jj,jk,jn) /= 0._wp ) THEN 
                         tsn(ji,jj,jk,jn) = tabres(ji,jj,jk,jn) * tmask(ji,jj,jk)
                      END IF
@@ -238,6 +220,6 @@
       LOGICAL                               , INTENT(in   ) :: before
       !
-      INTEGER  ::   ji, jj, jk
-      REAL(wp) ::   zrhoy
+      INTEGER ::   ji, jj, jk
+      REAL(wp)::   zrhoy
       !!---------------------------------------------
       ! 
@@ -268,20 +250,20 @@
 
    SUBROUTINE updatev( tabres, i1, i2, j1, j2, k1, k2, before )
-      !!---------------------------------------------
-      !!           *** ROUTINE updatev ***
-      !!---------------------------------------------
-      INTEGER :: i1,i2,j1,j2,k1,k2
-      INTEGER :: ji,jj,jk
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: tabres
-      LOGICAL :: before
+      !!----------------------------------------------------------------------
+      !!                      *** ROUTINE updatev ***
+      !!----------------------------------------------------------------------
+      INTEGER                               , INTENT(in   ) :: i1, i2, j1, j2, k1, k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: tabres
+      LOGICAL                               , INTENT(in   ) :: before
       !!
-      REAL(wp) :: zrhox
-      !!---------------------------------------------      
-      !
-      IF (before) THEN
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   zrhox
+      !!----------------------------------------------------------------------
+      !
+      IF( before ) THEN
          zrhox = Agrif_Rhox()
-         DO jk=k1,k2
-            DO jj=j1,j2
-               DO ji=i1,i2
+         DO jk = k1, k2
+            DO jj = j1, j2
+               DO ji = i1, i2
                   tabres(ji,jj,jk) = zrhox * e1v(ji,jj) * e3v_n(ji,jj,jk) * vn(ji,jj,jk)
                END DO
@@ -289,12 +271,12 @@
          END DO
       ELSE
-         DO jk=k1,k2
-            DO jj=j1,j2
-               DO ji=i1,i2
+         DO jk = k1, k2
+            DO jj = j1, j2
+               DO ji = i1, i2
                   tabres(ji,jj,jk) = tabres(ji,jj,jk) * r1_e1v(ji,jj) / e3v_n(ji,jj,jk)
                   !
-                  IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN ! Add asselin part
+                  IF( .NOT.(lk_agrif_fstep.AND.(neuler==0)) ) THEN ! Add asselin part
                      vb(ji,jj,jk) = vb(ji,jj,jk) & 
-                           & + atfp * ( tabres(ji,jj,jk) - vn(ji,jj,jk) ) * vmask(ji,jj,jk)
+                        &         + atfp * ( tabres(ji,jj,jk) - vn(ji,jj,jk) ) * vmask(ji,jj,jk)
                   ENDIF
                   !
@@ -309,17 +291,16 @@
 
    SUBROUTINE updateu2d( tabres, i1, i2, j1, j2, before )
+      !!----------------------------------------------------------------------
+      !!                      *** ROUTINE updateu2d ***
+      !!----------------------------------------------------------------------
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   tabres
+      LOGICAL                         , INTENT(in   ) ::   before
+      !! 
+      INTEGER ::   ji, jj, jk
+      REAL(wp)::   zrhoy, zcorr
       !!---------------------------------------------
-      !!          *** ROUTINE updateu2d ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-      !! 
-      INTEGER :: ji, jj, jk
-      REAL(wp) :: zrhoy
-      REAL(wp) :: zcorr
-      !!---------------------------------------------
-      !
-      IF (before) THEN
+      !
+      IF( before ) THEN
          zrhoy = Agrif_Rhoy()
          DO jj=j1,j2
@@ -374,17 +355,16 @@
 
    SUBROUTINE updatev2d( tabres, i1, i2, j1, j2, before )
-      !!---------------------------------------------
-      !!          *** ROUTINE updatev2d ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-      !! 
+      !!----------------------------------------------------------------------
+      !!                   *** ROUTINE updatev2d ***
+      !!----------------------------------------------------------------------
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   tabres
+      LOGICAL                         , INTENT(in   ) ::   before
+      ! 
       INTEGER :: ji, jj, jk
-      REAL(wp) :: zrhox
-      REAL(wp) :: zcorr
-      !!---------------------------------------------
-      !
-      IF (before) THEN
+      REAL(wp) :: zrhox, zcorr
+      !!----------------------------------------------------------------------
+      !
+      IF( before ) THEN
          zrhox = Agrif_Rhox()
          DO jj=j1,j2
@@ -439,15 +419,15 @@
 
    SUBROUTINE updateSSH( tabres, i1, i2, j1, j2, before )
-      !!---------------------------------------------
-      !!          *** ROUTINE updateSSH ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
+      !!----------------------------------------------------------------------
+      !!                   *** ROUTINE updateSSH ***
+      !!----------------------------------------------------------------------
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   tabres
+      LOGICAL                         , INTENT(in   ) ::   before
       !!
       INTEGER :: ji, jj
-      !!---------------------------------------------
-      ! 
-      IF (before) THEN
+      !!----------------------------------------------------------------------
+      ! 
+      IF( before ) THEN
          DO jj=j1,j2
             DO ji=i1,i2
@@ -478,14 +458,14 @@
 
    SUBROUTINE updateub2b( tabres, i1, i2, j1, j2, before )
-      !!---------------------------------------------
-      !!          *** ROUTINE updateub2b ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
+      !!----------------------------------------------------------------------
+      !!                      *** ROUTINE updateub2b ***
+      !!----------------------------------------------------------------------
+      INTEGER                            , INTENT(in) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   tabres
+      LOGICAL                            , INTENT(in) ::   before
       !!
-      INTEGER :: ji, jj
-      REAL(wp) :: zrhoy
-      !!---------------------------------------------
+      INTEGER ::   ji, jj
+      REAL(wp)::   zrhoy
+      !!----------------------------------------------------------------------
       !
       IF (before) THEN
@@ -509,16 +489,16 @@
 
    SUBROUTINE updatevb2b( tabres, i1, i2, j1, j2, before )
-      !!---------------------------------------------
-      !!          *** ROUTINE updatevb2b ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
+      !!----------------------------------------------------------------------
+      !!                      *** ROUTINE updatevb2b ***
+      !!----------------------------------------------------------------------
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   tabres
+      LOGICAL                         , INTENT(in   ) ::   before
       !!
-      INTEGER :: ji, jj
-      REAL(wp) :: zrhox
-      !!---------------------------------------------
-      !
-      IF (before) THEN
+      INTEGER ::   ji, jj
+      REAL(wp)::   zrhox
+      !!----------------------------------------------------------------------
+      !
+      IF( before ) THEN
          zrhox = Agrif_Rhox()
          DO jj=j1,j2
@@ -540,15 +520,17 @@
 
    SUBROUTINE update_scales( tabres, i1, i2, j1, j2, k1, k2, n1,n2, before )
-      ! currently not used
-      !!---------------------------------------------
-      !!           *** ROUTINE updateT ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2,n1,n2
-      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) :: tabres
-      LOGICAL, iNTENT(in) :: before
-      !
+      !
+      ! ====>>>>>>>>>>    currently not used
+      !
+      !!----------------------------------------------------------------------
+      !!                      *** ROUTINE updateT ***
+      !!----------------------------------------------------------------------
+      INTEGER                                    , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2, n1, n2
+      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) ::   tabres
+      LOGICAL                                    , INTENT(in   ) ::   before
+      !!
       INTEGER :: ji,jj,jk
       REAL(wp) :: ztemp
-      !!---------------------------------------------
+      !!----------------------------------------------------------------------
 
       IF (before) THEN
@@ -587,16 +569,15 @@
    END SUBROUTINE update_scales
 
-# if defined key_zdftke
 
    SUBROUTINE updateEN( ptab, i1, i2, j1, j2, k1, k2, before )
-      !!---------------------------------------------
-      !!           *** ROUTINE updateen ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2, k1, k2
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab
-      LOGICAL, INTENT(in) :: before
-      !!---------------------------------------------
-      !
-      IF (before) THEN
+      !!----------------------------------------------------------------------
+      !!                      *** ROUTINE updateen ***
+      !!----------------------------------------------------------------------
+      INTEGER                               , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) ::   ptab
+      LOGICAL                               , INTENT(in   ) ::   before
+      !!----------------------------------------------------------------------
+      !
+      IF( before ) THEN
          ptab (i1:i2,j1:j2,k1:k2) = en(i1:i2,j1:j2,k1:k2)
       ELSE
@@ -608,16 +589,14 @@
 
    SUBROUTINE updateAVT( ptab, i1, i2, j1, j2, k1, k2, before )
-      !!---------------------------------------------
-      !!           *** ROUTINE updateavt ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2, k1, k2
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab
-      LOGICAL, INTENT(in) :: before
-      !!---------------------------------------------
-      !
-      IF (before) THEN
-         ptab (i1:i2,j1:j2,k1:k2) = avt_k(i1:i2,j1:j2,k1:k2)
-      ELSE
-         avt_k(i1:i2,j1:j2,k1:k2) = ptab (i1:i2,j1:j2,k1:k2) 
+      !!----------------------------------------------------------------------
+      !!                      *** ROUTINE updateavt ***
+      !!----------------------------------------------------------------------
+      INTEGER                               , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) ::   ptab
+      LOGICAL                               , INTENT(in   ) ::   before
+      !!----------------------------------------------------------------------
+      !
+      IF( before ) THEN   ;   ptab (i1:i2,j1:j2,k1:k2) = avt_k(i1:i2,j1:j2,k1:k2)
+      ELSE                ;   avt_k(i1:i2,j1:j2,k1:k2) = ptab (i1:i2,j1:j2,k1:k2) 
       ENDIF
       !
@@ -628,29 +607,27 @@
       !!---------------------------------------------
       !!           *** ROUTINE updateavm ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2, k1, k2
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab
-      LOGICAL, INTENT(in) :: before
-      !!---------------------------------------------
-      !
-      IF (before) THEN
-         ptab (i1:i2,j1:j2,k1:k2) = avm_k(i1:i2,j1:j2,k1:k2)
-      ELSE
-         avm_k(i1:i2,j1:j2,k1:k2) = ptab (i1:i2,j1:j2,k1:k2) 
+      !!----------------------------------------------------------------------
+      INTEGER                               , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) ::   ptab
+      LOGICAL                               , INTENT(in   ) ::   before
+      !!----------------------------------------------------------------------
+      !
+      IF( before ) THEN   ;   ptab (i1:i2,j1:j2,k1:k2) = avm_k(i1:i2,j1:j2,k1:k2)
+      ELSE                ;   avm_k(i1:i2,j1:j2,k1:k2) = ptab (i1:i2,j1:j2,k1:k2) 
       ENDIF
       !
    END SUBROUTINE updateAVM
 
-# endif /* key_zdftke */ 
-
 #else
+   !!----------------------------------------------------------------------
+   !!   Empty module                                          no AGRIF zoom
+   !!----------------------------------------------------------------------
 CONTAINS
    SUBROUTINE agrif_opa_update_empty
-      !!---------------------------------------------
-      !!   *** ROUTINE agrif_opa_update_empty ***
-      !!---------------------------------------------
       WRITE(*,*)  'agrif_opa_update : You should not have seen this print! error?'
    END SUBROUTINE agrif_opa_update_empty
 #endif
+
+   !!======================================================================
 END MODULE agrif_opa_update
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_top_interp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_top_interp.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_top_interp.F90	(revision 9019)
@@ -1,4 +1,14 @@
 MODULE agrif_top_interp
+   !!======================================================================
+   !!                   ***  MODULE  agrif_top_interp  ***
+   !! AGRIF: interpolation package for TOP
+   !!======================================================================
+   !! History :  2.0  !  ??? 
+   !!----------------------------------------------------------------------
 #if defined key_agrif && defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_agrif'                                              AGRIF zoom
+   !!   'key_top'                                           on-line tracers
+   !!----------------------------------------------------------------------
    USE par_oce
    USE oce
@@ -8,6 +18,6 @@
    USE par_trc
    USE trc
-   USE lib_mpp
-   USE wrk_nemo  
+   !
+   USE lib_mpp     ! MPP library
 
    IMPLICIT NONE
@@ -16,7 +26,6 @@
    PUBLIC Agrif_trc, interptrn
 
-#  include "vectopt_loop_substitute.h90"
   !!----------------------------------------------------------------------
-   !! NEMO/NST 3.6 , NEMO Consortium (2010)
+   !! NEMO/NST 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -26,12 +35,12 @@
    SUBROUTINE Agrif_trc
       !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE Agrif_trc  ***
+      !!                   ***  ROUTINE Agrif_trc  ***
       !!----------------------------------------------------------------------
       !
       IF( Agrif_Root() )   RETURN
-
-      Agrif_SpecialValue    = 0.e0
+      !
+      Agrif_SpecialValue    = 0._wp
       Agrif_UseSpecialValue = .TRUE.
-
+      !
       CALL Agrif_Bc_variable( trn_id, procname=interptrn )
       Agrif_UseSpecialValue = .FALSE.
@@ -40,144 +49,130 @@
 
 
-   SUBROUTINE interptrn(ptab,i1,i2,j1,j2,k1,k2,n1,n2,before,nb,ndir)
-      !!---------------------------------------------
-      !!   *** ROUTINE interptrn ***
-      !!---------------------------------------------
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) :: ptab
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2,n1,n2
-      LOGICAL, INTENT(in) :: before
-      INTEGER, INTENT(in) :: nb , ndir
+   SUBROUTINE interptrn( ptab, i1, i2, j1, j2, k1, k2, n1, n2, before, nb, ndir )
+      !!----------------------------------------------------------------------
+      !!                   *** ROUTINE interptrn ***
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) ::   ptab
+      INTEGER                                     , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2, n1, n2
+      LOGICAL                                     , INTENT(in   ) ::   before
+      INTEGER                                     , INTENT(in   ) ::   nb , ndir
+      !!
+      INTEGER ::   ji, jj, jk, jn   ! dummy loop indices
+      INTEGER ::   imin, imax, jmin, jmax
+      LOGICAL ::   ll_west, ll_east, ll_north, ll_south
+      REAL(wp) ::   zrhox, z1, z2, z3, z4, z5, z6, z7
+      !!----------------------------------------------------------------------
       !
-      INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
-      INTEGER :: imin, imax, jmin, jmax
-      REAL(wp) ::   zrhox , zalpha1, zalpha2, zalpha3
-      REAL(wp) ::   zalpha4, zalpha5, zalpha6, zalpha7
-      LOGICAL :: western_side, eastern_side,northern_side,southern_side
-
-      IF (before) THEN         
+      IF( before ) THEN         
          ptab(i1:i2,j1:j2,k1:k2,n1:n2) = trn(i1:i2,j1:j2,k1:k2,n1:n2)
       ELSE
          !
-         western_side  = (nb == 1).AND.(ndir == 1)
-         eastern_side  = (nb == 1).AND.(ndir == 2)
-         southern_side = (nb == 2).AND.(ndir == 1)
-         northern_side = (nb == 2).AND.(ndir == 2)
-         !
-         zrhox = Agrif_Rhox()
-         ! 
-         zalpha1 = ( zrhox - 1. ) * 0.5
-         zalpha2 = 1. - zalpha1
-         ! 
-         zalpha3 = ( zrhox - 1. ) / ( zrhox + 1. )
-         zalpha4 = 1. - zalpha3
-         ! 
-         zalpha6 = 2. * ( zrhox - 1. ) / ( zrhox + 1. )
-         zalpha7 =    - ( zrhox - 1. ) / ( zrhox + 3. )
-         zalpha5 = 1. - zalpha6 - zalpha7
-         !
-         imin = i1
-         imax = i2
-         jmin = j1
-         jmax = j2
-         ! 
-         ! Remove CORNERS
-         IF((nbondj == -1).OR.(nbondj == 2)) jmin = 3
-         IF((nbondj == +1).OR.(nbondj == 2)) jmax = nlcj-2
-         IF((nbondi == -1).OR.(nbondi == 2)) imin = 3
-         IF((nbondi == +1).OR.(nbondi == 2)) imax = nlci-2        
-         !
-         IF( eastern_side) THEN
-            DO jn = 1, jptra
-               tra(nlci,j1:j2,k1:k2,jn) = zalpha1 * ptab(nlci,j1:j2,k1:k2,jn) + zalpha2 * ptab(nlci-1,j1:j2,k1:k2,jn)
-               DO jk = 1, jpkm1
-                  DO jj = jmin,jmax
-                     IF( umask(nlci-2,jj,jk) == 0.e0 ) THEN
-                        tra(nlci-1,jj,jk,jn) = tra(nlci,jj,jk,jn) * tmask(nlci-1,jj,jk)
-                     ELSE
-                        tra(nlci-1,jj,jk,jn)=(zalpha4*tra(nlci,jj,jk,jn)+zalpha3*tra(nlci-2,jj,jk,jn))*tmask(nlci-1,jj,jk)
-                        IF( un(nlci-2,jj,jk) > 0.e0 ) THEN
-                           tra(nlci-1,jj,jk,jn)=( zalpha6*tra(nlci-2,jj,jk,jn)+zalpha5*tra(nlci,jj,jk,jn) & 
-                                 + zalpha7*tra(nlci-3,jj,jk,jn) ) * tmask(nlci-1,jj,jk)
+         IF( nbghostcells > 1 ) THEN  ! no smoothing
+            tra(i1:i2,j1:j2,k1:k2,n1:n2) = ptab(i1:i2,j1:j2,k1:k2,n1:n2)
+         ELSE                         ! smoothing
+            !
+            ll_west  = (nb == 1).AND.(ndir == 1)   ;   ll_east  = (nb == 1).AND.(ndir == 2)
+            ll_south = (nb == 2).AND.(ndir == 1)   ;   ll_north = (nb == 2).AND.(ndir == 2)
+            !
+            zrhox = Agrif_Rhox()
+            z1 = ( zrhox - 1. ) * 0.5
+            z3 = ( zrhox - 1. ) / ( zrhox + 1. )
+            z6 = 2. * ( zrhox - 1. ) / ( zrhox + 1. )
+            z7 =    - ( zrhox - 1. ) / ( zrhox + 3. )
+            !
+            z2 = 1. - z1
+            z4 = 1. - z3
+            z5 = 1. - z6 - z7
+            !
+            imin = i1   ;   imax = i2
+            jmin = j1   ;   jmax = j2
+            ! 
+            ! Remove CORNERS
+            IF((nbondj == -1).OR.(nbondj == 2))   jmin = 3
+            IF((nbondj == +1).OR.(nbondj == 2))   jmax = nlcj-2
+            IF((nbondi == -1).OR.(nbondi == 2))   imin = 3
+            IF((nbondi == +1).OR.(nbondi == 2))   imax = nlci-2        
+            !
+            IF( ll_east ) THEN       !== eastern side  ==!
+               DO jn = 1, jptra
+                  tra(nlci,j1:j2,k1:k2,jn) = z1 * ptab(nlci,j1:j2,k1:k2,jn) + z2 * ptab(nlci-1,j1:j2,k1:k2,jn)
+                  DO jk = 1, jpkm1
+                     DO jj = jmin,jmax
+                        IF( umask(nlci-2,jj,jk) == 0._wp ) THEN
+                           tra(nlci-1,jj,jk,jn) = tra(nlci,jj,jk,jn) * tmask(nlci-1,jj,jk)
+                        ELSE
+                           tra(nlci-1,jj,jk,jn) = ( z4*tra(nlci,jj,jk,jn)+z3*tra(nlci-2,jj,jk,jn) ) * tmask(nlci-1,jj,jk)
+                           IF( un(nlci-2,jj,jk) > 0._wp ) THEN
+                              tra(nlci-1,jj,jk,jn) = ( z6*tra(nlci-2,jj,jk,jn)+z5*tra(nlci,jj,jk,jn)   & 
+                                 &                    +z7*tra(nlci-3,jj,jk,jn) ) * tmask(nlci-1,jj,jk)
+                           ENDIF
                         ENDIF
-                     ENDIF
+                     END DO
+                  END DO
+               ENDDO
+            ENDIF
+            ! 
+            IF( ll_north ) THEN        !==  northern side  ==!
+               DO jn = 1, jptra
+                  tra(i1:i2,nlcj,k1:k2,jn) = z1 * ptab(i1:i2,nlcj,k1:k2,jn) + z2 * ptab(i1:i2,nlcj-1,k1:k2,jn)
+                  DO jk = 1, jpkm1
+                     DO ji = imin, imax
+                        IF( vmask(ji,nlcj-2,jk) == 0._wp ) THEN
+                           tra(ji,nlcj-1,jk,jn) = tra(ji,nlcj,jk,jn) * tmask(ji,nlcj-1,jk)
+                        ELSE
+                           tra(ji,nlcj-1,jk,jn) = ( z4*tra(ji,nlcj,jk,jn)+z3*tra(ji,nlcj-2,jk,jn) ) * tmask(ji,nlcj-1,jk)        
+                           IF (vn(ji,nlcj-2,jk) > 0._wp ) THEN
+                              tra(ji,nlcj-1,jk,jn) = ( z6*tra(ji,nlcj-2,jk,jn)+z5*tra(ji,nlcj,jk,jn)  &
+                                 &                    +z7*tra(ji,nlcj-3,jk,jn) ) * tmask(ji,nlcj-1,jk)
+                           ENDIF
+                        ENDIF
+                     END DO
                   END DO
                END DO
-            ENDDO
-         ENDIF
-         ! 
-         IF( northern_side ) THEN            
-            DO jn = 1, jptra
-               tra(i1:i2,nlcj,k1:k2,jn) = zalpha1 * ptab(i1:i2,nlcj,k1:k2,jn) + zalpha2 * ptab(i1:i2,nlcj-1,k1:k2,jn)
-               DO jk = 1, jpkm1
-                  DO ji = imin,imax
-                     IF( vmask(ji,nlcj-2,jk) == 0.e0 ) THEN
-                        tra(ji,nlcj-1,jk,jn) = tra(ji,nlcj,jk,jn) * tmask(ji,nlcj-1,jk)
-                     ELSE
-                        tra(ji,nlcj-1,jk,jn)=(zalpha4*tra(ji,nlcj,jk,jn)+zalpha3*tra(ji,nlcj-2,jk,jn))*tmask(ji,nlcj-1,jk)        
-                        IF (vn(ji,nlcj-2,jk) > 0.e0 ) THEN
-                           tra(ji,nlcj-1,jk,jn)=( zalpha6*tra(ji,nlcj-2,jk,jn)+zalpha5*tra(ji,nlcj,jk,jn)  &
-                                 + zalpha7*tra(ji,nlcj-3,jk,jn) ) * tmask(ji,nlcj-1,jk)
+            ENDIF
+            !
+            IF( ll_west ) THEN         !==  western side  ==!          
+               DO jn = 1, jptra
+                  tra(1,j1:j2,k1:k2,jn) = z1 * ptab(1,j1:j2,k1:k2,jn) + z2 * ptab(2,j1:j2,k1:k2,jn)
+                  DO jk = 1, jpkm1
+                     DO jj = jmin,jmax
+                        IF( umask(2,jj,jk) == 0._wp ) THEN
+                           tra(2,jj,jk,jn) = tra(1,jj,jk,jn) * tmask(2,jj,jk)
+                        ELSE
+                           tra(2,jj,jk,jn) = ( z4*tra(1,jj,jk,jn)+z3*tra(3,jj,jk,jn) ) * tmask(2,jj,jk)        
+                           IF( un(2,jj,jk) < 0._wp ) THEN
+                              tra(2,jj,jk,jn) = ( z6*tra(3,jj,jk,jn)+z5*tra(1,jj,jk,jn)+z7*tra(4,jj,jk,jn) ) * tmask(2,jj,jk)
+                           ENDIF
                         ENDIF
-                     ENDIF
+                     END DO
                   END DO
                END DO
-            ENDDO
-         ENDIF
-         !
-         IF( western_side) THEN            
-            DO jn = 1, jptra
-               tra(1,j1:j2,k1:k2,jn) = zalpha1 * ptab(1,j1:j2,k1:k2,jn) + zalpha2 * ptab(2,j1:j2,k1:k2,jn)
-               DO jk = 1, jpkm1
-                  DO jj = jmin,jmax
-                     IF( umask(2,jj,jk) == 0.e0 ) THEN
-                        tra(2,jj,jk,jn) = tra(1,jj,jk,jn) * tmask(2,jj,jk)
-                     ELSE
-                        tra(2,jj,jk,jn)=(zalpha4*tra(1,jj,jk,jn)+zalpha3*tra(3,jj,jk,jn))*tmask(2,jj,jk)        
-                        IF( un(2,jj,jk) < 0.e0 ) THEN
-                           tra(2,jj,jk,jn)=(zalpha6*tra(3,jj,jk,jn)+zalpha5*tra(1,jj,jk,jn)+zalpha7*tra(4,jj,jk,jn))*tmask(2,jj,jk)
+            ENDIF
+            !
+            IF( ll_south ) THEN        !==  southern side  ==!
+               DO jn = 1, jptra
+                  tra(i1:i2,1,k1:k2,jn) = z1 * ptab(i1:i2,1,k1:k2,jn) + z2 * ptab(i1:i2,2,k1:k2,jn)
+                  DO jk = 1, jpk      
+                     DO ji = imin, imax
+                        IF( vmask(ji,2,jk) == 0._wp ) THEN
+                           tra(ji,2,jk,jn) = tra(ji,1,jk,jn) * tmask(ji,2,jk)
+                        ELSE
+                           tra(ji,2,jk,jn) = ( z4*tra(ji,1,jk,jn)+z3*tra(ji,3,jk,jn) ) * tmask(ji,2,jk)
+                           IF( vn(ji,2,jk) < 0._wp ) THEN
+                              tra(ji,2,jk,jn) = ( z6*tra(ji,3,jk,jn)+z5*tra(ji,1,jk,jn)+z7*tra(ji,4,jk,jn) ) * tmask(ji,2,jk)
+                           ENDIF
                         ENDIF
-                     ENDIF
+                     END DO
                   END DO
                END DO
-            END DO
+            ENDIF
+            !
+            ! Treatment of corners
+            IF( ll_east .AND.((nbondj == -1).OR.(nbondj == 2)) )   tra(nlci-1,   2  ,:,:) = ptab(nlci-1,   2  ,:,:)   ! East south
+            IF( ll_east .AND.((nbondj ==  1).OR.(nbondj == 2)) )   tra(nlci-1,nlcj-1,:,:) = ptab(nlci-1,nlcj-1,:,:)   ! East north
+            IF( ll_west .AND.((nbondj == -1).OR.(nbondj == 2)) )   tra(   2  ,   2  ,:,:) = ptab(   2  ,   2  ,:,:)   ! West south
+            IF( ll_west .AND.((nbondj ==  1).OR.(nbondj == 2)) )   tra(   2  ,nlcj-1,:,:) = ptab(   2  ,nlcj-1,:,:)   ! West north
+            !
          ENDIF
-         !
-         IF( southern_side ) THEN           
-            DO jn = 1, jptra
-               tra(i1:i2,1,k1:k2,jn) = zalpha1 * ptab(i1:i2,1,k1:k2,jn) + zalpha2 * ptab(i1:i2,2,k1:k2,jn)
-               DO jk=1,jpk      
-                  DO ji=imin,imax
-                     IF( vmask(ji,2,jk) == 0.e0 ) THEN
-                        tra(ji,2,jk,jn)=tra(ji,1,jk,jn) * tmask(ji,2,jk)
-                     ELSE
-                        tra(ji,2,jk,jn)=(zalpha4*tra(ji,1,jk,jn)+zalpha3*tra(ji,3,jk,jn))*tmask(ji,2,jk)
-                        IF( vn(ji,2,jk) < 0.e0 ) THEN
-                           tra(ji,2,jk,jn)=(zalpha6*tra(ji,3,jk,jn)+zalpha5*tra(ji,1,jk,jn)+zalpha7*tra(ji,4,jk,jn))*tmask(ji,2,jk)
-                        ENDIF
-                     ENDIF
-                  END DO
-               END DO
-            ENDDO
-         ENDIF
-         !
-         ! Treatment of corners
-         ! 
-         ! East south
-         IF ((eastern_side).AND.((nbondj == -1).OR.(nbondj == 2))) THEN
-            tra(nlci-1,2,:,:) = ptab(nlci-1,2,:,:)
-         ENDIF
-         ! East north
-         IF ((eastern_side).AND.((nbondj == 1).OR.(nbondj == 2))) THEN
-            tra(nlci-1,nlcj-1,:,:) = ptab(nlci-1,nlcj-1,:,:)
-         ENDIF
-         ! West south
-         IF ((western_side).AND.((nbondj == -1).OR.(nbondj == 2))) THEN
-            tra(2,2,:,:) = ptab(2,2,:,:)
-         ENDIF
-         ! West north
-         IF ((western_side).AND.((nbondj == 1).OR.(nbondj == 2))) THEN
-            tra(2,nlcj-1,:,:) = ptab(2,nlcj-1,:,:)
-         ENDIF
-         !
       ENDIF
       !
@@ -185,4 +180,7 @@
 
 #else
+   !!----------------------------------------------------------------------
+   !!   Empty module                                           no TOP AGRIF
+   !!----------------------------------------------------------------------
 CONTAINS
    SUBROUTINE Agrif_TOP_Interp_empty
@@ -193,3 +191,5 @@
    END SUBROUTINE Agrif_TOP_Interp_empty
 #endif
+
+   !!======================================================================
 END MODULE agrif_top_interp
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_top_sponge.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_top_sponge.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_top_sponge.F90	(revision 9019)
@@ -4,14 +4,13 @@
    !!======================================================================
    !!                ***  MODULE agrif_top_sponge  ***
-   !! AGRIF :   define in memory AGRIF variables for sea-ice
+   !! AGRIF :   sponge layer pakage for passive tracers (TOP)
    !!======================================================================
    !! History :  2.0  ! 2006-08  (R. Benshila, L. Debreu)  Original code
    !!----------------------------------------------------------------------
-
+#if defined key_agrif && defined key_top
    !!----------------------------------------------------------------------
    !!   Agrif_Sponge_trc : 
    !!   interptrn_sponge :  
    !!----------------------------------------------------------------------
-#if defined key_agrif && defined key_top
    USE par_oce
    USE par_trc
@@ -24,5 +23,4 @@
    USE in_out_manager
    USE lib_mpp
-   USE wrk_nemo  
 
    IMPLICIT NONE
@@ -32,5 +30,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.7 , NEMO Consortium (2015)
+   !! NEMO/NST 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -42,14 +40,14 @@
       !!                   *** ROUTINE Agrif_Sponge_Trc ***
       !!----------------------------------------------------------------------
-      REAL(wp) ::   timecoeff
+      REAL(wp) ::   zcoef   ! local scalar
       !!----------------------------------------------------------------------
       !
 #if defined SPONGE_TOP
-      timecoeff = REAL( Agrif_NbStepint(), wp ) / Agrif_rhot()
+      zcoef = REAL( Agrif_NbStepint(), wp ) / Agrif_rhot()
       CALL Agrif_sponge
       Agrif_SpecialValue    = 0._wp
       Agrif_UseSpecialValue = .TRUE.
       tabspongedone_trn     = .FALSE.
-      CALL Agrif_Bc_Variable( trn_sponge_id, calledweight=timecoeff, procname=interptrn_sponge )
+      CALL Agrif_Bc_Variable( trn_sponge_id, calledweight=zcoef, procname=interptrn_sponge )
       Agrif_UseSpecialValue = .FALSE.
 #endif
@@ -107,5 +105,7 @@
 
 #else
-
+   !!----------------------------------------------------------------------
+   !!   Empty module                                           no TOP AGRIF
+   !!----------------------------------------------------------------------
 CONTAINS
    SUBROUTINE agrif_top_sponge_empty
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_top_update.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_top_update.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_top_update.F90	(revision 9019)
@@ -5,17 +5,19 @@
    !!======================================================================
    !!                ***  MODULE agrif_top_update  ***
-   !! AGRIF :   
-   !!----------------------------------------------------------------------
+   !! AGRIF :   update package for passive tracers (TOP) 
+   !!======================================================================
    !! History :  
    !!----------------------------------------------------------------------
-
 #if defined key_agrif && defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_agrif'                                              AGRIF zoom
+   !!   'key_TOP'                                           on-line tracers
+   !!----------------------------------------------------------------------
    USE par_oce
    USE oce
+   USE dom_oce
+   USE agrif_oce
    USE par_trc
    USE trc
-   USE dom_oce
-   USE agrif_oce
-   USE wrk_nemo  
 
    IMPLICIT NONE
@@ -27,5 +29,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.7 , NEMO Consortium (2015)
+   !! NEMO/NST 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -112,9 +114,9 @@
 
 #else
+   !!----------------------------------------------------------------------
+   !!   Empty module                                           no TOP AGRIF
+   !!----------------------------------------------------------------------
 CONTAINS
    SUBROUTINE agrif_top_update_empty
-      !!---------------------------------------------
-      !!   *** ROUTINE agrif_Top_update_empty ***
-      !!---------------------------------------------
       WRITE(*,*)  'agrif_top_update : You should not have seen this print! error?'
    END SUBROUTINE agrif_top_update_empty
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_user.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 9019)
@@ -1,5 +1,5 @@
 #if defined key_agrif
 !!----------------------------------------------------------------------
-!! NEMO/NST 3.7 , NEMO Consortium (2016)
+!! NEMO/NST 4.0 , NEMO Consortium (2017)
 !! $Id$
 !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -28,6 +28,6 @@
       jpiglo  = nbcellsx + 2 + 2*nbghostcells
       jpjglo  = nbcellsy + 2 + 2*nbghostcells
-      jpi     = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci
-      jpj     = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj
+      jpi     = ( jpiglo-2*nn_hls + (jpni-1+0) ) / jpni + 2*nn_hls
+      jpj     = ( jpjglo-2*nn_hls + (jpnj-1+0) ) / jpnj + 2*nn_hls
 ! JC: change to allow for different vertical levels
 !     jpk is already set
@@ -105,5 +105,5 @@
    USE agrif_opa_interp
    USE agrif_opa_sponge
-   !!
+   !
    IMPLICIT NONE
    !!----------------------------------------------------------------------
@@ -125,31 +125,36 @@
    USE par_oce       
    USE oce
-   !!
-   IMPLICIT NONE
+   !
+   IMPLICIT NONE
+   !
+   INTEGER :: ind1, ind2, ind3
    !!----------------------------------------------------------------------
 
    ! 1. Declaration of the type of variable which have to be interpolated
    !---------------------------------------------------------------------
-   CALL agrif_declare_variable((/1,2/),(/2,3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),e1u_id)
-   CALL agrif_declare_variable((/2,1/),(/3,2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),e2v_id)
+   ind1 =     nbghostcells
+   ind2 = 1 + nbghostcells
+   ind3 = 2 + nbghostcells
+   CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),e1u_id)
+   CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),e2v_id)
 
    ! 2. Type of interpolation
    !-------------------------
-   CALL Agrif_Set_bcinterp(e1u_id,interp1=Agrif_linear,interp2=AGRIF_ppm)
-   CALL Agrif_Set_bcinterp(e2v_id,interp1=AGRIF_ppm,interp2=Agrif_linear)
+   CALL Agrif_Set_bcinterp( e1u_id, interp1=Agrif_linear, interp2=AGRIF_ppm    )
+   CALL Agrif_Set_bcinterp( e2v_id, interp1=AGRIF_ppm   , interp2=Agrif_linear )
 
    ! 3. Location of interpolation
    !-----------------------------
-   CALL Agrif_Set_bc(e1u_id,(/0,0/))
-   CALL Agrif_Set_bc(e2v_id,(/0,0/))
+   CALL Agrif_Set_bc(e1u_id,(/0,ind1-1/))
+   CALL Agrif_Set_bc(e2v_id,(/0,ind1-1/))
 
    ! 5. Update type
    !--------------- 
-   CALL Agrif_Set_Updatetype(e1u_id,update1 = Agrif_Update_Copy, update2=Agrif_Update_Average)
-   CALL Agrif_Set_Updatetype(e2v_id,update1 = Agrif_Update_Average, update2=Agrif_Update_Copy)
+   CALL Agrif_Set_Updatetype( e1u_id, update1=Agrif_Update_Copy   , update2=Agrif_Update_Average )
+   CALL Agrif_Set_Updatetype( e2v_id, update1=Agrif_Update_Average, update2=Agrif_Update_Copy    )
 
 ! High order updates
-!   CALL Agrif_Set_Updatetype(e1u_id,update1 = Agrif_Update_Average,            update2=Agrif_Update_Full_Weighting)
-!   CALL Agrif_Set_Updatetype(e2v_id,update1 = Agrif_Update_Full_Weighting,     update2=Agrif_Update_Average)
+!   CALL Agrif_Set_Updatetype( e1u_id, update1=Agrif_Update_Average       , update2=Agrif_Update_Full_Weighting )
+!   CALL Agrif_Set_Updatetype( e2v_id, update1=Agrif_Update_Full_Weighting, update2=Agrif_Update_Average        )
     !
 END SUBROUTINE agrif_declare_var_dom
@@ -162,14 +167,16 @@
    !! ** Purpose ::   Declaration of variables to be interpolated
    !!----------------------------------------------------------------------
+   USE agrif_opa_update
+   USE agrif_opa_interp
+   USE agrif_opa_sponge
    USE Agrif_Util
    USE oce 
    USE dom_oce
+   USE zdf_oce
    USE nemogcm
+   !
    USE lib_mpp
    USE in_out_manager
-   USE agrif_opa_update
-   USE agrif_opa_interp
-   USE agrif_opa_sponge
-   !!
+   !
    IMPLICIT NONE
    !
@@ -184,5 +191,5 @@
    ! 2. First interpolations of potentially non zero fields
    !-------------------------------------------------------
-   Agrif_SpecialValue=0.
+   Agrif_SpecialValue    = 0._wp
    Agrif_UseSpecialValue = .TRUE.
    CALL Agrif_Bc_variable(tsn_id,calledweight=1.,procname=interptsn)
@@ -319,8 +326,4 @@
    ENDIF
    !
-# if defined key_zdftke
-   CALL Agrif_Update_tke(0)
-# endif
-   !
    Agrif_UseSpecialValueInUpdate = .FALSE.
    nbcline = 0
@@ -337,43 +340,49 @@
    !!----------------------------------------------------------------------
    USE agrif_util
-   USE par_oce       !   ONLY : jpts
+   USE agrif_oce
+   USE par_oce       ! ocean parameters
+   USE zdf_oce       ! vertical physics
    USE oce
-   USE agrif_oce
-   !!
-   IMPLICIT NONE
+   !
+   IMPLICIT NONE
+   !
+   INTEGER :: ind1, ind2, ind3
    !!----------------------------------------------------------------------
 
    ! 1. Declaration of the type of variable which have to be interpolated
    !---------------------------------------------------------------------
-   CALL agrif_declare_variable((/2,2,0,0/),(/3,3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts/),tsn_id)
-   CALL agrif_declare_variable((/2,2,0,0/),(/3,3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts/),tsn_sponge_id)
-
-   CALL agrif_declare_variable((/1,2,0/),(/2,3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),un_interp_id)
-   CALL agrif_declare_variable((/2,1,0/),(/3,2,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),vn_interp_id)
-   CALL agrif_declare_variable((/1,2,0/),(/2,3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),un_update_id)
-   CALL agrif_declare_variable((/2,1,0/),(/3,2,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),vn_update_id)
-   CALL agrif_declare_variable((/1,2,0/),(/2,3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),un_sponge_id)
-   CALL agrif_declare_variable((/2,1,0/),(/3,2,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),vn_sponge_id)
-
-   CALL agrif_declare_variable((/2,2,0/),(/3,3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),e3t_id)
-   CALL agrif_declare_variable((/1,2,0/),(/2,3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),umsk_id)
-   CALL agrif_declare_variable((/2,1,0/),(/3,2,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),vmsk_id)
-
-   CALL agrif_declare_variable((/2,2,0,0/),(/3,3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,3/),scales_t_id)
-
-   CALL agrif_declare_variable((/1,2/),(/2,3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),unb_id)
-   CALL agrif_declare_variable((/2,1/),(/3,2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vnb_id)
-   CALL agrif_declare_variable((/1,2/),(/2,3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),ub2b_interp_id)
-   CALL agrif_declare_variable((/2,1/),(/3,2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vb2b_interp_id)
-   CALL agrif_declare_variable((/1,2/),(/2,3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),ub2b_update_id)
-   CALL agrif_declare_variable((/2,1/),(/3,2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vb2b_update_id)
-
-   CALL agrif_declare_variable((/2,2/),(/3,3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),sshn_id)
-
-# if defined key_zdftke
-   CALL agrif_declare_variable((/2,2,0/),(/3,3,0/),(/'x','y','N'/),(/1,1,1/),(/jpi,jpj,jpk/), en_id)
-   CALL agrif_declare_variable((/2,2,0/),(/3,3,0/),(/'x','y','N'/),(/1,1,1/),(/jpi,jpj,jpk/),avt_id)
-   CALL agrif_declare_variable((/2,2,0/),(/3,3,0/),(/'x','y','N'/),(/1,1,1/),(/jpi,jpj,jpk/),avm_id)
-# endif
+   ind1 =     nbghostcells
+   ind2 = 1 + nbghostcells
+   ind3 = 2 + nbghostcells
+   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts/),tsn_id)
+   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts/),tsn_sponge_id)
+
+   CALL agrif_declare_variable((/1,2,0/),(/ind2,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),un_interp_id)
+   CALL agrif_declare_variable((/2,1,0/),(/ind3,ind2,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),vn_interp_id)
+   CALL agrif_declare_variable((/1,2,0/),(/ind2,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),un_update_id)
+   CALL agrif_declare_variable((/2,1,0/),(/ind3,ind2,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),vn_update_id)
+   CALL agrif_declare_variable((/1,2,0/),(/ind2,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),un_sponge_id)
+   CALL agrif_declare_variable((/2,1,0/),(/ind3,ind2,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),vn_sponge_id)
+
+   CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),e3t_id)
+   CALL agrif_declare_variable((/1,2,0/),(/ind2,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),umsk_id)
+   CALL agrif_declare_variable((/2,1,0/),(/ind3,ind2,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),vmsk_id)
+
+   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,3/),scales_t_id)
+
+   CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),unb_id)
+   CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vnb_id)
+   CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),ub2b_interp_id)
+   CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vb2b_interp_id)
+   CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),ub2b_update_id)
+   CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vb2b_update_id)
+
+   CALL agrif_declare_variable((/2,2/),(/ind3,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),sshn_id)
+
+   IF( ln_zdftke ) THEN
+      CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/jpi,jpj,jpk/), en_id)
+      CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/jpi,jpj,jpk/),avt_id)
+      CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/jpi,jpj,jpk/),avm_id)
+   ENDIF
 
    ! 2. Type of interpolation
@@ -400,35 +409,27 @@
    CALL Agrif_Set_bcinterp(vmsk_id,interp=AGRIF_constant)
 
-# if defined key_zdftke
-   CALL Agrif_Set_bcinterp(avm_id ,interp=AGRIF_linear)
-# endif
-
+   IF( ln_zdftke )   CALL Agrif_Set_bcinterp( avm_id, interp=AGRIF_linear )
 
    ! 3. Location of interpolation
    !-----------------------------
-   CALL Agrif_Set_bc(tsn_id,(/0,1/))
-   CALL Agrif_Set_bc(un_interp_id,(/0,1/))
-   CALL Agrif_Set_bc(vn_interp_id,(/0,1/))
-
-!   CALL Agrif_Set_bc(tsn_sponge_id,(/-3*Agrif_irhox(),0/))
-!   CALL Agrif_Set_bc(un_sponge_id,(/-2*Agrif_irhox()-1,0/))
-!   CALL Agrif_Set_bc(vn_sponge_id,(/-2*Agrif_irhox()-1,0/))
-   CALL Agrif_Set_bc(tsn_sponge_id,(/-nn_sponge_len*Agrif_irhox()-1,0/))
-   CALL Agrif_Set_bc(un_sponge_id ,(/-nn_sponge_len*Agrif_irhox()-1,0/))
-   CALL Agrif_Set_bc(vn_sponge_id ,(/-nn_sponge_len*Agrif_irhox()-1,0/))
-
-   CALL Agrif_Set_bc(sshn_id,(/0,0/))
-   CALL Agrif_Set_bc(unb_id ,(/0,0/))
-   CALL Agrif_Set_bc(vnb_id ,(/0,0/))
-   CALL Agrif_Set_bc(ub2b_interp_id,(/0,0/))
-   CALL Agrif_Set_bc(vb2b_interp_id,(/0,0/))
-
-   CALL Agrif_Set_bc(e3t_id,(/-2*Agrif_irhox()-1,0/))   ! if west and rhox=3: column 2 to 9
-   CALL Agrif_Set_bc(umsk_id,(/0,0/))
-   CALL Agrif_Set_bc(vmsk_id,(/0,0/))
-
-# if defined key_zdftke
-   CALL Agrif_Set_bc(avm_id ,(/0,1/))
-# endif
+   CALL Agrif_Set_bc(       tsn_id, (/0,ind1/) )
+   CALL Agrif_Set_bc( un_interp_id, (/0,ind1/) )
+   CALL Agrif_Set_bc( vn_interp_id, (/0,ind1/) )
+
+   CALL Agrif_Set_bc( tsn_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) )  ! if west and rhox=3 and sponge=2 and ghost=1: columns 2 to 9 
+   CALL Agrif_Set_bc(  un_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) )
+   CALL Agrif_Set_bc(  vn_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) )
+
+   CALL Agrif_Set_bc(        sshn_id, (/0,ind1-1/) )
+   CALL Agrif_Set_bc(         unb_id, (/0,ind1-1/) )
+   CALL Agrif_Set_bc(         vnb_id, (/0,ind1-1/) )
+   CALL Agrif_Set_bc( ub2b_interp_id, (/0,ind1-1/) )
+   CALL Agrif_Set_bc( vb2b_interp_id, (/0,ind1-1/) )
+
+   CALL Agrif_Set_bc(  e3t_id, (/-2*Agrif_irhox()-1,ind1-1/) )   ! if west and rhox=3 and ghost=1: column 2 to 9
+   CALL Agrif_Set_bc( umsk_id, (/0,ind1-1/)                  )
+   CALL Agrif_Set_bc( vmsk_id, (/0,ind1-1/)                  )
+
+   IF( ln_zdftke )   CALL Agrif_Set_bc( avm_id, (/0,ind1/) )
 
    ! 5. Update type
@@ -446,9 +447,9 @@
    CALL Agrif_Set_Updatetype(vb2b_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy)
 
-# if defined key_zdftke
-   CALL Agrif_Set_Updatetype( en_id, update = AGRIF_Update_Average)
-   CALL Agrif_Set_Updatetype(avt_id, update = AGRIF_Update_Average)
-   CALL Agrif_Set_Updatetype(avm_id, update = AGRIF_Update_Average)
-# endif
+   IF( ln_zdftke) THEN
+      CALL Agrif_Set_Updatetype( en_id, update = AGRIF_Update_Average)
+      CALL Agrif_Set_Updatetype(avt_id, update = AGRIF_Update_Average)
+      CALL Agrif_Set_Updatetype(avm_id, update = AGRIF_Update_Average)
+   ENDIF
 
 ! High order updates
@@ -463,99 +464,4 @@
    !
 END SUBROUTINE agrif_declare_var
-
-#  if defined key_lim2
-SUBROUTINE Agrif_InitValues_cont_lim2
-   !!----------------------------------------------------------------------
-   !!                 *** ROUTINE Agrif_InitValues_cont_lim2 ***
-   !!
-   !! ** Purpose :: Initialisation of variables to be interpolated for LIM2
-   !!----------------------------------------------------------------------
-   USE Agrif_Util
-   USE ice_2
-   USE agrif_ice
-   USE in_out_manager
-   USE agrif_lim2_update
-   USE agrif_lim2_interp
-   USE lib_mpp
-   !!
-   IMPLICIT NONE
-   !!----------------------------------------------------------------------
-
-   ! 1. Declaration of the type of variable which have to be interpolated
-   !---------------------------------------------------------------------
-   CALL agrif_declare_var_lim2
-
-   ! 2. First interpolations of potentially non zero fields
-   !-------------------------------------------------------
-   Agrif_SpecialValue=-9999.
-   Agrif_UseSpecialValue = .TRUE.
-   !     Call Agrif_Bc_variable(zadv ,adv_ice_id ,calledweight=1.,procname=interp_adv_ice )
-   !     Call Agrif_Bc_variable(zvel ,u_ice_id   ,calledweight=1.,procname=interp_u_ice   )
-   !     Call Agrif_Bc_variable(zvel ,v_ice_id   ,calledweight=1.,procname=interp_v_ice   )
-   Agrif_SpecialValue=0.
-   Agrif_UseSpecialValue = .FALSE.
-
-   ! 3. Some controls
-   !-----------------
-
-#   if ! defined key_lim2_vp
-   lim_nbstep = 1.
-   CALL agrif_rhg_lim2_load
-   CALL agrif_trp_lim2_load
-   lim_nbstep = 0.
-#   endif
-   !RB mandatory but why ???
-   !      IF( nbclineupdate /= nn_fsbc .AND. nn_ice == 2 )THEN
-   !         CALL ctl_warn ('With ice model on child grid, nbclineupdate is set to nn_fsbc')
-   !         nbclineupdate = nn_fsbc
-   !       ENDIF
-   CALL Agrif_Update_lim2(0)
-   !
-END SUBROUTINE Agrif_InitValues_cont_lim2
-
-
-SUBROUTINE agrif_declare_var_lim2
-   !!----------------------------------------------------------------------
-   !!                 *** ROUTINE agrif_declare_var_lim2 ***
-   !!
-   !! ** Purpose :: Declaration of variables to be interpolated for LIM2
-   !!----------------------------------------------------------------------
-   USE agrif_util
-   USE ice_2
-   !!
-   IMPLICIT NONE
-   !!----------------------------------------------------------------------
-
-   ! 1. Declaration of the type of variable which have to be interpolated
-   !---------------------------------------------------------------------
-   CALL agrif_declare_variable((/2,2,0/),(/3,3,0/),(/'x','y','N'/),(/1,1,1/),(/jpi,jpj, 7/),adv_ice_id )
-#   if defined key_lim2_vp
-   CALL agrif_declare_variable((/1,1/),(/3,3/),(/'x','y'/),(/1,1/),(/jpi,jpj/),u_ice_id)
-   CALL agrif_declare_variable((/1,1/),(/3,3/),(/'x','y'/),(/1,1/),(/jpi,jpj/),v_ice_id)
-#   else
-   CALL agrif_declare_variable((/1,2/),(/2,3/),(/'x','y'/),(/1,1/),(/jpi,jpj/),u_ice_id)
-   CALL agrif_declare_variable((/2,1/),(/3,2/),(/'x','y'/),(/1,1/),(/jpi,jpj/),v_ice_id)
-#   endif
-
-   ! 2. Type of interpolation
-   !-------------------------
-   CALL Agrif_Set_bcinterp(adv_ice_id ,interp=AGRIF_linear)
-   CALL Agrif_Set_bcinterp(u_ice_id,interp1=Agrif_linear,interp2=AGRIF_ppm)
-   CALL Agrif_Set_bcinterp(v_ice_id,interp1=AGRIF_ppm,interp2=Agrif_linear)
-
-   ! 3. Location of interpolation
-   !-----------------------------
-   CALL Agrif_Set_bc(adv_ice_id ,(/0,1/))
-   CALL Agrif_Set_bc(u_ice_id,(/0,1/))
-   CALL Agrif_Set_bc(v_ice_id,(/0,1/))
-
-   ! 5. Update type
-   !---------------
-   CALL Agrif_Set_Updatetype(adv_ice_id , update = AGRIF_Update_Average)
-   CALL Agrif_Set_Updatetype(u_ice_id,update1 = Agrif_Update_Copy, update2 = Agrif_Update_Average)
-   CALL Agrif_Set_Updatetype(v_ice_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy)
-   ! 
-END SUBROUTINE agrif_declare_var_lim2
-#  endif
 
 #if defined key_lim3
@@ -623,6 +529,9 @@
    USE Agrif_Util
    USE ice
-
-   IMPLICIT NONE
+   USE par_oce, ONLY : nbghostcells
+   !
+   IMPLICIT NONE
+   !
+   INTEGER :: ind1, ind2, ind3
    !!----------------------------------------------------------------------
    !
@@ -634,7 +543,10 @@
    !                            2,2 = two ghost lines
    !-------------------------------------------------------------------------------------
-   CALL agrif_declare_variable((/2,2,0/),(/3,3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpl*(5+nlay_s+nlay_i)/),tra_ice_id )
-   CALL agrif_declare_variable((/1,2/)    ,(/2,3/),(/'x','y'/)    ,(/1,1/)  ,(/nlci,nlcj/)                      ,u_ice_id   )
-   CALL agrif_declare_variable((/2,1/)    ,(/3,2/),(/'x','y'/)    ,(/1,1/)  ,(/nlci,nlcj/)                      ,v_ice_id   )
+   ind1 =     nbghostcells
+   ind2 = 1 + nbghostcells
+   ind3 = 2 + nbghostcells
+   CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpl*(5+nlay_s+nlay_i)/),tra_ice_id )
+   CALL agrif_declare_variable((/1,2/)  ,(/ind2,ind3/)  ,(/'x','y'/)    ,(/1,1/)  ,(/nlci,nlcj/)                      ,u_ice_id   )
+   CALL agrif_declare_variable((/2,1/)  ,(/ind3,ind2/)  ,(/'x','y'/)    ,(/1,1/)  ,(/nlci,nlcj/)                      ,v_ice_id   )
 
    ! 2. Set interpolations (normal & tangent to the grid cell for velocities)
@@ -646,7 +558,7 @@
    ! 3. Set location of interpolations
    !----------------------------------
-   CALL Agrif_Set_bc(tra_ice_id,(/0,1/))
-   CALL Agrif_Set_bc(u_ice_id  ,(/0,1/))
-   CALL Agrif_Set_bc(v_ice_id  ,(/0,1/))
+   CALL Agrif_Set_bc(tra_ice_id,(/0,ind1/))
+   CALL Agrif_Set_bc(u_ice_id  ,(/0,ind1/))
+   CALL Agrif_Set_bc(v_ice_id  ,(/0,ind1/))
 
    ! 4. Set update type in case 2 ways (child=>parent) (normal & tangent to the grid cell for velocities)
@@ -777,10 +689,15 @@
    !!
    IMPLICIT NONE
+   !
+   INTEGER :: ind1, ind2, ind3
    !!----------------------------------------------------------------------
 
    ! 1. Declaration of the type of variable which have to be interpolated
    !---------------------------------------------------------------------
-   CALL agrif_declare_variable((/2,2,0,0/),(/3,3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra/),trn_id)
-   CALL agrif_declare_variable((/2,2,0,0/),(/3,3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra/),trn_sponge_id)
+   ind1 =     nbghostcells
+   ind2 = 1 + nbghostcells
+   ind3 = 2 + nbghostcells
+   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra/),trn_id)
+   CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra/),trn_sponge_id)
 
    ! 2. Type of interpolation
@@ -791,6 +708,5 @@
    ! 3. Location of interpolation
    !-----------------------------
-   CALL Agrif_Set_bc(trn_id,(/0,1/))
-!   CALL Agrif_Set_bc(trn_sponge_id,(/-3*Agrif_irhox(),0/))
+   CALL Agrif_Set_bc(trn_id,(/0,ind1/))
    CALL Agrif_Set_bc(trn_sponge_id,(/-nn_sponge_len*Agrif_irhox()-1,0/))
 
@@ -868,7 +784,4 @@
    !
    IF( agrif_oce_alloc()  > 0 )   CALL ctl_warn('agrif agrif_oce_alloc: allocation of arrays failed')
-# if defined key_lim2
-   IF( agrif_ice_alloc()  > 0 )   CALL ctl_stop('agrif agrif_ice_alloc: allocation of arrays failed') ! only for LIM2 (not LIM3)
-# endif
    !
 END SUBROUTINE agrif_nemo_init
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OFF_SRC/dtadyn.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OFF_SRC/dtadyn.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OFF_SRC/dtadyn.F90	(revision 9019)
@@ -167,11 +167,11 @@
       CALL zdf_mxl( kt )                                                   ! In any case, we need mxl
       !
-      hmld(:,:)         = sf_dyn(jf_mld)%fnow(:,:,1) * tmask(:,:,1)    ! mixed layer depht
-      avt(:,:,:)        = sf_dyn(jf_avt)%fnow(:,:,:) * tmask(:,:,:)    ! vertical diffusive coefficient 
-      !
-#if defined key_trabbl && ! defined key_c1d
-      ahu_bbl(:,:)      = sf_dyn(jf_ubl)%fnow(:,:,1) * umask(:,:,1)    ! bbl diffusive coef
-      ahv_bbl(:,:)      = sf_dyn(jf_vbl)%fnow(:,:,1) * vmask(:,:,1)
-#endif
+      hmld(:,:)       = sf_dyn(jf_mld)%fnow(:,:,1) * tmask(:,:,1)    ! mixed layer depht
+      avt(:,:,:)      = sf_dyn(jf_avt)%fnow(:,:,:) * tmask(:,:,:)    ! vertical diffusive coefficient 
+      !
+      IF( ln_trabbl .AND. .NOT.lk_c1d ) THEN       ! diffusive Bottom boundary layer param 
+         ahu_bbl(:,:) = sf_dyn(jf_ubl)%fnow(:,:,1) * umask(:,:,1)    ! bbl diffusive coef
+         ahv_bbl(:,:) = sf_dyn(jf_vbl)%fnow(:,:,1) * vmask(:,:,1)
+      ENDIF
       !
       !
@@ -275,5 +275,5 @@
       ENDIF
       !
-      IF( lk_trabbl ) THEN
+      IF( ln_trabbl ) THEN
                  jf_ubl  = jfld + 1    ;         jf_vbl  = jfld + 2     ;      jfld = jf_vbl
            slf_d(jf_ubl) = sn_ubl      ;   slf_d(jf_vbl) = sn_vbl
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90	(revision 9019)
@@ -28,11 +28,10 @@
    USE trabbl          ! bottom boundary layer          (tra_bbl_init routine)
    USE traldf          ! lateral physics                (tra_ldf_init routine)
-   USE zdfini          ! vertical physics: initialization
-   USE sbcmod          ! surface boundary condition       (sbc_init     routine)
-   USE phycst          ! physical constant                  (par_cst routine)
+   USE sbcmod          ! surface boundary condition     (sbc_init     routine)
+   USE phycst          ! physical constant                   (par_cst routine)
    USE dtadyn          ! Lecture and Interpolation of the dynamical fields
    USE trcini          ! Initilization of the passive tracers
-   USE daymod          ! calendar                         (day     routine)
-   USE trcstp          ! passive tracer time-stepping      (trc_stp routine)
+   USE daymod          ! calendar                            (day     routine)
+   USE trcstp          ! passive tracer time-stepping        (trc_stp routine)
    USE dtadyn          ! Lecture and interpolation of the dynamical fields
    !              ! Passive tracers needs
@@ -150,7 +149,9 @@
       !! ** Purpose :   initialization of the nemo model in off-line mode
       !!----------------------------------------------------------------------
-      INTEGER ::   ji            ! dummy loop indices
-      INTEGER ::   ilocal_comm   ! local integer
-      INTEGER ::   ios, inum
+      INTEGER  ::   ji                 ! dummy loop indices
+      INTEGER  ::   ilocal_comm        ! local integer
+      INTEGER  ::   ios, inum          ! local integers
+      INTEGER  ::   iiarea, ijarea     ! local integers
+      INTEGER  ::   iirest, ijrest     ! local integers
       REAL(wp) ::   ziglo, zjglo, zkglo, zperio   ! local scalars
       CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
@@ -158,5 +159,5 @@
       NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
          &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
-         &             nn_timing, nn_diacfl
+         &             ln_timing, ln_diacfl
 
       NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_write_cfg, cn_domcfg_out, ln_use_jattr
@@ -198,5 +199,4 @@
          CALL usr_def_nam( cltxt2, clnam, cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
       ENDIF
-      jpk    = jpkglo
       !
       !
@@ -246,12 +246,29 @@
       END IF
 
-      ! Calculate domain dimensions given calculated jpni and jpnj
-      ! This used to be done in par_oce.F90 when they were parameters rather
-      ! than variables
-      jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
-      jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
+      iiarea = 1 + MOD( narea - 1 , jpni )
+      ijarea = 1 + ( narea - 1 ) / jpni
+      iirest = 1 + MOD( jpiglo - 2*nn_hls - 1 , jpni )
+      ijrest = 1 + MOD( jpjglo - 2*nn_hls - 1 , jpnj )
+#if defined key_nemocice_decomp
+      jpi = ( nx_global+2-2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
+      jpj = ( ny_global+2-2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim. 
+      jpimax  = jpi
+      jpjmax  = jpj
+      IF( iiarea == jpni ) jpi = jpiglo - (jpni - 1) * (jpi - 2*nn_hls)
+      IF( ijarea == jpnj ) jpj = jpjglo - (jpnj - 1) * (jpj - 2*nn_hls)
+#else
+      jpi = ( jpiglo     -2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
+      jpj = ( jpjglo     -2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.
+      jpimax  = jpi
+      jpjmax  = jpj
+      IF( iiarea > iirest ) jpi = jpi - 1
+      IF( ijarea > ijrest ) jpj = jpj - 1
+#endif
+
+      jpk   = jpkglo                                           ! third dim
+
       jpim1 = jpi-1                                            ! inner domain indices
       jpjm1 = jpj-1                                            !   "           "
-      jpkm1 = jpk-1                                            !   "           "
+      jpkm1 = MAX( 1, jpk-1 )                                  !   "           "
       jpij  = jpi*jpj                                          !  jpi x j
 
@@ -286,46 +303,44 @@
 
       !                                      ! Domain decomposition
-      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
-      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
-      ENDIF
-      !
-      IF( nn_timing == 1 )  CALL timing_init
+      CALL mpp_init
+      !
+      IF( ln_timing    )   CALL timing_init
       !
 
       !                                      ! General initialization
-      IF( nn_timing == 1 )  CALL timing_start( 'nemo_init')
-      !
-                            CALL     phy_cst    ! Physical constants
-                            CALL     eos_init   ! Equation of state
-      IF( lk_c1d        )   CALL     c1d_init   ! 1D column configuration
-
-                            CALL     dom_init   ! Domain
-
-                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
-
-      IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
-
-      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
-
-                            CALL     sbc_init   ! Forcings : surface module
-
-                            CALL ldf_tra_init   ! Lateral ocean tracer physics
-                            CALL ldf_eiv_init   ! Eddy induced velocity param
-                            CALL tra_ldf_init   ! lateral mixing
-      IF( l_ldfslp )        CALL ldf_slp_init   ! slope of lateral mixing
-
-                            CALL tra_qsr_init   ! penetrative solar radiation qsr
-      IF( lk_trabbl     )   CALL tra_bbl_init   ! advective (and/or diffusive) bottom boundary layer scheme
-
-                            CALL trc_nam_run    ! Needed to get restart parameters for passive tracers
-                            CALL trc_rst_cal( nit000, 'READ' )   ! calendar
-                            CALL dta_dyn_init   ! Initialization for the dynamics
-
-                            CALL     trc_init   ! Passive tracers initialization
-                            CALL dia_ptr_init   ! Initialise diaptr as some variables are used 
+      IF( ln_timing    )   CALL timing_start( 'nemo_init')
+      !
+                           CALL     phy_cst    ! Physical constants
+                           CALL     eos_init   ! Equation of state
+      IF( lk_c1d       )   CALL     c1d_init   ! 1D column configuration
+
+                           CALL     dom_init   ! Domain
+
+                           CALL  istate_init   ! ocean initial state (Dynamics and tracers)
+
+      IF( ln_nnogather )   CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
+
+      IF( ln_ctl       )   CALL prt_ctl_init   ! Print control
+
+                           CALL     sbc_init   ! Forcings : surface module
+
+                           CALL ldf_tra_init   ! Lateral ocean tracer physics
+                           CALL ldf_eiv_init   ! Eddy induced velocity param
+                           CALL tra_ldf_init   ! lateral mixing
+      IF( l_ldfslp     )   CALL ldf_slp_init   ! slope of lateral mixing
+
+                           CALL tra_qsr_init   ! penetrative solar radiation qsr
+      IF( ln_trabbl    )   CALL tra_bbl_init   ! advective (and/or diffusive) bottom boundary layer scheme
+
+                           CALL trc_nam_run    ! Needed to get restart parameters for passive tracers
+                           CALL trc_rst_cal( nit000, 'READ' )   ! calendar
+                           CALL dta_dyn_init   ! Initialization for the dynamics
+
+                           CALL     trc_init   ! Passive tracers initialization
+                           CALL dia_ptr_init   ! Initialise diaptr as some variables are used 
       !                                         ! in various advection and diffusion routines
       IF(lwp) WRITE(numout,cform_aaa)           ! Flag AAAAAAA
       !
-      IF( nn_timing == 1 )  CALL timing_stop( 'nemo_init')
+      IF( ln_timing    )   CALL timing_stop( 'nemo_init')
       !
    END SUBROUTINE nemo_init
@@ -354,5 +369,6 @@
          WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
          WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
-         WRITE(numout,*) '      timing activated    (0/1)       nn_timing  = ', nn_timing
+         WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
+         WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
       ENDIF
       !
@@ -364,4 +380,9 @@
       isplt     = nn_isplt
       jsplt     = nn_jsplt
+!!gm to be remove at the end of the 2017 merge party
+      if( ln_timing ) then  ;  nn_timing = 1
+      else                  ;  nn_timing = 0
+      endif
+!!gm end
 
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ASM/asmbkg.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ASM/asmbkg.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ASM/asmbkg.F90	(revision 9019)
@@ -28,7 +28,5 @@
    USE ldfslp             ! Lateral diffusion: slopes of neutral surfaces
    USE tradmp             ! Tracer damping
-#if defined key_zdftke
    USE zdftke             ! TKE vertical physics
-#endif
    USE eosbn2             ! Equation of state (eos_bn2 routine)
    USE zdfmxl             ! Mixed layer depth
@@ -38,7 +36,4 @@
    USE asmpar             ! Parameters for the assmilation interface
    USE zdfmxl             ! mixed layer depth
-#if defined key_lim2
-   USE ice_2
-#endif
 #if defined key_lim3
    USE ice
@@ -94,10 +89,8 @@
             IF( nitbkg_r == nit000 - 1 ) THEN      ! Treat special case when nitbkg = 0
                zdate = REAL( ndastp )
-#if defined key_zdftke
-               ! lk_zdftke=T :   Read turbulent kinetic energy ( en )
-               IF(lwp) WRITE(numout,*) ' Reading TKE (en) from restart...'
-               CALL tke_rst( nit000, 'READ' )               ! lk_zdftke=T :   Read turbulent kinetic energy ( en )
-
-#endif
+               IF( ln_zdftke ) THEN                   ! read turbulent kinetic energy ( en )
+                  IF(lwp) WRITE(numout,*) ' Reading TKE (en) from restart...'
+                  CALL tke_rst( nit000, 'READ' )
+               ENDIF
             ELSE
                zdate = REAL( ndastp )
@@ -111,7 +104,5 @@
             CALL iom_rstput( kt, nitbkg_r, inum, 'sn'     , tsn(:,:,:,jp_sal) )
             CALL iom_rstput( kt, nitbkg_r, inum, 'sshn'   , sshn              )
-#if defined key_zdftke
-            CALL iom_rstput( kt, nitbkg_r, inum, 'en'     , en                )
-#endif
+            IF( ln_zdftke )   CALL iom_rstput( kt, nitbkg_r, inum, 'en'     , en                )
             !
             CALL iom_close( inum )
@@ -148,10 +139,11 @@
             CALL iom_rstput( kt, nitdin_r, inum, 'sn'     , tsn(:,:,:,jp_sal) )
             CALL iom_rstput( kt, nitdin_r, inum, 'sshn'   , sshn              )
-#if defined key_lim2 || defined key_lim3
-            IF( nn_ice == 2  .OR.  nn_ice == 3 ) THEN
-	            IF( ALLOCATED(frld) ) THEN
-                  CALL iom_rstput( kt, nitdin_r, inum, 'iceconc', 1._wp - frld(:,:)   )
+#if defined key_lim3
+            IF( nn_ice == 2 ) THEN
+	            IF( ALLOCATED(at_i) ) THEN
+                  CALL iom_rstput( kt, nitdin_r, inum, 'iceconc', at_i(:,:)   )
                ELSE
-		            CALL ctl_warn('Ice concentration not written to background as ice variable frld not allocated on this timestep')
+		            CALL ctl_warn('asm_bkg_wri: Ice concentration not written to background ',   &
+		               &          'as ice variable at_i not allocated on this timestep')
 	            ENDIF
             ENDIF
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 9019)
@@ -22,22 +22,22 @@
    !!   seaice_asm_inc : Apply the seaice increment
    !!----------------------------------------------------------------------
-   USE wrk_nemo         ! Memory Allocation
-   USE par_oce          ! Ocean space and time domain variables
-   USE dom_oce          ! Ocean space and time domain
-   USE domvvl           ! domain: variable volume level
-   USE oce              ! Dynamics and active tracers defined in memory
-   USE ldfdyn           ! lateral diffusion: eddy viscosity coefficients
-   USE eosbn2           ! Equation of state - in situ and potential density
-   USE zpshde           ! Partial step : Horizontal Derivative
-   USE iom              ! Library to read input files
-   USE asmpar           ! Parameters for the assmilation interface
-   USE c1d              ! 1D initialization
-   USE in_out_manager   ! I/O manager
-   USE lib_mpp          ! MPP library
-#if defined key_lim2
-   USE ice_2            ! LIM2
-#endif
-   USE sbc_oce          ! Surface boundary condition variables.
-   USE diaobs, ONLY: calc_date     ! Compute the calendar date on a given step
+   USE oce             ! Dynamics and active tracers defined in memory
+   USE par_oce         ! Ocean space and time domain variables
+   USE dom_oce         ! Ocean space and time domain
+   USE domvvl          ! domain: variable volume level
+   USE ldfdyn          ! lateral diffusion: eddy viscosity coefficients
+   USE eosbn2          ! Equation of state - in situ and potential density
+   USE zpshde          ! Partial step : Horizontal Derivative
+   USE asmpar          ! Parameters for the assmilation interface
+   USE c1d             ! 1D initialization
+   USE sbc_oce         ! Surface boundary condition variables.
+   USE diaobs   , ONLY : calc_date     ! Compute the calendar date on a given step
+#if defined key_lim3
+   USE ice      , ONLY : hm_i, at_i, at_i_b
+#endif
+   !
+   USE in_out_manager  ! I/O manager
+   USE iom             ! Library to read input files
+   USE lib_mpp         ! MPP library
 
    IMPLICIT NONE
@@ -127,5 +127,5 @@
       REAL(wp) :: zdate_inc    ! Time axis in increments file
       !
-      REAL(wp), POINTER, DIMENSION(:,:) ::   hdiv   ! 2D workspace
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zhdiv   ! 2D workspace
       !!
       NAMELIST/nam_asminc/ ln_bkgwri,                                      &
@@ -173,26 +173,17 @@
       ENDIF
 
-      nitbkg_r    = nitbkg    + nit000 - 1  ! Background time referenced to nit000
-      nitdin_r    = nitdin    + nit000 - 1  ! Background time for DI referenced to nit000
-      nitiaustr_r = nitiaustr + nit000 - 1  ! Start of IAU interval referenced to nit000
-      nitiaufin_r = nitiaufin + nit000 - 1  ! End of IAU interval referenced to nit000
-
-      iiauper = nitiaufin_r - nitiaustr_r + 1  ! IAU interval length
-      icycper = nitend      - nit000      + 1  ! Cycle interval length
-
-      ! Date of final time step
-      CALL calc_date( nitend, ditend_date )
-
-      ! Background time for Jb referenced to ndate0
-      CALL calc_date( nitbkg_r, ditbkg_date )
-
-      ! Background time for DI referenced to ndate0
-      CALL calc_date( nitdin_r, ditdin_date )
-
-      ! IAU start time referenced to ndate0
-      CALL calc_date( nitiaustr_r, ditiaustr_date )
-
-      ! IAU end time referenced to ndate0
-      CALL calc_date( nitiaufin_r, ditiaufin_date )
+      nitbkg_r    = nitbkg    + nit000 - 1            ! Background time referenced to nit000
+      nitdin_r    = nitdin    + nit000 - 1            ! Background time for DI referenced to nit000
+      nitiaustr_r = nitiaustr + nit000 - 1            ! Start of IAU interval referenced to nit000
+      nitiaufin_r = nitiaufin + nit000 - 1            ! End of IAU interval referenced to nit000
+
+      iiauper     = nitiaufin_r - nitiaustr_r + 1     ! IAU interval length
+      icycper     = nitend      - nit000      + 1     ! Cycle interval length
+
+      CALL calc_date( nitend     , ditend_date    )   ! Date of final time step
+      CALL calc_date( nitbkg_r   , ditbkg_date    )   ! Background time for Jb referenced to ndate0
+      CALL calc_date( nitdin_r   , ditdin_date    )   ! Background time for DI referenced to ndate0
+      CALL calc_date( nitiaustr_r, ditiaustr_date )   ! IAU start time referenced to ndate0
+      CALL calc_date( nitiaufin_r, ditiaufin_date )   ! IAU end time referenced to ndate0
 
       IF(lwp) THEN
@@ -266,5 +257,5 @@
          ALLOCATE( wgtiau( icycper ) )
 
-         wgtiau(:) = 0.0
+         wgtiau(:) = 0._wp
 
          IF ( niaufn == 0 ) THEN
@@ -339,21 +330,17 @@
       ALLOCATE( ssh_bkginc(jpi,jpj)   )
       ALLOCATE( seaice_bkginc(jpi,jpj))
+      t_bkginc     (:,:,:) = 0._wp
+      s_bkginc     (:,:,:) = 0._wp
+      u_bkginc     (:,:,:) = 0._wp
+      v_bkginc     (:,:,:) = 0._wp
+      ssh_bkginc   (:,:)   = 0._wp
+      seaice_bkginc(:,:)   = 0._wp
 #if defined key_asminc
       ALLOCATE( ssh_iau(jpi,jpj)      )
+      ssh_iau      (:,:)   = 0._wp
 #endif
 #if defined key_cice && defined key_asminc
-      ALLOCATE( ndaice_da(jpi,jpj)      )
-#endif
-      t_bkginc(:,:,:) = 0.0
-      s_bkginc(:,:,:) = 0.0
-      u_bkginc(:,:,:) = 0.0
-      v_bkginc(:,:,:) = 0.0
-      ssh_bkginc(:,:) = 0.0
-      seaice_bkginc(:,:) = 0.0
-#if defined key_asminc
-      ssh_iau(:,:)    = 0.0
-#endif
-#if defined key_cice && defined key_asminc
-      ndaice_da(:,:) = 0.0
+      ALLOCATE( ndaice_da(jpi,jpj)    )
+      ndaice_da    (:,:)   = 0._wp
 #endif
       IF ( ( ln_trainc ).OR.( ln_dyninc ).OR.( ln_sshinc ).OR.( ln_seaiceinc ) ) THEN
@@ -441,26 +428,26 @@
       IF ( ln_dyninc .AND. nn_divdmp > 0 ) THEN
          !
-         CALL wrk_alloc( jpi,jpj,   hdiv ) 
+         ALLOCATE( zhdiv(jpi,jpj) ) 
          !
          DO jt = 1, nn_divdmp
             !
-            DO jk = 1, jpkm1           ! hdiv = e1e1 * div
-               hdiv(:,:) = 0._wp
+            DO jk = 1, jpkm1           ! zhdiv = e1e1 * div
+               zhdiv(:,:) = 0._wp
                DO jj = 2, jpjm1
                   DO ji = fs_2, fs_jpim1   ! vector opt.
-                     hdiv(ji,jj) = (  e2u(ji  ,jj) * e3u_n(ji  ,jj,jk) * u_bkginc(ji  ,jj,jk)    &
-                        &           - e2u(ji-1,jj) * e3u_n(ji-1,jj,jk) * u_bkginc(ji-1,jj,jk)    &
-                        &           + e1v(ji,jj  ) * e3v_n(ji,jj  ,jk) * v_bkginc(ji,jj  ,jk)    &
-                        &           - e1v(ji,jj-1) * e3v_n(ji,jj-1,jk) * v_bkginc(ji,jj-1,jk)  ) / e3t_n(ji,jj,jk)
+                     zhdiv(ji,jj) = (  e2u(ji  ,jj) * e3u_n(ji  ,jj,jk) * u_bkginc(ji  ,jj,jk)    &
+                        &            - e2u(ji-1,jj) * e3u_n(ji-1,jj,jk) * u_bkginc(ji-1,jj,jk)    &
+                        &            + e1v(ji,jj  ) * e3v_n(ji,jj  ,jk) * v_bkginc(ji,jj  ,jk)    &
+                        &            - e1v(ji,jj-1) * e3v_n(ji,jj-1,jk) * v_bkginc(ji,jj-1,jk)  ) / e3t_n(ji,jj,jk)
                   END DO
                END DO
-               CALL lbc_lnk( hdiv, 'T', 1. )   ! lateral boundary cond. (no sign change)
+               CALL lbc_lnk( zhdiv, 'T', 1. )   ! lateral boundary cond. (no sign change)
                !
                DO jj = 2, jpjm1
                   DO ji = fs_2, fs_jpim1   ! vector opt.
                      u_bkginc(ji,jj,jk) = u_bkginc(ji,jj,jk)                         &
-                        &               + 0.2_wp * ( hdiv(ji+1,jj) - hdiv(ji  ,jj) ) * r1_e1u(ji,jj) * umask(ji,jj,jk)
+                        &               + 0.2_wp * ( zhdiv(ji+1,jj) - zhdiv(ji  ,jj) ) * r1_e1u(ji,jj) * umask(ji,jj,jk)
                      v_bkginc(ji,jj,jk) = v_bkginc(ji,jj,jk)                         &
-                        &               + 0.2_wp * ( hdiv(ji,jj+1) - hdiv(ji,jj  ) ) * r1_e2v(ji,jj) * vmask(ji,jj,jk) 
+                        &               + 0.2_wp * ( zhdiv(ji,jj+1) - zhdiv(ji,jj  ) ) * r1_e2v(ji,jj) * vmask(ji,jj,jk) 
                   END DO
                END DO
@@ -469,5 +456,5 @@
          END DO
          !
-         CALL wrk_dealloc( jpi,jpj,   hdiv ) 
+         DEALLOCATE( zhdiv ) 
          !
       ENDIF
@@ -815,5 +802,5 @@
       INTEGER  ::   it
       REAL(wp) ::   zincwgt   ! IAU weight for current time step
-#if defined key_lim2
+#if defined key_lim3
       REAL(wp), DIMENSION(jpi,jpj) ::   zofrld, zohicif, zseaicendg, zhicifinc  ! LIM
       REAL(wp) ::   zhicifmin = 0.5_wp      ! ice minimum depth in metres
@@ -837,20 +824,19 @@
             ENDIF
             !
-            ! Sea-ice : LIM-3 case (to add)
-            !
-#if defined key_lim2
-            ! Sea-ice : LIM-2 case
-            zofrld (:,:) = frld(:,:)
-            zohicif(:,:) = hicif(:,:)
-            !
-            frld  = MIN( MAX( frld (:,:) - seaice_bkginc(:,:) * zincwgt, 0.0_wp), 1.0_wp)
-            pfrld = MIN( MAX( pfrld(:,:) - seaice_bkginc(:,:) * zincwgt, 0.0_wp), 1.0_wp)
-            fr_i(:,:) = 1.0_wp - frld(:,:)        ! adjust ice fraction
-            !
-            zseaicendg(:,:) = zofrld(:,:) - frld(:,:)   ! find out actual sea ice nudge applied
+            ! Sea-ice : LIM-3 case
+            !
+#if defined key_lim3
+            zofrld (:,:) = 1._wp - at_i(:,:)
+            zohicif(:,:) = hm_i(:,:)
+            !
+            at_i  (:,:) = 1. - MIN( MAX( 1.-at_i  (:,:) - seaice_bkginc(:,:) * zincwgt, 0.0_wp), 1.0_wp)
+            at_i_b(:,:) = 1. - MIN( MAX( 1.-at_i_b(:,:) - seaice_bkginc(:,:) * zincwgt, 0.0_wp), 1.0_wp)
+            fr_i(:,:) = at_i(:,:)        ! adjust ice fraction
+            !
+            zseaicendg(:,:) = zofrld(:,:) - (1. - at_i(:,:))   ! find out actual sea ice nudge applied
             !
             ! Nudge sea ice depth to bring it up to a required minimum depth
-            WHERE( zseaicendg(:,:) > 0.0_wp .AND. hicif(:,:) < zhicifmin ) 
-               zhicifinc(:,:) = (zhicifmin - hicif(:,:)) * zincwgt    
+            WHERE( zseaicendg(:,:) > 0.0_wp .AND. hm_i(:,:) < zhicifmin ) 
+               zhicifinc(:,:) = (zhicifmin - hm_i(:,:)) * zincwgt    
             ELSEWHERE
                zhicifinc(:,:) = 0.0_wp
@@ -858,6 +844,5 @@
             !
             ! nudge ice depth
-            hicif (:,:) = hicif (:,:) + zhicifinc(:,:)
-            phicif(:,:) = phicif(:,:) + zhicifinc(:,:)       
+            hm_i (:,:) = hm_i (:,:) + zhicifinc(:,:)
             !
             ! seaice salinity balancing (to add)
@@ -888,27 +873,26 @@
             neuler = 0                    ! Force Euler forward step
             !
-            ! Sea-ice : LIM-3 case (to add)
-            !
-#if defined key_lim2
-            ! Sea-ice : LIM-2 case.
-            zofrld(:,:)=frld(:,:)
-            zohicif(:,:)=hicif(:,:)
+            ! Sea-ice : LIM-3 case
+            !
+#if defined key_lim3
+            zofrld (:,:) = 1._wp - at_i(:,:)
+            zohicif(:,:) = hm_i(:,:)
             ! 
             ! Initialize the now fields the background + increment
-            frld (:,:) = MIN( MAX( frld(:,:) - seaice_bkginc(:,:), 0.0_wp), 1.0_wp)
-            pfrld(:,:) = frld(:,:) 
-            fr_i (:,:) = 1.0_wp - frld(:,:)                ! adjust ice fraction
-            zseaicendg(:,:) = zofrld(:,:) - frld(:,:)      ! find out actual sea ice nudge applied
+            at_i(:,:) = 1. - MIN( MAX( 1.-at_i(:,:) - seaice_bkginc(:,:), 0.0_wp), 1.0_wp)
+            at_i_b(:,:) = at_i(:,:) 
+            fr_i(:,:) = at_i(:,:)        ! adjust ice fraction
+            !
+            zseaicendg(:,:) = zofrld(:,:) - (1. - at_i(:,:))   ! find out actual sea ice nudge applied
             !
             ! Nudge sea ice depth to bring it up to a required minimum depth
-            WHERE( zseaicendg(:,:) > 0.0_wp .AND. hicif(:,:) < zhicifmin ) 
-               zhicifinc(:,:) = (zhicifmin - hicif(:,:)) * zincwgt    
+            WHERE( zseaicendg(:,:) > 0.0_wp .AND. hm_i(:,:) < zhicifmin ) 
+               zhicifinc(:,:) = (zhicifmin - hm_i(:,:)) * zincwgt    
             ELSEWHERE
-               zhicifinc(:,:) = 0._wp
+               zhicifinc(:,:) = 0.0_wp
             END WHERE
             !
             ! nudge ice depth
-            hicif (:,:) = hicif (:,:) + zhicifinc(:,:)
-            phicif(:,:) = phicif(:,:)       
+            hm_i (:,:) = hm_i (:,:) + zhicifinc(:,:)
             !
             ! seaice salinity balancing (to add)
@@ -932,5 +916,5 @@
          ENDIF
 
-!#if defined defined key_lim2 || defined key_cice
+!#if defined defined key_lim3 || defined key_cice
 !
 !            IF (ln_seaicebal ) THEN       
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/BDY/bdy_oce.F90	(revision 9019)
@@ -55,18 +55,11 @@
       REAL(wp), POINTER, DIMENSION(:,:) ::  tem
       REAL(wp), POINTER, DIMENSION(:,:) ::  sal
-#if defined key_lim2
-      LOGICAL                           ::   ll_frld
-      LOGICAL                           ::   ll_hicif
-      LOGICAL                           ::   ll_hsnif
-      REAL(wp), POINTER, DIMENSION(:)   ::   frld
-      REAL(wp), POINTER, DIMENSION(:)   ::   hicif
-      REAL(wp), POINTER, DIMENSION(:)   ::   hsnif
-#elif defined key_lim3
+#if defined key_lim3
       LOGICAL                           ::   ll_a_i
-      LOGICAL                           ::   ll_ht_i
-      LOGICAL                           ::   ll_ht_s
+      LOGICAL                           ::   ll_h_i
+      LOGICAL                           ::   ll_h_s
       REAL(wp), POINTER, DIMENSION(:,:) ::   a_i    !: now ice leads fraction climatology
-      REAL(wp), POINTER, DIMENSION(:,:) ::   ht_i   !: Now ice  thickness climatology
-      REAL(wp), POINTER, DIMENSION(:,:) ::   ht_s   !: now snow thickness
+      REAL(wp), POINTER, DIMENSION(:,:) ::   h_i    !: Now ice  thickness climatology
+      REAL(wp), POINTER, DIMENSION(:,:) ::   h_s    !: now snow thickness
 #endif
 #if defined key_top
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90	(revision 9019)
@@ -13,24 +13,25 @@
    !!            3.6  !  2012-01  (C. Rousset) add ice boundary conditions for lim3
    !!----------------------------------------------------------------------
-   !!    bdy_dta        : read external data along open boundaries from file
-   !!    bdy_dta_init   : initialise arrays etc for reading of external data
+
    !!----------------------------------------------------------------------
-   USE timing          ! Timing
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE bdy_oce         ! ocean open boundary conditions  
-   USE bdytides        ! tidal forcing at boundaries
-   USE fldread         ! read input fields
-   USE iom             ! IOM library
-   USE in_out_manager  ! I/O logical units
-#if defined key_lim2
-   USE ice_2
-#elif defined key_lim3
-   USE ice
-   USE limvar          ! redistribute ice input into categories
-#endif
-   USE sbcapr
-   USE sbctide         ! Tidal forcing or not
+   !!    bdy_dta      : read external data along open boundaries from file
+   !!    bdy_dta_init : initialise arrays etc for reading of external data
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE sbcapr         ! atmospheric pressure forcing
+   USE sbctide        ! Tidal forcing or not
+   USE bdy_oce        ! ocean open boundary conditions  
+   USE bdytides       ! tidal forcing at boundaries
+#if defined key_lim3
+   USE ice            ! sea-ice variables
+   USE icevar         ! redistribute ice input into categories
+#endif
+   !
+   USE fldread        ! read input fields
+   USE iom            ! IOM library
+   USE in_out_manager ! I/O logical units
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -50,10 +51,10 @@
 
 #if defined key_lim3
-   LOGICAL :: ll_bdylim3                  ! determine whether ice input is lim2 (F) or lim3 (T) type
-   INTEGER :: jfld_hti, jfld_hts, jfld_ai ! indices of ice thickness, snow thickness and concentration in bf structure
+   INTEGER ::   nice_cat                      ! number of categories in the input file
+   INTEGER ::   jfld_hti, jfld_hts, jfld_ai   ! indices of ice thickness, snow thickness and concentration in bf structure
 #endif
 
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$ 
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -79,5 +80,6 @@
       !                                               ! etc.
       !
-      INTEGER ::  ib_bdy, jfld, jstart, jend, ib, ii, ij, ik, igrd, jl  ! local indices
+      INTEGER ::  jbdy, jfld, jstart, jend, ib, jl  ! dummy loop indices
+      INTEGER ::  ii, ij, ik, igrd                  ! local integers
       INTEGER,          DIMENSION(jpbgrd) ::   ilen1 
       INTEGER, POINTER, DIMENSION(:)      ::   nblen, nblenrim  ! short cuts
@@ -94,39 +96,39 @@
          !-----------------------------
          
-         DO ib_bdy = 1, nb_bdy
+         DO jbdy = 1, nb_bdy
             !
-            nblen => idx_bdy(ib_bdy)%nblen
-            nblenrim => idx_bdy(ib_bdy)%nblenrim
-            dta => dta_bdy(ib_bdy)
-
-            IF( nn_dyn2d_dta(ib_bdy) == 0 ) THEN 
+            nblen    => idx_bdy(jbdy)%nblen
+            nblenrim => idx_bdy(jbdy)%nblenrim
+            dta      => dta_bdy(jbdy)
+            !
+            IF( nn_dyn2d_dta(jbdy) == 0 ) THEN 
                ilen1(:) = nblen(:)
                IF( dta%ll_ssh ) THEN 
                   igrd = 1
                   DO ib = 1, ilen1(igrd)
-                     ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                     ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                     dta_bdy(ib_bdy)%ssh(ib) = sshn(ii,ij) * tmask(ii,ij,1)         
+                     ii = idx_bdy(jbdy)%nbi(ib,igrd)
+                     ij = idx_bdy(jbdy)%nbj(ib,igrd)
+                     dta_bdy(jbdy)%ssh(ib) = sshn(ii,ij) * tmask(ii,ij,1)         
                   END DO 
-               END IF
+               ENDIF
                IF( dta%ll_u2d ) THEN 
                   igrd = 2
                   DO ib = 1, ilen1(igrd)
-                     ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                     ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                     dta_bdy(ib_bdy)%u2d(ib) = un_b(ii,ij) * umask(ii,ij,1)         
+                     ii = idx_bdy(jbdy)%nbi(ib,igrd)
+                     ij = idx_bdy(jbdy)%nbj(ib,igrd)
+                     dta_bdy(jbdy)%u2d(ib) = un_b(ii,ij) * umask(ii,ij,1)         
                   END DO 
-               END IF
+               ENDIF
                IF( dta%ll_v2d ) THEN 
                   igrd = 3
                   DO ib = 1, ilen1(igrd)
-                     ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                     ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                     dta_bdy(ib_bdy)%v2d(ib) = vn_b(ii,ij) * vmask(ii,ij,1)         
+                     ii = idx_bdy(jbdy)%nbi(ib,igrd)
+                     ij = idx_bdy(jbdy)%nbj(ib,igrd)
+                     dta_bdy(jbdy)%v2d(ib) = vn_b(ii,ij) * vmask(ii,ij,1)         
                   END DO 
-               END IF
-            ENDIF
-
-            IF( nn_dyn3d_dta(ib_bdy) == 0 ) THEN 
+               ENDIF
+            ENDIF
+            !
+            IF( nn_dyn3d_dta(jbdy) == 0 ) THEN 
                ilen1(:) = nblen(:)
                IF( dta%ll_u3d ) THEN 
@@ -134,23 +136,23 @@
                   DO ib = 1, ilen1(igrd)
                      DO ik = 1, jpkm1
-                        ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                        ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                        dta_bdy(ib_bdy)%u3d(ib,ik) =  ( un(ii,ij,ik) - un_b(ii,ij) ) * umask(ii,ij,ik)         
+                        ii = idx_bdy(jbdy)%nbi(ib,igrd)
+                        ij = idx_bdy(jbdy)%nbj(ib,igrd)
+                        dta_bdy(jbdy)%u3d(ib,ik) =  ( un(ii,ij,ik) - un_b(ii,ij) ) * umask(ii,ij,ik)         
                      END DO
                   END DO 
-               END IF
+               ENDIF
                IF( dta%ll_v3d ) THEN 
                   igrd = 3 
                   DO ib = 1, ilen1(igrd)
                      DO ik = 1, jpkm1
-                        ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                        ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                        dta_bdy(ib_bdy)%v3d(ib,ik) =  ( vn(ii,ij,ik) - vn_b(ii,ij) ) * vmask(ii,ij,ik)         
+                        ii = idx_bdy(jbdy)%nbi(ib,igrd)
+                        ij = idx_bdy(jbdy)%nbj(ib,igrd)
+                        dta_bdy(jbdy)%v3d(ib,ik) =  ( vn(ii,ij,ik) - vn_b(ii,ij) ) * vmask(ii,ij,ik)         
                         END DO
                   END DO 
-               END IF
-            ENDIF
-
-            IF( nn_tra_dta(ib_bdy) == 0 ) THEN 
+               ENDIF
+            ENDIF
+
+            IF( nn_tra_dta(jbdy) == 0 ) THEN 
                ilen1(:) = nblen(:)
                IF( dta%ll_tem ) THEN
@@ -158,52 +160,24 @@
                   DO ib = 1, ilen1(igrd)
                      DO ik = 1, jpkm1
-                        ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                        ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                        dta_bdy(ib_bdy)%tem(ib,ik) = tsn(ii,ij,ik,jp_tem) * tmask(ii,ij,ik)         
+                        ii = idx_bdy(jbdy)%nbi(ib,igrd)
+                        ij = idx_bdy(jbdy)%nbj(ib,igrd)
+                        dta_bdy(jbdy)%tem(ib,ik) = tsn(ii,ij,ik,jp_tem) * tmask(ii,ij,ik)         
                      END DO
                   END DO 
-               END IF
+               ENDIF
                IF( dta%ll_sal ) THEN
                   igrd = 1 
                   DO ib = 1, ilen1(igrd)
                      DO ik = 1, jpkm1
-                        ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                        ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                        dta_bdy(ib_bdy)%sal(ib,ik) = tsn(ii,ij,ik,jp_sal) * tmask(ii,ij,ik)         
+                        ii = idx_bdy(jbdy)%nbi(ib,igrd)
+                        ij = idx_bdy(jbdy)%nbj(ib,igrd)
+                        dta_bdy(jbdy)%sal(ib,ik) = tsn(ii,ij,ik,jp_sal) * tmask(ii,ij,ik)         
                      END DO
                   END DO 
-               END IF
-            ENDIF
-
-#if defined key_lim2
-            IF( nn_ice_lim_dta(ib_bdy) == 0 ) THEN 
-               ilen1(:) = nblen(:)
-               IF( dta%ll_frld ) THEN
-                  igrd = 1 
-                  DO ib = 1, ilen1(igrd)
-                     ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                     ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                     dta_bdy(ib_bdy)%frld(ib) = frld(ii,ij) * tmask(ii,ij,1)         
-                  END DO 
-               END IF
-               IF( dta%ll_hicif ) THEN
-                  igrd = 1 
-                  DO ib = 1, ilen1(igrd)
-                     ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                     ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                     dta_bdy(ib_bdy)%hicif(ib) = hicif(ii,ij) * tmask(ii,ij,1)         
-                  END DO 
-               END IF
-               IF( dta%ll_hsnif ) THEN
-                  igrd = 1 
-                  DO ib = 1, ilen1(igrd)
-                     ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                     ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                     dta_bdy(ib_bdy)%hsnif(ib) = hsnif(ii,ij) * tmask(ii,ij,1)         
-                  END DO 
-               END IF
-            ENDIF
-#elif defined key_lim3
-            IF( nn_ice_lim_dta(ib_bdy) == 0 ) THEN 
+               ENDIF
+            ENDIF
+
+#if defined key_lim3
+            IF( nn_ice_lim_dta(jbdy) == 0 ) THEN    ! set ice to initial values
                ilen1(:) = nblen(:)
                IF( dta%ll_a_i ) THEN
@@ -211,27 +185,27 @@
                   DO jl = 1, jpl
                      DO ib = 1, ilen1(igrd)
-                        ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                        ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                        dta_bdy(ib_bdy)%a_i (ib,jl) =  a_i(ii,ij,jl) * tmask(ii,ij,1) 
+                        ii = idx_bdy(jbdy)%nbi(ib,igrd)
+                        ij = idx_bdy(jbdy)%nbj(ib,igrd)
+                        dta_bdy(jbdy)%a_i (ib,jl) =  a_i(ii,ij,jl) * tmask(ii,ij,1) 
                      END DO
                   END DO
                ENDIF
-               IF( dta%ll_ht_i ) THEN
+               IF( dta%ll_h_i ) THEN
                   igrd = 1   
                   DO jl = 1, jpl
                      DO ib = 1, ilen1(igrd)
-                        ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                        ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                        dta_bdy(ib_bdy)%ht_i (ib,jl) =  ht_i(ii,ij,jl) * tmask(ii,ij,1) 
+                        ii = idx_bdy(jbdy)%nbi(ib,igrd)
+                        ij = idx_bdy(jbdy)%nbj(ib,igrd)
+                        dta_bdy(jbdy)%h_i (ib,jl) =  h_i(ii,ij,jl) * tmask(ii,ij,1) 
                      END DO
                   END DO
                ENDIF
-               IF( dta%ll_ht_s ) THEN
+               IF( dta%ll_h_s ) THEN
                   igrd = 1   
                   DO jl = 1, jpl
                      DO ib = 1, ilen1(igrd)
-                        ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                        ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                        dta_bdy(ib_bdy)%ht_s (ib,jl) =  ht_s(ii,ij,jl) * tmask(ii,ij,1) 
+                        ii = idx_bdy(jbdy)%nbi(ib,igrd)
+                        ij = idx_bdy(jbdy)%nbj(ib,igrd)
+                        dta_bdy(jbdy)%h_s (ib,jl) =  h_s(ii,ij,jl) * tmask(ii,ij,1) 
                      END DO
                   END DO
@@ -239,5 +213,5 @@
             ENDIF
 #endif
-         END DO ! ib_bdy
+         END DO ! jbdy
          !
       ENDIF ! kt == nit000
@@ -247,25 +221,25 @@
      
       jstart = 1
-      DO ib_bdy = 1, nb_bdy   
-         dta => dta_bdy(ib_bdy)
-         IF( nn_dta(ib_bdy) == 1 ) THEN ! skip this bit if no external data required
+      DO jbdy = 1, nb_bdy   
+         dta => dta_bdy(jbdy)
+         IF( nn_dta(jbdy) == 1 ) THEN ! skip this bit if no external data required
       
             IF( PRESENT(jit) ) THEN
                ! Update barotropic boundary conditions only
                ! jit is optional argument for fld_read and bdytide_update
-               IF( cn_dyn2d(ib_bdy) /= 'none' ) THEN
-                  IF( nn_dyn2d_dta(ib_bdy) == 2 ) THEN ! tidal harmonic forcing ONLY: initialise arrays
+               IF( cn_dyn2d(jbdy) /= 'none' ) THEN
+                  IF( nn_dyn2d_dta(jbdy) == 2 ) THEN ! tidal harmonic forcing ONLY: initialise arrays
                      IF( dta%ll_ssh ) dta%ssh(:) = 0._wp
                      IF( dta%ll_u2d ) dta%u2d(:) = 0._wp
                      IF( dta%ll_u3d ) dta%v2d(:) = 0._wp
                   ENDIF
-                  IF (cn_tra(ib_bdy) /= 'runoff') THEN
-                     IF( nn_dyn2d_dta(ib_bdy) == 1 .OR. nn_dyn2d_dta(ib_bdy) == 3 ) THEN
+                  IF (cn_tra(jbdy) /= 'runoff') THEN
+                     IF( nn_dyn2d_dta(jbdy) == 1 .OR. nn_dyn2d_dta(jbdy) == 3 ) THEN
 
                         jend = jstart + dta%nread(2) - 1
-                        IF( ln_full_vel_array(ib_bdy) ) THEN
+                        IF( ln_full_vel_array(jbdy) ) THEN
                            CALL fld_read( kt=kt, kn_fsbc=1, sd=bf(jstart:jend), map=nbmap_ptr(jstart:jend),  &
                                      & kit=jit, kt_offset=time_offset , jpk_bdy=nb_jpk_bdy,   &
-                                     & fvl=ln_full_vel_array(ib_bdy)  )
+                                     & fvl=ln_full_vel_array(jbdy)  )
                         ELSE
                            CALL fld_read( kt=kt, kn_fsbc=1, sd=bf(jstart:jend), map=nbmap_ptr(jstart:jend),  &
@@ -274,13 +248,13 @@
 
                         ! If full velocities in boundary data then extract barotropic velocities from 3D fields
-                        IF( ln_full_vel_array(ib_bdy) .AND.                                             &
-                          &    ( nn_dyn2d_dta(ib_bdy) == 1 .OR. nn_dyn2d_dta(ib_bdy) == 3 .OR.  &
-                          &      nn_dyn3d_dta(ib_bdy) == 1 ) )THEN
+                        IF( ln_full_vel_array(jbdy) .AND.                                             &
+                          &    ( nn_dyn2d_dta(jbdy) == 1 .OR. nn_dyn2d_dta(jbdy) == 3 .OR.  &
+                          &      nn_dyn3d_dta(jbdy) == 1 ) )THEN
 
                            igrd = 2                      ! zonal velocity
                            dta%u2d(:) = 0._wp
-                           DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
-                              ii   = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                              ij   = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                           DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
+                              ii   = idx_bdy(jbdy)%nbi(ib,igrd)
+                              ij   = idx_bdy(jbdy)%nbj(ib,igrd)
                               DO ik = 1, jpkm1
                                  dta%u2d(ib) = dta%u2d(ib) &
@@ -291,7 +265,7 @@
                            igrd = 3                      ! meridional velocity
                            dta%v2d(:) = 0._wp
-                           DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
-                              ii   = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                              ij   = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                           DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
+                              ii   = idx_bdy(jbdy)%nbi(ib,igrd)
+                              ij   = idx_bdy(jbdy)%nbj(ib,igrd)
                               DO ik = 1, jpkm1
                                  dta%v2d(ib) = dta%v2d(ib) &
@@ -302,6 +276,6 @@
                         ENDIF                    
                      ENDIF
-                     IF( nn_dyn2d_dta(ib_bdy) .ge. 2 ) THEN ! update tidal harmonic forcing
-                        CALL bdytide_update( kt=kt, idx=idx_bdy(ib_bdy), dta=dta, td=tides(ib_bdy),   & 
+                     IF( nn_dyn2d_dta(jbdy) .ge. 2 ) THEN ! update tidal harmonic forcing
+                        CALL bdytide_update( kt=kt, idx=idx_bdy(jbdy), dta=dta, td=tides(jbdy),   & 
                           &                 jit=jit, time_offset=time_offset )
                      ENDIF
@@ -309,24 +283,24 @@
                ENDIF
             ELSE
-               IF (cn_tra(ib_bdy) == 'runoff') then      ! runoff condition
-                  jend = nb_bdy_fld(ib_bdy)
+               IF (cn_tra(jbdy) == 'runoff') then      ! runoff condition
+                  jend = nb_bdy_fld(jbdy)
                   CALL fld_read( kt=kt, kn_fsbc=1, sd=bf(jstart:jend),  &
                                & map=nbmap_ptr(jstart:jend), kt_offset=time_offset )
                   !
                   igrd = 2                      ! zonal velocity
-                  DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
-                     ii   = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                     ij   = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                  DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
+                     ii   = idx_bdy(jbdy)%nbi(ib,igrd)
+                     ij   = idx_bdy(jbdy)%nbj(ib,igrd)
                      dta%u2d(ib) = dta%u2d(ib) / ( e2u(ii,ij) * hu_0(ii,ij) )
                   END DO
                   !
                   igrd = 3                      ! meridional velocity
-                  DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
-                     ii   = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                     ij   = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                  DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
+                     ii   = idx_bdy(jbdy)%nbi(ib,igrd)
+                     ij   = idx_bdy(jbdy)%nbj(ib,igrd)
                      dta%v2d(ib) = dta%v2d(ib) / ( e1v(ii,ij) * hv_0(ii,ij) )
                   END DO
                ELSE
-                  IF( nn_dyn2d_dta(ib_bdy) == 2 ) THEN ! tidal harmonic forcing ONLY: initialise arrays
+                  IF( nn_dyn2d_dta(jbdy) == 2 ) THEN ! tidal harmonic forcing ONLY: initialise arrays
                      IF( dta%ll_ssh ) dta%ssh(:) = 0._wp
                      IF( dta%ll_u2d ) dta%u2d(:) = 0._wp
@@ -337,15 +311,15 @@
                      CALL fld_read( kt=kt, kn_fsbc=1, sd=bf(jstart:jend), &
                                   & map=nbmap_ptr(jstart:jend), kt_offset=time_offset, jpk_bdy=nb_jpk_bdy,   &
-                                  & fvl=ln_full_vel_array(ib_bdy) )
+                                  & fvl=ln_full_vel_array(jbdy) )
                   ENDIF
                   ! If full velocities in boundary data then split into barotropic and baroclinic data
-                  IF( ln_full_vel_array(ib_bdy) .and.                                             &
-                    & ( nn_dyn2d_dta(ib_bdy) == 1 .OR. nn_dyn2d_dta(ib_bdy) == 3 .OR. &
-                    &   nn_dyn3d_dta(ib_bdy) == 1 ) ) THEN
+                  IF( ln_full_vel_array(jbdy) .and.                                             &
+                    & ( nn_dyn2d_dta(jbdy) == 1 .OR. nn_dyn2d_dta(jbdy) == 3 .OR. &
+                    &   nn_dyn3d_dta(jbdy) == 1 ) ) THEN
                      igrd = 2                      ! zonal velocity
                      dta%u2d(:) = 0._wp
-                     DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
-                        ii   = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                        ij   = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                     DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
+                        ii   = idx_bdy(jbdy)%nbi(ib,igrd)
+                        ij   = idx_bdy(jbdy)%nbj(ib,igrd)
                         DO ik = 1, jpkm1
                            dta%u2d(ib) = dta%u2d(ib) &
@@ -359,7 +333,7 @@
                      igrd = 3                      ! meridional velocity
                      dta%v2d(:) = 0._wp
-                     DO ib = 1, idx_bdy(ib_bdy)%nblen(igrd)
-                        ii   = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                        ij   = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                     DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
+                        ii   = idx_bdy(jbdy)%nbi(ib,igrd)
+                        ij   = idx_bdy(jbdy)%nbj(ib,igrd)
                         DO ik = 1, jpkm1
                            dta%v2d(ib) = dta%v2d(ib) &
@@ -375,24 +349,29 @@
                ENDIF
 #if defined key_lim3
-               IF( .NOT. ll_bdylim3 .AND. cn_ice_lim(ib_bdy) /= 'none' .AND. nn_ice_lim_dta(ib_bdy) == 1 ) THEN ! bdy ice input (case input is lim2 type)
-     	          CALL lim_var_itd ( bf(jfld_hti)%fnow(:,1,1), bf(jfld_hts)%fnow(:,1,1), bf(jfld_ai)%fnow(:,1,1), &
-                                  & dta_bdy(ib_bdy)%ht_i,     dta_bdy(ib_bdy)%ht_s,     dta_bdy(ib_bdy)%a_i     )
+               IF( cn_ice_lim(jbdy) /= 'none' .AND. nn_ice_lim_dta(jbdy) == 1 ) THEN
+                  IF( nice_cat == 1 ) THEN ! case input cat = 1
+                     CALL ice_var_itd ( bf(jfld_hti)%fnow(:,1,1), bf(jfld_hts)%fnow(:,1,1), bf(jfld_ai)%fnow(:,1,1), &
+                        &               dta_bdy(jbdy)%h_i     , dta_bdy(jbdy)%h_s     , dta_bdy(jbdy)%a_i    )
+                  ELSEIF( nice_cat /= 1 .AND. nice_cat /= jpl ) THEN ! case input cat /=1 and /=jpl
+                     CALL ice_var_itd2( bf(jfld_hti)%fnow(:,1,:), bf(jfld_hts)%fnow(:,1,:), bf(jfld_ai)%fnow(:,1,:), &
+                        &               dta_bdy(jbdy)%h_i     , dta_bdy(jbdy)%h_s     , dta_bdy(jbdy)%a_i    )
+                  ENDIF
                ENDIF
 #endif
             ENDIF
             jstart = jstart + dta%nread(1)
-         END IF ! nn_dta(ib_bdy) = 1
-      END DO  ! ib_bdy
+         ENDIF    ! nn_dta(jbdy) = 1
+      END DO  ! jbdy
 
       IF ( ln_tide ) THEN
          IF (ln_dynspg_ts) THEN      ! Fill temporary arrays with slow-varying bdy data                           
-            DO ib_bdy = 1, nb_bdy    ! Tidal component added in ts loop
-               IF ( nn_dyn2d_dta(ib_bdy) .ge. 2 ) THEN
-                  nblen => idx_bdy(ib_bdy)%nblen
-                  nblenrim => idx_bdy(ib_bdy)%nblenrim
-                  IF( cn_dyn2d(ib_bdy) == 'frs' ) THEN; ilen1(:)=nblen(:) ; ELSE ; ilen1(:)=nblenrim(:) ; ENDIF 
-                  IF ( dta_bdy(ib_bdy)%ll_ssh ) dta_bdy_s(ib_bdy)%ssh(1:ilen1(1)) = dta_bdy(ib_bdy)%ssh(1:ilen1(1))
-                  IF ( dta_bdy(ib_bdy)%ll_u2d ) dta_bdy_s(ib_bdy)%u2d(1:ilen1(2)) = dta_bdy(ib_bdy)%u2d(1:ilen1(2))
-                  IF ( dta_bdy(ib_bdy)%ll_v2d ) dta_bdy_s(ib_bdy)%v2d(1:ilen1(3)) = dta_bdy(ib_bdy)%v2d(1:ilen1(3))
+            DO jbdy = 1, nb_bdy    ! Tidal component added in ts loop
+               IF ( nn_dyn2d_dta(jbdy) .ge. 2 ) THEN
+                  nblen => idx_bdy(jbdy)%nblen
+                  nblenrim => idx_bdy(jbdy)%nblenrim
+                  IF( cn_dyn2d(jbdy) == 'frs' ) THEN; ilen1(:)=nblen(:) ; ELSE ; ilen1(:)=nblenrim(:) ; ENDIF 
+                  IF ( dta_bdy(jbdy)%ll_ssh ) dta_bdy_s(jbdy)%ssh(1:ilen1(1)) = dta_bdy(jbdy)%ssh(1:ilen1(1))
+                  IF ( dta_bdy(jbdy)%ll_u2d ) dta_bdy_s(jbdy)%u2d(1:ilen1(2)) = dta_bdy(jbdy)%u2d(1:ilen1(2))
+                  IF ( dta_bdy(jbdy)%ll_v2d ) dta_bdy_s(jbdy)%v2d(1:ilen1(3)) = dta_bdy(jbdy)%v2d(1:ilen1(3))
                ENDIF
             END DO
@@ -404,11 +383,11 @@
 
       IF ( ln_apr_obc ) THEN
-         DO ib_bdy = 1, nb_bdy
-            IF (cn_tra(ib_bdy) /= 'runoff')THEN
+         DO jbdy = 1, nb_bdy
+            IF (cn_tra(jbdy) /= 'runoff')THEN
                igrd = 1                      ! meridional velocity
-               DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
-                  ii   = idx_bdy(ib_bdy)%nbi(ib,igrd)
-                  ij   = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                  dta_bdy(ib_bdy)%ssh(ib) = dta_bdy(ib_bdy)%ssh(ib) + ssh_ib(ii,ij)
+               DO ib = 1, idx_bdy(jbdy)%nblenrim(igrd)
+                  ii   = idx_bdy(jbdy)%nbi(ib,igrd)
+                  ij   = idx_bdy(jbdy)%nbj(ib,igrd)
+                  dta_bdy(jbdy)%ssh(ib) = dta_bdy(jbdy)%ssh(ib) + ssh_ib(ii,ij)
                END DO
             ENDIF
@@ -431,5 +410,5 @@
       !!                
       !!----------------------------------------------------------------------
-      INTEGER ::   ib_bdy, jfld, jstart, jend, ierror, ios     ! Local integers
+      INTEGER ::   jbdy, jfld, jstart, jend, ierror, ios     ! Local integers
       !
       CHARACTER(len=100)                     ::   cn_dir        ! Root directory for location of data files
@@ -437,5 +416,5 @@
       CHARACTER(len = 256)::   clname                           ! temporary file name
       LOGICAL                                ::   ln_full_vel   ! =T => full velocities in 3D boundary data
-                                                                ! =F => baroclinic velocities in 3D boundary data
+      !                                                         ! =F => baroclinic velocities in 3D boundary data
       INTEGER                                ::   ilen_global   ! Max length required for global bdy dta arrays
       INTEGER, ALLOCATABLE, DIMENSION(:)     ::   ilen1, ilen3  ! size of 1st and 3rd dimensions of local arrays
@@ -445,5 +424,6 @@
       TYPE(OBC_DATA), POINTER                ::   dta           ! short cut
 #if defined key_lim3
-      INTEGER               ::   zndims   ! number of dimensions in an array (i.e. 3 = wo ice cat; 4 = w ice cat)
+      INTEGER               ::   kndims   ! number of dimensions in an array (i.e. 3 = wo ice cat; 4 = w ice cat)
+      INTEGER, DIMENSION(4) ::   kdimsz   ! size   of dimensions
       INTEGER               ::   inum,id1 ! local integer
 #endif
@@ -451,14 +431,10 @@
       TYPE(FLD_N) ::   bn_tem, bn_sal, bn_u3d, bn_v3d   ! 
       TYPE(FLD_N) ::   bn_ssh, bn_u2d, bn_v2d           ! informations about the fields to be read
-#if defined key_lim2
-      TYPE(FLD_N) ::   bn_frld, bn_hicif, bn_hsnif      !
-#elif defined key_lim3
-      TYPE(FLD_N) ::   bn_a_i, bn_ht_i, bn_ht_s      
+#if defined key_lim3
+      TYPE(FLD_N) ::   bn_a_i, bn_h_i, bn_h_s      
 #endif
       NAMELIST/nambdy_dta/ cn_dir, bn_tem, bn_sal, bn_u3d, bn_v3d, bn_ssh, bn_u2d, bn_v2d 
-#if defined key_lim2
-      NAMELIST/nambdy_dta/ bn_frld, bn_hicif, bn_hsnif
-#elif defined key_lim3
-      NAMELIST/nambdy_dta/ bn_a_i, bn_ht_i, bn_ht_s
+#if defined key_lim3
+      NAMELIST/nambdy_dta/ bn_a_i, bn_h_i, bn_h_s
 #endif
       NAMELIST/nambdy_dta/ ln_full_vel, nb_jpk_bdy
@@ -473,13 +449,13 @@
 
       ! Set nn_dta
-      DO ib_bdy = 1, nb_bdy
-         nn_dta(ib_bdy) = MAX(  nn_dyn2d_dta(ib_bdy)       &
-                               ,nn_dyn3d_dta(ib_bdy)       &
-                               ,nn_tra_dta(ib_bdy)         &
-#if ( defined key_lim2 || defined key_lim3 )
-                              ,nn_ice_lim_dta(ib_bdy)    &
+      DO jbdy = 1, nb_bdy
+         nn_dta(jbdy) = MAX(   nn_dyn2d_dta  (jbdy)    &
+            &                , nn_dyn3d_dta  (jbdy)    &
+            &                , nn_tra_dta    (jbdy)    &
+#if defined key_lim3
+            &                , nn_ice_lim_dta(jbdy)    &
 #endif
                               )
-         IF(nn_dta(ib_bdy) > 1) nn_dta(ib_bdy) = 1
+         IF(nn_dta(jbdy) > 1)   nn_dta(jbdy) = 1
       END DO
 
@@ -488,20 +464,20 @@
       ALLOCATE( nb_bdy_fld(nb_bdy) )
       nb_bdy_fld(:) = 0
-      DO ib_bdy = 1, nb_bdy         
-         IF( cn_dyn2d(ib_bdy) /= 'none' .and. ( nn_dyn2d_dta(ib_bdy) == 1 .or. nn_dyn2d_dta(ib_bdy) == 3 ) ) THEN
-            nb_bdy_fld(ib_bdy) = nb_bdy_fld(ib_bdy) + 3
-         ENDIF
-         IF( cn_dyn3d(ib_bdy) /= 'none' .and. nn_dyn3d_dta(ib_bdy) == 1 ) THEN
-            nb_bdy_fld(ib_bdy) = nb_bdy_fld(ib_bdy) + 2
-         ENDIF
-         IF( cn_tra(ib_bdy) /= 'none' .and. nn_tra_dta(ib_bdy) == 1  ) THEN
-            nb_bdy_fld(ib_bdy) = nb_bdy_fld(ib_bdy) + 2
-         ENDIF
-#if ( defined key_lim2 || defined key_lim3 )
-         IF( cn_ice_lim(ib_bdy) /= 'none' .and. nn_ice_lim_dta(ib_bdy) == 1  ) THEN
-            nb_bdy_fld(ib_bdy) = nb_bdy_fld(ib_bdy) + 3
+      DO jbdy = 1, nb_bdy         
+         IF( cn_dyn2d(jbdy) /= 'none' .AND. ( nn_dyn2d_dta(jbdy) == 1 .or. nn_dyn2d_dta(jbdy) == 3 ) ) THEN
+            nb_bdy_fld(jbdy) = nb_bdy_fld(jbdy) + 3
+         ENDIF
+         IF( cn_dyn3d(jbdy) /= 'none' .AND. nn_dyn3d_dta(jbdy) == 1 ) THEN
+            nb_bdy_fld(jbdy) = nb_bdy_fld(jbdy) + 2
+         ENDIF
+         IF( cn_tra(jbdy) /= 'none' .AND. nn_tra_dta(jbdy) == 1  ) THEN
+            nb_bdy_fld(jbdy) = nb_bdy_fld(jbdy) + 2
+         ENDIF
+#if defined key_lim3
+         IF( cn_ice_lim(jbdy) /= 'none' .AND. nn_ice_lim_dta(jbdy) == 1  ) THEN
+            nb_bdy_fld(jbdy) = nb_bdy_fld(jbdy) + 3
          ENDIF
 #endif               
-         IF(lwp) WRITE(numout,*) 'Maximum number of files to open =',nb_bdy_fld(ib_bdy)
+         IF(lwp) WRITE(numout,*) 'Maximum number of files to open =', nb_bdy_fld(jbdy)
       END DO            
 
@@ -529,6 +505,6 @@
       REWIND(numnam_cfg)
       jfld = 0 
-      DO ib_bdy = 1, nb_bdy         
-         IF( nn_dta(ib_bdy) == 1 ) THEN
+      DO jbdy = 1, nb_bdy         
+         IF( nn_dta(jbdy) == 1 ) THEN
             READ  ( numnam_ref, nambdy_dta, IOSTAT = ios, ERR = 901)
 901         IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy_dta in reference namelist', lwp )
@@ -538,15 +514,15 @@
             IF(lwm) WRITE( numond, nambdy_dta )
 
-            cn_dir_array(ib_bdy) = cn_dir
-            ln_full_vel_array(ib_bdy) = ln_full_vel
-
-            nblen => idx_bdy(ib_bdy)%nblen
-            nblenrim => idx_bdy(ib_bdy)%nblenrim
-            dta => dta_bdy(ib_bdy)
+            cn_dir_array(jbdy) = cn_dir
+            ln_full_vel_array(jbdy) = ln_full_vel
+
+            nblen => idx_bdy(jbdy)%nblen
+            nblenrim => idx_bdy(jbdy)%nblenrim
+            dta => dta_bdy(jbdy)
             dta%nread(2) = 0
 
             ! Only read in necessary fields for this set.
             ! Important that barotropic variables come first.
-            IF( nn_dyn2d_dta(ib_bdy) == 1 .or. nn_dyn2d_dta(ib_bdy) == 3 ) THEN 
+            IF( nn_dyn2d_dta(jbdy) == 1 .or. nn_dyn2d_dta(jbdy) == 3 ) THEN 
 
                IF( dta%ll_ssh ) THEN 
@@ -554,5 +530,5 @@
                   jfld = jfld + 1
                   blf_i(jfld) = bn_ssh
-                  ibdy(jfld) = ib_bdy
+                  ibdy(jfld) = jbdy
                   igrid(jfld) = 1
                   ilen1(jfld) = nblen(igrid(jfld))
@@ -561,9 +537,9 @@
                ENDIF
 
-               IF( dta%ll_u2d .and. .not. ln_full_vel_array(ib_bdy) ) THEN
+               IF( dta%ll_u2d .and. .not. ln_full_vel_array(jbdy) ) THEN
                   if(lwp) write(numout,*) '++++++ reading in u2d field'
                   jfld = jfld + 1
                   blf_i(jfld) = bn_u2d
-                  ibdy(jfld) = ib_bdy
+                  ibdy(jfld) = jbdy
                   igrid(jfld) = 2
                   ilen1(jfld) = nblen(igrid(jfld))
@@ -572,9 +548,9 @@
                ENDIF
 
-               IF( dta%ll_v2d .and. .not. ln_full_vel_array(ib_bdy) ) THEN
+               IF( dta%ll_v2d .and. .not. ln_full_vel_array(jbdy) ) THEN
                   if(lwp) write(numout,*) '++++++ reading in v2d field'
                   jfld = jfld + 1
                   blf_i(jfld) = bn_v2d
-                  ibdy(jfld) = ib_bdy
+                  ibdy(jfld) = jbdy
                   igrid(jfld) = 3
                   ilen1(jfld) = nblen(igrid(jfld))
@@ -587,27 +563,27 @@
             ! read 3D velocities if baroclinic velocities require OR if
             ! barotropic velocities required and ln_full_vel set to .true.
-            IF( nn_dyn3d_dta(ib_bdy) == 1 .OR. &
-           &  ( ln_full_vel_array(ib_bdy) .AND. ( nn_dyn2d_dta(ib_bdy) == 1 .or. nn_dyn2d_dta(ib_bdy) == 3 ) ) ) THEN
-
-               IF( dta%ll_u3d .OR. ( ln_full_vel_array(ib_bdy) .and. dta%ll_u2d ) ) THEN
+            IF( nn_dyn3d_dta(jbdy) == 1 .OR. &
+           &  ( ln_full_vel_array(jbdy) .AND. ( nn_dyn2d_dta(jbdy) == 1 .OR. nn_dyn2d_dta(jbdy) == 3 ) ) ) THEN
+
+               IF( dta%ll_u3d .OR. ( ln_full_vel_array(jbdy) .and. dta%ll_u2d ) ) THEN
                   if(lwp) write(numout,*) '++++++ reading in u3d field'
                   jfld = jfld + 1
                   blf_i(jfld) = bn_u3d
-                  ibdy(jfld) = ib_bdy
+                  ibdy(jfld) = jbdy
                   igrid(jfld) = 2
                   ilen1(jfld) = nblen(igrid(jfld))
                   ilen3(jfld) = jpk
-                  IF( ln_full_vel_array(ib_bdy) .and. dta%ll_u2d ) dta%nread(2) = dta%nread(2) + 1
-               ENDIF
-
-               IF( dta%ll_v3d .OR. ( ln_full_vel_array(ib_bdy) .and. dta%ll_v2d ) ) THEN
+                  IF( ln_full_vel_array(jbdy) .and. dta%ll_u2d ) dta%nread(2) = dta%nread(2) + 1
+               ENDIF
+
+               IF( dta%ll_v3d .OR. ( ln_full_vel_array(jbdy) .and. dta%ll_v2d ) ) THEN
                   if(lwp) write(numout,*) '++++++ reading in v3d field'
                   jfld = jfld + 1
                   blf_i(jfld) = bn_v3d
-                  ibdy(jfld) = ib_bdy
+                  ibdy(jfld) = jbdy
                   igrid(jfld) = 3
                   ilen1(jfld) = nblen(igrid(jfld))
                   ilen3(jfld) = jpk
-                  IF( ln_full_vel_array(ib_bdy) .and. dta%ll_v2d ) dta%nread(2) = dta%nread(2) + 1
+                  IF( ln_full_vel_array(jbdy) .and. dta%ll_v2d ) dta%nread(2) = dta%nread(2) + 1
                ENDIF
 
@@ -615,5 +591,5 @@
 
             ! temperature and salinity
-            IF( nn_tra_dta(ib_bdy) == 1 ) THEN
+            IF( nn_tra_dta(jbdy) == 1 ) THEN
 
                IF( dta%ll_tem ) THEN
@@ -621,5 +597,5 @@
                   jfld = jfld + 1
                   blf_i(jfld) = bn_tem
-                  ibdy(jfld) = ib_bdy
+                  ibdy(jfld) = jbdy
                   igrid(jfld) = 1
                   ilen1(jfld) = nblen(igrid(jfld))
@@ -631,5 +607,5 @@
                   jfld = jfld + 1
                   blf_i(jfld) = bn_sal
-                  ibdy(jfld) = ib_bdy
+                  ibdy(jfld) = jbdy
                   igrid(jfld) = 1
                   ilen1(jfld) = nblen(igrid(jfld))
@@ -639,40 +615,8 @@
             ENDIF
 
-#if defined key_lim2
+#if defined key_lim3
             ! sea ice
-            IF( nn_ice_lim_dta(ib_bdy) == 1 ) THEN
-
-               IF( dta%ll_frld ) THEN
-                  jfld = jfld + 1
-                  blf_i(jfld) = bn_frld
-                  ibdy(jfld) = ib_bdy
-                  igrid(jfld) = 1
-                  ilen1(jfld) = nblen(igrid(jfld))
-                  ilen3(jfld) = 1
-               ENDIF
-
-               IF( dta%ll_hicif ) THEN
-                  jfld = jfld + 1
-                  blf_i(jfld) = bn_hicif
-                  ibdy(jfld) = ib_bdy
-                  igrid(jfld) = 1
-                  ilen1(jfld) = nblen(igrid(jfld))
-                  ilen3(jfld) = 1
-               ENDIF
-
-               IF( dta%ll_hsnif ) THEN
-                  jfld = jfld + 1
-                  blf_i(jfld) = bn_hsnif
-                  ibdy(jfld) = ib_bdy
-                  igrid(jfld) = 1
-                  ilen1(jfld) = nblen(igrid(jfld))
-                  ilen3(jfld) = 1
-               ENDIF
-
-            ENDIF
-#elif defined key_lim3
-            ! sea ice
-            IF( nn_ice_lim_dta(ib_bdy) == 1 ) THEN
-               ! Test for types of ice input (lim2 or lim3) 
+            IF( nn_ice_lim_dta(jbdy) == 1 ) THEN
+               ! Test for types of ice input (1cat or Xcat) 
                ! Build file name to find dimensions 
                clname=TRIM( cn_dir )//TRIM(bn_a_i%clname)
@@ -687,11 +631,11 @@
                !
                CALL iom_open  ( clname, inum )
-               id1 = iom_varid( inum, bn_a_i%clvar, kndims=zndims, ldstop = .FALSE. )
+               id1 = iom_varid( inum, bn_a_i%clvar, kdimsz=kdimsz, kndims=kndims, ldstop = .FALSE. )
                CALL iom_close ( inum )
 
-      	       IF ( zndims == 4 ) THEN
-                 ll_bdylim3 = .TRUE.   ! lim3 input
+      	       IF ( kndims == 4 ) THEN
+                 nice_cat = kdimsz(4)   ! Xcat input
                ELSE
-                 ll_bdylim3 = .FALSE.  ! lim2 input      
+                 nice_cat = 1           ! 1cat input      
                ENDIF
                ! End test
@@ -700,26 +644,26 @@
                   jfld = jfld + 1
                   blf_i(jfld) = bn_a_i
-                  ibdy(jfld) = ib_bdy
+                  ibdy(jfld)  = jbdy
                   igrid(jfld) = 1
                   ilen1(jfld) = nblen(igrid(jfld))
-                  IF ( ll_bdylim3 ) THEN ; ilen3(jfld)=jpl ; ELSE ; ilen3(jfld)=1 ; ENDIF
-               ENDIF
-
-               IF( dta%ll_ht_i ) THEN
-                  jfld = jfld + 1
-                  blf_i(jfld) = bn_ht_i
-                  ibdy(jfld) = ib_bdy
+                  ilen3(jfld) = nice_cat
+               ENDIF
+
+               IF( dta%ll_h_i ) THEN
+                  jfld = jfld + 1
+                  blf_i(jfld) = bn_h_i
+                  ibdy(jfld)  = jbdy
                   igrid(jfld) = 1
                   ilen1(jfld) = nblen(igrid(jfld))
-                  IF ( ll_bdylim3 ) THEN ; ilen3(jfld)=jpl ; ELSE ; ilen3(jfld)=1 ; ENDIF
-               ENDIF
-
-               IF( dta%ll_ht_s ) THEN
-                  jfld = jfld + 1
-                   blf_i(jfld) = bn_ht_s
-                  ibdy(jfld) = ib_bdy
+                  ilen3(jfld) = nice_cat
+               ENDIF
+
+               IF( dta%ll_h_s ) THEN
+                  jfld = jfld + 1
+                  blf_i(jfld) = bn_h_s
+                  ibdy(jfld)  = jbdy
                   igrid(jfld) = 1
                   ilen1(jfld) = nblen(igrid(jfld))
-                  IF ( ll_bdylim3 ) THEN ; ilen3(jfld)=jpl ; ELSE ; ilen3(jfld)=1 ; ENDIF
+                  ilen3(jfld) = nice_cat
                ENDIF
 
@@ -728,17 +672,17 @@
             ! Recalculate field counts
             !-------------------------
-            IF( ib_bdy == 1 ) THEN 
+            IF( jbdy == 1 ) THEN 
                nb_bdy_fld_sum = 0
-               nb_bdy_fld(ib_bdy) = jfld
+               nb_bdy_fld(jbdy) = jfld
                nb_bdy_fld_sum     = jfld              
             ELSE
-               nb_bdy_fld(ib_bdy) = jfld - nb_bdy_fld_sum
-               nb_bdy_fld_sum = nb_bdy_fld_sum + nb_bdy_fld(ib_bdy)
-            ENDIF
-
-            dta%nread(1) = nb_bdy_fld(ib_bdy)
+               nb_bdy_fld(jbdy) = jfld - nb_bdy_fld_sum
+               nb_bdy_fld_sum = nb_bdy_fld_sum + nb_bdy_fld(jbdy)
+            ENDIF
+
+            dta%nread(1) = nb_bdy_fld(jbdy)
 
          ENDIF ! nn_dta == 1
-      ENDDO ! ib_bdy
+      ENDDO ! jbdy
 
       DO jfld = 1, nb_bdy_fld_sum
@@ -752,7 +696,7 @@
       !-------------------------------------
       jstart = 1
-      DO ib_bdy = 1, nb_bdy
-         jend = jstart - 1 + nb_bdy_fld(ib_bdy) 
-         CALL fld_fill( bf(jstart:jend), blf_i(jstart:jend), cn_dir_array(ib_bdy), 'bdy_dta',   &
+      DO jbdy = 1, nb_bdy
+         jend = jstart - 1 + nb_bdy_fld(jbdy) 
+         CALL fld_fill( bf(jstart:jend), blf_i(jstart:jend), cn_dir_array(jbdy), 'bdy_dta',   &
          &              'open boundary conditions', 'nambdy_dta' )
          jstart = jend + 1
@@ -765,8 +709,8 @@
 
       jfld = 0
-      DO ib_bdy=1, nb_bdy
-
-         nblen => idx_bdy(ib_bdy)%nblen
-         dta => dta_bdy(ib_bdy)
+      DO jbdy=1, nb_bdy
+
+         nblen => idx_bdy(jbdy)%nblen
+         dta => dta_bdy(jbdy)
 
          if(lwp) then
@@ -780,5 +724,5 @@
          endif
 
-         IF ( nn_dyn2d_dta(ib_bdy) == 0 .or. nn_dyn2d_dta(ib_bdy) == 2 ) THEN
+         IF ( nn_dyn2d_dta(jbdy) == 0 .or. nn_dyn2d_dta(jbdy) == 2 ) THEN
             if(lwp) write(numout,*) '++++++ dta%ssh/u2d/u3d allocated space'
             IF( dta%ll_ssh ) ALLOCATE( dta%ssh(nblen(1)) )
@@ -786,5 +730,5 @@
             IF( dta%ll_v2d ) ALLOCATE( dta%v2d(nblen(3)) )
          ENDIF
-         IF ( nn_dyn2d_dta(ib_bdy) == 1 .or. nn_dyn2d_dta(ib_bdy) == 3 ) THEN
+         IF ( nn_dyn2d_dta(jbdy) == 1 .or. nn_dyn2d_dta(jbdy) == 3 ) THEN
             IF( dta%ll_ssh ) THEN
                if(lwp) write(numout,*) '++++++ dta%ssh pointing to fnow'
@@ -793,5 +737,5 @@
             ENDIF
             IF ( dta%ll_u2d ) THEN
-               IF ( ln_full_vel_array(ib_bdy) ) THEN
+               IF ( ln_full_vel_array(jbdy) ) THEN
                   if(lwp) write(numout,*) '++++++ dta%u2d allocated space'
                   ALLOCATE( dta%u2d(nblen(2)) )
@@ -803,5 +747,5 @@
             ENDIF
             IF ( dta%ll_v2d ) THEN
-               IF ( ln_full_vel_array(ib_bdy) ) THEN
+               IF ( ln_full_vel_array(jbdy) ) THEN
                   if(lwp) write(numout,*) '++++++ dta%v2d allocated space'
                   ALLOCATE( dta%v2d(nblen(3)) )
@@ -814,80 +758,65 @@
          ENDIF
 
-         IF ( nn_dyn3d_dta(ib_bdy) == 0 ) THEN
+         IF ( nn_dyn3d_dta(jbdy) == 0 ) THEN
             if(lwp) write(numout,*) '++++++ dta%u3d/v3d allocated space'
-            IF( dta%ll_u3d ) ALLOCATE( dta_bdy(ib_bdy)%u3d(nblen(2),jpk) )
-            IF( dta%ll_v3d ) ALLOCATE( dta_bdy(ib_bdy)%v3d(nblen(3),jpk) )
-         ENDIF
-         IF ( nn_dyn3d_dta(ib_bdy) == 1 .or. &
-           &  ( ln_full_vel_array(ib_bdy) .and. ( nn_dyn2d_dta(ib_bdy) == 1 .or. nn_dyn2d_dta(ib_bdy) == 3 ) ) ) THEN
-            IF ( dta%ll_u3d .or. ( ln_full_vel_array(ib_bdy) .and. dta%ll_u2d ) ) THEN
+            IF( dta%ll_u3d ) ALLOCATE( dta_bdy(jbdy)%u3d(nblen(2),jpk) )
+            IF( dta%ll_v3d ) ALLOCATE( dta_bdy(jbdy)%v3d(nblen(3),jpk) )
+         ENDIF
+         IF ( nn_dyn3d_dta(jbdy) == 1 .or. &
+           &  ( ln_full_vel_array(jbdy) .and. ( nn_dyn2d_dta(jbdy) == 1 .or. nn_dyn2d_dta(jbdy) == 3 ) ) ) THEN
+            IF ( dta%ll_u3d .or. ( ln_full_vel_array(jbdy) .and. dta%ll_u2d ) ) THEN
                if(lwp) write(numout,*) '++++++ dta%u3d pointing to fnow'
                jfld = jfld + 1
-               dta_bdy(ib_bdy)%u3d => bf(jfld)%fnow(:,1,:)
-            ENDIF
-            IF ( dta%ll_v3d .or. ( ln_full_vel_array(ib_bdy) .and. dta%ll_v2d ) ) THEN
+               dta_bdy(jbdy)%u3d => bf(jfld)%fnow(:,1,:)
+            ENDIF
+            IF ( dta%ll_v3d .or. ( ln_full_vel_array(jbdy) .and. dta%ll_v2d ) ) THEN
                if(lwp) write(numout,*) '++++++ dta%v3d pointing to fnow'
                jfld = jfld + 1
-               dta_bdy(ib_bdy)%v3d => bf(jfld)%fnow(:,1,:)
-            ENDIF
-         ENDIF
-
-         IF( nn_tra_dta(ib_bdy) == 0 ) THEN
+               dta_bdy(jbdy)%v3d => bf(jfld)%fnow(:,1,:)
+            ENDIF
+         ENDIF
+
+         IF( nn_tra_dta(jbdy) == 0 ) THEN
             if(lwp) write(numout,*) '++++++ dta%tem/sal allocated space'
-            IF( dta%ll_tem ) ALLOCATE( dta_bdy(ib_bdy)%tem(nblen(1),jpk) )
-            IF( dta%ll_sal ) ALLOCATE( dta_bdy(ib_bdy)%sal(nblen(1),jpk) )
+            IF( dta%ll_tem ) ALLOCATE( dta_bdy(jbdy)%tem(nblen(1),jpk) )
+            IF( dta%ll_sal ) ALLOCATE( dta_bdy(jbdy)%sal(nblen(1),jpk) )
          ELSE
             IF( dta%ll_tem ) THEN
                if(lwp) write(numout,*) '++++++ dta%tem pointing to fnow'
                jfld = jfld + 1
-               dta_bdy(ib_bdy)%tem => bf(jfld)%fnow(:,1,:)
+               dta_bdy(jbdy)%tem => bf(jfld)%fnow(:,1,:)
             ENDIF
             IF( dta%ll_sal ) THEN 
                if(lwp) write(numout,*) '++++++ dta%sal pointing to fnow'
                jfld = jfld + 1
-               dta_bdy(ib_bdy)%sal => bf(jfld)%fnow(:,1,:)
-            ENDIF
-         ENDIF
-
-#if defined key_lim2
-         IF (cn_ice_lim(ib_bdy) /= 'none') THEN
-            IF( nn_ice_lim_dta(ib_bdy) == 0 ) THEN
-               ALLOCATE( dta_bdy(ib_bdy)%frld(nblen(1)) )
-               ALLOCATE( dta_bdy(ib_bdy)%hicif(nblen(1)) )
-               ALLOCATE( dta_bdy(ib_bdy)%hsnif(nblen(1)) )
+               dta_bdy(jbdy)%sal => bf(jfld)%fnow(:,1,:)
+            ENDIF
+         ENDIF
+
+#if defined key_lim3
+         IF (cn_ice_lim(jbdy) /= 'none') THEN
+            IF( nn_ice_lim_dta(jbdy) == 0 ) THEN
+               ALLOCATE( dta_bdy(jbdy)%a_i(nblen(1),jpl) )
+               ALLOCATE( dta_bdy(jbdy)%h_i(nblen(1),jpl) )
+               ALLOCATE( dta_bdy(jbdy)%h_s(nblen(1),jpl) )
             ELSE
-               jfld = jfld + 1
-               dta_bdy(ib_bdy)%frld  => bf(jfld)%fnow(:,1,1)
-               jfld = jfld + 1
-               dta_bdy(ib_bdy)%hicif => bf(jfld)%fnow(:,1,1)
-               jfld = jfld + 1
-               dta_bdy(ib_bdy)%hsnif => bf(jfld)%fnow(:,1,1)
-            ENDIF
-         ENDIF
-#elif defined key_lim3
-         IF (cn_ice_lim(ib_bdy) /= 'none') THEN
-            IF( nn_ice_lim_dta(ib_bdy) == 0 ) THEN
-               ALLOCATE( dta_bdy(ib_bdy)%a_i (nblen(1),jpl) )
-               ALLOCATE( dta_bdy(ib_bdy)%ht_i(nblen(1),jpl) )
-               ALLOCATE( dta_bdy(ib_bdy)%ht_s(nblen(1),jpl) )
-            ELSE
-               IF ( ll_bdylim3 ) THEN ! case input is lim3 type
-                  jfld = jfld + 1
-                  dta_bdy(ib_bdy)%a_i  => bf(jfld)%fnow(:,1,:)
-                  jfld = jfld + 1
-                  dta_bdy(ib_bdy)%ht_i => bf(jfld)%fnow(:,1,:)
-                  jfld = jfld + 1
-                  dta_bdy(ib_bdy)%ht_s => bf(jfld)%fnow(:,1,:)
-               ELSE ! case input is lim2 type
+               IF ( nice_cat == jpl ) THEN ! case input cat = jpl
+                  jfld = jfld + 1
+                  dta_bdy(jbdy)%a_i => bf(jfld)%fnow(:,1,:)
+                  jfld = jfld + 1
+                  dta_bdy(jbdy)%h_i => bf(jfld)%fnow(:,1,:)
+                  jfld = jfld + 1
+                  dta_bdy(jbdy)%h_s => bf(jfld)%fnow(:,1,:)
+               ELSE                        ! case input cat = 1 OR (/=1 and /=jpl)
                   jfld_ai  = jfld + 1
                   jfld_hti = jfld + 2
                   jfld_hts = jfld + 3
                   jfld     = jfld + 3
-                  ALLOCATE( dta_bdy(ib_bdy)%a_i (nblen(1),jpl) )
-                  ALLOCATE( dta_bdy(ib_bdy)%ht_i(nblen(1),jpl) )
-                  ALLOCATE( dta_bdy(ib_bdy)%ht_s(nblen(1),jpl) )
-                  dta_bdy(ib_bdy)%a_i (:,:) = 0._wp
-                  dta_bdy(ib_bdy)%ht_i(:,:) = 0._wp
-                  dta_bdy(ib_bdy)%ht_s(:,:) = 0._wp
+                  ALLOCATE( dta_bdy(jbdy)%a_i(nblen(1),jpl) )
+                  ALLOCATE( dta_bdy(jbdy)%h_i(nblen(1),jpl) )
+                  ALLOCATE( dta_bdy(jbdy)%h_s(nblen(1),jpl) )
+                  dta_bdy(jbdy)%a_i(:,:) = 0._wp
+                  dta_bdy(jbdy)%h_i(:,:) = 0._wp
+                  dta_bdy(jbdy)%h_s(:,:) = 0._wp
                ENDIF
 
@@ -896,5 +825,5 @@
 #endif
          !
-      END DO ! ib_bdy 
+      END DO ! jbdy 
       !
       IF( nn_timing == 1 ) CALL timing_stop('bdy_dta_init')
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn2d.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn2d.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn2d.F90	(revision 9019)
@@ -249,6 +249,4 @@
       !  
       CALL bdy_orlanski_2d( idx, igrd, pvb2d, pva2d, dta%v2d, ll_npo )
-      !
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_dyn2d_orlanski')
       !
       CALL lbc_bdy_lnk( pua2d, 'U', -1., ib_bdy )   ! Boundary points should be updated
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice.F90	(revision 9019)
@@ -0,0 +1,372 @@
+MODULE bdyice
+   !!======================================================================
+   !!                       ***  MODULE  bdyice  ***
+   !! Unstructured Open Boundary Cond. :  Open boundary conditions for sea-ice (LIM3)
+   !!======================================================================
+   !!  History :  3.3  !  2010-09 (D. Storkey)  Original code
+   !!             3.4  !  2011    (D. Storkey)  rewrite in preparation for OBC-BDY merge
+   !!              -   !  2012-01 (C. Rousset)  add lim3 and remove useless jk loop 
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                                 LIM-3 sea ice model
+   !!----------------------------------------------------------------------
+   !!   bdy_ice        : Application of open boundaries to ice
+   !!   bdy_ice_frs    : Application of Flow Relaxation Scheme
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE ice             ! sea-ice: variables
+   USE icevar          ! sea-ice: operations
+   USE iceitd          ! sea-ice: rebining
+   USE icectl          ! sea-ice: control prints
+   USE phycst          ! physical constant
+   USE eosbn2          ! equation of state
+   USE par_oce         ! ocean parameters
+   USE dom_oce         ! ocean space and time domain variables 
+   USE sbc_oce         ! Surface boundary condition: ocean fields
+   USE bdy_oce         ! ocean open boundary conditions
+   !
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager  ! write to numout file
+   USE lib_mpp         ! distributed memory computing
+   USE lib_fortran     ! to use key_nosignedzero
+   USE timing          ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   bdy_ice     ! routine called in sbcmod
+   PUBLIC   bdy_ice_dyn ! routine called in limrhg
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
+   !! $Id: bdyice.F90 8306 2017-07-10 10:18:03Z clem $
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE bdy_ice( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  SUBROUTINE bdy_ice  ***
+      !!
+      !! ** Purpose : - Apply open boundary conditions for ice (LIM3)
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! Main time step counter
+      !
+      INTEGER ::   ib_bdy   ! Loop index
+      !!----------------------------------------------------------------------
+      !
+      CALL ice_var_glo2eqv
+      !
+      DO ib_bdy = 1, nb_bdy
+         !
+         SELECT CASE( cn_ice_lim(ib_bdy) )
+         CASE('none')
+            CYCLE
+         CASE('frs')
+            CALL bdy_ice_frs( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
+         CASE DEFAULT
+            CALL ctl_stop( 'bdy_ice : unrecognised option for open boundaries for ice fields' )
+         END SELECT
+         !
+      END DO
+      !
+                        CALL ice_var_zapsmall
+                        CALL ice_var_agg(1)
+      IF( ln_icectl )   CALL ice_prt( kt, iiceprt, jiceprt, 1, ' - ice thermo bdy - ' )
+      !
+   END SUBROUTINE bdy_ice
+
+
+   SUBROUTINE bdy_ice_frs( idx, dta, kt, ib_bdy )
+      !!------------------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_ice_frs  ***
+      !!                    
+      !! ** Purpose : Apply the Flow Relaxation Scheme for sea-ice fields in the case 
+      !!              of unstructured open boundaries.
+      !! 
+      !! Reference : Engedahl H., 1995: Use of the flow relaxation scheme in a three-
+      !!             dimensional baroclinic ocean model with realistic topography. Tellus, 365-382.
+      !!------------------------------------------------------------------------------
+      TYPE(OBC_INDEX), INTENT(in) ::   idx     ! OBC indices
+      TYPE(OBC_DATA),  INTENT(in) ::   dta     ! OBC external data
+      INTEGER,         INTENT(in) ::   kt      ! main time-step counter
+      INTEGER,         INTENT(in) ::   ib_bdy  ! BDY set index
+      !
+      INTEGER  ::   jpbound            ! 0 = incoming ice
+      !                                ! 1 = outgoing ice
+      INTEGER  ::   jb, jk, jgrd, jl   ! dummy loop indices
+      INTEGER  ::   ji, jj, ii, ij     ! local scalar
+      REAL(wp) ::   zwgt, zwgt1        ! local scalar
+      REAL(wp) ::   ztmelts, zdh
+      !!------------------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('bdy_ice_frs')
+      !
+      jgrd = 1      ! Everything is at T-points here
+      !
+      DO jl = 1, jpl
+         DO jb = 1, idx%nblenrim(jgrd)
+            ji    = idx%nbi(jb,jgrd)
+            jj    = idx%nbj(jb,jgrd)
+            zwgt  = idx%nbw(jb,jgrd)
+            zwgt1 = 1.e0 - idx%nbw(jb,jgrd)
+            a_i(ji,jj,jl) = ( a_i(ji,jj,jl) * zwgt1 + dta%a_i(jb,jl) * zwgt ) * tmask(ji,jj,1)  ! Leads fraction 
+            h_i(ji,jj,jl) = ( h_i(ji,jj,jl) * zwgt1 + dta%h_i(jb,jl) * zwgt ) * tmask(ji,jj,1)  ! Ice depth 
+            h_s(ji,jj,jl) = ( h_s(ji,jj,jl) * zwgt1 + dta%h_s(jb,jl) * zwgt ) * tmask(ji,jj,1)  ! Snow depth
+
+            ! -----------------
+            ! Pathological case
+            ! -----------------
+            ! In case a) snow load would be in excess or b) ice is coming into a warmer environment that would lead to 
+            ! very large transformation from snow to ice (see icethd_dh.F90)
+
+            ! Then, a) transfer the snow excess into the ice (different from icethd_dh)
+            zdh = MAX( 0._wp, ( rhosn * h_s(ji,jj,jl) + ( rhoic - rau0 ) * h_i(ji,jj,jl) ) * r1_rau0 )
+            ! Or, b) transfer all the snow into ice (if incoming ice is likely to melt as it comes into a warmer environment)
+            !zdh = MAX( 0._wp, h_s(ji,jj,jl) * rhosn / rhoic )
+
+            ! recompute h_i, h_s
+            h_i(ji,jj,jl) = MIN( hi_max(jl), h_i(ji,jj,jl) + zdh )
+            h_s(ji,jj,jl) = MAX( 0._wp, h_s(ji,jj,jl) - zdh * rhoic / rhosn ) 
+
+         ENDDO
+         CALL lbc_bdy_lnk( a_i(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk( h_i(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk( h_s(:,:,jl), 'T', 1., ib_bdy )
+      ENDDO
+      ! retrieve at_i
+      at_i(:,:) = 0._wp
+      DO jl = 1, jpl
+         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+      END DO
+
+      DO jl = 1, jpl
+         DO jb = 1, idx%nblenrim(jgrd)
+            ji    = idx%nbi(jb,jgrd)
+            jj    = idx%nbj(jb,jgrd)
+
+            ! condition on ice thickness depends on the ice velocity
+            ! if velocity is outward (strictly), then ice thickness, volume... must be equal to adjacent values
+            jpbound = 0   ;   ii = ji   ;   ij = jj
+            !
+            IF( u_ice(ji+1,jj  ) < 0. .AND. umask(ji-1,jj  ,1) == 0. ) jpbound = 1; ii = ji+1; ij = jj
+            IF( u_ice(ji-1,jj  ) > 0. .AND. umask(ji+1,jj  ,1) == 0. ) jpbound = 1; ii = ji-1; ij = jj
+            IF( v_ice(ji  ,jj+1) < 0. .AND. vmask(ji  ,jj-1,1) == 0. ) jpbound = 1; ii = ji  ; ij = jj+1
+            IF( v_ice(ji  ,jj-1) > 0. .AND. vmask(ji  ,jj+1,1) == 0. ) jpbound = 1; ii = ji  ; ij = jj-1
+            !
+            IF( nn_ice_lim_dta(ib_bdy) == 0 ) jpbound = 0; ii = ji; ij = jj   ! case ice boundaries = initial conditions
+            !                                                                 !      do not make state variables dependent on velocity
+            !
+            rswitch = MAX( 0.0_wp , SIGN ( 1.0_wp , at_i(ii,ij) - 0.01 ) ) ! 0 if no ice
+            !
+            ! concentration and thickness
+            a_i(ji,jj,jl) = a_i(ii,ij,jl) * rswitch
+            h_i(ji,jj,jl) = h_i(ii,ij,jl) * rswitch
+            h_s(ji,jj,jl) = h_s(ii,ij,jl) * rswitch
+            !
+            ! Ice and snow volumes
+            v_i(ji,jj,jl) = h_i(ji,jj,jl) * a_i(ji,jj,jl)
+            v_s(ji,jj,jl) = h_s(ji,jj,jl) * a_i(ji,jj,jl)
+            !
+            SELECT CASE( jpbound )
+            !
+            CASE( 0 )   ! velocity is inward
+               !
+               ! Ice salinity, age, temperature
+               s_i (ji,jj,jl)   = rswitch * rn_ice_sal(ib_bdy)  + ( 1.0 - rswitch ) * rn_simin
+               oa_i(ji,jj,jl)   = rswitch * rn_ice_age(ib_bdy) * a_i(ji,jj,jl)
+               t_su(ji,jj,jl)   = rswitch * rn_ice_tem(ib_bdy)  + ( 1.0 - rswitch ) * rn_ice_tem(ib_bdy)
+               DO jk = 1, nlay_s
+                  t_s(ji,jj,jk,jl) = rswitch * rn_ice_tem(ib_bdy) + ( 1.0 - rswitch ) * rt0
+               END DO
+               DO jk = 1, nlay_i
+                  t_i (ji,jj,jk,jl) = rswitch * rn_ice_tem(ib_bdy) + ( 1.0 - rswitch ) * rt0 
+                  sz_i(ji,jj,jk,jl) = rswitch * rn_ice_sal(ib_bdy) + ( 1.0 - rswitch ) * rn_simin
+               END DO
+               !
+            CASE( 1 )   ! velocity is outward
+               !
+               ! Ice salinity, age, temperature
+               s_i (ji,jj,jl)   = rswitch * s_i (ii,ij,jl)  + ( 1.0 - rswitch ) * rn_simin
+               oa_i(ji,jj,jl)   = rswitch * oa_i(ii,ij,jl)
+               t_su(ji,jj,jl)   = rswitch * t_su(ii,ij,jl)  + ( 1.0 - rswitch ) * rt0
+               DO jk = 1, nlay_s
+                  t_s(ji,jj,jk,jl) = rswitch * t_s(ii,ij,jk,jl) + ( 1.0 - rswitch ) * rt0
+               END DO
+               DO jk = 1, nlay_i
+                  t_i (ji,jj,jk,jl) = rswitch * t_i (ii,ij,jk,jl) + ( 1.0 - rswitch ) * rt0
+                  sz_i(ji,jj,jk,jl) = rswitch * sz_i(ii,ij,jk,jl) + ( 1.0 - rswitch ) * rn_simin
+               END DO
+               !
+            END SELECT
+            !
+            IF( nn_icesal == 1 ) THEN     ! constant salinity : overwrite rn_icesal
+               s_i (ji,jj  ,jl) = rn_icesal
+               sz_i(ji,jj,:,jl) = rn_icesal
+            ENDIF
+            !
+            ! contents
+            sv_i(ji,jj,jl)  = MIN( s_i(ji,jj,jl) , sss_m(ji,jj) ) * v_i(ji,jj,jl)
+            DO jk = 1, nlay_s
+               ! Snow energy of melting
+               e_s(ji,jj,jk,jl) = rswitch * rhosn * ( cpic * ( rt0 - t_s(ji,jj,jk,jl) ) + lfus )
+               ! Multiply by volume, so that heat content in J/m2
+               e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) * v_s(ji,jj,jl) * r1_nlay_s
+            END DO
+            DO jk = 1, nlay_i
+               ztmelts          = - tmut * sz_i(ji,jj,jk,jl) + rt0 !Melting temperature in K                  
+               ! heat content per unit volume
+               e_i(ji,jj,jk,jl) = rswitch * rhoic * &
+                  (   cpic    * ( ztmelts - t_i(ji,jj,jk,jl) ) &
+                  +   lfus    * ( 1.0 - (ztmelts-rt0) / MIN((t_i(ji,jj,jk,jl)-rt0),-epsi20) ) &
+                  - rcp      * ( ztmelts - rt0 ) )
+               ! Mutliply by ice volume, and divide by number of layers to get heat content in J/m2
+               e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * a_i(ji,jj,jl) * h_i(ji,jj,jl) * r1_nlay_i
+            END DO
+            !
+         END DO
+         !
+         CALL lbc_bdy_lnk( a_i(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk( h_i(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk( h_s(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk( v_i(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk( v_s(:,:,jl), 'T', 1., ib_bdy )
+         !
+         CALL lbc_bdy_lnk( sv_i(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk(  s_i(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk( oa_i(:,:,jl), 'T', 1., ib_bdy )
+         CALL lbc_bdy_lnk( t_su(:,:,jl), 'T', 1., ib_bdy )
+         DO jk = 1, nlay_s
+            CALL lbc_bdy_lnk(t_s(:,:,jk,jl), 'T', 1., ib_bdy )
+            CALL lbc_bdy_lnk(e_s(:,:,jk,jl), 'T', 1., ib_bdy )
+         END DO
+         DO jk = 1, nlay_i
+            CALL lbc_bdy_lnk(t_i(:,:,jk,jl), 'T', 1., ib_bdy )
+            CALL lbc_bdy_lnk(e_i(:,:,jk,jl), 'T', 1., ib_bdy )
+         END DO
+         !
+      END DO !jl
+      !
+      ! --- In case categories are out of bounds, do a remapping --- !
+      !     i.e. inputs have not the same ice thickness distribution 
+      !          (set by rn_himean) than the regional simulation
+      IF( jpl > 1 )   CALL ice_itd_reb( kt )
+      !      
+      IF( ln_timing )   CALL timing_stop('bdy_ice_frs')
+      !
+   END SUBROUTINE bdy_ice_frs
+
+
+   SUBROUTINE bdy_ice_dyn( cd_type )
+      !!------------------------------------------------------------------------------
+      !!                 ***  SUBROUTINE bdy_ice_dyn  ***
+      !!                    
+      !! ** Purpose : Apply dynamics boundary conditions for sea-ice in the cas of unstructured open boundaries.
+      !!              u_ice and v_ice are equal to the value of the adjacent grid point if this latter is not ice free
+      !!              if adjacent grid point is ice free, then u_ice and v_ice are equal to ocean velocities
+      !!
+      !! 2013-06 : C. Rousset
+      !!------------------------------------------------------------------------------
+      CHARACTER(len=1), INTENT(in)  ::   cd_type   ! nature of velocity grid-points
+      !
+      INTEGER  ::   jb, jgrd           ! dummy loop indices
+      INTEGER  ::   ji, jj             ! local scalar
+      INTEGER  ::   ib_bdy             ! Loop index
+      REAL(wp) ::   zmsk1, zmsk2, zflag
+      !!------------------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('bdy_ice_dyn')
+      !
+      DO ib_bdy=1, nb_bdy
+         !
+         SELECT CASE( cn_ice_lim(ib_bdy) )
+         !
+         CASE('none')
+            CYCLE
+            !
+         CASE('frs')
+            !
+            IF( nn_ice_lim_dta(ib_bdy) == 0 ) CYCLE            ! case ice boundaries = initial conditions 
+            !                                                  !      do not change ice velocity (it is only computed by rheology)
+            SELECT CASE ( cd_type )
+            !     
+            CASE ( 'U' )  
+               jgrd = 2      ! u velocity
+               DO jb = 1, idx_bdy(ib_bdy)%nblenrim(jgrd)
+                  ji    = idx_bdy(ib_bdy)%nbi(jb,jgrd)
+                  jj    = idx_bdy(ib_bdy)%nbj(jb,jgrd)
+                  zflag = idx_bdy(ib_bdy)%flagu(jb,jgrd)
+                  !
+                  IF ( ABS( zflag ) == 1. ) THEN  ! eastern and western boundaries
+                     ! one of the two zmsk is always 0 (because of zflag)
+                     zmsk1 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji+1,jj) ) ) ! 0 if no ice
+                     zmsk2 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji-1,jj) ) ) ! 0 if no ice
+                     !  
+                     ! u_ice = u_ice of the adjacent grid point except if this grid point is ice-free (then u_ice = u_oce)
+                     u_ice (ji,jj) = u_ice(ji+1,jj) * 0.5_wp * ABS( zflag + 1._wp ) * zmsk1 + &
+                        &            u_ice(ji-1,jj) * 0.5_wp * ABS( zflag - 1._wp ) * zmsk2 + &
+                        &            u_oce(ji  ,jj) * ( 1._wp - MIN( 1._wp, zmsk1 + zmsk2 ) )
+                  ELSE                             ! everywhere else
+                     !u_ice(ji,jj) = u_oce(ji,jj)
+                     u_ice(ji,jj) = 0._wp
+                  ENDIF
+                  ! mask ice velocities
+                  rswitch = MAX( 0.0_wp , SIGN ( 1.0_wp , at_i(ji,jj) - 0.01_wp ) ) ! 0 if no ice
+                  u_ice(ji,jj) = rswitch * u_ice(ji,jj)
+                  !
+               END DO
+               CALL lbc_bdy_lnk( u_ice(:,:), 'U', -1., ib_bdy )
+               !
+            CASE ( 'V' )
+               jgrd = 3      ! v velocity
+               DO jb = 1, idx_bdy(ib_bdy)%nblenrim(jgrd)
+                  ji    = idx_bdy(ib_bdy)%nbi(jb,jgrd)
+                  jj    = idx_bdy(ib_bdy)%nbj(jb,jgrd)
+                  zflag = idx_bdy(ib_bdy)%flagv(jb,jgrd)
+                  !
+                  IF ( ABS( zflag ) == 1. ) THEN  ! northern and southern boundaries
+                     ! one of the two zmsk is always 0 (because of zflag)
+                     zmsk1 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji,jj+1) ) ) ! 0 if no ice
+                     zmsk2 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji,jj-1) ) ) ! 0 if no ice
+                     !  
+                     ! u_ice = u_ice of the adjacent grid point except if this grid point is ice-free (then u_ice = u_oce)
+                     v_ice (ji,jj) = v_ice(ji,jj+1) * 0.5_wp * ABS( zflag + 1._wp ) * zmsk1 + &
+                        &            v_ice(ji,jj-1) * 0.5_wp * ABS( zflag - 1._wp ) * zmsk2 + &
+                        &            v_oce(ji,jj  ) * ( 1._wp - MIN( 1._wp, zmsk1 + zmsk2 ) )
+                  ELSE                             ! everywhere else
+                     !v_ice(ji,jj) = v_oce(ji,jj)
+                     v_ice(ji,jj) = 0._wp
+                  ENDIF
+                  ! mask ice velocities
+                  rswitch = MAX( 0.0_wp , SIGN ( 1.0_wp , at_i(ji,jj) - 0.01 ) ) ! 0 if no ice
+                  v_ice(ji,jj) = rswitch * v_ice(ji,jj)
+                  !
+               END DO
+               CALL lbc_bdy_lnk( v_ice(:,:), 'V', -1., ib_bdy )
+               !
+            END SELECT
+            !
+         CASE DEFAULT
+            CALL ctl_stop( 'bdy_ice_dyn : unrecognised option for open boundaries for ice fields' )
+         END SELECT
+         !
+      END DO
+      !
+      IF( ln_timing )   CALL timing_stop('bdy_ice_dyn')
+      !
+    END SUBROUTINE bdy_ice_dyn
+
+#else
+   !!---------------------------------------------------------------------------------
+   !!   Default option                                                    Empty module
+   !!---------------------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE bdy_ice( kt )      ! Empty routine
+      WRITE(*,*) 'bdy_ice: You should not have seen this print! error?', kt
+   END SUBROUTINE bdy_ice
+#endif
+
+   !!=================================================================================
+END MODULE bdyice
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90	(revision 9018)
+++ 	(revision )
@@ -1,402 +1,0 @@
-MODULE bdyice_lim
-   !!======================================================================
-   !!                       ***  MODULE  bdyice_lim  ***
-   !! Unstructured Open Boundary Cond. :  Open boundary conditions for sea-ice (LIM2 and LIM3)
-   !!======================================================================
-   !!  History :  3.3  !  2010-09 (D. Storkey)  Original code
-   !!             3.4  !  2011    (D. Storkey)  rewrite in preparation for OBC-BDY merge
-   !!              -   !  2012-01 (C. Rousset)  add lim3 and remove useless jk loop 
-   !!----------------------------------------------------------------------
-#if defined key_lim2 || defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim2'                                                 LIM-2 sea ice model
-   !!   'key_lim3'                                                 LIM-3 sea ice model
-   !!----------------------------------------------------------------------
-   !!   bdy_ice_lim        : Application of open boundaries to ice
-   !!   bdy_ice_frs        : Application of Flow Relaxation Scheme
-   !!----------------------------------------------------------------------
-   USE timing          ! Timing
-   USE phycst          ! physical constant
-   USE eosbn2          ! equation of state
-   USE oce             ! ocean dynamics and tracers variables
-#if defined key_lim2
-   USE par_ice_2
-   USE ice_2           ! LIM_2 ice variables
-   USE dom_ice_2       ! sea-ice domain
-#elif defined key_lim3
-   USE ice             ! LIM_3 ice variables
-   USE limvar
-   USE limctl
-#endif 
-   USE par_oce         ! ocean parameters
-   USE dom_oce         ! ocean space and time domain variables 
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE bdy_oce         ! ocean open boundary conditions
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE in_out_manager  ! write to numout file
-   USE lib_mpp         ! distributed memory computing
-   USE lib_fortran     ! to use key_nosignedzero
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   bdy_ice_lim     ! routine called in sbcmod
-   PUBLIC   bdy_ice_lim_dyn ! routine called in limrhg
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE bdy_ice_lim( kt )
-      !!----------------------------------------------------------------------
-      !!                  ***  SUBROUTINE bdy_ice_lim  ***
-      !!
-      !! ** Purpose : - Apply open boundary conditions for ice (LIM2 and LIM3)
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt   ! Main time step counter
-      !
-      INTEGER ::   ib_bdy   ! Loop index
-      !!----------------------------------------------------------------------
-      !
-#if defined key_lim3
-      CALL lim_var_glo2eqv
-#endif
-      !
-      DO ib_bdy=1, nb_bdy
-         !
-         SELECT CASE( cn_ice_lim(ib_bdy) )
-         CASE('none')
-            CYCLE
-         CASE('frs')
-            CALL bdy_ice_frs( idx_bdy(ib_bdy), dta_bdy(ib_bdy), kt, ib_bdy )
-         CASE DEFAULT
-            CALL ctl_stop( 'bdy_ice_lim : unrecognised option for open boundaries for ice fields' )
-         END SELECT
-         !
-      END DO
-      !
-#if defined key_lim3
-                        CALL lim_var_zapsmall
-                        CALL lim_var_agg(1)
-      IF( ln_limctl )   CALL lim_prt( kt, iiceprt, jiceprt, 1, ' - ice thermo bdy - ' )
-#endif
-      !
-   END SUBROUTINE bdy_ice_lim
-
-
-   SUBROUTINE bdy_ice_frs( idx, dta, kt, ib_bdy )
-      !!------------------------------------------------------------------------------
-      !!                 ***  SUBROUTINE bdy_ice_frs  ***
-      !!                    
-      !! ** Purpose : Apply the Flow Relaxation Scheme for sea-ice fields in the case 
-      !!              of unstructured open boundaries.
-      !! 
-      !! Reference : Engedahl H., 1995: Use of the flow relaxation scheme in a three-
-      !!             dimensional baroclinic ocean model with realistic topography. Tellus, 365-382.
-      !!------------------------------------------------------------------------------
-      TYPE(OBC_INDEX), INTENT(in) ::   idx     ! OBC indices
-      TYPE(OBC_DATA),  INTENT(in) ::   dta     ! OBC external data
-      INTEGER,         INTENT(in) ::   kt      ! main time-step counter
-      INTEGER,         INTENT(in) ::   ib_bdy  ! BDY set index
-      !
-      INTEGER  ::   jpbound            ! 0 = incoming ice
-      !                                ! 1 = outgoing ice
-      INTEGER  ::   jb, jk, jgrd, jl   ! dummy loop indices
-      INTEGER  ::   ji, jj, ii, ij     ! local scalar
-      REAL(wp) ::   zwgt, zwgt1        ! local scalar
-      REAL(wp) ::   ztmelts, zdh
-#if  defined key_lim2 && ! defined key_lim2_vp && defined key_agrif
-     USE ice_2, vt_s => hsnm
-     USE ice_2, vt_i => hicm
-#endif
-      !!------------------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )   CALL timing_start('bdy_ice_frs')
-      !
-      jgrd = 1      ! Everything is at T-points here
-      !
-#if defined key_lim2
-      DO jb = 1, idx%nblenrim(jgrd)
-         ji    = idx%nbi(jb,jgrd)
-         jj    = idx%nbj(jb,jgrd)
-         zwgt  = idx%nbw(jb,jgrd)
-         zwgt1 = 1.e0 - idx%nbw(jb,jgrd)
-         frld (ji,jj) = ( frld (ji,jj) * zwgt1 + dta%frld (jb) * zwgt ) * tmask(ji,jj,1)     ! Leads fraction 
-         hicif(ji,jj) = ( hicif(ji,jj) * zwgt1 + dta%hicif(jb) * zwgt ) * tmask(ji,jj,1)     ! Ice depth 
-         hsnif(ji,jj) = ( hsnif(ji,jj) * zwgt1 + dta%hsnif(jb) * zwgt ) * tmask(ji,jj,1)     ! Snow depth
-      END DO 
-
-      CALL lbc_bdy_lnk( frld,  'T', 1., ib_bdy )                                         ! lateral boundary conditions
-      CALL lbc_bdy_lnk( hicif, 'T', 1., ib_bdy )
-      CALL lbc_bdy_lnk( hsnif, 'T', 1., ib_bdy )
-
-      vt_i(:,:) = hicif(:,:) * frld(:,:)
-      vt_s(:,:) = hsnif(:,:) * frld(:,:)
-      !
-#elif defined key_lim3
-
-      DO jl = 1, jpl
-         DO jb = 1, idx%nblenrim(jgrd)
-            ji    = idx%nbi(jb,jgrd)
-            jj    = idx%nbj(jb,jgrd)
-            zwgt  = idx%nbw(jb,jgrd)
-            zwgt1 = 1.e0 - idx%nbw(jb,jgrd)
-            a_i (ji,jj,jl) = ( a_i (ji,jj,jl) * zwgt1 + dta%a_i (jb,jl) * zwgt ) * tmask(ji,jj,1)  ! Leads fraction 
-            ht_i(ji,jj,jl) = ( ht_i(ji,jj,jl) * zwgt1 + dta%ht_i(jb,jl) * zwgt ) * tmask(ji,jj,1)  ! Ice depth 
-            ht_s(ji,jj,jl) = ( ht_s(ji,jj,jl) * zwgt1 + dta%ht_s(jb,jl) * zwgt ) * tmask(ji,jj,1)  ! Snow depth
-
-            ! -----------------
-            ! Pathological case
-            ! -----------------
-            ! In case a) snow load would be in excess or b) ice is coming into a warmer environment that would lead to 
-            ! very large transformation from snow to ice (see limthd_dh.F90)
-
-            ! Then, a) transfer the snow excess into the ice (different from limthd_dh)
-            zdh = MAX( 0._wp, ( rhosn * ht_s(ji,jj,jl) + ( rhoic - rau0 ) * ht_i(ji,jj,jl) ) * r1_rau0 )
-            ! Or, b) transfer all the snow into ice (if incoming ice is likely to melt as it comes into a warmer environment)
-            !zdh = MAX( 0._wp, ht_s(ji,jj,jl) * rhosn / rhoic )
-
-            ! recompute ht_i, ht_s
-            ht_i(ji,jj,jl) = MIN( hi_max(jl), ht_i(ji,jj,jl) + zdh )
-            ht_s(ji,jj,jl) = MAX( 0._wp, ht_s(ji,jj,jl) - zdh * rhoic / rhosn ) 
-
-         ENDDO
-         CALL lbc_bdy_lnk(  a_i(:,:,jl), 'T', 1., ib_bdy )
-         CALL lbc_bdy_lnk( ht_i(:,:,jl), 'T', 1., ib_bdy )
-         CALL lbc_bdy_lnk( ht_s(:,:,jl), 'T', 1., ib_bdy )
-      ENDDO
-      ! retrieve at_i
-      at_i(:,:) = 0._wp
-      DO jl = 1, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-      DO jl = 1, jpl
-         DO jb = 1, idx%nblenrim(jgrd)
-            ji    = idx%nbi(jb,jgrd)
-            jj    = idx%nbj(jb,jgrd)
-
-            ! condition on ice thickness depends on the ice velocity
-            ! if velocity is outward (strictly), then ice thickness, volume... must be equal to adjacent values
-            jpbound = 0   ;   ii = ji   ;   ij = jj
-            !
-            IF( u_ice(ji+1,jj  ) < 0. .AND. umask(ji-1,jj  ,1) == 0. ) jpbound = 1; ii = ji+1; ij = jj
-            IF( u_ice(ji-1,jj  ) > 0. .AND. umask(ji+1,jj  ,1) == 0. ) jpbound = 1; ii = ji-1; ij = jj
-            IF( v_ice(ji  ,jj+1) < 0. .AND. vmask(ji  ,jj-1,1) == 0. ) jpbound = 1; ii = ji  ; ij = jj+1
-            IF( v_ice(ji  ,jj-1) > 0. .AND. vmask(ji  ,jj+1,1) == 0. ) jpbound = 1; ii = ji  ; ij = jj-1
-            !
-            IF( nn_ice_lim_dta(ib_bdy) == 0 ) jpbound = 0; ii = ji; ij = jj   ! case ice boundaries = initial conditions
-            !                                                                 !      do not make state variables dependent on velocity
-            !
-            rswitch = MAX( 0.0_wp , SIGN ( 1.0_wp , at_i(ii,ij) - 0.01 ) ) ! 0 if no ice
-            !
-            ! concentration and thickness
-            a_i (ji,jj,jl) = a_i (ii,ij,jl) * rswitch
-            ht_i(ji,jj,jl) = ht_i(ii,ij,jl) * rswitch
-            ht_s(ji,jj,jl) = ht_s(ii,ij,jl) * rswitch
-            !
-            ! Ice and snow volumes
-            v_i(ji,jj,jl) = ht_i(ji,jj,jl) * a_i(ji,jj,jl)
-            v_s(ji,jj,jl) = ht_s(ji,jj,jl) * a_i(ji,jj,jl)
-            !
-            SELECT CASE( jpbound )
-            !
-            CASE( 0 )   ! velocity is inward
-               !
-               ! Ice salinity, age, temperature
-               sm_i(ji,jj,jl)   = rswitch * rn_ice_sal(ib_bdy)  + ( 1.0 - rswitch ) * rn_simin
-               oa_i(ji,jj,jl)   = rswitch * rn_ice_age(ib_bdy) * a_i(ji,jj,jl)
-               t_su(ji,jj,jl)   = rswitch * rn_ice_tem(ib_bdy)  + ( 1.0 - rswitch ) * rn_ice_tem(ib_bdy)
-               DO jk = 1, nlay_s
-                  t_s(ji,jj,jk,jl) = rswitch * rn_ice_tem(ib_bdy) + ( 1.0 - rswitch ) * rt0
-               END DO
-               DO jk = 1, nlay_i
-                  t_i(ji,jj,jk,jl) = rswitch * rn_ice_tem(ib_bdy) + ( 1.0 - rswitch ) * rt0 
-                  s_i(ji,jj,jk,jl) = rswitch * rn_ice_sal(ib_bdy) + ( 1.0 - rswitch ) * rn_simin
-               END DO
-               !
-            CASE( 1 )   ! velocity is outward
-               !
-               ! Ice salinity, age, temperature
-               sm_i(ji,jj,jl)   = rswitch * sm_i(ii,ij,jl)  + ( 1.0 - rswitch ) * rn_simin
-               oa_i(ji,jj,jl)   = rswitch * oa_i(ii,ij,jl)
-               t_su(ji,jj,jl)   = rswitch * t_su(ii,ij,jl)  + ( 1.0 - rswitch ) * rt0
-               DO jk = 1, nlay_s
-                  t_s(ji,jj,jk,jl) = rswitch * t_s(ii,ij,jk,jl) + ( 1.0 - rswitch ) * rt0
-               END DO
-               DO jk = 1, nlay_i
-                  t_i(ji,jj,jk,jl) = rswitch * t_i(ii,ij,jk,jl) + ( 1.0 - rswitch ) * rt0
-                  s_i(ji,jj,jk,jl) = rswitch * s_i(ii,ij,jk,jl) + ( 1.0 - rswitch ) * rn_simin
-               END DO
-               !
-            END SELECT
-            !
-            IF( nn_icesal == 1 ) THEN     ! constant salinity : overwrite rn_icesal
-               sm_i(ji,jj  ,jl) = rn_icesal
-               s_i (ji,jj,:,jl) = rn_icesal
-            ENDIF
-            !
-            ! contents
-            smv_i(ji,jj,jl)  = MIN( sm_i(ji,jj,jl) , sss_m(ji,jj) ) * v_i(ji,jj,jl)
-            DO jk = 1, nlay_s
-               ! Snow energy of melting
-               e_s(ji,jj,jk,jl) = rswitch * rhosn * ( cpic * ( rt0 - t_s(ji,jj,jk,jl) ) + lfus )
-               ! Multiply by volume, so that heat content in J/m2
-               e_s(ji,jj,jk,jl) = e_s(ji,jj,jk,jl) * v_s(ji,jj,jl) * r1_nlay_s
-            END DO
-            DO jk = 1, nlay_i
-               ztmelts          = - tmut * s_i(ji,jj,jk,jl) + rt0 !Melting temperature in K                  
-               ! heat content per unit volume
-               e_i(ji,jj,jk,jl) = rswitch * rhoic * &
-                  (   cpic    * ( ztmelts - t_i(ji,jj,jk,jl) ) &
-                  +   lfus    * ( 1.0 - (ztmelts-rt0) / MIN((t_i(ji,jj,jk,jl)-rt0),-epsi20) ) &
-                  - rcp      * ( ztmelts - rt0 ) )
-               ! Mutliply by ice volume, and divide by number of layers to get heat content in J/m2
-               e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * a_i(ji,jj,jl) * ht_i(ji,jj,jl) * r1_nlay_i
-            END DO
-            !
-         END DO
-         !
-         CALL lbc_bdy_lnk(  a_i(:,:,jl), 'T', 1., ib_bdy )
-         CALL lbc_bdy_lnk( ht_i(:,:,jl), 'T', 1., ib_bdy )
-         CALL lbc_bdy_lnk( ht_s(:,:,jl), 'T', 1., ib_bdy )
-         CALL lbc_bdy_lnk(  v_i(:,:,jl), 'T', 1., ib_bdy )
-         CALL lbc_bdy_lnk(  v_s(:,:,jl), 'T', 1., ib_bdy )
-         !
-         CALL lbc_bdy_lnk( smv_i(:,:,jl), 'T', 1., ib_bdy )
-         CALL lbc_bdy_lnk(  sm_i(:,:,jl), 'T', 1., ib_bdy )
-         CALL lbc_bdy_lnk(  oa_i(:,:,jl), 'T', 1., ib_bdy )
-         CALL lbc_bdy_lnk(  t_su(:,:,jl), 'T', 1., ib_bdy )
-         DO jk = 1, nlay_s
-            CALL lbc_bdy_lnk(t_s(:,:,jk,jl), 'T', 1., ib_bdy )
-            CALL lbc_bdy_lnk(e_s(:,:,jk,jl), 'T', 1., ib_bdy )
-         END DO
-         DO jk = 1, nlay_i
-            CALL lbc_bdy_lnk(t_i(:,:,jk,jl), 'T', 1., ib_bdy )
-            CALL lbc_bdy_lnk(e_i(:,:,jk,jl), 'T', 1., ib_bdy )
-         END DO
-         !
-      END DO !jl
-      !
-#endif
-      !      
-      IF( nn_timing == 1 )   CALL timing_stop('bdy_ice_frs')
-      !
-   END SUBROUTINE bdy_ice_frs
-
-
-   SUBROUTINE bdy_ice_lim_dyn( cd_type )
-      !!------------------------------------------------------------------------------
-      !!                 ***  SUBROUTINE bdy_ice_lim_dyn  ***
-      !!                    
-      !! ** Purpose : Apply dynamics boundary conditions for sea-ice in the cas of unstructured open boundaries.
-      !!              u_ice and v_ice are equal to the value of the adjacent grid point if this latter is not ice free
-      !!              if adjacent grid point is ice free, then u_ice and v_ice are equal to ocean velocities
-      !!
-      !! 2013-06 : C. Rousset
-      !!------------------------------------------------------------------------------
-      CHARACTER(len=1), INTENT(in)  ::   cd_type   ! nature of velocity grid-points
-      !
-      INTEGER  ::   jb, jgrd           ! dummy loop indices
-      INTEGER  ::   ji, jj             ! local scalar
-      INTEGER  ::   ib_bdy             ! Loop index
-      REAL(wp) ::   zmsk1, zmsk2, zflag
-      !!------------------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 ) CALL timing_start('bdy_ice_lim_dyn')
-      !
-      DO ib_bdy=1, nb_bdy
-         !
-         SELECT CASE( cn_ice_lim(ib_bdy) )
-         !
-         CASE('none')
-            CYCLE
-            !
-         CASE('frs')
-            !
-            IF( nn_ice_lim_dta(ib_bdy) == 0 ) CYCLE            ! case ice boundaries = initial conditions 
-            !                                                  !      do not change ice velocity (it is only computed by rheology)
-            SELECT CASE ( cd_type )
-            !     
-            CASE ( 'U' )  
-               jgrd = 2      ! u velocity
-               DO jb = 1, idx_bdy(ib_bdy)%nblenrim(jgrd)
-                  ji    = idx_bdy(ib_bdy)%nbi(jb,jgrd)
-                  jj    = idx_bdy(ib_bdy)%nbj(jb,jgrd)
-                  zflag = idx_bdy(ib_bdy)%flagu(jb,jgrd)
-                  !
-                  IF ( ABS( zflag ) == 1. ) THEN  ! eastern and western boundaries
-                     ! one of the two zmsk is always 0 (because of zflag)
-                     zmsk1 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji+1,jj) ) ) ! 0 if no ice
-                     zmsk2 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji-1,jj) ) ) ! 0 if no ice
-                     !  
-                     ! u_ice = u_ice of the adjacent grid point except if this grid point is ice-free (then u_ice = u_oce)
-                     u_ice (ji,jj) = u_ice(ji+1,jj) * 0.5_wp * ABS( zflag + 1._wp ) * zmsk1 + &
-                        &            u_ice(ji-1,jj) * 0.5_wp * ABS( zflag - 1._wp ) * zmsk2 + &
-                        &            u_oce(ji  ,jj) * ( 1._wp - MIN( 1._wp, zmsk1 + zmsk2 ) )
-                  ELSE                             ! everywhere else
-                     !u_ice(ji,jj) = u_oce(ji,jj)
-                     u_ice(ji,jj) = 0._wp
-                  ENDIF
-                  ! mask ice velocities
-                  rswitch = MAX( 0.0_wp , SIGN ( 1.0_wp , at_i(ji,jj) - 0.01_wp ) ) ! 0 if no ice
-                  u_ice(ji,jj) = rswitch * u_ice(ji,jj)
-                  !
-               END DO
-               CALL lbc_bdy_lnk( u_ice(:,:), 'U', -1., ib_bdy )
-               !
-            CASE ( 'V' )
-               jgrd = 3      ! v velocity
-               DO jb = 1, idx_bdy(ib_bdy)%nblenrim(jgrd)
-                  ji    = idx_bdy(ib_bdy)%nbi(jb,jgrd)
-                  jj    = idx_bdy(ib_bdy)%nbj(jb,jgrd)
-                  zflag = idx_bdy(ib_bdy)%flagv(jb,jgrd)
-                  !
-                  IF ( ABS( zflag ) == 1. ) THEN  ! northern and southern boundaries
-                     ! one of the two zmsk is always 0 (because of zflag)
-                     zmsk1 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji,jj+1) ) ) ! 0 if no ice
-                     zmsk2 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji,jj-1) ) ) ! 0 if no ice
-                     !  
-                     ! u_ice = u_ice of the adjacent grid point except if this grid point is ice-free (then u_ice = u_oce)
-                     v_ice (ji,jj) = v_ice(ji,jj+1) * 0.5_wp * ABS( zflag + 1._wp ) * zmsk1 + &
-                        &            v_ice(ji,jj-1) * 0.5_wp * ABS( zflag - 1._wp ) * zmsk2 + &
-                        &            v_oce(ji,jj  ) * ( 1._wp - MIN( 1._wp, zmsk1 + zmsk2 ) )
-                  ELSE                             ! everywhere else
-                     !v_ice(ji,jj) = v_oce(ji,jj)
-                     v_ice(ji,jj) = 0._wp
-                  ENDIF
-                  ! mask ice velocities
-                  rswitch = MAX( 0.0_wp , SIGN ( 1.0_wp , at_i(ji,jj) - 0.01 ) ) ! 0 if no ice
-                  v_ice(ji,jj) = rswitch * v_ice(ji,jj)
-                  !
-               END DO
-               CALL lbc_bdy_lnk( v_ice(:,:), 'V', -1., ib_bdy )
-               !
-            END SELECT
-            !
-         CASE DEFAULT
-            CALL ctl_stop( 'bdy_ice_lim_dyn : unrecognised option for open boundaries for ice fields' )
-         END SELECT
-         !
-      END DO
-      !
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_ice_lim_dyn')
-      !
-    END SUBROUTINE bdy_ice_lim_dyn
-
-#else
-   !!---------------------------------------------------------------------------------
-   !!   Default option                                                    Empty module
-   !!---------------------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE bdy_ice_lim( kt )      ! Empty routine
-      WRITE(*,*) 'bdy_ice_lim: You should not have seen this print! error?', kt
-   END SUBROUTINE bdy_ice_lim
-#endif
-
-   !!=================================================================================
-END MODULE bdyice_lim
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 9019)
@@ -29,5 +29,4 @@
    USE lib_mpp        ! for mpp_sum  
    USE iom            ! I/O
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
 
@@ -117,5 +116,6 @@
       !
    END SUBROUTINE bdy_init
-   
+
+
    SUBROUTINE bdy_segs
       !!----------------------------------------------------------------------
@@ -129,7 +129,4 @@
       !! ** Input   :  bdy_init.nc, input file for unstructured open boundaries
       !!----------------------------------------------------------------------      
-
-      ! local variables
-      !-------------------
       INTEGER  ::   ib_bdy, ii, ij, ik, igrd, ib, ir, iseg ! dummy loop indices
       INTEGER  ::   icount, icountr, ibr_max, ilen1, ibm1  ! local integers
@@ -151,5 +148,5 @@
       INTEGER :: com_east_b, com_west_b, com_south_b, com_north_b  ! Flags for boundaries receiving
       INTEGER :: iw_b(4), ie_b(4), is_b(4), in_b(4)                ! Arrays for neighbours coordinates
-      REAL(wp), POINTER, DIMENSION(:,:)       ::   zfmask  ! temporary fmask array excluding coastal boundary condition (shlat)
+      REAL(wp), TARGET, DIMENSION(jpi,jpj) ::   zfmask  ! temporary fmask array excluding coastal boundary condition (shlat)
       !!
       CHARACTER(LEN=1)                     ::   ctypebdy   !     -        - 
@@ -351,42 +348,19 @@
         IF(lwp) WRITE(numout,*)
 
-#if defined key_lim2
-        IF(lwp) WRITE(numout,*) 'Boundary conditions for sea ice:  '
-        SELECT CASE( cn_ice_lim(ib_bdy) )                  
-          CASE('none')
+#if defined key_lim3
+         IF(lwp) WRITE(numout,*) 'Boundary conditions for sea ice:  '
+         SELECT CASE( cn_ice_lim(ib_bdy) )                  
+         CASE('none')
              IF(lwp) WRITE(numout,*) '      no open boundary condition'        
-             dta_bdy(ib_bdy)%ll_frld  = .false.
-             dta_bdy(ib_bdy)%ll_hicif = .false.
-             dta_bdy(ib_bdy)%ll_hsnif = .false.
-          CASE('frs')
+             dta_bdy(ib_bdy)%ll_a_i = .false.
+             dta_bdy(ib_bdy)%ll_h_i = .false.
+             dta_bdy(ib_bdy)%ll_h_s = .false.
+         CASE('frs')
              IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
-             dta_bdy(ib_bdy)%ll_frld  = .true.
-             dta_bdy(ib_bdy)%ll_hicif = .true.
-             dta_bdy(ib_bdy)%ll_hsnif = .true.
-          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_ice_lim' )
-        END SELECT
-        IF( cn_ice_lim(ib_bdy) /= 'none' ) THEN 
-           SELECT CASE( nn_ice_lim_dta(ib_bdy) )                   ! 
-              CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for bdy data'        
-              CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      boundary data taken from file'
-              CASE DEFAULT   ;   CALL ctl_stop( 'nn_ice_lim_dta must be 0 or 1' )
-           END SELECT
-        ENDIF
-        IF(lwp) WRITE(numout,*)
-#elif defined key_lim3
-        IF(lwp) WRITE(numout,*) 'Boundary conditions for sea ice:  '
-        SELECT CASE( cn_ice_lim(ib_bdy) )                  
-          CASE('none')
-             IF(lwp) WRITE(numout,*) '      no open boundary condition'        
-             dta_bdy(ib_bdy)%ll_a_i  = .false.
-             dta_bdy(ib_bdy)%ll_ht_i = .false.
-             dta_bdy(ib_bdy)%ll_ht_s = .false.
-          CASE('frs')
-             IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
-             dta_bdy(ib_bdy)%ll_a_i  = .true.
-             dta_bdy(ib_bdy)%ll_ht_i = .true.
-             dta_bdy(ib_bdy)%ll_ht_s = .true.
-          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_ice_lim' )
-        END SELECT
+             dta_bdy(ib_bdy)%ll_a_i = .true.
+             dta_bdy(ib_bdy)%ll_h_i = .true.
+             dta_bdy(ib_bdy)%ll_h_s = .true.
+         CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for cn_ice_lim' )
+         END SELECT
         IF( cn_ice_lim(ib_bdy) /= 'none' ) THEN 
            SELECT CASE( nn_ice_lim_dta(ib_bdy) )                   ! 
@@ -404,8 +378,8 @@
         IF(lwp) WRITE(numout,*) '      Width of relaxation zone = ', nn_rimwidth(ib_bdy)
         IF(lwp) WRITE(numout,*)
-
-      ENDDO
-
-     IF (nb_bdy .gt. 0) THEN
+         !
+      END DO
+
+     IF( nb_bdy > 0 ) THEN
         IF( ln_vol ) THEN                     ! check volume conservation (nn_volctl value)
           IF(lwp) WRITE(numout,*) 'Volume correction applied at open boundaries'
@@ -528,6 +502,4 @@
             DO igrd = 1, jpbgrd
                id_dummy = iom_varid( inum, 'nbi'//cgrid(igrd), kdimsz=kdimsz )  
-               !clem nblendta(igrd,ib_bdy) = kdimsz(1)
-               !clem jpbdtau = MAX(jpbdtau, kdimsz(1))
                nblendta(igrd,ib_bdy) = MAXVAL(kdimsz)
                jpbdtau = MAX(jpbdtau, MAXVAL(kdimsz))
@@ -919,21 +891,21 @@
                   IF( nbrdta(ib,igrd,ib_bdy) == 1 )   icountr = icountr+1
                ENDIF
-            ENDDO
+            END DO
             idx_bdy(ib_bdy)%nblenrim(igrd) = icountr !: length of rim boundary data on each proc
             idx_bdy(ib_bdy)%nblen   (igrd) = icount  !: length of boundary data on each proc        
-         ENDDO  ! igrd
+         END DO  ! igrd
 
          ! Allocate index arrays for this boundary set
          !--------------------------------------------
          ilen1 = MAXVAL( idx_bdy(ib_bdy)%nblen(:) )
-         ALLOCATE( idx_bdy(ib_bdy)%nbi   (ilen1,jpbgrd) )
-         ALLOCATE( idx_bdy(ib_bdy)%nbj   (ilen1,jpbgrd) )
-         ALLOCATE( idx_bdy(ib_bdy)%nbr   (ilen1,jpbgrd) )
-         ALLOCATE( idx_bdy(ib_bdy)%nbd   (ilen1,jpbgrd) )
-         ALLOCATE( idx_bdy(ib_bdy)%nbdout(ilen1,jpbgrd) )
-         ALLOCATE( idx_bdy(ib_bdy)%nbmap (ilen1,jpbgrd) )
-         ALLOCATE( idx_bdy(ib_bdy)%nbw   (ilen1,jpbgrd) )
-         ALLOCATE( idx_bdy(ib_bdy)%flagu (ilen1,jpbgrd) )
-         ALLOCATE( idx_bdy(ib_bdy)%flagv (ilen1,jpbgrd) )
+         ALLOCATE( idx_bdy(ib_bdy)%nbi   (ilen1,jpbgrd) ,   &
+            &      idx_bdy(ib_bdy)%nbj   (ilen1,jpbgrd) ,   &
+            &      idx_bdy(ib_bdy)%nbr   (ilen1,jpbgrd) ,   &
+            &      idx_bdy(ib_bdy)%nbd   (ilen1,jpbgrd) ,   &
+            &      idx_bdy(ib_bdy)%nbdout(ilen1,jpbgrd) ,   &
+            &      idx_bdy(ib_bdy)%nbmap (ilen1,jpbgrd) ,   &
+            &      idx_bdy(ib_bdy)%nbw   (ilen1,jpbgrd) ,   &
+            &      idx_bdy(ib_bdy)%flagu (ilen1,jpbgrd) ,   &
+            &      idx_bdy(ib_bdy)%flagv (ilen1,jpbgrd) )
 
          ! Dispatch mapping indices and discrete distances on each processor
@@ -1148,5 +1120,5 @@
          END DO 
 
-      ENDDO
+      END DO
 
       ! ------------------------------------------------------
@@ -1212,10 +1184,9 @@
         DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
           bdyvmask(idx_bdy(ib_bdy)%nbi(ib,igrd), idx_bdy(ib_bdy)%nbj(ib,igrd)) = 0._wp
-        ENDDO
-      ENDDO
+        END DO
+      END DO
 
       ! For the flagu/flagv calculation below we require a version of fmask without
       ! the land boundary condition (shlat) included:
-      CALL wrk_alloc(jpi,jpj,  zfmask ) 
       DO ij = 2, jpjm1
          DO ii = 2, jpim1
@@ -1241,5 +1212,5 @@
          ! flagu =  1 : u is normal to the boundary and is direction is inward
   
-         DO igrd = 1,jpbgrd 
+         DO igrd = 1, jpbgrd 
             SELECT CASE( igrd )
                CASE( 1 )   ;   pmask => umask   (:,:,1)   ;   i_offset = 0
@@ -1346,9 +1317,8 @@
       IF( nb_bdy>0 )   DEALLOCATE( nbidta, nbjdta, nbrdta )
       !
-      CALL wrk_dealloc(jpi,jpj,   zfmask ) 
-      !
       IF( nn_timing == 1 )   CALL timing_stop('bdy_segs')
       !
    END SUBROUTINE bdy_segs
+
 
    SUBROUTINE bdy_ctl_seg
@@ -1727,4 +1697,5 @@
    END SUBROUTINE bdy_ctl_seg
 
+
    SUBROUTINE bdy_ctl_corn( ib1, ib2 )
       !!----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/C1D/dyncor_c1d.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/C1D/dyncor_c1d.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/C1D/dyncor_c1d.F90	(revision 9019)
@@ -21,4 +21,7 @@
    USE prtctl         ! Print control
 
+   USE sbcwave        ! Surface Waves (add Stokes-Coriolis force)
+   USE sbc_oce , ONLY : ln_stcor    ! use Stoke-Coriolis force
+   
    IMPLICIT NONE
    PRIVATE
@@ -71,12 +74,24 @@
       ENDIF
       !
-      DO jk = 1, jpkm1
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               ua(ji,jj,jk) = ua(ji,jj,jk) + ff_t(ji,jj) * vn(ji,jj,jk)
-               va(ji,jj,jk) = va(ji,jj,jk) - ff_t(ji,jj) * un(ji,jj,jk)
+      IF( ln_stcor ) THEN
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ua(ji,jj,jk) = ua(ji,jj,jk) + ff_t(ji,jj) * (vn(ji,jj,jk) + vsd(ji,jj,jk))
+                  va(ji,jj,jk) = va(ji,jj,jk) - ff_t(ji,jj) * (un(ji,jj,jk) + usd(ji,jj,jk))
+               END DO
             END DO
          END DO
-      END DO   
+      ELSE
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ua(ji,jj,jk) = ua(ji,jj,jk) + ff_t(ji,jj) * vn(ji,jj,jk)
+                  va(ji,jj,jk) = va(ji,jj,jk) - ff_t(ji,jj) * un(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      END IF
+      
       !
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' cor  - Ua: ', mask1=umask,  &
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/C1D/step_c1d.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/C1D/step_c1d.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/C1D/step_c1d.F90	(revision 9019)
@@ -27,6 +27,4 @@
    PUBLIC stp_c1d      ! called by opa.F90
 
-   !! * Substitutions
-#  include "zdfddm_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/C1D 3.7 , NEMO Consortium (2015)
@@ -76,29 +74,12 @@
                          CALL bn2( tsb, rab_b, rn2b ) ! before Brunt-Vaisala frequency
                          CALL bn2( tsn, rab_n, rn2  ) ! now    Brunt-Vaisala frequency
-      !  VERTICAL PHYSICS   
-                         CALL zdf_bfr( kstp )         ! bottom friction
-      !                                               ! Vertical eddy viscosity and diffusivity coefficients
-      IF( lk_zdfric  )   CALL zdf_ric( kstp )            ! Richardson number dependent Kz
-      IF( lk_zdftke  )   CALL zdf_tke( kstp )            ! TKE closure scheme for Kz
-      IF( lk_zdfgls  )   CALL zdf_gls( kstp )            ! GLS closure scheme for Kz
-      IF( lk_zdfcst  )   THEN                            ! Constant Kz (reset avt, avm[uv] to the background value)
-         avt (:,:,:) = rn_avt0 * tmask(:,:,:)
-         avmu(:,:,:) = rn_avm0 * umask(:,:,:)
-         avmv(:,:,:) = rn_avm0 * vmask(:,:,:)
-      ENDIF
+      
+      !  VERTICAL PHYSICS
+                         CALL zdf_phy( kstp )         ! vertical physics update (bfr, avt, avs, avm + MLD)
 
-      IF( ln_rnf_mouth ) THEN                         ! increase diffusivity at rivers mouths
-         DO jk = 2, nkrnf   ;   avt(:,:,jk) = avt(:,:,jk) + 2.e0 * rn_avt_rnf * rnfmsk(:,:)   ;   END DO
-      ENDIF
-      IF( ln_zdfevd  )   CALL zdf_evd( kstp )         ! enhanced vertical eddy diffusivity
-      IF( lk_zdftmx  )   CALL zdf_tmx( kstp )         ! tidal vertical mixing
-      IF( lk_zdfddm  )   CALL zdf_ddm( kstp )         ! double diffusive mixing
-                         CALL zdf_mxl( kstp )         ! mixed layer depth
+      IF(.NOT.ln_linssh )   CALL ssh_nxt       ( kstp )  ! after ssh (includes call to div_hor)
+      IF(.NOT.ln_linssh )   CALL dom_vvl_sf_nxt( kstp )  ! after vertical scale factors 
 
-                                                      ! write tke information in the restart file
-      IF( lrst_oce .AND. lk_zdftke )   CALL tke_rst( kstp, 'WRITE' )
-                                                      ! write gls information in the restart file
-      IF( lrst_oce .AND. lk_zdfgls )   CALL gls_rst( kstp, 'WRITE' )
-
+      IF(.NOT.ln_linssh )   CALL wzv           ( kstp )  ! now cross-level velocity 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ! diagnostics and outputs             (ua, va, ta, sa used as workspace)
@@ -123,4 +104,6 @@
       IF( ln_traqsr )   CALL tra_qsr( kstp )       ! penetrative solar radiation qsr
       IF( ln_tradmp )   CALL tra_dmp( kstp )       ! internal damping trends- tracers
+      IF(.NOT.ln_linssh)CALL tra_adv( kstp )       ! horizontal & vertical advection
+      IF( ln_zdfosm  )  CALL tra_osm( kstp )       ! OSMOSIS non-local tracer fluxes
                         CALL tra_zdf( kstp )       ! vertical mixing
                         CALL eos( tsn, rhd, rhop, gdept_0(:,:,:) )   ! now potential density for zdfmxl
@@ -138,6 +121,10 @@
       IF( ln_dyndmp )   CALL dyn_dmp    ( kstp )   ! internal damping trends- momentum
                         CALL dyn_cor_c1d( kstp )   ! vorticity term including Coriolis
+      IF( ln_zdfosm  )  CALL dyn_osm    ( kstp )   ! OSMOSIS non-local velocity fluxes
                         CALL dyn_zdf    ( kstp )   ! vertical diffusion
                         CALL dyn_nxt    ( kstp )   ! lateral velocity at next time step
+      IF(.NOT.ln_linssh)CALL ssh_swp    ( kstp )   ! swap of sea surface height
+
+      IF(.NOT.ln_linssh)CALL dom_vvl_sf_swp( kstp )! swap of vertical scale factors
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crs.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crs.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crs.F90	(revision 9019)
@@ -140,5 +140,5 @@
       ! Physical and dynamical ocean fields for output or passing to TOP, time-mean fields
       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE      :: tsn_crs
-      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE      :: un_crs, vn_crs, wn_crs, rke_crs
+      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE      :: un_crs, vn_crs, wn_crs
       REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE      :: hdivn_crs    
       REAL(wp), DIMENSION(:,:)    , ALLOCATABLE      :: sshn_crs    
@@ -151,8 +151,6 @@
 
       ! Vertical diffusion
-      REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:)  ::  avt_crs           !: vert. diffusivity coef. [m2/s] at w-point for temp  
-# if defined key_zdfddm
-      REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:)  ::  avs_crs           !: salinity vertical diffusivity coeff. [m2/s] at w-point
-# endif
+      REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:)  ::  avt_crs           !: temperature vertical diffusivity coeff. [m2/s] at w-point
+      REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:)  ::  avs_crs           !: salinity    vertical diffusivity coeff. [m2/s] at w-point
 
       ! Mixing and Mixed Layer Depth
@@ -230,7 +228,6 @@
 
 
-      ALLOCATE( un_crs(jpi_crs,jpj_crs,jpk) , vn_crs(jpi_crs,jpj_crs,jpk) , &
-         &      wn_crs(jpi_crs,jpj_crs,jpk) , hdivn_crs(jpi_crs,jpj_crs,jpk),&
-         &      rke_crs(jpi_crs,jpj_crs,jpk),                                STAT=ierr(11))
+      ALLOCATE( un_crs(jpi_crs,jpj_crs,jpk) , vn_crs   (jpi_crs,jpj_crs,jpk) ,     &
+         &      wn_crs(jpi_crs,jpj_crs,jpk) , hdivn_crs(jpi_crs,jpj_crs,jpk) , STAT=ierr(11))
 
      ALLOCATE( sshn_crs(jpi_crs,jpj_crs), emp_crs (jpi_crs,jpj_crs), emp_b_crs(jpi_crs,jpj_crs), &
@@ -239,21 +236,17 @@
          &     fr_i_crs(jpi_crs,jpj_crs), sfx_crs(jpi_crs ,jpj_crs),  STAT=ierr(12)  )
 
-     ALLOCATE( tsn_crs(jpi_crs,jpj_crs,jpk,jpts), avt_crs(jpi_crs,jpj_crs,jpk),    &
-# if defined key_zdfddm
-         &      avs_crs(jpi_crs,jpj_crs,jpk),    &
-# endif
-         &      STAT=ierr(13) )
+     ALLOCATE( tsn_crs(jpi_crs,jpj_crs,jpk,jpts), avt_crs(jpi_crs,jpj_crs,jpk),   &
+         &                                        avs_crs(jpi_crs,jpj_crs,jpk), STAT=ierr(13) )
 
       ALLOCATE( nmln_crs(jpi_crs,jpj_crs) , hmld_crs(jpi_crs,jpj_crs) , &
          &      hmlp_crs(jpi_crs,jpj_crs) , hmlpt_crs(jpi_crs,jpj_crs) , STAT=ierr(14) )
          
-      ALLOCATE( nimppt_crs(jpnij) , nlcit_crs(jpnij) , nldit_crs(jpnij) , nleit_crs(jpnij), &
-       &  nimppt_full(jpnij) , nlcit_full(jpnij) , nldit_full(jpnij) , nleit_full(jpnij),   &
-                njmppt_crs(jpnij) , nlcjt_crs(jpnij) , nldjt_crs(jpnij) , nlejt_crs(jpnij), &
-       &  njmppt_full(jpnij) , nlcjt_full(jpnij) , nldjt_full(jpnij) , nlejt_full(jpnij)  , STAT=ierr(15) )
-
-         
+      ALLOCATE( nimppt_crs (jpnij) , nlcit_crs (jpnij) , nldit_crs (jpnij) , nleit_crs (jpnij),   &
+         &      nimppt_full(jpnij) , nlcit_full(jpnij) , nldit_full(jpnij) , nleit_full(jpnij),   &
+                njmppt_crs (jpnij) , nlcjt_crs (jpnij) , nldjt_crs (jpnij) , nlejt_crs (jpnij),   &
+         &      njmppt_full(jpnij) , nlcjt_full(jpnij) , nldjt_full(jpnij) , nlejt_full(jpnij)  , STAT=ierr(15) )
+   
       crs_dom_alloc = MAXVAL(ierr)
-
+      !
    END FUNCTION crs_dom_alloc
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsdom.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsdom.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsdom.F90	(revision 9019)
@@ -1895,6 +1895,6 @@
       jpjglo_crsm1 = jpjglo_crs - 1  
 
-      jpi_crs = ( jpiglo_crs   - 2 * jpreci + (jpni-1) ) / jpni + 2 * jpreci
-      jpj_crs = ( jpjglo_crsm1 - 2 * jprecj + (jpnj-1) ) / jpnj + 2 * jprecj   
+      jpi_crs = ( jpiglo_crs   - 2 * nn_hls + (jpni-1) ) / jpni + 2 * nn_hls
+      jpj_crs = ( jpjglo_crsm1 - 2 * nn_hls + (jpnj-1) ) / jpnj + 2 * nn_hls   
               
       IF( noso < 0 ) jpj_crs = jpj_crs + 1    ! add a local band on southern processors  
@@ -1940,5 +1940,5 @@
               CASE ( -1 )
                 IF( MOD( jpjglo - njmppt(jn), nn_facty) > 0 )  nlejt_crs(jn) = nlejt_crs(jn) + 1
-                nlcjt_crs(jn) = nlejt_crs(jn) + jprecj
+                nlcjt_crs(jn) = nlejt_crs(jn) + nn_hls
                 nldjt_crs(jn) = nldjt(jn)
               
@@ -1947,10 +1947,10 @@
                 nldjt_crs(jn) = nldjt(jn)
                 IF( nldjt(jn) == 1 )  nlejt_crs(jn) = nlejt_crs(jn) + 1
-                nlejt_crs(jn) = nlejt_crs(jn) + jprecj
-                nlcjt_crs(jn) = nlejt_crs(jn) + jprecj
+                nlejt_crs(jn) = nlejt_crs(jn) + nn_hls
+                nlcjt_crs(jn) = nlejt_crs(jn) + nn_hls
                 
               CASE ( 1, 2 )
               
-                nlejt_crs(jn) = nlejt_crs(jn) + jprecj
+                nlejt_crs(jn) = nlejt_crs(jn) + nn_hls
                 nlcjt_crs(jn) = nlejt_crs(jn)
                 nldjt_crs(jn) = nldjt(jn)
@@ -1990,16 +1990,16 @@
            SELECT CASE( ibonit(jn) )
               CASE ( -1 )
-                 nleit_crs(jn) = nleit_crs(jn) + jpreci           
-                 nlcit_crs(jn) = nleit_crs(jn) + jpreci
+                 nleit_crs(jn) = nleit_crs(jn) + nn_hls           
+                 nlcit_crs(jn) = nleit_crs(jn) + nn_hls
                  nldit_crs(jn) = nldit(jn) 
               
               CASE ( 0 )
-                 nleit_crs(jn) = nleit_crs(jn) + jpreci
-                 nlcit_crs(jn) = nleit_crs(jn) + jpreci
+                 nleit_crs(jn) = nleit_crs(jn) + nn_hls
+                 nlcit_crs(jn) = nleit_crs(jn) + nn_hls
                  nldit_crs(jn) = nldit(jn) 
                 
               CASE ( 1, 2 )
                  IF( MOD( jpiglo - nimppt(jn), nn_factx) > 0 )  nleit_crs(jn) = nleit_crs(jn) + 1
-                 nleit_crs(jn) = nleit_crs(jn) + jpreci
+                 nleit_crs(jn) = nleit_crs(jn) + nn_hls
                  nlcit_crs(jn) = nleit_crs(jn)
                  nldit_crs(jn) = nldit(jn) 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsdomwri.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsdomwri.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsdomwri.F90	(revision 9019)
@@ -133,8 +133,8 @@
       
       tmask_i_crs(:,:) = tmask_crs(:,:,1)
-      iif = jpreci
-      iil = nlci_crs - jpreci + 1
-      ijf = jpreci
-      ijl = nlcj_crs - jprecj + 1
+      iif = nn_hls
+      iil = nlci_crs - nn_hls + 1
+      ijf = nn_hls
+      ijl = nlcj_crs - nn_hls + 1
      
       tmask_i_crs( 1:iif ,    :  ) = 0._wp
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsfld.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsfld.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsfld.F90	(revision 9019)
@@ -25,5 +25,4 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE timing          ! preformance summary
-   USE wrk_nemo        ! working array
 
    IMPLICIT NONE
@@ -58,18 +57,12 @@
       INTEGER  ::   ji, jj, jk        ! dummy loop indices
       REAL(wp) ::   z2dcrsu, z2dcrsv  ! local scalars
-      !
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ze3t, ze3u, ze3v, ze3w   ! 3D workspace for e3
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zt, zt_crs
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zs, zs_crs  
+      REAL(wp) ::   zztmp             !   -      -
+      !
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze3t, ze3u, ze3v, ze3w   ! 3D workspace for e3
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zt  , zs  , z3d
+      REAL(wp), DIMENSION(jpi_crs,jpj_crs,jpk) ::   zt_crs, zs_crs  
       !!----------------------------------------------------------------------
       ! 
       IF( nn_timing == 1 )   CALL timing_start('crs_fld')
-
-      !  Initialize arrays
-      CALL wrk_alloc( jpi,jpj,jpk,   ze3t, ze3w )
-      CALL wrk_alloc( jpi,jpj,jpk,   ze3u, ze3v )
-      CALL wrk_alloc( jpi,jpj,jpk,   zt  , zs   )
-      !
-      CALL wrk_alloc( jpi_crs,jpj_crs,jpk,   zt_crs, zs_crs )
 
       ! Depth work arrrays
@@ -84,7 +77,6 @@
          vn_crs   (:,:,:  ) = 0._wp    ! v-velocity
          wn_crs   (:,:,:  ) = 0._wp    ! w
-         avt_crs  (:,:,:  ) = 0._wp    ! avt
+         avs_crs  (:,:,:  ) = 0._wp    ! avt
          hdivn_crs(:,:,:  ) = 0._wp    ! hdiv
-         rke_crs  (:,:,:  ) = 0._wp    ! rke
          sshn_crs (:,:    ) = 0._wp    ! ssh
          utau_crs (:,:    ) = 0._wp    ! taux
@@ -158,9 +150,23 @@
       CALL iom_put( "voces" , zs_crs )   ! vS
 
-     
-      !  Kinetic energy
-      CALL crs_dom_ope( rke, 'VOL', 'T', tmask, rke_crs, p_e12=e1e2t, p_e3=ze3t, psgn=1.0 )
-      CALL iom_put( "eken", rke_crs )
-
+      IF( iom_use( "eken") ) THEN     !      kinetic energy
+         z3d(:,:,jk) = 0._wp 
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zztmp  = r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
+                  z3d(ji,jj,jk) = 0.25_wp * zztmp * (                                    &
+                     &            un(ji-1,jj,jk)**2 * e2u(ji-1,jj) * e3u_n(ji-1,jj,jk)   &
+                     &          + un(ji  ,jj,jk)**2 * e2u(ji  ,jj) * e3u_n(ji  ,jj,jk)   &
+                     &          + vn(ji,jj-1,jk)**2 * e1v(ji,jj-1) * e3v_n(ji,jj-1,jk)   &
+                     &          + vn(ji,jj  ,jk)**2 * e1v(ji,jj  ) * e3v_n(ji,jj  ,jk)   )
+               END DO
+            END DO
+         END DO
+         CALL lbc_lnk( z3d, 'T', 1. )
+         !
+         CALL crs_dom_ope( z3d, 'VOL', 'T', tmask, zt_crs, p_e12=e1e2t, p_e3=ze3t, psgn=1.0 )
+         CALL iom_put( "eken", zt_crs )
+      ENDIF
       !  Horizontal divergence ( following OPA_SRC/DYN/divhor.F90 ) 
       DO jk = 1, jpkm1
@@ -175,7 +181,7 @@
                    hdivn_crs(ji,jj,jk) = ( z2dcrsu + z2dcrsv ) / crs_volt_wgt(ji,jj,jk) 
                ENDIF
-            ENDDO
-         ENDDO
-      ENDDO
+            END DO
+         END DO
+      END DO
       CALL crs_lbc_lnk( hdivn_crs, 'T', 1.0 )
       !
@@ -196,16 +202,19 @@
       !  free memory
 
-      !  avt, avs
-!!gm BUG   TOP always uses avs !!!
+      !  avs
       SELECT CASE ( nn_crs_kz )
          CASE ( 0 )
             CALL crs_dom_ope( avt, 'VOL', 'W', tmask, avt_crs, p_e12=e1e2t, p_e3=ze3w, psgn=1.0 )
+            CALL crs_dom_ope( avs, 'VOL', 'W', tmask, avs_crs, p_e12=e1e2t, p_e3=ze3w, psgn=1.0 )
          CASE ( 1 )
             CALL crs_dom_ope( avt, 'MAX', 'W', tmask, avt_crs, p_e12=e1e2t, p_e3=ze3w, psgn=1.0 )
+            CALL crs_dom_ope( avs, 'MAX', 'W', tmask, avs_crs, p_e12=e1e2t, p_e3=ze3w, psgn=1.0 )
          CASE ( 2 )
             CALL crs_dom_ope( avt, 'MIN', 'W', tmask, avt_crs, p_e12=e1e2t, p_e3=ze3w, psgn=1.0 )
+            CALL crs_dom_ope( avs, 'MIN', 'W', tmask, avs_crs, p_e12=e1e2t, p_e3=ze3w, psgn=1.0 )
       END SELECT
       !
-      CALL iom_put( "avt", avt_crs )   !  Kz
+      CALL iom_put( "avt", avt_crs )   !  Kz on T
+      CALL iom_put( "avs", avs_crs )   !  Kz on S
       
       !  sbc fields  
@@ -231,9 +240,4 @@
       CALL iom_put( "ice_cover", fr_i_crs )   ! ice cover output 
 
-      !  free memory
-      CALL wrk_dealloc( jpi,jpj,jpk,   ze3t, ze3w )
-      CALL wrk_dealloc( jpi,jpj,jpk,   ze3u, ze3v )
-      CALL wrk_dealloc( jpi,jpj,jpk,   zt  , zs   )
-      CALL wrk_dealloc( jpi_crs,jpj_crs,jpk,   zt_crs, zs_crs )
       !
       CALL iom_swap( "nemo" )     ! return back on high-resolution grid
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsini.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsini.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crsini.F90	(revision 9019)
@@ -250,4 +250,6 @@
       CALL wrk_dealloc( jpi,jpj,jpk,   ze3t, ze3u, ze3v, ze3w )
       !
+      IF( nn_timing == 1 )  CALL timing_stop('crs_init')
+      !
    END SUBROUTINE crs_init
     
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crslbclnk.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crslbclnk.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/CRS/crslbclnk.F90	(revision 9019)
@@ -15,5 +15,5 @@
    
    INTERFACE crs_lbc_lnk
-      MODULE PROCEDURE crs_lbc_lnk_3d, crs_lbc_lnk_3d_gather, crs_lbc_lnk_2d
+      MODULE PROCEDURE crs_lbc_lnk_3d, crs_lbc_lnk_2d
    END INTERFACE
    
@@ -49,12 +49,12 @@
       ll_grid_crs = ( jpi == jpi_crs )
       !
-      IF( PRESENT(pval) ) THEN  ;  zval = pval
-      ELSE                      ;  zval = 0._wp
+      IF( PRESENT(pval) ) THEN   ;   zval = pval
+      ELSE                       ;   zval = 0._wp
       ENDIF
       !
       IF( .NOT.ll_grid_crs )   CALL dom_grid_crs   ! Save the parent grid information  & Switch to coarse grid domain
       !
-      IF( PRESENT( cd_mpp ) ) THEN ; CALL lbc_lnk( pt3d1, cd_type1, psgn, cd_mpp, pval=zval  )
-      ELSE                         ; CALL lbc_lnk( pt3d1, cd_type1, psgn, pval=zval  )
+      IF( PRESENT( cd_mpp ) ) THEN   ;   CALL lbc_lnk( pt3d1, cd_type1, psgn, cd_mpp, pval=zval  )
+      ELSE                           ;   CALL lbc_lnk( pt3d1, cd_type1, psgn        , pval=zval  )
       ENDIF
       !
@@ -62,33 +62,4 @@
       !
    END SUBROUTINE crs_lbc_lnk_3d
-   
-   
-   SUBROUTINE crs_lbc_lnk_3d_gather( pt3d1, cd_type1, pt3d2, cd_type2, psgn )
-      !!---------------------------------------------------------------------
-      !!                  ***  SUBROUTINE crs_lbc_lnk  ***
-      !!
-      !! ** Purpose :   set lateral boundary conditions for coarsened grid
-      !!
-      !! ** Method  :   Swap domain indices from full to coarse domain
-      !!                before arguments are passed directly to lbc_lnk.
-      !!                Upon exiting, switch back to full domain indices.
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)                        , INTENT(in   ) ::   cd_type1, cd_type2 ! grid type
-      REAL(wp)                                , INTENT(in   ) ::   psgn               ! control of the sign
-      REAL(wp), DIMENSION(jpi_crs,jpj_crs,jpk), INTENT(inout) ::   pt3d1   , pt3d2    ! 3D array on which the lbc is applied
-      !
-      LOGICAL ::   ll_grid_crs
-      !!----------------------------------------------------------------------
-      !
-      ll_grid_crs = ( jpi == jpi_crs )
-      !
-      IF( .NOT.ll_grid_crs )   CALL dom_grid_crs   ! Save the parent grid information  & Switch to coarse grid domain
-      !
-      CALL lbc_lnk( pt3d1, cd_type1, pt3d2, cd_type2, psgn  )
-      !
-      IF( .NOT.ll_grid_crs )   CALL dom_grid_glo   ! Return to parent grid domain
-      !
-   END SUBROUTINE crs_lbc_lnk_3d_gather
-
    
    
@@ -115,12 +86,12 @@
       ll_grid_crs = ( jpi == jpi_crs )
       !
-      IF( PRESENT(pval) ) THEN  ;  zval = pval
-      ELSE                      ;  zval = 0._wp
+      IF( PRESENT(pval) ) THEN   ;   zval = pval
+      ELSE                       ;   zval = 0._wp
       ENDIF
       !
       IF( .NOT.ll_grid_crs )   CALL dom_grid_crs   ! Save the parent grid information  & Switch to coarse grid domain
       !
-      IF( PRESENT( cd_mpp ) ) THEN ; CALL lbc_lnk( pt2d, cd_type, psgn, cd_mpp, pval=zval  )
-      ELSE                         ; CALL lbc_lnk( pt2d, cd_type, psgn, pval=zval  )
+      IF( PRESENT( cd_mpp ) ) THEN   ;   CALL lbc_lnk( pt2d, cd_type, psgn, cd_mpp, pval=zval  )
+      ELSE                           ;   CALL lbc_lnk( pt2d, cd_type, psgn        , pval=zval  )
       ENDIF
       !
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/dia25h.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/dia25h.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/dia25h.F90	(revision 9019)
@@ -8,37 +8,26 @@
    USE oce             ! ocean dynamics and tracers variables
    USE dom_oce         ! ocean space and time domain
+   USE zdf_oce         ! ocean vertical physics    
+   USE zdfgls   , ONLY : hmxl_n
+   !
    USE in_out_manager  ! I/O units
    USE iom             ! I/0 library
-   USE wrk_nemo        ! working arrays
-#if defined key_zdftke 
-   USE zdf_oce, ONLY: en
-#endif
-   USE zdf_oce, ONLY: avt, avm
-#if defined key_zdfgls
-   USE zdf_oce, ONLY: en
-   USE zdfgls, ONLY: mxln
-#endif
 
    IMPLICIT NONE
    PRIVATE
 
-   LOGICAL , PUBLIC ::   ln_dia25h     !:  25h mean output
    PUBLIC   dia_25h_init               ! routine called by nemogcm.F90
    PUBLIC   dia_25h                    ! routine called by diawri.F90
 
-  !! * variables for calculating 25-hourly means
-   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:) ::   tn_25h  , sn_25h
-   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:)   ::   sshn_25h 
-   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:) ::   un_25h  , vn_25h  , wn_25h
-   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:) ::   avt_25h , avm_25h
-#if defined key_zdfgls || key_zdftke
-   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:) ::   en_25h
-#endif
-#if defined key_zdfgls 
-   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:) ::   rmxln_25h
-#endif
-   INTEGER, SAVE :: cnt_25h     ! Counter for 25 hour means
-
-
+   LOGICAL, PUBLIC ::   ln_dia25h      !:  25h mean output
+
+   ! variables for calculating 25-hourly means
+   INTEGER , SAVE ::   cnt_25h           ! Counter for 25 hour means
+   REAL(wp), SAVE ::   r1_25 = 0.04_wp   ! =1/25 
+   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   tn_25h  , sn_25h
+   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:)   ::   sshn_25h 
+   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   un_25h  , vn_25h  , wn_25h
+   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   avt_25h , avm_25h
+   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   en_25h  , rmxln_25h
 
    !!----------------------------------------------------------------------
@@ -56,8 +45,5 @@
       !!        
       !! ** Method : Read namelist
-      !!   History
-      !!   3.6  !  08-14  (E. O'Dea) Routine to initialize dia_25h
       !!---------------------------------------------------------------------------
-      !!
       INTEGER ::   ios                 ! Local integer output status for namelist read
       INTEGER ::   ierror              ! Local integer for memory allocation
@@ -79,6 +65,6 @@
          WRITE(numout,*) 'dia_25h_init : Output 25 hour mean diagnostics'
          WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) 'Namelist nam_dia25h : set 25h outputs '
-         WRITE(numout,*) 'Switch for 25h diagnostics (T) or not (F)  ln_dia25h  = ', ln_dia25h
+         WRITE(numout,*) '   Namelist nam_dia25h : set 25h outputs '
+         WRITE(numout,*) '      Switch for 25h diagnostics (T) or not (F)  ln_dia25h  = ', ln_dia25h
       ENDIF
       IF( .NOT. ln_dia25h )   RETURN
@@ -86,47 +72,22 @@
       ! 1 - Allocate memory !
       ! ------------------- !
-      ALLOCATE( tn_25h(jpi,jpj,jpk), STAT=ierror )
+      !                                ! ocean arrays
+      ALLOCATE( tn_25h (jpi,jpj,jpk), sn_25h (jpi,jpj,jpk), sshn_25h(jpi,jpj)  ,     &
+         &      un_25h (jpi,jpj,jpk), vn_25h (jpi,jpj,jpk), wn_25h(jpi,jpj,jpk),     &
+         &      avt_25h(jpi,jpj,jpk), avm_25h(jpi,jpj,jpk),                      STAT=ierror )
       IF( ierror > 0 ) THEN
-         CALL ctl_stop( 'dia_25h: unable to allocate tn_25h' )   ;   RETURN
-      ENDIF
-      ALLOCATE( sn_25h(jpi,jpj,jpk), STAT=ierror )
-      IF( ierror > 0 ) THEN
-         CALL ctl_stop( 'dia_25h: unable to allocate sn_25h' )   ;   RETURN
-      ENDIF
-      ALLOCATE( un_25h(jpi,jpj,jpk), STAT=ierror )
-      IF( ierror > 0 ) THEN
-         CALL ctl_stop( 'dia_25h: unable to allocate un_25h' )   ;   RETURN
-      ENDIF
-      ALLOCATE( vn_25h(jpi,jpj,jpk), STAT=ierror )
-      IF( ierror > 0 ) THEN
-         CALL ctl_stop( 'dia_25h: unable to allocate vn_25h' )   ;   RETURN
-      ENDIF
-      ALLOCATE( wn_25h(jpi,jpj,jpk), STAT=ierror )
-      IF( ierror > 0 ) THEN
-         CALL ctl_stop( 'dia_25h: unable to allocate wn_25h' )   ;   RETURN
-      ENDIF
-      ALLOCATE( avt_25h(jpi,jpj,jpk), STAT=ierror )
-      IF( ierror > 0 ) THEN
-         CALL ctl_stop( 'dia_25h: unable to allocate avt_25h' )   ;   RETURN
-      ENDIF
-      ALLOCATE( avm_25h(jpi,jpj,jpk), STAT=ierror )
-      IF( ierror > 0 ) THEN
-         CALL ctl_stop( 'dia_25h: unable to allocate avm_25h' )   ;   RETURN
-      ENDIF
-# if defined key_zdfgls || defined key_zdftke
-      ALLOCATE( en_25h(jpi,jpj,jpk), STAT=ierror )
-      IF( ierror > 0 ) THEN
-         CALL ctl_stop( 'dia_25h: unable to allocate en_25h' )   ;   RETURN
-      ENDIF
-#endif
-# if defined key_zdfgls 
-      ALLOCATE( rmxln_25h(jpi,jpj,jpk), STAT=ierror )
-      IF( ierror > 0 ) THEN
-         CALL ctl_stop( 'dia_25h: unable to allocate rmxln_25h' )   ;   RETURN
-      ENDIF
-#endif
-      ALLOCATE( sshn_25h(jpi,jpj), STAT=ierror )
-      IF( ierror > 0 ) THEN
-         CALL ctl_stop( 'dia_25h: unable to allocate sshn_25h' )   ;   RETURN
+         CALL ctl_stop( 'dia_25h: unable to allocate ocean arrays' )   ;   RETURN
+      ENDIF
+      IF( ln_zdftke ) THEN             ! TKE physics
+         ALLOCATE( en_25h(jpi,jpj,jpk), STAT=ierror )
+         IF( ierror > 0 ) THEN
+            CALL ctl_stop( 'dia_25h: unable to allocate en_25h' )   ;   RETURN
+         ENDIF
+      ENDIF
+      IF( ln_zdfgls ) THEN             ! GLS physics
+         ALLOCATE( en_25h(jpi,jpj,jpk), rmxln_25h(jpi,jpj,jpk), STAT=ierror )
+         IF( ierror > 0 ) THEN
+            CALL ctl_stop( 'dia_25h: unable to allocate en_25h and rmxln_25h' )   ;   RETURN
+         ENDIF
       ENDIF
       ! ------------------------- !
@@ -134,27 +95,23 @@
       ! ------------------------- !
       cnt_25h = 1  ! sets the first value of sum at timestep 1 (note - should strictly be at timestep zero so before values used where possible) 
-      tn_25h(:,:,:) = tsb(:,:,:,jp_tem)
-      sn_25h(:,:,:) = tsb(:,:,:,jp_sal)
-      sshn_25h(:,:) = sshb(:,:)
-      un_25h(:,:,:) = ub(:,:,:)
-      vn_25h(:,:,:) = vb(:,:,:)
-      wn_25h(:,:,:) = wn(:,:,:)
-      avt_25h(:,:,:) = avt(:,:,:)
-      avm_25h(:,:,:) = avm(:,:,:)
-# if defined key_zdfgls || defined key_zdftke
+      tn_25h  (:,:,:) = tsb (:,:,:,jp_tem)
+      sn_25h  (:,:,:) = tsb (:,:,:,jp_sal)
+      sshn_25h(:,:)   = sshb(:,:)
+      un_25h  (:,:,:) = ub  (:,:,:)
+      vn_25h  (:,:,:) = vb  (:,:,:)
+      wn_25h  (:,:,:) = wn  (:,:,:)
+      avt_25h (:,:,:) = avt (:,:,:)
+      avm_25h (:,:,:) = avm (:,:,:)
+      IF( ln_zdftke ) THEN
          en_25h(:,:,:) = en(:,:,:)
-#endif
-# if defined key_zdfgls
-         rmxln_25h(:,:,:) = mxln(:,:,:)
-#endif
-#if defined key_lim3 || defined key_lim2
-         CALL ctl_stop('STOP', 'dia_25h not setup yet to do tidemean ice')
+      ENDIF
+      IF( ln_zdfgls ) THEN
+         en_25h   (:,:,:) = en    (:,:,:)
+         rmxln_25h(:,:,:) = hmxl_n(:,:,:)
+      ENDIF
+#if defined key_lim3
+      CALL ctl_stop('STOP', 'dia_25h not setup yet to do tidemean ice')
 #endif 
-
-      ! -------------------------- !
-      ! 3 - Return to dia_wri      !
-      ! -------------------------- !
-
-
+      !
    END SUBROUTINE dia_25h_init
 
@@ -164,36 +121,18 @@
       !!                 ***  ROUTINE dia_25h  ***
       !!         
-      !!
-      !!--------------------------------------------------------------------
-      !!                   
       !! ** Purpose :   Write diagnostics with M2/S2 tide removed
       !!
-      !! ** Method  :   
-      !!      25hr mean outputs for shelf seas
+      !! ** Method  :   25hr mean outputs for shelf seas
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       !!
-      !! History :
-      !!   ?.0  !  07-04  (A. Hines) New routine, developed from dia_wri_foam
-      !!   3.4  !  02-13  (J. Siddorn) Routine taken from old dia_wri_foam
-      !!   3.6  !  08-14  (E. O'Dea) adapted for VN3.6
-      !!----------------------------------------------------------------------
-      !! * Modules used
-
-      IMPLICIT NONE
-
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-
-
-      !! * Local declarations
       INTEGER ::   ji, jj, jk
-
+      INTEGER                          ::   iyear0, nimonth0,iday0            ! start year,imonth,day
       LOGICAL ::   ll_print = .FALSE.    ! =T print and flush numout
-      REAL(wp)                         ::   zsto, zout, zmax, zjulian, zmdi       ! temporary reals
-      INTEGER                          ::   i_steps                               ! no of timesteps per hour
-      REAL(wp), DIMENSION(jpi,jpj    ) ::   zw2d, un_dm, vn_dm                    ! temporary workspace
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zw3d                                  ! temporary workspace
-      REAL(wp), DIMENSION(jpi,jpj,3)   ::   zwtmb                                 ! temporary workspace
-      INTEGER                          ::   iyear0, nimonth0,iday0                ! start year,imonth,day
-
+      REAL(wp)                         ::   zsto, zout, zmax, zjulian, zmdi   ! local scalars
+      INTEGER                          ::   i_steps                           ! no of timesteps per hour
+      REAL(wp), DIMENSION(jpi,jpj    ) ::   zw2d, un_dm, vn_dm                ! workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zw3d                              ! workspace
+      REAL(wp), DIMENSION(jpi,jpj,3)   ::   zwtmb                             ! workspace
       !!----------------------------------------------------------------------
 
@@ -207,14 +146,9 @@
       ENDIF
 
-#if defined key_lim3 || defined key_lim2
-      CALL ctl_stop('STOP', 'dia_wri_tide not setup yet to do tidemean ice')
-#endif
-
       ! local variable for debugging
       ll_print = ll_print .AND. lwp
 
-      ! Sum of 25 hourly instantaneous values to give a 25h mean from 24hours
-      ! every day
-      IF( MOD( kt, i_steps ) == 0  .and. kt .ne. nn_it000 ) THEN
+      ! Sum of 25 hourly instantaneous values to give a 25h mean from 24hours every day
+      IF( MOD( kt, i_steps ) == 0  .AND. kt /= nn_it000 ) THEN
 
          IF (lwp) THEN
@@ -223,103 +157,104 @@
          ENDIF
 
-         tn_25h(:,:,:)        = tn_25h(:,:,:) + tsn(:,:,:,jp_tem)
-         sn_25h(:,:,:)        = sn_25h(:,:,:) + tsn(:,:,:,jp_sal)
-         sshn_25h(:,:)        = sshn_25h(:,:) + sshn (:,:)
-         un_25h(:,:,:)        = un_25h(:,:,:) + un(:,:,:)
-         vn_25h(:,:,:)        = vn_25h(:,:,:) + vn(:,:,:)
-         wn_25h(:,:,:)        = wn_25h(:,:,:) + wn(:,:,:)
-         avt_25h(:,:,:)       = avt_25h(:,:,:) + avt(:,:,:)
-         avm_25h(:,:,:)       = avm_25h(:,:,:) + avm(:,:,:)
-# if defined key_zdfgls || defined key_zdftke
-         en_25h(:,:,:)        = en_25h(:,:,:) + en(:,:,:)
-#endif
-# if defined key_zdfgls
-         rmxln_25h(:,:,:)      = rmxln_25h(:,:,:) + mxln(:,:,:)
-#endif
+         tn_25h  (:,:,:)     = tn_25h  (:,:,:) + tsn (:,:,:,jp_tem)
+         sn_25h  (:,:,:)     = sn_25h  (:,:,:) + tsn (:,:,:,jp_sal)
+         sshn_25h(:,:)       = sshn_25h(:,:)   + sshn(:,:)
+         un_25h  (:,:,:)     = un_25h  (:,:,:) + un  (:,:,:)
+         vn_25h  (:,:,:)     = vn_25h  (:,:,:) + vn  (:,:,:)
+         wn_25h  (:,:,:)     = wn_25h  (:,:,:) + wn  (:,:,:)
+         avt_25h (:,:,:)     = avt_25h (:,:,:) + avt (:,:,:)
+         avm_25h (:,:,:)     = avm_25h (:,:,:) + avm (:,:,:)
+         IF( ln_zdftke ) THEN
+            en_25h(:,:,:)    = en_25h  (:,:,:) + en(:,:,:)
+         ENDIF
+         IF( ln_zdfgls ) THEN
+            en_25h   (:,:,:) = en_25h   (:,:,:) + en    (:,:,:)
+            rmxln_25h(:,:,:) = rmxln_25h(:,:,:) + hmxl_n(:,:,:)
+         ENDIF
          cnt_25h = cnt_25h + 1
-
+         !
          IF (lwp) THEN
             WRITE(numout,*) 'dia_tide : Summed the following number of hourly values so far',cnt_25h
          ENDIF
-
+         !
       ENDIF ! MOD( kt, i_steps ) == 0
 
-         ! Write data for 25 hour mean output streams
-      IF( cnt_25h .EQ. 25 .AND.  MOD( kt, i_steps*24) == 0 .AND. kt .NE. nn_it000 ) THEN
-
-            IF(lwp) THEN
-               WRITE(numout,*) 'dia_wri_tide : Writing 25 hour mean tide diagnostics at timestep', kt
-               WRITE(numout,*) '~~~~~~~~~~~~ '
-            ENDIF
-
-            tn_25h(:,:,:)        = tn_25h(:,:,:) / 25.0_wp
-            sn_25h(:,:,:)        = sn_25h(:,:,:) / 25.0_wp
-            sshn_25h(:,:)        = sshn_25h(:,:) / 25.0_wp
-            un_25h(:,:,:)        = un_25h(:,:,:) / 25.0_wp
-            vn_25h(:,:,:)        = vn_25h(:,:,:) / 25.0_wp
-            wn_25h(:,:,:)        = wn_25h(:,:,:) / 25.0_wp
-            avt_25h(:,:,:)       = avt_25h(:,:,:) / 25.0_wp
-            avm_25h(:,:,:)       = avm_25h(:,:,:) / 25.0_wp
-# if defined key_zdfgls || defined key_zdftke
-            en_25h(:,:,:)        = en_25h(:,:,:) / 25.0_wp
-#endif
-# if defined key_zdfgls
-            rmxln_25h(:,:,:)       = rmxln_25h(:,:,:) / 25.0_wp
-#endif
-
-            IF (lwp)  WRITE(numout,*) 'dia_wri_tide : Mean calculated by dividing 25 hour sums and writing output'
-            zmdi=1.e+20 !missing data indicator for masking
-            ! write tracers (instantaneous)
-            zw3d(:,:,:) = tn_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
-            CALL iom_put("temper25h", zw3d)   ! potential temperature
-            zw3d(:,:,:) = sn_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
-            CALL iom_put( "salin25h", zw3d  )   ! salinity
-            zw2d(:,:) = sshn_25h(:,:)*tmask(:,:,1) + zmdi*(1.0-tmask(:,:,1))
-            CALL iom_put( "ssh25h", zw2d )   ! sea surface 
-
-
-            ! Write velocities (instantaneous)
-            zw3d(:,:,:) = un_25h(:,:,:)*umask(:,:,:) + zmdi*(1.0-umask(:,:,:))
-            CALL iom_put("vozocrtx25h", zw3d)    ! i-current
-            zw3d(:,:,:) = vn_25h(:,:,:)*vmask(:,:,:) + zmdi*(1.0-vmask(:,:,:))
-            CALL iom_put("vomecrty25h", zw3d  )   ! j-current
-
-            zw3d(:,:,:) = wn_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
-            CALL iom_put("vomecrtz25h", zw3d )   ! k-current
-            zw3d(:,:,:) = avt_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
-            CALL iom_put("avt25h", zw3d )   ! diffusivity
-            zw3d(:,:,:) = avm_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
-            CALL iom_put("avm25h", zw3d)   ! viscosity
-#if defined key_zdftke || defined key_zdfgls 
-            zw3d(:,:,:) = en_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
+      ! Write data for 25 hour mean output streams
+      IF( cnt_25h == 25 .AND.  MOD( kt, i_steps*24) == 0 .AND. kt /= nn_it000 ) THEN
+         !
+         IF(lwp) THEN
+            WRITE(numout,*) 'dia_wri_tide : Writing 25 hour mean tide diagnostics at timestep', kt
+            WRITE(numout,*) '~~~~~~~~~~~~ '
+         ENDIF
+         !
+         tn_25h  (:,:,:) = tn_25h  (:,:,:) * r1_25
+         sn_25h  (:,:,:) = sn_25h  (:,:,:) * r1_25
+         sshn_25h(:,:)   = sshn_25h(:,:)   * r1_25
+         un_25h  (:,:,:) = un_25h  (:,:,:) * r1_25
+         vn_25h  (:,:,:) = vn_25h  (:,:,:) * r1_25
+         wn_25h  (:,:,:) = wn_25h  (:,:,:) * r1_25
+         avt_25h (:,:,:) = avt_25h (:,:,:) * r1_25
+         avm_25h (:,:,:) = avm_25h (:,:,:) * r1_25
+         IF( ln_zdftke ) THEN
+            en_25h(:,:,:) = en_25h(:,:,:) * r1_25
+         ENDIF
+         IF( ln_zdfgls ) THEN
+            en_25h   (:,:,:) = en_25h   (:,:,:) * r1_25
+            rmxln_25h(:,:,:) = rmxln_25h(:,:,:) * r1_25
+         ENDIF
+         !
+         IF(lwp)  WRITE(numout,*) 'dia_wri_tide : Mean calculated by dividing 25 hour sums and writing output'
+         zmdi=1.e+20 !missing data indicator for masking
+         ! write tracers (instantaneous)
+         zw3d(:,:,:) = tn_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
+         CALL iom_put("temper25h", zw3d)   ! potential temperature
+         zw3d(:,:,:) = sn_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
+         CALL iom_put( "salin25h", zw3d  )   ! salinity
+         zw2d(:,:) = sshn_25h(:,:)*tmask(:,:,1) + zmdi*(1.0-tmask(:,:,1))
+         CALL iom_put( "ssh25h", zw2d )   ! sea surface 
+         ! Write velocities (instantaneous)
+         zw3d(:,:,:) = un_25h(:,:,:)*umask(:,:,:) + zmdi*(1.0-umask(:,:,:))
+         CALL iom_put("vozocrtx25h", zw3d)    ! i-current
+         zw3d(:,:,:) = vn_25h(:,:,:)*vmask(:,:,:) + zmdi*(1.0-vmask(:,:,:))
+         CALL iom_put("vomecrty25h", zw3d  )   ! j-current
+         zw3d(:,:,:) = wn_25h(:,:,:)*wmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
+         CALL iom_put("vomecrtz25h", zw3d )   ! k-current
+         ! Write vertical physics
+         zw3d(:,:,:) = avt_25h(:,:,:)*wmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
+         CALL iom_put("avt25h", zw3d )   ! diffusivity
+         zw3d(:,:,:) = avm_25h(:,:,:)*wmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
+         CALL iom_put("avm25h", zw3d)   ! viscosity
+         IF( ln_zdftke ) THEN
+            zw3d(:,:,:) = en_25h(:,:,:)*wmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
             CALL iom_put("tke25h", zw3d)   ! tke
-#endif
-#if defined key_zdfgls 
-            zw3d(:,:,:) = rmxln_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
+         ENDIF
+         IF( ln_zdfgls ) THEN
+            zw3d(:,:,:) = en_25h(:,:,:)*wmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
+            CALL iom_put("tke25h", zw3d)   ! tke
+            zw3d(:,:,:) = rmxln_25h(:,:,:)*wmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
             CALL iom_put( "mxln25h",zw3d)
-#endif
-
-            ! After the write reset the values to cnt=1 and sum values equal current value 
-            tn_25h(:,:,:) = tsn(:,:,:,jp_tem)
-            sn_25h(:,:,:) = tsn(:,:,:,jp_sal)
-            sshn_25h(:,:) = sshn (:,:)
-            un_25h(:,:,:) = un(:,:,:)
-            vn_25h(:,:,:) = vn(:,:,:)
-            wn_25h(:,:,:) = wn(:,:,:)
-            avt_25h(:,:,:) = avt(:,:,:)
-            avm_25h(:,:,:) = avm(:,:,:)
-# if defined key_zdfgls || defined key_zdftke
+         ENDIF
+         !
+         ! After the write reset the values to cnt=1 and sum values equal current value 
+         tn_25h  (:,:,:) = tsn (:,:,:,jp_tem)
+         sn_25h  (:,:,:) = tsn (:,:,:,jp_sal)
+         sshn_25h(:,:)   = sshn(:,:)
+         un_25h  (:,:,:) = un  (:,:,:)
+         vn_25h  (:,:,:) = vn  (:,:,:)
+         wn_25h  (:,:,:) = wn  (:,:,:)
+         avt_25h (:,:,:) = avt (:,:,:)
+         avm_25h (:,:,:) = avm (:,:,:)
+         IF( ln_zdftke ) THEN
             en_25h(:,:,:) = en(:,:,:)
-#endif
-# if defined key_zdfgls
-            rmxln_25h(:,:,:) = mxln(:,:,:)
-#endif
-            cnt_25h = 1
-            IF (lwp)  WRITE(numout,*) 'dia_wri_tide :   &
-        &    After 25hr mean write, reset sum to current value and cnt_25h to one for overlapping average',cnt_25h
-
+         ENDIF
+         IF( ln_zdfgls ) THEN
+            en_25h   (:,:,:) = en    (:,:,:)
+            rmxln_25h(:,:,:) = hmxl_n(:,:,:)
+         ENDIF
+         cnt_25h = 1
+         IF(lwp)  WRITE(numout,*) 'dia_wri_tide :   &
+            &    After 25hr mean write, reset sum to current value and cnt_25h to one for overlapping average', cnt_25h
       ENDIF !  cnt_25h .EQ. 25 .AND.  MOD( kt, i_steps * 24) == 0 .AND. kt .NE. nn_it000
-
-
+      !
    END SUBROUTINE dia_25h 
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90	(revision 9019)
@@ -39,5 +39,4 @@
       
    !! * Substitutions
-#  include "zdfddm_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -214,5 +213,5 @@
          CALL wrk_alloc( jpi, jpj, zpe )
          zpe(:,:) = 0._wp
-         IF( lk_zdfddm ) THEN
+         IF( ln_zdfddm ) THEN
             DO jk = 2, jpk
                DO jj = 1, jpj
@@ -221,4 +220,7 @@
                         zrw =   ( gdepw_n(ji,jj,jk  ) - gdept_n(ji,jj,jk) )   &
                            &  / ( gdept_n(ji,jj,jk-1) - gdept_n(ji,jj,jk) )
+!!gm  this can be reduced to :  (depw-dept) / e3w   (NB idem dans bn2 !)
+!                        zrw =   ( gdept_n(ji,jj,jk) - gdepw_n(ji,jj,jk) ) / e3w_n(ji,jj,jk)
+!!gm end
                         !
                         zaw = rab_n(ji,jj,jk,jp_tem) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_tem)* zrw
@@ -226,6 +228,6 @@
                         !
                         zpe(ji, jj) = zpe(ji, jj)            &
-                           &        -  grav * (    avt(ji,jj,jk) * zaw * (tsn(ji,jj,jk-1,jp_tem) - tsn(ji,jj,jk,jp_tem) )  &
-                           &                   - fsavs(ji,jj,jk) * zbw * (tsn(ji,jj,jk-1,jp_sal) - tsn(ji,jj,jk,jp_sal) ) )
+                           &        -  grav * (  avt(ji,jj,jk) * zaw * (tsn(ji,jj,jk-1,jp_tem) - tsn(ji,jj,jk,jp_tem) )  &
+                           &                   - avs(ji,jj,jk) * zbw * (tsn(ji,jj,jk-1,jp_sal) - tsn(ji,jj,jk,jp_sal) ) )
                      ENDIF
                   END DO
@@ -241,7 +243,8 @@
             END DO
          ENDIF
-         CALL lbc_lnk( zpe, 'T', 1._wp)         
-         CALL iom_put( 'tnpeo', zpe )
-         CALL wrk_dealloc( jpi, jpj, zpe )
+!!gm useless lbc_lnk since the computation above is performed over 1:jpi & 1:jpj
+!!gm           CALL lbc_lnk( zpe, 'T', 1._wp)         
+          CALL iom_put( 'tnpeo', zpe )
+          CALL wrk_dealloc( jpi, jpj, zpe )
       ENDIF
       !
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diacfl.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diacfl.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diacfl.F90	(revision 9019)
@@ -1,10 +1,10 @@
 MODULE diacfl
-   !!==============================================================================
+   !!======================================================================
    !!                       ***  MODULE  diacfl  ***
    !! Output CFL diagnostics to ascii file
-   !!==============================================================================
-   !! History :  1.0  !  2010-03  (E. Blockley)  Original code
-   !!                 !  2014-06  (T Graham) Removed CPP key & Updated to vn3.6
-   !! 
+   !!======================================================================
+   !! History :  3.4  !  2010-03  (E. Blockley)  Original code
+   !!            3.6  !  2014-06  (T. Graham)  Removed CPP key & Updated to vn3.6
+   !!            4.0  !  2017-09  (G. Madec)  style + comments
    !!----------------------------------------------------------------------
    !!   dia_cfl        : Compute and output Courant numbers at each timestep
@@ -12,8 +12,9 @@
    USE oce             ! ocean dynamics and active tracers
    USE dom_oce         ! ocean space and time domain
+   USE domvvl          ! 
+   !
    USE lib_mpp         ! distribued memory computing
    USE lbclnk          ! ocean lateral boundary condition (or mpp link)
    USE in_out_manager  ! I/O manager
-   USE domvvl     
    USE timing          ! Performance output
 
@@ -21,12 +22,14 @@
    PRIVATE
 
-   REAL(wp) :: cu_max, cv_max, cw_max                      ! Run max U Courant number 
-   INTEGER, DIMENSION(3) :: cu_loc, cv_loc, cw_loc         ! Run max locations
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: zcu_cfl           ! Courant number arrays
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: zcv_cfl           ! Courant number arrays
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: zcw_cfl           ! Courant number arrays
+   CHARACTER(LEN=50) :: clname="cfl_diagnostics.ascii"    ! ascii filename
+   INTEGER           :: numcfl                            ! outfile unit
+   !
+   INTEGER, DIMENSION(3) ::   nCu_loc, nCv_loc, nCw_loc   ! U, V, and W run max locations in the global domain
+   REAL(wp)              ::   rCu_max, rCv_max, rCw_max   ! associated run max Courant number 
 
-   INTEGER  :: numcfl                                       ! outfile unit
-   CHARACTER(LEN=50) :: clname="cfl_diagnostics.ascii"      ! ascii filename
+!!gm CAUTION: need to declare these arrays here, otherwise the calculation fails in multi-proc !
+!!gm          I don't understand why.
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   zCu_cfl, zCv_cfl, zCw_cfl         ! workspace
+!!gm end
 
    PUBLIC   dia_cfl       ! routine called by step.F90
@@ -40,8 +43,5 @@
    !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
-
 CONTAINS
-
 
    SUBROUTINE dia_cfl ( kt )
@@ -52,119 +52,94 @@
       !!               and output to ascii file 'cfl_diagnostics.ascii'
       !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      INTEGER :: ji, jj, jk   ! dummy loop indices
+      REAL(wp)::   z2dt, zCu_max, zCv_max, zCw_max       ! local scalars
+      INTEGER , DIMENSION(3)           ::   iloc_u , iloc_v , iloc_w , iloc   ! workspace
+!!gm this does not work      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zCu_cfl, zCv_cfl, zCw_cfl         ! workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('dia_cfl')
+      !
+      !                       ! setup timestep multiplier to account for initial Eulerian timestep
+      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;    z2dt = rdt
+      ELSE                                        ;    z2dt = rdt * 2._wp
+      ENDIF
+      !
+      !                
+      DO jk = 1, jpk       ! calculate Courant numbers
+         DO jj = 1, jpj
+            DO ji = 1, fs_jpim1   ! vector opt.
+               zCu_cfl(ji,jj,jk) = ABS( un(ji,jj,jk) ) * z2dt / e1u  (ji,jj)      ! for i-direction
+               zCv_cfl(ji,jj,jk) = ABS( vn(ji,jj,jk) ) * z2dt / e2v  (ji,jj)      ! for j-direction
+               zCw_cfl(ji,jj,jk) = ABS( wn(ji,jj,jk) ) * z2dt / e3w_n(ji,jj,jk)   ! for k-direction
+            END DO
+         END DO         
+      END DO
+      !
+      !                    ! calculate maximum values and locations
+      IF( lk_mpp ) THEN
+         CALL mpp_maxloc( zCu_cfl, umask, zCu_max, iloc_u(1), iloc_u(2), iloc_u(3) )
+         CALL mpp_maxloc( zCv_cfl, vmask, zCv_max, iloc_v(1), iloc_v(2), iloc_v(3) )
+         CALL mpp_maxloc( zCw_cfl, wmask, zCw_max, iloc_w(1), iloc_w(2), iloc_w(3) )
+      ELSE
+         iloc = MAXLOC( ABS( zcu_cfl(:,:,:) ) )
+         iloc_u(1) = iloc(1) + nimpp - 1
+         iloc_u(2) = iloc(2) + njmpp - 1
+         iloc_u(3) = iloc(3)
+         zCu_max = zCu_cfl(iloc(1),iloc(2),iloc(3))
+         !
+         iloc = MAXLOC( ABS( zcv_cfl(:,:,:) ) )
+         iloc_v(1) = iloc(1) + nimpp - 1
+         iloc_v(2) = iloc(2) + njmpp - 1
+         iloc_v(3) = iloc(3)
+         zCv_max = zCv_cfl(iloc(1),iloc(2),iloc(3))
+         !
+         iloc = MAXLOC( ABS( zcw_cfl(:,:,:) ) )
+         iloc_w(1) = iloc(1) + nimpp - 1
+         iloc_w(2) = iloc(2) + njmpp - 1
+         iloc_w(3) = iloc(3)
+         zCw_max = zCw_cfl(iloc(1),iloc(2),iloc(3))
+      ENDIF
+      !
+      !                    ! write out to file
+      IF( lwp ) THEN
+         WRITE(numcfl,FMT='(2x,i4,5x,a6,4x,f7.4,1x,i4,1x,i4,1x,i4)') kt, 'Max Cu', zCu_max, iloc_u(1), iloc_u(2), iloc_u(3)
+         WRITE(numcfl,FMT='(11x,     a6,4x,f7.4,1x,i4,1x,i4,1x,i4)')     'Max Cv', zCv_max, iloc_v(1), iloc_v(2), iloc_v(3)
+         WRITE(numcfl,FMT='(11x,     a6,4x,f7.4,1x,i4,1x,i4,1x,i4)')     'Max Cw', zCw_max, iloc_w(1), iloc_w(2), iloc_w(3)
+      ENDIF
+      !
+      !                    ! update maximum Courant numbers from whole run if applicable
+      IF( zCu_max > rCu_max ) THEN   ;   rCu_max = zCu_max   ;   nCu_loc(:) = iloc_u(:)   ;   ENDIF
+      IF( zCv_max > rCv_max ) THEN   ;   rCv_max = zCv_max   ;   nCv_loc(:) = iloc_v(:)   ;   ENDIF
+      IF( zCw_max > rCw_max ) THEN   ;   rCw_max = zCw_max   ;   nCw_loc(:) = iloc_w(:)   ;   ENDIF
 
-      INTEGER, INTENT(in) ::  kt                            ! ocean time-step index
+      !                    ! at end of run output max Cu and Cv and close ascii file
+      IF( kt == nitend .AND. lwp ) THEN
+         ! to ascii file
+         WRITE(numcfl,*) '******************************************'
+         WRITE(numcfl,FMT='(3x,a12,6x,f7.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cu', rCu_max, nCu_loc(1), nCu_loc(2), nCu_loc(3)
+         WRITE(numcfl,FMT='(3x,a8,11x,f15.1)') ' => dt/C', z2dt/rCu_max
+         WRITE(numcfl,*) '******************************************'
+         WRITE(numcfl,FMT='(3x,a12,6x,f7.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cv', rCv_max, nCv_loc(1), nCv_loc(2), nCv_loc(3)
+         WRITE(numcfl,FMT='(3x,a8,11x,f15.1)') ' => dt/C', z2dt/rCv_max
+         WRITE(numcfl,*) '******************************************'
+         WRITE(numcfl,FMT='(3x,a12,6x,f7.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cw', rCw_max, nCw_loc(1), nCw_loc(2), nCw_loc(3)
+         WRITE(numcfl,FMT='(3x,a8,11x,f15.1)') ' => dt/C', z2dt/rCw_max
+         CLOSE( numcfl ) 
+         !
+         ! to ocean output
+         WRITE(numout,*)
+         WRITE(numout,*) 'dia_cfl : Maximum Courant number information for the run '
+         WRITE(numout,*) '~~~~~~~'
+         WRITE(numout,*) '   Max Cu = ', rCu_max, ' at (i,j,k) = (',nCu_loc(1),nCu_loc(2),nCu_loc(3),') => dt/C = ', z2dt/rCu_max
+         WRITE(numout,*) '   Max Cv = ', rCv_max, ' at (i,j,k) = (',nCv_loc(1),nCv_loc(2),nCv_loc(3),') => dt/C = ', z2dt/rCv_max
+         WRITE(numout,*) '   Max Cw = ', rCw_max, ' at (i,j,k) = (',nCw_loc(1),nCw_loc(2),nCw_loc(3),') => dt/C = ', z2dt/rCw_max
+      ENDIF
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('dia_cfl')
+      !
+   END SUBROUTINE dia_cfl
 
-      REAL(wp) :: zcu_max, zcv_max, zcw_max                 ! max Courant numbers per timestep
-      INTEGER, DIMENSION(3) :: zcu_loc, zcv_loc, zcw_loc    ! max Courant number locations
-
-      REAL(wp) :: dt                                        ! temporary scalars
-      INTEGER, DIMENSION(3) :: zlocu, zlocv, zlocw          ! temporary arrays 
-      INTEGER  :: ji, jj, jk                                ! dummy loop indices
-
-      
-      IF( nn_diacfl == 1) THEN
-         IF( nn_timing == 1 )   CALL timing_start('dia_cfl')
-         ! setup timestep multiplier to account for initial Eulerian timestep
-         IF( neuler == 0 .AND. kt == nit000 ) THEN   ;    dt = rdt
-         ELSE                                        ;    dt = rdt * 2.0
-         ENDIF
-
-             ! calculate Courant numbers
-         DO jk = 1, jpk
-            DO jj = 1, jpj
-               DO ji = 1, fs_jpim1   ! vector opt.
-
-                  ! Courant number for x-direction (zonal current)
-                  zcu_cfl(ji,jj,jk) = ABS(un(ji,jj,jk))*dt/e1u(ji,jj)
-
-                  ! Courant number for y-direction (meridional current)
-                  zcv_cfl(ji,jj,jk) = ABS(vn(ji,jj,jk))*dt/e2v(ji,jj)
-
-                  ! Courant number for z-direction (vertical current)
-                  zcw_cfl(ji,jj,jk) = ABS(wn(ji,jj,jk))*dt/e3w_n(ji,jj,jk)
-               END DO
-            END DO         
-         END DO
-
-         ! calculate maximum values and locations
-         IF( lk_mpp ) THEN
-            CALL mpp_maxloc(zcu_cfl,umask,zcu_max, zcu_loc(1), zcu_loc(2), zcu_loc(3))
-            CALL mpp_maxloc(zcv_cfl,vmask,zcv_max, zcv_loc(1), zcv_loc(2), zcv_loc(3))
-            CALL mpp_maxloc(zcw_cfl,tmask,zcw_max, zcw_loc(1), zcw_loc(2), zcw_loc(3))
-         ELSE
-            zlocu = MAXLOC( ABS( zcu_cfl(:,:,:) ) )
-            zcu_loc(1) = zlocu(1) + nimpp - 1
-            zcu_loc(2) = zlocu(2) + njmpp - 1
-            zcu_loc(3) = zlocu(3)
-            zcu_max = zcu_cfl(zcu_loc(1),zcu_loc(2),zcu_loc(3))
-
-            zlocv = MAXLOC( ABS( zcv_cfl(:,:,:) ) )
-            zcv_loc(1) = zlocv(1) + nimpp - 1
-            zcv_loc(2) = zlocv(2) + njmpp - 1
-            zcv_loc(3) = zlocv(3)
-            zcv_max = zcv_cfl(zcv_loc(1),zcv_loc(2),zcv_loc(3))
-
-            zlocw = MAXLOC( ABS( zcw_cfl(:,:,:) ) )
-            zcw_loc(1) = zlocw(1) + nimpp - 1
-            zcw_loc(2) = zlocw(2) + njmpp - 1
-            zcw_loc(3) = zlocw(3)
-            zcw_max = zcw_cfl(zcw_loc(1),zcw_loc(2),zcw_loc(3))
-         ENDIF
-      
-         ! write out to file
-         IF( lwp ) THEN
-            WRITE(numcfl,FMT='(2x,i4,5x,a6,5x,f6.4,1x,i4,1x,i4,1x,i4)') kt, 'Max Cu', zcu_max, zcu_loc(1), zcu_loc(2), zcu_loc(3)
-            WRITE(numcfl,FMT='(11x,a6,5x,f6.4,1x,i4,1x,i4,1x,i4)') 'Max Cv', zcv_max, zcv_loc(1), zcv_loc(2), zcv_loc(3)
-            WRITE(numcfl,FMT='(11x,a6,5x,f6.4,1x,i4,1x,i4,1x,i4)') 'Max Cw', zcw_max, zcw_loc(1), zcw_loc(2), zcw_loc(3)
-         ENDIF
-
-         ! update maximum Courant numbers from whole run if applicable
-         IF( zcu_max > cu_max ) THEN
-            cu_max = zcu_max
-            cu_loc = zcu_loc
-         ENDIF
-         IF( zcv_max > cv_max ) THEN
-            cv_max = zcv_max
-            cv_loc = zcv_loc
-         ENDIF
-         IF( zcw_max > cw_max ) THEN
-            cw_max = zcw_max
-            cw_loc = zcw_loc
-         ENDIF
-
-         ! at end of run output max Cu and Cv and close ascii file
-         IF( kt == nitend .AND. lwp ) THEN
-            ! to ascii file
-            WRITE(numcfl,*) '******************************************'
-            WRITE(numcfl,FMT='(3x,a12,7x,f6.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cu', cu_max, cu_loc(1), cu_loc(2), cu_loc(3)
-            WRITE(numcfl,FMT='(3x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cu_max)
-            WRITE(numcfl,*) '******************************************'
-            WRITE(numcfl,FMT='(3x,a12,7x,f6.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cv', cv_max, cv_loc(1), cv_loc(2), cv_loc(3)
-            WRITE(numcfl,FMT='(3x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cv_max)
-            WRITE(numcfl,*) '******************************************'
-            WRITE(numcfl,FMT='(3x,a12,7x,f6.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cw', cw_max, cw_loc(1), cw_loc(2), cw_loc(3)
-            WRITE(numcfl,FMT='(3x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cw_max)
-            CLOSE( numcfl ) 
-
-            ! to ocean output
-            WRITE(numout,*)
-            WRITE(numout,*) 'dia_cfl     : Maximum Courant number information for the run:'
-            WRITE(numout,*) '~~~~~~~~~~~~'
-            WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cu', cu_max, 'at (i, j, k) =   &
-                          &   (', cu_loc(1), cu_loc(2), cu_loc(3), ')'
-            WRITE(numout,FMT='(12x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cu_max)
-            WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cv', cv_max, 'at (i, j, k) =   &
-                          &   (', cv_loc(1), cv_loc(2), cv_loc(3), ')'
-            WRITE(numout,FMT='(12x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cv_max)
-            WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cw', cw_max, 'at (i, j, k) =   &
-                          &   (', cw_loc(1), cw_loc(2), cw_loc(3), ')'
-            WRITE(numout,FMT='(12x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cw_max)
-
-         ENDIF
-
-         IF( nn_timing == 1 )   CALL timing_stop('dia_cfl')
-      ENDIF
-
-   END SUBROUTINE dia_cfl
 
    SUBROUTINE dia_cfl_init
@@ -174,36 +149,27 @@
       !! ** Purpose :   create output file, initialise arrays
       !!----------------------------------------------------------------------
-
-
-      IF( nn_diacfl == 1 ) THEN
-         IF( nn_timing == 1 )   CALL timing_start('dia_cfl_init')
-
-         cu_max=0.0
-         cv_max=0.0
-         cw_max=0.0
-
-         ALLOCATE( zcu_cfl(jpi, jpj, jpk), zcv_cfl(jpi, jpj, jpk), zcw_cfl(jpi, jpj, jpk) )
-
-         zcu_cfl(:,:,:)=0.0
-         zcv_cfl(:,:,:)=0.0
-         zcw_cfl(:,:,:)=0.0
-
-         IF( lwp ) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) 'dia_cfl     : Outputting CFL diagnostics to '//TRIM(clname)
-            WRITE(numout,*) '~~~~~~~~~~~~'
-            WRITE(numout,*)
-
-            ! create output ascii file
-            CALL ctl_opn( numcfl, clname, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', 1, numout, lwp, 1 )
-            WRITE(numcfl,*) 'Timestep  Direction  Max C     i    j    k'
-            WRITE(numcfl,*) '******************************************'
-         ENDIF
-
-         IF( nn_timing == 1 )   CALL timing_stop('dia_cfl_init')
-
+      !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dia_cfl : Outputting CFL diagnostics to ',TRIM(clname), ' file'
+         WRITE(numout,*) '~~~~~~~'
+         WRITE(numout,*)
+         !
+         ! create output ascii file
+         CALL ctl_opn( numcfl, clname, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', 1, numout, lwp, 1 )
+         WRITE(numcfl,*) 'Timestep  Direction  Max C     i    j    k'
+         WRITE(numcfl,*) '******************************************'
       ENDIF
-
+      !
+      rCu_max = 0._wp
+      rCv_max = 0._wp
+      rCw_max = 0._wp
+      !
+!!gm required to work
+      ALLOCATE ( zCu_cfl(jpi,jpj,jpk), zCv_cfl(jpi,jpj,jpk), zCw_cfl(jpi,jpj,jpk) )
+!!gm end
+      !      
    END SUBROUTINE dia_cfl_init
 
+   !!======================================================================
 END MODULE diacfl
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90	(revision 9019)
@@ -32,7 +32,4 @@
    USE dianam          ! build name of file
    USE lib_mpp         ! distributed memory computing library
-#if defined key_lim2
-   USE ice_2
-#endif
 #if defined key_lim3
    USE ice
@@ -747,5 +744,5 @@
            END DO !end of loop on the level
 
-#if defined key_lim2 || defined key_lim3
+#if defined key_lim3
 
            !ICE CASE    
@@ -769,21 +766,13 @@
               zTnorm=zumid_ice*e2u(k%I,k%J)+zvmid_ice*e1v(k%I,k%J)
 
-#if defined key_lim2   
-              transports_2d(1,jsec,jseg) = transports_2d(1,jsec,jseg) + (zTnorm)*   & 
-                                   (1.0 - frld(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J))  & 
-                                  *(hsnif(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J) +  & 
-                                    hicif(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J))
-              transports_2d(2,jsec,jseg) = transports_2d(2,jsec,jseg) + (zTnorm)*   & 
-                                    (1.0 -  frld(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J))
-#endif
 #if defined key_lim3
               DO jl=1,jpl
-                 transports_2d(1,jsec,jseg) = transports_2d(1,jsec,jseg) + (zTnorm)*     &
-                                   a_i(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J,jl) * &
-                                  ( ht_i(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J,jl) +  &
-                                    ht_s(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J,jl) )
+                 transports_2d(1,jsec,jseg) = transports_2d(1,jsec,jseg) + (zTnorm)*       &
+                                    a_i(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J,jl) *  &
+                                  ( h_i(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J,jl) +  &
+                                    h_s(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J,jl) )
                                    
                  transports_2d(2,jsec,jseg) = transports_2d(2,jsec,jseg) + (zTnorm)*   &
-                                   a_i(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J,jl)
+                                    a_i(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J,jl)
               END DO
 #endif
@@ -956,9 +945,9 @@
                  ENDIF ! end of test if point is in class 
     
-              ENDDO ! end of loop on the classes 
- 
-           ENDDO ! loop over jk 
- 
-#if defined key_lim2 || defined key_lim3 
+              END DO ! end of loop on the classes 
+ 
+           END DO ! loop over jk 
+ 
+#if defined key_lim3 
  
            !ICE CASE     
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diahth.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diahth.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diahth.F90	(revision 9019)
@@ -139,5 +139,5 @@
       DO jj = 1, jpj
          DO ji = 1, jpi
-            zztmp = bathy(ji,jj)
+            zztmp = gdepw_n(ji,jj,mbkt(ji,jj)+1) 
             hth     (ji,jj) = zztmp
             zabs2   (ji,jj) = zztmp
@@ -150,5 +150,5 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               zztmp = bathy(ji,jj)
+               zztmp = gdepw_n(ji,jj,mbkt(ji,jj)+1) 
                zrho0_3(ji,jj) = zztmp
                zrho0_1(ji,jj) = zztmp
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 9019)
@@ -397,5 +397,5 @@
       REWIND( numnam_cfg )              ! Namelist namptr in configuration namelist : Poleward transport
       READ  ( numnam_cfg, namptr, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namptr in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namptr in configuration namelist', lwp )
       IF(lwm) WRITE ( numond, namptr )
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 9019)
@@ -25,34 +25,32 @@
    !!   dia_wri_state : create an output NetCDF file for a single instantaeous ocean state and forcing fields
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers 
-   USE dom_oce         ! ocean space and time domain
-   USE dynadv, ONLY: ln_dynadv_vec
-   USE zdf_oce         ! ocean vertical physics
-   USE ldftra          ! lateral physics: eddy diffusivity coef.
-   USE ldfdyn          ! lateral physics: eddy viscosity   coef.
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice fields
-   USE icb_oce         ! Icebergs
-   USE icbdia          ! Iceberg budgets
-   USE sbcssr          ! restoring term toward SST/SSS climatology
-   USE phycst          ! physical constants
-   USE zdfmxl          ! mixed layer
-   USE dianam          ! build name of file (routine)
-   USE zdfddm          ! vertical  physics: double diffusion
-   USE diahth          ! thermocline diagnostics
-   USE wet_dry         ! wetting and drying
-   USE sbcwave         ! wave parameters
+   USE oce            ! ocean dynamics and tracers 
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE dianam         ! build name of file (routine)
+   USE diahth         ! thermocline diagnostics
+   USE dynadv   , ONLY: ln_dynadv_vec
+   USE icb_oce        ! Icebergs
+   USE icbdia         ! Iceberg budgets
+   USE ldftra         ! lateral physics: eddy diffusivity coef.
+   USE ldfdyn         ! lateral physics: eddy viscosity   coef.
+   USE sbc_oce        ! Surface boundary condition: ocean fields
+   USE sbc_ice        ! Surface boundary condition: ice fields
+   USE sbcssr         ! restoring term toward SST/SSS climatology
+   USE sbcwave        ! wave parameters
+   USE wet_dry        ! wetting and drying
+   USE zdf_oce        ! ocean vertical physics
+   USE zdfdrg         ! ocean vertical physics: top/bottom friction
+   USE zdfmxl         ! mixed layer
    !
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE in_out_manager  ! I/O manager
-   USE diatmb          ! Top,middle,bottom output
-   USE dia25h          ! 25h Mean output
-   USE iom
-   USE ioipsl
-
-#if defined key_lim2
-   USE limwri_2 
-#elif defined key_lim3
-   USE limwri 
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE in_out_manager ! I/O manager
+   USE diatmb         ! Top,middle,bottom output
+   USE dia25h         ! 25h Mean output
+   USE iom            ! 
+   USE ioipsl         ! 
+
+#if defined key_lim3
+   USE icewri 
 #endif
    USE lib_mpp         ! MPP library
@@ -60,5 +58,4 @@
    USE diurnal_bulk    ! diurnal warm layer
    USE cool_skin       ! Cool skin
-   USE wrk_nemo        ! working array
 
    IMPLICIT NONE
@@ -80,5 +77,4 @@
 
    !! * Substitutions
-#  include "zdfddm_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -120,20 +116,16 @@
       !! ** Method  :  use iom_put
       !!----------------------------------------------------------------------
-      !!
       INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
       !!
-      INTEGER                      ::   ji, jj, jk              ! dummy loop indices
-      INTEGER                      ::   jkbot                   !
-      REAL(wp)                     ::   zztmp, zztmpx, zztmpy   ! 
-      !!
-      REAL(wp), POINTER, DIMENSION(:,:)   :: z2d      ! 2D workspace
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: z3d      ! 3D workspace
+      INTEGER ::   ji, jj, jk       ! dummy loop indices
+      INTEGER ::   ikbot            ! local integer
+      REAL(wp)::   zztmp , zztmpx   ! local scalar
+      REAL(wp)::   zztmp2, zztmpy   !   -      -
+      REAL(wp), DIMENSION(jpi,jpj)     ::   z2d   ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   z3d   ! 3D workspace
       !!----------------------------------------------------------------------
       ! 
       IF( nn_timing == 1 )   CALL timing_start('dia_wri')
       ! 
-      CALL wrk_alloc( jpi , jpj      , z2d )
-      CALL wrk_alloc( jpi , jpj, jpk , z3d )
-      !
       ! Output the initial state and forcings
       IF( ninist == 1 ) THEN                       
@@ -163,6 +155,6 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               jkbot = mbkt(ji,jj)
-               z2d(ji,jj) = tsn(ji,jj,jkbot,jp_tem)
+               ikbot = mbkt(ji,jj)
+               z2d(ji,jj) = tsn(ji,jj,ikbot,jp_tem)
             END DO
          END DO
@@ -175,6 +167,6 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               jkbot = mbkt(ji,jj)
-               z2d(ji,jj) = tsn(ji,jj,jkbot,jp_sal)
+               ikbot = mbkt(ji,jj)
+               z2d(ji,jj) = tsn(ji,jj,ikbot,jp_sal)
             END DO
          END DO
@@ -183,26 +175,27 @@
 
       IF ( iom_use("taubot") ) THEN                ! bottom stress
+         zztmp = rau0 * 0.25
          z2d(:,:) = 0._wp
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zztmpx = (  bfrua(ji  ,jj) * un(ji  ,jj,mbku(ji  ,jj))  &
-                      &  + bfrua(ji-1,jj) * un(ji-1,jj,mbku(ji-1,jj))  )      
-               zztmpy = (  bfrva(ji,  jj) * vn(ji,jj  ,mbkv(ji,jj  ))  &
-                      &  + bfrva(ji,jj-1) * vn(ji,jj-1,mbkv(ji,jj-1))  ) 
-               z2d(ji,jj) = rau0 * SQRT( zztmpx * zztmpx + zztmpy * zztmpy ) * tmask(ji,jj,1) 
+               zztmp2 = (  ( rCdU_bot(ji+1,jj)+rCdU_bot(ji  ,jj) ) * un(ji  ,jj,mbku(ji  ,jj))  )**2   &
+                  &   + (  ( rCdU_bot(ji  ,jj)+rCdU_bot(ji-1,jj) ) * un(ji-1,jj,mbku(ji-1,jj))  )**2   &
+                  &   + (  ( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj  ) ) * vn(ji,jj  ,mbkv(ji,jj  ))  )**2   &
+                  &   + (  ( rCdU_bot(ji,jj  )+rCdU_bot(ji,jj-1) ) * vn(ji,jj-1,mbkv(ji,jj-1))  )**2
+               z2d(ji,jj) = zztmp * SQRT( zztmp2 ) * tmask(ji,jj,1) 
                !
-            ENDDO
-         ENDDO
+            END DO
+         END DO
          CALL lbc_lnk( z2d, 'T', 1. )
          CALL iom_put( "taubot", z2d )           
       ENDIF
          
-      CALL iom_put( "uoce", un(:,:,:)         )    ! 3D i-current
-      CALL iom_put(  "ssu", un(:,:,1)         )    ! surface i-current
+      CALL iom_put( "uoce", un(:,:,:) )            ! 3D i-current
+      CALL iom_put(  "ssu", un(:,:,1) )            ! surface i-current
       IF ( iom_use("sbu") ) THEN
          DO jj = 1, jpj
             DO ji = 1, jpi
-               jkbot = mbku(ji,jj)
-               z2d(ji,jj) = un(ji,jj,jkbot)
+               ikbot = mbku(ji,jj)
+               z2d(ji,jj) = un(ji,jj,ikbot)
             END DO
          END DO
@@ -210,11 +203,11 @@
       ENDIF
       
-      CALL iom_put( "voce", vn(:,:,:)         )    ! 3D j-current
-      CALL iom_put(  "ssv", vn(:,:,1)         )    ! surface j-current
+      CALL iom_put( "voce", vn(:,:,:) )            ! 3D j-current
+      CALL iom_put(  "ssv", vn(:,:,1) )            ! surface j-current
       IF ( iom_use("sbv") ) THEN
          DO jj = 1, jpj
             DO ji = 1, jpi
-               jkbot = mbkv(ji,jj)
-               z2d(ji,jj) = vn(ji,jj,jkbot)
+               ikbot = mbkv(ji,jj)
+               z2d(ji,jj) = vn(ji,jj,ikbot)
             END DO
          END DO
@@ -233,10 +226,10 @@
       ENDIF
 
-      CALL iom_put( "avt" , avt                        )    ! T vert. eddy diff. coef.
-      CALL iom_put( "avm" , avmu                       )    ! T vert. eddy visc. coef.
-      CALL iom_put( "avs" , fsavs(:,:,:)               )    ! S vert. eddy diff. coef. (useful only with key_zdfddm)
-
-      IF( iom_use('logavt') )   CALL iom_put( "logavt", LOG( MAX( 1.e-20_wp, avt  (:,:,:) ) ) )
-      IF( iom_use('logavs') )   CALL iom_put( "logavs", LOG( MAX( 1.e-20_wp, fsavs(:,:,:) ) ) )
+      CALL iom_put( "avt" , avt )                  ! T vert. eddy diff. coef.
+      CALL iom_put( "avs" , avs )                  ! S vert. eddy diff. coef.
+      CALL iom_put( "avm" , avm )                  ! T vert. eddy visc. coef.
+
+      IF( iom_use('logavt') )   CALL iom_put( "logavt", LOG( MAX( 1.e-20_wp, avt(:,:,:) ) ) )
+      IF( iom_use('logavs') )   CALL iom_put( "logavs", LOG( MAX( 1.e-20_wp, avs(:,:,:) ) ) )
 
       IF ( iom_use("sstgrad") .OR. iom_use("sstgrad2") ) THEN
@@ -251,10 +244,10 @@
          END DO
          CALL lbc_lnk( z2d, 'T', 1. )
-         CALL iom_put( "sstgrad2",  z2d               )    ! square of module of sst gradient
+         CALL iom_put( "sstgrad2",  z2d )          ! square of module of sst gradient
          z2d(:,:) = SQRT( z2d(:,:) )
-         CALL iom_put( "sstgrad" ,  z2d               )    ! module of sst gradient
+         CALL iom_put( "sstgrad" ,  z2d )          ! module of sst gradient
       ENDIF
          
-      ! clem: heat and salt content
+      ! heat and salt contents
       IF( iom_use("heatc") ) THEN
          z2d(:,:)  = 0._wp 
@@ -266,5 +259,5 @@
             END DO
          END DO
-         CALL iom_put( "heatc", (rau0 * rcp) * z2d )    ! vertically integrated heat content (J/m2)
+         CALL iom_put( "heatc", rau0_rcp * z2d )   ! vertically integrated heat content (J/m2)
       ENDIF
 
@@ -278,28 +271,22 @@
             END DO
          END DO
-         CALL iom_put( "saltc", rau0 * z2d )   ! vertically integrated salt content (PSU*kg/m2)
+         CALL iom_put( "saltc", rau0 * z2d )          ! vertically integrated salt content (PSU*kg/m2)
       ENDIF
       !
       IF ( iom_use("eken") ) THEN
-         rke(:,:,jpk) = 0._wp                               !      kinetic energy 
+         z3d(:,:,jk) = 0._wp 
          DO jk = 1, jpkm1
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zztmp   = r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
-                  zztmpx  = 0.5 * (  un(ji-1,jj,jk) * un(ji-1,jj,jk) * e1e2u(ji-1,jj) * e3u_n(ji-1,jj,jk)    &
-                     &             + un(ji  ,jj,jk) * un(ji  ,jj,jk) * e1e2u(ji  ,jj) * e3u_n(ji  ,jj,jk) )  &
-                     &          *  zztmp 
-                  !
-                  zztmpy  = 0.5 * (  vn(ji,jj-1,jk) * vn(ji,jj-1,jk) * e1e2v(ji,jj-1) * e3v_n(ji,jj-1,jk)    &
-                     &             + vn(ji,jj  ,jk) * vn(ji,jj  ,jk) * e1e2v(ji,jj  ) * e3v_n(ji,jj  ,jk) )  &
-                     &          *  zztmp 
-                  !
-                  rke(ji,jj,jk) = 0.5_wp * ( zztmpx + zztmpy )
-                  !
-               ENDDO
-            ENDDO
-         ENDDO
-         CALL lbc_lnk( rke, 'T', 1. )
-         CALL iom_put( "eken", rke )           
+                  zztmp  = 0.25_wp * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
+                  z3d(ji,jj,jk) = zztmp * (  un(ji-1,jj,jk)**2 * e2u(ji-1,jj) * e3u_n(ji-1,jj,jk)   &
+                     &                     + un(ji  ,jj,jk)**2 * e2u(ji  ,jj) * e3u_n(ji  ,jj,jk)   &
+                     &                     + vn(ji,jj-1,jk)**2 * e1v(ji,jj-1) * e3v_n(ji,jj-1,jk)   &
+                     &                     + vn(ji,jj  ,jk)**2 * e1v(ji,jj  ) * e3v_n(ji,jj  ,jk)   )
+               END DO
+            END DO
+         END DO
+         CALL lbc_lnk( z3d, 'T', 1. )
+         CALL iom_put( "eken", z3d )                 ! kinetic energy
       ENDIF
       !
@@ -313,10 +300,10 @@
             z2d(:,:) = z2d(:,:) + z3d(:,:,jk)
          END DO
-         CALL iom_put( "u_masstr", z3d )                  ! mass transport in i-direction
-         CALL iom_put( "u_masstr_vint", z2d )             ! mass transport in i-direction vertical sum
+         CALL iom_put( "u_masstr"     , z3d )         ! mass transport in i-direction
+         CALL iom_put( "u_masstr_vint", z2d )         ! mass transport in i-direction vertical sum
       ENDIF
       
       IF( iom_use("u_heattr") ) THEN
-         z2d(:,:) = 0.e0 
+         z2d(:,:) = 0._wp 
          DO jk = 1, jpkm1
             DO jj = 2, jpjm1
@@ -327,5 +314,5 @@
          END DO
          CALL lbc_lnk( z2d, 'U', -1. )
-         CALL iom_put( "u_heattr", (0.5 * rcp) * z2d )    ! heat transport in i-direction
+         CALL iom_put( "u_heattr", 0.5*rcp * z2d )    ! heat transport in i-direction
       ENDIF
 
@@ -340,5 +327,5 @@
          END DO
          CALL lbc_lnk( z2d, 'U', -1. )
-         CALL iom_put( "u_salttr", 0.5 * z2d )            ! heat transport in i-direction
+         CALL iom_put( "u_salttr", 0.5 * z2d )        ! heat transport in i-direction
       ENDIF
 
@@ -349,5 +336,5 @@
             z3d(:,:,jk) = rau0 * vn(:,:,jk) * e1v(:,:) * e3v_n(:,:,jk) * vmask(:,:,jk)
          END DO
-         CALL iom_put( "v_masstr", z3d )                  ! mass transport in j-direction
+         CALL iom_put( "v_masstr", z3d )              ! mass transport in j-direction
       ENDIF
       
@@ -362,9 +349,9 @@
          END DO
          CALL lbc_lnk( z2d, 'V', -1. )
-         CALL iom_put( "v_heattr", (0.5 * rcp) * z2d )    !  heat transport in j-direction
+         CALL iom_put( "v_heattr", 0.5*rcp * z2d )    !  heat transport in j-direction
       ENDIF
 
       IF( iom_use("v_salttr") ) THEN
-         z2d(:,:) = 0.e0 
+         z2d(:,:) = 0._wp 
          DO jk = 1, jpkm1
             DO jj = 2, jpjm1
@@ -375,22 +362,19 @@
          END DO
          CALL lbc_lnk( z2d, 'V', -1. )
-         CALL iom_put( "v_salttr", 0.5 * z2d )            !  heat transport in j-direction
-      ENDIF
-
-      ! Vertical integral of temperature
+         CALL iom_put( "v_salttr", 0.5 * z2d )        !  heat transport in j-direction
+      ENDIF
+
       IF( iom_use("tosmint") ) THEN
-         z2d(:,:)=0._wp
+         z2d(:,:) = 0._wp
          DO jk = 1, jpkm1
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  z2d(ji,jj) = z2d(ji,jj) + rau0 * e3t_n(ji,jj,jk) *  tsn(ji,jj,jk,jp_tem)
+                  z2d(ji,jj) = z2d(ji,jj) + e3t_n(ji,jj,jk) *  tsn(ji,jj,jk,jp_tem)
                END DO
             END DO
          END DO
          CALL lbc_lnk( z2d, 'T', -1. )
-         CALL iom_put( "tosmint", z2d ) 
-      ENDIF
-
-      ! Vertical integral of salinity
+         CALL iom_put( "tosmint", rau0 * z2d )        ! Vertical integral of temperature
+      ENDIF
       IF( iom_use("somint") ) THEN
          z2d(:,:)=0._wp
@@ -398,25 +382,18 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  z2d(ji,jj) = z2d(ji,jj) + rau0 * e3t_n(ji,jj,jk) * tsn(ji,jj,jk,jp_sal)
+                  z2d(ji,jj) = z2d(ji,jj) + e3t_n(ji,jj,jk) * tsn(ji,jj,jk,jp_sal)
                END DO
             END DO
          END DO
          CALL lbc_lnk( z2d, 'T', -1. )
-         CALL iom_put( "somint", z2d ) 
-      ENDIF
-
-      CALL iom_put( "bn2", rn2 )  !Brunt-Vaisala buoyancy frequency (N^2)
-      !
-      CALL wrk_dealloc( jpi , jpj      , z2d )
-      CALL wrk_dealloc( jpi , jpj, jpk , z3d )
-      !
-      ! If we want tmb values 
-
-      IF (ln_diatmb) THEN
-         CALL dia_tmb 
-      ENDIF 
-      IF (ln_dia25h) THEN
-         CALL dia_25h( kt )
-      ENDIF 
+         CALL iom_put( "somint", rau0 * z2d )         ! Vertical integral of salinity
+      ENDIF
+
+      CALL iom_put( "bn2", rn2 )                      ! Brunt-Vaisala buoyancy frequency (N^2)
+      !
+
+      IF (ln_diatmb)   CALL dia_tmb                   ! tmb values 
+          
+      IF (ln_dia25h)   CALL dia_25h( kt )             ! 25h averaging
 
       IF( nn_timing == 1 )   CALL timing_stop('dia_wri')
@@ -452,15 +429,11 @@
       REAL(wp) ::   zsto, zout, zmax, zjulian                ! local scalars
       !
-      REAL(wp), POINTER, DIMENSION(:,:)   :: zw2d       ! 2D workspace
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zw3d       ! 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj)   :: zw2d       ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zw3d       ! 3D workspace
       !!----------------------------------------------------------------------
       ! 
       IF( nn_timing == 1 )   CALL timing_start('dia_wri')
       !
-                             CALL wrk_alloc( jpi,jpj      , zw2d )
-      IF( .NOT.ln_linssh )   CALL wrk_alloc( jpi,jpj,jpk  , zw3d )
-      !
-      ! Output the initial state and forcings
-      IF( ninist == 1 ) THEN                       
+      IF( ninist == 1 ) THEN     !==  Output the initial state and forcings  ==!
          CALL dia_wri_state( 'output.init', kt )
          ninist = 0
@@ -470,6 +443,5 @@
       ! -----------------
 
-      ! local variable for debugging
-      ll_print = .FALSE.
+      ll_print = .FALSE.                  ! local variable for debugging
       ll_print = ll_print .AND. lwp
 
@@ -707,11 +679,4 @@
 #endif
 
-         IF( ln_cpl .AND. nn_ice == 2 ) THEN
-            CALL histdef( nid_T,"soicetem" , "Ice Surface Temperature"            , "K"      ,   &  ! tn_ice
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-            CALL histdef( nid_T,"soicealb" , "Ice Albedo"                         , "[0,1]"  ,   &  ! alb_ice
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         ENDIF
-
          CALL histend( nid_T, snc4chunks=snc4set )
 
@@ -747,8 +712,8 @@
          CALL histdef( nid_W, "votkeavt", "Vertical Eddy Diffusivity"          , "m2/s"   ,   &  ! avt
             &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
-         CALL histdef( nid_W, "votkeavm", "Vertical Eddy Viscosity"             , "m2/s"  ,   &  ! avmu
+         CALL histdef( nid_W, "votkeavm", "Vertical Eddy Viscosity"             , "m2/s"  ,   &  ! avm
             &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
 
-         IF( lk_zdfddm ) THEN
+         IF( ln_zdfddm ) THEN
             CALL histdef( nid_W,"voddmavs","Salt Vertical Eddy Diffusivity"    , "m2/s"   ,   &  ! avs
                &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
@@ -861,9 +826,4 @@
 #endif
 
-      IF( ln_cpl .AND. nn_ice == 2 ) THEN
-         CALL histwrite( nid_T, "soicetem", it, tn_ice(:,:,1) , ndim_hT, ndex_hT )   ! surf. ice temperature
-         CALL histwrite( nid_T, "soicealb", it, alb_ice(:,:,1), ndim_hT, ndex_hT )   ! ice albedo
-      ENDIF
-
       CALL histwrite( nid_U, "vozocrtx", it, un            , ndim_U , ndex_U )    ! i-current
       CALL histwrite( nid_U, "sozotaux", it, utau          , ndim_hU, ndex_hU )   ! i-wind stress
@@ -874,13 +834,13 @@
       CALL histwrite( nid_W, "vovecrtz", it, wn             , ndim_T, ndex_T )    ! vert. current
       CALL histwrite( nid_W, "votkeavt", it, avt            , ndim_T, ndex_T )    ! T vert. eddy diff. coef.
-      CALL histwrite( nid_W, "votkeavm", it, avmu           , ndim_T, ndex_T )    ! T vert. eddy visc. coef.
-      IF( lk_zdfddm ) THEN
-         CALL histwrite( nid_W, "voddmavs", it, fsavs(:,:,:), ndim_T, ndex_T )    ! S vert. eddy diff. coef.
+      CALL histwrite( nid_W, "votkeavm", it, avm            , ndim_T, ndex_T )    ! T vert. eddy visc. coef.
+      IF( ln_zdfddm ) THEN
+         CALL histwrite( nid_W, "voddmavs", it, avs         , ndim_T, ndex_T )    ! S vert. eddy diff. coef.
       ENDIF
 
       IF( ln_wave .AND. ln_sdw ) THEN
-         CALL histwrite( nid_U, "sdzocrtx", it, usd           , ndim_U , ndex_U )    ! i-StokesDrift-current
-         CALL histwrite( nid_V, "sdmecrty", it, vsd           , ndim_V , ndex_V )    ! j-StokesDrift-current
-         CALL histwrite( nid_W, "sdvecrtz", it, wsd           , ndim_T , ndex_T )    ! StokesDrift vert. current
+         CALL histwrite( nid_U, "sdzocrtx", it, usd         , ndim_U , ndex_U )    ! i-StokesDrift-current
+         CALL histwrite( nid_V, "sdmecrty", it, vsd         , ndim_V , ndex_V )    ! j-StokesDrift-current
+         CALL histwrite( nid_W, "sdvecrtz", it, wsd         , ndim_T , ndex_T )    ! StokesDrift vert. current
       ENDIF
 
@@ -893,7 +853,4 @@
          CALL histclo( nid_W )
       ENDIF
-      !
-                             CALL wrk_dealloc( jpi , jpj        , zw2d )
-      IF( .NOT.ln_linssh )   CALL wrk_dealloc( jpi , jpj , jpk  , zw3d )
       !
       IF( nn_timing == 1 )   CALL timing_stop('dia_wri')
@@ -1009,8 +966,8 @@
       ENDIF
 
-#if defined key_lim2
-      CALL lim_wri_state_2( kt, id_i, nh_i )
-#elif defined key_lim3
-      CALL lim_wri_state( kt, id_i, nh_i )
+#if defined key_lim3
+      IF( nn_ice == 2 ) THEN   ! condition needed in case agrif + ice-model but no-ice in child grid
+         CALL ice_wri_state( kt, id_i, nh_i )
+      ENDIF
 #else
       CALL histend( id_i, snc4chunks=snc4set )
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90	(revision 9019)
@@ -223,5 +223,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('day')
+      IF( ln_timing )   CALL timing_start('day')
       !
       zprec = 0.1 / rday
@@ -277,5 +277,5 @@
       IF( lrst_oce         ) CALL day_rst( kt, 'WRITE' )      ! write day restart information
       !
-      IF( nn_timing == 1 )  CALL timing_stop('day')
+      IF( ln_timing )   CALL timing_stop('day')
       !
    END SUBROUTINE day
@@ -403,5 +403,5 @@
          CALL iom_rstput( kt, nitrst, numrow, 'adatrj' , adatrj            )   ! number of elapsed days since
          !                                                                     ! the begining of the run [s]
-	 CALL iom_rstput( kt, nitrst, numrow, 'ntime'  , REAL( nn_time0, wp) ) ! time
+	      CALL iom_rstput( kt, nitrst, numrow, 'ntime'  , REAL( nn_time0, wp) ) ! time
       ENDIF
       !
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/depth_e3.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/depth_e3.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/depth_e3.F90	(revision 9019)
@@ -20,5 +20,4 @@
    USE lbclnk            ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp           ! distributed memory computing library
-   USE wrk_nemo          ! Memory allocation
    USE timing            ! Timing
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 9019)
@@ -90,8 +90,4 @@
    INTEGER, PUBLIC ::   noea, nowe        !: index of the local neighboring processors in
    INTEGER, PUBLIC ::   noso, nono        !: east, west, south and north directions
-   INTEGER, PUBLIC ::   npne, npnw        !: index of north east and north west processor
-   INTEGER, PUBLIC ::   npse, npsw        !: index of south east and south west processor
-   INTEGER, PUBLIC ::   nbne, nbnw        !: logical of north east & north west processor
-   INTEGER, PUBLIC ::   nbse, nbsw        !: logical of south east & south west processor
    INTEGER, PUBLIC ::   nidom             !: ???
 
@@ -124,5 +120,5 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   e1e2f , r1_e1e2f                !: associated metrics at f-point
    !
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   ff_f, ff_t                      !: Coriolis factor at f- & t-points  [1/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   ff_f  , ff_t                    !: Coriolis factor at f- & t-points  [1/s]
    !!----------------------------------------------------------------------
    !! vertical coordinate and scale factors
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 9019)
@@ -37,5 +37,4 @@
    USE domvvl         ! variable volume
    USE c1d            ! 1D configuration
-   USE domc1d         ! 1D configuration: column location
    USE dyncor_c1d     ! 1D configuration: Coriolis term    (cor_c1d routine)
    USE wet_dry        ! wetting and drying
@@ -45,5 +44,4 @@
    USE lbclnk         ! ocean lateral boundary condition (or mpp link)
    USE lib_mpp        ! distributed memory computing library
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
 
@@ -83,5 +81,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start('dom_init')
+      IF( ln_timing )   CALL timing_start('dom_init')
       !
       IF(lwp) THEN         ! Ocean domain Parameters (control print)
@@ -98,6 +96,6 @@
          WRITE(numout,cform) '       ' ,'   jpij    : ', jpij
          WRITE(numout,*)     '      mpp local domain info (mpp):'
-         WRITE(numout,*)     '              jpni    : ', jpni, '   jpreci  : ', jpreci
-         WRITE(numout,*)     '              jpnj    : ', jpnj, '   jprecj  : ', jprecj
+         WRITE(numout,*)     '              jpni    : ', jpni, '   nn_hls  : ', nn_hls
+         WRITE(numout,*)     '              jpnj    : ', jpnj, '   nn_hls  : ', nn_hls
          WRITE(numout,*)     '              jpnij   : ', jpnij
          WRITE(numout,*)     '      lateral boundary of the Global domain : jperio  = ', jperio
@@ -119,9 +117,4 @@
       ENDIF
       !
-      !      
-!!gm  This should be removed with the new configuration interface
-      IF( lk_c1d .AND. ln_c1d_locpt )  CALL dom_c1d( rn_lat1d, rn_lon1d )
-!!gm end
-      !
       !           !==  Reference coordinate system  ==!
       !
@@ -199,5 +192,5 @@
       IF( ln_write_cfg )   CALL cfg_write         ! create the configuration file
       !
-      IF( nn_timing == 1 )   CALL timing_stop('dom_init')
+      IF( ln_timing )   CALL timing_stop('dom_init')
       !
    END SUBROUTINE dom_init
@@ -246,20 +239,20 @@
          IF( nn_print >= 1 ) THEN
             WRITE(numout,*)
-            WRITE(numout,*) '          conversion local  ==> global i-index domain'
+            WRITE(numout,*) '          conversion local  ==> global i-index domain (mig)'
             WRITE(numout,25)              (mig(ji),ji = 1,jpi)
             WRITE(numout,*)
             WRITE(numout,*) '          conversion global ==> local  i-index domain'
-            WRITE(numout,*) '             starting index'
+            WRITE(numout,*) '             starting index (mi0)'
             WRITE(numout,25)              (mi0(ji),ji = 1,jpiglo)
-            WRITE(numout,*) '             ending index'
+            WRITE(numout,*) '             ending index (mi1)'
             WRITE(numout,25)              (mi1(ji),ji = 1,jpiglo)
             WRITE(numout,*)
-            WRITE(numout,*) '          conversion local  ==> global j-index domain'
+            WRITE(numout,*) '          conversion local  ==> global j-index domain (mjg)'
             WRITE(numout,25)              (mjg(jj),jj = 1,jpj)
             WRITE(numout,*)
             WRITE(numout,*) '          conversion global ==> local  j-index domain'
-            WRITE(numout,*) '             starting index'
+            WRITE(numout,*) '             starting index (mj0)'
             WRITE(numout,25)              (mj0(jj),jj = 1,jpjglo)
-            WRITE(numout,*) '             ending index'
+            WRITE(numout,*) '             ending index (mj1)'
             WRITE(numout,25)              (mj1(jj),jj = 1,jpjglo)
          ENDIF
@@ -593,5 +586,5 @@
       !                       ! ============================= !
       !         
-      clnam = 'domcfg_out'  ! filename (configuration information)
+      clnam = cn_domcfg_out  ! filename (configuration information)
       CALL iom_open( TRIM(clnam), inum, ldwrt = .TRUE., kiolib = jprstlib )
       
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domhgr.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domhgr.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domhgr.F90	(revision 9019)
@@ -79,5 +79,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dom_hgr')
+      IF( ln_timing )   CALL timing_start('dom_hgr')
       !
       IF(lwp) THEN
@@ -152,5 +152,5 @@
       !
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dom_hgr')
+      IF( ln_timing )   CALL timing_stop('dom_hgr')
       !
    END SUBROUTINE dom_hgr
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 9019)
@@ -30,5 +30,4 @@
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp        ! Massively Parallel Processing library
-   USE wrk_nemo       ! Memory allocation
    USE timing         ! Timing
 
@@ -92,5 +91,5 @@
       INTEGER  ::   iktop, ikbot   !   -       -
       INTEGER  ::   ios, inum
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zwf   ! 2D workspace
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zwf   ! 2D workspace
       !!
       NAMELIST/namlbc/ rn_shlat, ln_vorlat
@@ -104,5 +103,5 @@
       !!---------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dom_msk')
+      IF( ln_timing )   CALL timing_start('dom_msk')
       !
       REWIND( numnam_ref )              ! Namelist namlbc in reference namelist : Lateral momentum boundary condition
@@ -212,6 +211,6 @@
       ! --------------------
       !
-      iif = jpreci   ;   iil = nlci - jpreci + 1
-      ijf = jprecj   ;   ijl = nlcj - jprecj + 1
+      iif = nn_hls   ;   iil = nlci - nn_hls + 1
+      ijf = nn_hls   ;   ijl = nlcj - nn_hls + 1
       !
       !                          ! halo mask : 0 on the halo and 1 elsewhere
@@ -248,5 +247,5 @@
       IF( rn_shlat /= 0 ) THEN      ! Not free-slip lateral boundary condition
          !
-         CALL wrk_alloc( jpi,jpj,   zwf )
+         ALLOCATE( zwf(jpi,jpj) )
          !
          DO jk = 1, jpk
@@ -278,5 +277,5 @@
          END DO
          !
-         CALL wrk_dealloc( jpi,jpj,   zwf )
+         DEALLOCATE( zwf )
          !
          CALL lbc_lnk( fmask, 'F', 1._wp )      ! Lateral boundary conditions on fmask
@@ -292,5 +291,5 @@
       !
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dom_msk')
+      IF( ln_timing )   CALL timing_stop('dom_msk')
       !
    END SUBROUTINE dom_msk
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domngb.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domngb.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domngb.F90	(revision 9019)
@@ -11,7 +11,7 @@
    !!----------------------------------------------------------------------
    USE dom_oce        ! ocean space and time domain
+   !
    USE in_out_manager ! I/O manager
    USE lib_mpp        ! for mppsum
-   USE wrk_nemo       ! Memory allocation
    USE timing         ! Timing
 
@@ -45,10 +45,8 @@
       INTEGER , DIMENSION(2) ::   iloc
       REAL(wp)               ::   zlon, zmini
-      REAL(wp), POINTER, DIMENSION(:,:) ::  zglam, zgphi, zmask, zdist
+      REAL(wp), DIMENSION(jpi,jpj) ::   zglam, zgphi, zmask, zdist
       !!--------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dom_ngb')
-      !
-      CALL wrk_alloc( jpi,jpj,   zglam, zgphi, zmask, zdist )
+      IF( ln_timing )   CALL timing_start('dom_ngb')
       !
       zmask(:,:) = 0._wp
@@ -79,7 +77,5 @@
       ENDIF
       !
-      CALL wrk_dealloc( jpi,jpj,   zglam, zgphi, zmask, zdist )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('dom_ngb')
+      IF( ln_timing )   CALL timing_stop('dom_ngb')
       !
    END SUBROUTINE dom_ngb
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domvvl.F90	(revision 9019)
@@ -6,6 +6,5 @@
    !! History :  2.0  !  2006-06  (B. Levier, L. Marie)  original code
    !!            3.1  !  2009-02  (G. Madec, M. Leclair, R. Benshila)  pure z* coordinate
-   !!            3.3  !  2011-10  (M. Leclair) totally rewrote domvvl:
-   !!                                          vvl option includes z_star and z_tilde coordinates
+   !!            3.3  !  2011-10  (M. Leclair) totally rewrote domvvl: vvl option includes z_star and z_tilde coordinates
    !!            3.6  !  2014-11  (P. Mathiot) add ice shelf capability
    !!----------------------------------------------------------------------
@@ -31,5 +30,4 @@
    USE lib_mpp         ! distributed memory computing library
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE wrk_nemo        ! Memory allocation
    USE timing          ! Timing
 
@@ -122,5 +120,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start('dom_vvl_init')
+      IF( ln_timing )   CALL timing_start('dom_vvl_init')
       !
       IF(lwp) WRITE(numout,*)
@@ -242,5 +240,5 @@
       ENDIF
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dom_vvl_init')
+      IF( ln_timing )   CALL timing_stop('dom_vvl_init')
       !
    END SUBROUTINE dom_vvl_init
@@ -276,15 +274,12 @@
       REAL(wp)               ::   z2dt, z_tmin, z_tmax  ! local scalars
       LOGICAL                ::   ll_do_bclinic         ! local logical
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ze3t
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::   zht, z_scale, zwu, zwv, zhdiv
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zht, z_scale, zwu, zwv, zhdiv
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze3t
       !!----------------------------------------------------------------------
       !
       IF( ln_linssh )   RETURN      ! No calculation in linear free surface
       !
-      IF( nn_timing == 1 )   CALL timing_start('dom_vvl_sf_nxt')
-      !
-      CALL wrk_alloc( jpi,jpj,zht,   z_scale, zwu, zwv, zhdiv )
-      CALL wrk_alloc( jpi,jpj,jpk,   ze3t )
-
+      IF( ln_timing )   CALL timing_start('dom_vvl_sf_nxt')
+      !
       IF( kt == nit000 ) THEN
          IF(lwp) WRITE(numout,*)
@@ -543,8 +538,5 @@
       r1_hv_a(:,:) = ssvmask(:,:) / ( hv_a(:,:) + 1._wp - ssvmask(:,:) )
       !
-      CALL wrk_dealloc( jpi,jpj,       zht, z_scale, zwu, zwv, zhdiv )
-      CALL wrk_dealloc( jpi,jpj,jpk,   ze3t )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('dom_vvl_sf_nxt')
+      IF( ln_timing )   CALL timing_stop('dom_vvl_sf_nxt')
       !
    END SUBROUTINE dom_vvl_sf_nxt
@@ -583,5 +575,5 @@
       IF( ln_linssh )   RETURN      ! No calculation in linear free surface
       !
-      IF( nn_timing == 1 )  CALL timing_start('dom_vvl_sf_swp')
+      IF( ln_timing )   CALL timing_start('dom_vvl_sf_swp')
       !
       IF( kt == nit000 )   THEN
@@ -657,7 +649,7 @@
       ! write restart file
       ! ==================
-      IF( lrst_oce )   CALL dom_vvl_rst( kt, 'WRITE' )
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('dom_vvl_sf_swp')
+      IF( lrst_oce  )   CALL dom_vvl_rst( kt, 'WRITE' )
+      !
+      IF( ln_timing )   CALL timing_stop('dom_vvl_sf_swp')
       !
    END SUBROUTINE dom_vvl_sf_swp
@@ -683,5 +675,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start('dom_vvl_interpol')
+      IF( ln_timing )   CALL timing_start('dom_vvl_interpol')
       !
       IF(ln_wd) THEN
@@ -770,5 +762,5 @@
       END SELECT
       !
-      IF( nn_timing == 1 )   CALL timing_stop('dom_vvl_interpol')
+      IF( ln_timing )   CALL timing_stop('dom_vvl_interpol')
       !
    END SUBROUTINE dom_vvl_interpol
@@ -794,5 +786,6 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dom_vvl_rst')
+      IF( ln_timing )   CALL timing_start('dom_vvl_rst')
+      !
       IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
          !                                   ! ===============
@@ -947,5 +940,5 @@
       ENDIF
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dom_vvl_rst')
+      IF( ln_timing )   CALL timing_stop('dom_vvl_rst')
       !
    END SUBROUTINE dom_vvl_rst
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domwri.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domwri.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domwri.F90	(revision 9019)
@@ -24,5 +24,4 @@
    USE lbclnk          ! lateral boundary conditions - mpp exchanges
    USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! Memory allocation
    USE timing          ! Timing
 
@@ -75,12 +74,9 @@
       INTEGER           ::   izco, izps, isco, icav
       !                               
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zprt, zprw     ! 2D workspace
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zdepu, zdepv   ! 3D workspace
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('dom_wri')
-      !
-      CALL wrk_alloc( jpi,jpj,       zprt , zprw  )
-      CALL wrk_alloc( jpi,jpj,jpk,   zdepu, zdepv )
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zprt, zprw     ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdepu, zdepv   ! 3D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('dom_wri')
       !
       IF(lwp) WRITE(numout,*)
@@ -206,8 +202,5 @@
       !                                     ! ============================
       !
-      CALL wrk_dealloc( jpi, jpj, zprt, zprw )
-      CALL wrk_dealloc( jpi, jpj, jpk, zdepu, zdepv )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('dom_wri')
+      IF( ln_timing )   CALL timing_stop('dom_wri')
       !
    END SUBROUTINE dom_wri
@@ -229,10 +222,8 @@
       INTEGER  ::  ji       ! dummy loop indices
       LOGICAL, DIMENSION(SIZE(puniq,1),SIZE(puniq,2),1) ::  lldbl  ! store whether each point is unique or not
-      REAL(wp), POINTER, DIMENSION(:,:) :: ztstref
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('dom_uniq')
-      !
-      CALL wrk_alloc( jpi, jpj, ztstref )
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztstref
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('dom_uniq')
       !
       ! build an array with different values for each element 
@@ -250,7 +241,5 @@
       puniq(nldi:nlei,nldj:nlej) = REAL( COUNT( lldbl(nldi:nlei,nldj:nlej,:), dim = 3 ) , wp )
       !
-      CALL wrk_dealloc( jpi, jpj, ztstref )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('dom_uniq')
+      IF( ln_timing )   CALL timing_stop('dom_uniq')
       !
    END SUBROUTINE dom_uniq
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 9019)
@@ -36,5 +36,4 @@
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp        ! distributed memory computing library
-   USE wrk_nemo       ! Memory allocation
    USE timing         ! Timing
 
@@ -77,5 +76,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start('dom_zgr')
+      IF( ln_timing )   CALL timing_start('dom_zgr')
       !
       IF(lwp) THEN                     ! Control print
@@ -164,5 +163,5 @@
       ENDIF
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dom_zgr')
+      IF( ln_timing )   CALL timing_stop('dom_zgr')
       !
    END SUBROUTINE dom_zgr
@@ -284,10 +283,8 @@
       !
       INTEGER ::   ji, jj   ! dummy loop indices
-      REAL(wp), POINTER, DIMENSION(:,:) ::  zk
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('zgr_top_bot')
-      !
-      CALL wrk_alloc( jpi,jpj,   zk )
+      REAL(wp), DIMENSION(jpi,jpj) ::   zk   ! workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('zgr_top_bot')
       !
       IF(lwp) WRITE(numout,*)
@@ -319,7 +316,5 @@
       zk(:,:) = REAL( mbkv(:,:), wp )   ;   CALL lbc_lnk( zk, 'V', 1. )   ;   mbkv(:,:) = MAX( INT( zk(:,:) ), 1 )
       !
-      CALL wrk_dealloc( jpi,jpj,   zk )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('zgr_top_bot')
+      IF( ln_timing )   CALL timing_stop('zgr_top_bot')
       !
    END SUBROUTINE zgr_top_bot
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/dtatsd.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/dtatsd.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/dtatsd.F90	(revision 9019)
@@ -16,10 +16,10 @@
    !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers
+   USE phycst          ! physical constants
    USE dom_oce         ! ocean space and time domain
    USE fldread         ! read input fields
+   !
    USE in_out_manager  ! I/O manager
-   USE phycst          ! physical constants
    USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! Memory allocation
    USE timing          ! Timing
 
@@ -62,5 +62,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dta_tsd_init')
+      IF( ln_timing )   CALL timing_start('dta_tsd_init')
       !
       !  Initialisation
@@ -120,5 +120,5 @@
       ENDIF
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dta_tsd_init')
+      IF( ln_timing )   CALL timing_stop('dta_tsd_init')
       !
    END SUBROUTINE dta_tsd_init
@@ -145,9 +145,9 @@
       INTEGER ::   ji, jj, jk, jl, jkk   ! dummy loop indicies
       INTEGER ::   ik, il0, il1, ii0, ii1, ij0, ij1   ! local integers
-      REAL(wp)::   zl, zi
-      REAL(wp), POINTER, DIMENSION(:) ::  ztp, zsp   ! 1D workspace
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('dta_tsd')
+      REAL(wp)::   zl, zi                             ! local scalars
+      REAL(wp), DIMENSION(jpk) ::  ztp, zsp   ! 1D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('dta_tsd')
       !
       CALL fld_read( kt, 1, sf_tsd )      !==   read T & S data at kt time step   ==!
@@ -185,6 +185,4 @@
       !
       IF( ln_sco ) THEN                   !==   s- or mixed s-zps-coordinate   ==!
-         !
-         CALL wrk_alloc( jpk, ztp, zsp )
          !
          IF( kt == nit000 .AND. lwp )THEN
@@ -222,6 +220,4 @@
          END DO
          ! 
-         CALL wrk_dealloc( jpk, ztp, zsp )
-         ! 
       ELSE                                !==   z- or zps- coordinate   ==!
          !                             
@@ -260,5 +256,5 @@
       ENDIF
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dta_tsd')
+      IF( ln_timing )   CALL timing_stop('dta_tsd')
       !
    END SUBROUTINE dta_tsd
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/iscplhsb.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/iscplhsb.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/iscplhsb.F90	(revision 9019)
@@ -13,16 +13,16 @@
    !!   iscpl_div      : correction of divergence to keep volume conservation
    !!----------------------------------------------------------------------
+   USE oce             ! global tra/dyn variable
    USE dom_oce         ! ocean space and time domain
    USE domwri          ! ocean space and time domain
+   USE domngb          ! 
    USE phycst          ! physical constants
    USE sbc_oce         ! surface boundary condition variables
-   USE oce             ! global tra/dyn variable
+   USE iscplini        ! 
+   !
    USE in_out_manager  ! I/O manager
    USE lib_mpp         ! MPP library
    USE lib_fortran     ! MPP library
-   USE wrk_nemo        ! Memory allocation
    USE lbclnk          !
-   USE domngb          !
-   USE iscplini
 
    IMPLICIT NONE
@@ -56,35 +56,31 @@
       REAL(wp), DIMENSION(:,:,:  ), INTENT(out) :: pvol_flx    !! corrective flux to have volume conservation
       REAL(wp),                     INTENT(in ) :: prdt_iscpl  !! coupling period 
-      !!
-      INTEGER :: ji, jj, jk                                    !! loop index
-      INTEGER :: jip1, jim1, jjp1, jjm1
-      !!
-      REAL(wp):: summsk, zsum, zsum1, zarea, zsumn, zsumb
-      REAL(wp):: r1_rdtiscpl
-      REAL(wp):: zjip1_ratio  , zjim1_ratio  , zjjp1_ratio  , zjjm1_ratio
-      !!
-      REAL(wp):: zde3t, zdtem, zdsal
-      REAL(wp), DIMENSION(:,:), POINTER :: zdssh
-      !!
-      REAL(wp), DIMENSION(:), ALLOCATABLE :: zlon, zlat
-      REAL(wp), DIMENSION(:), ALLOCATABLE :: zcorr_vol, zcorr_tem, zcorr_sal
-      INTEGER , DIMENSION(:), ALLOCATABLE :: ixpts, iypts, izpts, inpts
+      !
+      INTEGER  ::   ji  , jj  , jk           ! loop index
+      INTEGER  ::   jip1, jim1, jjp1, jjm1
+      REAL(wp) ::   summsk, zsum , zsumn, zjip1_ratio  , zjim1_ratio, zdtem, zde3t, z1_rdtiscpl
+      REAL(wp) ::   zarea , zsum1, zsumb, zjjp1_ratio  , zjjm1_ratio, zdsal
+      REAL(wp), DIMENSION(jpi,jpj)        ::   zdssh   ! workspace
+      REAL(wp), DIMENSION(:), ALLOCATABLE ::   zlon, zlat
+      REAL(wp), DIMENSION(:), ALLOCATABLE ::   zcorr_vol, zcorr_tem, zcorr_sal
+      INTEGER , DIMENSION(:), ALLOCATABLE ::   ixpts, iypts, izpts, inpts
       INTEGER :: jpts, npts
-
-      CALL wrk_alloc(jpi,jpj, zdssh )
+      !!----------------------------------------------------------------------
 
       ! get imbalance (volume heat and salt)
       ! initialisation difference
-      zde3t = 0.0_wp; zdsal = 0.0_wp ; zdtem = 0.0_wp
+      zde3t = 0._wp   ;   zdsal = 0._wp   ;   zdtem = 0._wp
 
       ! initialisation correction term
-      pvol_flx(:,:,:  ) = 0.0_wp
-      pts_flx (:,:,:,:) = 0.0_wp
+      pvol_flx(:,:,:  ) = 0._wp
+      pts_flx (:,:,:,:) = 0._wp
       
-      r1_rdtiscpl = 1._wp / prdt_iscpl 
+      z1_rdtiscpl = 1._wp / prdt_iscpl 
 
       ! mask tsn and tsb 
-      tsb(:,:,:,jp_tem)=tsb(:,:,:,jp_tem)*ptmask_b(:,:,:); tsn(:,:,:,jp_tem)=tsn(:,:,:,jp_tem)*tmask(:,:,:);
-      tsb(:,:,:,jp_sal)=tsb(:,:,:,jp_sal)*ptmask_b(:,:,:); tsn(:,:,:,jp_sal)=tsn(:,:,:,jp_sal)*tmask(:,:,:);
+      tsb(:,:,:,jp_tem) = tsb(:,:,:,jp_tem) * ptmask_b(:,:,:)
+      tsn(:,:,:,jp_tem) = tsn(:,:,:,jp_tem) *  tmask  (:,:,:)
+      tsb(:,:,:,jp_sal) = tsb(:,:,:,jp_sal) * ptmask_b(:,:,:)
+      tsn(:,:,:,jp_sal) = tsn(:,:,:,jp_sal) *  tmask  (:,:,:)
 
       !==============================================================================
@@ -118,7 +114,7 @@
 
                   ! volume, heat and salt differences in each cell 
-                  pvol_flx(ji,jj,jk)       =   pvol_flx(ji,jj,jk)        + zde3t * r1_rdtiscpl
-                  pts_flx (ji,jj,jk,jp_sal)=   pts_flx (ji,jj,jk,jp_sal) + zdsal * r1_rdtiscpl 
-                  pts_flx (ji,jj,jk,jp_tem)=   pts_flx (ji,jj,jk,jp_tem) + zdtem * r1_rdtiscpl
+                  pvol_flx(ji,jj,jk)       =   pvol_flx(ji,jj,jk)        + zde3t * z1_rdtiscpl
+                  pts_flx (ji,jj,jk,jp_sal)=   pts_flx (ji,jj,jk,jp_sal) + zdsal * z1_rdtiscpl 
+                  pts_flx (ji,jj,jk,jp_tem)=   pts_flx (ji,jj,jk,jp_tem) + zdtem * z1_rdtiscpl
 
                   ! case where we close a cell: check if the neighbour cells are wet 
@@ -184,12 +180,16 @@
       END DO
 
-      CALL lbc_sum(pvol_flx(:,:,:       ),'T',1.)
-      CALL lbc_sum(pts_flx (:,:,:,jp_sal),'T',1.)
-      CALL lbc_sum(pts_flx (:,:,:,jp_tem),'T',1.)
-
+!!gm  ERROR !!!!
+!!    juste use tmask_i  or in case of ISF smask_i (to be created to compute the sum without halos)
+!
+!      CALL lbc_sum(pvol_flx(:,:,:       ),'T',1.)
+!      CALL lbc_sum(pts_flx (:,:,:,jp_sal),'T',1.)
+!      CALL lbc_sum(pts_flx (:,:,:,jp_tem),'T',1.)
+      STOP ' iscpl_cons:   please modify this module !'
+!!gm end
       ! if no neighbour wet cell in case of 2close a cell", need to find the nearest wet point 
       ! allocation and initialisation of the list of problematic point
-      ALLOCATE(inpts(jpnij))
-      inpts(:)=0
+      ALLOCATE( inpts(jpnij) )
+      inpts(:) = 0
 
       ! fill narea location with the number of problematic point
@@ -283,13 +283,16 @@
       pts_flx (:,:,:,jp_tem) = pts_flx (:,:,:,jp_tem) * tmask(:,:,:)
 
-      ! compute sum over the halo and set it to 0.
-      CALL lbc_sum(pvol_flx(:,:,:       ),'T',1._wp)
-      CALL lbc_sum(pts_flx (:,:,:,jp_sal),'T',1._wp)
-      CALL lbc_sum(pts_flx (:,:,:,jp_tem),'T',1._wp)
-
-      ! deallocate variables
-      CALL wrk_dealloc(jpi,jpj, zdssh ) 
-
+!!gm  ERROR !!!!
+!!    juste use tmask_i  or in case of ISF smask_i (to be created to compute the sum without halos)
+!
+!      ! compute sum over the halo and set it to 0.
+!      CALL lbc_sum(pvol_flx(:,:,:       ),'T',1._wp)
+!      CALL lbc_sum(pts_flx (:,:,:,jp_sal),'T',1._wp)
+!      CALL lbc_sum(pts_flx (:,:,:,jp_tem),'T',1._wp)
+!!gm end
+
+      !
    END SUBROUTINE iscpl_cons
+
 
    SUBROUTINE iscpl_div( phdivn )
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/iscplini.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/iscplini.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/iscplini.F90	(revision 9019)
@@ -11,6 +11,7 @@
    !!   iscpl_alloc    : allocation of correction variables
    !!----------------------------------------------------------------------
+   USE oce             ! global tra/dyn variable
    USE dom_oce         ! ocean space and time domain
-   USE oce             ! global tra/dyn variable
+   !
    USE lib_mpp         ! MPP library
    USE lib_fortran     ! MPP library
@@ -47,11 +48,10 @@
    END FUNCTION iscpl_alloc
 
+
    SUBROUTINE iscpl_init()
+      !!----------------------------------------------------------------------
       INTEGER ::   ios           ! Local integer output status for namelist read
-      NAMELIST/namsbc_iscpl/nn_fiscpl,ln_hsb,nn_drown
+      NAMELIST/namsbc_iscpl/ nn_fiscpl, ln_hsb, nn_drown
       !!----------------------------------------------------------------------
-      !                                   ! ============
-      !                                   !   Namelist
-      !                                   ! ============
       !
       nn_fiscpl = 0
@@ -79,7 +79,8 @@
          WRITE(numout,*) ' coupling time step                       = ', rdt_iscpl
          WRITE(numout,*) ' number of call of the extrapolation loop = ', nn_drown
-      END IF
-
+      ENDIF
+      !
    END SUBROUTINE iscpl_init
 
+   !!======================================================================
 END MODULE iscplini
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/iscplrst.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/iscplrst.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/iscplrst.F90	(revision 9019)
@@ -11,18 +11,18 @@
    !!   iscpl_rst_interpol : restart interpolation in case of coupling with ice sheet
    !!----------------------------------------------------------------------
+   USE oce             ! global tra/dyn variable
    USE dom_oce         ! ocean space and time domain
    USE domwri          ! ocean space and time domain
-   USE domvvl, ONLY : dom_vvl_interpol
+   USE domvvl   , ONLY : dom_vvl_interpol
    USE phycst          ! physical constants
    USE sbc_oce         ! surface boundary condition variables
-   USE oce             ! global tra/dyn variable
+   USE iscplini        ! ice sheet coupling: initialisation
+   USE iscplhsb        ! ice sheet coupling: conservation
+   !
    USE in_out_manager  ! I/O manager
    USE iom             ! I/O module
    USE lib_mpp         ! MPP library
    USE lib_fortran     ! MPP library
-   USE wrk_nemo        ! Memory allocation
    USE lbclnk          ! communication
-   USE iscplini        ! ice sheet coupling: initialisation
-   USE iscplhsb        ! ice sheet coupling: conservation
 
    IMPLICIT NONE
@@ -50,18 +50,12 @@
       !!----------------------------------------------------------------------
       INTEGER  ::   inum0
-      REAL(wp), DIMENSION(:,:  ), POINTER ::   zsmask_b
-      REAL(wp), DIMENSION(:,:,:), POINTER ::   ztmask_b, zumask_b, zvmask_b
-      REAL(wp), DIMENSION(:,:,:), POINTER ::   ze3t_b  , ze3u_b  , ze3v_b  
-      REAL(wp), DIMENSION(:,:,:), POINTER ::   zdepw_b
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zsmask_b
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztmask_b, zumask_b, zvmask_b
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze3t_b  , ze3u_b  , ze3v_b  
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdepw_b
       CHARACTER(20) :: cfile
       !!----------------------------------------------------------------------
-
-      CALL wrk_alloc(jpi,jpj,jpk,   ztmask_b, zumask_b, zvmask_b) ! mask before
-      CALL wrk_alloc(jpi,jpj,jpk,   ze3t_b  , ze3u_b  , ze3v_b  ) ! e3   before
-      CALL wrk_alloc(jpi,jpj,jpk,   zdepw_b )
-      CALL wrk_alloc(jpi,jpj,       zsmask_b                    )
-
-
-      !! get restart variable
+      !
+      !                       ! get restart variable
       CALL iom_get( numror, jpdom_autoglo, 'tmask'  , ztmask_b   ) ! need to extrapolate T/S
       CALL iom_get( numror, jpdom_autoglo, 'umask'  , zumask_b   ) ! need to correct barotropic velocity
@@ -72,20 +66,17 @@
       CALL iom_get( numror, jpdom_autoglo, 'e3v_n'  , ze3v_b(:,:,:) )  ! need to correct barotropic velocity
       CALL iom_get( numror, jpdom_autoglo, 'gdepw_n', zdepw_b(:,:,:) ) ! need to interpol vertical profile (vvl)
-
-      !! read namelist
-      CALL iscpl_init()
-
-      !!  ! Extrapolation/interpolation of modify cell and new cells ... (maybe do it later after domvvl)
+      !
+      CALL iscpl_init()       ! read namelist
+      !                       ! Extrapolation/interpolation of modify cell and new cells ... (maybe do it later after domvvl)
       CALL iscpl_rst_interpol( ztmask_b, zumask_b, zvmask_b, zsmask_b, ze3t_b, ze3u_b, ze3v_b, zdepw_b )
-
-      !! compute correction if conservation needed
-      IF ( ln_hsb ) THEN
+      !
+      IF ( ln_hsb ) THEN      ! compute correction if conservation needed
          IF( iscpl_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'rst_iscpl : unable to allocate rst_iscpl arrays' )
          CALL iscpl_cons(ztmask_b, zsmask_b, ze3t_b, htsc_iscpl, hdiv_iscpl, rdt_iscpl)
       END IF
          
-      !! print mesh/mask
-      IF( nn_msh /= 0 .AND. ln_iscpl )   CALL dom_wri      ! Create a domain file
-
+      !                       ! create  a domain file
+      IF( nn_msh /= 0 .AND. ln_iscpl )   CALL dom_wri
+      !
       IF ( ln_hsb ) THEN
          cfile='correction'
@@ -97,24 +88,18 @@
          CALL iom_close ( inum0 )
       END IF
-
-      CALL wrk_dealloc(jpi,jpj,jpk,   ztmask_b,zumask_b,zvmask_b )  
-      CALL wrk_dealloc(jpi,jpj,jpk,   ze3t_b  ,ze3u_b  ,ze3v_b   )  
-      CALL wrk_dealloc(jpi,jpj,jpk,   zdepw_b                    )
-      CALL wrk_dealloc(jpi,jpj,       zsmask_b                   )
-
-      !! next step is an euler time step
-      neuler = 0
-
-      !! set _b and _n variables equal
+      !
+      neuler = 0              ! next step is an euler time step
+      !
+      !                       ! set _b and _n variables equal
       tsb (:,:,:,:) = tsn (:,:,:,:)
       ub  (:,:,:)   = un  (:,:,:)
       vb  (:,:,:)   = vn  (:,:,:)
       sshb(:,:)     = sshn(:,:)
-
-      !! set _b and _n vertical scale factor equal
+      !
+      !                       ! set _b and _n vertical scale factor equal
       e3t_b (:,:,:) = e3t_n (:,:,:)
       e3u_b (:,:,:) = e3u_n (:,:,:)
       e3v_b (:,:,:) = e3v_n (:,:,:)
-
+      !
       e3uw_b (:,:,:) = e3uw_n (:,:,:)
       e3vw_b (:,:,:) = e3vw_n (:,:,:)
@@ -150,27 +135,16 @@
       REAL(wp):: zdz, zdzm1, zdzp1
       !!
-      REAL(wp), DIMENSION(:,:    ), POINTER :: zdmask , zdsmask, zvcorr, zucorr, zde3t
-      REAL(wp), DIMENSION(:,:    ), POINTER :: zbub   , zbvb   , zbun  , zbvn
-      REAL(wp), DIMENSION(:,:    ), POINTER :: zssh0  , zssh1, zhu1, zhv1
-      REAL(wp), DIMENSION(:,:    ), POINTER :: zsmask0, zsmask1
-      REAL(wp), DIMENSION(:,:,:  ), POINTER :: ztmask0, ztmask1, ztrp
-      REAL(wp), DIMENSION(:,:,:  ), POINTER :: zwmaskn, zwmaskb, ztmp3d
-      REAL(wp), DIMENSION(:,:,:,:), POINTER :: zts0
+      REAL(wp), DIMENSION(jpi,jpj)          :: zdmask , zsmask0, zucorr, zbub, zbun, zssh0, zhu1, zde3t
+      REAL(wp), DIMENSION(jpi,jpj)          :: zdsmask, zsmask1, zvcorr, zbvb, zbvn, zssh1, zhv1
+      REAL(wp), DIMENSION(jpi,jpj,jpk)      :: ztmask0, zwmaskn, ztrp
+      REAL(wp), DIMENSION(jpi,jpj,jpk)      :: ztmask1, zwmaskb, ztmp3d
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts) :: zts0
       !!----------------------------------------------------------------------
-
-      !! allocate variables
-      CALL wrk_alloc(jpi,jpj,jpk,2, zts0                                   )
-      CALL wrk_alloc(jpi,jpj,jpk,   ztmask0, ztmask1 , ztrp, ztmp3d        ) 
-      CALL wrk_alloc(jpi,jpj,jpk,   zwmaskn, zwmaskb                       ) 
-      CALL wrk_alloc(jpi,jpj,       zsmask0, zsmask1                       ) 
-      CALL wrk_alloc(jpi,jpj,       zdmask , zdsmask, zvcorr, zucorr, zde3t) 
-      CALL wrk_alloc(jpi,jpj,       zbub   , zbvb    , zbun , zbvn         ) 
-      CALL wrk_alloc(jpi,jpj,       zssh0  , zssh1, zhu1, zhv1             ) 
-
-      !! mask value to be sure
+      !
+      !                 ! mask value to be sure
       tsn(:,:,:,jp_tem) = tsn(:,:,:,jp_tem) * ptmask_b(:,:,:)
       tsn(:,:,:,jp_sal) = tsn(:,:,:,jp_sal) * ptmask_b(:,:,:)
-      
-      ! compute wmask
+      !
+      !                 ! compute wmask
       zwmaskn(:,:,1) = tmask   (:,:,1)
       zwmaskb(:,:,1) = ptmask_b(:,:,1)
@@ -179,11 +153,11 @@
          zwmaskb(:,:,jk) = ptmask_b(:,:,jk) * ptmask_b(:,:,jk-1)
       END DO
-           
-      ! compute new ssh if we open a full water column (average of the closest neigbourgs)  
+      !    
+      !                 ! compute new ssh if we open a full water column (average of the closest neigbourgs)  
       sshb (:,:)=sshn(:,:)
       zssh0(:,:)=sshn(:,:)
       zsmask0(:,:) = psmask_b(:,:)
       zsmask1(:,:) = psmask_b(:,:)
-      DO iz = 1,10    ! need to be tuned (configuration dependent) (OK for ISOMIP+)
+      DO iz = 1, 10                 ! need to be tuned (configuration dependent) (OK for ISOMIP+)
          zdsmask(:,:) = ssmask(:,:)-zsmask0(:,:)
          DO jj = 2,jpj-1
@@ -198,9 +172,9 @@
                   &           + zssh0(ji,jjm1)*zsmask0(ji,jjm1))/summsk
                   zsmask1(ji,jj)=1._wp
-               END IF
+               ENDIF
             END DO
          END DO
-         CALL lbc_lnk(sshn,'T',1._wp)
-         CALL lbc_lnk(zsmask1,'T',1._wp)
+         CALL lbc_lnk( sshn   , 'T', 1._wp )
+         CALL lbc_lnk( zsmask1, 'T', 1._wp )
          zssh0   = sshn
          zsmask0 = zsmask1
@@ -210,5 +184,5 @@
 !=============================================================================
 !PM: Is this needed since introduction of VVL by default?
-      IF (.NOT.ln_linssh) THEN
+      IF ( .NOT.ln_linssh ) THEN
       ! Reconstruction of all vertical scale factors at now time steps
       ! =============================================================================
@@ -225,17 +199,17 @@
             END DO
          END DO
-
+         !
          CALL dom_vvl_interpol( e3t_n(:,:,:), e3u_n(:,:,:), 'U' )
          CALL dom_vvl_interpol( e3t_n(:,:,:), e3v_n(:,:,:), 'V' )
          CALL dom_vvl_interpol( e3u_n(:,:,:), e3f_n(:,:,:), 'F' )
 
-      ! Vertical scale factor interpolations
-      ! ------------------------------------
+         ! Vertical scale factor interpolations
+         ! ------------------------------------
          CALL dom_vvl_interpol( e3t_n(:,:,:), e3w_n (:,:,:), 'W'  )
          CALL dom_vvl_interpol( e3u_n(:,:,:), e3uw_n(:,:,:), 'UW' )
          CALL dom_vvl_interpol( e3v_n(:,:,:), e3vw_n(:,:,:), 'VW' )
-
-      ! t- and w- points depth
-      ! ----------------------
+         
+         ! t- and w- points depth
+         ! ----------------------
          gdept_n(:,:,1) = 0.5_wp * e3w_n(:,:,1)
          gdepw_n(:,:,1) = 0.0_wp
@@ -431,13 +405,4 @@
       ! nothing to do
       ! 
-      ! deallocation tmp arrays
-      CALL wrk_dealloc(jpi,jpj,jpk,2, zts0                                   )
-      CALL wrk_dealloc(jpi,jpj,jpk,   ztmask0, ztmask1 , ztrp                ) 
-      CALL wrk_dealloc(jpi,jpj,jpk,   zwmaskn, zwmaskb , ztmp3d              ) 
-      CALL wrk_dealloc(jpi,jpj,       zsmask0, zsmask1                       ) 
-      CALL wrk_dealloc(jpi,jpj,       zdmask , zdsmask, zvcorr, zucorr, zde3t) 
-      CALL wrk_dealloc(jpi,jpj,       zbub   , zbvb    , zbun  , zbvn        ) 
-      CALL wrk_dealloc(jpi,jpj,       zssh0  , zssh1  , zhu1 , zhv1          ) 
-      !
    END SUBROUTINE iscpl_rst_interpol
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/istate.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/istate.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/istate.F90	(revision 9019)
@@ -36,5 +36,4 @@
    USE lib_mpp         ! MPP library
    USE restart         ! restart
-   USE wrk_nemo        ! Memory allocation
    USE timing          ! Timing
 
@@ -60,8 +59,10 @@
       !!----------------------------------------------------------------------
       INTEGER ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   zuvd    ! U & V data workspace
+!!gm see comment further down
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) ::   zuvd    ! U & V data workspace
+!!gm end
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start('istate_init')
+      IF( ln_timing )   CALL timing_start('istate_init')
       !
       IF(lwp) WRITE(numout,*)
@@ -121,9 +122,9 @@
 !!gm to be moved in usrdef of C1D case
 !         IF ( ln_uvd_init .AND. lk_c1d ) THEN ! read 3D U and V data at nit000
-!            CALL wrk_alloc( jpi,jpj,jpk,2,   zuvd )
+!            ALLOCATE( zuvd(jpi,jpj,jpk,2) )
 !            CALL dta_uvd( nit000, zuvd )
 !            ub(:,:,:) = zuvd(:,:,:,1) ;  un(:,:,:) = ub(:,:,:)
 !            vb(:,:,:) = zuvd(:,:,:,2) ;  vn(:,:,:) = vb(:,:,:)
-!            CALL wrk_dealloc( jpi,jpj,jpk,2,   zuvd )
+!            DEALLOCATE( zuvd )
 !         ENDIF
          !
@@ -164,5 +165,5 @@
       vb_b(:,:) = vb_b(:,:) * r1_hv_b(:,:)
       !
-      IF( nn_timing == 1 )   CALL timing_stop('istate_init')
+      IF( ln_timing )   CALL timing_stop('istate_init')
       !
    END SUBROUTINE istate_init
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/phycst.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/phycst.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DOM/phycst.F90	(revision 9019)
@@ -54,4 +54,5 @@
 
    REAL(wp), PUBLIC ::   rhosn    =  330._wp         !: volumic mass of snow          [kg/m3]
+   REAL(wp), PUBLIC ::   rhofw    = 1000._wp         !: volumic mass of freshwater in melt ponds [kg/m3]
    REAL(wp), PUBLIC ::   emic     =    0.97_wp       !: emissivity of snow or ice
    REAL(wp), PUBLIC ::   sice     =    6.0_wp        !: salinity of ice               [psu]
@@ -88,4 +89,5 @@
    REAL(wp), PUBLIC ::   r1_rhoic                    !: 1 / rhoic
    REAL(wp), PUBLIC ::   r1_rhosn                    !: 1 / rhosn
+   REAL(wp), PUBLIC ::   r1_cpic                     !: 1 / cpic
 #endif
    !!----------------------------------------------------------------------
@@ -156,4 +158,5 @@
       r1_rhoic = 1._wp / rhoic
       r1_rhosn = 1._wp / rhosn
+      r1_cpic  = 1._wp / cpic
 #endif
       IF(lwp) THEN
@@ -176,4 +179,5 @@
          WRITE(numout,*) '          density of sea ice                        = ', rhoic   , ' kg/m^3'
          WRITE(numout,*) '          density of snow                           = ', rhosn   , ' kg/m^3'
+         WRITE(numout,*) '          density of freshwater (in melt ponds)     = ', rhofw   , ' kg/m^3'
          WRITE(numout,*) '          emissivity of snow or ice                 = ', emic  
          WRITE(numout,*) '          salinity of ice                           = ', sice    , ' psu'
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/divhor.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/divhor.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/divhor.F90	(revision 9019)
@@ -29,5 +29,4 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! Memory Allocation
    USE timing          ! Timing
 
@@ -40,5 +39,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -64,5 +63,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start('div_hor')
+      IF( ln_timing )   CALL timing_start('div_hor')
       !
       IF( kt == nit000 ) THEN
@@ -75,28 +74,30 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               hdivn(ji,jj,jk) = (  e2u(ji  ,jj) * e3u_n(ji  ,jj,jk) * un(ji  ,jj,jk)        &
-                  &               - e2u(ji-1,jj) * e3u_n(ji-1,jj,jk) * un(ji-1,jj,jk)        &
-                  &               + e1v(ji,jj  ) * e3v_n(ji,jj  ,jk) * vn(ji,jj  ,jk)        &
-                  &               - e1v(ji,jj-1) * e3v_n(ji,jj-1,jk) * vn(ji,jj-1,jk)   )    &
-                  &            / ( e1e2t(ji,jj) * e3t_n(ji,jj,jk) )
+               hdivn(ji,jj,jk) = (  e2u(ji  ,jj) * e3u_n(ji  ,jj,jk) * un(ji  ,jj,jk)      &
+                  &               - e2u(ji-1,jj) * e3u_n(ji-1,jj,jk) * un(ji-1,jj,jk)      &
+                  &               + e1v(ji,jj  ) * e3v_n(ji,jj  ,jk) * vn(ji,jj  ,jk)      &
+                  &               - e1v(ji,jj-1) * e3v_n(ji,jj-1,jk) * vn(ji,jj-1,jk)  )   &
+                  &            * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
             END DO  
          END DO  
-         IF( .NOT. AGRIF_Root() ) THEN
-            IF( nbondi ==  1 .OR. nbondi == 2 )   hdivn(nlci-1,   :  ,jk) = 0._wp      ! east
-            IF( nbondi == -1 .OR. nbondi == 2 )   hdivn(  2   ,   :  ,jk) = 0._wp      ! west
-            IF( nbondj ==  1 .OR. nbondj == 2 )   hdivn(  :   ,nlcj-1,jk) = 0._wp      ! north
-            IF( nbondj == -1 .OR. nbondj == 2 )   hdivn(  :   ,  2   ,jk) = 0._wp      ! south
-         ENDIF
       END DO
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() ) THEN
+         IF( nbondi == -1 .OR. nbondi == 2 )   hdivn( 2:nbghostcells+1,:        ,:) = 0._wp      ! west
+         IF( nbondi ==  1 .OR. nbondi == 2 )   hdivn( nlci-nbghostcells:nlci-1,:,:) = 0._wp      ! east
+         IF( nbondj == -1 .OR. nbondj == 2 )   hdivn( :,2:nbghostcells+1        ,:) = 0._wp      ! south
+         IF( nbondj ==  1 .OR. nbondj == 2 )   hdivn( :,nlcj-nbghostcells:nlcj-1,:) = 0._wp      ! north
+      ENDIF
+#endif
       !
-      IF( ln_rnf )   CALL sbc_rnf_div( hdivn )      !==  runoffs    ==!   (update hdivn field)
+      IF( ln_rnf )   CALL sbc_rnf_div( hdivn )              !==  runoffs    ==!   (update hdivn field)
       !
-      IF( ln_isf )   CALL sbc_isf_div( hdivn )      !==  ice shelf  ==!   (update hdivn field)
+      IF( ln_isf )   CALL sbc_isf_div( hdivn )              !==  ice shelf  ==!   (update hdivn field)
       !
-      IF( ln_iscpl .AND. ln_hsb ) CALL iscpl_div( hdivn )  !==  ice sheet  ==!   (update hdivn field)
+      IF( ln_iscpl .AND. ln_hsb )   CALL iscpl_div( hdivn ) !==  ice sheet  ==!   (update hdivn field)
       !
-      CALL lbc_lnk( hdivn, 'T', 1. )                !==  lateral boundary cond.  ==!   (no sign change)
+      CALL lbc_lnk( hdivn, 'T', 1. )   !   (no sign change)
       !
-      IF( nn_timing == 1 )  CALL timing_stop('div_hor')
+      IF( ln_timing )   CALL timing_stop('div_hor')
       !
    END SUBROUTINE div_hor
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv.F90	(revision 9019)
@@ -7,4 +7,5 @@
    !!            3.3  !  2010-10  (C. Ethe, G. Madec)  reorganisation of initialisation phase
    !!            3.6  !  2015-05  (N. Ducousso, G. Madec)  add Hollingsworth scheme as an option 
+   !!            4.0  !  2017-07  (G. Madec)  add a linear dynamics option
    !!----------------------------------------------------------------------
 
@@ -30,16 +31,21 @@
  
    !                                    !* namdyn_adv namelist *
-   LOGICAL, PUBLIC ::   ln_dynadv_vec   !: vector form flag
-   INTEGER, PUBLIC ::   nn_dynkeg       !: scheme of kinetic energy gradient: =0 C2 ; =1 Hollingsworth
+   LOGICAL, PUBLIC ::   ln_dynadv_NONE  !: linear dynamics (no momentum advection)
+   LOGICAL, PUBLIC ::   ln_dynadv_vec   !: vector form
+   INTEGER, PUBLIC ::      nn_dynkeg       !: scheme of grad(KE): =0 C2 ; =1 Hollingsworth
    LOGICAL, PUBLIC ::   ln_dynadv_cen2  !: flux form - 2nd order centered scheme flag
    LOGICAL, PUBLIC ::   ln_dynadv_ubs   !: flux form - 3rd order UBS scheme flag
-   LOGICAL, PUBLIC ::   ln_dynzad_zts   !: vertical advection with sub-timestepping (requires vector form)
    
-   INTEGER ::   nadv   ! choice of the formulation and scheme for the advection
+   INTEGER, PUBLIC ::   n_dynadv   !: choice of the formulation and scheme for momentum advection
+   !                               !  associated indices:
+   INTEGER, PUBLIC, PARAMETER ::   np_LIN_dyn = 0   ! no advection: linear dynamics
+   INTEGER, PUBLIC, PARAMETER ::   np_VEC_c2  = 1   ! vector form : 2nd order centered scheme
+   INTEGER, PUBLIC, PARAMETER ::   np_FLX_c2  = 2   ! flux   form : 2nd order centered scheme
+   INTEGER, PUBLIC, PARAMETER ::   np_FLX_ubs = 3   ! flux   form : 3rd order Upstream Biased Scheme
 
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.6 , NEMO Consortium (2015)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -53,5 +59,6 @@
       !! ** Purpose :   compute the ocean momentum advection trend.
       !!
-      !! ** Method  : - Update (ua,va) with the advection term following nadv
+      !! ** Method  : - Update (ua,va) with the advection term following n_dynadv
+      !!
       !!      NB: in flux form advection (ln_dynadv_cen2 or ln_dynadv_ubs=T) 
       !!      a metric term is add to the coriolis term while in vector form 
@@ -62,20 +69,17 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_adv')
+      IF( ln_timing )   CALL timing_start( 'dyn_adv' )
       !
-      SELECT CASE ( nadv )                  ! compute advection trend and add it to general trend
-      CASE ( 0 )     
-                      CALL dyn_keg     ( kt, nn_dynkeg )    ! vector form : horizontal gradient of kinetic energy
-                      CALL dyn_zad     ( kt )               ! vector form : vertical advection
-      CASE ( 1 )     
-                      CALL dyn_keg     ( kt, nn_dynkeg )    ! vector form : horizontal gradient of kinetic energy
-                      CALL dyn_zad_zts ( kt )               ! vector form : vertical advection with sub-timestepping
-      CASE ( 2 ) 
-                      CALL dyn_adv_cen2( kt )               ! 2nd order centered scheme
-      CASE ( 3 )   
-                      CALL dyn_adv_ubs ( kt )               ! 3rd order UBS      scheme
+      SELECT CASE( n_dynadv )    !==  compute advection trend and add it to general trend  ==!
+      CASE( np_VEC_c2  )     
+         CALL dyn_keg     ( kt, nn_dynkeg )    ! vector form : horizontal gradient of kinetic energy
+         CALL dyn_zad     ( kt )               ! vector form : vertical advection
+      CASE( np_FLX_c2  ) 
+         CALL dyn_adv_cen2( kt )               ! 2nd order centered scheme
+      CASE( np_FLX_ubs )   
+         CALL dyn_adv_ubs ( kt )               ! 3rd order UBS      scheme (UP3)
       END SELECT
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_adv')
+      IF( ln_timing )   CALL timing_stop( 'dyn_adv' )
       !
    END SUBROUTINE dyn_adv
@@ -87,9 +91,9 @@
       !!                
       !! ** Purpose :   Control the consistency between namelist options for 
-      !!              momentum advection formulation & scheme and set nadv
+      !!              momentum advection formulation & scheme and set n_dynadv
       !!----------------------------------------------------------------------
       INTEGER ::   ioptio, ios   ! Local integer
       !
-      NAMELIST/namdyn_adv/ ln_dynadv_vec, nn_dynkeg, ln_dynadv_cen2 , ln_dynadv_ubs, ln_dynzad_zts
+      NAMELIST/namdyn_adv/ ln_dynadv_NONE, ln_dynadv_vec, nn_dynkeg, ln_dynadv_cen2, ln_dynadv_ubs
       !!----------------------------------------------------------------------
       !
@@ -108,38 +112,31 @@
          WRITE(numout,*) '~~~~~~~~~~~~'
          WRITE(numout,*) '   Namelist namdyn_adv : chose a advection formulation & scheme for momentum'
-         WRITE(numout,*) '      Vector/flux form (T/F)                           ln_dynadv_vec  = ', ln_dynadv_vec
-         WRITE(numout,*) '      = 0 standard scheme  ; =1 Hollingsworth scheme   nn_dynkeg      = ', nn_dynkeg
-         WRITE(numout,*) '      2nd order centred advection scheme               ln_dynadv_cen2 = ', ln_dynadv_cen2
-         WRITE(numout,*) '      3rd order UBS advection scheme                   ln_dynadv_ubs  = ', ln_dynadv_ubs
-         WRITE(numout,*) '      Sub timestepping of vertical advection           ln_dynzad_zts  = ', ln_dynzad_zts
+         WRITE(numout,*) '      linear dynamics : no momentum advection          ln_dynadv_NONE = ', ln_dynadv_NONE
+         WRITE(numout,*) '      Vector form: 2nd order centered scheme           ln_dynadv_vec  = ', ln_dynadv_vec
+         WRITE(numout,*) '         with Hollingsworth scheme (=1) or not (=0)       nn_dynkeg   = ', nn_dynkeg
+         WRITE(numout,*) '      flux form: 2nd order centred scheme              ln_dynadv_cen2 = ', ln_dynadv_cen2
+         WRITE(numout,*) '                 3rd order UBS scheme                  ln_dynadv_ubs  = ', ln_dynadv_ubs
       ENDIF
 
-      ioptio = 0                      ! Parameter control
-      IF( ln_dynadv_vec  )   ioptio = ioptio + 1
-      IF( ln_dynadv_cen2 )   ioptio = ioptio + 1
-      IF( ln_dynadv_ubs  )   ioptio = ioptio + 1
+      ioptio = 0                      ! parameter control and set n_dynadv
+      IF( ln_dynadv_NONE ) THEN   ;   ioptio = ioptio + 1   ;   n_dynadv = np_LIN_dyn   ;   ENDIF
+      IF( ln_dynadv_vec  ) THEN   ;   ioptio = ioptio + 1   ;   n_dynadv = np_VEC_c2    ;   ENDIF
+      IF( ln_dynadv_cen2 ) THEN   ;   ioptio = ioptio + 1   ;   n_dynadv = np_FLX_c2    ;   ENDIF
+      IF( ln_dynadv_ubs  ) THEN   ;   ioptio = ioptio + 1   ;   n_dynadv = np_FLX_ubs   ;   ENDIF
 
-      IF( ioptio /= 1 )   CALL ctl_stop( 'Choose ONE advection scheme in namelist namdyn_adv' )
-      IF( ln_dynzad_zts .AND. .NOT. ln_dynadv_vec )   &
-         CALL ctl_stop( 'Sub timestepping of vertical advection requires vector form; set ln_dynadv_vec = .TRUE.' )
-      IF( nn_dynkeg /= nkeg_C2 .AND. nn_dynkeg /= nkeg_HW )   &  
-         CALL ctl_stop( 'KEG scheme wrong value of nn_dynkeg' )
+      IF( ioptio /= 1 )   CALL ctl_stop( 'choose ONE and only ONE advection scheme' )
+      IF( nn_dynkeg /= nkeg_C2 .AND. nn_dynkeg /= nkeg_HW )   CALL ctl_stop( 'KEG scheme wrong value of nn_dynkeg' )
 
-      !                               ! Set nadv
-      IF( ln_dynadv_vec  )   nadv =  0 
-      IF( ln_dynzad_zts  )   nadv =  1
-      IF( ln_dynadv_cen2 )   nadv =  2
-      IF( ln_dynadv_ubs  )   nadv =  3
 
       IF(lwp) THEN                    ! Print the choice
          WRITE(numout,*)
-         IF( nadv ==  0 )   WRITE(numout,*) '      ===>>   vector form : keg + zad + vor is used' 
-         IF( nadv ==  1 )   WRITE(numout,*) '      ===>>   vector form : keg + zad_zts + vor is used'
-         IF( nadv ==  0 .OR. nadv ==  1 ) THEN
+         SELECT CASE( n_dynadv )
+         CASE( np_LIN_dyn )   ;   WRITE(numout,*) '      ===>>   linear dynamics : no momentum advection used'
+         CASE( np_VEC_c2  )   ;   WRITE(numout,*) '      ===>>   vector form : keg + zad + vor is used' 
             IF( nn_dynkeg == nkeg_C2  )   WRITE(numout,*) '              with Centered standard keg scheme'
             IF( nn_dynkeg == nkeg_HW  )   WRITE(numout,*) '              with Hollingsworth keg scheme'
-         ENDIF
-         IF( nadv ==  2 )   WRITE(numout,*) '      ===>>   flux form   : 2nd order scheme is used'
-         IF( nadv ==  3 )   WRITE(numout,*) '      ===>>   flux form   : UBS       scheme is used'
+         CASE( np_FLX_c2  )   ;   WRITE(numout,*) '      ===>>   flux form   : 2nd order scheme is used'
+         CASE( np_FLX_ubs )   ;   WRITE(numout,*) '      ===>>   flux form   : UBS       scheme is used'
+         END SELECT
       ENDIF
       !
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_cen2.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_cen2.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_cen2.F90	(revision 9019)
@@ -20,5 +20,4 @@
    USE lib_mpp        ! MPP library
    USE prtctl         ! Print control
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
 
@@ -31,5 +30,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -51,11 +50,9 @@
       !
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zfu_t, zfv_t, zfu_f, zfv_f, zfu_uw, zfv_vw, zfw
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zfu, zfv
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  zfu_t, zfu_f, zfu_uw, zfu
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  zfv_t, zfv_f, zfv_vw, zfv, zfw
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_adv_cen2')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   zfu_t, zfv_t, zfu_f, zfv_f, zfu_uw, zfv_vw, zfu, zfv, zfw )
+      IF( ln_timing )   CALL timing_start('dyn_adv_cen2')
       !
       IF( kt == nit000 .AND. lwp ) THEN
@@ -148,7 +145,5 @@
          &                       tab3d_2=va, clinfo2=           ' Va: ', mask2=vmask, clinfo3='dyn' )
       !
-      CALL wrk_dealloc( jpi, jpj, jpk, zfu_t, zfv_t, zfu_f, zfv_f, zfu_uw, zfv_vw, zfu, zfv, zfw )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_adv_cen2')
+      IF( ln_timing )   CALL timing_stop('dyn_adv_cen2')
       !
    END SUBROUTINE dyn_adv_cen2
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_ubs.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_ubs.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynadv_ubs.F90	(revision 9019)
@@ -23,5 +23,4 @@
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
 
@@ -37,5 +36,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -74,13 +73,11 @@
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
       REAL(wp) ::   zui, zvj, zfuj, zfvi, zl_u, zl_v   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:  ) ::  zfu, zfv
-      REAL(wp), POINTER, DIMENSION(:,:,:  ) ::  zfu_t, zfv_t, zfu_f, zfv_f, zfu_uw, zfv_vw, zfw
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::  zlu_uu, zlv_vv, zlu_uv, zlv_vu
+      REAL(wp), DIMENSION(jpi,jpj,jpk)   ::   zfu_t, zfu_f, zfu_uw, zfu
+      REAL(wp), DIMENSION(jpi,jpj,jpk)   ::   zfv_t, zfv_f, zfv_vw, zfv, zfw
+      REAL(wp), DIMENSION(jpi,jpj,jpk,2) ::   zlu_uu, zlu_uv
+      REAL(wp), DIMENSION(jpi,jpj,jpk,2) ::   zlv_vv, zlv_vu
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_adv_ubs')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,        zfu_t , zfv_t , zfu_f , zfv_f, zfu_uw, zfv_vw, zfu, zfv, zfw )
-      CALL wrk_alloc( jpi,jpj,jpk,jpts,   zlu_uu, zlv_vv, zlu_uv, zlv_vu                               )
+      IF( ln_timing )   CALL timing_start('dyn_adv_ubs')
       !
       IF( kt == nit000 ) THEN
@@ -241,8 +238,5 @@
          &                       tab3d_2=va, clinfo2=           ' Va: ', mask2=vmask, clinfo3='dyn' )
       !
-      CALL wrk_dealloc( jpi,jpj,jpk,        zfu_t , zfv_t , zfu_f , zfv_f, zfu_uw, zfv_vw, zfu, zfv, zfw )
-      CALL wrk_dealloc( jpi,jpj,jpk,jpts,   zlu_uu, zlv_vv, zlu_uv, zlv_vu                               )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_adv_ubs')
+      IF( ln_timing )   CALL timing_stop('dyn_adv_ubs')
       !
    END SUBROUTINE dyn_adv_ubs
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynbfr.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynbfr.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynbfr.F90	(revision 9019)
@@ -5,6 +5,6 @@
    !!==============================================================================
    !! History :  3.2  ! 2008-11  (A. C. Coward)  Original code
-   !!            3.4  ! 2011-09  (H. Liu) Make it consistent with semi-implicit
-   !!                            Bottom friction (ln_bfrimp = .true.) 
+   !!            3.4  ! 2011-09  (H. Liu) Make it consistent with semi-implicit Bottom friction (ln_drgimp =T) 
+   !!            4.0  ! 2017-05  (G. Madec)  drag coef. defined at t-point (zdfdrg.F90)
    !!----------------------------------------------------------------------
 
@@ -14,12 +14,12 @@
    USE oce            ! ocean dynamics and tracers variables
    USE dom_oce        ! ocean space and time domain variables 
-   USE zdf_oce        ! ocean vertical physics variables
-   USE zdfbfr         ! ocean bottom friction variables
+   USE zdf_oce        ! vertical physics: variables
+   USE zdfdrg         ! vertical physics: top/bottom drag coef.
    USE trd_oce        ! trends: ocean variables
    USE trddyn         ! trend manager: dynamics
+   !
    USE in_out_manager ! I/O manager
    USE prtctl         ! Print control
    USE timing         ! Timing
-   USE wrk_nemo       ! Memory Allocation
 
    IMPLICIT NONE
@@ -31,5 +31,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -43,4 +43,7 @@
       !! ** Purpose :   compute the bottom friction ocean dynamics physics.
       !!
+      !!              only for explicit bottom friction form
+      !!              implicit bfr is implemented in dynzdf_imp
+      !!
       !! ** Action  :   (ua,va)   momentum trend increased by bottom friction trend
       !!---------------------------------------------------------------------
@@ -50,65 +53,61 @@
       INTEGER  ::   ikbu, ikbv   ! local integers
       REAL(wp) ::   zm1_2dt      ! local scalar
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrdu, ztrdv
+      REAL(wp) ::   zCdu, zCdv   !   -      -
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ztrdu, ztrdv
       !!---------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_bfr')
+      IF( ln_timing )   CALL timing_start('dyn_bfr')
       !
-!!gm issue: better to put the logical in step to control the call of zdf_bfr
-!!          ==> change the logical from ln_bfrimp to ln_bfr_exp !!
-      IF( .NOT.ln_bfrimp) THEN     ! only for explicit bottom friction form
-                                    ! implicit bfr is implemented in dynzdf_imp
+!!gm bug : time step is only rdt (not 2 rdt if euler start !)
+         zm1_2dt = - 1._wp / ( 2._wp * rdt )
 
-!!gm bug : time step is only rdt (not 2 rdt if euler start !)
-        zm1_2dt = - 1._wp / ( 2._wp * rdt )
-
-        IF( l_trddyn ) THEN      ! trends: store the input trends
-           CALL wrk_alloc( jpi,jpj,jpk,   ztrdu, ztrdv )
-           ztrdu(:,:,:) = ua(:,:,:)
-           ztrdv(:,:,:) = va(:,:,:)
-        ENDIF
+      IF( l_trddyn ) THEN      ! trends: store the input trends
+         ALLOCATE( ztrdu(jpi,jpj,jpk) , ztrdv(jpi,jpj,jpk) )
+         ztrdu(:,:,:) = ua(:,:,:)
+            ztrdv(:,:,:) = va(:,:,:)
+      ENDIF
 
 
-        DO jj = 2, jpjm1
-           DO ji = 2, jpim1
-              ikbu = mbku(ji,jj)          ! deepest ocean u- & v-levels
-              ikbv = mbkv(ji,jj)
-              !
-              ! Apply stability criteria on absolute value  : abs(bfr/e3) < 1/(2dt) => bfr/e3 > -1/(2dt)
-              ua(ji,jj,ikbu) = ua(ji,jj,ikbu) + MAX(  bfrua(ji,jj) / e3u_n(ji,jj,ikbu) , zm1_2dt  ) * ub(ji,jj,ikbu)
-              va(ji,jj,ikbv) = va(ji,jj,ikbv) + MAX(  bfrva(ji,jj) / e3v_n(ji,jj,ikbv) , zm1_2dt  ) * vb(ji,jj,ikbv)
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            ikbu = mbku(ji,jj)          ! deepest wet ocean u- & v-levels
+            ikbv = mbkv(ji,jj)
+            !
+            ! Apply stability criteria on absolute value  : abs(bfr/e3) < 1/(2dt) => bfr/e3 > -1/(2dt)
+            zCdu = 0.5*( rCdU_bot(ji+1,jj)+rCdU_bot(ji,jj) ) / e3u_n(ji,jj,ikbu)
+            zCdv = 0.5*( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj) ) / e3v_n(ji,jj,ikbv)
+            !
+            ua(ji,jj,ikbu) = ua(ji,jj,ikbu) + MAX(  zCdu , zm1_2dt  ) * ub(ji,jj,ikbu)
+            va(ji,jj,ikbv) = va(ji,jj,ikbv) + MAX(  zCdv , zm1_2dt  ) * vb(ji,jj,ikbv)
+         END DO
+      END DO
+      !
+      IF( ln_isfcav ) THEN        ! ocean cavities
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               ikbu = miku(ji,jj)          ! first wet ocean u- & v-levels
+               ikbv = mikv(ji,jj)
+               !
+               ! Apply stability criteria on absolute value  : abs(bfr/e3) < 1/(2dt) => bfr/e3 > -1/(2dt)
+               zCdu = 0.5*( rCdU_top(ji+1,jj)+rCdU_top(ji,jj) ) / e3u_n(ji,jj,ikbu)    ! NB: Cdtop masked
+               zCdv = 0.5*( rCdU_top(ji,jj+1)+rCdU_top(ji,jj) ) / e3v_n(ji,jj,ikbv)
+               !
+               ua(ji,jj,ikbu) = ua(ji,jj,ikbu) + MAX(  zCdu , zm1_2dt  ) * ub(ji,jj,ikbu)
+               va(ji,jj,ikbv) = va(ji,jj,ikbv) + MAX(  zCdv , zm1_2dt  ) * vb(ji,jj,ikbv)
            END DO
-        END DO
-        !
-        IF( ln_isfcav ) THEN        ! ocean cavities
-           DO jj = 2, jpjm1
-              DO ji = 2, jpim1
-                 ! (ISF) stability criteria for top friction
-                 ikbu = miku(ji,jj)          ! first wet ocean u- & v-levels
-                 ikbv = mikv(ji,jj)
-                 !
-                 ! Apply stability criteria on absolute value  : abs(bfr/e3) < 1/(2dt) => bfr/e3 > -1/(2dt)
-                 ua(ji,jj,ikbu) = ua(ji,jj,ikbu) + MAX(  tfrua(ji,jj) / e3u_n(ji,jj,ikbu) , zm1_2dt  ) * ub(ji,jj,ikbu) &
-                    &             * (1.-umask(ji,jj,1))
-                 va(ji,jj,ikbv) = va(ji,jj,ikbv) + MAX(  tfrva(ji,jj) / e3v_n(ji,jj,ikbv) , zm1_2dt  ) * vb(ji,jj,ikbv) &
-                    &             * (1.-vmask(ji,jj,1))
-                 ! (ISF)
-              END DO
-           END DO
-        END IF
-        !
-        IF( l_trddyn ) THEN      ! trends: send trends to trddyn for further diagnostics
-           ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
-           ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-           CALL trd_dyn( ztrdu(:,:,:), ztrdv(:,:,:), jpdyn_bfr, kt )
-           CALL wrk_dealloc( jpi,jpj,jpk,   ztrdu, ztrdv )
-        ENDIF
-        !                                          ! print mean trends (used for debugging)
-        IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' bfr  - Ua: ', mask1=umask,               &
-           &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-        !
-      ENDIF     ! end explicit bottom friction
+         END DO
+      ENDIF
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_bfr')
+      IF( l_trddyn ) THEN      ! trends: send trends to trddyn for further diagnostics
+         ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+         ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+         CALL trd_dyn( ztrdu(:,:,:), ztrdv(:,:,:), jpdyn_bfr, kt )
+         DEALLOCATE( ztrdu, ztrdv )
+      ENDIF
+      !                                          ! print mean trends (used for debugging)
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' bfr  - Ua: ', mask1=umask,               &
+         &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
+      !
+      IF( ln_timing )   CALL timing_stop('dyn_bfr')
       !
    END SUBROUTINE dyn_bfr
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 9019)
@@ -44,5 +44,4 @@
    USE lib_mpp         ! MPP library
    USE eosbn2          ! compute density
-   USE wrk_nemo        ! Memory Allocation
    USE timing          ! Timing
    USE iom
@@ -84,11 +83,11 @@
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrdu, ztrdv
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_hpg')
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrdu, ztrdv
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('dyn_hpg')
       !
       IF( l_trddyn ) THEN                    ! Temporary saving of ua and va trends (l_trddyn)
-         CALL wrk_alloc( jpi,jpj,jpk, ztrdu, ztrdv )
+         ALLOCATE( ztrdu(jpi,jpj,jpk) , ztrdv(jpi,jpj,jpk) )
          ztrdu(:,:,:) = ua(:,:,:)
          ztrdv(:,:,:) = va(:,:,:)
@@ -108,5 +107,5 @@
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
          CALL trd_dyn( ztrdu, ztrdv, jpdyn_hpg, kt )
-         CALL wrk_dealloc( jpi,jpj,jpk, ztrdu, ztrdv )
+         DEALLOCATE( ztrdu , ztrdv )
       ENDIF
       !
@@ -114,5 +113,5 @@
          &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_hpg')
+      IF( ln_timing )   CALL timing_stop('dyn_hpg')
       !
    END SUBROUTINE dyn_hpg
@@ -134,7 +133,7 @@
       INTEGER  ::   ji, jj, jk, ikt    ! dummy loop indices      ISF
       REAL(wp) ::   znad
-      REAL(wp), POINTER, DIMENSION(:,:,:)   ::  ztstop, zrhd ! hypothesys on isf density
-      REAL(wp), POINTER, DIMENSION(:,:)     ::  zrhdtop_isf  ! density at bottom of ISF
-      REAL(wp), POINTER, DIMENSION(:,:)     ::  ziceload     ! density at bottom of ISF
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::  zts_top, zrhd   ! hypothesys on isf density
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:)   ::  zrhdtop_isf    ! density at bottom of ISF
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:)   ::  ziceload       ! density at bottom of ISF
       !!
       NAMELIST/namdyn_hpg/ ln_hpg_zco, ln_hpg_zps, ln_hpg_sco,     &
@@ -165,17 +164,18 @@
       !
       IF( ln_hpg_djc )   &
-         &   CALL ctl_stop('dyn_hpg_init : Density Jacobian: Cubic polynominal method &
-                           & currently disabled (bugs under investigation). Please select &
-                           & either  ln_hpg_sco or  ln_hpg_prj instead')
-      !
-      IF( .NOT.ln_linssh .AND. .NOT.(ln_hpg_sco.OR.ln_hpg_prj.OR.ln_hpg_isf) )        &
-         &   CALL ctl_stop('dyn_hpg_init : non-linear free surface requires either ', &
-         &                 '   the standard jacobian formulation hpg_sco    or '    , &
-         &                 '   the pressure jacobian formulation hpg_prj'            )
-
-      IF(       ln_hpg_isf .AND. .NOT. ln_isfcav )   &
-         &   CALL ctl_stop( ' hpg_isf not available if ln_isfcav = false ' )
-      IF( .NOT. ln_hpg_isf .AND.       ln_isfcav )   &
-         &   CALL ctl_stop( 'Only hpg_isf has been corrected to work with ice shelf cavity.' )
+         &   CALL ctl_stop('dyn_hpg_init : Density Jacobian: Cubic polynominal method',   &
+         &                 '   currently disabled (bugs under investigation).'        ,   &
+         &                 '   Please select either  ln_hpg_sco or  ln_hpg_prj instead' )
+         !
+      IF( .NOT.ln_linssh .AND. .NOT.(ln_hpg_sco.OR.ln_hpg_prj.OR.ln_hpg_isf) )          &
+         &   CALL ctl_stop('dyn_hpg_init : non-linear free surface requires either ',   &
+         &                 '   the standard jacobian formulation hpg_sco    or '    ,   &
+         &                 '   the pressure jacobian formulation hpg_prj'             )
+         !
+      IF( ln_hpg_isf ) THEN
+         IF( .NOT. ln_isfcav )   CALL ctl_stop( ' hpg_isf not available if ln_isfcav = false ' )
+       ELSE
+         IF(       ln_isfcav )   CALL ctl_stop( 'Only hpg_isf has been corrected to work with ice shelf cavity.' )
+      ENDIF
       !
       !                               ! Set nhpg from ln_hpg_... flags
@@ -197,51 +197,44 @@
       IF( ioptio /= 1 )   CALL ctl_stop( 'NO or several hydrostatic pressure gradient options used' )
       ! 
-      ! initialisation of ice shelf load
-      IF ( .NOT. ln_isfcav ) riceload(:,:)=0.0
-      IF (       ln_isfcav ) THEN
-         CALL wrk_alloc( jpi,jpj, 2,  ztstop) 
-         CALL wrk_alloc( jpi,jpj,jpk, zrhd  )
-         CALL wrk_alloc( jpi,jpj,     zrhdtop_isf, ziceload) 
+      !                          
+      IF ( .NOT. ln_isfcav ) THEN     !--- no ice shelf load
+         riceload(:,:) = 0._wp
+         !
+      ELSE                            !--- set an ice shelf load
          !
          IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dyn:hpg_isf : hydrostatic pressure gradient trend for ice shelf'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'  
-
-         ! To use density and not density anomaly
-         znad=1._wp
-         
-         ! assume water displaced by the ice shelf is at T=-1.9 and S=34.4 (rude)
-         ztstop(:,:,1)=-1.9_wp ; ztstop(:,:,2)=34.4_wp
-
-         ! compute density of the water displaced by the ice shelf 
-         DO jk = 1, jpk
-            CALL eos(ztstop(:,:,:),gdept_n(:,:,jk),zrhd(:,:,jk))
-         END DO
-      
-         ! compute rhd at the ice/oce interface (ice shelf side)
-         CALL eos(ztstop,risfdep,zrhdtop_isf)
-
-         ! Surface value + ice shelf gradient
-         ! compute pressure due to ice shelf load (used to compute hpgi/j for all the level from 1 to miku/v)
-         ! divided by 2 later
-         ziceload = 0._wp
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               ikt=mikt(ji,jj)
+         IF(lwp) WRITE(numout,*) '   ice shelf case: set the ice-shelf load'
+         ALLOCATE( zts_top(jpi,jpj,jpts) , zrhd(jpi,jpj,jpk) , zrhdtop_isf(jpi,jpj) , ziceload(jpi,jpj) ) 
+         !
+         znad = 1._wp                     !- To use density and not density anomaly
+         !
+         !                                !- assume water displaced by the ice shelf is at T=-1.9 and S=34.4 (rude)
+         zts_top(:,:,jp_tem) = -1.9_wp   ;   zts_top(:,:,jp_sal) = 34.4_wp
+         !
+         DO jk = 1, jpk                   !- compute density of the water displaced by the ice shelf 
+            CALL eos( zts_top(:,:,:), gdept_n(:,:,jk), zrhd(:,:,jk) )
+         END DO
+         !
+         !                                !- compute rhd at the ice/oce interface (ice shelf side)
+         CALL eos( zts_top , risfdep, zrhdtop_isf )
+         !
+         !                                !- Surface value + ice shelf gradient
+         ziceload = 0._wp                       ! compute pressure due to ice shelf load 
+         DO jj = 1, jpj                         ! (used to compute hpgi/j for all the level from 1 to miku/v)
+            DO ji = 1, jpi                      ! divided by 2 later
+               ikt = mikt(ji,jj)
                ziceload(ji,jj) = ziceload(ji,jj) + (znad + zrhd(ji,jj,1) ) * e3w_n(ji,jj,1) * (1._wp - tmask(ji,jj,1))
-               DO jk=2,ikt-1
+               DO jk = 2, ikt-1
                   ziceload(ji,jj) = ziceload(ji,jj) + (2._wp * znad + zrhd(ji,jj,jk-1) + zrhd(ji,jj,jk)) * e3w_n(ji,jj,jk) &
                      &                              * (1._wp - tmask(ji,jj,jk))
                END DO
                IF (ikt  >=  2) ziceload(ji,jj) = ziceload(ji,jj) + (2._wp * znad + zrhdtop_isf(ji,jj) + zrhd(ji,jj,ikt-1)) &
-                                  &                              * ( risfdep(ji,jj) - gdept_1d(ikt-1) )
-            END DO
-         END DO
-         riceload(:,:)=ziceload(:,:)  ! need to be saved for diaar5
-
-         CALL wrk_dealloc( jpi,jpj, 2,  ztstop) 
-         CALL wrk_dealloc( jpi,jpj,jpk, zrhd  )
-         CALL wrk_dealloc( jpi,jpj,     zrhdtop_isf, ziceload) 
-      END IF
+                  &                                              * ( risfdep(ji,jj) - gdept_1d(ikt-1) )
+            END DO
+         END DO
+         riceload(:,:) = ziceload(:,:)  ! need to be saved for diaar5
+         !
+         DEALLOCATE( zts_top , zrhd , zrhdtop_isf , ziceload ) 
+      ENDIF
       !
    END SUBROUTINE dyn_hpg_init
@@ -268,8 +261,6 @@
       INTEGER  ::   ji, jj, jk       ! dummy loop indices
       REAL(wp) ::   zcoef0, zcoef1   ! temporary scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zhpi, zhpj
-      !!----------------------------------------------------------------------
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   zhpi, zhpj )
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  zhpi, zhpj
+      !!----------------------------------------------------------------------
       !
       IF( kt == nit000 ) THEN
@@ -315,6 +306,4 @@
       END DO
       !
-      CALL wrk_dealloc( jpi,jpj,jpk,   zhpi, zhpj )
-      !
    END SUBROUTINE hpg_zco
 
@@ -333,8 +322,6 @@
       INTEGER  ::   iku, ikv                         ! temporary integers
       REAL(wp) ::   zcoef0, zcoef1, zcoef2, zcoef3   ! temporary scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zhpi, zhpj
-      !!----------------------------------------------------------------------
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   zhpi, zhpj )
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  zhpi, zhpj
+      !!----------------------------------------------------------------------
       !
       IF( kt == nit000 ) THEN
@@ -405,6 +392,4 @@
       END DO
       !
-      CALL wrk_dealloc( jpi,jpj,jpk,   zhpi, zhpj )
-      !
    END SUBROUTINE hpg_zps
 
@@ -433,10 +418,7 @@
       REAL(wp) ::   zcoef0, zuap, zvap, znad, ztmp       ! temporary scalars
       LOGICAL  ::   ll_tmp1, ll_tmp2                     ! local logical variables
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zhpi, zhpj
-      REAL(wp), POINTER, DIMENSION(:,:)   ::  zcpx, zcpy !W/D pressure filter
-      !!----------------------------------------------------------------------
-      !
-      CALL wrk_alloc( jpi,jpj,jpk, zhpi, zhpj )
-      IF( ln_wd ) CALL wrk_alloc( jpi,jpj, zcpx, zcpy )
+      REAL(wp), DIMENSION(jpi,jpj,jpk)      ::   zhpi, zhpj
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   zcpx, zcpy   !W/D pressure filter
+      !!----------------------------------------------------------------------
       !
       IF( kt == nit000 ) THEN
@@ -452,45 +434,46 @@
       !
       IF( ln_wd ) THEN
-        DO jj = 2, jpjm1
-           DO ji = 2, jpim1 
-             ll_tmp1 = MIN(   sshn(ji,jj)               ,   sshn(ji+1,jj) ) >                &
+         ALLOCATE( zcpx(jpi,jpj) , zcpy(jpi,jpj) )
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1 
+               ll_tmp1 = MIN(   sshn(ji,jj)               ,   sshn(ji+1,jj) ) >                &
                   &    MAX( -ht_wd(ji,jj)               , -ht_wd(ji+1,jj) ) .AND.            &
                   &    MAX(   sshn(ji,jj) + ht_wd(ji,jj),   sshn(ji+1,jj) + ht_wd(ji+1,jj) ) &
                   &                                                         > rn_wdmin1 + rn_wdmin2
-             ll_tmp2 = ( ABS( sshn(ji,jj)               -   sshn(ji+1,jj) ) > 1.E-12 ) .AND. (             &
+               ll_tmp2 = ( ABS( sshn(ji,jj)               -   sshn(ji+1,jj) ) > 1.E-12 ) .AND. (             &
                   &    MAX(   sshn(ji,jj)               ,   sshn(ji+1,jj) ) >                &
                   &    MAX( -ht_wd(ji,jj)               , -ht_wd(ji+1,jj) ) + rn_wdmin1 + rn_wdmin2 )
 
-             IF(ll_tmp1) THEN
-               zcpx(ji,jj) = 1.0_wp
-             ELSE IF(ll_tmp2) THEN
-               ! no worries about  sshn(ji+1,jj) -  sshn(ji  ,jj) = 0, it won't happen ! here
-               zcpx(ji,jj) = ABS( (sshn(ji+1,jj) + ht_wd(ji+1,jj) - sshn(ji,jj) - ht_wd(ji,jj)) &
-                           &    / (sshn(ji+1,jj) -  sshn(ji  ,jj)) )
-             ELSE
-               zcpx(ji,jj) = 0._wp
-             END IF
-      
-             ll_tmp1 = MIN(   sshn(ji,jj)               ,   sshn(ji,jj+1) ) >                &
+               IF(ll_tmp1) THEN
+                  zcpx(ji,jj) = 1.0_wp
+               ELSE IF(ll_tmp2) THEN
+                  ! no worries about  sshn(ji+1,jj) -  sshn(ji  ,jj) = 0, it won't happen ! here
+                  zcpx(ji,jj) = ABS(   ( sshn(ji+1,jj)+ht_wd(ji+1,jj) - sshn(ji,jj)-ht_wd(ji,jj) )   &
+                     &                / ( sshn(ji+1,jj)                - sshn(ji,jj)              )   )
+               ELSE
+                  zcpx(ji,jj) = 0._wp
+               ENDIF
+               !
+               ll_tmp1 = MIN(   sshn(ji,jj)               ,   sshn(ji,jj+1) ) >                &
                   &    MAX( -ht_wd(ji,jj)               , -ht_wd(ji,jj+1) ) .AND.            &
                   &    MAX(   sshn(ji,jj) + ht_wd(ji,jj),   sshn(ji,jj+1) + ht_wd(ji,jj+1) ) &
                   &                                                         > rn_wdmin1 + rn_wdmin2
-             ll_tmp2 = ( ABS( sshn(ji,jj)               -   sshn(ji,jj+1) ) > 1.E-12 ) .AND. (             &
+               ll_tmp2 = ( ABS( sshn(ji,jj)               -   sshn(ji,jj+1) ) > 1.E-12 ) .AND. (             &
                   &    MAX(   sshn(ji,jj)               ,   sshn(ji,jj+1) ) >                &
                   &    MAX( -ht_wd(ji,jj)               , -ht_wd(ji,jj+1) ) + rn_wdmin1 + rn_wdmin2 )
-
-             IF(ll_tmp1) THEN
-               zcpy(ji,jj) = 1.0_wp
-             ELSE IF(ll_tmp2) THEN
-               ! no worries about  sshn(ji,jj+1) -  sshn(ji,jj  ) = 0, it won't happen ! here
-               zcpy(ji,jj) = ABS( (sshn(ji,jj+1) + ht_wd(ji,jj+1) - sshn(ji,jj) - ht_wd(ji,jj)) &
-                           &    / (sshn(ji,jj+1) -  sshn(ji,jj  )) )
-             ELSE
-               zcpy(ji,jj) = 0._wp
-             END IF
-           END DO
-        END DO
-        CALL lbc_lnk( zcpx, 'U', 1._wp )    ;   CALL lbc_lnk( zcpy, 'V', 1._wp )
-      END IF
+                  !
+               IF(ll_tmp1) THEN
+                  zcpy(ji,jj) = 1.0_wp
+               ELSE IF(ll_tmp2) THEN
+                  ! no worries about  sshn(ji,jj+1) -  sshn(ji,jj  ) = 0, it won't happen ! here
+                  zcpy(ji,jj) = ABS(   ( sshn(ji,jj+1)+ht_wd(ji,jj+1) - sshn(ji,jj) - ht_wd(ji,jj) )   &
+                     &               / ( sshn(ji,jj+1)                - sshn(ji,jj)                )   )
+               ELSE
+                  zcpy(ji,jj) = 0._wp
+               ENDIF
+            END DO
+         END DO
+         CALL lbc_lnk( zcpx, 'U', 1._wp )    ;   CALL lbc_lnk( zcpy, 'V', 1._wp )
+      ENDIF
 
       ! Surface value
@@ -507,14 +490,12 @@
             zvap = -zcoef0 * ( rhd    (ji,jj+1,1) + rhd    (ji,jj,1) + 2._wp * znad )   &
                &           * ( gde3w_n(ji,jj+1,1) - gde3w_n(ji,jj,1) ) * r1_e2v(ji,jj)
-
-
+            !
             IF( ln_wd ) THEN
-
-              zhpi(ji,jj,1) = zhpi(ji,jj,1) * zcpx(ji,jj)
-              zhpj(ji,jj,1) = zhpj(ji,jj,1) * zcpy(ji,jj) 
-              zuap = zuap * zcpx(ji,jj)
-              zvap = zvap * zcpy(ji,jj)
+               zhpi(ji,jj,1) = zhpi(ji,jj,1) * zcpx(ji,jj)
+               zhpj(ji,jj,1) = zhpj(ji,jj,1) * zcpy(ji,jj) 
+               zuap = zuap * zcpx(ji,jj)
+               zvap = zvap * zcpy(ji,jj)
             ENDIF
-
+            !
             ! add to the general momentum trend
             ua(ji,jj,1) = ua(ji,jj,1) + zhpi(ji,jj,1) + zuap
@@ -539,12 +520,12 @@
                zvap = -zcoef0 * ( rhd    (ji  ,jj+1,jk) + rhd    (ji,jj,jk) + 2._wp * znad )   &
                   &           * ( gde3w_n(ji  ,jj+1,jk) - gde3w_n(ji,jj,jk) ) * r1_e2v(ji,jj)
-
+               !
                IF( ln_wd ) THEN
-                 zhpi(ji,jj,jk) = zhpi(ji,jj,jk) * zcpx(ji,jj)
-                 zhpj(ji,jj,jk) = zhpj(ji,jj,jk) * zcpy(ji,jj) 
-                 zuap = zuap * zcpx(ji,jj)
-                 zvap = zvap * zcpy(ji,jj)
-               ENDIF
-
+                  zhpi(ji,jj,jk) = zhpi(ji,jj,jk) * zcpx(ji,jj)
+                  zhpj(ji,jj,jk) = zhpj(ji,jj,jk) * zcpy(ji,jj) 
+                  zuap = zuap * zcpx(ji,jj)
+                  zvap = zvap * zcpy(ji,jj)
+               ENDIF
+               !
                ! add to the general momentum trend
                ua(ji,jj,jk) = ua(ji,jj,jk) + zhpi(ji,jj,jk) + zuap
@@ -554,6 +535,5 @@
       END DO
       !
-      CALL wrk_dealloc( jpi,jpj,jpk, zhpi, zhpj )
-      IF( ln_wd ) CALL wrk_dealloc( jpi,jpj, zcpx, zcpy )
+      IF( ln_wd )   DEALLOCATE( zcpx , zcpy )
       !
    END SUBROUTINE hpg_sco
@@ -583,32 +563,26 @@
       INTEGER  ::   ji, jj, jk, ikt, iktp1i, iktp1j   ! dummy loop indices
       REAL(wp) ::   zcoef0, zuap, zvap, znad          ! temporary scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:)   ::  zhpi, zhpj
-      REAL(wp), POINTER, DIMENSION(:,:,:)   ::  ztstop
-      REAL(wp), POINTER, DIMENSION(:,:)     ::  zrhdtop_oce
-      !!----------------------------------------------------------------------
-      !
-      CALL wrk_alloc( jpi,jpj,  2, ztstop) 
-      CALL wrk_alloc( jpi,jpj,jpk, zhpi, zhpj)
-      CALL wrk_alloc( jpi,jpj,     zrhdtop_oce )
-      !
-      ! Local constant initialization
-      zcoef0 = - grav * 0.5_wp
-  
-      ! To use density and not density anomaly
-      znad=1._wp
-
-      ! iniitialised to 0. zhpi zhpi 
-      zhpi(:,:,:)=0._wp ; zhpj(:,:,:)=0._wp
+      REAL(wp), DIMENSION(jpi,jpj,jpk ) ::  zhpi, zhpj
+      REAL(wp), DIMENSION(jpi,jpj,jpts) ::  zts_top
+      REAL(wp), DIMENSION(jpi,jpj)      ::  zrhdtop_oce
+      !!----------------------------------------------------------------------
+      !
+      zcoef0 = - grav * 0.5_wp   ! Local constant initialization
+      !
+      znad=1._wp                 ! To use density and not density anomaly
+      !
+      !                          ! iniitialised to 0. zhpi zhpi 
+      zhpi(:,:,:) = 0._wp   ;   zhpj(:,:,:) = 0._wp
 
       ! compute rhd at the ice/oce interface (ocean side)
       ! usefull to reduce residual current in the test case ISOMIP with no melting
-      DO ji=1,jpi
-        DO jj=1,jpj
-          ikt=mikt(ji,jj)
-          ztstop(ji,jj,1)=tsn(ji,jj,ikt,1)
-          ztstop(ji,jj,2)=tsn(ji,jj,ikt,2)
+      DO ji = 1, jpi
+        DO jj = 1, jpj
+          ikt = mikt(ji,jj)
+          zts_top(ji,jj,1) = tsn(ji,jj,ikt,1)
+          zts_top(ji,jj,2) = tsn(ji,jj,ikt,2)
         END DO
       END DO
-      CALL eos( ztstop, risfdep, zrhdtop_oce )
+      CALL eos( zts_top, risfdep, zrhdtop_oce )
 
 !==================================================================================     
@@ -667,8 +641,4 @@
          END DO
       END DO
-     !
-      CALL wrk_dealloc( jpi,jpj,2  , ztstop)
-      CALL wrk_dealloc( jpi,jpj,jpk, zhpi, zhpj)
-      CALL wrk_dealloc( jpi,jpj    , zrhdtop_oce )
       !
    END SUBROUTINE hpg_isf
@@ -690,59 +660,54 @@
       REAL(wp) ::   z1_12, cffv, cffy   !    "         "
       LOGICAL  ::   ll_tmp1, ll_tmp2    ! local logical variables
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zhpi, zhpj
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  dzx, dzy, dzz, dzu, dzv, dzw
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  drhox, drhoy, drhoz, drhou, drhov, drhow
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  rho_i, rho_j, rho_k
-      REAL(wp), POINTER, DIMENSION(:,:)   ::  zcpx, zcpy    !W/D pressure filter
-      !!----------------------------------------------------------------------
-      !
-      CALL wrk_alloc( jpi, jpj, jpk, dzx  , dzy  , dzz  , dzu  , dzv  , dzw   )
-      CALL wrk_alloc( jpi, jpj, jpk, drhox, drhoy, drhoz, drhou, drhov, drhow )
-      CALL wrk_alloc( jpi, jpj, jpk, rho_i, rho_j, rho_k,  zhpi,  zhpj        )
-      IF( ln_wd ) CALL wrk_alloc( jpi,jpj, zcpx, zcpy )
-      !
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zhpi, zhpj
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   dzx, dzy, dzz, dzu, dzv, dzw
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   drhox, drhoy, drhoz, drhou, drhov, drhow
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   rho_i, rho_j, rho_k
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   zcpx, zcpy   !W/D pressure filter
+      !!----------------------------------------------------------------------
       !
       IF( ln_wd ) THEN
-        DO jj = 2, jpjm1
-           DO ji = 2, jpim1 
-             ll_tmp1 = MIN(   sshn(ji,jj)               ,   sshn(ji+1,jj) ) >                &
+         ALLOCATE( zcpx(jpi,jpj) , zcpy(jpi,jpj) )
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1 
+               ll_tmp1 = MIN(   sshn(ji,jj)               ,   sshn(ji+1,jj) ) >                &
                   &    MAX( -ht_wd(ji,jj)               , -ht_wd(ji+1,jj) ) .AND.            &
                   &    MAX(   sshn(ji,jj) + ht_wd(ji,jj),   sshn(ji+1,jj) + ht_wd(ji+1,jj) ) &
                   &                                                         > rn_wdmin1 + rn_wdmin2
-             ll_tmp2 = ( ABS( sshn(ji,jj)               -   sshn(ji+1,jj) ) > 1.E-12 ) .AND. (             &
+               ll_tmp2 = ( ABS( sshn(ji,jj)               -   sshn(ji+1,jj) ) > 1.E-12 ) .AND. (             &
                   &    MAX(   sshn(ji,jj)               ,   sshn(ji+1,jj) ) >                &
                   &    MAX( -ht_wd(ji,jj)               , -ht_wd(ji+1,jj) ) + rn_wdmin1 + rn_wdmin2 )
 
-             IF(ll_tmp1) THEN
-               zcpx(ji,jj) = 1.0_wp
-             ELSE IF(ll_tmp2) THEN
-               ! no worries about  sshn(ji+1,jj) -  sshn(ji  ,jj) = 0, it won't happen ! here
-               zcpx(ji,jj) = ABS( (sshn(ji+1,jj) + ht_wd(ji+1,jj) - sshn(ji,jj) - ht_wd(ji,jj)) &
-                           &    / (sshn(ji+1,jj) -  sshn(ji  ,jj)) )
-             ELSE
-               zcpx(ji,jj) = 0._wp
-             END IF
+               IF(ll_tmp1) THEN
+                  zcpx(ji,jj) = 1.0_wp
+               ELSE IF(ll_tmp2) THEN
+                  ! no worries about  sshn(ji+1,jj) -  sshn(ji  ,jj) = 0, it won't happen ! here
+                  zcpx(ji,jj) = ABS( (sshn(ji+1,jj) + ht_wd(ji+1,jj) - sshn(ji,jj) - ht_wd(ji,jj)) &
+                              &    / (sshn(ji+1,jj) -  sshn(ji  ,jj)) )
+               ELSE
+                  zcpx(ji,jj) = 0._wp
+               ENDIF
       
-             ll_tmp1 = MIN(   sshn(ji,jj)               ,   sshn(ji,jj+1) ) >                &
+               ll_tmp1 = MIN(   sshn(ji,jj)               ,   sshn(ji,jj+1) ) >                &
                   &    MAX( -ht_wd(ji,jj)               , -ht_wd(ji,jj+1) ) .AND.            &
                   &    MAX(   sshn(ji,jj) + ht_wd(ji,jj),   sshn(ji,jj+1) + ht_wd(ji,jj+1) ) &
                   &                                                         > rn_wdmin1 + rn_wdmin2
-             ll_tmp2 = ( ABS( sshn(ji,jj)               -   sshn(ji,jj+1) ) > 1.E-12 ) .AND. (             &
+               ll_tmp2 = ( ABS( sshn(ji,jj)               -   sshn(ji,jj+1) ) > 1.E-12 ) .AND. (             &
                   &    MAX(   sshn(ji,jj)               ,   sshn(ji,jj+1) ) >                &
                   &    MAX( -ht_wd(ji,jj)               , -ht_wd(ji,jj+1) ) + rn_wdmin1 + rn_wdmin2 )
 
-             IF(ll_tmp1) THEN
-               zcpy(ji,jj) = 1.0_wp
-             ELSE IF(ll_tmp2) THEN
-               ! no worries about  sshn(ji,jj+1) -  sshn(ji,jj  ) = 0, it won't happen ! here
-               zcpy(ji,jj) = ABS( (sshn(ji,jj+1) + ht_wd(ji,jj+1) - sshn(ji,jj) - ht_wd(ji,jj)) &
-                           &    / (sshn(ji,jj+1) -  sshn(ji,jj  )) )
-             ELSE
-               zcpy(ji,jj) = 0._wp
-             END IF
-           END DO
-        END DO
-        CALL lbc_lnk( zcpx, 'U', 1._wp )    ;   CALL lbc_lnk( zcpy, 'V', 1._wp )
-      END IF
+               IF(ll_tmp1) THEN
+                  zcpy(ji,jj) = 1.0_wp
+               ELSE IF(ll_tmp2) THEN
+                  ! no worries about  sshn(ji,jj+1) -  sshn(ji,jj  ) = 0, it won't happen ! here
+                  zcpy(ji,jj) = ABS( (sshn(ji,jj+1) + ht_wd(ji,jj+1) - sshn(ji,jj) - ht_wd(ji,jj)) &
+                              &    / (sshn(ji,jj+1) -  sshn(ji,jj  )) )
+               ELSE
+                  zcpy(ji,jj) = 0._wp
+               ENDIF
+            END DO
+         END DO
+         CALL lbc_lnk( zcpx, 'U', 1._wp )    ;   CALL lbc_lnk( zcpy, 'V', 1._wp )
+      ENDIF
 
       IF( kt == nit000 ) THEN
@@ -903,7 +868,7 @@
          END DO
       END DO
-      CALL lbc_lnk(rho_k,'W',1.)
-      CALL lbc_lnk(rho_i,'U',1.)
-      CALL lbc_lnk(rho_j,'V',1.)
+      CALL lbc_lnk( rho_k, 'W', 1. )
+      CALL lbc_lnk( rho_i, 'U', 1. )
+      CALL lbc_lnk( rho_j, 'V', 1. )
 
 
@@ -949,8 +914,5 @@
       END DO
       !
-      CALL wrk_dealloc( jpi, jpj, jpk, dzx  , dzy  , dzz  , dzu  , dzv  , dzw   )
-      CALL wrk_dealloc( jpi, jpj, jpk, drhox, drhoy, drhoz, drhou, drhov, drhow )
-      CALL wrk_dealloc( jpi, jpj, jpk, rho_i, rho_j, rho_k,  zhpi,  zhpj        )
-      IF( ln_wd ) CALL wrk_dealloc( jpi,jpj, zcpx, zcpy )
+      IF( ln_wd )   DEALLOCATE( zcpx, zcpy )
       !
    END SUBROUTINE hpg_djc
@@ -980,14 +942,9 @@
       REAL(wp) :: zrhdt1
       REAL(wp) :: zdpdx1, zdpdx2, zdpdy1, zdpdy2
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zdept, zrhh
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zhpi, zu, zv, fsp, xsp, asp, bsp, csp, dsp
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zsshu_n, zsshv_n
-      REAL(wp), POINTER, DIMENSION(:,:)   ::  zcpx, zcpy    !W/D pressure filter
-      !!----------------------------------------------------------------------
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   zhpi, zu, zv, fsp, xsp, asp, bsp, csp, dsp )
-      CALL wrk_alloc( jpi,jpj,jpk,   zdept, zrhh )
-      CALL wrk_alloc( jpi,jpj,       zsshu_n, zsshv_n )
-      IF( ln_wd ) CALL wrk_alloc( jpi,jpj, zcpx, zcpy )
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdept, zrhh
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zhpi, zu, zv, fsp, xsp, asp, bsp, csp, dsp
+      REAL(wp), DIMENSION(jpi,jpj)   ::   zsshu_n, zsshv_n
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   zcpx, zcpy   !W/D pressure filter
+      !!----------------------------------------------------------------------
       !
       IF( kt == nit000 ) THEN
@@ -1003,45 +960,46 @@
 
       IF( ln_wd ) THEN
-        DO jj = 2, jpjm1
-           DO ji = 2, jpim1 
-             ll_tmp1 = MIN(   sshn(ji,jj)               ,   sshn(ji+1,jj) ) >                &
+         ALLOCATE( zcpx(jpi,jpj) , zcpy(jpi,jpj) )
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1 
+               ll_tmp1 = MIN(   sshn(ji,jj)               ,   sshn(ji+1,jj) ) >                &
                   &    MAX( -ht_wd(ji,jj)               , -ht_wd(ji+1,jj) ) .AND.            &
                   &    MAX(   sshn(ji,jj) + ht_wd(ji,jj),   sshn(ji+1,jj) + ht_wd(ji+1,jj) ) &
                   &                                                         > rn_wdmin1 + rn_wdmin2
-             ll_tmp2 = ( ABS( sshn(ji,jj)               -   sshn(ji+1,jj) ) > 1.E-12 ) .AND. (             &
+               ll_tmp2 = ( ABS( sshn(ji,jj)               -   sshn(ji+1,jj) ) > 1.E-12 ) .AND. (             &
                   &    MAX(   sshn(ji,jj)               ,   sshn(ji+1,jj) ) >                &
                   &    MAX( -ht_wd(ji,jj)               , -ht_wd(ji+1,jj) ) + rn_wdmin1 + rn_wdmin2 )
 
-             IF(ll_tmp1) THEN
-               zcpx(ji,jj) = 1.0_wp
-             ELSE IF(ll_tmp2) THEN
-               ! no worries about  sshn(ji+1,jj) -  sshn(ji  ,jj) = 0, it won't happen ! here
-               zcpx(ji,jj) = ABS( (sshn(ji+1,jj) + ht_wd(ji+1,jj) - sshn(ji,jj) - ht_wd(ji,jj)) &
-                           &    / (sshn(ji+1,jj) -  sshn(ji  ,jj)) )
-             ELSE
-               zcpx(ji,jj) = 0._wp
-             END IF
+               IF(ll_tmp1) THEN
+                  zcpx(ji,jj) = 1.0_wp
+               ELSE IF(ll_tmp2) THEN
+                  ! no worries about  sshn(ji+1,jj) -  sshn(ji  ,jj) = 0, it won't happen ! here
+                  zcpx(ji,jj) = ABS( (sshn(ji+1,jj) + ht_wd(ji+1,jj) - sshn(ji,jj) - ht_wd(ji,jj)) &
+                             &    / (sshn(ji+1,jj) -  sshn(ji  ,jj)) )
+               ELSE
+                  zcpx(ji,jj) = 0._wp
+               ENDIF
       
-             ll_tmp1 = MIN(   sshn(ji,jj)               ,   sshn(ji,jj+1) ) >                &
+               ll_tmp1 = MIN(   sshn(ji,jj)             ,   sshn(ji,jj+1) ) >                &
                   &    MAX( -ht_wd(ji,jj)               , -ht_wd(ji,jj+1) ) .AND.            &
                   &    MAX(   sshn(ji,jj) + ht_wd(ji,jj),   sshn(ji,jj+1) + ht_wd(ji,jj+1) ) &
                   &                                                         > rn_wdmin1 + rn_wdmin2
-             ll_tmp2 = ( ABS( sshn(ji,jj)               -   sshn(ji,jj+1) ) > 1.E-12 ) .AND. (             &
+               ll_tmp2 = ( ABS( sshn(ji,jj)             -   sshn(ji,jj+1) ) > 1.E-12 ) .AND. (             &
                   &    MAX(   sshn(ji,jj)               ,   sshn(ji,jj+1) ) >                &
                   &    MAX( -ht_wd(ji,jj)               , -ht_wd(ji,jj+1) ) + rn_wdmin1 + rn_wdmin2 )
 
-             IF(ll_tmp1) THEN
-               zcpy(ji,jj) = 1.0_wp
-             ELSE IF(ll_tmp2) THEN
-               ! no worries about  sshn(ji,jj+1) -  sshn(ji,jj  ) = 0, it won't happen ! here
-               zcpy(ji,jj) = ABS( (sshn(ji,jj+1) + ht_wd(ji,jj+1) - sshn(ji,jj) - ht_wd(ji,jj)) &
+               IF(ll_tmp1) THEN
+                  zcpy(ji,jj) = 1.0_wp
+               ELSE IF(ll_tmp2) THEN
+                  ! no worries about  sshn(ji,jj+1) -  sshn(ji,jj  ) = 0, it won't happen ! here
+                  zcpy(ji,jj) = ABS( (sshn(ji,jj+1) + ht_wd(ji,jj+1) - sshn(ji,jj) - ht_wd(ji,jj)) &
                            &    / (sshn(ji,jj+1) -  sshn(ji,jj  )) )
-             ELSE
-               zcpy(ji,jj) = 0._wp
-             END IF
-           END DO
-        END DO
-        CALL lbc_lnk( zcpx, 'U', 1._wp )    ;   CALL lbc_lnk( zcpy, 'V', 1._wp )
-      END IF
+               ELSE
+                  zcpy(ji,jj) = 0._wp
+               ENDIF
+            END DO
+         END DO
+         CALL lbc_lnk( zcpx, 'U', 1._wp )    ;   CALL lbc_lnk( zcpy, 'V', 1._wp )
+      ENDIF
 
       ! Clean 3-D work arrays
@@ -1298,8 +1256,5 @@
       END DO
       !
-      CALL wrk_dealloc( jpi,jpj,jpk,   zhpi, zu, zv, fsp, xsp, asp, bsp, csp, dsp )
-      CALL wrk_dealloc( jpi,jpj,jpk,   zdept, zrhh )
-      CALL wrk_dealloc( jpi,jpj,       zsshu_n, zsshv_n )
-      IF( ln_wd ) CALL wrk_dealloc( jpi,jpj, zcpx, zcpy )
+      IF( ln_wd )   DEALLOCATE( zcpx, zcpy )
       !
    END SUBROUTINE hpg_prj
@@ -1353,6 +1308,6 @@
            !!Simply geometric average
                DO jk = 2, jpkm1-1
-                  zdf1 = (fsp(ji,jj,jk) - fsp(ji,jj,jk-1)) / (xsp(ji,jj,jk) - xsp(ji,jj,jk-1))
-                  zdf2 = (fsp(ji,jj,jk+1) - fsp(ji,jj,jk)) / (xsp(ji,jj,jk+1) - xsp(ji,jj,jk))
+                  zdf1 = (fsp(ji,jj,jk  ) - fsp(ji,jj,jk-1)) / (xsp(ji,jj,jk  ) - xsp(ji,jj,jk-1))
+                  zdf2 = (fsp(ji,jj,jk+1) - fsp(ji,jj,jk  )) / (xsp(ji,jj,jk+1) - xsp(ji,jj,jk  ))
 
                   IF(zdf1 * zdf2 <= 0._wp) THEN
@@ -1403,9 +1358,9 @@
             END DO
          END DO
-
+         !
       ELSE
-           CALL ctl_stop( 'invalid polynomial type in cspline' )
-      ENDIF
-
+         CALL ctl_stop( 'invalid polynomial type in cspline' )
+      ENDIF
+      !
    END SUBROUTINE cspline
 
@@ -1457,5 +1412,5 @@
       !!                 ***  ROUTINE interp1  ***
       !!
-      !! ** Purpose :   Calculate the first order of deriavtive of
+      !! ** Purpose :   Calculate the first order of derivative of
       !!                a cubic spline function y=a+b*x+c*x^2+d*x^3
       !!
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynkeg.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynkeg.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynkeg.F90	(revision 9019)
@@ -22,5 +22,4 @@
    USE lib_mpp         ! MPP library
    USE prtctl          ! Print control
-   USE wrk_nemo        ! Memory Allocation
    USE timing          ! Timing
    USE bdy_oce         ! ocean open boundary conditions
@@ -39,5 +38,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.6 , NEMO Consortium (2015)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -75,16 +74,13 @@
       INTEGER, INTENT( in ) ::   kscheme   ! =0/1   type of KEG scheme 
       !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zu, zv       ! temporary scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zhke
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: ztrdu, ztrdv 
-      INTEGER  ::   jb                 ! dummy loop indices
-      INTEGER  ::   ii, ij, igrd, ib_bdy   ! local integers
-      INTEGER  ::   fu, fv
+      INTEGER  ::   ji, jj, jk, jb    ! dummy loop indices
+      INTEGER  ::   ii, ifu, ib_bdy   ! local integers
+      INTEGER  ::   ij, ifv, igrd     !   -       -
+      REAL(wp) ::   zu, zv            ! local scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk)        ::   zhke
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrdu, ztrdv 
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start('dyn_keg')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   zhke )
+      IF( ln_timing )   CALL timing_start('dyn_keg')
       !
       IF( kt == nit000 ) THEN
@@ -94,6 +90,6 @@
       ENDIF
 
-      IF( l_trddyn ) THEN           ! Save ua and va trends
-         CALL wrk_alloc( jpi,jpj,jpk,   ztrdu, ztrdv )
+      IF( l_trddyn ) THEN           ! Save the input trends
+         ALLOCATE( ztrdu(jpi,jpj,jpk) , ztrdv(jpi,jpj,jpk) )
          ztrdu(:,:,:) = ua(:,:,:) 
          ztrdv(:,:,:) = va(:,:,:) 
@@ -112,6 +108,6 @@
                      ii   = idx_bdy(ib_bdy)%nbi(jb,igrd)
                      ij   = idx_bdy(ib_bdy)%nbj(jb,igrd)
-                     fu   = NINT( idx_bdy(ib_bdy)%flagu(jb,igrd) )
-                     un(ii-fu,ij,jk) = un(ii,ij,jk) * umask(ii,ij,jk)
+                     ifu   = NINT( idx_bdy(ib_bdy)%flagu(jb,igrd) )
+                     un(ii-ifu,ij,jk) = un(ii,ij,jk) * umask(ii,ij,jk)
                   END DO
                END DO
@@ -122,6 +118,6 @@
                      ii   = idx_bdy(ib_bdy)%nbi(jb,igrd)
                      ij   = idx_bdy(ib_bdy)%nbj(jb,igrd)
-                     fv   = NINT( idx_bdy(ib_bdy)%flagv(jb,igrd) )
-                     vn(ii,ij-fv,jk) = vn(ii,ij,jk) * vmask(ii,ij,jk)
+                     ifv   = NINT( idx_bdy(ib_bdy)%flagv(jb,igrd) )
+                     vn(ii,ij-ifv,jk) = vn(ii,ij,jk) * vmask(ii,ij,jk)
                   END DO
                END DO
@@ -172,5 +168,4 @@
       ENDIF      
 
-
       !
       DO jk = 1, jpkm1                    !==  grad( KE ) added to the general momentum trends  ==!
@@ -187,5 +182,5 @@
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
          CALL trd_dyn( ztrdu, ztrdv, jpdyn_keg, kt )
-         CALL wrk_dealloc( jpi,jpj,jpk,   ztrdu, ztrdv )
+         DEALLOCATE( ztrdu , ztrdv )
       ENDIF
       !
@@ -193,7 +188,5 @@
          &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
       !
-      CALL wrk_dealloc( jpi,jpj,jpk,   zhke )
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('dyn_keg')
+      IF( ln_timing )   CALL timing_stop('dyn_keg')
       !
    END SUBROUTINE dyn_keg
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf.F90	(revision 9019)
@@ -27,5 +27,4 @@
    USE lib_mpp        ! distribued memory computing library
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
 
@@ -37,16 +36,16 @@
 
    !                      ! Parameter to control the type of lateral viscous operator
-   INTEGER, PARAMETER, PUBLIC ::   np_ERROR  =-10   ! error in setting the operator
-   INTEGER, PARAMETER, PUBLIC ::   np_no_ldf = 00   ! without operator (i.e. no lateral viscous trend)
+   INTEGER, PARAMETER, PUBLIC ::   np_ERROR  =-10   !: error in setting the operator
+   INTEGER, PARAMETER, PUBLIC ::   np_no_ldf = 00   !: without operator (i.e. no lateral viscous trend)
    !                          !!      laplacian     !    bilaplacian    !
-   INTEGER, PARAMETER, PUBLIC ::   np_lap    = 10   ,   np_blp    = 20  ! iso-level operator
-   INTEGER, PARAMETER, PUBLIC ::   np_lap_i  = 11                       ! iso-neutral or geopotential operator
+   INTEGER, PARAMETER, PUBLIC ::   np_lap    = 10   ,   np_blp    = 20  !: iso-level operator
+   INTEGER, PARAMETER, PUBLIC ::   np_lap_i  = 11                       !: iso-neutral or geopotential operator
 
-   INTEGER ::   nldf   ! type of lateral diffusion used defined from ln_dynldf_... (namlist logicals)
+   INTEGER, PUBLIC ::   nldf   !: type of lateral diffusion used defined from ln_dynldf_... (namlist logicals)
 
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -62,11 +61,11 @@
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       !
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrdu, ztrdv
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrdu, ztrdv
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_ldf')
+      IF( ln_timing )   CALL timing_start('dyn_ldf')
       !
       IF( l_trddyn )   THEN                      ! temporary save of momentum trends
-         CALL wrk_alloc( jpi,jpj,jpk,   ztrdu, ztrdv )
+         ALLOCATE( ztrdu(jpi,jpj,jpk) , ztrdv(jpi,jpj,jpk) )
          ztrdu(:,:,:) = ua(:,:,:) 
          ztrdv(:,:,:) = va(:,:,:) 
@@ -85,5 +84,5 @@
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
          CALL trd_dyn( ztrdu, ztrdv, jpdyn_ldf, kt )
-         CALL wrk_dealloc( jpi,jpj,jpk,   ztrdu, ztrdv )
+         DEALLOCATE ( ztrdu , ztrdv )
       ENDIF
       !                                          ! print sum trends (used for debugging)
@@ -91,5 +90,5 @@
          &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_ldf')
+      IF( ln_timing )   CALL timing_stop('dyn_ldf')
       !
    END SUBROUTINE dyn_ldf
@@ -102,50 +101,52 @@
       !! ** Purpose :   initializations of the horizontal ocean dynamics physics
       !!----------------------------------------------------------------------
-      INTEGER ::   ioptio, ierr         ! temporary integers 
+      INTEGER ::   ioptio, ierr   ! temporary integers 
       !!----------------------------------------------------------------------
       !
-      !                                   ! Namelist nam_dynldf: already read in ldfdyn module
+      !                                !==  Namelist nam_dynldf  ==!   already read in ldfdyn module
       !
-      IF(lwp) THEN                        ! Namelist print
+      IF(lwp) THEN                     !== Namelist print  ==!
          WRITE(numout,*)
          WRITE(numout,*) 'dyn_ldf_init : Choice of the lateral diffusive operator on dynamics'
          WRITE(numout,*) '~~~~~~~~~~~~'
          WRITE(numout,*) '   Namelist nam_dynldf : set lateral mixing parameters (type, direction, coefficients)'
-         WRITE(numout,*) '      laplacian operator          ln_dynldf_lap = ', ln_dynldf_lap
-         WRITE(numout,*) '      bilaplacian operator        ln_dynldf_blp = ', ln_dynldf_blp
-         WRITE(numout,*) '      iso-level                   ln_dynldf_lev = ', ln_dynldf_lev
-         WRITE(numout,*) '      horizontal (geopotential)   ln_dynldf_hor = ', ln_dynldf_hor
-         WRITE(numout,*) '      iso-neutral                 ln_dynldf_iso = ', ln_dynldf_iso
+         WRITE(numout,*) '      Type of operator'
+         WRITE(numout,*) '         no explicit diffusion       ln_dynldf_NONE = ', ln_dynldf_NONE
+         WRITE(numout,*) '         laplacian operator          ln_dynldf_lap  = ', ln_dynldf_lap
+         WRITE(numout,*) '         bilaplacian operator        ln_dynldf_blp  = ', ln_dynldf_blp
+         WRITE(numout,*) '      Direction of action'
+         WRITE(numout,*) '         iso-level                   ln_dynldf_lev  = ', ln_dynldf_lev
+         WRITE(numout,*) '         horizontal (geopotential)   ln_dynldf_hor  = ', ln_dynldf_hor
+         WRITE(numout,*) '         iso-neutral                 ln_dynldf_iso  = ', ln_dynldf_iso
       ENDIF
-      !                                   ! use of lateral operator or not
+      !                                !==  use of lateral operator or not  ==!
       nldf = np_ERROR
       ioptio = 0
-      IF( ln_dynldf_lap )   ioptio = ioptio + 1
-      IF( ln_dynldf_blp )   ioptio = ioptio + 1
-      IF( ioptio >  1   )   CALL ctl_stop( 'dyn_ldf_init: use ONE or NONE of the 2 lap/bilap operator type on momentum' )
-      IF( ioptio == 0   )   nldf = np_no_ldf     ! No lateral mixing operator
+      IF( ln_dynldf_NONE ) THEN   ;   nldf = np_no_ldf   ;   ioptio = ioptio + 1   ;   ENDIF
+      IF( ln_dynldf_lap  ) THEN   ;                          ioptio = ioptio + 1   ;   ENDIF
+      IF( ln_dynldf_blp  ) THEN   ;                          ioptio = ioptio + 1   ;   ENDIF
+      IF( ioptio /= 1    )   CALL ctl_stop( 'dyn_ldf_init: use ONE of the 3 operator options (NONE/lap/blp)' )
       !
-      IF( nldf /= np_no_ldf ) THEN        ! direction ==>> type of operator  
+      IF(.NOT.ln_dynldf_NONE ) THEN    !==  direction ==>> type of operator  ==!
          ioptio = 0
          IF( ln_dynldf_lev )   ioptio = ioptio + 1
          IF( ln_dynldf_hor )   ioptio = ioptio + 1
          IF( ln_dynldf_iso )   ioptio = ioptio + 1
-         IF( ioptio >  1   )   CALL ctl_stop( '          use only ONE direction (level/hor/iso)' )
-         IF( ioptio == 0   )   CALL ctl_stop( '          use at least ONE direction (level/hor/iso)' )
+         IF( ioptio /= 1   )   CALL ctl_stop( 'dyn_ldf_init: use ONE of the 3 direction options (level/hor/iso)' )
          !
-         !                                   ! Set nldf, the type of lateral diffusion, from ln_dynldf_... logicals
+         !                             ! Set nldf, the type of lateral diffusion, from ln_dynldf_... logicals
          ierr = 0
-         IF ( ln_dynldf_lap ) THEN      ! laplacian operator
-            IF ( ln_zco ) THEN                ! z-coordinate
+         IF( ln_dynldf_lap ) THEN         ! laplacian operator
+            IF( ln_zco ) THEN                ! z-coordinate
                IF ( ln_dynldf_lev )   nldf = np_lap     ! iso-level = horizontal (no rotation)
                IF ( ln_dynldf_hor )   nldf = np_lap     ! iso-level = horizontal (no rotation)
                IF ( ln_dynldf_iso )   nldf = np_lap_i   ! iso-neutral            (   rotation)
             ENDIF
-            IF ( ln_zps ) THEN             ! z-coordinate with partial step
+            IF( ln_zps ) THEN                ! z-coordinate with partial step
                IF ( ln_dynldf_lev )   nldf = np_lap     ! iso-level              (no rotation)
                IF ( ln_dynldf_hor )   nldf = np_lap     ! iso-level              (no rotation)
                IF ( ln_dynldf_iso )   nldf = np_lap_i   ! iso-neutral            (   rotation)
             ENDIF
-            IF ( ln_sco ) THEN             ! s-coordinate
+            IF( ln_sco ) THEN                ! s-coordinate
                IF ( ln_dynldf_lev )   nldf = np_lap     ! iso-level = horizontal (no rotation)
                IF ( ln_dynldf_hor )   nldf = np_lap_i   ! horizontal             (   rotation)
@@ -154,19 +155,19 @@
          ENDIF
          !
-         IF( ln_dynldf_blp ) THEN          ! bilaplacian operator
-            IF ( ln_zco ) THEN                ! z-coordinate
-               IF ( ln_dynldf_lev )   nldf = np_blp     ! iso-level = horizontal (no rotation)
-               IF ( ln_dynldf_hor )   nldf = np_blp     ! iso-level = horizontal (no rotation)
-               IF ( ln_dynldf_iso )   ierr = 2          ! iso-neutral            (   rotation)
+         IF( ln_dynldf_blp ) THEN         ! bilaplacian operator
+            IF( ln_zco ) THEN                ! z-coordinate
+               IF( ln_dynldf_lev )   nldf = np_blp     ! iso-level = horizontal (no rotation)
+               IF( ln_dynldf_hor )   nldf = np_blp     ! iso-level = horizontal (no rotation)
+               IF( ln_dynldf_iso )   ierr = 2          ! iso-neutral            (   rotation)
             ENDIF
-            IF ( ln_zps ) THEN             ! z-coordinate with partial step
-               IF ( ln_dynldf_lev )   nldf = np_blp     ! iso-level              (no rotation)
-               IF ( ln_dynldf_hor )   nldf = np_blp     ! iso-level              (no rotation)
-               IF ( ln_dynldf_iso )   ierr = 2          ! iso-neutral            (   rotation)
+            IF( ln_zps ) THEN                ! z-coordinate with partial step
+               IF( ln_dynldf_lev )   nldf = np_blp     ! iso-level              (no rotation)
+               IF( ln_dynldf_hor )   nldf = np_blp     ! iso-level              (no rotation)
+               IF( ln_dynldf_iso )   ierr = 2          ! iso-neutral            (   rotation)
             ENDIF
-            IF ( ln_sco ) THEN             ! s-coordinate
-               IF ( ln_dynldf_lev )   nldf = np_blp     ! iso-level              (no rotation)
-               IF ( ln_dynldf_hor )   ierr = 2          ! horizontal             (   rotation)
-               IF ( ln_dynldf_iso )   ierr = 2          ! iso-neutral            (   rotation)
+            IF( ln_sco ) THEN                ! s-coordinate
+               IF( ln_dynldf_lev )   nldf = np_blp     ! iso-level              (no rotation)
+               IF( ln_dynldf_hor )   ierr = 2          ! horizontal             (   rotation)
+               IF( ln_dynldf_iso )   ierr = 2          ! iso-neutral            (   rotation)
             ENDIF
          ENDIF
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_iso.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_iso.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_iso.F90	(revision 9019)
@@ -28,5 +28,4 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE prtctl          ! Print control
-   USE wrk_nemo        ! Memory Allocation
    USE timing          ! Timing
 
@@ -37,4 +36,6 @@
    PUBLIC   dyn_ldf_iso_alloc     ! called by nemogcm.F90
 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   akzu, akzv   !: vertical component of rotated lateral viscosity
+   
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) :: zfuw, zdiu, zdju, zdj1u   ! 2D workspace (dyn_ldf_iso) 
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) :: zfvw, zdiv, zdjv, zdj1v   !  -      -
@@ -43,5 +44,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2011)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -53,6 +54,6 @@
       !!                  ***  ROUTINE dyn_ldf_iso_alloc  ***
       !!----------------------------------------------------------------------
-      ALLOCATE( zfuw(jpi,jpk) , zdiu(jpi,jpk) , zdju(jpi,jpk) , zdj1u(jpi,jpk) ,     & 
-         &      zfvw(jpi,jpk) , zdiv(jpi,jpk) , zdjv(jpi,jpk) , zdj1v(jpi,jpk) , STAT=dyn_ldf_iso_alloc )
+      ALLOCATE( akzu(jpi,jpj,jpk) , zfuw(jpi,jpk) , zdiu(jpi,jpk) , zdju(jpi,jpk) , zdj1u(jpi,jpk) ,     & 
+         &      akzv(jpi,jpj,jpk) , zfvw(jpi,jpk) , zdiv(jpi,jpk) , zdjv(jpi,jpk) , zdj1v(jpi,jpk) , STAT=dyn_ldf_iso_alloc )
          !
       IF( dyn_ldf_iso_alloc /= 0 )   CALL ctl_warn('dyn_ldf_iso_alloc: array allocate failed.')
@@ -99,23 +100,19 @@
       !!
       !! ** Action :
-      !!        Update (ua,va) arrays with the before geopotential biharmonic
-      !!      mixing trend.
-      !!        Update (avmu,avmv) to accompt for the diagonal vertical component
-      !!      of the rotated operator in dynzdf module
+      !!       -(ua,va) updated with the before geopotential harmonic mixing trend
+      !!       -(akzu,akzv) to accompt for the diagonal vertical component
+      !!                    of the rotated operator in dynzdf module
       !!----------------------------------------------------------------------
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
       !
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zabe1, zabe2, zcof1, zcof2                       ! local scalars
-      REAL(wp) ::   zmskt, zmskf                                     !   -      -
-      REAL(wp) ::   zcoef0, zcoef3, zcoef4, zmkt, zmkf               !   -      -
-      REAL(wp) ::   zuav, zvav, zuwslpi, zuwslpj, zvwslpi, zvwslpj   !   -      -
-      !
-      REAL(wp), POINTER, DIMENSION(:,:) :: ziut, zjuf, zjvt, zivf, zdku, zdk1u, zdkv, zdk1v
+      REAL(wp) ::   zabe1, zmskt, zmkt, zuav, zuwslpi, zuwslpj   ! local scalars
+      REAL(wp) ::   zabe2, zmskf, zmkf, zvav, zvwslpi, zvwslpj   !   -      -
+      REAL(wp) ::   zcof0, zcof1, zcof2, zcof3, zcof4            !   -      -
+      REAL(wp), DIMENSION(jpi,jpj) ::   ziut, zivf, zdku, zdk1u  ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj) ::   zjuf, zjvt, zdkv, zdk1v  !  -      -
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_ldf_iso')
-      !
-      CALL wrk_alloc( jpi, jpj, ziut, zjuf, zjvt, zivf, zdku, zdk1u, zdkv, zdk1v ) 
+      IF( ln_timing )   CALL timing_start('dyn_ldf_iso')
       !
       IF( kt == nit000 ) THEN
@@ -144,12 +141,6 @@
          CALL lbc_lnk( uslp , 'U', -1. )      ;      CALL lbc_lnk( vslp , 'V', -1. )
          CALL lbc_lnk( wslpi, 'W', -1. )      ;      CALL lbc_lnk( wslpj, 'W', -1. )
- 
-!!bug
-         IF( kt == nit000 ) then
-            IF(lwp) WRITE(numout,*) ' max slop: u', SQRT( MAXVAL(uslp*uslp)), ' v ', SQRT(MAXVAL(vslp)),  &
-               &                             ' wi', sqrt(MAXVAL(wslpi))     , ' wj', sqrt(MAXVAL(wslpj))
-         endif
-!!end
-      ENDIF
+         !
+       ENDIF
 
       !                                                ! ===============
@@ -348,24 +339,24 @@
          DO jk = 2, jpkm1
             DO ji = 2, jpim1
-               zcoef0= 0.5 * rn_aht_0 * umask(ji,jj,jk)
+               zcof0 = 0.5_wp * rn_aht_0 * umask(ji,jj,jk)
                !
-               zuwslpi = zcoef0 * ( wslpi(ji+1,jj,jk) + wslpi(ji,jj,jk) )
-               zuwslpj = zcoef0 * ( wslpj(ji+1,jj,jk) + wslpj(ji,jj,jk) )
+               zuwslpi = zcof0 * ( wslpi(ji+1,jj,jk) + wslpi(ji,jj,jk) )
+               zuwslpj = zcof0 * ( wslpj(ji+1,jj,jk) + wslpj(ji,jj,jk) )
                !
-               zmkt = 1./MAX(  tmask(ji,jj,jk-1)+tmask(ji+1,jj,jk-1)   &
-                             + tmask(ji,jj,jk  )+tmask(ji+1,jj,jk  ), 1. )
-               zmkf = 1./MAX(  fmask(ji,jj-1,jk-1) + fmask(ji,jj,jk-1)   &
-                             + fmask(ji,jj-1,jk  ) + fmask(ji,jj,jk  ), 1. )
-
-               zcoef3 = - e2u(ji,jj) * zmkt * zuwslpi
-               zcoef4 = - e1u(ji,jj) * zmkf * zuwslpj
+               zmkt = 1./MAX(  tmask(ji,jj,jk-1)+tmask(ji+1,jj,jk-1)      &
+                             + tmask(ji,jj,jk  )+tmask(ji+1,jj,jk  ) , 1. )
+               zmkf = 1./MAX(  fmask(ji,jj-1,jk-1) + fmask(ji,jj,jk-1)      &
+                             + fmask(ji,jj-1,jk  ) + fmask(ji,jj,jk  ) , 1. )
+
+               zcof3 = - e2u(ji,jj) * zmkt * zuwslpi
+               zcof4 = - e1u(ji,jj) * zmkf * zuwslpj
                ! vertical flux on u field
-               zfuw(ji,jk) = zcoef3 * ( zdiu (ji,jk-1) + zdiu (ji+1,jk-1)     &
-                                       +zdiu (ji,jk  ) + zdiu (ji+1,jk  ) )   &
-                           + zcoef4 * ( zdj1u(ji,jk-1) + zdju (ji  ,jk-1)     &
-                                       +zdj1u(ji,jk  ) + zdju (ji  ,jk  ) )
-               ! update avmu (add isopycnal vertical coefficient to avmu)
-               ! Caution: zcoef0 include rn_aht_0, so divided by rn_aht_0 to obtain slp^2 * rn_aht_0
-               avmu(ji,jj,jk) = avmu(ji,jj,jk) + ( zuwslpi * zuwslpi + zuwslpj * zuwslpj ) / rn_aht_0
+               zfuw(ji,jk) = zcof3 * (  zdiu (ji,jk-1) + zdiu (ji+1,jk-1)      &
+                  &                   + zdiu (ji,jk  ) + zdiu (ji+1,jk  )  )   &
+                  &        + zcof4 * (  zdj1u(ji,jk-1) + zdju (ji  ,jk-1)      &
+                  &                   + zdj1u(ji,jk  ) + zdju (ji  ,jk  )  )
+               ! vertical mixing coefficient (akzu)
+               ! Note: zcof0 include rn_aht_0, so divided by rn_aht_0 to obtain slp^2 * rn_aht_0
+               akzu(ji,jj,jk) = ( zuwslpi * zuwslpi + zuwslpj * zuwslpj ) / rn_aht_0
             END DO
          END DO
@@ -374,24 +365,24 @@
          DO jk = 2, jpkm1
             DO ji = 2, jpim1
-               zcoef0 = 0.5 * rn_aht_0 * vmask(ji,jj,jk)
-
-               zvwslpi = zcoef0 * ( wslpi(ji,jj+1,jk) + wslpi(ji,jj,jk) )
-               zvwslpj = zcoef0 * ( wslpj(ji,jj+1,jk) + wslpj(ji,jj,jk) )
-
-               zmkf = 1./MAX(  fmask(ji-1,jj,jk-1)+fmask(ji,jj,jk-1)   &
-                             + fmask(ji-1,jj,jk  )+fmask(ji,jj,jk  ), 1. )
-               zmkt = 1./MAX(  tmask(ji,jj,jk-1)+tmask(ji,jj+1,jk-1)   &
-                             + tmask(ji,jj,jk  )+tmask(ji,jj+1,jk  ), 1. )
-
-               zcoef3 = - e2v(ji,jj) * zmkf * zvwslpi
-               zcoef4 = - e1v(ji,jj) * zmkt * zvwslpj
+               zcof0 = 0.5_wp * rn_aht_0 * vmask(ji,jj,jk)
+               !
+               zvwslpi = zcof0 * ( wslpi(ji,jj+1,jk) + wslpi(ji,jj,jk) )
+               zvwslpj = zcof0 * ( wslpj(ji,jj+1,jk) + wslpj(ji,jj,jk) )
+               !
+               zmkf = 1./MAX(  fmask(ji-1,jj,jk-1)+fmask(ji,jj,jk-1)      &
+                  &          + fmask(ji-1,jj,jk  )+fmask(ji,jj,jk  ) , 1. )
+               zmkt = 1./MAX(  tmask(ji,jj,jk-1)+tmask(ji,jj+1,jk-1)      &
+                  &          + tmask(ji,jj,jk  )+tmask(ji,jj+1,jk  ) , 1. )
+
+               zcof3 = - e2v(ji,jj) * zmkf * zvwslpi
+               zcof4 = - e1v(ji,jj) * zmkt * zvwslpj
                ! vertical flux on v field
-               zfvw(ji,jk) = zcoef3 * ( zdiv (ji,jk-1) + zdiv (ji-1,jk-1)     &
-                  &                    +zdiv (ji,jk  ) + zdiv (ji-1,jk  ) )   &
-                  &        + zcoef4 * ( zdjv (ji,jk-1) + zdj1v(ji  ,jk-1)     &
-                  &                    +zdjv (ji,jk  ) + zdj1v(ji  ,jk  ) )
-               ! update avmv (add isopycnal vertical coefficient to avmv)
-               ! Caution: zcoef0 include rn_aht_0, so divided by rn_aht_0 to obtain slp^2 * rn_aht_0
-               avmv(ji,jj,jk) = avmv(ji,jj,jk) + ( zvwslpi * zvwslpi + zvwslpj * zvwslpj ) / rn_aht_0
+               zfvw(ji,jk) = zcof3 * (  zdiv (ji,jk-1) + zdiv (ji-1,jk-1)      &
+                  &                   + zdiv (ji,jk  ) + zdiv (ji-1,jk  )  )   &
+                  &        + zcof4 * (  zdjv (ji,jk-1) + zdj1v(ji  ,jk-1)      &
+                  &                   + zdjv (ji,jk  ) + zdj1v(ji  ,jk  )  )
+               ! vertical mixing coefficient (akzv)
+               ! Note: zcof0 include rn_aht_0, so divided by rn_aht_0 to obtain slp^2 * rn_aht_0
+               akzv(ji,jj,jk) = ( zvwslpi * zvwslpi + zvwslpj * zvwslpj ) / rn_aht_0
             END DO
          END DO
@@ -409,7 +400,6 @@
       END DO                                           !   End of slab
       !                                                ! ===============
-      CALL wrk_dealloc( jpi, jpj, ziut, zjuf, zjvt, zivf, zdku, zdk1u, zdkv, zdk1v ) 
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_ldf_iso')
+      IF( ln_timing )   CALL timing_stop('dyn_ldf_iso')
       !
    END SUBROUTINE dyn_ldf_iso
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_lap_blp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_lap_blp.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynldf_lap_blp.F90	(revision 9019)
@@ -19,5 +19,4 @@
    USE in_out_manager ! I/O manager
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
 
@@ -31,5 +30,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -57,5 +56,5 @@
       REAL(wp) ::   zsign        ! local scalars
       REAL(wp) ::   zua, zva     ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:) ::  zcur, zdiv
+      REAL(wp), DIMENSION(jpi,jpj) ::   zcur, zdiv
       !!----------------------------------------------------------------------
       !
@@ -66,7 +65,5 @@
       ENDIF
       !
-      IF( nn_timing == 1 )   CALL timing_start('dyn_ldf_lap')
-      !
-      CALL wrk_alloc( jpi, jpj, zcur, zdiv ) 
+      IF( ln_timing )   CALL timing_start('dyn_ldf_lap')
       !
       IF( kpass == 1 ) THEN   ;   zsign =  1._wp      ! bilaplacian operator require a minus sign
@@ -107,7 +104,6 @@
       END DO                                           !   End of slab
       !                                                ! ===============
-      CALL wrk_dealloc( jpi, jpj, zcur, zdiv ) 
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_ldf_lap')
+      IF( ln_timing )   CALL timing_stop('dyn_ldf_lap')
       !
    END SUBROUTINE dyn_ldf_lap
@@ -131,10 +127,8 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pua, pva   ! momentum trend
       !
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zulap, zvlap   ! laplacian at u- and v-point
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zulap, zvlap   ! laplacian at u- and v-point
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_ldf_blp')
-      !
-      CALL wrk_alloc( jpi, jpj, jpk, zulap, zvlap ) 
+      IF( ln_timing )   CALL timing_start('dyn_ldf_blp')
       !
       IF( kt == nit000 )  THEN
@@ -154,7 +148,5 @@
       CALL dyn_ldf_lap( kt, zulap, zvlap, pua, pva, 2 )   ! rotated laplacian applied to zlap (output in pta)
       !
-      CALL wrk_dealloc( jpi, jpj, jpk, zulap, zvlap ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_ldf_blp')
+      IF( ln_timing )   CALL timing_stop('dyn_ldf_blp')
       !
    END SUBROUTINE dyn_ldf_blp
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 9019)
@@ -44,5 +44,4 @@
    USE lbclnk         ! lateral boundary condition (or mpp link)
    USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory Allocation
    USE prtctl         ! Print control
    USE timing         ! Timing
@@ -57,5 +56,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -97,12 +96,11 @@
       REAL(wp) ::   zue3a, zue3n, zue3b, zuf, zcoef    ! local scalars
       REAL(wp) ::   zve3a, zve3n, zve3b, zvf, z1_2dt   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:)   ::  zue, zve
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ze3u_f, ze3v_f, zua, zva 
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:)   ::   zue, zve
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ze3u_f, ze3v_f, zua, zva 
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start('dyn_nxt')
-      !
-      IF( ln_dynspg_ts       )   CALL wrk_alloc( jpi,jpj,       zue, zve)
-      IF( l_trddyn           )   CALL wrk_alloc( jpi,jpj,jpk,   zua, zva)
+      IF( ln_timing    )   CALL timing_start('dyn_nxt')
+      IF( ln_dynspg_ts )   ALLOCATE( zue(jpi,jpj)     , zve(jpi,jpj)     )
+      IF( l_trddyn     )   ALLOCATE( zua(jpi,jpj,jpk) , zva(jpi,jpj,jpk) )
       !
       IF( kt == nit000 ) THEN
@@ -253,5 +251,5 @@
             ELSE                          ! Asselin filter applied on thickness weighted velocity
                !
-               CALL wrk_alloc( jpi,jpj,jpk,   ze3u_f, ze3v_f )
+               ALLOCATE( ze3u_f(jpi,jpj,jpk) , ze3v_f(jpi,jpj,jpk) )
                ! Before filtered scale factor at (u/v)-points stored in ze3u_f, ze3v_f
                CALL dom_vvl_interpol( e3t_b(:,:,:), ze3u_f, 'U' )
@@ -280,5 +278,5 @@
                e3v_b(:,:,1:jpkm1) = ze3v_f(:,:,1:jpkm1)
                !
-               CALL wrk_dealloc( jpi,jpj,jpk,   ze3u_f, ze3v_f )
+               DEALLOCATE( ze3u_f , ze3v_f )
             ENDIF
             !
@@ -346,8 +344,7 @@
          &                       tab3d_2=vn, clinfo2=' Vn: '       , mask2=vmask )
       ! 
-      IF( ln_dynspg_ts )   CALL wrk_dealloc( jpi,jpj,       zue, zve )
-      IF( l_trddyn     )   CALL wrk_dealloc( jpi,jpj,jpk,   zua, zva )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_nxt')
+      IF( ln_dynspg_ts )   DEALLOCATE( zue, zve )
+      IF( l_trddyn     )   DEALLOCATE( zua, zva )
+      IF( ln_timing    )   CALL timing_stop('dyn_nxt')
       !
    END SUBROUTINE dyn_nxt
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg.F90	(revision 9019)
@@ -17,4 +17,5 @@
    USE phycst         ! physical constants
    USE sbc_oce        ! surface boundary condition: ocean
+   USE sbc_ice , ONLY : snwice_mass, snwice_mass_b
    USE sbcapr         ! surface boundary condition: atmospheric pressure
    USE dynspg_exp     ! surface pressure gradient     (dyn_spg_exp routine)
@@ -28,5 +29,4 @@
    USE in_out_manager ! I/O manager
    USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
 
@@ -47,5 +47,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.2 , LODYC-IPSL  (2009)
+   !! NEMO/OPA 4.0 , LODYC-IPSL  (2017)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -71,16 +71,16 @@
       !!             period is used to prevent the divergence of odd and even time step.
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in   ) ::   kt       ! ocean time-step index
-      !
-      INTEGER  ::   ji, jj, jk                             ! dummy loop indices
-      REAL(wp) ::   z2dt, zg_2, zintp, zgrau0r             ! temporary scalar
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrdu, ztrdv
-      REAL(wp), POINTER, DIMENSION(:,:)   ::  zpice
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_spg')
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      INTEGER  ::   ji, jj, jk                   ! dummy loop indices
+      REAL(wp) ::   z2dt, zg_2, zintp, zgrau0r   ! local scalars
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:)   ::   zpice
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrdu, ztrdv
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('dyn_spg')
       !
       IF( l_trddyn )   THEN                      ! temporary save of ta and sa trends
-         CALL wrk_alloc( jpi,jpj,jpk,   ztrdu, ztrdv ) 
+         ALLOCATE( ztrdu(jpi,jpj,jpk) , ztrdv(jpi,jpj,jpk) ) 
          ztrdu(:,:,:) = ua(:,:,:)
          ztrdv(:,:,:) = va(:,:,:)
@@ -89,5 +89,5 @@
       IF(      ln_apr_dyn                                                &   ! atmos. pressure
          .OR.  ( .NOT.ln_dynspg_ts .AND. (ln_tide_pot .AND. ln_tide) )   &   ! tide potential (no time slitting)
-         .OR.  nn_ice_embd == 2  ) THEN                                      ! embedded sea-ice
+         .OR.  ln_ice_embd ) THEN                                            ! embedded sea-ice
          !
          DO jj = 2, jpjm1
@@ -103,7 +103,7 @@
                DO ji = fs_2, fs_jpim1   ! vector opt.
                   spgu(ji,jj) = spgu(ji,jj) + zg_2 * (  ssh_ib (ji+1,jj) - ssh_ib (ji,jj)    &
-                     &                      + ssh_ibb(ji+1,jj) - ssh_ibb(ji,jj)  ) * r1_e1u(ji,jj)
+                     &                                + ssh_ibb(ji+1,jj) - ssh_ibb(ji,jj)  ) * r1_e1u(ji,jj)
                   spgv(ji,jj) = spgv(ji,jj) + zg_2 * (  ssh_ib (ji,jj+1) - ssh_ib (ji,jj)    &
-                     &                      + ssh_ibb(ji,jj+1) - ssh_ibb(ji,jj)  ) * r1_e2v(ji,jj)
+                     &                                + ssh_ibb(ji,jj+1) - ssh_ibb(ji,jj)  ) * r1_e2v(ji,jj)
                END DO
             END DO
@@ -123,7 +123,6 @@
          ENDIF
          !
-         IF( nn_ice_embd == 2 ) THEN          !== embedded sea ice: Pressure gradient due to snow-ice mass ==!
-            CALL wrk_alloc( jpi,jpj,   zpice )
-            !                                            
+         IF( ln_ice_embd ) THEN              !== embedded sea ice: Pressure gradient due to snow-ice mass ==!
+            ALLOCATE( zpice(jpi,jpj) )
             zintp = REAL( MOD( kt-1, nn_fsbc ) ) / REAL( nn_fsbc )
             zgrau0r     = - grav * r1_rau0
@@ -135,6 +134,5 @@
                END DO
             END DO
-            !
-            CALL wrk_dealloc( jpi,jpj,   zpice )         
+            DEALLOCATE( zpice )         
          ENDIF
          !
@@ -161,5 +159,5 @@
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
          CALL trd_dyn( ztrdu, ztrdv, jpdyn_spg, kt )
-         CALL wrk_dealloc( jpi,jpj,jpk,   ztrdu, ztrdv ) 
+         DEALLOCATE( ztrdu , ztrdv ) 
       ENDIF
       !                                      ! print mean trends (used for debugging)
@@ -167,5 +165,5 @@
          &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_spg')
+      IF( ln_timing )   CALL timing_stop('dyn_spg')
       !
    END SUBROUTINE dyn_spg
@@ -186,5 +184,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_spg_init')
+      IF( ln_timing )   CALL timing_start('dyn_spg_init')
       !
       REWIND( numnam_ref )              ! Namelist namdyn_spg in reference namelist : Free surface
@@ -227,5 +225,5 @@
       ENDIF
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_spg_init')
+      IF( ln_timing )   CALL timing_stop('dyn_spg_init')
       !
    END SUBROUTINE dyn_spg_init
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90	(revision 9019)
@@ -61,5 +61,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_spg_exp')
+      IF( ln_timing )   CALL timing_start('dyn_spg_exp')
       !
       IF( kt == nit000 ) THEN
@@ -93,5 +93,5 @@
       ENDIF
       !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_spg_exp')
+      IF( ln_timing )   CALL timing_stop('dyn_spg_exp')
       !
    END SUBROUTINE dyn_spg_exp
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 9019)
@@ -16,4 +16,5 @@
    !!             3.7  ! 2015-11  (J. Chanut) free surface simplification
    !!              -   ! 2016-12  (G. Madec, E. Clementi) update for Stoke-Drift divergence
+   !!             4.0  ! 2017-05  (G. Madec)  drag coef. defined at t-point (zdfdrg.F90)
    !!---------------------------------------------------------------------
 
@@ -27,5 +28,6 @@
    USE dom_oce         ! ocean space and time domain
    USE sbc_oce         ! surface boundary condition: ocean
-   USE zdf_oce         ! Bottom friction coefts
+   USE zdf_oce         ! vertical physics: variables
+   USE zdfdrg          ! vertical physics: top/bottom drag coef.
    USE sbcisf          ! ice shelf variable (fwfisf)
    USE sbcapr          ! surface boundary condition: atmospheric pressure
@@ -40,4 +42,11 @@
    USE updtide         ! tide potential
    USE sbcwave         ! surface wave
+   USE diatmb          ! Top,middle,bottom output
+#if defined key_agrif
+   USE agrif_opa_interp ! agrif
+#endif
+#if defined key_asminc   
+   USE asminc          ! Assimilation increment
+#endif
    !
    USE in_out_manager  ! I/O manager
@@ -47,14 +56,5 @@
    USE iom             ! IOM library
    USE restart         ! only for lrst_oce
-   USE wrk_nemo        ! Memory Allocation
    USE timing          ! Timing    
-   USE diatmb          ! Top,middle,bottom output
-#if defined key_agrif
-   USE agrif_opa_interp ! agrif
-#endif
-#if defined key_asminc   
-   USE asminc          ! Assimilation increment
-#endif
-
 
    IMPLICIT NONE
@@ -66,20 +66,24 @@
    PUBLIC ts_rst            !    "      "     "    "
 
-   INTEGER, SAVE :: icycle  ! Number of barotropic sub-steps for each internal step nn_baro <= 2.5 nn_baro
-   REAL(wp),SAVE :: rdtbt   ! Barotropic time step
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::   wgtbtp1, wgtbtp2   !: 1st & 2nd weights used in time filtering of barotropic fields
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  zwz          !: ff_f/h at F points
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ftnw, ftne   !: triad of coriolis parameter
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ftsw, ftse   !: (only used with een vorticity scheme)
-
    !! Time filtered arrays at baroclinic time step:
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   un_adv , vn_adv     !: Advection vel. at "now" barocl. step
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   un_adv , vn_adv   !: Advection vel. at "now" barocl. step
+
+   INTEGER , SAVE ::   icycle   ! Number of barotropic sub-steps for each internal step nn_baro <= 2.5 nn_baro
+   REAL(wp), SAVE ::   rdtbt    ! Barotropic time step
+   !
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:)   ::   wgtbtp1, wgtbtp2   ! 1st & 2nd weights used in time filtering of barotropic fields
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  zwz                 ! ff_f/h at F points
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ftnw, ftne          ! triad of coriolis parameter
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ftsw, ftse          ! (only used with een vorticity scheme)
+
+   REAL(wp) ::   r1_12 = 1._wp / 12._wp   ! local ratios
+   REAL(wp) ::   r1_8  = 0.125_wp         !
+   REAL(wp) ::   r1_4  = 0.25_wp          !
+   REAL(wp) ::   r1_2  = 0.5_wp           !
 
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.5 , NEMO Consortium (2013)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -137,45 +141,31 @@
       INTEGER, INTENT(in)  ::   kt   ! ocean time-step index
       !
-      LOGICAL  ::   ll_fw_start			! if true, forward integration 
-      LOGICAL  ::   ll_init			    ! if true, special startup of 2d equations
-      LOGICAL  ::   ll_tmp1, ll_tmp2            ! local logical variables used in W/D
       INTEGER  ::   ji, jj, jk, jn   		! dummy loop indices
-      INTEGER  ::   ikbu, ikbv, noffset    	! local integers
-      INTEGER  ::   iktu, iktv             	! local integers
-      REAL(wp) ::   zmdi
-      REAL(wp) ::   zraur, z1_2dt_b, z2dt_bf  	! local scalars
-      REAL(wp) ::   zx1, zy1, zx2, zy2          !   -      -
-      REAL(wp) ::   z1_12, z1_8, z1_4, z1_2 	!   -      -
-      REAL(wp) ::   zu_spg, zv_spg              !   -      -
-      REAL(wp) ::   zhura, zhvra         	!   -      -
-      REAL(wp) ::   za0, za1, za2, za3		!   -      -
-      !
-      REAL(wp), POINTER, DIMENSION(:,:) :: zsshp2_e
-      REAL(wp), POINTER, DIMENSION(:,:) :: zu_trd, zv_trd, zu_frc, zv_frc, zssh_frc
-      REAL(wp), POINTER, DIMENSION(:,:) :: zwx, zwy, zhdiv
-      REAL(wp), POINTER, DIMENSION(:,:) :: zhup2_e, zhvp2_e, zhust_e, zhvst_e
-      REAL(wp), POINTER, DIMENSION(:,:) :: zsshu_a, zsshv_a
-      REAL(wp), POINTER, DIMENSION(:,:) :: zhf
-      REAL(wp), POINTER, DIMENSION(:,:) :: zcpx, zcpy                 ! Wetting/Dying gravity filter coef.
+      LOGICAL  ::   ll_fw_start           ! =T : forward integration 
+      LOGICAL  ::   ll_init			      ! =T : special startup of 2d equations
+      LOGICAL  ::   ll_tmp1, ll_tmp2      ! local logical variables used in W/D
+      INTEGER  ::   ikbu, iktu, noffset   ! local integers
+      INTEGER  ::   ikbv, iktv            !   -      -
+      REAL(wp) ::   z1_2dt_b, z2dt_bf  	   ! local scalars
+      REAL(wp) ::   zx1, zx2, zu_spg, zhura  !   -      -
+      REAL(wp) ::   zy1, zy2, zv_spg, zhvra  !   -      -
+      REAL(wp) ::   za0, za1, za2, za3       !   -      -
+      REAL(wp) ::   zmdi, zztmp              !   -      -
+      REAL(wp), DIMENSION(jpi,jpj) :: zsshp2_e, zhf
+      REAL(wp), DIMENSION(jpi,jpj) :: zwx, zu_trd, zu_frc, zssh_frc
+      REAL(wp), DIMENSION(jpi,jpj) :: zwy, zv_trd, zv_frc, zhdiv
+      REAL(wp), DIMENSION(jpi,jpj) :: zsshu_a, zhup2_e, zhust_e
+      REAL(wp), DIMENSION(jpi,jpj) :: zsshv_a, zhvp2_e, zhvst_e
+      REAL(wp), DIMENSION(jpi,jpj) :: zCdU_u, zCdU_v   ! top/bottom stress at u- & v-points
+      !
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: zcpx, zcpy   ! Wetting/Dying gravity filter coef.
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_spg_ts')
-      !
-      !                                         !* Allocate temporary arrays
-      CALL wrk_alloc( jpi,jpj,   zsshp2_e, zhdiv )
-      CALL wrk_alloc( jpi,jpj,   zu_trd, zv_trd)
-      CALL wrk_alloc( jpi,jpj,   zwx, zwy, zssh_frc, zu_frc, zv_frc)
-      CALL wrk_alloc( jpi,jpj,   zhup2_e, zhvp2_e, zhust_e, zhvst_e)
-      CALL wrk_alloc( jpi,jpj,   zsshu_a, zsshv_a                  )
-      CALL wrk_alloc( jpi,jpj,   zhf )
-      IF( ln_wd ) CALL wrk_alloc( jpi, jpj, zcpx, zcpy )
+      IF( ln_timing )   CALL timing_start('dyn_spg_ts')
+      !
+      IF( ln_wd ) ALLOCATE( zcpx(jpi,jpj), zcpy(jpi,jpj) )
       !
       zmdi=1.e+20                               !  missing data indicator for masking
-      !                                         !* Local constant initialization
-      z1_12 = 1._wp / 12._wp 
-      z1_8  = 0.125_wp                                   
-      z1_4  = 0.25_wp
-      z1_2  = 0.5_wp     
-      zraur = 1._wp / rau0
+      !
       !  	                                       ! reciprocal of baroclinic time step 
       IF( kt == nit000 .AND. neuler == 0 ) THEN   ;   z2dt_bf =          rdt
@@ -210,4 +200,20 @@
          CALL ts_wgt( ln_bt_av, ll_fw_start, icycle, wgtbtp1, wgtbtp2 )
          !
+      ENDIF
+      !
+      IF( ln_isfcav ) THEN    ! top+bottom friction (ocean cavities)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zCdU_u(ji,jj) = 0.5*( rCdU_bot(ji+1,jj)+rCdU_bot(ji,jj) + rCdU_top(ji+1,jj)+rCdU_top(ji,jj) )
+               zCdU_v(ji,jj) = 0.5*( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj) + rCdU_top(ji,jj+1)+rCdU_top(ji,jj) )
+            END DO
+         END DO
+      ELSE                    ! bottom friction only
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zCdU_u(ji,jj) = 0.5*( rCdU_bot(ji+1,jj)+rCdU_bot(ji,jj) )
+               zCdU_v(ji,jj) = 0.5*( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj) )
+            END DO
+         END DO
       ENDIF
       !
@@ -263,5 +269,5 @@
 !!gm 
 !!            
-              IF ( .not. ln_sco ) THEN
+              IF( .NOT.ln_sco ) THEN
   
    !!gm  agree the JC comment  : this should be done in a much clear way
@@ -314,5 +320,5 @@
       IF (.NOT.ln_bt_fw .AND.( neuler==0 .AND. kt==nit000+1 ) ) THEN
          ll_fw_start=.FALSE.
-         CALL ts_wgt(ln_bt_av, ll_fw_start, icycle, wgtbtp1, wgtbtp2)
+         CALL ts_wgt( ln_bt_av, ll_fw_start, icycle, wgtbtp1, wgtbtp2 )
       ENDIF
                           
@@ -363,6 +369,6 @@
                zx2 = ( zwx(ji  ,jj) + zwx(ji  ,jj+1) ) * r1_e2v(ji,jj)
                ! energy conserving formulation for planetary vorticity term
-               zu_trd(ji,jj) = z1_4 * ( zwz(ji  ,jj-1) * zy1 + zwz(ji,jj) * zy2 )
-               zv_trd(ji,jj) =-z1_4 * ( zwz(ji-1,jj  ) * zx1 + zwz(ji,jj) * zx2 )
+               zu_trd(ji,jj) =   r1_4 * ( zwz(ji  ,jj-1) * zy1 + zwz(ji,jj) * zy2 )
+               zv_trd(ji,jj) = - r1_4 * ( zwz(ji-1,jj  ) * zx1 + zwz(ji,jj) * zx2 )
             END DO
          END DO
@@ -371,7 +377,7 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zy1 =   z1_8 * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1) &
+               zy1 =   r1_8 * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1) &
                  &            + zwy(ji  ,jj  ) + zwy(ji+1,jj  ) ) * r1_e1u(ji,jj)
-               zx1 = - z1_8 * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1) &
+               zx1 = - r1_8 * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1) &
                  &            + zwx(ji  ,jj  ) + zwx(ji  ,jj+1) ) * r1_e2v(ji,jj)
                zu_trd(ji,jj)  = zy1 * ( zwz(ji  ,jj-1) + zwz(ji,jj) )
@@ -383,9 +389,9 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zu_trd(ji,jj) = + z1_12 * r1_e1u(ji,jj) * (  ftne(ji,jj  ) * zwy(ji  ,jj  ) &
+               zu_trd(ji,jj) = + r1_12 * r1_e1u(ji,jj) * (  ftne(ji,jj  ) * zwy(ji  ,jj  ) &
                 &                                         + ftnw(ji+1,jj) * zwy(ji+1,jj  ) &
                 &                                         + ftse(ji,jj  ) * zwy(ji  ,jj-1) &
                 &                                         + ftsw(ji+1,jj) * zwy(ji+1,jj-1) )
-               zv_trd(ji,jj) = - z1_12 * r1_e2v(ji,jj) * (  ftsw(ji,jj+1) * zwx(ji-1,jj+1) &
+               zv_trd(ji,jj) = - r1_12 * r1_e2v(ji,jj) * (  ftsw(ji,jj+1) * zwx(ji-1,jj+1) &
                 &                                         + ftse(ji,jj+1) * zwx(ji  ,jj+1) &
                 &                                         + ftnw(ji,jj  ) * zwx(ji-1,jj  ) &
@@ -399,66 +405,65 @@
       !                                   ! ----------------------------------------------------
       IF( .NOT.ln_linssh ) THEN                 ! Variable volume : remove surface pressure gradient
-        IF( ln_wd ) THEN                        ! Calculating and applying W/D gravity filters
-           DO jj = 2, jpjm1
-              DO ji = 2, jpim1 
-                ll_tmp1 = MIN(   sshn(ji,jj)               ,   sshn(ji+1,jj) ) >                &
-                     &    MAX( -ht_wd(ji,jj)               , -ht_wd(ji+1,jj) ) .AND.            &
-                     &    MAX(   sshn(ji,jj) + ht_wd(ji,jj),   sshn(ji+1,jj) + ht_wd(ji+1,jj) ) &
+         IF( ln_wd ) THEN                        ! Calculating and applying W/D gravity filters
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1 
+                  ll_tmp1 = MIN(   sshn(ji,jj)               ,   sshn(ji+1,jj) ) >                &
+                     &      MAX( -ht_wd(ji,jj)               , -ht_wd(ji+1,jj) ) .AND.            &
+                     &      MAX(   sshn(ji,jj) + ht_wd(ji,jj),   sshn(ji+1,jj) + ht_wd(ji+1,jj) ) &
                      &                                                         > rn_wdmin1 + rn_wdmin2
-                ll_tmp2 = ( ABS( sshn(ji+1,jj)             -   sshn(ji  ,jj))  > 1.E-12 ).AND.( &
-                     &    MAX(   sshn(ji,jj)               ,   sshn(ji+1,jj) ) >                &
-                     &    MAX( -ht_wd(ji,jj)               , -ht_wd(ji+1,jj) ) + rn_wdmin1 + rn_wdmin2 )
-   
-                IF(ll_tmp1) THEN
-                  zcpx(ji,jj) = 1.0_wp
-                ELSE IF(ll_tmp2) THEN
-                  ! no worries about  sshn(ji+1,jj) -  sshn(ji  ,jj) = 0, it won't happen ! here
-                  zcpx(ji,jj) = ABS( (sshn(ji+1,jj) + ht_wd(ji+1,jj) - sshn(ji,jj) - ht_wd(ji,jj)) &
-                              &    / (sshn(ji+1,jj) -  sshn(ji  ,jj)) )
-                ELSE
-                  zcpx(ji,jj) = 0._wp
-                END IF
-         
-                ll_tmp1 = MIN(   sshn(ji,jj)               ,   sshn(ji,jj+1) ) >                &
+                  ll_tmp2 = ( ABS( sshn(ji+1,jj)             -   sshn(ji  ,jj))  > 1.E-12 ).AND.( &
+                     &      MAX(   sshn(ji,jj)               ,   sshn(ji+1,jj) ) >                &
+                     &      MAX( -ht_wd(ji,jj)               , -ht_wd(ji+1,jj) ) + rn_wdmin1 + rn_wdmin2 )
+                     !
+                  IF(ll_tmp1) THEN
+                     zcpx(ji,jj) = 1.0_wp
+                  ELSE IF(ll_tmp2) THEN   ! no worries about  sshn(ji+1,jj) -  sshn(ji  ,jj) = 0, it won't happen ! here
+                     zcpx(ji,jj) = ABS( (sshn(ji+1,jj) + ht_wd(ji+1,jj) - sshn(ji,jj) - ht_wd(ji,jj)) &
+                        &             / (sshn(ji+1,jj) -  sshn(ji  ,jj)) )
+                  ELSE
+                     zcpx(ji,jj) = 0._wp
+                  ENDIF
+                  !
+                  ll_tmp1 = MIN(   sshn(ji,jj)               ,   sshn(ji,jj+1) ) >                &
                      &    MAX( -ht_wd(ji,jj)               , -ht_wd(ji,jj+1) ) .AND.            &
                      &    MAX(   sshn(ji,jj) + ht_wd(ji,jj),   sshn(ji,jj+1) + ht_wd(ji,jj+1) ) &
                      &                                                         > rn_wdmin1 + rn_wdmin2
-                ll_tmp2 = ( ABS( sshn(ji,jj)               -   sshn(ji,jj+1))  > 1.E-12 ).AND.( &
+                  ll_tmp2 = ( ABS( sshn(ji,jj)               -   sshn(ji,jj+1))  > 1.E-12 ).AND.( &
                      &    MAX(   sshn(ji,jj)               ,   sshn(ji,jj+1) ) >                &
                      &    MAX( -ht_wd(ji,jj)               , -ht_wd(ji,jj+1) ) + rn_wdmin1 + rn_wdmin2 )
-   
-                IF(ll_tmp1) THEN
-                  zcpy(ji,jj) = 1.0_wp
-                ELSE IF(ll_tmp2) THEN
-                  ! no worries about  sshn(ji,jj+1) -  sshn(ji,jj  ) = 0, it won't happen ! here
-                  zcpy(ji,jj) = ABS( (sshn(ji,jj+1) + ht_wd(ji,jj+1) - sshn(ji,jj) - ht_wd(ji,jj)) &
-                              &    / (sshn(ji,jj+1) -  sshn(ji,jj  )) )
-                ELSE
-                  zcpy(ji,jj) = 0._wp
-                END IF
-              END DO
-           END DO
- 
-           DO jj = 2, jpjm1
-              DO ji = 2, jpim1
-                 zu_trd(ji,jj) = zu_trd(ji,jj) - grav * ( sshn(ji+1,jj  ) - sshn(ji  ,jj ) )   &
-                        &                        * r1_e1u(ji,jj) * zcpx(ji,jj)
-                 zv_trd(ji,jj) = zv_trd(ji,jj) - grav * ( sshn(ji  ,jj+1) - sshn(ji  ,jj ) )   &
-                        &                        * r1_e2v(ji,jj) * zcpy(ji,jj)
-              END DO
-           END DO
-
+                     !
+                  IF(ll_tmp1) THEN
+                     zcpy(ji,jj) = 1.0_wp
+                  ELSE IF(ll_tmp2) THEN
+                     ! no worries about  sshn(ji,jj+1) -  sshn(ji,jj  ) = 0, it won't happen ! here
+                     zcpy(ji,jj) = ABS( (sshn(ji,jj+1) + ht_wd(ji,jj+1) - sshn(ji,jj) - ht_wd(ji,jj)) &
+                        &             / (sshn(ji,jj+1) -  sshn(ji,jj  )) )
+                  ELSE
+                     zcpy(ji,jj) = 0._wp
+                  ENDIF
+               END DO
+            END DO
+            !
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  zu_trd(ji,jj) = zu_trd(ji,jj) - grav * ( sshn(ji+1,jj  ) - sshn(ji  ,jj ) )   &
+                     &                            * r1_e1u(ji,jj) * zcpx(ji,jj)
+                  zv_trd(ji,jj) = zv_trd(ji,jj) - grav * ( sshn(ji  ,jj+1) - sshn(ji  ,jj ) )   &
+                     &                            * r1_e2v(ji,jj) * zcpy(ji,jj)
+               END DO
+            END DO
+            !
          ELSE
-
-           DO jj = 2, jpjm1
-              DO ji = fs_2, fs_jpim1   ! vector opt.
-                 zu_trd(ji,jj) = zu_trd(ji,jj) - grav * (  sshn(ji+1,jj  ) - sshn(ji  ,jj  )  ) * r1_e1u(ji,jj)
-                 zv_trd(ji,jj) = zv_trd(ji,jj) - grav * (  sshn(ji  ,jj+1) - sshn(ji  ,jj  )  ) * r1_e2v(ji,jj) 
-              END DO
-           END DO
-        ENDIF
-
-      ENDIF
-
+            !
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zu_trd(ji,jj) = zu_trd(ji,jj) - grav * (  sshn(ji+1,jj  ) - sshn(ji  ,jj  )  ) * r1_e1u(ji,jj)
+                  zv_trd(ji,jj) = zv_trd(ji,jj) - grav * (  sshn(ji  ,jj+1) - sshn(ji  ,jj  )  ) * r1_e2v(ji,jj) 
+               END DO
+            END DO
+         ENDIF
+         !
+      ENDIF
+      !
       DO jj = 2, jpjm1                          ! Remove coriolis term (and possibly spg) from barotropic trend
          DO ji = fs_2, fs_jpim1
@@ -468,6 +473,6 @@
       END DO 
       !
-      !						! Add bottom stress contribution from baroclinic velocities:      
-      IF (ln_bt_fw) THEN
+      !						! Add BOTTOM stress contribution from baroclinic velocities:      
+      IF( ln_bt_fw ) THEN
          DO jj = 2, jpjm1                          
             DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -491,19 +496,9 @@
       ! Note that the "unclipped" bottom friction parameter is used even with explicit drag
       IF( ln_wd ) THEN
-        zu_frc(:,:) = zu_frc(:,:) + MAX(r1_hu_n(:,:) * bfrua(:,:),-1._wp / rdtbt) * zwx(:,:)
-        zv_frc(:,:) = zv_frc(:,:) + MAX(r1_hv_n(:,:) * bfrva(:,:),-1._wp / rdtbt) * zwy(:,:)
-      ELSE
-        zu_frc(:,:) = zu_frc(:,:) + r1_hu_n(:,:) * bfrua(:,:) * zwx(:,:)
-        zv_frc(:,:) = zv_frc(:,:) + r1_hv_n(:,:) * bfrva(:,:) * zwy(:,:)
-      END IF
-      !
-      !                                         ! Add top stress contribution from baroclinic velocities:      
-      IF( ln_bt_fw ) THEN
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               iktu = miku(ji,jj)
-               iktv = mikv(ji,jj)
-               zwx(ji,jj) = un(ji,jj,iktu) - un_b(ji,jj) ! NOW top baroclinic velocities
-               zwy(ji,jj) = vn(ji,jj,iktv) - vn_b(ji,jj)
+         zztmp = - 1._wp / rdtbt
+         DO jj = 2, jpjm1                          
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zu_frc(ji,jj) = zu_frc(ji,jj) + MAX( r1_hu_n(ji,jj) * 0.5*( rCdU_bot(ji+1,jj)+rCdU_bot(ji,jj) ) , zztmp ) * zwx(ji,jj)
+               zv_frc(ji,jj) = zv_frc(ji,jj) + MAX( r1_hv_n(ji,jj) * 0.5*( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj) ) , zztmp ) * zwy(ji,jj)
             END DO
          END DO
@@ -511,26 +506,59 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               iktu = miku(ji,jj)
-               iktv = mikv(ji,jj)
-               zwx(ji,jj) = ub(ji,jj,iktu) - ub_b(ji,jj) ! BEFORE top baroclinic velocities
-               zwy(ji,jj) = vb(ji,jj,iktv) - vb_b(ji,jj)
-            END DO
-         END DO
-      ENDIF
-      !
-      ! Note that the "unclipped" top friction parameter is used even with explicit drag
-      zu_frc(:,:) = zu_frc(:,:) + r1_hu_n(:,:) * tfrua(:,:) * zwx(:,:)
-      zv_frc(:,:) = zv_frc(:,:) + r1_hv_n(:,:) * tfrva(:,:) * zwy(:,:)
+               zu_frc(ji,jj) = zu_frc(ji,jj) + r1_hu_n(ji,jj) * 0.5*( rCdU_bot(ji+1,jj)+rCdU_bot(ji,jj) ) * zwx(ji,jj)
+               zv_frc(ji,jj) = zv_frc(ji,jj) + r1_hv_n(ji,jj) * 0.5*( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj) ) * zwy(ji,jj)
+            END DO
+         END DO
+      ENDIF
+      !
+      IF( ln_isfcav ) THEN       ! Add TOP stress contribution from baroclinic velocities:      
+         IF( ln_bt_fw ) THEN
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  iktu = miku(ji,jj)
+                  iktv = mikv(ji,jj)
+                  zwx(ji,jj) = un(ji,jj,iktu) - un_b(ji,jj) ! NOW top baroclinic velocities
+                  zwy(ji,jj) = vn(ji,jj,iktv) - vn_b(ji,jj)
+               END DO
+            END DO
+         ELSE
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  iktu = miku(ji,jj)
+                  iktv = mikv(ji,jj)
+                  zwx(ji,jj) = ub(ji,jj,iktu) - ub_b(ji,jj) ! BEFORE top baroclinic velocities
+                  zwy(ji,jj) = vb(ji,jj,iktv) - vb_b(ji,jj)
+               END DO
+            END DO
+         ENDIF
+         !
+         ! Note that the "unclipped" top friction parameter is used even with explicit drag
+         DO jj = 2, jpjm1              
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zu_frc(ji,jj) = zu_frc(ji,jj) + r1_hu_n(ji,jj) * 0.5*( rCdU_top(ji+1,jj)+rCdU_top(ji,jj) ) * zwx(ji,jj)
+               zv_frc(ji,jj) = zv_frc(ji,jj) + r1_hv_n(ji,jj) * 0.5*( rCdU_top(ji,jj+1)+rCdU_top(ji,jj) ) * zwy(ji,jj)
+            END DO
+         END DO
+      ENDIF
       !       
-      IF (ln_bt_fw) THEN                        ! Add wind forcing
-         zu_frc(:,:) =  zu_frc(:,:) + zraur * utau(:,:) * r1_hu_n(:,:)
-         zv_frc(:,:) =  zv_frc(:,:) + zraur * vtau(:,:) * r1_hv_n(:,:)
+      IF( ln_bt_fw ) THEN                        ! Add wind forcing
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zu_frc(ji,jj) =  zu_frc(ji,jj) + r1_rau0 * utau(ji,jj) * r1_hu_n(ji,jj)
+               zv_frc(ji,jj) =  zv_frc(ji,jj) + r1_rau0 * vtau(ji,jj) * r1_hv_n(ji,jj)
+            END DO
+         END DO
       ELSE
-         zu_frc(:,:) =  zu_frc(:,:) + zraur * z1_2 * ( utau_b(:,:) + utau(:,:) ) * r1_hu_n(:,:)
-         zv_frc(:,:) =  zv_frc(:,:) + zraur * z1_2 * ( vtau_b(:,:) + vtau(:,:) ) * r1_hv_n(:,:)
+         zztmp = r1_rau0 * r1_2
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zu_frc(ji,jj) =  zu_frc(ji,jj) + zztmp * ( utau_b(ji,jj) + utau(ji,jj) ) * r1_hu_n(ji,jj)
+               zv_frc(ji,jj) =  zv_frc(ji,jj) + zztmp * ( vtau_b(ji,jj) + vtau(ji,jj) ) * r1_hv_n(ji,jj)
+            END DO
+         END DO
       ENDIF  
       !
-      IF ( ln_apr_dyn ) THEN                    ! Add atm pressure forcing
-         IF (ln_bt_fw) THEN
+      IF( ln_apr_dyn ) THEN                     ! Add atm pressure forcing
+         IF( ln_bt_fw ) THEN
             DO jj = 2, jpjm1              
                DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -542,10 +570,11 @@
             END DO
          ELSE
+            zztmp = grav * r1_2
             DO jj = 2, jpjm1              
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zu_spg =  grav * z1_2 * (  ssh_ib (ji+1,jj  ) - ssh_ib (ji,jj)    &
-                      &                    + ssh_ibb(ji+1,jj  ) - ssh_ibb(ji,jj)  ) * r1_e1u(ji,jj)
-                  zv_spg =  grav * z1_2 * (  ssh_ib (ji  ,jj+1) - ssh_ib (ji,jj)    &
-                      &                    + ssh_ibb(ji  ,jj+1) - ssh_ibb(ji,jj)  ) * r1_e2v(ji,jj)
+                  zu_spg = zztmp * (  ssh_ib (ji+1,jj  ) - ssh_ib (ji,jj)    &
+                      &             + ssh_ibb(ji+1,jj  ) - ssh_ibb(ji,jj)  ) * r1_e1u(ji,jj)
+                  zv_spg = zztmp * (  ssh_ib (ji  ,jj+1) - ssh_ib (ji,jj)    &
+                      &             + ssh_ibb(ji  ,jj+1) - ssh_ibb(ji,jj)  ) * r1_e2v(ji,jj)
                   zu_frc(ji,jj) = zu_frc(ji,jj) + zu_spg
                   zv_frc(ji,jj) = zv_frc(ji,jj) + zv_spg
@@ -558,8 +587,9 @@
       !                                         ! Surface net water flux and rivers
       IF (ln_bt_fw) THEN
-         zssh_frc(:,:) = zraur * ( emp(:,:) - rnf(:,:) + fwfisf(:,:) )
+         zssh_frc(:,:) = r1_rau0 * ( emp(:,:) - rnf(:,:) + fwfisf(:,:) )
       ELSE
-         zssh_frc(:,:) = zraur * z1_2 * (  emp(:,:) + emp_b(:,:) - rnf(:,:) - rnf_b(:,:)   &
-                &                        + fwfisf(:,:) + fwfisf_b(:,:)                     )
+         zztmp = r1_rau0 * r1_2
+         zssh_frc(:,:) = zztmp * (  emp(:,:) + emp_b(:,:) - rnf(:,:) - rnf_b(:,:)   &
+                &                 + fwfisf(:,:) + fwfisf_b(:,:)                     )
       ENDIF
       !
@@ -657,8 +687,8 @@
             DO jj = 2, jpjm1                                    ! Sea Surface Height at u- & v-points
                DO ji = 2, fs_jpim1   ! Vector opt.
-                  zwx(ji,jj) = z1_2 * ssumask(ji,jj)  * r1_e1e2u(ji,jj)     &
+                  zwx(ji,jj) = r1_2 * ssumask(ji,jj)  * r1_e1e2u(ji,jj)     &
                      &              * ( e1e2t(ji  ,jj) * zsshp2_e(ji  ,jj)  &
                      &              +   e1e2t(ji+1,jj) * zsshp2_e(ji+1,jj) )
-                  zwy(ji,jj) = z1_2 * ssvmask(ji,jj)  * r1_e1e2v(ji,jj)     &
+                  zwy(ji,jj) = r1_2 * ssvmask(ji,jj)  * r1_e1e2v(ji,jj)     &
                      &              * ( e1e2t(ji,jj  ) * zsshp2_e(ji,jj  )  &
                      &              +   e1e2t(ji,jj+1) * zsshp2_e(ji,jj+1) )
@@ -685,21 +715,21 @@
          IF( .NOT.Agrif_Root() .AND. ln_bt_fw ) THEN
             IF((nbondi == -1).OR.(nbondi == 2)) THEN
-               DO jj=1,jpj
-                  zwx(2,jj) = ubdy_w(jj) * e2u(2,jj)
+               DO jj = 1, jpj
+                  zwx(2:nbghostcells+1,jj) = ubdy_w(jj) * e2u(2:nbghostcells+1,jj)
                END DO
             ENDIF
             IF((nbondi ==  1).OR.(nbondi == 2)) THEN
                DO jj=1,jpj
-                  zwx(nlci-2,jj) = ubdy_e(jj) * e2u(nlci-2,jj)
+                  zwx(nlci-nbghostcells-1:nlci-2,jj) = ubdy_e(jj) * e2u(nlci-nbghostcells-1:nlci-2,jj)
                END DO
             ENDIF
             IF((nbondj == -1).OR.(nbondj == 2)) THEN
                DO ji=1,jpi
-                  zwy(ji,2) = vbdy_s(ji) * e1v(ji,2)
+                  zwy(ji,2:nbghostcells+1) = vbdy_s(ji) * e1v(ji,2:nbghostcells+1)
                END DO
             ENDIF
             IF((nbondj ==  1).OR.(nbondj == 2)) THEN
                DO ji=1,jpi
-                  zwy(ji,nlcj-2) = vbdy_n(ji) * e1v(ji,nlcj-2)
+                  zwy(ji,nlcj-nbghostcells-1:nlcj-2) = vbdy_n(ji) * e1v(ji,nlcj-nbghostcells-1:nlcj-2)
                END DO
             ENDIF
@@ -734,8 +764,8 @@
             DO jj = 2, jpjm1
                DO ji = 2, jpim1      ! NO Vector Opt.
-                  zsshu_a(ji,jj) = z1_2 * ssumask(ji,jj) * r1_e1e2u(ji,jj)    &
+                  zsshu_a(ji,jj) = r1_2 * ssumask(ji,jj) * r1_e1e2u(ji,jj)    &
                      &              * ( e1e2t(ji  ,jj  )  * ssha_e(ji  ,jj  ) &
                      &              +   e1e2t(ji+1,jj  )  * ssha_e(ji+1,jj  ) )
-                  zsshv_a(ji,jj) = z1_2 * ssvmask(ji,jj) * r1_e1e2v(ji,jj)    &
+                  zsshv_a(ji,jj) = r1_2 * ssvmask(ji,jj) * r1_e1e2v(ji,jj)    &
                      &              * ( e1e2t(ji  ,jj  )  * ssha_e(ji  ,jj  ) &
                      &              +   e1e2t(ji  ,jj+1)  * ssha_e(ji  ,jj+1) )
@@ -813,8 +843,8 @@
             DO jj = 2, jpjm1                            
                DO ji = 2, jpim1
-                  zx1 = z1_2 * ssumask(ji  ,jj) *  r1_e1e2u(ji  ,jj)    &
+                  zx1 = r1_2 * ssumask(ji  ,jj) *  r1_e1e2u(ji  ,jj)    &
                      &      * ( e1e2t(ji  ,jj  ) * zsshp2_e(ji  ,jj)    &
                      &      +   e1e2t(ji+1,jj  ) * zsshp2_e(ji+1,jj  ) )
-                  zy1 = z1_2 * ssvmask(ji  ,jj) *  r1_e1e2v(ji  ,jj  )  &
+                  zy1 = r1_2 * ssvmask(ji  ,jj) *  r1_e1e2v(ji  ,jj  )  &
                      &       * ( e1e2t(ji ,jj  ) * zsshp2_e(ji  ,jj  )  &
                      &       +   e1e2t(ji ,jj+1) * zsshp2_e(ji  ,jj+1) )
@@ -840,6 +870,6 @@
                   zx1 = ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1) ) * r1_e2v(ji,jj)
                   zx2 = ( zwx(ji  ,jj  ) + zwx(ji  ,jj+1) ) * r1_e2v(ji,jj)
-                  zu_trd(ji,jj) = z1_4 * ( zwz(ji  ,jj-1) * zy1 + zwz(ji,jj) * zy2 )
-                  zv_trd(ji,jj) =-z1_4 * ( zwz(ji-1,jj  ) * zx1 + zwz(ji,jj) * zx2 )
+                  zu_trd(ji,jj) = r1_4 * ( zwz(ji  ,jj-1) * zy1 + zwz(ji,jj) * zy2 )
+                  zv_trd(ji,jj) =-r1_4 * ( zwz(ji-1,jj  ) * zx1 + zwz(ji,jj) * zx2 )
                END DO
             END DO
@@ -848,7 +878,7 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zy1 =   z1_8 * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1) &
+                  zy1 =   r1_8 * ( zwy(ji  ,jj-1) + zwy(ji+1,jj-1) &
                    &             + zwy(ji  ,jj  ) + zwy(ji+1,jj  ) ) * r1_e1u(ji,jj)
-                  zx1 = - z1_8 * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1) &
+                  zx1 = - r1_8 * ( zwx(ji-1,jj  ) + zwx(ji-1,jj+1) &
                    &             + zwx(ji  ,jj  ) + zwx(ji  ,jj+1) ) * r1_e2v(ji,jj)
                   zu_trd(ji,jj)  = zy1 * ( zwz(ji  ,jj-1) + zwz(ji,jj) )
@@ -860,9 +890,9 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zu_trd(ji,jj) = + z1_12 * r1_e1u(ji,jj) * (  ftne(ji,jj  ) * zwy(ji  ,jj  ) &
+                  zu_trd(ji,jj) = + r1_12 * r1_e1u(ji,jj) * (  ftne(ji,jj  ) * zwy(ji  ,jj  ) &
                      &                                       + ftnw(ji+1,jj) * zwy(ji+1,jj  ) &
                      &                                       + ftse(ji,jj  ) * zwy(ji  ,jj-1) & 
                      &                                       + ftsw(ji+1,jj) * zwy(ji+1,jj-1) )
-                  zv_trd(ji,jj) = - z1_12 * r1_e2v(ji,jj) * (  ftsw(ji,jj+1) * zwx(ji-1,jj+1) & 
+                  zv_trd(ji,jj) = - r1_12 * r1_e2v(ji,jj) * (  ftsw(ji,jj+1) * zwx(ji-1,jj+1) & 
                      &                                       + ftse(ji,jj+1) * zwx(ji  ,jj+1) &
                      &                                       + ftnw(ji,jj  ) * zwx(ji-1,jj  ) & 
@@ -885,14 +915,12 @@
          ENDIF
          !
-         ! Add bottom stresses:
-         zu_trd(:,:) = zu_trd(:,:) + bfrua(:,:) * un_e(:,:) * hur_e(:,:)
-         zv_trd(:,:) = zv_trd(:,:) + bfrva(:,:) * vn_e(:,:) * hvr_e(:,:)
-         !
-         ! Add top stresses:
-         zu_trd(:,:) = zu_trd(:,:) + tfrua(:,:) * un_e(:,:) * hur_e(:,:)
-         zv_trd(:,:) = zv_trd(:,:) + tfrva(:,:) * vn_e(:,:) * hvr_e(:,:)
+         DO jj = 2, jpjm1               ! Add top/bottom stresses:
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zu_trd(ji,jj) = zu_trd(ji,jj) + zCdU_u(ji,jj) * un_e(ji,jj) * hur_e(ji,jj)
+               zv_trd(ji,jj) = zv_trd(ji,jj) + zCdU_v(ji,jj) * vn_e(ji,jj) * hvr_e(ji,jj)
+            END DO
+         END DO
          !
          ! Surface pressure trend:
-
          IF( ln_wd ) THEN
            DO jj = 2, jpjm1
@@ -1025,6 +1053,6 @@
          vn_adv(:,:) = zwy(:,:) * r1_hv_n(:,:)
       ELSE
-         un_adv(:,:) = z1_2 * ( ub2_b(:,:) + zwx(:,:) ) * r1_hu_n(:,:)
-         vn_adv(:,:) = z1_2 * ( vb2_b(:,:) + zwy(:,:) ) * r1_hv_n(:,:)
+         un_adv(:,:) = r1_2 * ( ub2_b(:,:) + zwx(:,:) ) * r1_hu_n(:,:)
+         vn_adv(:,:) = r1_2 * ( vb2_b(:,:) + zwy(:,:) ) * r1_hv_n(:,:)
       END IF
 
@@ -1044,8 +1072,8 @@
          DO jj = 1, jpjm1
             DO ji = 1, jpim1      ! NO Vector Opt.
-               zsshu_a(ji,jj) = z1_2 * umask(ji,jj,1)  * r1_e1e2u(ji,jj) &
+               zsshu_a(ji,jj) = r1_2 * umask(ji,jj,1)  * r1_e1e2u(ji,jj) &
                   &              * ( e1e2t(ji  ,jj) * ssha(ji  ,jj)    &
                   &              +   e1e2t(ji+1,jj) * ssha(ji+1,jj) )
-               zsshv_a(ji,jj) = z1_2 * vmask(ji,jj,1)  * r1_e1e2v(ji,jj) &
+               zsshv_a(ji,jj) = r1_2 * vmask(ji,jj,1)  * r1_e1e2v(ji,jj) &
                   &              * ( e1e2t(ji,jj  ) * ssha(ji,jj  )    &
                   &              +   e1e2t(ji,jj+1) * ssha(ji,jj+1) )
@@ -1091,17 +1119,11 @@
       IF( lrst_oce .AND.ln_bt_fw )   CALL ts_rst( kt, 'WRITE' )
       !
-      CALL wrk_dealloc( jpi,jpj,   zsshp2_e, zhdiv )
-      CALL wrk_dealloc( jpi,jpj,   zu_trd, zv_trd )
-      CALL wrk_dealloc( jpi,jpj,   zwx, zwy, zssh_frc, zu_frc, zv_frc )
-      CALL wrk_dealloc( jpi,jpj,   zhup2_e, zhvp2_e, zhust_e, zhvst_e )
-      CALL wrk_dealloc( jpi,jpj,   zsshu_a, zsshv_a                                   )
-      CALL wrk_dealloc( jpi,jpj,   zhf )
-      IF( ln_wd ) CALL wrk_dealloc( jpi, jpj, zcpx, zcpy )
-      !
-      IF ( ln_diatmb ) THEN
+      IF( ln_wd )   DEALLOCATE( zcpx, zcpy )
+      !
+      IF( ln_diatmb ) THEN
          CALL iom_put( "baro_u" , un_b*umask(:,:,1)+zmdi*(1-umask(:,:,1 ) ) )  ! Barotropic  U Velocity
          CALL iom_put( "baro_v" , vn_b*vmask(:,:,1)+zmdi*(1-vmask(:,:,1 ) ) )  ! Barotropic  V Velocity
       ENDIF
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_spg_ts')
+      IF( ln_timing )   CALL timing_stop('dyn_spg_ts')
       !
    END SUBROUTINE dyn_spg_ts
@@ -1248,10 +1270,8 @@
       INTEGER  ::   ji ,jj              ! dummy loop indices
       REAL(wp) ::   zxr2, zyr2, zcmax   ! local scalar
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zcu
+      REAL(wp), DIMENSION(jpi,jpj) ::   zcu
       !!----------------------------------------------------------------------
       !
       ! Max courant number for ext. grav. waves
-      !
-      CALL wrk_alloc( jpi,jpj,   zcu )
       !
       DO jj = 1, jpj
@@ -1320,6 +1340,4 @@
       ENDIF
       !
-      CALL wrk_dealloc( jpi,jpj,   zcu )
-      !
    END SUBROUTINE dyn_spg_ts_init
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 9019)
@@ -14,21 +14,22 @@
    !!            2.0  ! 2006-11  (G. Madec)  flux form advection: add metric term
    !!            3.2  ! 2009-04  (R. Benshila)  vvl: correction of een scheme
-   !!            3.3  ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
-   !!            3.7  ! 2014-04  (G. Madec) trend simplification: suppress jpdyn_trd_dat vorticity 
-   !!             -   ! 2014-06  (G. Madec) suppression of velocity curl from in-core memory
+   !!            3.3  ! 2010-10  (C. Ethe, G. Madec)  reorganisation of initialisation phase
+   !!            3.7  ! 2014-04  (G. Madec)  trend simplification: suppress jpdyn_trd_dat vorticity 
+   !!             -   ! 2014-06  (G. Madec)  suppression of velocity curl from in-core memory
    !!             -   ! 2016-12  (G. Madec, E. Clementi) add Stokes-Coriolis trends (ln_stcor=T)
+   !!            4.0  ! 2017-07  (G. Madec)  linear dynamics + trends diag. with Stokes-Coriolis
    !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
-   !!   dyn_vor      : Update the momentum trend with the vorticity trend
-   !!       vor_ens  : enstrophy conserving scheme       (ln_dynvor_ens=T)
-   !!       vor_ene  : energy conserving scheme          (ln_dynvor_ene=T)
-   !!       vor_een  : energy and enstrophy conserving   (ln_dynvor_een=T)
-   !!   dyn_vor_init : set and control of the different vorticity option
+   !!   dyn_vor       : Update the momentum trend with the vorticity trend
+   !!       vor_ens   : enstrophy conserving scheme       (ln_dynvor_ens=T)
+   !!       vor_ene   : energy conserving scheme          (ln_dynvor_ene=T)
+   !!       vor_een   : energy and enstrophy conserving   (ln_dynvor_een=T)
+   !!   dyn_vor_init  : set and control of the different vorticity option
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and tracers
    USE dom_oce        ! ocean space and time domain
    USE dommsk         ! ocean mask
-   USE dynadv         ! momentum advection (use ln_dynadv_vec value)
+   USE dynadv         ! momentum advection
    USE trd_oce        ! trends: ocean variables
    USE trddyn         ! trend manager: dynamics
@@ -40,7 +41,5 @@
    USE in_out_manager ! I/O manager
    USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
-
 
    IMPLICIT NONE
@@ -80,5 +79,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2016)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -98,91 +97,61 @@
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
       !
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrdu, ztrdv
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_vor')
-      !
-      IF( l_trddyn )   CALL wrk_alloc( jpi,jpj,jpk, ztrdu, ztrdv )
-      !
-      SELECT CASE ( nvor_scheme )               !==  vorticity trend added to the general trend  ==!
-      !
-      CASE ( np_ENE )                                 !* energy conserving scheme
-         IF( l_trddyn ) THEN                                ! trend diagnostics: split the trend in two
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::  ztrdu, ztrdv
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('dyn_vor')
+      !
+      IF( l_trddyn ) THEN     !==  trend diagnostics case : split the added trend in two parts  ==!
+         !
+         ALLOCATE( ztrdu(jpi,jpj,jpk), ztrdv(jpi,jpj,jpk) )
+         !
+         ztrdu(:,:,:) = ua(:,:,:)            !* planetary vorticity trend (including Stokes-Coriolis force)
+         ztrdv(:,:,:) = va(:,:,:)
+         SELECT CASE( nvor_scheme )
+         CASE( np_ENE, np_MIX )   ;   CALL vor_ene( kt, ncor, un , vn , ua, va )   ! energy conserving scheme
+            IF( ln_stcor )            CALL vor_ene( kt, ncor, usd, vsd, ua, va )   ! add the Stokes-Coriolis trend
+         CASE( np_ENS )           ;   CALL vor_ens( kt, ncor, un , vn , ua, va )   ! enstrophy conserving scheme
+            IF( ln_stcor )            CALL vor_ens( kt, ncor, usd, vsd, ua, va )   ! add the Stokes-Coriolis trend
+         CASE( np_EEN )           ;   CALL vor_een( kt, ncor, un , vn , ua, va )   ! energy & enstrophy scheme
+            IF( ln_stcor )            CALL vor_een( kt, ncor, usd, vsd, ua, va )   ! add the Stokes-Coriolis trend
+         END SELECT
+         ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
+         ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
+         CALL trd_dyn( ztrdu, ztrdv, jpdyn_pvo, kt )
+         !
+         IF( n_dynadv /= np_LIN_dyn ) THEN   !* relative vorticity or metric trend (only in non-linear case)
             ztrdu(:,:,:) = ua(:,:,:)
             ztrdv(:,:,:) = va(:,:,:)
-            CALL vor_ene( kt, nrvm, un , vn , ua, va )                    ! relative vorticity or metric trend
+            SELECT CASE( nvor_scheme )
+            CASE( np_ENE )           ;   CALL vor_ene( kt, nrvm, un , vn , ua, va )  ! energy conserving scheme
+            CASE( np_ENS, np_MIX )   ;   CALL vor_ens( kt, nrvm, un , vn , ua, va )  ! enstrophy conserving scheme
+            CASE( np_EEN )           ;   CALL vor_een( kt, nrvm, un , vn , ua, va )  ! energy & enstrophy scheme
+            END SELECT
             ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
             ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
             CALL trd_dyn( ztrdu, ztrdv, jpdyn_rvo, kt )
-            ztrdu(:,:,:) = ua(:,:,:)
-            ztrdv(:,:,:) = va(:,:,:)
-            CALL vor_ene( kt, ncor, un , vn , ua, va )                    ! planetary vorticity trend
-            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
-            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_dyn( ztrdu, ztrdv, jpdyn_pvo, kt )
-         ELSE                                               ! total vorticity trend
+         ENDIF
+         !
+         DEALLOCATE( ztrdu, ztrdv )
+         !
+      ELSE              !==  total vorticity trend added to the general trend  ==!
+         !
+         SELECT CASE ( nvor_scheme )      !==  vorticity trend added to the general trend  ==!
+         CASE( np_ENE )                        !* energy conserving scheme
                              CALL vor_ene( kt, ntot, un , vn , ua, va )   ! total vorticity trend
             IF( ln_stcor )   CALL vor_ene( kt, ncor, usd, vsd, ua, va )   ! add the Stokes-Coriolis trend
-         ENDIF
-         !
-      CASE ( np_ENS )                                 !* enstrophy conserving scheme
-         IF( l_trddyn ) THEN                                ! trend diagnostics: splitthe trend in two    
-            ztrdu(:,:,:) = ua(:,:,:)
-            ztrdv(:,:,:) = va(:,:,:)
-            CALL vor_ens( kt, nrvm, un , vn , ua, va )            ! relative vorticity or metric trend
-            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
-            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_dyn( ztrdu, ztrdv, jpdyn_rvo, kt )
-            ztrdu(:,:,:) = ua(:,:,:)
-            ztrdv(:,:,:) = va(:,:,:)
-            CALL vor_ens( kt, ncor, un , vn , ua, va )            ! planetary vorticity trend
-            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
-            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_dyn( ztrdu, ztrdv, jpdyn_pvo, kt )
-         ELSE                                               ! total vorticity trend
+         CASE( np_ENS )                        !* enstrophy conserving scheme
                              CALL vor_ens( kt, ntot, un , vn , ua, va )  ! total vorticity trend
             IF( ln_stcor )   CALL vor_ens( kt, ncor, usd, vsd, ua, va )  ! add the Stokes-Coriolis trend
-         ENDIF
-         !
-      CASE ( np_MIX )                                 !* mixed ene-ens scheme
-         IF( l_trddyn ) THEN                                ! trend diagnostics: split the trend in two
-            ztrdu(:,:,:) = ua(:,:,:)
-            ztrdv(:,:,:) = va(:,:,:)
-            CALL vor_ens( kt, nrvm, un , vn , ua, va )            ! relative vorticity or metric trend (ens)
-            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
-            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_dyn( ztrdu, ztrdv, jpdyn_rvo, kt )
-            ztrdu(:,:,:) = ua(:,:,:)
-            ztrdv(:,:,:) = va(:,:,:)
-            CALL vor_ene( kt, ncor, un , vn , ua, va )            ! planetary vorticity trend (ene)
-            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
-            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_dyn( ztrdu, ztrdv, jpdyn_pvo, kt )
-         ELSE                                               ! total vorticity trend
+         CASE( np_MIX )                        !* mixed ene-ens scheme
                              CALL vor_ens( kt, nrvm, un , vn , ua, va )   ! relative vorticity or metric trend (ens)
                              CALL vor_ene( kt, ncor, un , vn , ua, va )   ! planetary vorticity trend (ene)
             IF( ln_stcor )   CALL vor_ene( kt, ncor, usd, vsd, ua, va )   ! add the Stokes-Coriolis trend
-        ENDIF
-         !
-      CASE ( np_EEN )                                 !* energy and enstrophy conserving scheme
-         IF( l_trddyn ) THEN                                ! trend diagnostics: split the trend in two
-            ztrdu(:,:,:) = ua(:,:,:)
-            ztrdv(:,:,:) = va(:,:,:)
-            CALL vor_een( kt, nrvm, un , vn , ua, va )            ! relative vorticity or metric trend
-            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
-            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_dyn( ztrdu, ztrdv, jpdyn_rvo, kt )
-            ztrdu(:,:,:) = ua(:,:,:)
-            ztrdv(:,:,:) = va(:,:,:)
-            CALL vor_een( kt, ncor, un , vn , ua, va )            ! planetary vorticity trend
-            ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
-            ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-            CALL trd_dyn( ztrdu, ztrdv, jpdyn_pvo, kt )
-         ELSE                                               ! total vorticity trend
+         CASE( np_EEN )                        !* energy and enstrophy conserving scheme
                              CALL vor_een( kt, ntot, un , vn , ua, va )   ! total vorticity trend
             IF( ln_stcor )   CALL vor_een( kt, ncor, usd, vsd, ua, va )   ! add the Stokes-Coriolis trend
-         ENDIF
-         !
-      END SELECT
+         END SELECT
+         !
+      ENDIF
       !
       !                       ! print sum trends (used for debugging)
@@ -190,7 +159,5 @@
          &                     tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
       !
-      IF( l_trddyn )   CALL wrk_dealloc( jpi,jpj,jpk, ztrdu, ztrdv )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_vor')
+      IF( ln_timing )   CALL timing_stop('dyn_vor')
       !
    END SUBROUTINE dyn_vor
@@ -217,18 +184,15 @@
       !! References : Sadourny, r., 1975, j. atmos. sciences, 32, 680-689.
       !!----------------------------------------------------------------------
-      INTEGER , INTENT(in   )                         ::   kt          ! ocean time-step index
-      INTEGER , INTENT(in   )                         ::   kvor        ! =ncor (planetary) ; =ntot (total) ;
-      !                                                                ! =nrvm (relative vorticity or metric)
-      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pun, pvn    ! now velocities
-      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pua, pva    ! total v-trend
+      INTEGER                         , INTENT(in   ) ::   kt          ! ocean time-step index
+      INTEGER                         , INTENT(in   ) ::   kvor        ! total, planetary, relative, or metric
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pun, pvn    ! now velocities
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pua, pva    ! total v-trend
       !
       INTEGER  ::   ji, jj, jk           ! dummy loop indices
       REAL(wp) ::   zx1, zy1, zx2, zy2   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zwx, zwy, zwz   ! 2D workspace
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('vor_ene')
-      !
-      CALL wrk_alloc( jpi,jpj,   zwx, zwy, zwz ) 
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz   ! 2D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )  CALL timing_start('vor_ene')
       !
       IF( kt == nit000 ) THEN
@@ -264,5 +228,5 @@
                DO ji = 1, fs_jpim1   ! vector opt.
                   zwz(ji,jj) = ff_f(ji,jj) + (  e2v(ji+1,jj  ) * pvn(ji+1,jj  ,jk) - e2v(ji,jj) * pvn(ji,jj,jk)    &
-                     &                      - e1u(ji  ,jj+1) * pun(ji  ,jj+1,jk) + e1u(ji,jj) * pun(ji,jj,jk)  ) &
+                     &                      - e1u(ji  ,jj+1) * pun(ji  ,jj+1,jk) + e1u(ji,jj) * pun(ji,jj,jk)  )   &
                      &                   * r1_e1e2f(ji,jj)
                END DO
@@ -311,7 +275,6 @@
       END DO                                           !   End of slab
       !                                                ! ===============
-      CALL wrk_dealloc( jpi, jpj, zwx, zwy, zwz ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('vor_ene')
+      !
+      IF( ln_timing )  CALL timing_stop('vor_ene')
       !
    END SUBROUTINE vor_ene
@@ -338,18 +301,15 @@
       !! References : Sadourny, r., 1975, j. atmos. sciences, 32, 680-689.
       !!----------------------------------------------------------------------
-      INTEGER , INTENT(in   )                         ::   kt          ! ocean time-step index
-      INTEGER , INTENT(in   )                         ::   kvor        ! =ncor (planetary) ; =ntot (total) ;
-         !                                                             ! =nrvm (relative vorticity or metric)
-      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pun, pvn    ! now velocities
-      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pua, pva    ! total v-trend
+      INTEGER                         , INTENT(in   ) ::   kt          ! ocean time-step index
+      INTEGER                         , INTENT(in   ) ::   kvor        ! total, planetary, relative, or metric
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pun, pvn    ! now velocities
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pua, pva    ! total v-trend
       !
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
       REAL(wp) ::   zuav, zvau   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zwx, zwy, zwz, zww   ! 2D workspace
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('vor_ens')
-      !
-      CALL wrk_alloc( jpi,jpj,   zwx, zwy, zwz ) 
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz, zww   ! 2D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('vor_ens')
       !
       IF( kt == nit000 ) THEN
@@ -431,7 +391,6 @@
       END DO                                           !   End of slab
       !                                                ! ===============
-      CALL wrk_dealloc( jpi, jpj, zwx, zwy, zwz ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('vor_ens')
+      !
+      IF( ln_timing )   CALL timing_stop('vor_ens')
       !
    END SUBROUTINE vor_ens
@@ -455,9 +414,8 @@
       !! References : Arakawa and Lamb 1980, Mon. Wea. Rev., 109, 18-36
       !!----------------------------------------------------------------------
-      INTEGER , INTENT(in   )                         ::   kt          ! ocean time-step index
-      INTEGER , INTENT(in   )                         ::   kvor        ! =ncor (planetary) ; =ntot (total) ;
-         !                                                             ! =nrvm (relative vorticity or metric)
-      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pun, pvn    ! now velocities
-      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pua, pva    ! total v-trend
+      INTEGER                         , INTENT(in   ) ::   kt          ! ocean time-step index
+      INTEGER                         , INTENT(in   ) ::   kvor        ! total, planetary, relative, or metric
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pun, pvn    ! now velocities
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pua, pva    ! total v-trend
       !
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
@@ -465,13 +423,9 @@
       REAL(wp) ::   zua, zva     ! local scalars
       REAL(wp) ::   zmsk, ze3    ! local scalars
-      !
-      REAL(wp), POINTER, DIMENSION(:,:)   :: zwx, zwy, zwz, z1_e3f
-      REAL(wp), POINTER, DIMENSION(:,:)   :: ztnw, ztne, ztsw, ztse
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('vor_een')
-      !
-      CALL wrk_alloc( jpi,jpj,   zwx , zwy , zwz , z1_e3f ) 
-      CALL wrk_alloc( jpi,jpj,   ztnw, ztne, ztsw, ztse   ) 
+      REAL(wp), DIMENSION(jpi,jpj)   :: zwx , zwy , zwz , z1_e3f
+      REAL(wp), DIMENSION(jpi,jpj)   :: ztnw, ztne, ztsw, ztse
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('vor_een')
       !
       IF( kt == nit000 ) THEN
@@ -599,8 +553,5 @@
       !                                                ! ===============
       !
-      CALL wrk_dealloc( jpi,jpj,   zwx , zwy , zwz , z1_e3f ) 
-      CALL wrk_dealloc( jpi,jpj,   ztnw, ztne, ztsw, ztse   ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('vor_een')
+      IF( ln_timing )   CALL timing_stop('vor_een')
       !
    END SUBROUTINE vor_een
@@ -618,5 +569,6 @@
       INTEGER ::   ios             ! Local integer output status for namelist read
       !!
-      NAMELIST/namdyn_vor/ ln_dynvor_ens, ln_dynvor_ene, ln_dynvor_mix, ln_dynvor_een, nn_een_e3f, ln_dynvor_msk
+      NAMELIST/namdyn_vor/ ln_dynvor_ens, ln_dynvor_ene, ln_dynvor_mix,   &
+         &                 ln_dynvor_een, nn_een_e3f   , ln_dynvor_msk
       !!----------------------------------------------------------------------
 
@@ -672,21 +624,28 @@
       !                      
       IF(lwp) WRITE(numout,*)        ! type of calculated vorticity (set ncor, nrvm, ntot)
-      ncor = np_COR
-      IF( ln_dynadv_vec ) THEN     
-         IF(lwp) WRITE(numout,*) '      ===>>   Vector form advection : vorticity = Coriolis + relative vorticity'
+      ncor = np_COR                       ! planetary vorticity
+      SELECT CASE( n_dynadv )
+      CASE( np_LIN_dyn )
+         IF(lwp) WRITE(numout,*) '      ===>>   linear dynamics : total vorticity = Coriolis'
+         nrvm = np_COR        ! planetary vorticity
+         ntot = np_COR        !     -         -
+      CASE( np_VEC_c2  )
+         IF(lwp) WRITE(numout,*) '      ===>>   vector form dynamics : total vorticity = Coriolis + relative vorticity' 
          nrvm = np_RVO        ! relative vorticity
-         ntot = np_CRV        ! relative + planetary vorticity
-      ELSE                        
-         IF(lwp) WRITE(numout,*) '      ===>>   Flux form advection   : vorticity = Coriolis + metric term'
+         ntot = np_CRV        ! relative + planetary vorticity         
+      CASE( np_FLX_c2 , np_FLX_ubs  )
+         IF(lwp) WRITE(numout,*) '      ===>>   flux form dynamics : total vorticity = Coriolis + metric term'
          nrvm = np_MET        ! metric term
          ntot = np_CME        ! Coriolis + metric term
-      ENDIF
+      END SELECT
       
       IF(lwp) THEN                   ! Print the choice
          WRITE(numout,*)
-         IF( nvor_scheme ==  np_ENE )   WRITE(numout,*) '      ===>>   energy conserving scheme'
-         IF( nvor_scheme ==  np_ENS )   WRITE(numout,*) '      ===>>   enstrophy conserving scheme'
-         IF( nvor_scheme ==  np_MIX )   WRITE(numout,*) '      ===>>   mixed enstrophy/energy conserving scheme'
-         IF( nvor_scheme ==  np_EEN )   WRITE(numout,*) '      ===>>   energy and enstrophy conserving scheme'
+         SELECT CASE( nvor_scheme )
+         CASE( np_ENE )   ;   WRITE(numout,*) '      ===>>   energy conserving scheme'
+         CASE( np_ENS )   ;   WRITE(numout,*) '      ===>>   enstrophy conserving scheme'
+         CASE( np_MIX )   ;   WRITE(numout,*) '      ===>>   mixed enstrophy/energy conserving scheme'
+         CASE( np_EEN )   ;   WRITE(numout,*) '      ===>>   energy and enstrophy conserving scheme'
+         END SELECT         
       ENDIF
       !
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynzad.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynzad.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynzad.F90	(revision 9019)
@@ -5,6 +5,4 @@
    !!======================================================================
    !! History :  OPA  ! 1991-01  (G. Madec) Original code
-   !!            7.0  ! 1991-11  (G. Madec)
-   !!            7.5  ! 1996-01  (G. Madec) statement function for e3
    !!   NEMO     0.5  ! 2002-07  (G. Madec) Free form, F90
    !!----------------------------------------------------------------------
@@ -22,5 +20,4 @@
    USE lib_mpp        ! MPP library
    USE prtctl         ! Print control
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
 
@@ -29,10 +26,9 @@
    
    PUBLIC   dyn_zad       ! routine called by dynadv.F90
-   PUBLIC   dyn_zad_zts   ! routine called by dynadv.F90
 
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -58,23 +54,20 @@
       INTEGER, INTENT(in) ::   kt   ! ocean time-step inedx
       !
-      INTEGER  ::   ji, jj, jk      ! dummy loop indices
-      REAL(wp) ::   zua, zva        ! temporary scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zwuw , zwvw
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::  zww
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrdu, ztrdv
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zua, zva     ! local scalars
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zww
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwuw, zwvw
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ztrdu, ztrdv
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_zad')
-      !
-      CALL wrk_alloc( jpi,jpj, zww ) 
-      CALL wrk_alloc( jpi,jpj,jpk, zwuw , zwvw ) 
+      IF( ln_timing )   CALL timing_start('dyn_zad')
       !
       IF( kt == nit000 ) THEN
-         IF(lwp)WRITE(numout,*)
-         IF(lwp)WRITE(numout,*) 'dyn_zad : arakawa advection scheme'
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_zad : 2nd order vertical advection scheme'
       ENDIF
 
       IF( l_trddyn )   THEN         ! Save ua and va trends
-         CALL wrk_alloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
+         ALLOCATE( ztrdu(jpi,jpj,jpk) , ztrdv(jpi,jpj,jpk) ) 
          ztrdu(:,:,:) = ua(:,:,:) 
          ztrdv(:,:,:) = va(:,:,:) 
@@ -96,5 +89,5 @@
       !
       ! Surface and bottom advective fluxes set to zero
-      IF ( ln_isfcav ) THEN
+      IF( ln_isfcav ) THEN
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1           ! vector opt.
@@ -119,10 +112,6 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1       ! vector opt.
-               !                         ! vertical momentum advective trends
-               zua = - ( zwuw(ji,jj,jk) + zwuw(ji,jj,jk+1) ) * r1_e1e2u(ji,jj) / e3u_n(ji,jj,jk)
-               zva = - ( zwvw(ji,jj,jk) + zwvw(ji,jj,jk+1) ) * r1_e1e2v(ji,jj) / e3v_n(ji,jj,jk)
-               !                         ! add the trends to the general momentum trends
-               ua(ji,jj,jk) = ua(ji,jj,jk) + zua
-               va(ji,jj,jk) = va(ji,jj,jk) + zva
+               ua(ji,jj,jk) = ua(ji,jj,jk) - ( zwuw(ji,jj,jk) + zwuw(ji,jj,jk+1) ) * r1_e1e2u(ji,jj) / e3u_n(ji,jj,jk)
+               va(ji,jj,jk) = va(ji,jj,jk) - ( zwvw(ji,jj,jk) + zwvw(ji,jj,jk+1) ) * r1_e1e2v(ji,jj) / e3v_n(ji,jj,jk)
             END DO  
          END DO  
@@ -133,5 +122,5 @@
          ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
          CALL trd_dyn( ztrdu, ztrdv, jpdyn_zad, kt )
-         CALL wrk_dealloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
+         DEALLOCATE( ztrdu, ztrdv ) 
       ENDIF
       !                             ! Control print
@@ -139,155 +128,8 @@
          &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
       !
-      CALL wrk_dealloc( jpi,jpj, zww ) 
-      CALL wrk_dealloc( jpi,jpj,jpk, zwuw , zwvw ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_zad')
+      IF( ln_timing )   CALL timing_stop('dyn_zad')
       !
    END SUBROUTINE dyn_zad
 
-
-   SUBROUTINE dyn_zad_zts ( kt )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE dynzad_zts  ***
-      !! 
-      !! ** Purpose :   Compute the now vertical momentum advection trend and 
-      !!      add it to the general trend of momentum equation. This version
-      !!      uses sub-timesteps for improved numerical stability with small
-      !!      vertical grid sizes. This is especially relevant when using 
-      !!      embedded ice with thin surface boxes.
-      !!
-      !! ** Method  :   The now vertical advection of momentum is given by:
-      !!         w dz(u) = ua + 1/(e1u*e2u*e3u) mk+1[ mi(e1t*e2t*wn) dk(un) ]
-      !!         w dz(v) = va + 1/(e1v*e2v*e3v) mk+1[ mj(e1t*e2t*wn) dk(vn) ]
-      !!      Add this trend to the general trend (ua,va):
-      !!         (ua,va) = (ua,va) + w dz(u,v)
-      !!
-      !! ** Action  : - Update (ua,va) with the vert. momentum adv. trends
-      !!              - Save the trends in (ztrdu,ztrdv) ('key_trddyn')
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step inedx
-      !
-      INTEGER  ::   ji, jj, jk, jl  ! dummy loop indices
-      INTEGER  ::   jnzts = 5       ! number of sub-timesteps for vertical advection
-      INTEGER  ::   jtb, jtn, jta   ! sub timestep pointers for leap-frog/euler forward steps
-      REAL(wp) ::   zua, zva        ! temporary scalars
-      REAL(wp) ::   zr_rdt          ! temporary scalar
-      REAL(wp) ::   z2dtzts         ! length of Euler forward sub-timestep for vertical advection
-      REAL(wp) ::   zts             ! length of sub-timestep for vertical advection
-      REAL(wp), POINTER, DIMENSION(:,:,:)   ::  zwuw , zwvw, zww
-      REAL(wp), POINTER, DIMENSION(:,:,:)   ::  ztrdu, ztrdv
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::  zus , zvs
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_zad_zts')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,     zwuw, zwvw, zww ) 
-      CALL wrk_alloc( jpi,jpj,jpk,3,   zus , zvs ) 
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp)WRITE(numout,*)
-         IF(lwp)WRITE(numout,*) 'dyn_zad_zts : arakawa advection scheme with sub-timesteps'
-      ENDIF
-
-      IF( l_trddyn )   THEN         ! Save ua and va trends
-         CALL wrk_alloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
-         ztrdu(:,:,:) = ua(:,:,:) 
-         ztrdv(:,:,:) = va(:,:,:) 
-      ENDIF
-      
-      IF( neuler == 0 .AND. kt == nit000 ) THEN
-          z2dtzts =         rdt / REAL( jnzts, wp )   ! = rdt (restart with Euler time stepping)
-      ELSE
-          z2dtzts = 2._wp * rdt / REAL( jnzts, wp )   ! = 2 rdt (leapfrog)
-      ENDIF
-      
-      DO jk = 2, jpkm1                    ! Calculate and store vertical fluxes
-         DO jj = 2, jpj                   
-            DO ji = fs_2, jpi             ! vector opt.
-               zww(ji,jj,jk) = 0.25_wp * e1e2t(ji,jj) * wn(ji,jj,jk)
-            END DO
-         END DO
-      END DO
-
-      DO jj = 2, jpjm1                    ! Surface and bottom advective fluxes set to zero
-         DO ji = fs_2, fs_jpim1           ! vector opt.
- !!gm missing ISF boundary condition
-            zwuw(ji,jj, 1 ) = 0._wp
-            zwvw(ji,jj, 1 ) = 0._wp
-            zwuw(ji,jj,jpk) = 0._wp
-            zwvw(ji,jj,jpk) = 0._wp
-         END DO  
-      END DO
-
-! Start with before values and use sub timestepping to reach after values
-
-      zus(:,:,:,1) = ub(:,:,:)
-      zvs(:,:,:,1) = vb(:,:,:)
-
-      DO jl = 1, jnzts                   ! Start of sub timestepping loop
-
-         IF( jl == 1 ) THEN              ! Euler forward to kick things off
-           jtb = 1   ;   jtn = 1   ;   jta = 2
-           zts = z2dtzts
-         ELSEIF( jl == 2 ) THEN          ! First leapfrog step
-           jtb = 1   ;   jtn = 2   ;   jta = 3
-           zts = 2._wp * z2dtzts
-         ELSE                            ! Shuffle pointers for subsequent leapfrog steps
-           jtb = MOD(jtb,3) + 1
-           jtn = MOD(jtn,3) + 1
-           jta = MOD(jta,3) + 1
-         ENDIF
-
-         DO jk = 2, jpkm1           ! Vertical momentum advection at level w and u- and v- vertical
-            DO jj = 2, jpjm1                 ! vertical momentum advection at w-point
-               DO ji = fs_2, fs_jpim1        ! vector opt.
-                  zwuw(ji,jj,jk) = ( zww(ji+1,jj  ,jk) + zww(ji,jj,jk) ) * ( zus(ji,jj,jk-1,jtn)-zus(ji,jj,jk,jtn) ) !* wumask(ji,jj,jk)
-                  zwvw(ji,jj,jk) = ( zww(ji  ,jj+1,jk) + zww(ji,jj,jk) ) * ( zvs(ji,jj,jk-1,jtn)-zvs(ji,jj,jk,jtn) ) !* wvmask(ji,jj,jk)
-               END DO  
-            END DO   
-         END DO
-         DO jk = 1, jpkm1           ! Vertical momentum advection at u- and v-points
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1       ! vector opt.
-                  !                         ! vertical momentum advective trends
-                  zua = - ( zwuw(ji,jj,jk) + zwuw(ji,jj,jk+1) ) * r1_e1e2u(ji,jj) / e3u_n(ji,jj,jk)
-                  zva = - ( zwvw(ji,jj,jk) + zwvw(ji,jj,jk+1) ) * r1_e1e2v(ji,jj) / e3v_n(ji,jj,jk)
-                  zus(ji,jj,jk,jta) = zus(ji,jj,jk,jtb) + zua * zts
-                  zvs(ji,jj,jk,jta) = zvs(ji,jj,jk,jtb) + zva * zts
-               END DO  
-            END DO  
-         END DO
-
-      END DO      ! End of sub timestepping loop
-
-      zr_rdt = 1._wp / ( REAL( jnzts, wp ) * z2dtzts )
-      DO jk = 1, jpkm1              ! Recover trends over the outer timestep
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1       ! vector opt.
-               !                         ! vertical momentum advective trends
-               !                         ! add the trends to the general momentum trends
-               ua(ji,jj,jk) = ua(ji,jj,jk) + ( zus(ji,jj,jk,jta) - ub(ji,jj,jk)) * zr_rdt
-               va(ji,jj,jk) = va(ji,jj,jk) + ( zvs(ji,jj,jk,jta) - vb(ji,jj,jk)) * zr_rdt
-            END DO  
-         END DO  
-      END DO
-
-      IF( l_trddyn ) THEN           ! save the vertical advection trends for diagnostic
-         ztrdu(:,:,:) = ua(:,:,:) - ztrdu(:,:,:)
-         ztrdv(:,:,:) = va(:,:,:) - ztrdv(:,:,:)
-         CALL trd_dyn( ztrdu, ztrdv, jpdyn_zad, kt )
-         CALL wrk_dealloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
-      ENDIF
-      !                             ! Control print
-      IF(ln_ctl)   CALL prt_ctl( tab3d_1=ua, clinfo1=' zad  - Ua: ', mask1=umask,   &
-         &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-      !
-      CALL wrk_dealloc( jpi,jpj,jpk,     zwuw, zwvw, zww ) 
-      CALL wrk_dealloc( jpi,jpj,jpk,3,   zus , zvs ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('dyn_zad_zts')
-      !
-   END SUBROUTINE dyn_zad_zts
-
    !!======================================================================
 END MODULE dynzad
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf.F90	(revision 9019)
@@ -6,15 +6,19 @@
    !! History :  1.0  !  2005-11  (G. Madec)  Original code
    !!            3.3  !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dyn_zdf       : Update the momentum trend with the vertical diffusion
-   !!   dyn_zdf_init  : initializations of the vertical diffusion scheme
+   !!            4.0  !  2017-06  (G. Madec) remove the explicit time-stepping option + avm at t-point
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dyn_zdf       : compute the after velocity through implicit calculation of vertical mixing
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and tracers variables
+   USE phycst         ! physical constants
    USE dom_oce        ! ocean space and time domain variables 
+   USE sbc_oce        ! surface boundary condition: ocean
    USE zdf_oce        ! ocean vertical physics variables
-   USE dynzdf_exp     ! vertical diffusion: explicit (dyn_zdf_exp     routine)
-   USE dynzdf_imp     ! vertical diffusion: implicit (dyn_zdf_imp     routine)
+   USE zdfdrg         ! vertical physics: top/bottom drag coef.
+   USE dynadv    ,ONLY: ln_dynadv_vec    ! dynamics: advection form
+   USE dynldf    ,ONLY: nldf, np_lap_i   ! dynamics: type of lateral mixing 
+   USE dynldf_iso,ONLY: akzu, akzv       ! dynamics: vertical component of rotated lateral mixing 
    USE ldfdyn         ! lateral diffusion: eddy viscosity coef.
    USE trd_oce        ! trends: ocean variables
@@ -24,5 +28,4 @@
    USE lib_mpp        ! MPP library
    USE prtctl         ! Print control
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
 
@@ -30,17 +33,15 @@
    PRIVATE
 
-   PUBLIC   dyn_zdf       !  routine called by step.F90
-   PUBLIC   dyn_zdf_init  !  routine called by opa.F90
-
-   INTEGER  ::   nzdf = 0   ! type vertical diffusion algorithm used, defined from ln_zdf... namlist logicals
+   PUBLIC   dyn_zdf   !  routine called by step.F90
+
+   REAL(wp) ::  r_vvl     ! non-linear free surface indicator: =0 if ln_linssh=T, =1 otherwise 
 
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
    
@@ -49,37 +50,341 @@
       !!                  ***  ROUTINE dyn_zdf  ***
       !!
-      !! ** Purpose :   compute the vertical ocean dynamics physics.
+      !! ** Purpose :   compute the trend due to the vert. momentum diffusion
+      !!              together with the Leap-Frog time stepping using an 
+      !!              implicit scheme.
+      !!
+      !! ** Method  :  - Leap-Frog time stepping on all trends but the vertical mixing
+      !!         ua =         ub + 2*dt *       ua             vector form or linear free surf.
+      !!         ua = ( e3u_b*ub + 2*dt * e3u_n*ua ) / e3u_a   otherwise
+      !!               - update the after velocity with the implicit vertical mixing.
+      !!      This requires to solver the following system: 
+      !!         ua = ua + 1/e3u_a dk+1[ mi(avm) / e3uw_a dk[ua] ]
+      !!      with the following surface/top/bottom boundary condition:
+      !!      surface: wind stress input (averaged over kt-1/2 & kt+1/2)
+      !!      top & bottom : top stress (iceshelf-ocean) & bottom stress (cf zdfdrg.F90)
+      !!
+      !! ** Action :   (ua,va)   after velocity 
       !!---------------------------------------------------------------------
-      !!
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-      !
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrdu, ztrdv
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      INTEGER  ::   ji, jj, jk         ! dummy loop indices
+      INTEGER  ::   iku, ikv           ! local integers
+      REAL(wp) ::   zzwi, ze3ua, zdt   ! local scalars
+      REAL(wp) ::   zzws, ze3va        !   -      -
+      REAL(wp), DIMENSION(jpi,jpj,jpk)        ::  zwi, zwd, zws   ! 3D workspace 
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ztrdu, ztrdv   !  -      -
       !!---------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start('dyn_zdf')
-      !
-      !                                          ! set time step
+      IF( ln_timing )   CALL timing_start('dyn_zdf')
+      !
+      IF( kt == nit000 ) THEN       !* initialization
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_zdf_imp : vertical momentum diffusion implicit operator'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
+         !
+         If( ln_linssh ) THEN   ;    r_vvl = 0._wp    ! non-linear free surface indicator
+         ELSE                   ;    r_vvl = 1._wp
+         ENDIF
+      ENDIF
+      !                             !* set time step
       IF( neuler == 0 .AND. kt == nit000     ) THEN   ;   r2dt =      rdt   ! = rdt (restart with Euler time stepping)
       ELSEIF(               kt <= nit000 + 1 ) THEN   ;   r2dt = 2. * rdt   ! = 2 rdt (leapfrog)
       ENDIF
 
-      IF( l_trddyn )   THEN                      ! temporary save of ta and sa trends
-         CALL wrk_alloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
+      IF( l_trddyn )   THEN         !* temporary save of ta and sa trends
+         ALLOCATE( ztrdu(jpi,jpj,jpk), ztrdv(jpi,jpj,jpk) ) 
          ztrdu(:,:,:) = ua(:,:,:)
          ztrdv(:,:,:) = va(:,:,:)
       ENDIF
-
-      SELECT CASE ( nzdf )                       ! compute lateral mixing trend and add it to the general trend
-      !
-      CASE ( 0 )   ;   CALL dyn_zdf_exp( kt, r2dt )      ! explicit scheme
-      CASE ( 1 )   ;   CALL dyn_zdf_imp( kt, r2dt )      ! implicit scheme
-      !
-      END SELECT
-
+      !
+      !              !==  RHS: Leap-Frog time stepping on all trends but the vertical mixing  ==!   (put in ua,va)
+      !
+      !                    ! time stepping except vertical diffusion
+      IF( ln_dynadv_vec .OR. ln_linssh ) THEN   ! applied on velocity
+         DO jk = 1, jpkm1
+            ua(:,:,jk) = ( ub(:,:,jk) + r2dt * ua(:,:,jk) ) * umask(:,:,jk)
+            va(:,:,jk) = ( vb(:,:,jk) + r2dt * va(:,:,jk) ) * vmask(:,:,jk)
+         END DO
+      ELSE                                      ! applied on thickness weighted velocity
+         DO jk = 1, jpkm1
+            ua(:,:,jk) = (         e3u_b(:,:,jk) * ub(:,:,jk)  &
+               &          + r2dt * e3u_n(:,:,jk) * ua(:,:,jk)  ) / e3u_a(:,:,jk) * umask(:,:,jk)
+            va(:,:,jk) = (         e3v_b(:,:,jk) * vb(:,:,jk)  &
+               &          + r2dt * e3v_n(:,:,jk) * va(:,:,jk)  ) / e3v_a(:,:,jk) * vmask(:,:,jk)
+         END DO
+      ENDIF
+      !                    ! add top/bottom friction 
+      !     With split-explicit free surface, barotropic stress is treated explicitly Update velocities at the bottom.
+      !     J. Chanut: The bottom stress is computed considering after barotropic velocities, which does 
+      !                not lead to the effective stress seen over the whole barotropic loop. 
+      !     G. Madec : in linear free surface, e3u_a = e3u_n = e3u_0, so systematic use of e3u_a
+      IF( ln_drgimp .AND. ln_dynspg_ts ) THEN
+         DO jk = 1, jpkm1        ! remove barotropic velocities
+            ua(:,:,jk) = ( ua(:,:,jk) - ua_b(:,:) ) * umask(:,:,jk)
+            va(:,:,jk) = ( va(:,:,jk) - va_b(:,:) ) * vmask(:,:,jk)
+         END DO
+         DO jj = 2, jpjm1        ! Add bottom/top stress due to barotropic component only
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               iku = mbku(ji,jj)         ! ocean bottom level at u- and v-points 
+               ikv = mbkv(ji,jj)         ! (deepest ocean u- and v-points)
+               ze3ua =  ( 1._wp - r_vvl ) * e3u_n(ji,jj,iku) + r_vvl * e3u_a(ji,jj,iku)
+               ze3va =  ( 1._wp - r_vvl ) * e3v_n(ji,jj,ikv) + r_vvl * e3v_a(ji,jj,ikv)
+               ua(ji,jj,iku) = ua(ji,jj,iku) + r2dt * 0.5*( rCdU_bot(ji+1,jj)+rCdU_bot(ji,jj) ) * ua_b(ji,jj) / ze3ua
+               va(ji,jj,ikv) = va(ji,jj,ikv) + r2dt * 0.5*( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj) ) * va_b(ji,jj) / ze3va
+            END DO
+         END DO
+         IF( ln_isfcav ) THEN    ! Ocean cavities (ISF)
+            DO jj = 2, jpjm1        
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  iku = miku(ji,jj)         ! top ocean level at u- and v-points 
+                  ikv = mikv(ji,jj)         ! (first wet ocean u- and v-points)
+                  ze3ua =  ( 1._wp - r_vvl ) * e3u_n(ji,jj,iku) + r_vvl * e3u_a(ji,jj,iku)
+                  ze3va =  ( 1._wp - r_vvl ) * e3v_n(ji,jj,ikv) + r_vvl * e3v_a(ji,jj,ikv)
+                  ua(ji,jj,iku) = ua(ji,jj,iku) + r2dt * 0.5*( rCdU_top(ji+1,jj)+rCdU_top(ji,jj) ) * ua_b(ji,jj) / ze3ua
+                  va(ji,jj,ikv) = va(ji,jj,ikv) + r2dt * 0.5*( rCdU_top(ji+1,jj)+rCdU_top(ji,jj) ) * va_b(ji,jj) / ze3va
+               END DO
+            END DO
+         END IF
+      ENDIF
+      !
+      !              !==  Vertical diffusion on u  ==!
+      !
+      !                    !* Matrix construction
+      zdt = r2dt * 0.5
+      IF( nldf == np_lap_i ) THEN   ! rotated lateral mixing: add its vertical mixing (akzu)
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1 
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ze3ua =  ( 1._wp - r_vvl ) * e3u_n(ji,jj,jk) + r_vvl * e3u_a(ji,jj,jk)   ! after scale factor at T-point
+                  zzwi = - zdt * ( avm(ji+1,jj,jk  ) + avm(ji,jj,jk  ) + akzu(ji,jj,jk  ) )   &
+                     &         / ( ze3ua * e3uw_n(ji,jj,jk  ) ) * wumask(ji,jj,jk  )
+                  zzws = - zdt * ( avm(ji+1,jj,jk+1) + avm(ji,jj,jk+1) + akzu(ji,jj,jk+1) )   &
+                     &         / ( ze3ua * e3uw_n(ji,jj,jk+1) ) * wumask(ji,jj,jk+1)
+                  zwi(ji,jj,jk) = zzwi
+                  zws(ji,jj,jk) = zzws
+                  zwd(ji,jj,jk) = 1._wp - zzwi - zzws
+               END DO
+            END DO
+         END DO
+      ELSE                          ! standard case
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1 
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ze3ua =  ( 1._wp - r_vvl ) * e3u_n(ji,jj,jk) + r_vvl * e3u_a(ji,jj,jk)   ! after scale factor at T-point
+                  zzwi = - zdt * ( avm(ji+1,jj,jk  ) + avm(ji,jj,jk  ) ) / ( ze3ua * e3uw_n(ji,jj,jk  ) ) * wumask(ji,jj,jk  )
+                  zzws = - zdt * ( avm(ji+1,jj,jk+1) + avm(ji,jj,jk+1) ) / ( ze3ua * e3uw_n(ji,jj,jk+1) ) * wumask(ji,jj,jk+1)
+                  zwi(ji,jj,jk) = zzwi
+                  zws(ji,jj,jk) = zzws
+                  zwd(ji,jj,jk) = 1._wp - zzwi - zzws
+               END DO
+            END DO
+         END DO
+      ENDIF
+      !
+      DO jj = 2, jpjm1     !* Surface boundary conditions
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zwi(ji,jj,1) = 0._wp
+            zwd(ji,jj,1) = 1._wp - zws(ji,jj,1)
+         END DO
+      END DO
+      !
+      !              !==  Apply semi-implicit bottom friction  ==!
+      !
+      !     Only needed for semi-implicit bottom friction setup. The explicit
+      !     bottom friction has been included in "u(v)a" which act as the R.H.S
+      !     column vector of the tri-diagonal matrix equation
+      !
+      IF ( ln_drgimp ) THEN      ! implicit bottom friction
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               iku = mbku(ji,jj)       ! ocean bottom level at u- and v-points
+               ze3ua =  ( 1._wp - r_vvl ) * e3u_n(ji,jj,iku) + r_vvl * e3u_a(ji,jj,iku)   ! after scale factor at T-point
+               zwd(ji,jj,iku) = zwd(ji,jj,iku) - r2dt * 0.5*( rCdU_bot(ji+1,jj)+rCdU_bot(ji,jj) ) / ze3ua
+            END DO
+         END DO
+         IF ( ln_isfcav ) THEN   ! top friction (always implicit)
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  !!gm   top Cd is masked (=0 outside cavities) no need of test on mik>=2  ==>> it has been suppressed
+                  iku = miku(ji,jj)       ! ocean top level at u- and v-points 
+                  ze3ua =  ( 1._wp - r_vvl ) * e3u_n(ji,jj,iku) + r_vvl * e3u_a(ji,jj,iku)   ! after scale factor at T-point
+                  zwd(ji,jj,iku) = zwd(ji,jj,iku) - r2dt * 0.5*( rCdU_top(ji+1,jj)+rCdU_top(ji,jj) ) / ze3ua
+               END DO
+            END DO
+         END IF
+      ENDIF
+      !
+      ! Matrix inversion starting from the first level
+      !-----------------------------------------------------------------------
+      !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+      !
+      !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+      !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+      !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+      !        (        ...               )( ...  ) ( ...  )
+      !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+      !
+      !   m is decomposed in the product of an upper and a lower triangular matrix
+      !   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+      !   The solution (the after velocity) is in ua
+      !-----------------------------------------------------------------------
+      !
+      DO jk = 2, jpkm1        !==  First recurrence : Dk = Dk - Lk * Uk-1 / Dk-1   (increasing k)  ==
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zwd(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1) / zwd(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+      !
+      DO jj = 2, jpjm1        !==  second recurrence:    SOLk = RHSk - Lk / Dk-1  Lk-1  ==!
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ze3ua =  ( 1._wp - r_vvl ) * e3u_n(ji,jj,1) + r_vvl * e3u_a(ji,jj,1) 
+            ua(ji,jj,1) = ua(ji,jj,1) + r2dt * 0.5_wp * ( utau_b(ji,jj) + utau(ji,jj) )   &
+               &                                      / ( ze3ua * rau0 ) * umask(ji,jj,1) 
+         END DO
+      END DO
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               ua(ji,jj,jk) = ua(ji,jj,jk) - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * ua(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+      !
+      DO jj = 2, jpjm1        !==  thrid recurrence : SOLk = ( Lk - Uk * Ek+1 ) / Dk  ==!
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            ua(ji,jj,jpkm1) = ua(ji,jj,jpkm1) / zwd(ji,jj,jpkm1)
+         END DO
+      END DO
+      DO jk = jpk-2, 1, -1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               ua(ji,jj,jk) = ( ua(ji,jj,jk) - zws(ji,jj,jk) * ua(ji,jj,jk+1) ) / zwd(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
+      !              !==  Vertical diffusion on v  ==!
+      !
+      !                       !* Matrix construction
+      zdt = r2dt * 0.5
+      IF( nldf == np_lap_i ) THEN   ! rotated lateral mixing: add its vertical mixing (akzu)
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1   
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ze3va =  ( 1._wp - r_vvl ) * e3v_n(ji,jj,jk) + r_vvl * e3v_a(ji,jj,jk)   ! after scale factor at T-point
+                  zzwi = - zdt * ( avm(ji,jj+1,jk  )+ avm(ji,jj,jk  ) + akzv(ji,jj,jk  ) )   &
+                     &         / ( ze3va * e3vw_n(ji,jj,jk  ) ) * wvmask(ji,jj,jk  )
+                  zzws = - zdt * ( avm(ji,jj+1,jk+1)+ avm(ji,jj,jk+1) + akzv(ji,jj,jk+1) )   &
+                     &         / ( ze3va * e3vw_n(ji,jj,jk+1) ) * wvmask(ji,jj,jk+1)
+                  zwi(ji,jj,jk) = zzwi * wvmask(ji,jj,jk  )
+                  zws(ji,jj,jk) = zzws * wvmask(ji,jj,jk+1)
+                  zwd(ji,jj,jk) = 1._wp - zzwi - zzws
+               END DO
+            END DO
+         END DO
+      ELSE                          ! standard case
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1   
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ze3va =  ( 1._wp - r_vvl ) * e3v_n(ji,jj,jk) + r_vvl * e3v_a(ji,jj,jk)   ! after scale factor at T-point
+                  zzwi = - zdt * ( avm(ji,jj+1,jk  )+ avm(ji,jj,jk  ) ) / ( ze3va * e3vw_n(ji,jj,jk  ) ) * wvmask(ji,jj,jk  )
+                  zzws = - zdt * ( avm(ji,jj+1,jk+1)+ avm(ji,jj,jk+1) ) / ( ze3va * e3vw_n(ji,jj,jk+1) ) * wvmask(ji,jj,jk+1)
+                  zwi(ji,jj,jk) = zzwi * wvmask(ji,jj,jk  )
+                  zws(ji,jj,jk) = zzws * wvmask(ji,jj,jk+1)
+                  zwd(ji,jj,jk) = 1._wp - zzwi - zzws
+               END DO
+            END DO
+         END DO
+      ENDIF
+      !
+      DO jj = 2, jpjm1        !* Surface boundary conditions
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zwi(ji,jj,1) = 0._wp
+            zwd(ji,jj,1) = 1._wp - zws(ji,jj,1)
+         END DO
+      END DO
+      !              !==  Apply semi-implicit top/bottom friction  ==!
+      !
+      !     Only needed for semi-implicit bottom friction setup. The explicit
+      !     bottom friction has been included in "u(v)a" which act as the R.H.S
+      !     column vector of the tri-diagonal matrix equation
+      !
+      IF( ln_drgimp ) THEN
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               ikv = mbkv(ji,jj)       ! (deepest ocean u- and v-points)
+               ze3va =  ( 1._wp - r_vvl ) * e3v_n(ji,jj,ikv) + r_vvl * e3v_a(ji,jj,ikv)   ! after scale factor at T-point
+               zwd(ji,jj,ikv) = zwd(ji,jj,ikv) - r2dt * 0.5*( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj) ) / ze3va           
+            END DO
+         END DO
+         IF ( ln_isfcav ) THEN
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  ikv = mikv(ji,jj)       ! (first wet ocean u- and v-points)
+                  ze3va =  ( 1._wp - r_vvl ) * e3v_n(ji,jj,ikv) + r_vvl * e3v_a(ji,jj,ikv)   ! after scale factor at T-point
+                  zwd(ji,jj,iku) = zwd(ji,jj,iku) - r2dt * 0.5*( rCdU_top(ji+1,jj)+rCdU_top(ji,jj) ) / ze3va
+               END DO
+            END DO
+         ENDIF
+      ENDIF
+
+      ! Matrix inversion
+      !-----------------------------------------------------------------------
+      !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+      !
+      !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+      !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+      !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+      !        (        ...               )( ...  ) ( ...  )
+      !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+      !
+      !   m is decomposed in the product of an upper and lower triangular matrix
+      !   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
+      !   The solution (after velocity) is in 2d array va
+      !-----------------------------------------------------------------------
+      !
+      DO jk = 2, jpkm1        !==  First recurrence : Dk = Dk - Lk * Uk-1 / Dk-1   (increasing k)  ==
+         DO jj = 2, jpjm1   
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zwd(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1) / zwd(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+      !
+      DO jj = 2, jpjm1        !==  second recurrence:    SOLk = RHSk - Lk / Dk-1  Lk-1  ==!
+         DO ji = fs_2, fs_jpim1   ! vector opt.          
+            ze3va =  ( 1._wp - r_vvl ) * e3v_n(ji,jj,1) + r_vvl * e3v_a(ji,jj,1) 
+            va(ji,jj,1) = va(ji,jj,1) + r2dt * 0.5_wp * ( vtau_b(ji,jj) + vtau(ji,jj) )   &
+               &                                      / ( ze3va * rau0 ) * vmask(ji,jj,1) 
+         END DO
+      END DO
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               va(ji,jj,jk) = va(ji,jj,jk) - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * va(ji,jj,jk-1)
+            END DO
+         END DO
+      END DO
+      !
+      DO jj = 2, jpjm1        !==  third recurrence : SOLk = ( Lk - Uk * SOLk+1 ) / Dk  ==!
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            va(ji,jj,jpkm1) = va(ji,jj,jpkm1) / zwd(ji,jj,jpkm1)
+         END DO
+      END DO
+      DO jk = jpk-2, 1, -1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               va(ji,jj,jk) = ( va(ji,jj,jk) - zws(ji,jj,jk) * va(ji,jj,jk+1) ) / zwd(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      !
       IF( l_trddyn )   THEN                      ! save the vertical diffusive trends for further diagnostics
          ztrdu(:,:,:) = ( ua(:,:,:) - ub(:,:,:) ) / r2dt - ztrdu(:,:,:)
          ztrdv(:,:,:) = ( va(:,:,:) - vb(:,:,:) ) / r2dt - ztrdv(:,:,:)
          CALL trd_dyn( ztrdu, ztrdv, jpdyn_zdf, kt )
-         CALL wrk_dealloc( jpi, jpj, jpk, ztrdu, ztrdv ) 
+         DEALLOCATE( ztrdu, ztrdv ) 
       ENDIF
       !                                          ! print mean trends (used for debugging)
@@ -87,41 +392,7 @@
          &                       tab3d_2=va, clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
          !
-      IF( nn_timing == 1 )   CALL timing_stop('dyn_zdf')
+      IF( ln_timing )   CALL timing_stop('dyn_zdf')
       !
    END SUBROUTINE dyn_zdf
-
-
-   SUBROUTINE dyn_zdf_init
-      !!----------------------------------------------------------------------
-      !!                 ***  ROUTINE dyn_zdf_init  ***
-      !!
-      !! ** Purpose :   initializations of the vertical diffusion scheme
-      !!
-      !! ** Method  :   implicit (euler backward) scheme (default)
-      !!                explicit (time-splitting) scheme if ln_zdfexp=T
-      !!----------------------------------------------------------------------
-      USE zdftke
-      USE zdfgls
-      !!----------------------------------------------------------------------
-      !
-      ! Choice from ln_zdfexp read in namelist in zdfini
-      IF( ln_zdfexp ) THEN   ;   nzdf = 0           ! use explicit scheme
-      ELSE                   ;   nzdf = 1           ! use implicit scheme
-      ENDIF
-      !
-      ! Force implicit schemes
-      IF( lk_zdftke .OR. lk_zdfgls   )   nzdf = 1   ! TKE or GLS physics
-      IF( ln_dynldf_iso              )   nzdf = 1   ! iso-neutral lateral physics
-      IF( ln_dynldf_hor .AND. ln_sco )   nzdf = 1   ! horizontal lateral physics in s-coordinate
-      !
-      IF(lwp) THEN                                  ! Print the choice
-         WRITE(numout,*)
-         WRITE(numout,*) 'dyn_zdf_init : vertical dynamics physics scheme'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         IF( nzdf ==  0 )   WRITE(numout,*) '      ===>>   Explicit time-splitting scheme'
-         IF( nzdf ==  1 )   WRITE(numout,*) '      ===>>   Implicit (euler backward) scheme'
-      ENDIF
-      !
-   END SUBROUTINE dyn_zdf_init
 
    !!==============================================================================
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf_exp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf_exp.F90	(revision 9018)
+++ 	(revision )
@@ -1,149 +1,0 @@
-MODULE dynzdf_exp
-   !!==============================================================================
-   !!                     ***  MODULE  dynzdf_exp  ***
-   !! Ocean dynamics:  vertical component(s) of the momentum mixing trend
-   !!==============================================================================
-   !! History :  OPA  !  1990-10  (B. Blanke)  Original code
-   !!            8.0  !  1997-05  (G. Madec)  vertical component of isopycnal
-   !!   NEMO     0.5  !  2002-08  (G. Madec)  F90: Free form and module
-   !!            3.3  !  2010-04  (M. Leclair, G. Madec)  Forcing averaged over 2 time steps
-   !!            3.7  !  2015-11  (J. Chanut) output velocities instead of trends
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dyn_zdf_exp   : update the momentum trend with the vertical diffusion using a split-explicit scheme
-   !!                   and perform the Leap-Frog time integration.
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers
-   USE dom_oce        ! ocean space and time domain
-   USE phycst         ! physical constants
-   USE zdf_oce        ! ocean vertical physics
-   USE dynadv   , ONLY: ln_dynadv_vec ! Momentum advection form
-   USE sbc_oce        ! surface boundary condition: ocean
-   !
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory Allocation
-   USE timing         ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   dyn_zdf_exp   ! called by step.F90
-   
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dyn_zdf_exp( kt, p2dt )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE dyn_zdf_exp  ***
-      !!                   
-      !! ** Purpose :   Compute the trend due to the vert. momentum diffusion
-      !!              and perform the Leap-Frog time stepping.
-      !!
-      !! ** Method  : - Split-explicit forward time stepping.
-      !!      The vertical mixing of momentum is given by:
-      !!         diffu = dz( avmu dz(u) ) = 1/e3u dk+1( avmu/e3uw dk(ub) )
-      !!      Surface boundary conditions: wind stress input (averaged over kt-1/2 & kt+1/2)
-      !!      Bottom boundary conditions : bottom stress (cf zdfbfr.F90)
-      !!      Add this trend to the general trend ua :
-      !!         ua = ua + dz( avmu dz(u) )
-      !!              - Leap-Frog time stepping (Asselin filter will be applied in dyn_nxt) 
-      !!         ua =         ub + 2*dt *       ua             vector form or linear free surf.
-      !!         ua = ( e3u_b*ub + 2*dt * e3u_n*ua ) / e3u_a   otherwise
-      !!
-      !! ** Action : - (ua,va) after velocity
-      !!---------------------------------------------------------------------
-      INTEGER , INTENT(in) ::   kt     ! ocean time-step index
-      REAL(wp), INTENT(in) ::   p2dt   ! time-step 
-      !
-      INTEGER  ::   ji, jj, jk, jl     ! dummy loop indices
-      REAL(wp) ::   zlavmr, zua, zva   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zwx, zwy, zwz, zww
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )   CALL timing_start('dyn_zdf_exp')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   zwx, zwy, zwz, zww ) 
-      !
-      IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'dyn_zdf_exp : vertical momentum diffusion - explicit operator'
-         WRITE(numout,*) '~~~~~~~~~~~ '
-      ENDIF
-      !
-      !                 !==  vertical mixing trend  ==!
-      !
-      zlavmr = 1. / REAL( nn_zdfexp )
-      !
-      DO jj = 2, jpjm1           ! Surface boundary condition
-         DO ji = 2, jpim1
-            zwy(ji,jj,1) = ( utau_b(ji,jj) + utau(ji,jj) ) * r1_rau0
-            zww(ji,jj,1) = ( vtau_b(ji,jj) + vtau(ji,jj) ) * r1_rau0
-         END DO  
-      END DO  
-      DO jk = 1, jpk             ! Initialization of x, z and contingently trends array
-         DO jj = 2, jpjm1 
-            DO ji = 2, jpim1
-               zwx(ji,jj,jk) = ub(ji,jj,jk)
-               zwz(ji,jj,jk) = vb(ji,jj,jk)
-            END DO  
-         END DO  
-      END DO  
-      !
-      DO jl = 1, nn_zdfexp       ! Time splitting loop
-         !
-         DO jk = 2, jpk                ! First vertical derivative
-            DO jj = 2, jpjm1 
-               DO ji = 2, jpim1
-                  zwy(ji,jj,jk) = avmu(ji,jj,jk) * ( zwx(ji,jj,jk-1) - zwx(ji,jj,jk) ) / e3uw_n(ji,jj,jk) 
-                  zww(ji,jj,jk) = avmv(ji,jj,jk) * ( zwz(ji,jj,jk-1) - zwz(ji,jj,jk) ) / e3vw_n(ji,jj,jk)
-               END DO  
-            END DO  
-         END DO  
-         DO jk = 1, jpkm1              ! Second vertical derivative and trend estimation at kt+l*rdt/nn_zdfexp
-            DO jj = 2, jpjm1 
-               DO ji = 2, jpim1
-                  zua = zlavmr * ( zwy(ji,jj,jk) - zwy(ji,jj,jk+1) ) / e3u_n(ji,jj,jk)
-                  zva = zlavmr * ( zww(ji,jj,jk) - zww(ji,jj,jk+1) ) / e3v_n(ji,jj,jk)
-                  ua(ji,jj,jk) = ua(ji,jj,jk) + zua
-                  va(ji,jj,jk) = va(ji,jj,jk) + zva
-                  !
-                  zwx(ji,jj,jk) = zwx(ji,jj,jk) + p2dt * zua * umask(ji,jj,jk)
-                  zwz(ji,jj,jk) = zwz(ji,jj,jk) + p2dt * zva * vmask(ji,jj,jk)
-               END DO  
-            END DO  
-         END DO  
-      END DO                     ! End of time splitting
-      !
-      !
-      !                 !==  Leap-Frog time integration  ==!
-      !
-      IF( ln_dynadv_vec .OR. ln_linssh ) THEN   ! applied on velocity
-         DO jk = 1, jpkm1
-            ua(:,:,jk) = ( ub(:,:,jk) + p2dt * ua(:,:,jk) ) * umask(:,:,jk)
-            va(:,:,jk) = ( vb(:,:,jk) + p2dt * va(:,:,jk) ) * vmask(:,:,jk)
-         END DO
-      ELSE                                      ! applied on thickness weighted velocity
-         DO jk = 1, jpkm1
-            ua(:,:,jk) = (          e3u_b(:,:,jk) * ub(:,:,jk)    &
-               &           + p2dt * e3u_n(:,:,jk) * ua(:,:,jk)  ) / e3u_a(:,:,jk) * umask(:,:,jk)
-            va(:,:,jk) = (          e3v_b(:,:,jk) * vb(:,:,jk)    &
-               &           + p2dt * e3v_n(:,:,jk) * va(:,:,jk)  ) / e3v_a(:,:,jk) * vmask(:,:,jk)
-         END DO
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi,jpj,jpk,   zwx, zwy, zwz, zww ) 
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('dyn_zdf_exp')
-      !
-   END SUBROUTINE dyn_zdf_exp
-
-   !!==============================================================================
-END MODULE dynzdf_exp
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf_imp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/dynzdf_imp.F90	(revision 9018)
+++ 	(revision )
@@ -1,351 +1,0 @@
-MODULE dynzdf_imp
-   !!======================================================================
-   !!                    ***  MODULE  dynzdf_imp  ***
-   !! Ocean dynamics:  vertical component(s) of the momentum mixing trend, implicit scheme
-   !!======================================================================
-   !! History :  OPA  !  1990-10  (B. Blanke)  Original code
-   !!            8.0  !  1997-05  (G. Madec)  vertical component of isopycnal
-   !!   NEMO     0.5  !  2002-08  (G. Madec)  F90: Free form and module
-   !!            3.3  !  2010-04  (M. Leclair, G. Madec)  Forcing averaged over 2 time steps
-   !!            3.4  !  2012-01  (H. Liu) Semi-implicit bottom friction
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dyn_zdf_imp   : compute the vertical diffusion using a implicit scheme
-   !!                   together with the Leap-Frog time integration.
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers
-   USE phycst         ! physical constants
-   USE dom_oce        ! ocean space and time domain
-   USE domvvl         ! variable volume
-   USE sbc_oce        ! surface boundary condition: ocean
-   USE dynadv   , ONLY: ln_dynadv_vec ! Momentum advection form
-   USE zdf_oce        ! ocean vertical physics
-   USE zdfbfr         ! Bottom friction setup
-   !
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory Allocation
-   USE timing         ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   dyn_zdf_imp   ! called by step.F90
-
-   REAL(wp) ::  r_vvl     ! non-linear free surface indicator: =0 if ln_linssh=T, =1 otherwise 
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dyn_zdf_imp( kt, p2dt )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE dyn_zdf_imp  ***
-      !!                   
-      !! ** Purpose :   Compute the trend due to the vert. momentum diffusion
-      !!              together with the Leap-Frog time stepping using an 
-      !!              implicit scheme.
-      !!
-      !! ** Method  :  - Leap-Frog time stepping on all trends but the vertical mixing
-      !!         ua =         ub + 2*dt *       ua             vector form or linear free surf.
-      !!         ua = ( e3u_b*ub + 2*dt * e3u_n*ua ) / e3u_a   otherwise
-      !!               - update the after velocity with the implicit vertical mixing.
-      !!      This requires to solver the following system: 
-      !!         ua = ua + 1/e3u_a dk+1[ avmu / e3uw_a dk[ua] ]
-      !!      with the following surface/top/bottom boundary condition:
-      !!      surface: wind stress input (averaged over kt-1/2 & kt+1/2)
-      !!      top & bottom : top stress (iceshelf-ocean) & bottom stress (cf zdfbfr.F)
-      !!
-      !! ** Action :   (ua,va) after velocity 
-      !!---------------------------------------------------------------------
-      INTEGER , INTENT(in) ::  kt     ! ocean time-step index
-      REAL(wp), INTENT(in) ::  p2dt   ! vertical profile of tracer time-step
-      !
-      INTEGER  ::   ji, jj, jk    ! dummy loop indices
-      INTEGER  ::   ikbu, ikbv    ! local integers
-      REAL(wp) ::   zzwi, ze3ua   ! local scalars
-      REAL(wp) ::   zzws, ze3va   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zwi, zwd, zws
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('dyn_zdf_imp')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk, zwi, zwd, zws ) 
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dyn_zdf_imp : vertical momentum diffusion implicit operator'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~ '
-         !
-         If( ln_linssh ) THEN   ;    r_vvl = 0._wp    ! non-linear free surface indicator
-         ELSE                   ;    r_vvl = 1._wp
-         ENDIF
-      ENDIF
-      !
-      !              !==  Time step dynamics  ==!
-      !
-      IF( ln_dynadv_vec .OR. ln_linssh ) THEN      ! applied on velocity
-         DO jk = 1, jpkm1
-            ua(:,:,jk) = ( ub(:,:,jk) + p2dt * ua(:,:,jk) ) * umask(:,:,jk)
-            va(:,:,jk) = ( vb(:,:,jk) + p2dt * va(:,:,jk) ) * vmask(:,:,jk)
-         END DO
-      ELSE                                         ! applied on thickness weighted velocity
-         DO jk = 1, jpkm1
-            ua(:,:,jk) = (         e3u_b(:,:,jk) * ub(:,:,jk)  &
-               &          + p2dt * e3u_n(:,:,jk) * ua(:,:,jk)  ) / e3u_a(:,:,jk) * umask(:,:,jk)
-            va(:,:,jk) = (         e3v_b(:,:,jk) * vb(:,:,jk)  &
-               &          + p2dt * e3v_n(:,:,jk) * va(:,:,jk)  ) / e3v_a(:,:,jk) * vmask(:,:,jk)
-         END DO
-      ENDIF
-      !
-      !              !==  Apply semi-implicit bottom friction  ==!
-      !
-      ! Only needed for semi-implicit bottom friction setup. The explicit
-      ! bottom friction has been included in "u(v)a" which act as the R.H.S
-      ! column vector of the tri-diagonal matrix equation
-      !
-      IF( ln_bfrimp ) THEN
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1
-               ikbu = mbku(ji,jj)       ! ocean bottom level at u- and v-points 
-               ikbv = mbkv(ji,jj)       ! (deepest ocean u- and v-points)
-               avmu(ji,jj,ikbu+1) = -bfrua(ji,jj) * e3uw_n(ji,jj,ikbu+1)
-               avmv(ji,jj,ikbv+1) = -bfrva(ji,jj) * e3vw_n(ji,jj,ikbv+1)
-            END DO
-         END DO
-         IF ( ln_isfcav ) THEN
-            DO jj = 2, jpjm1
-               DO ji = 2, jpim1
-                  ikbu = miku(ji,jj)       ! ocean top level at u- and v-points 
-                  ikbv = mikv(ji,jj)       ! (first wet ocean u- and v-points)
-                  IF( ikbu >= 2 )   avmu(ji,jj,ikbu) = -tfrua(ji,jj) * e3uw_n(ji,jj,ikbu)
-                  IF( ikbv >= 2 )   avmv(ji,jj,ikbv) = -tfrva(ji,jj) * e3vw_n(ji,jj,ikbv)
-               END DO
-            END DO
-         END IF
-      ENDIF
-      !
-      ! With split-explicit free surface, barotropic stress is treated explicitly
-      ! Update velocities at the bottom.
-      ! J. Chanut: The bottom stress is computed considering after barotropic velocities, which does 
-      !            not lead to the effective stress seen over the whole barotropic loop. 
-      ! G. Madec : in linear free surface, e3u_a = e3u_n = e3u_0, so systematic use of e3u_a
-      IF( ln_bfrimp .AND. ln_dynspg_ts ) THEN
-         DO jk = 1, jpkm1        ! remove barotropic velocities
-            ua(:,:,jk) = ( ua(:,:,jk) - ua_b(:,:) ) * umask(:,:,jk)
-            va(:,:,jk) = ( va(:,:,jk) - va_b(:,:) ) * vmask(:,:,jk)
-         END DO
-         DO jj = 2, jpjm1        ! Add bottom/top stress due to barotropic component only
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               ikbu = mbku(ji,jj)         ! ocean bottom level at u- and v-points 
-               ikbv = mbkv(ji,jj)         ! (deepest ocean u- and v-points)
-               ze3ua =  ( 1._wp - r_vvl ) * e3u_n(ji,jj,ikbu) + r_vvl * e3u_a(ji,jj,ikbu)
-               ze3va =  ( 1._wp - r_vvl ) * e3v_n(ji,jj,ikbv) + r_vvl * e3v_a(ji,jj,ikbv)
-               ua(ji,jj,ikbu) = ua(ji,jj,ikbu) + p2dt * bfrua(ji,jj) * ua_b(ji,jj) / ze3ua
-               va(ji,jj,ikbv) = va(ji,jj,ikbv) + p2dt * bfrva(ji,jj) * va_b(ji,jj) / ze3va
-            END DO
-         END DO
-         IF( ln_isfcav ) THEN    ! Ocean cavities (ISF)
-            DO jj = 2, jpjm1        
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  ikbu = miku(ji,jj)         ! top ocean level at u- and v-points 
-                  ikbv = mikv(ji,jj)         ! (first wet ocean u- and v-points)
-                  ze3ua =  ( 1._wp - r_vvl ) * e3u_n(ji,jj,ikbu) + r_vvl * e3u_a(ji,jj,ikbu)
-                  ze3va =  ( 1._wp - r_vvl ) * e3v_n(ji,jj,ikbv) + r_vvl * e3v_a(ji,jj,ikbv)
-                  ua(ji,jj,ikbu) = ua(ji,jj,ikbu) + p2dt * tfrua(ji,jj) * ua_b(ji,jj) / ze3ua
-                  va(ji,jj,ikbv) = va(ji,jj,ikbv) + p2dt * tfrva(ji,jj) * va_b(ji,jj) / ze3va
-               END DO
-            END DO
-         END IF
-      ENDIF
-      !
-      !              !==  Vertical diffusion on u  ==!
-      !
-      ! Matrix and second member construction
-      ! bottom boundary condition: both zwi and zws must be masked as avmu can take
-      ! non zero value at the ocean bottom depending on the bottom friction used.
-      !
-      DO jk = 1, jpkm1        ! Matrix
-         DO jj = 2, jpjm1 
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               ze3ua =  ( 1._wp - r_vvl ) * e3u_n(ji,jj,jk) + r_vvl * e3u_a(ji,jj,jk)   ! after scale factor at T-point
-               zzwi = - p2dt * avmu(ji,jj,jk  ) / ( ze3ua * e3uw_n(ji,jj,jk  ) )
-               zzws = - p2dt * avmu(ji,jj,jk+1) / ( ze3ua * e3uw_n(ji,jj,jk+1) )
-               zwi(ji,jj,jk) = zzwi * wumask(ji,jj,jk  )
-               zws(ji,jj,jk) = zzws * wumask(ji,jj,jk+1)
-               zwd(ji,jj,jk) = 1._wp - zzwi - zzws
-            END DO
-         END DO
-      END DO
-      DO jj = 2, jpjm1        ! Surface boundary conditions
-         DO ji = fs_2, fs_jpim1   ! vector opt.
-            zwi(ji,jj,1) = 0._wp
-            zwd(ji,jj,1) = 1._wp - zws(ji,jj,1)
-         END DO
-      END DO
-
-      ! Matrix inversion starting from the first level
-      !-----------------------------------------------------------------------
-      !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
-      !
-      !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
-      !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
-      !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
-      !        (        ...               )( ...  ) ( ...  )
-      !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
-      !
-      !   m is decomposed in the product of an upper and a lower triangular matrix
-      !   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
-      !   The solution (the after velocity) is in ua
-      !-----------------------------------------------------------------------
-      !
-      DO jk = 2, jpkm1        !==  First recurrence : Dk = Dk - Lk * Uk-1 / Dk-1   (increasing k)  ==
-         DO jj = 2, jpjm1   
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zwd(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1) / zwd(ji,jj,jk-1)
-            END DO
-         END DO
-      END DO
-      !
-      DO jj = 2, jpjm1        !==  second recurrence:    SOLk = RHSk - Lk / Dk-1  Lk-1  ==!
-         DO ji = fs_2, fs_jpim1   ! vector opt.
-            ze3ua =  ( 1._wp - r_vvl ) * e3u_n(ji,jj,1) + r_vvl * e3u_a(ji,jj,1) 
-            ua(ji,jj,1) = ua(ji,jj,1) + p2dt * 0.5_wp * ( utau_b(ji,jj) + utau(ji,jj) )   &
-               &                                      / ( ze3ua * rau0 ) * umask(ji,jj,1) 
-         END DO
-      END DO
-      DO jk = 2, jpkm1
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1
-               ua(ji,jj,jk) = ua(ji,jj,jk) - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * ua(ji,jj,jk-1)
-            END DO
-         END DO
-      END DO
-      !
-      DO jj = 2, jpjm1        !==  thrid recurrence : SOLk = ( Lk - Uk * Ek+1 ) / Dk  ==!
-         DO ji = fs_2, fs_jpim1   ! vector opt.
-            ua(ji,jj,jpkm1) = ua(ji,jj,jpkm1) / zwd(ji,jj,jpkm1)
-         END DO
-      END DO
-      DO jk = jpk-2, 1, -1
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1
-               ua(ji,jj,jk) = ( ua(ji,jj,jk) - zws(ji,jj,jk) * ua(ji,jj,jk+1) ) / zwd(ji,jj,jk)
-            END DO
-         END DO
-      END DO
-      !
-      !              !==  Vertical diffusion on v  ==!
-      !
-      ! Matrix and second member construction
-      ! bottom boundary condition: both zwi and zws must be masked as avmv can take
-      ! non zero value at the ocean bottom depending on the bottom friction used
-      !
-      DO jk = 1, jpkm1        ! Matrix
-         DO jj = 2, jpjm1   
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               ze3va =  ( 1._wp - r_vvl ) * e3v_n(ji,jj,jk) + r_vvl * e3v_a(ji,jj,jk)   ! after scale factor at T-point
-               zzwi = - p2dt * avmv (ji,jj,jk  ) / ( ze3va * e3vw_n(ji,jj,jk  ) )
-               zzws = - p2dt * avmv (ji,jj,jk+1) / ( ze3va * e3vw_n(ji,jj,jk+1) )
-               zwi(ji,jj,jk) = zzwi * wvmask(ji,jj,jk  )
-               zws(ji,jj,jk) = zzws * wvmask(ji,jj,jk+1)
-               zwd(ji,jj,jk) = 1._wp - zzwi - zzws
-            END DO
-         END DO
-      END DO
-      DO jj = 2, jpjm1        ! Surface boundary conditions
-         DO ji = fs_2, fs_jpim1   ! vector opt.
-            zwi(ji,jj,1) = 0._wp
-            zwd(ji,jj,1) = 1._wp - zws(ji,jj,1)
-         END DO
-      END DO
-
-      ! Matrix inversion
-      !-----------------------------------------------------------------------
-      !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
-      !
-      !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
-      !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
-      !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
-      !        (        ...               )( ...  ) ( ...  )
-      !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
-      !
-      !   m is decomposed in the product of an upper and lower triangular matrix
-      !   The 3 diagonal terms are in 2d arrays: zwd, zws, zwi
-      !   The solution (after velocity) is in 2d array va
-      !-----------------------------------------------------------------------
-      !
-      DO jk = 2, jpkm1        !==  First recurrence : Dk = Dk - Lk * Uk-1 / Dk-1   (increasing k)  ==
-         DO jj = 2, jpjm1   
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zwd(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1) / zwd(ji,jj,jk-1)
-            END DO
-         END DO
-      END DO
-      !
-      DO jj = 2, jpjm1        !==  second recurrence:    SOLk = RHSk - Lk / Dk-1  Lk-1  ==!
-         DO ji = fs_2, fs_jpim1   ! vector opt.          
-            ze3va =  ( 1._wp - r_vvl ) * e3v_n(ji,jj,1) + r_vvl * e3v_a(ji,jj,1) 
-            va(ji,jj,1) = va(ji,jj,1) + p2dt * 0.5_wp * ( vtau_b(ji,jj) + vtau(ji,jj) )   &
-               &                                      / ( ze3va * rau0 ) * vmask(ji,jj,1) 
-         END DO
-      END DO
-      DO jk = 2, jpkm1
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               va(ji,jj,jk) = va(ji,jj,jk) - zwi(ji,jj,jk) / zwd(ji,jj,jk-1) * va(ji,jj,jk-1)
-            END DO
-         END DO
-      END DO
-      !
-      DO jj = 2, jpjm1        !==  third recurrence : SOLk = ( Lk - Uk * SOLk+1 ) / Dk  ==!
-         DO ji = fs_2, fs_jpim1   ! vector opt.
-            va(ji,jj,jpkm1) = va(ji,jj,jpkm1) / zwd(ji,jj,jpkm1)
-         END DO
-      END DO
-      DO jk = jpk-2, 1, -1
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1
-               va(ji,jj,jk) = ( va(ji,jj,jk) - zws(ji,jj,jk) * va(ji,jj,jk+1) ) / zwd(ji,jj,jk)
-            END DO
-         END DO
-      END DO
-      
-      ! J. Chanut: Lines below are useless ?
-      !! restore bottom layer avmu(v) 
-      !!gm  I almost sure it is !!!!
-      IF( ln_bfrimp ) THEN
-        DO jj = 2, jpjm1
-           DO ji = 2, jpim1
-              ikbu = mbku(ji,jj)         ! ocean bottom level at u- and v-points 
-              ikbv = mbkv(ji,jj)         ! (deepest ocean u- and v-points)
-              avmu(ji,jj,ikbu+1) = 0._wp
-              avmv(ji,jj,ikbv+1) = 0._wp
-           END DO
-        END DO
-        IF (ln_isfcav) THEN
-           DO jj = 2, jpjm1
-              DO ji = 2, jpim1
-                 ikbu = miku(ji,jj)         ! ocean top level at u- and v-points 
-                 ikbv = mikv(ji,jj)         ! (first wet ocean u- and v-points)
-                 IF( ikbu > 1 )   avmu(ji,jj,ikbu) = 0._wp
-                 IF( ikbv > 1 )   avmv(ji,jj,ikbv) = 0._wp
-              END DO
-           END DO
-        ENDIF
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi,jpj,jpk,   zwi, zwd, zws) 
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('dyn_zdf_imp')
-      !
-   END SUBROUTINE dyn_zdf_imp
-
-   !!==============================================================================
-END MODULE dynzdf_imp
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/sshwzv.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/sshwzv.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/sshwzv.F90	(revision 9019)
@@ -22,5 +22,5 @@
    USE divhor         ! horizontal divergence
    USE phycst         ! physical constants
-   USE bdy_oce   , ONLY: ln_bdy, bdytmask
+   USE bdy_oce , ONLY : ln_bdy, bdytmask   ! Open BounDarY
    USE bdydyn2d       ! bdy_ssh routine
 #if defined key_agrif
@@ -36,7 +36,6 @@
    USE lbclnk         ! ocean lateral boundary condition (or mpp link)
    USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
-   USE wet_dry         ! Wetting/Drying flux limting
+   USE wet_dry        ! Wetting/Drying flux limting
 
    IMPLICIT NONE
@@ -74,10 +73,8 @@
       INTEGER  ::   jk            ! dummy loop indice
       REAL(wp) ::   z2dt, zcoef   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::   zhdiv   ! 2D workspace
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )   CALL timing_start('ssh_nxt')
-      !
-      CALL wrk_alloc( jpi,jpj,   zhdiv ) 
+      REAL(wp), DIMENSION(jpi,jpj) ::   zhdiv   ! 2D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('ssh_nxt')
       !
       IF( kt == nit000 ) THEN
@@ -134,7 +131,5 @@
       IF(ln_ctl)   CALL prt_ctl( tab2d_1=ssha, clinfo1=' ssha  - : ', mask1=tmask, ovlap=1 )
       !
-      CALL wrk_dealloc( jpi, jpj, zhdiv ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('ssh_nxt')
+      IF( ln_timing )   CALL timing_stop('ssh_nxt')
       !
    END SUBROUTINE ssh_nxt
@@ -160,9 +155,8 @@
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
       REAL(wp) ::   z1_2dt       ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::  z2d
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  z3d, zhdiv
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )   CALL timing_start('wzv')
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   zhdiv
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('wzv')
       !
       IF( kt == nit000 ) THEN
@@ -180,5 +174,5 @@
       !
       IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN      ! z_tilde and layer cases
-         CALL wrk_alloc( jpi, jpj, jpk, zhdiv ) 
+         ALLOCATE( zhdiv(jpi,jpj,jpk) ) 
          !
          DO jk = 1, jpkm1
@@ -200,5 +194,5 @@
          END DO
          !          IF( ln_vvl_layer ) wn(:,:,:) = 0.e0
-         CALL wrk_dealloc( jpi, jpj, jpk, zhdiv ) 
+         DEALLOCATE( zhdiv ) 
       ELSE   ! z_star and linear free surface cases
          DO jk = jpkm1, 1, -1                       ! integrate from the bottom the hor. divergence
@@ -215,5 +209,5 @@
       ENDIF
       !
-      IF( nn_timing == 1 )  CALL timing_stop('wzv')
+      IF( ln_timing )   CALL timing_stop('wzv')
       !
    END SUBROUTINE wzv
@@ -244,5 +238,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('ssh_swp')
+      IF( ln_timing )  CALL timing_start('ssh_swp')
       !
       IF( kt == nit000 ) THEN
@@ -271,5 +265,5 @@
       IF(ln_ctl)   CALL prt_ctl( tab2d_1=sshb, clinfo1=' sshb  - : ', mask1=tmask, ovlap=1 )
       !
-      IF( nn_timing == 1 )   CALL timing_stop('ssh_swp')
+      IF( ln_timing )   CALL timing_stop('ssh_swp')
       !
    END SUBROUTINE ssh_swp
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/wet_dry.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/wet_dry.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/DYN/wet_dry.F90	(revision 9019)
@@ -11,16 +11,17 @@
 
    !!----------------------------------------------------------------------
-   !!   wad_lmt    : Compute the horizontal flux limiter and the limited velocity
-   !!                when wetting and drying happens 
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE sbc_oce, ONLY : ln_rnf   ! surface boundary condition: ocean
-   USE sbcrnf          ! river runoff 
-   USE in_out_manager  ! I/O manager
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! Memory Allocation
-   USE timing          ! Timing
+   !!   wad_init      : initialisation of wetting and drying
+   !!   wad_lmt       : horizontal flux limiter and limited velocity when wetting and drying happens
+   !!   wad_lmt_bt    : same as wad_lmt for the barotropic stepping (dynspg_ts)
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE sbc_oce  , ONLY: ln_rnf   ! surface boundary condition: ocean
+   USE sbcrnf         ! river runoff 
+   !
+   USE in_out_manager ! I/O manager
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp        ! MPP library
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -31,13 +32,12 @@
    !! ---------------------------------------------------------------------
 
-   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:) ::   wdmask         !: u- and v- limiter 
-   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:) ::   ht_wd          !: wetting and drying t-pt depths
-                                                                     !  (can include negative depths)
+   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:) ::   wdmask   !: u- and v- limiter 
+   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:) ::   ht_wd    !: wetting and drying t-pt depths
+   !                                                           !  (can include negative depths)
 
    LOGICAL,  PUBLIC  ::   ln_wd       !: Wetting/drying activation switch (T:on,F:off)
    REAL(wp), PUBLIC  ::   rn_wdmin1   !: minimum water depth on dried cells
    REAL(wp), PUBLIC  ::   rn_wdmin2   !: tolerrance of minimum water depth on dried cells
-   REAL(wp), PUBLIC  ::   rn_wdld     !: land elevation below which wetting/drying 
-                                           !: will be considered
+   REAL(wp), PUBLIC  ::   rn_wdld     !: land elevation below which wetting/drying will be considered
    INTEGER , PUBLIC  ::   nn_wdit     !: maximum number of iteration for W/D limiter
 
@@ -48,4 +48,5 @@
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
 CONTAINS
 
@@ -58,19 +59,17 @@
       !! ** input   : - namwad namelist
       !!----------------------------------------------------------------------
+      INTEGER  ::   ios, ierr   ! Local integer
+      !!
       NAMELIST/namwad/ ln_wd, rn_wdmin1, rn_wdmin2, rn_wdld, nn_wdit
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
-      INTEGER  ::   ierr                ! Local integer status array allocation 
-      !!----------------------------------------------------------------------
-
-      REWIND( numnam_ref )              ! Namelist namwad in reference namelist 
-                                        ! : Parameters for Wetting/Drying
+      !!----------------------------------------------------------------------
+      !
+      REWIND( numnam_ref )              ! Namelist namwad in reference namelist : Parameters for Wetting/Drying
       READ  ( numnam_ref, namwad, IOSTAT = ios, ERR = 905)
 905   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namwad in reference namelist', .TRUE.) 
-      REWIND( numnam_cfg )              ! Namelist namwad in configuration namelist 
-                                        ! : Parameters for Wetting/Drying
+      REWIND( numnam_cfg )              ! Namelist namwad in configuration namelist : Parameters for Wetting/Drying
       READ  ( numnam_cfg, namwad, IOSTAT = ios, ERR = 906)
 906   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namwad in configuration namelist', .TRUE. )
       IF(lwm) WRITE ( numond, namwad )
-
+      !
       IF(lwp) THEN                  ! control print
          WRITE(numout,*)
@@ -103,7 +102,7 @@
       !! ** Action  : - calculate flux limiter and W/D flag
       !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   sshb1
-      REAL(wp), DIMENSION(:,:), INTENT(in)    ::   sshemp
-      REAL(wp), INTENT(in) :: z2dt
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   sshb1        !!gm DOCTOR names: should start with p !
+      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   sshemp
+      REAL(wp)                , INTENT(in   ) ::   z2dt
       !
       INTEGER  ::   ji, jj, jk, jk1     ! dummy loop indices
@@ -113,151 +112,139 @@
       REAL(wp) ::   zdepwd              ! local scalar, always wet cell depth
       REAL(wp) ::   ztmp                ! local scalars
-      REAL(wp), POINTER,  DIMENSION(:,:) ::   zwdlmtu, zwdlmtv         !: W/D flux limiters
-      REAL(wp), POINTER,  DIMENSION(:,:) ::   zflxp,  zflxn            ! local 2D workspace
-      REAL(wp), POINTER,  DIMENSION(:,:) ::   zflxu,  zflxv            ! local 2D workspace
-      REAL(wp), POINTER,  DIMENSION(:,:) ::   zflxu1, zflxv1           ! local 2D workspace
-      !!----------------------------------------------------------------------
-      !
-
-      IF( nn_timing == 1 )  CALL timing_start('wad_lmt')
-
-      IF(ln_wd) THEN
-
-        CALL wrk_alloc( jpi, jpj, zflxp, zflxn, zflxu, zflxv, zflxu1, zflxv1 )
-        CALL wrk_alloc( jpi, jpj, zwdlmtu, zwdlmtv)
-        !
-       
-        !IF(lwp) WRITE(numout,*)
-        !IF(lwp) WRITE(numout,*) 'wad_lmt : wetting/drying limiters and velocity limiting'
-       
-        jflag  = 0
-        zdepwd = 50._wp   !maximum depth on which that W/D could possibly happen
-
-       
-        zflxp(:,:)   = 0._wp
-        zflxn(:,:)   = 0._wp
-        zflxu(:,:)   = 0._wp
-        zflxv(:,:)   = 0._wp
-
-        zwdlmtu(:,:)  = 1._wp
-        zwdlmtv(:,:)  = 1._wp
-       
-        ! Horizontal Flux in u and v direction
-        DO jk = 1, jpkm1  
-           DO jj = 1, jpj
-              DO ji = 1, jpi
-                 zflxu(ji,jj) = zflxu(ji,jj) + e3u_n(ji,jj,jk) * un(ji,jj,jk) * umask(ji,jj,jk)
-                 zflxv(ji,jj) = zflxv(ji,jj) + e3v_n(ji,jj,jk) * vn(ji,jj,jk) * vmask(ji,jj,jk)
-              END DO  
-           END DO  
-        END DO
-       
-        zflxu(:,:) = zflxu(:,:) * e2u(:,:)
-        zflxv(:,:) = zflxv(:,:) * e1v(:,:)
-       
-        wdmask(:,:) = 1
-        DO jj = 2, jpj
-           DO ji = 2, jpi 
-
-             IF( tmask(ji, jj, 1) < 0.5_wp ) CYCLE   ! we don't care about land cells
-             IF( ht_wd(ji,jj) > zdepwd )      CYCLE   ! and cells which are unlikely to dry
-
-              zflxp(ji,jj) = max(zflxu(ji,jj), 0._wp) - min(zflxu(ji-1,jj),   0._wp) + &
-                           & max(zflxv(ji,jj), 0._wp) - min(zflxv(ji,  jj-1), 0._wp) 
-              zflxn(ji,jj) = min(zflxu(ji,jj), 0._wp) - max(zflxu(ji-1,jj),   0._wp) + &
-                           & min(zflxv(ji,jj), 0._wp) - max(zflxv(ji,  jj-1), 0._wp) 
-
-              zdep2 = ht_wd(ji,jj) + sshb1(ji,jj) - rn_wdmin1
-              IF(zdep2 .le. 0._wp) THEN  !add more safty, but not necessary
-                sshb1(ji,jj) = rn_wdmin1 - ht_wd(ji,jj)
-                IF(zflxu(ji,  jj) > 0._wp) zwdlmtu(ji  ,jj) = 0._wp
-                IF(zflxu(ji-1,jj) < 0._wp) zwdlmtu(ji-1,jj) = 0._wp
-                IF(zflxv(ji,  jj) > 0._wp) zwdlmtv(ji  ,jj) = 0._wp
-                IF(zflxv(ji,jj-1) < 0._wp) zwdlmtv(ji,jj-1) = 0._wp 
-                wdmask(ji,jj) = 0._wp
-              END IF
-           ENDDO
-        END DO
-
-      
-        !! start limiter iterations 
-        DO jk1 = 1, nn_wdit + 1
-       
-          
-           zflxu1(:,:) = zflxu(:,:) * zwdlmtu(:,:)
-           zflxv1(:,:) = zflxv(:,:) * zwdlmtv(:,:)
-           jflag = 0     ! flag indicating if any further iterations are needed
-          
-           DO jj = 2, jpj
-              DO ji = 2, jpi 
-        
-                 IF( tmask(ji, jj, 1) < 0.5_wp ) CYCLE 
-                 IF( ht_wd(ji,jj) > zdepwd )      CYCLE
-        
-                 ztmp = e1e2t(ji,jj)
-
-                 zzflxp = max(zflxu1(ji,jj), 0._wp) - min(zflxu1(ji-1,jj),   0._wp) + &
-                        & max(zflxv1(ji,jj), 0._wp) - min(zflxv1(ji,  jj-1), 0._wp) 
-                 zzflxn = min(zflxu1(ji,jj), 0._wp) - max(zflxu1(ji-1,jj),   0._wp) + &
-                        & min(zflxv1(ji,jj), 0._wp) - max(zflxv1(ji,  jj-1), 0._wp) 
-          
-                 zdep1 = (zzflxp + zzflxn) * z2dt / ztmp
-                 zdep2 = ht_wd(ji,jj) + sshb1(ji,jj) - rn_wdmin1 - z2dt * sshemp(ji,jj)
-          
-                 IF( zdep1 > zdep2 ) THEN
-                   wdmask(ji, jj) = 0
-                   zcoef = ( ( zdep2 - rn_wdmin2 ) * ztmp - zzflxn * z2dt ) / ( zflxp(ji,jj) * z2dt )
-                   !zcoef = ( ( zdep2 - rn_wdmin2 ) * ztmp - zzflxn * z2dt ) / ( zzflxp * z2dt )
-                   ! flag if the limiter has been used but stop flagging if the only
-                   ! changes have zeroed the coefficient since further iterations will
-                   ! not change anything
-                   IF( zcoef > 0._wp ) THEN
-                      jflag = 1 
-                   ELSE
-                      zcoef = 0._wp
-                   ENDIF
-                   IF(jk1 > nn_wdit) zcoef = 0._wp
-                   IF(zflxu1(ji,  jj) > 0._wp) zwdlmtu(ji  ,jj) = zcoef
-                   IF(zflxu1(ji-1,jj) < 0._wp) zwdlmtu(ji-1,jj) = zcoef
-                   IF(zflxv1(ji,  jj) > 0._wp) zwdlmtv(ji  ,jj) = zcoef
-                   IF(zflxv1(ji,jj-1) < 0._wp) zwdlmtv(ji,jj-1) = zcoef
-                 END IF
-              END DO ! ji loop
-           END DO  ! jj loop
-
-           CALL lbc_lnk( zwdlmtu, 'U', 1. )
-           CALL lbc_lnk( zwdlmtv, 'V', 1. )
-
-           IF(lk_mpp) CALL mpp_max(jflag)   !max over the global domain
-
-           IF(jflag == 0) EXIT
-          
-        END DO  ! jk1 loop
-       
-        DO jk = 1, jpkm1
-          un(:,:,jk) = un(:,:,jk) * zwdlmtu(:, :) 
-          vn(:,:,jk) = vn(:,:,jk) * zwdlmtv(:, :) 
-        END DO
-
-        CALL lbc_lnk( un, 'U', -1. )
-        CALL lbc_lnk( vn, 'V', -1. )
-      !
-        un_b(:,:) = un_b(:,:) * zwdlmtu(:, :)
-        vn_b(:,:) = vn_b(:,:) * zwdlmtv(:, :)
-        CALL lbc_lnk( un_b, 'U', -1. )
-        CALL lbc_lnk( vn_b, 'V', -1. )
-       
-        IF(jflag == 1 .AND. lwp) WRITE(numout,*) 'Need more iterations in wad_lmt!!!'
-       
-        !IF( ln_rnf      )   CALL sbc_rnf_div( hdivn )          ! runoffs (update hdivn field)
-        !IF( nn_cla == 1 )   CALL cla_div    ( kt )             ! Cross Land Advection (update hdivn field)
-        !
-        !
-        CALL wrk_dealloc( jpi, jpj, zflxp, zflxn, zflxu, zflxv, zflxu1, zflxv1 )
-        CALL wrk_dealloc( jpi, jpj, zwdlmtu, zwdlmtv)
-        !
-      ENDIF
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('wad_lmt')
+      REAL(wp),  DIMENSION(jpi,jpj) ::   zwdlmtu, zwdlmtv   ! W/D flux limiters
+      REAL(wp),  DIMENSION(jpi,jpj) ::   zflxp  ,  zflxn    ! local 2D workspace
+      REAL(wp),  DIMENSION(jpi,jpj) ::   zflxu  ,  zflxv    ! local 2D workspace
+      REAL(wp),  DIMENSION(jpi,jpj) ::   zflxu1 , zflxv1    ! local 2D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('wad_lmt')
+      !
+      !IF(lwp) WRITE(numout,*)
+      !IF(lwp) WRITE(numout,*) 'wad_lmt : wetting/drying limiters and velocity limiting'
+      !
+      jflag  = 0
+      zdepwd = 50._wp   !maximum depth on which that W/D could possibly happen
+      ! 
+      zflxp(:,:)   = 0._wp
+      zflxn(:,:)   = 0._wp
+      zflxu(:,:)   = 0._wp
+      zflxv(:,:)   = 0._wp
+      !
+      zwdlmtu(:,:) = 1._wp
+      zwdlmtv(:,:) = 1._wp
+      ! 
+      ! Horizontal Flux in u and v direction
+      DO jk = 1, jpkm1  
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zflxu(ji,jj) = zflxu(ji,jj) + e3u_n(ji,jj,jk) * un(ji,jj,jk) * umask(ji,jj,jk)
+               zflxv(ji,jj) = zflxv(ji,jj) + e3v_n(ji,jj,jk) * vn(ji,jj,jk) * vmask(ji,jj,jk)
+            END DO  
+         END DO  
+      END DO
+      !
+      zflxu(:,:) = zflxu(:,:) * e2u(:,:)
+      zflxv(:,:) = zflxv(:,:) * e1v(:,:)
+      ! 
+      wdmask(:,:) = 1
+      DO jj = 2, jpj
+         DO ji = 2, jpi 
+            !
+            IF( tmask(ji, jj, 1) < 0.5_wp )   CYCLE   ! we don't care about land cells
+            IF( ht_wd(ji,jj)     > zdepwd )   CYCLE   ! and cells which are unlikely to dry
+            !
+            zflxp(ji,jj) = MAX( zflxu(ji,jj) , 0._wp ) - MIN( zflxu(ji-1,jj) , 0._wp )   &
+               &         + MAX( zflxv(ji,jj) , 0._wp ) - MIN( zflxv(ji,jj-1) , 0._wp ) 
+            zflxn(ji,jj) = MIN( zflxu(ji,jj) , 0._wp ) - MAX( zflxu(ji-1,jj) , 0._wp )   &
+               &         + MIN( zflxv(ji,jj) , 0._wp ) - MAX( zflxv(ji,jj-1) , 0._wp ) 
+            !
+            zdep2 = ht_wd(ji,jj) + sshb1(ji,jj) - rn_wdmin1
+            IF( zdep2 .le. 0._wp) THEN  !add more safty, but not necessary
+               sshb1(ji,jj) = rn_wdmin1 - ht_wd(ji,jj)
+               IF( zflxu(ji,  jj) > 0._wp )   zwdlmtu(ji  ,jj) = 0._wp
+               IF( zflxu(ji-1,jj) < 0._wp )   zwdlmtu(ji-1,jj) = 0._wp
+               IF( zflxv(ji,  jj) > 0._wp )   zwdlmtv(ji  ,jj) = 0._wp
+               IF( zflxv(ji,jj-1) < 0._wp )   zwdlmtv(ji,jj-1) = 0._wp 
+               wdmask(ji,jj) = 0._wp
+            ENDIF
+         END DO
+      END DO
+      !!
+      !! start limiter iterations 
+      DO jk1 = 1, nn_wdit + 1
+         ! 
+         zflxu1(:,:) = zflxu(:,:) * zwdlmtu(:,:)
+         zflxv1(:,:) = zflxv(:,:) * zwdlmtv(:,:)
+         jflag = 0     ! flag indicating if any further iterations are needed
+         ! 
+         DO jj = 2, jpj
+            DO ji = 2, jpi 
+               !
+               IF( tmask(ji,jj,1) < 0.5_wp )   CYCLE 
+               IF( ht_wd(ji,jj)   > zdepwd )   CYCLE
+               !
+               ztmp = e1e2t(ji,jj)
+               !
+               zzflxp = MAX( zflxu1(ji,jj) , 0._wp ) - MIN( zflxu1(ji-1,jj) , 0._wp )   &
+                  &   + MAX( zflxv1(ji,jj) , 0._wp ) - MIN( zflxv1(ji,jj-1) , 0._wp ) 
+               zzflxn = MIN( zflxu1(ji,jj) , 0._wp ) - MAX( zflxu1(ji-1,jj) , 0._wp )   &
+                  &   + MIN( zflxv1(ji,jj) , 0._wp ) - MAX( zflxv1(ji,jj-1) , 0._wp ) 
+               !
+               zdep1 = (zzflxp + zzflxn) * z2dt / ztmp
+               zdep2 = ht_wd(ji,jj) + sshb1(ji,jj) - rn_wdmin1 - z2dt * sshemp(ji,jj)
+               !
+               IF( zdep1 > zdep2 ) THEN
+                  wdmask(ji, jj) = 0
+                  zcoef = ( ( zdep2 - rn_wdmin2 ) * ztmp - zzflxn * z2dt ) / ( zflxp(ji,jj) * z2dt )
+                  !zcoef = ( ( zdep2 - rn_wdmin2 ) * ztmp - zzflxn * z2dt ) / ( zzflxp * z2dt )
+                  ! flag if the limiter has been used but stop flagging if the only
+                  ! changes have zeroed the coefficient since further iterations will
+                  ! not change anything
+                  IF( zcoef > 0._wp ) THEN   ;   jflag = 1 
+                  ELSE                       ;   zcoef = 0._wp
+                  ENDIF
+                  IF( jk1 > nn_wdit )   zcoef = 0._wp
+                  IF( zflxu1(ji,  jj) > 0._wp )   zwdlmtu(ji  ,jj) = zcoef
+                  IF( zflxu1(ji-1,jj) < 0._wp )   zwdlmtu(ji-1,jj) = zcoef
+                  IF( zflxv1(ji,  jj) > 0._wp )   zwdlmtv(ji  ,jj) = zcoef
+                  IF( zflxv1(ji,jj-1) < 0._wp )   zwdlmtv(ji,jj-1) = zcoef
+               ENDIF
+            END DO ! ji loop
+         END DO  ! jj loop
+         !
+         CALL lbc_lnk( zwdlmtu, 'U', 1. )
+         CALL lbc_lnk( zwdlmtv, 'V', 1. )
+         !
+         IF(lk_mpp)   CALL mpp_max(jflag)   !max over the global domain
+         !
+         IF(jflag == 0)   EXIT
+         ! 
+      END DO  ! jk1 loop
+       
+      DO jk = 1, jpkm1
+         un(:,:,jk) = un(:,:,jk) * zwdlmtu(:,:) 
+         vn(:,:,jk) = vn(:,:,jk) * zwdlmtv(:,:) 
+      END DO
+
+!!gm ==> Andrew  : the lbclnk below is useless since above lbclnk is applied on zwdlmtu/v
+!!                                             and un, vn always with lbclnk
+      CALL lbc_lnk( un, 'U', -1. )
+      CALL lbc_lnk( vn, 'V', -1. )
+!!gm end
+      !
+      un_b(:,:) = un_b(:,:) * zwdlmtu(:,:)
+      vn_b(:,:) = vn_b(:,:) * zwdlmtv(:,:)
+!!gm ==> Andrew   : probably same as above
+      CALL lbc_lnk( un_b, 'U', -1. )
+      CALL lbc_lnk( vn_b, 'V', -1. )
+!!gm end
+       
+      IF(jflag == 1 .AND. lwp) WRITE(numout,*) 'Need more iterations in wad_lmt!!!'
+       
+      !IF( ln_rnf      )   CALL sbc_rnf_div( hdivn )          ! runoffs (update hdivn field)
+      !IF( nn_cla == 1 )   CALL cla_div    ( kt )             ! Cross Land Advection (update hdivn field)
+      !
+      !
+      IF( ln_timing )   CALL timing_stop('wad_lmt')
       !
    END SUBROUTINE wad_lmt
@@ -284,127 +271,115 @@
       REAL(wp) ::   zdepwd              ! local scalar, always wet cell depth
       REAL(wp) ::   ztmp                ! local scalars
-      REAL(wp), POINTER,  DIMENSION(:,:) ::   zwdlmtu, zwdlmtv         !: W/D flux limiters
-      REAL(wp), POINTER,  DIMENSION(:,:) ::   zflxp,  zflxn            ! local 2D workspace
-      REAL(wp), POINTER,  DIMENSION(:,:) ::   zflxu1, zflxv1           ! local 2D workspace
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('wad_lmt_bt')
-
-      IF(ln_wd) THEN
-
-        CALL wrk_alloc( jpi, jpj, zflxp, zflxn, zflxu1, zflxv1 )
-        CALL wrk_alloc( jpi, jpj, zwdlmtu, zwdlmtv)
-        !
-       
-        !IF(lwp) WRITE(numout,*)
-        !IF(lwp) WRITE(numout,*) 'wad_lmt_bt : wetting/drying limiters and velocity limiting'
-       
-        jflag  = 0
-        zdepwd = 50._wp   !maximum depth that ocean cells can have W/D processes
-
-        z2dt = rdtbt   
-       
-        zflxp(:,:)   = 0._wp
-        zflxn(:,:)   = 0._wp
-
-        zwdlmtu(:,:)  = 1._wp
-        zwdlmtv(:,:)  = 1._wp
-       
-        ! Horizontal Flux in u and v direction
-       
-        DO jj = 2, jpj
-           DO ji = 2, jpi 
-
-             IF( tmask(ji, jj, 1 ) < 0.5_wp) CYCLE   ! we don't care about land cells
-             IF( ht_wd(ji,jj) > zdepwd )      CYCLE   ! and cells which are unlikely to dry
-
-              zflxp(ji,jj) = max(zflxu(ji,jj), 0._wp) - min(zflxu(ji-1,jj),   0._wp) + &
-                           & max(zflxv(ji,jj), 0._wp) - min(zflxv(ji,  jj-1), 0._wp) 
-              zflxn(ji,jj) = min(zflxu(ji,jj), 0._wp) - max(zflxu(ji-1,jj),   0._wp) + &
-                           & min(zflxv(ji,jj), 0._wp) - max(zflxv(ji,  jj-1), 0._wp) 
-
-              zdep2 = ht_wd(ji,jj) + sshn_e(ji,jj) - rn_wdmin1
-              IF(zdep2 .le. 0._wp) THEN  !add more safety, but not necessary
-                sshn_e(ji,jj) = rn_wdmin1 - ht_wd(ji,jj)
-                IF(zflxu(ji,  jj) > 0._wp) zwdlmtu(ji  ,jj) = 0._wp
-                IF(zflxu(ji-1,jj) < 0._wp) zwdlmtu(ji-1,jj) = 0._wp
-                IF(zflxv(ji,  jj) > 0._wp) zwdlmtv(ji  ,jj) = 0._wp
-                IF(zflxv(ji,jj-1) < 0._wp) zwdlmtv(ji,jj-1) = 0._wp 
-              END IF
-           ENDDO
-        END DO
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwdlmtu, zwdlmtv         !: W/D flux limiters
+      REAL(wp), DIMENSION(jpi,jpj) ::   zflxp,  zflxn            ! local 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj) ::   zflxu1, zflxv1           ! local 2D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )  CALL timing_start('wad_lmt_bt')
+      !       
+      !IF(lwp) WRITE(numout,*)
+      !IF(lwp) WRITE(numout,*) 'wad_lmt_bt : wetting/drying limiters and velocity limiting'
+       
+      jflag  = 0
+      zdepwd = 50._wp   !maximum depth that ocean cells can have W/D processes
+
+      z2dt = rdtbt   
+       
+      zflxp(:,:)   = 0._wp
+      zflxn(:,:)   = 0._wp
+
+      zwdlmtu(:,:) = 1._wp
+      zwdlmtv(:,:) = 1._wp
+       
+      ! Horizontal Flux in u and v direction
+       
+      DO jj = 2, jpj
+         DO ji = 2, jpi 
+            !
+            IF( tmask(ji,jj,1) < 0.5_wp )   CYCLE   ! we don't care about land cells
+            IF( ht_wd(ji,jj)   > zdepwd )   CYCLE   ! and cells which are unlikely to dry
+            !
+            zflxp(ji,jj) = MAX( zflxu(ji,jj) , 0._wp ) - MIN( zflxu(ji-1,jj) , 0._wp )   &
+               &         + MAX( zflxv(ji,jj) , 0._wp ) - MIN( zflxv(ji,jj-1) , 0._wp ) 
+            zflxn(ji,jj) = MIN( zflxu(ji,jj) , 0._wp ) - MAX( zflxu(ji-1,jj) , 0._wp )   &
+               &         + MIN( zflxv(ji,jj) , 0._wp ) - MAX( zflxv(ji,jj-1) , 0._wp ) 
+
+            zdep2 = ht_wd(ji,jj) + sshn_e(ji,jj) - rn_wdmin1
+            IF(zdep2 .le. 0._wp) THEN  !add more safety, but not necessary
+               sshn_e(ji,jj) = rn_wdmin1 - ht_wd(ji,jj)
+               IF( zflxu(ji,  jj) > 0._wp )   zwdlmtu(ji  ,jj) = 0._wp
+               IF( zflxu(ji-1,jj) < 0._wp )   zwdlmtu(ji-1,jj) = 0._wp
+               IF( zflxv(ji,  jj) > 0._wp )   zwdlmtv(ji  ,jj) = 0._wp
+               IF( zflxv(ji,jj-1) < 0._wp )   zwdlmtv(ji,jj-1) = 0._wp 
+            ENDIF
+         END DO
+      END DO
 
       
-        !! start limiter iterations 
-        DO jk1 = 1, nn_wdit + 1
-       
+      !! start limiter iterations 
+      DO jk1 = 1, nn_wdit + 1
+         ! 
+         zflxu1(:,:) = zflxu(:,:) * zwdlmtu(:,:)
+         zflxv1(:,:) = zflxv(:,:) * zwdlmtv(:,:)
+         jflag = 0     ! flag indicating if any further iterations are needed
+         !
+         DO jj = 2, jpj
+            DO ji = 2, jpi 
+               !
+               IF( tmask(ji,jj, 1 ) < 0.5_wp  )   CYCLE 
+               IF( ht_wd(ji,jj)      > zdepwd )   CYCLE
+               !
+               ztmp = e1e2t(ji,jj)
+               !
+               zzflxp = MAX( zflxu1(ji,jj) , 0._wp ) - MIN( zflxu1(ji-1,jj) , 0._wp )   &
+                  &   + MAX( zflxv1(ji,jj) , 0._wp ) - MIN( zflxv1(ji,jj-1) , 0._wp ) 
+               zzflxn = MIN( zflxu1(ji,jj) , 0._wp ) - MAX( zflxu1(ji-1,jj) , 0._wp )   &
+                  &   + MIN( zflxv1(ji,jj) , 0._wp ) - MAX( zflxv1(ji,jj-1) , 0._wp ) 
           
-           zflxu1(:,:) = zflxu(:,:) * zwdlmtu(:,:)
-           zflxv1(:,:) = zflxv(:,:) * zwdlmtv(:,:)
-           jflag = 0     ! flag indicating if any further iterations are needed
+               zdep1 = (zzflxp + zzflxn) * z2dt / ztmp
+               zdep2 = ht_wd(ji,jj) + sshn_e(ji,jj) - rn_wdmin1 - z2dt * zssh_frc(ji,jj)
           
-           DO jj = 2, jpj
-              DO ji = 2, jpi 
-        
-                 IF( tmask(ji, jj, 1 ) < 0.5_wp) CYCLE 
-                 IF( ht_wd(ji,jj) > zdepwd )      CYCLE
-        
-                 ztmp = e1e2t(ji,jj)
-
-                 zzflxp = max(zflxu1(ji,jj), 0._wp) - min(zflxu1(ji-1,jj),   0._wp) + &
-                        & max(zflxv1(ji,jj), 0._wp) - min(zflxv1(ji,  jj-1), 0._wp) 
-                 zzflxn = min(zflxu1(ji,jj), 0._wp) - max(zflxu1(ji-1,jj),   0._wp) + &
-                        & min(zflxv1(ji,jj), 0._wp) - max(zflxv1(ji,  jj-1), 0._wp) 
-          
-                 zdep1 = (zzflxp + zzflxn) * z2dt / ztmp
-                 zdep2 = ht_wd(ji,jj) + sshn_e(ji,jj) - rn_wdmin1 - z2dt * zssh_frc(ji,jj)
-          
-                 IF(zdep1 > zdep2) THEN
-                   zcoef = ( ( zdep2 - rn_wdmin2 ) * ztmp - zzflxn * z2dt ) / ( zflxp(ji,jj) * z2dt )
-                   !zcoef = ( ( zdep2 - rn_wdmin2 ) * ztmp - zzflxn * z2dt ) / ( zzflxp * z2dt )
-                   ! flag if the limiter has been used but stop flagging if the only
-                   ! changes have zeroed the coefficient since further iterations will
-                   ! not change anything
-                   IF( zcoef > 0._wp ) THEN
+               IF(zdep1 > zdep2) THEN
+                  zcoef = ( ( zdep2 - rn_wdmin2 ) * ztmp - zzflxn * z2dt ) / ( zflxp(ji,jj) * z2dt )
+                  !zcoef = ( ( zdep2 - rn_wdmin2 ) * ztmp - zzflxn * z2dt ) / ( zzflxp * z2dt )
+                  ! flag if the limiter has been used but stop flagging if the only
+                  ! changes have zeroed the coefficient since further iterations will
+                  ! not change anything
+                  IF( zcoef > 0._wp ) THEN
                       jflag = 1 
-                   ELSE
+                  ELSE
                       zcoef = 0._wp
-                   ENDIF
-                   IF(jk1 > nn_wdit) zcoef = 0._wp
-                   IF(zflxu1(ji,  jj) > 0._wp) zwdlmtu(ji  ,jj) = zcoef
-                   IF(zflxu1(ji-1,jj) < 0._wp) zwdlmtu(ji-1,jj) = zcoef
-                   IF(zflxv1(ji,  jj) > 0._wp) zwdlmtv(ji  ,jj) = zcoef
-                   IF(zflxv1(ji,jj-1) < 0._wp) zwdlmtv(ji,jj-1) = zcoef
-                 END IF
-              END DO ! ji loop
-           END DO  ! jj loop
-
-           CALL lbc_lnk( zwdlmtu, 'U', 1. )
-           CALL lbc_lnk( zwdlmtv, 'V', 1. )
-
-           IF(lk_mpp) CALL mpp_max(jflag)   !max over the global domain
-
-           IF(jflag == 0) EXIT
-          
-        END DO  ! jk1 loop
-       
-        zflxu(:,:) = zflxu(:,:) * zwdlmtu(:, :) 
-        zflxv(:,:) = zflxv(:,:) * zwdlmtv(:, :) 
-
-        CALL lbc_lnk( zflxu, 'U', -1. )
-        CALL lbc_lnk( zflxv, 'V', -1. )
-       
-        IF(jflag == 1 .AND. lwp) WRITE(numout,*) 'Need more iterations in wad_lmt_bt!!!'
-       
-        !IF( ln_rnf      )   CALL sbc_rnf_div( hdivn )          ! runoffs (update hdivn field)
-        !IF( nn_cla == 1 )   CALL cla_div    ( kt )             ! Cross Land Advection (update hdivn field)
-        !
-        !
-        CALL wrk_dealloc( jpi, jpj, zflxp, zflxn, zflxu1, zflxv1 )
-        CALL wrk_dealloc( jpi, jpj, zwdlmtu, zwdlmtv)
-        !
-      END IF
-
-      IF( nn_timing == 1 )  CALL timing_stop('wad_lmt')
+                  ENDIF
+                  IF( jk1 > nn_wdit )   zcoef = 0._wp
+                  IF( zflxu1(ji,  jj) > 0._wp )   zwdlmtu(ji  ,jj) = zcoef
+                  IF( zflxu1(ji-1,jj) < 0._wp )   zwdlmtu(ji-1,jj) = zcoef
+                  IF( zflxv1(ji,  jj) > 0._wp )   zwdlmtv(ji  ,jj) = zcoef
+                  IF( zflxv1(ji,jj-1) < 0._wp )   zwdlmtv(ji,jj-1) = zcoef
+               ENDIF
+            END DO ! ji loop
+         END DO  ! jj loop
+         !
+         CALL lbc_lnk( zwdlmtu, 'U', 1. )
+         CALL lbc_lnk( zwdlmtv, 'V', 1. )
+         !
+         IF(lk_mpp)   CALL mpp_max(jflag)   !max over the global domain
+         !
+         IF( jflag == 0 )   EXIT
+         !    
+      END DO  ! jk1 loop
+      ! 
+      zflxu(:,:) = zflxu(:,:) * zwdlmtu(:, :) 
+      zflxv(:,:) = zflxv(:,:) * zwdlmtv(:, :) 
+      !
+      CALL lbc_lnk( zflxu, 'U', -1. )
+      CALL lbc_lnk( zflxv, 'V', -1. )
+      !
+      IF(jflag == 1 .AND. lwp) WRITE(numout,*) 'Need more iterations in wad_lmt_bt!!!'
+       
+      !IF( ln_rnf      )   CALL sbc_rnf_div( hdivn )          ! runoffs (update hdivn field)
+      !IF( nn_cla == 1 )   CALL cla_div    ( kt )             ! Cross Land Advection (update hdivn field)
+      !
+      IF( ln_timing )  CALL timing_stop('wad_lmt_bt')
+      !
    END SUBROUTINE wad_lmt_bt
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ICB/icb_oce.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ICB/icb_oce.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ICB/icb_oce.F90	(revision 9019)
@@ -90,5 +90,5 @@
    REAL(wp), PUBLIC, DIMENSION(:,:), ALLOCATABLE ::   ua_e, va_e
    REAL(wp), PUBLIC, DIMENSION(:,:), ALLOCATABLE ::   ssh_e
-#if defined key_lim2 || defined key_lim3 || defined key_cice
+#if defined key_lim3 || defined key_cice
    REAL(wp), PUBLIC, DIMENSION(:,:), ALLOCATABLE ::   ui_e, vi_e
 #endif
@@ -170,5 +170,5 @@
       ALLOCATE( uo_e(0:jpi+1,0:jpj+1) , ua_e(0:jpi+1,0:jpj+1) ,   &
          &      vo_e(0:jpi+1,0:jpj+1) , va_e(0:jpi+1,0:jpj+1) ,   &
-#if defined key_lim2 || defined key_lim3 || defined key_cice
+#if defined key_lim3 || defined key_cice
          &      ui_e(0:jpi+1,0:jpj+1) ,                            &
          &      vi_e(0:jpi+1,0:jpj+1) ,                            &
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ICB/icbtrj.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ICB/icbtrj.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ICB/icbtrj.F90	(revision 9019)
@@ -16,11 +16,11 @@
    USE dom_oce        ! NEMO ocean domain
    USE phycst         ! NEMO physical constants
+   USE icb_oce        ! define iceberg arrays
+   USE icbutl         ! iceberg utility routines
+   !
    USE lib_mpp        ! NEMO MPI library, lk_mpp in particular
    USE in_out_manager ! NEMO IO, numout in particular
-   USE ioipsl, ONLY : ju2ymds    ! for calendar
+   USE ioipsl  , ONLY : ju2ymds    ! for calendar
    USE netcdf
-   !
-   USE icb_oce        ! define iceberg arrays
-   USE icbutl         ! iceberg utility routines
 
    IMPLICIT NONE
@@ -58,13 +58,12 @@
       !! ** Purpose :   initialise iceberg trajectory output files
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in )                 :: ktend
-      !
-      INTEGER                               :: iret
-      INTEGER                               :: iyear, imonth, iday
-      REAL(wp)                              :: zfjulday, zsec
-      CHARACTER(len=80)                     :: cl_filename
-      TYPE(iceberg), POINTER                :: this
-      TYPE(point)  , POINTER                :: pt
-      CHARACTER(LEN=20)                     :: cldate_ini, cldate_end
+      INTEGER, INTENT(in) ::   ktend   ! time step index
+      !
+      INTEGER                ::   iret, iyear, imonth, iday
+      REAL(wp)               ::   zfjulday, zsec
+      CHARACTER(len=80)      ::   cl_filename
+      CHARACTER(LEN=20)      ::   cldate_ini, cldate_end
+      TYPE(iceberg), POINTER ::   this
+      TYPE(point)  , POINTER ::   pt
       !!----------------------------------------------------------------------
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ICB/icbutl.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ICB/icbutl.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ICB/icbutl.F90	(revision 9019)
@@ -21,11 +21,6 @@
    USE icb_oce                             ! define iceberg arrays
    USE sbc_oce                             ! ocean surface boundary conditions
-#if defined key_lim2
-   USE ice_2,         ONLY: u_ice, v_ice   ! LIM-2 ice velocities  (CAUTION in C-grid do not use key_vp option)
-   USE ice_2,         ONLY: hicif          ! LIM-2 ice thickness
-#elif defined key_lim3
-   USE ice,           ONLY: u_ice, v_ice   ! LIM-3 variables  (always in C-grid)
-                                           ! gm  LIM3 case the mean ice thickness (i.e. averaged over categories)
-                                           ! gm            has to be computed somewhere in the ice and accessed here
+#if defined key_lim3
+   USE ice,    ONLY: u_ice, v_ice, hm_i    ! LIM-3 variables
 #endif
 
@@ -85,13 +80,9 @@
       CALL lbc_lnk_icb( fr_e, 'T', +1._wp, 1, 1 )
       CALL lbc_lnk_icb( tt_e, 'T', +1._wp, 1, 1 )
-#if defined key_lim2
-      hicth(:,:) = 0._wp ;  hicth(1:jpi,1:jpj) = hicif(:,:)  
-      CALL lbc_lnk_icb(hicth, 'T', +1._wp, 1, 1 )  
-#endif
-
-#if defined key_lim2 || defined key_lim3
+#if defined key_lim3
+      hicth(:,:) = 0._wp ;  hicth(1:jpi,1:jpj) = hm_i (:,:)  
       ui_e(:,:) = 0._wp ;   ui_e(1:jpi, 1:jpj) = u_ice(:,:)
       vi_e(:,:) = 0._wp ;   vi_e(1:jpi, 1:jpj) = v_ice(:,:)
-
+      CALL lbc_lnk_icb(hicth, 'T', +1._wp, 1, 1 )
       CALL lbc_lnk_icb( ui_e, 'U', -1._wp, 1, 1 )
       CALL lbc_lnk_icb( vi_e, 'V', -1._wp, 1, 1 )
@@ -157,12 +148,8 @@
       pva  = pva * zmod
 
-#if defined key_lim2 || defined key_lim3
+#if defined key_lim3
       pui = icb_utl_bilin_h( ui_e, pi, pj, 'U' )              ! sea-ice velocities
       pvi = icb_utl_bilin_h( vi_e, pi, pj, 'V' )
-# if defined key_lim3
-      phi = 0._wp                                             ! LIM-3 case (to do)
-# else
       phi = icb_utl_bilin_h(hicth, pi, pj, 'T' )              ! ice thickness
-# endif
 #else
       pui = 0._wp
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 9019)
@@ -88,6 +88,9 @@
    INTEGER ::   nitrst                !: time step at which restart file should be written
    LOGICAL ::   lrst_oce              !: logical to control the oce restart write 
+   LOGICAL ::   lrst_ice              !: logical to control the ice restart write 
    INTEGER ::   numror = 0            !: logical unit for ocean restart (read). Init to 0 is needed for SAS (in daymod.F90)
+   INTEGER ::   numrir                !: logical unit for ice   restart (read)
    INTEGER ::   numrow                !: logical unit for ocean restart (write)
+   INTEGER ::   numriw                !: logical unit for ice   restart (write)
    INTEGER ::   nrst_lst              !: number of restart to output next
 
@@ -96,6 +99,9 @@
    !!----------------------------------------------------------------------
    LOGICAL ::   ln_ctl           !: run control for debugging
+   LOGICAL ::   ln_timing        !: run control for timing
+!!gm to be removed at the end of the 2017 merge party
    INTEGER ::   nn_timing        !: run control for timing
-   INTEGER ::   nn_diacfl        !: flag whether to create CFL diagnostics
+!!gm end
+   LOGICAL ::   ln_diacfl        !: flag whether to create CFL diagnostics
    INTEGER ::   nn_print         !: level of print (0 no print)
    INTEGER ::   nn_ictls         !: Start i indice for the SUM control
@@ -126,5 +132,5 @@
    INTEGER ::   numoni          =   -1      !: logical unit for Output Namelist Ice
    INTEGER ::   numevo_ice      =   -1      !: logical unit for ice variables (temp. evolution)
-   INTEGER ::   numsol          =   -1      !: logical unit for solver statistics
+   INTEGER ::   numrun          =   -1      !: logical unit for run statistics
    INTEGER ::   numdct_in       =   -1      !: logical unit for transports computing
    INTEGER ::   numdct_vol      =   -1      !: logical unit for voulume transports output
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 9019)
@@ -1,7 +1,7 @@
 MODULE iom
-   !!=====================================================================
+   !!======================================================================
    !!                    ***  MODULE  iom ***
    !! Input/Output manager :  Library to read input files
-   !!====================================================================
+   !!======================================================================
    !! History :  2.0  ! 2005-12  (J. Belier) Original code
    !!            2.0  ! 2006-02  (S. Masson) Adaptation to NEMO
@@ -10,7 +10,8 @@
    !!            3.6  ! 2014-15  DIMG format removed
    !!            3.6  ! 2015-15  (J. Harle) Added procedure to read REAL attributes
-   !!--------------------------------------------------------------------
-
-   !!--------------------------------------------------------------------
+   !!            4.0  ! 2017-11  (M. Andrejczuk) Extend IOM interface to write any 3D fields
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
    !!   iom_open       : open a file read only
    !!   iom_close      : close a file or all files opened by iom
@@ -19,5 +20,5 @@
    !!   iom_varid      : get the id of a variable in a file
    !!   iom_rstput     : write a field in a restart file (interfaced to several routines)
-   !!--------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    USE dom_oce         ! ocean space and time domain
    USE c1d             ! 1D vertical configuration
@@ -29,11 +30,9 @@
    USE lib_mpp           ! MPP library
 #if defined key_iomput
-   USE sbc_oce, ONLY :   nn_fsbc         ! ocean space and time domain
-   USE trc_oce, ONLY :   nn_dttrc        !  !: frequency of step on passive tracers
-   USE icb_oce, ONLY :   nclasses, class_num       !  !: iceberg classes
+   USE sbc_oce  , ONLY :   nn_fsbc         ! ocean space and time domain
+   USE trc_oce  , ONLY :   nn_dttrc        !  !: frequency of step on passive tracers
+   USE icb_oce  , ONLY :   nclasses, class_num       !  !: iceberg classes
 #if defined key_lim3
-   USE ice    , ONLY :   jpl
-#elif defined key_lim2
-   USE par_ice_2
+   USE ice      , ONLY :   jpl
 #endif
    USE domngb          ! ocean space and time domain
@@ -82,9 +81,8 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -97,6 +95,7 @@
       !!----------------------------------------------------------------------
       CHARACTER(len=*), INTENT(in)  :: cdname
+      !
 #if defined key_iomput
-
+      !
       TYPE(xios_duration) :: dtime    = xios_duration(0, 0, 0, 0, 0, 0)
       TYPE(xios_date)     :: start_date
@@ -106,7 +105,7 @@
       REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: zt_bnds, zw_bnds
       !!----------------------------------------------------------------------
-
+      !
       ALLOCATE( zt_bnds(2,jpk), zw_bnds(2,jpk) )
-
+      !
       clname = cdname
       IF( TRIM(Agrif_CFixed()) /= '0' )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(cdname)
@@ -127,5 +126,5 @@
       ! horizontal grid definition
       CALL set_scalar
-
+      !
       IF( TRIM(cdname) == TRIM(cxios_context) ) THEN  
          CALL set_grid( "T", glamt, gphit ) 
@@ -146,5 +145,5 @@
          ENDIF
       ENDIF
-
+      !
       IF( TRIM(cdname) == TRIM(cxios_context)//"_crs" ) THEN  
          CALL dom_grid_crs   ! Save the parent grid information  & Switch to coarse grid domain
@@ -169,5 +168,5 @@
          ENDIF
       ENDIF
-
+      !
       ! vertical grid definition
       CALL iom_set_axis_attr( "deptht", gdept_1d )
@@ -175,5 +174,5 @@
       CALL iom_set_axis_attr( "depthv", gdept_1d )
       CALL iom_set_axis_attr( "depthw", gdepw_1d )
-
+      !
       ! Add vertical grid bounds
       jkmin = MIN(2,jpk)  ! in case jpk=1 (i.e. sas2D)
@@ -188,12 +187,13 @@
       CALL iom_set_axis_attr( "depthv", bounds=zt_bnds )
       CALL iom_set_axis_attr( "depthw", bounds=zw_bnds )
-
-
+      !
 # if defined key_floats
       CALL iom_set_axis_attr( "nfloat", (/ (REAL(ji,wp), ji=1,nfloat) /) )
 # endif
-#if defined key_lim3 || defined key_lim2
+# if defined key_lim3
       CALL iom_set_axis_attr( "ncatice", (/ (REAL(ji,wp), ji=1,jpl) /) )
-#endif
+      ! SIMIP diagnostics (4 main arctic straits)
+      CALL iom_set_axis_attr( "nstrait", (/ (REAL(ji,wp), ji=1,4) /) )
+# endif
       CALL iom_set_axis_attr( "icbcla", class_num )
       CALL iom_set_axis_attr( "iax_20C", (/ REAL(20,wp) /) )
@@ -202,16 +202,15 @@
       ! automatic definitions of some of the xml attributs
       CALL set_xmlatt
-
+      !
       ! end file definition
       dtime%second = rdt
-      CALL xios_set_timestep(dtime)
+      CALL xios_set_timestep( dtime )
       CALL xios_close_context_definition()
-      
-      CALL xios_update_calendar(0)
-
+      CALL xios_update_calendar( 0 )
+      !
       DEALLOCATE( zt_bnds, zw_bnds )
-
+      !
 #endif
-      
+      !
    END SUBROUTINE iom_init
 
@@ -239,5 +238,5 @@
 
 
-   SUBROUTINE iom_open( cdname, kiomid, ldwrt, kdom, kiolib, ldstop, ldiof )
+   SUBROUTINE iom_open( cdname, kiomid, ldwrt, kdom, kiolib, ldstop, ldiof, kdlev )
       !!---------------------------------------------------------------------
       !!                   ***  SUBROUTINE  iom_open  ***
@@ -252,5 +251,6 @@
       LOGICAL         , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if open to read a non-existing file (default = .TRUE.)
       LOGICAL         , INTENT(in   ), OPTIONAL ::   ldiof    ! Interp On the Fly, needed for AGRIF (default = .FALSE.)
-
+      INTEGER         , INTENT(in   ), OPTIONAL ::   kdlev    ! number of vertical levels
+      !
       CHARACTER(LEN=256)    ::   clname    ! the name of the file based on cdname [[+clcpu]+clcpu]
       CHARACTER(LEN=256)    ::   cltmpn    ! tempory name to store clname (in writting mode)
@@ -405,5 +405,5 @@
       IF( istop == nstop ) THEN   ! no error within this routine
          SELECT CASE (iolib)
-         CASE (jpnf90   )   ;   CALL iom_nf90_open(    clname, kiomid, llwrt, llok, idompar )
+         CASE (jpnf90   )   ;   CALL iom_nf90_open(    clname, kiomid, llwrt, llok, idompar, kdlev = kdlev )
          CASE DEFAULT
             CALL ctl_stop( TRIM(clinfo)//' accepted IO library is only jpnf90 (jpioipsl option has been removed) ' )
@@ -644,7 +644,7 @@
       INTEGER , DIMENSION(:)     , INTENT(in   ), OPTIONAL ::   kcount     ! number of points to be read in each axis
       LOGICAL                    , INTENT(in   ), OPTIONAL ::   lrowattr   ! logical flag telling iom_get to
-                                                                           ! look for and use a file attribute
-                                                                           ! called open_ocean_jstart to set the start
-                                                                           ! value for the 2nd dimension (netcdf only)
+      !                                                                    ! look for and use a file attribute
+      !                                                                    ! called open_ocean_jstart to set the start
+      !                                                                    ! value for the 2nd dimension (netcdf only)
       !
       LOGICAL                        ::   llnoov      ! local definition to read overlap
@@ -672,6 +672,9 @@
       CHARACTER(LEN=1)               ::   clrankpv, cldmspc      ! 
       LOGICAL                        ::   ll_depth_spec ! T => if kstart, kcount present then *only* use values for 3rd spatial dimension.
+      INTEGER                        ::   inlev       ! number of levels for 3D data
       !---------------------------------------------------------------------
       !
+      inlev = -1
+      IF( PRESENT(pv_r3d) )   inlev = SIZE(pv_r3d, 3)
       clname = iom_file(kiomid)%name   !   esier to read
       clinfo = '          iom_get_123d, file: '//trim(clname)//', var: '//trim(cdvar)
@@ -775,5 +778,6 @@
 
          IF( PRESENT(kstart) .AND. .NOT. ll_depth_spec ) THEN 
-            istart(1:idmspc) = kstart(1:idmspc) ; icnt(1:idmspc) = kcount(1:idmspc)
+            istart(1:idmspc) = kstart(1:idmspc) 
+            icnt  (1:idmspc) = kcount(1:idmspc)
          ELSE
             IF(idom == jpdom_unknown ) THEN
@@ -801,7 +805,7 @@
                   ENDIF
                   IF( PRESENT(pv_r3d) ) THEN
-                     IF( idom == jpdom_data ) THEN                                  ; icnt(3) = jpkglo
-                     ELSE IF( ll_depth_spec .AND. PRESENT(kstart) ) THEN            ; istart(3) = kstart(3); icnt(3) = kcount(3)
-                     ELSE                                                           ; icnt(3) = jpk
+                     IF( idom == jpdom_data ) THEN                        ;                               icnt(3) = inlev
+                     ELSEIF( ll_depth_spec .AND. PRESENT(kstart) ) THEN   ;   istart(3) = kstart(3)   ;   icnt(3) = kcount(3)
+                     ELSE                                                 ;                               icnt(3) = inlev
                      ENDIF
                   ENDIF
@@ -886,5 +890,5 @@
             ELSEIF( PRESENT(pv_r3d) .AND. idom /= jpdom_unknown ) THEN
                ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension
-               IF( icnt(3) == jpk ) THEN
+               IF( icnt(3) == inlev ) THEN
                   CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' )
                ELSE   ! put some arbitrary value (a call to lbc_lnk will be done later...)
@@ -1135,4 +1139,5 @@
    END SUBROUTINE iom_rp0d
 
+
    SUBROUTINE iom_rp1d( kt, kwrite, kiomid, cdvar, pvar, ktype )
       INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
@@ -1155,4 +1160,5 @@
    END SUBROUTINE iom_rp1d
 
+
    SUBROUTINE iom_rp2d( kt, kwrite, kiomid, cdvar, pvar, ktype )
       INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
@@ -1175,4 +1181,5 @@
    END SUBROUTINE iom_rp2d
 
+
    SUBROUTINE iom_rp3d( kt, kwrite, kiomid, cdvar, pvar, ktype )
       INTEGER         , INTENT(in)                         ::   kt       ! ocean time-step
@@ -1236,26 +1243,30 @@
       REAL(wp),       DIMENSION(:,:,:), INTENT(in) ::   pfield3d
 #if defined key_iomput
-      CALL xios_send_field(cdname, pfield3d)
+      CALL xios_send_field( cdname, pfield3d )
 #else
       IF( .FALSE. )   WRITE(numout,*) cdname, pfield3d   ! useless test to avoid compilation warnings
 #endif
    END SUBROUTINE iom_p3d
+
+#if defined key_iomput
    !!----------------------------------------------------------------------
-
-#if defined key_iomput
+   !!   'key_iomput'                                         IOM  interface
+   !!----------------------------------------------------------------------
 
    SUBROUTINE iom_set_domain_attr( cdid, ni_glo, nj_glo, ibegin, jbegin, ni, nj, zoom_ibegin, zoom_jbegin, zoom_ni, zoom_nj,   &
       &                                    data_dim, data_ibegin, data_ni, data_jbegin, data_nj, lonvalue, latvalue, mask,     &
       &                                    nvertex, bounds_lon, bounds_lat, area )
-      CHARACTER(LEN=*)                   , INTENT(in) ::   cdid
-      INTEGER                  , OPTIONAL, INTENT(in) ::   ni_glo, nj_glo, ibegin, jbegin, ni, nj
-      INTEGER                  , OPTIONAL, INTENT(in) ::   data_dim, data_ibegin, data_ni, data_jbegin, data_nj
-      INTEGER                  , OPTIONAL, INTENT(in) ::   zoom_ibegin, zoom_jbegin, zoom_ni, zoom_nj, nvertex
-      REAL(wp), DIMENSION(:)   , OPTIONAL, INTENT(in) ::   lonvalue, latvalue
-      REAL(wp), DIMENSION(:,:) , OPTIONAL, INTENT(in) ::   bounds_lon, bounds_lat, area
-      LOGICAL, DIMENSION(:)   , OPTIONAL, INTENT(in) ::   mask
-
-
-      IF ( xios_is_valid_domain     (cdid) ) THEN
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+      CHARACTER(LEN=*)                  , INTENT(in) ::   cdid
+      INTEGER                 , OPTIONAL, INTENT(in) ::   ni_glo, nj_glo, ibegin, jbegin, ni, nj
+      INTEGER                 , OPTIONAL, INTENT(in) ::   data_dim, data_ibegin, data_ni, data_jbegin, data_nj
+      INTEGER                 , OPTIONAL, INTENT(in) ::   zoom_ibegin, zoom_jbegin, zoom_ni, zoom_nj, nvertex
+      REAL(wp), DIMENSION(:)  , OPTIONAL, INTENT(in) ::   lonvalue, latvalue
+      REAL(wp), DIMENSION(:,:), OPTIONAL, INTENT(in) ::   bounds_lon, bounds_lat, area
+      LOGICAL , DIMENSION(:)  , OPTIONAL, INTENT(in) ::   mask
+      !!----------------------------------------------------------------------
+      !
+      IF( xios_is_valid_domain     (cdid) ) THEN
          CALL xios_set_domain_attr     ( cdid, ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, jbegin=jbegin, ni=ni, nj=nj,   &
             &    data_dim=data_dim, data_ibegin=data_ibegin, data_ni=data_ni, data_jbegin=data_jbegin, data_nj=data_nj ,   &
@@ -1263,5 +1274,5 @@
             &    bounds_lat_1D=bounds_lat, area=area, type='curvilinear')
      ENDIF
-      IF ( xios_is_valid_domaingroup(cdid) ) THEN
+      IF( xios_is_valid_domaingroup(cdid) ) THEN
          CALL xios_set_domaingroup_attr( cdid, ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, jbegin=jbegin, ni=ni, nj=nj,   &
             &    data_dim=data_dim, data_ibegin=data_ibegin, data_ni=data_ni, data_jbegin=data_jbegin, data_nj=data_nj ,   &
@@ -1269,32 +1280,33 @@
             &    bounds_lat_1D=bounds_lat, area=area, type='curvilinear' )
       ENDIF
-
+      !
       CALL xios_solve_inheritance()
-
+      !
    END SUBROUTINE iom_set_domain_attr
 
 
-   SUBROUTINE iom_set_zoom_domain_attr( cdid, ibegin, jbegin, ni, nj)
-      CHARACTER(LEN=*)                   , INTENT(in) ::   cdid
-      INTEGER                  , OPTIONAL, INTENT(in) ::   ibegin, jbegin, ni, nj
-
-      IF ( xios_is_valid_zoom_domain     (cdid) ) THEN
-          CALL xios_set_zoom_domain_attr     ( cdid, ibegin=ibegin, jbegin=jbegin, ni=ni,    &
-            &   nj=nj)
-     ENDIF
+   SUBROUTINE iom_set_zoom_domain_attr( cdid, ibegin, jbegin, ni, nj )
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+      CHARACTER(LEN=*)          , INTENT(in) ::   cdid
+      INTEGER         , OPTIONAL, INTENT(in) ::   ibegin, jbegin, ni, nj
+      !!----------------------------------------------------------------------
+      IF( xios_is_valid_zoom_domain(cdid) )   CALL xios_set_zoom_domain_attr( cdid, ibegin=ibegin, jbegin=jbegin, ni=ni, nj=nj )
    END SUBROUTINE iom_set_zoom_domain_attr
 
 
    SUBROUTINE iom_set_axis_attr( cdid, paxis, bounds )
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
       CHARACTER(LEN=*)      , INTENT(in) ::   cdid
       REAL(wp), DIMENSION(:)  , OPTIONAL, INTENT(in) ::   paxis
       REAL(wp), DIMENSION(:,:), OPTIONAL, INTENT(in) ::   bounds
-
-      IF ( PRESENT(paxis) ) THEN
-         IF ( xios_is_valid_axis     (cdid) )   CALL xios_set_axis_attr     ( cdid, n_glo=SIZE(paxis), value=paxis )
-         IF ( xios_is_valid_axisgroup(cdid) )   CALL xios_set_axisgroup_attr( cdid, n_glo=SIZE(paxis), value=paxis )
-      ENDIF
-      IF ( xios_is_valid_axis     (cdid) )   CALL xios_set_axis_attr     ( cdid, bounds=bounds )
-      IF ( xios_is_valid_axisgroup(cdid) )   CALL xios_set_axisgroup_attr( cdid, bounds=bounds )
+      !!----------------------------------------------------------------------
+      IF( PRESENT(paxis) ) THEN
+         IF( xios_is_valid_axis     (cdid) )   CALL xios_set_axis_attr     ( cdid, n_glo=SIZE(paxis), value=paxis )
+         IF( xios_is_valid_axisgroup(cdid) )   CALL xios_set_axisgroup_attr( cdid, n_glo=SIZE(paxis), value=paxis )
+      ENDIF
+      IF( xios_is_valid_axis     (cdid) )   CALL xios_set_axis_attr     ( cdid, bounds=bounds )
+      IF( xios_is_valid_axisgroup(cdid) )   CALL xios_set_axisgroup_attr( cdid, bounds=bounds )
       CALL xios_solve_inheritance()
    END SUBROUTINE iom_set_axis_attr
@@ -1302,11 +1314,12 @@
 
    SUBROUTINE iom_set_field_attr( cdid, freq_op, freq_offset )
-      CHARACTER(LEN=*)          , INTENT(in) ::   cdid
-      TYPE(xios_duration),OPTIONAL , INTENT(in) ::   freq_op
-      TYPE(xios_duration),OPTIONAL , INTENT(in) ::   freq_offset
-      IF ( xios_is_valid_field     (cdid) )   CALL xios_set_field_attr       &
-    &     ( cdid, freq_op=freq_op, freq_offset=freq_offset )
-      IF ( xios_is_valid_fieldgroup(cdid) )   CALL xios_set_fieldgroup_attr  &
-    &                    ( cdid, freq_op=freq_op, freq_offset=freq_offset )
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+      CHARACTER(LEN=*)             , INTENT(in) ::   cdid
+      TYPE(xios_duration), OPTIONAL, INTENT(in) ::   freq_op
+      TYPE(xios_duration), OPTIONAL, INTENT(in) ::   freq_offset
+      !!----------------------------------------------------------------------
+      IF( xios_is_valid_field     (cdid) )   CALL xios_set_field_attr     ( cdid, freq_op=freq_op, freq_offset=freq_offset )
+      IF( xios_is_valid_fieldgroup(cdid) )   CALL xios_set_fieldgroup_attr( cdid, freq_op=freq_op, freq_offset=freq_offset )
       CALL xios_solve_inheritance()
    END SUBROUTINE iom_set_field_attr
@@ -1314,8 +1327,11 @@
 
    SUBROUTINE iom_set_file_attr( cdid, name, name_suffix )
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
       CHARACTER(LEN=*)          , INTENT(in) ::   cdid
       CHARACTER(LEN=*),OPTIONAL , INTENT(in) ::   name, name_suffix
-      IF ( xios_is_valid_file     (cdid) )   CALL xios_set_file_attr     ( cdid, name=name, name_suffix=name_suffix )
-      IF ( xios_is_valid_filegroup(cdid) )   CALL xios_set_filegroup_attr( cdid, name=name, name_suffix=name_suffix )
+      !!----------------------------------------------------------------------
+      IF( xios_is_valid_file     (cdid) )   CALL xios_set_file_attr     ( cdid, name=name, name_suffix=name_suffix )
+      IF( xios_is_valid_filegroup(cdid) )   CALL xios_set_filegroup_attr( cdid, name=name, name_suffix=name_suffix )
       CALL xios_solve_inheritance()
    END SUBROUTINE iom_set_file_attr
@@ -1323,4 +1339,6 @@
 
    SUBROUTINE iom_get_file_attr( cdid, name, name_suffix, output_freq )
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
       CHARACTER(LEN=*)          , INTENT(in ) ::   cdid
       CHARACTER(LEN=*),OPTIONAL , INTENT(out) ::   name, name_suffix
@@ -1331,5 +1349,5 @@
       IF( PRESENT( name_suffix ) )   name_suffix = ''
       IF( PRESENT( output_freq ) )   output_freq = xios_duration(0,0,0,0,0,0)
-      IF ( xios_is_valid_file     (cdid) ) THEN
+      IF( xios_is_valid_file     (cdid) ) THEN
          CALL xios_solve_inheritance()
          CALL xios_is_defined_file_attr     ( cdid, name = llexist1, name_suffix = llexist2, output_freq = llexist3)
@@ -1338,5 +1356,5 @@
          IF(llexist3)   CALL xios_get_file_attr     ( cdid, output_freq = output_freq )
       ENDIF
-      IF ( xios_is_valid_filegroup(cdid) ) THEN
+      IF( xios_is_valid_filegroup(cdid) ) THEN
          CALL xios_solve_inheritance()
          CALL xios_is_defined_filegroup_attr( cdid, name = llexist1, name_suffix = llexist2, output_freq = llexist3)
@@ -1349,24 +1367,30 @@
 
    SUBROUTINE iom_set_grid_attr( cdid, mask )
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
       CHARACTER(LEN=*)                   , INTENT(in) ::   cdid
       LOGICAL, DIMENSION(:,:,:), OPTIONAL, INTENT(in) ::   mask
-      IF ( xios_is_valid_grid     (cdid) )   CALL xios_set_grid_attr     ( cdid, mask_3D=mask )
-      IF ( xios_is_valid_gridgroup(cdid) )   CALL xios_set_gridgroup_attr( cdid, mask_3D=mask )
+      !!----------------------------------------------------------------------
+      IF( xios_is_valid_grid     (cdid) )   CALL xios_set_grid_attr     ( cdid, mask_3D=mask )
+      IF( xios_is_valid_gridgroup(cdid) )   CALL xios_set_gridgroup_attr( cdid, mask_3D=mask )
       CALL xios_solve_inheritance()
    END SUBROUTINE iom_set_grid_attr
 
    SUBROUTINE iom_setkt( kt, cdname )
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
       INTEGER         , INTENT(in) ::   kt 
       CHARACTER(LEN=*), INTENT(in) ::   cdname
-      !     
+      !!----------------------------------------------------------------------
       CALL iom_swap( cdname )   ! swap to cdname context
       CALL xios_update_calendar(kt)
-      IF( cdname /= TRIM(cxios_context) ) CALL iom_swap( TRIM(cxios_context) )   ! return back to nemo context
-      !
+      IF( cdname /= TRIM(cxios_context) )   CALL iom_swap( TRIM(cxios_context) )   ! return back to nemo context
    END SUBROUTINE iom_setkt
 
    SUBROUTINE iom_context_finalize( cdname )
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
       CHARACTER(LEN=*), INTENT(in) :: cdname
-      !
+      !!----------------------------------------------------------------------
       IF( xios_is_valid_context(cdname) ) THEN
          CALL iom_swap( cdname )   ! swap to cdname context
@@ -1374,5 +1398,4 @@
          IF( cdname /= TRIM(cxios_context) ) CALL iom_swap( TRIM(cxios_context) )   ! return back to nemo context
       ENDIF
-      !
    END SUBROUTINE iom_context_finalize
 
@@ -1383,5 +1406,4 @@
       !!
       !! ** Purpose :   define horizontal grids
-      !!
       !!----------------------------------------------------------------------
       CHARACTER(LEN=1)            , INTENT(in) ::   cdgrd
@@ -1389,14 +1411,16 @@
       REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plat
       !
+      INTEGER  :: ni, nj
       REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zmask
-      INTEGER  :: ni,nj
-      
-      ni=nlei-nldi+1 ; nj=nlej-nldj+1
-
+      !!----------------------------------------------------------------------
+      !
+      ni = nlei-nldi+1
+      nj = nlej-nldj+1
+      !
       CALL iom_set_domain_attr("grid_"//cdgrd, ni_glo=jpiglo, nj_glo=jpjglo, ibegin=nimpp+nldi-2, jbegin=njmpp+nldj-2, ni=ni, nj=nj)
       CALL iom_set_domain_attr("grid_"//cdgrd, data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj)
       CALL iom_set_domain_attr("grid_"//cdgrd, lonvalue = RESHAPE(plon(nldi:nlei, nldj:nlej),(/ ni*nj /)),   &
          &                                     latvalue = RESHAPE(plat(nldi:nlei, nldj:nlej),(/ ni*nj /)))  
-
+      !
       IF ( ln_mskland ) THEN
          ! mask land points, keep values on coast line -> specific mask for U, V and W points
@@ -1411,5 +1435,5 @@
          CALL iom_set_grid_attr  ( "grid_"//cdgrd//"_3D", mask = RESHAPE(zmask(nldi:nlei,nldj:nlej,:),(/ni,nj,jpk/)) /= 0. )
       ENDIF
-      
+      !
    END SUBROUTINE set_grid
 
@@ -1422,34 +1446,31 @@
       !!
       !!----------------------------------------------------------------------
-      CHARACTER(LEN=1) , INTENT(in) :: cdgrd
-      !
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in)           :: plon_cnr, plat_cnr  ! Lat/lon coordinates of a contiguous vertex of cell (i,j)
-      REAL(wp), DIMENSION(jpi,jpj), OPTIONAL, INTENT(in) :: plon_pnt, plat_pnt  ! Lat/lon coordinates of the point of cell (i,j)
-      !
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:)   :: z_bnds      ! Lat/lon coordinates of the vertices of cell (i,j)
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:)       :: z_fld       ! Working array to determine where to rotate cells
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:)       :: z_rot       ! Lat/lon working array for rotation of cells
-      !
-      INTEGER :: icnr, jcnr                                      ! Offset such that the vertex coordinate (i+icnr,j+jcnr)
-      !                                                          ! represents the bottom-left corner of cell (i,j)
+      CHARACTER(LEN=1)                      , INTENT(in) :: cdgrd
+      REAL(wp), DIMENSION(jpi,jpj)          , INTENT(in) :: plon_cnr, plat_cnr  ! Lat/lon coord. of a contiguous vertex of cell (i,j)
+      REAL(wp), DIMENSION(jpi,jpj), OPTIONAL, INTENT(in) :: plon_pnt, plat_pnt  ! Lat/lon coord. of the point of cell (i,j)
+      !
       INTEGER :: ji, jj, jn, ni, nj
-
+      INTEGER :: icnr, jcnr                                    ! Offset such that the vertex coordinate (i+icnr,j+jcnr)
+      !                                                        ! represents the bottom-left corner of cell (i,j)
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) :: z_bnds      ! Lat/lon coordinates of the vertices of cell (i,j)
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:)     :: z_fld       ! Working array to determine where to rotate cells
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:)     :: z_rot       ! Lat/lon working array for rotation of cells
+      !!----------------------------------------------------------------------
+      !
       ALLOCATE( z_bnds(4,jpi,jpj,2), z_fld(jpi,jpj), z_rot(4,2)  )
-
+      !
       ! Offset of coordinate representing bottom-left corner
       SELECT CASE ( TRIM(cdgrd) )
-         CASE ('T', 'W')
-            icnr = -1 ; jcnr = -1
-         CASE ('U')
-            icnr =  0 ; jcnr = -1
-         CASE ('V')
-            icnr = -1 ; jcnr =  0
+      CASE ('T', 'W')   ;   icnr = -1   ;   jcnr = -1
+      CASE ('U')        ;   icnr =  0   ;   jcnr = -1
+      CASE ('V')        ;   icnr = -1   ;   jcnr =  0
       END SELECT
-
-      ni = nlei-nldi+1 ; nj = nlej-nldj+1  ! Dimensions of subdomain interior
-
+      !
+      ni = nlei-nldi+1   ! Dimensions of subdomain interior
+      nj = nlej-nldj+1
+      !
       z_fld(:,:) = 1._wp
       CALL lbc_lnk( z_fld, cdgrd, -1. )    ! Working array for location of northfold
-
+      !
       ! Cell vertices that can be defined
       DO jj = 2, jpjm1
@@ -1465,5 +1486,5 @@
          END DO
       END DO
-
+      !
       ! Cell vertices on boundries
       DO jn = 1, 4
@@ -1471,5 +1492,5 @@
          CALL lbc_lnk( z_bnds(jn,:,:,2), cdgrd, 1., pval=999._wp )
       END DO
-
+      !
       ! Zero-size cells at closed boundaries if cell points provided,
       ! otherwise they are closed cells with unrealistic bounds
@@ -1496,7 +1517,6 @@
          ENDIF
       ENDIF
-
-      ! Rotate cells at the north fold
-      IF( (nbondj == 1 .OR. nbondj == 2) .AND. jperio >= 3 ) THEN
+      !
+      IF( (nbondj == 1 .OR. nbondj == 2) .AND. jperio >= 3 ) THEN    ! Rotate cells at the north fold
          DO jj = 1, jpj
             DO ji = 1, jpi
@@ -1508,7 +1528,5 @@
             END DO
          END DO
-
-      ! Invert cells at the symmetric equator
-      ELSE IF( nbondj == 2 .AND. jperio == 2 ) THEN
+      ELSE IF( nbondj == 2 .AND. jperio == 2 ) THEN                  ! Invert cells at the symmetric equator
          DO ji = 1, jpi
             z_rot(1:2,:) = z_bnds(3:4,ji,1,:)
@@ -1517,10 +1535,10 @@
          END DO
       ENDIF
-
+      !
       CALL iom_set_domain_attr("grid_"//cdgrd, bounds_lat = RESHAPE(z_bnds(:,nldi:nlei,nldj:nlej,1),(/ 4,ni*nj /)),           &
-                                               bounds_lon = RESHAPE(z_bnds(:,nldi:nlei,nldj:nlej,2),(/ 4,ni*nj /)), nvertex=4 )
-
+          &                                    bounds_lon = RESHAPE(z_bnds(:,nldi:nlei,nldj:nlej,2),(/ 4,ni*nj /)), nvertex=4 )
+      !
       DEALLOCATE( z_bnds, z_fld, z_rot ) 
-
+      !
    END SUBROUTINE set_grid_bounds
 
@@ -1535,12 +1553,14 @@
       REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   plat
       !
+      INTEGER  :: ni, nj, ix, iy
       REAL(wp), DIMENSION(:), ALLOCATABLE  ::   zlon
-      INTEGER  :: ni,nj, ix, iy
-
-      
-      ni=nlei-nldi+1 ; nj=nlej-nldj+1            ! define zonal mean domain (jpj*jpk)
-      ALLOCATE( zlon(ni*nj) )       ;       zlon(:) = 0.
-
+      !!----------------------------------------------------------------------
+      !
+      ni=nlei-nldi+1       ! define zonal mean domain (jpj*jpk)
+      nj=nlej-nldj+1
+      ALLOCATE( zlon(ni*nj) )       ;       zlon(:) = 0._wp
+      !
       CALL dom_ngb( -168.53, 65.03, ix, iy, 'T' ) !  i-line that passes through Bering Strait: Reference latitude (used in plots)
+!      CALL dom_ngb( 180., 90., ix, iy, 'T' ) !  i-line that passes near the North Pole : Reference latitude (used in plots)
       CALL iom_set_domain_attr("gznl", ni_glo=jpiglo, nj_glo=jpjglo, ibegin=nimpp+nldi-2, jbegin=njmpp+nldj-2, ni=ni, nj=nj)
       CALL iom_set_domain_attr("gznl", data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj)
@@ -1553,4 +1573,5 @@
    END SUBROUTINE set_grid_znl
 
+
    SUBROUTINE set_scalar
       !!----------------------------------------------------------------------
@@ -1562,11 +1583,11 @@
       REAL(wp), DIMENSION(1)   ::   zz = 1.
       !!----------------------------------------------------------------------
-
+      !
       CALL iom_set_domain_attr('scalarpoint', ni_glo=jpnij, nj_glo=1, ibegin=narea-1, jbegin=0, ni=1, nj=1)
       CALL iom_set_domain_attr('scalarpoint', data_dim=2, data_ibegin = 1, data_ni = 1, data_jbegin = 1, data_nj = 1)
-      
-      zz=REAL(narea,wp)
+      !
+      zz = REAL( narea, wp )
       CALL iom_set_domain_attr('scalarpoint', lonvalue=zz, latvalue=zz)
-
+      !
    END SUBROUTINE set_scalar
 
@@ -1596,11 +1617,11 @@
       ! 
       ! frequency of the call of iom_put (attribut: freq_op)
-      f_op%timestep = 1        ;  f_of%timestep = 0  ; CALL iom_set_field_attr('field_definition', freq_op=f_op, freq_offset=f_of)
-      f_op%timestep = 2        ;  f_of%timestep = 0  ; CALL iom_set_field_attr('trendT_even'     , freq_op=f_op, freq_offset=f_of)
-      f_op%timestep = 2        ;  f_of%timestep = -1 ; CALL iom_set_field_attr('trendT_odd'      , freq_op=f_op, freq_offset=f_of)
-      f_op%timestep = nn_fsbc  ;  f_of%timestep = 0  ; CALL iom_set_field_attr('SBC'             , freq_op=f_op, freq_offset=f_of)
-      f_op%timestep = nn_fsbc  ;  f_of%timestep = 0  ; CALL iom_set_field_attr('SBC_scalar'      , freq_op=f_op, freq_offset=f_of)
-      f_op%timestep = nn_dttrc ;  f_of%timestep = 0  ; CALL iom_set_field_attr('ptrc_T'          , freq_op=f_op, freq_offset=f_of)
-      f_op%timestep = nn_dttrc ;  f_of%timestep = 0  ; CALL iom_set_field_attr('diad_T'          , freq_op=f_op, freq_offset=f_of)
+      f_op%timestep = 1        ;  f_of%timestep =  0  ; CALL iom_set_field_attr('field_definition', freq_op=f_op, freq_offset=f_of)
+      f_op%timestep = 2        ;  f_of%timestep =  0  ; CALL iom_set_field_attr('trendT_even'     , freq_op=f_op, freq_offset=f_of)
+      f_op%timestep = 2        ;  f_of%timestep = -1  ; CALL iom_set_field_attr('trendT_odd'      , freq_op=f_op, freq_offset=f_of)
+      f_op%timestep = nn_fsbc  ;  f_of%timestep =  0  ; CALL iom_set_field_attr('SBC'             , freq_op=f_op, freq_offset=f_of)
+      f_op%timestep = nn_fsbc  ;  f_of%timestep =  0  ; CALL iom_set_field_attr('SBC_scalar'      , freq_op=f_op, freq_offset=f_of)
+      f_op%timestep = nn_dttrc ;  f_of%timestep =  0  ; CALL iom_set_field_attr('ptrc_T'          , freq_op=f_op, freq_offset=f_of)
+      f_op%timestep = nn_dttrc ;  f_of%timestep =  0  ; CALL iom_set_field_attr('diad_T'          , freq_op=f_op, freq_offset=f_of)
 
       ! output file names (attribut: name)
@@ -1641,10 +1662,9 @@
       zlatpira = (/ -19.0, -14.0,  -8.0, 0.0, 4.0, 8.0, 12.0, 15.0, 20.0 /)
       CALL set_mooring( zlonpira, zlatpira )
-
-      
+      !
    END SUBROUTINE set_xmlatt
 
 
-   SUBROUTINE set_mooring( plon, plat)
+   SUBROUTINE set_mooring( plon, plat )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE set_mooring  ***
@@ -1653,5 +1673,5 @@
       !!
       !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:), INTENT(in) ::  plon, plat           ! longitudes/latitudes oft the mooring
+      REAL(wp), DIMENSION(:), INTENT(in) ::   plon, plat   ! longitudes/latitudes oft the mooring
       !
 !!$      CHARACTER(len=1),DIMENSION(4) ::   clgrd = (/ 'T', 'U', 'V', 'W' /)   ! suffix name
@@ -1736,13 +1756,13 @@
       TYPE(xios_duration)   ::   output_freq 
       !!----------------------------------------------------------------------
-
-      DO jn = 1,2
-
+      !
+      DO jn = 1, 2
+         !
          output_freq = xios_duration(0,0,0,0,0,0)
          IF( jn == 1 )   CALL iom_get_file_attr( cdid, name        = clname, output_freq = output_freq )
          IF( jn == 2 )   CALL iom_get_file_attr( cdid, name_suffix = clname )
-
+         !
          IF ( TRIM(clname) /= '' ) THEN 
-
+            !
             idx = INDEX(clname,'@expname@') + INDEX(clname,'@EXPNAME@')
             DO WHILE ( idx /= 0 ) 
@@ -1750,5 +1770,5 @@
                idx = INDEX(clname,'@expname@') + INDEX(clname,'@EXPNAME@')
             END DO
-
+            !
             idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@')
             DO WHILE ( idx /= 0 ) 
@@ -1781,5 +1801,5 @@
               idx = INDEX(clname,'@freq@') + INDEX(clname,'@FREQ@')
             END DO
-
+            !
             idx = INDEX(clname,'@startdate@') + INDEX(clname,'@STARTDATE@')
             DO WHILE ( idx /= 0 ) 
@@ -1788,5 +1808,5 @@
                idx = INDEX(clname,'@startdate@') + INDEX(clname,'@STARTDATE@')
             END DO
-
+            !
             idx = INDEX(clname,'@startdatefull@') + INDEX(clname,'@STARTDATEFULL@')
             DO WHILE ( idx /= 0 ) 
@@ -1795,5 +1815,5 @@
                idx = INDEX(clname,'@startdatefull@') + INDEX(clname,'@STARTDATEFULL@')
             END DO
-
+            !
             idx = INDEX(clname,'@enddate@') + INDEX(clname,'@ENDDATE@')
             DO WHILE ( idx /= 0 ) 
@@ -1802,5 +1822,5 @@
                idx = INDEX(clname,'@enddate@') + INDEX(clname,'@ENDDATE@')
             END DO
-
+            !
             idx = INDEX(clname,'@enddatefull@') + INDEX(clname,'@ENDDATEFULL@')
             DO WHILE ( idx /= 0 ) 
@@ -1809,13 +1829,13 @@
                idx = INDEX(clname,'@enddatefull@') + INDEX(clname,'@ENDDATEFULL@')
             END DO
-
+            !
             IF( jn == 1 .AND. TRIM(Agrif_CFixed()) /= '0' )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname)
             IF( jn == 1 )   CALL iom_set_file_attr( cdid, name        = clname )
             IF( jn == 2 )   CALL iom_set_file_attr( cdid, name_suffix = clname )
-
-         ENDIF
-
+            !
+         ENDIF
+         !
       END DO
-
+      !
    END SUBROUTINE iom_update_file_name
 
@@ -1826,9 +1846,8 @@
       !!
       !! ** Purpose :   send back the date corresponding to the given julian day
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), INTENT(in   )           ::   pjday         ! julian day
-      LOGICAL , INTENT(in   ), OPTIONAL ::   ld24          ! true to force 24:00 instead of 00:00
-      LOGICAL , INTENT(in   ), OPTIONAL ::   ldfull        ! true to get the compleate date: yyyymmdd_hh:mm:ss
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in   )           ::   pjday    ! julian day
+      LOGICAL , INTENT(in   ), OPTIONAL ::   ld24     ! true to force 24:00 instead of 00:00
+      LOGICAL , INTENT(in   ), OPTIONAL ::   ldfull   ! true to get the compleate date: yyyymmdd_hh:mm:ss
       !
       CHARACTER(LEN=20) ::   iom_sdate
@@ -1837,27 +1856,28 @@
       REAL(wp)          ::   zsec
       LOGICAL           ::   ll24, llfull
+      !!----------------------------------------------------------------------
       !
       IF( PRESENT(ld24) ) THEN   ;   ll24 = ld24
       ELSE                       ;   ll24 = .FALSE.
       ENDIF
-
+      !
       IF( PRESENT(ldfull) ) THEN   ;   llfull = ldfull
       ELSE                         ;   llfull = .FALSE.
       ENDIF
-
+      !
       CALL ju2ymds( pjday, iyear, imonth, iday, zsec )
       isec = NINT(zsec)
-
+      !
       IF ( ll24 .AND. isec == 0 ) THEN   ! 00:00 of the next day -> move to 24:00 of the current day
          CALL ju2ymds( pjday - 1., iyear, imonth, iday, zsec )
          isec = 86400
       ENDIF
-
+      !
       IF( iyear < 10000 ) THEN   ;   clfmt = "i4.4,2i2.2"                ! format used to write the date 
       ELSE                       ;   WRITE(clfmt, "('i',i1,',2i2.2')") INT(LOG10(REAL(iyear,wp))) + 1
       ENDIF
-      
+      !
 !$AGRIF_DO_NOT_TREAT      
-! Should be fixed in the conv
+      ! needed in the conv
       IF( llfull ) THEN 
          clfmt = TRIM(clfmt)//",'_',i2.2,':',i2.2,':',i2.2"
@@ -1871,9 +1891,11 @@
       ENDIF
 !$AGRIF_END_DO_NOT_TREAT      
-
+      !
    END FUNCTION iom_sdate
 
 #else
-
+   !!----------------------------------------------------------------------
+   !!   NOT 'key_iomput'                               a few dummy routines
+   !!----------------------------------------------------------------------
 
    SUBROUTINE iom_setkt( kt, cdname )
@@ -1891,5 +1913,8 @@
 
    LOGICAL FUNCTION iom_use( cdname )
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
       CHARACTER(LEN=*), INTENT(in) ::   cdname
+      !!----------------------------------------------------------------------
 #if defined key_iomput
       iom_use = xios_field_is_active( cdname )
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/IOM/iom_def.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/IOM/iom_def.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/IOM/iom_def.F90	(revision 9019)
@@ -1,16 +1,11 @@
 MODULE iom_def
-   !!=====================================================================
+   !!======================================================================
    !!                    ***  MODULE  iom_def ***
    !! IOM variables definitions
-   !!====================================================================
-   !! History :  9.0  ! 06 09  (S. Masson) Original code
-   !!             "   ! 07 07  (D. Storkey) Add uldname
-   !!--------------------------------------------------------------------
-   !!---------------------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!---------------------------------------------------------------------------------
-
+   !!======================================================================
+   !! History :  9.0  ! 2006 09  (S. Masson) Original code
+   !!             -   ! 2007 07  (D. Storkey) Add uldname
+   !!            4.0  ! 2017-11 (M. Andrejczuk) Extend IOM interface to write any 3D fields
+   !!----------------------------------------------------------------------
    USE par_kind
 
@@ -64,8 +59,13 @@
       REAL(kind=wp), DIMENSION(jpmax_vars)      ::   scf      !: scale_factor of the variables
       REAL(kind=wp), DIMENSION(jpmax_vars)      ::   ofs      !: add_offset of the variables
+      INTEGER                                   ::   nlev     ! number of vertical levels
    END TYPE file_descriptor
    TYPE(file_descriptor), DIMENSION(jpmax_files), PUBLIC ::   iom_file !: array containing the info for all opened files
 !$AGRIF_END_DO_NOT_TREAT
 
-   !!=====================================================================
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id$
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!======================================================================
 END MODULE iom_def
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90	(revision 9019)
@@ -1,15 +1,15 @@
 MODULE iom_nf90
-   !!=====================================================================
+   !!======================================================================
    !!                    ***  MODULE  iom_nf90 ***
    !! Input/Output manager :  Library to read input files with NF90 (only fliocom module)
-   !!====================================================================
+   !!======================================================================
    !! History :  9.0  ! 05 12  (J. Belier) Original code
    !!            9.0  ! 06 02  (S. Masson) Adaptation to NEMO
    !!             "   ! 07 07  (D. Storkey) Changes to iom_nf90_gettime
    !!            3.6  ! 2015-15  (J. Harle) Added procedure to read REAL attributes
-   !!--------------------------------------------------------------------
-   !!gm  caution add !DIR nec: improved performance to be checked as well as no result changes
-
-   !!--------------------------------------------------------------------
+   !!            4.0  ! 2017-11 (M. Andrejczuk) Extend IOM interface to write any 3D fields
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
    !!   iom_open       : open a file read only
    !!   iom_close      : close a file or all files opened by iom
@@ -18,5 +18,5 @@
    !!   iom_varid      : get the id of a variable in a file
    !!   iom_rstput     : write a field in a restart file (interfaced to several routines)
-   !!--------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    USE dom_oce         ! ocean space and time domain
    USE lbclnk          ! lateal boundary condition / mpp exchanges
@@ -29,5 +29,5 @@
    PRIVATE
 
-   PUBLIC iom_nf90_open, iom_nf90_close, iom_nf90_varid, iom_nf90_get, iom_nf90_gettime, iom_nf90_rstput
+   PUBLIC iom_nf90_open  , iom_nf90_close, iom_nf90_varid, iom_nf90_get, iom_nf90_gettime, iom_nf90_rstput
    PUBLIC iom_nf90_getatt, iom_nf90_putatt
 
@@ -46,12 +46,11 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
-   SUBROUTINE iom_nf90_open( cdname, kiomid, ldwrt, ldok, kdompar )
+   SUBROUTINE iom_nf90_open( cdname, kiomid, ldwrt, ldok, kdompar, kdlev )
       !!---------------------------------------------------------------------
       !!                   ***  SUBROUTINE  iom_open  ***
@@ -64,4 +63,5 @@
       LOGICAL                , INTENT(in   )           ::   ldok        ! check the existence 
       INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar     ! domain parameters: 
+      INTEGER                , INTENT(in   ), OPTIONAL ::   kdlev       ! size of the third dimension
 
       CHARACTER(LEN=256) ::   clinfo           ! info character
@@ -76,8 +76,15 @@
       INTEGER            ::   ihdf5            ! local variable for retrieval of value for NF90_HDF5
       LOGICAL            ::   llclobber        ! local definition of ln_clobber
-      !---------------------------------------------------------------------
-
+      INTEGER            ::   ilevels           ! vertical levels
+      !---------------------------------------------------------------------
+      !
       clinfo = '                    iom_nf90_open ~~~  '
-      istop = nstop   ! store the actual value of nstop
+      istop = nstop     ! store the actual value of nstop
+      !
+      !                 !number of vertical levels
+      IF( PRESENT(kdlev) ) THEN   ;   ilevels = kdlev    ! use input value (useful for sea-ice)
+      ELSE                        ;   ilevels = jpk      ! by default jpk
+      ENDIF
+      !
       IF( nn_chunksz > 0 ) THEN   ;   ichunk = nn_chunksz
       ELSE                        ;   ichunk = NF90_SIZEHINT_DEFAULT
@@ -85,6 +92,6 @@
       !
       llclobber = ldwrt .AND. ln_clobber
-      IF( ldok .AND. .NOT. llclobber ) THEN      ! Open existing file...
-         !                 ! =============
+      IF( ldok .AND. .NOT. llclobber ) THEN      !==  Open existing file ==!
+         !                                       !=========================!
          IF( ldwrt ) THEN  ! ... in write mode
             IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in WRITE mode'
@@ -99,8 +106,8 @@
             CALL iom_nf90_check(NF90_OPEN( TRIM(cdname), NF90_NOWRITE, if90id, chunksize = ichunk ), clinfo)
          ENDIF
-      ELSE                                       ! the file does not exist (or we overwrite it)
-         !                 ! =============
+      ELSE                                       !== the file doesn't exist ==!   (or we overwrite it)
+         !                                       !============================!
          iln = INDEX( cdname, '.nc' )
-         IF( ldwrt ) THEN  ! the file should be open in write mode so we create it...
+         IF( ldwrt ) THEN              !* the file should be open in write mode so we create it...
             IF( jpnij > 1 ) THEN
                WRITE(cltmp,'(a,a,i4.4,a)') cdname(1:iln-1), '_', narea-1, '.nc'
@@ -126,5 +133,5 @@
             CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'x', kdompar(1,1)  , idmy ), clinfo)
             CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'y', kdompar(2,1)  , idmy ), clinfo)
-            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'z', jpk           , idmy ), clinfo)
+            CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'z', ilevels       , idmy ), clinfo)
             CALL iom_nf90_check(NF90_DEF_DIM( if90id, 't', NF90_UNLIMITED, idmy ), clinfo)
             ! global attributes
@@ -139,8 +146,9 @@
             CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_halo_size_end'  , kdompar(:,5)       ), clinfo)
             CALL iom_nf90_check(NF90_PUT_ATT( if90id, NF90_GLOBAL, 'DOMAIN_type'           , 'BOX'              ), clinfo)
-         ELSE              ! the file should be open for read mode so it must exist...
+         ELSE                          !* the file should be open for read mode so it must exist...
             CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' )
          ENDIF
       ENDIF
+      !
       ! start to fill file informations
       ! =============
@@ -156,9 +164,10 @@
          iom_file(kiomid)%nvars  = 0
          iom_file(kiomid)%irec   = -1   ! useless for NetCDF files, used to know if the file is in define mode 
+         iom_file(kiomid)%nlev   = ilevels
          CALL iom_nf90_check(NF90_Inquire(if90id, unlimitedDimId = iom_file(kiomid)%iduld), clinfo)
-         IF ( iom_file(kiomid)%iduld .GE. 0 ) THEN
-           CALL iom_nf90_check(NF90_Inquire_Dimension(if90id, iom_file(kiomid)%iduld,     & 
-        &                                               name = iom_file(kiomid)%uldname,  &
-        &                                               len  = iom_file(kiomid)%lenuld ), clinfo )
+         IF( iom_file(kiomid)%iduld .GE. 0 ) THEN
+            CALL iom_nf90_check(NF90_Inquire_Dimension(if90id, iom_file(kiomid)%iduld,    & 
+               &                                       name = iom_file(kiomid)%uldname,   &
+               &                                       len  = iom_file(kiomid)%lenuld ), clinfo )
          ENDIF
          IF(lwp) WRITE(numout,*) '                   ---> '//TRIM(cdname)//' OK'
@@ -179,8 +188,6 @@
       CHARACTER(LEN=100)  ::   clinfo   ! info character
       !---------------------------------------------------------------------
-      !
       clinfo = '      iom_nf90_close    , file: '//TRIM(iom_file(kiomid)%name)
       CALL iom_nf90_check(NF90_CLOSE(iom_file(kiomid)%nfid), clinfo)
-      !    
    END SUBROUTINE iom_nf90_close
 
@@ -275,5 +282,4 @@
       clinfo = 'iom_nf90_g0d , file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(iom_file(kiomid)%cn_var(kvid))
       CALL iom_nf90_check(NF90_GET_VAR(iom_file(kiomid)%nfid, iom_file(kiomid)%nvid(kvid), pvar, start = kstart), clinfo )
-      ! 
    END SUBROUTINE iom_nf90_g0d
 
@@ -357,5 +363,5 @@
          ivarid = NF90_GLOBAL
       ENDIF
-!
+      !
       IF( llok) THEN
          clinfo = 'iom_nf90_getatt, file: '//TRIM(iom_file(kiomid)%name)//', giatt: '//TRIM(cdatt)
@@ -368,5 +374,6 @@
    END SUBROUTINE iom_nf90_giatt
 
-   SUBROUTINE iom_nf90_gratt( kiomid, cdatt, pv_r0d, cdvar)
+
+   SUBROUTINE iom_nf90_gratt( kiomid, cdatt, pv_r0d, cdvar )
       !!-----------------------------------------------------------------------
       !!                  ***  ROUTINE  iom_nf90_gratt  ***
@@ -376,14 +383,13 @@
       !!               attribute if optional variable name is supplied (cdvar))
       !!-----------------------------------------------------------------------
-      INTEGER         , INTENT(in   ) ::   kiomid   ! Identifier of the file
-      CHARACTER(len=*), INTENT(in   ) ::   cdatt    ! attribute name
-      REAL(wp)        , INTENT(  out) ::   pv_r0d   ! read field
-      CHARACTER(len=*), INTENT(in   ), OPTIONAL     &
-                      &               ::   cdvar    ! name of the variable
-      !
-      INTEGER                         ::   if90id   ! temporary integer
-      INTEGER                         ::   ivarid   ! NetCDF variable Id
-      LOGICAL                         ::   llok     ! temporary logical
-      CHARACTER(LEN=100)              ::   clinfo   ! info character
+      INTEGER                   , INTENT(in   ) ::   kiomid   ! Identifier of the file
+      CHARACTER(len=*)          , INTENT(in   ) ::   cdatt    ! attribute name
+      REAL(wp)                  , INTENT(  out) ::   pv_r0d   ! read field
+      CHARACTER(len=*), OPTIONAL, INTENT(in   ) ::   cdvar    ! name of the variable
+      !
+      INTEGER            ::   if90id   ! temporary integer
+      INTEGER            ::   ivarid   ! NetCDF variable Id
+      LOGICAL            ::   llok     ! temporary logical
+      CHARACTER(LEN=100) ::   clinfo   ! info character
       !---------------------------------------------------------------------
       !
@@ -402,5 +408,5 @@
          ivarid = NF90_GLOBAL
       ENDIF
-!
+      !
       IF( llok) THEN
          clinfo = 'iom_nf90_getatt, file: '//TRIM(iom_file(kiomid)%name)//', gratt: '//TRIM(cdatt)
@@ -413,5 +419,6 @@
    END SUBROUTINE iom_nf90_gratt
 
-   SUBROUTINE iom_nf90_gcatt( kiomid, cdatt, pv_c0d, cdvar)
+
+   SUBROUTINE iom_nf90_gcatt( kiomid, cdatt, pv_c0d, cdvar )
       !!-----------------------------------------------------------------------
       !!                  ***  ROUTINE  iom_nf90_gcatt  ***
@@ -421,14 +428,13 @@
       !!               attribute if optional variable name is supplied (cdvar))
       !!-----------------------------------------------------------------------
-      INTEGER         , INTENT(in   ) ::   kiomid   ! Identifier of the file
-      CHARACTER(len=*), INTENT(in   ) ::   cdatt    ! attribute name
-      CHARACTER(len=*), INTENT(  out) ::   pv_c0d   ! read field
-      CHARACTER(len=*), INTENT(in   ), OPTIONAL     &
-                      &               ::   cdvar    ! name of the variable
-      !
-      INTEGER                         ::   if90id   ! temporary integer
-      INTEGER                         ::   ivarid   ! NetCDF variable Id
-      LOGICAL                         ::   llok     ! temporary logical
-      CHARACTER(LEN=100)              ::   clinfo   ! info character
+      INTEGER                   , INTENT(in   ) ::   kiomid   ! Identifier of the file
+      CHARACTER(len=*)          , INTENT(in   ) ::   cdatt    ! attribute name
+      CHARACTER(len=*)          , INTENT(  out) ::   pv_c0d   ! read field
+      CHARACTER(len=*), OPTIONAL, INTENT(in   ) ::   cdvar    ! name of the variable
+      !
+      INTEGER            ::   if90id   ! temporary integer
+      INTEGER            ::   ivarid   ! NetCDF variable Id
+      LOGICAL            ::   llok     ! temporary logical
+      CHARACTER(LEN=100) ::   clinfo   ! info character
       !---------------------------------------------------------------------
       !
@@ -458,4 +464,5 @@
    END SUBROUTINE iom_nf90_gcatt
 
+
    !!----------------------------------------------------------------------
    !!                   INTERFACE iom_nf90_putatt
@@ -495,5 +502,5 @@
          ivarid = NF90_GLOBAL
       ENDIF
-!
+      !
       IF( llok) THEN
          clinfo = 'iom_nf90_putatt, file: '//TRIM(iom_file(kiomid)%name)//', piatt: '//TRIM(cdatt)
@@ -517,5 +524,6 @@
    END SUBROUTINE iom_nf90_piatt
 
-   SUBROUTINE iom_nf90_pratt( kiomid, cdatt, pv_r0d, cdvar)
+
+   SUBROUTINE iom_nf90_pratt( kiomid, cdatt, pv_r0d, cdvar )
       !!-----------------------------------------------------------------------
       !!                  ***  ROUTINE  iom_nf90_pratt  ***
@@ -525,15 +533,14 @@
       !!               attribute if optional variable name is supplied (cdvar))
       !!-----------------------------------------------------------------------
-      INTEGER         , INTENT(in   ) ::   kiomid   ! Identifier of the file
-      CHARACTER(len=*), INTENT(in   ) ::   cdatt    ! attribute name
-      REAL(wp)        , INTENT(in   ) ::   pv_r0d   ! write field
-      CHARACTER(len=*), INTENT(in   ), OPTIONAL     &
-                      &               ::   cdvar    ! name of the variable
-      !
-      INTEGER                         ::   if90id   ! temporary integer
-      INTEGER                         ::   ivarid   ! NetCDF variable Id
-      LOGICAL                         ::   llok     ! temporary logical
-      LOGICAL                         ::   lenddef  ! temporary logical
-      CHARACTER(LEN=100)              ::   clinfo   ! info character
+      INTEGER                   , INTENT(in   ) ::   kiomid   ! Identifier of the file
+      CHARACTER(len=*)          , INTENT(in   ) ::   cdatt    ! attribute name
+      REAL(wp)                  , INTENT(in   ) ::   pv_r0d   ! write field
+      CHARACTER(len=*), OPTIONAL, INTENT(in   ) ::   cdvar    ! name of the variable
+      !
+      INTEGER            ::   if90id   ! temporary integer
+      INTEGER            ::   ivarid   ! NetCDF variable Id
+      LOGICAL            ::   llok     ! temporary logical
+      LOGICAL            ::   lenddef  ! temporary logical
+      CHARACTER(LEN=100) ::   clinfo   ! info character
       !---------------------------------------------------------------------
       !
@@ -550,5 +557,5 @@
          ivarid = NF90_GLOBAL
       ENDIF
-!
+      !
       IF( llok) THEN
          clinfo = 'iom_nf90_putatt, file: '//TRIM(iom_file(kiomid)%name)//', pratt: '//TRIM(cdatt)
@@ -572,5 +579,6 @@
    END SUBROUTINE iom_nf90_pratt
 
-   SUBROUTINE iom_nf90_pcatt( kiomid, cdatt, pv_c0d, cdvar)
+
+   SUBROUTINE iom_nf90_pcatt( kiomid, cdatt, pv_c0d, cdvar )
       !!-----------------------------------------------------------------------
       !!                  ***  ROUTINE  iom_nf90_pcatt  ***
@@ -580,15 +588,14 @@
       !!               attribute if optional variable name is supplied (cdvar))
       !!-----------------------------------------------------------------------
-      INTEGER         , INTENT(in   ) ::   kiomid   ! Identifier of the file
-      CHARACTER(len=*), INTENT(in   ) ::   cdatt    ! attribute name
-      CHARACTER(len=*), INTENT(in   ) ::   pv_c0d   ! write field
-      CHARACTER(len=*), INTENT(in   ), OPTIONAL     &
-                      &               ::   cdvar    ! name of the variable
-      !
-      INTEGER                         ::   if90id   ! temporary integer
-      INTEGER                         ::   ivarid   ! NetCDF variable Id
-      LOGICAL                         ::   llok     ! temporary logical
-      LOGICAL                         ::   lenddef  ! temporary logical
-      CHARACTER(LEN=100)              ::   clinfo   ! info character
+      INTEGER                   , INTENT(in   ) ::   kiomid   ! Identifier of the file
+      CHARACTER(len=*)          , INTENT(in   ) ::   cdatt    ! attribute name
+      CHARACTER(len=*)          , INTENT(in   ) ::   pv_c0d   ! write field
+      CHARACTER(len=*), OPTIONAL, INTENT(in   ) ::   cdvar    ! name of the variable
+      !
+      INTEGER            ::   if90id   ! temporary integer
+      INTEGER            ::   ivarid   ! NetCDF variable Id
+      LOGICAL            ::   llok     ! temporary logical
+      LOGICAL            ::   lenddef  ! temporary logical
+      CHARACTER(LEN=100) ::   clinfo   ! info character
       !---------------------------------------------------------------------
       !
@@ -605,5 +612,5 @@
          ivarid = NF90_GLOBAL
       ENDIF
-!
+      !
       IF( llok) THEN
          clinfo = 'iom_nf90_putatt, file: '//TRIM(iom_file(kiomid)%name)//', pcatt: '//TRIM(cdatt)
@@ -658,5 +665,5 @@
 
    SUBROUTINE iom_nf90_rp0123d( kt, kwrite, kiomid, cdvar , kvid  , ktype,   &
-         &                               pv_r0d, pv_r1d, pv_r2d, pv_r3d )
+         &                                  pv_r0d, pv_r1d, pv_r2d, pv_r3d )
       !!--------------------------------------------------------------------
       !!                   ***  SUBROUTINE  iom_nf90_rstput  ***
@@ -687,10 +694,10 @@
       INTEGER               :: itype                ! variable type
       INTEGER, DIMENSION(4) :: ichunksz             ! NetCDF4 chunk sizes. Will be computed using
-                                                    ! nn_nchunks_[i,j,k,t] namelist parameters
-      INTEGER               :: ichunkalg, ishuffle,&
-                               ideflate, ideflate_level
-                                                    ! NetCDF4 internally fixed parameters
+      !                                             ! nn_nchunks_[i,j,k,t] namelist parameters
+      INTEGER               :: ichunkalg, ishuffle, ideflate, ideflate_level
+      !                                             ! NetCDF4 internally fixed parameters
       LOGICAL               :: lchunk               ! logical switch to activate chunking and compression
-                                                    ! when appropriate (currently chunking is applied to 4d fields only)
+      !                                             ! when appropriate (currently chunking is applied to 4d fields only)
+      INTEGER               :: idlv                 ! local variable
       !---------------------------------------------------------------------
       !
@@ -706,5 +713,9 @@
          ENDIF
          ! define the dimension variables if it is not already done
-         cltmp = (/ 'nav_lon     ', 'nav_lat     ', 'nav_lev     ', 'time_counter' /)
+         IF(iom_file(kiomid)%nlev == jpk ) THEN
+          cltmp = (/ 'nav_lon     ', 'nav_lat     ', 'nav_lev     ', 'time_counter' /)
+         ELSE
+          cltmp = (/ 'nav_lon     ', 'nav_lat     ', 'numcat      ', 'time_counter' /)
+         ENDIF
          CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(1)), NF90_FLOAT , (/ 1, 2 /), iom_file(kiomid)%nvid(1) ), clinfo)
          CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cltmp(2)), NF90_FLOAT , (/ 1, 2 /), iom_file(kiomid)%nvid(2) ), clinfo)
@@ -755,11 +766,11 @@
          IF( PRESENT(pv_r0d) ) THEN
             CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cdvar), itype,                    &
-                 &                            iom_file(kiomid)%nvid(idvar) ), clinfo)
+               &                              iom_file(kiomid)%nvid(idvar) ), clinfo )
          ELSE
             CALL iom_nf90_check(NF90_DEF_VAR( if90id, TRIM(cdvar), itype, idimid(1:idims),   &
-                 &                            iom_file(kiomid)%nvid(idvar) ), clinfo)
+               &                              iom_file(kiomid)%nvid(idvar) ), clinfo )
          ENDIF
          lchunk = .false.
-         IF( snc4set%luse .AND. idims.eq.4 ) lchunk = .true.
+         IF( snc4set%luse .AND. idims == 4 )   lchunk = .true.
          ! update informations structure related the new variable we want to add...
          iom_file(kiomid)%nvars         = idvar
@@ -782,5 +793,5 @@
             ichunksz(3) = MIN( ichunksz(3),MAX( (ichunksz(3)-1)/snc4set%nk + 1 , 1 ) ) ! Suggested default nc4set%nk=6
             ichunksz(4) = 1                                                            ! Do not allow chunks to span the
-                                                                                       ! unlimited dimension
+            !                                                                          ! unlimited dimension
             CALL iom_nf90_check(SET_NF90_DEF_VAR_CHUNKING(if90id, idvar, ichunkalg, ichunksz), clinfo)
             CALL iom_nf90_check(SET_NF90_DEF_VAR_DEFLATE(if90id, idvar, ishuffle, ideflate, ideflate_level), clinfo)
@@ -791,5 +802,5 @@
          idvar = kvid
       ENDIF
-
+      !
       ! time step kwrite : write the variable
       IF( kt == kwrite ) THEN
@@ -815,18 +826,24 @@
             ! trick: is defined to 0 => dimension variable are defined but not yet written
             IF( iom_file(kiomid)%dimsz(1, 1) == 0 ) THEN
-               CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'nav_lon'     , idmy ), clinfo)
-               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, glamt(ix1:ix2, iy1:iy2) ), clinfo)
-               CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'nav_lat'     , idmy ), clinfo)
-               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, gphit(ix1:ix2, iy1:iy2) ), clinfo)
-               CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'nav_lev'     , idmy ), clinfo)
-               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, gdept_1d                ), clinfo)
+               CALL iom_nf90_check( NF90_INQ_VARID( if90id, 'nav_lon'     , idmy )         , clinfo )
+               CALL iom_nf90_check( NF90_PUT_VAR  ( if90id, idmy, glamt(ix1:ix2, iy1:iy2) ), clinfo )
+               CALL iom_nf90_check( NF90_INQ_VARID( if90id, 'nav_lat'     , idmy )         , clinfo )
+               CALL iom_nf90_check( NF90_PUT_VAR  ( if90id, idmy, gphit(ix1:ix2, iy1:iy2) ), clinfo )
+               IF(iom_file(kiomid)%nlev == jpk ) THEN 
+                  !NEMO
+                  CALL iom_nf90_check( NF90_INQ_VARID( if90id, 'nav_lev'     , idmy ), clinfo )
+                  CALL iom_nf90_check( NF90_PUT_VAR  ( if90id, idmy, gdept_1d       ), clinfo )
+               ELSE
+                  CALL iom_nf90_check( NF90_INQ_VARID( if90id, 'numcat'     , idmy ), clinfo)
+                  CALL iom_nf90_check( NF90_PUT_VAR  ( if90id, idmy, (/ (idlv, idlv = 1,iom_file(kiomid)%nlev) /)), clinfo )
+               ENDIF
                ! +++ WRONG VALUE: to be improved but not really useful...
-               CALL iom_nf90_check(NF90_INQ_VARID( if90id, 'time_counter', idmy ), clinfo)
-               CALL iom_nf90_check(NF90_PUT_VAR( if90id, idmy, kt                      ), clinfo)   
+               CALL iom_nf90_check( NF90_INQ_VARID( if90id, 'time_counter', idmy ), clinfo )
+               CALL iom_nf90_check( NF90_PUT_VAR( if90id, idmy, kt                      ), clinfo )   
                ! update the values of the variables dimensions size
-               CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 1, len = iom_file(kiomid)%dimsz(1,1) ), clinfo)
-               CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 2, len = iom_file(kiomid)%dimsz(2,1) ), clinfo)
+               CALL iom_nf90_check( NF90_INQUIRE_DIMENSION( if90id, 1, len = iom_file(kiomid)%dimsz(1,1) ), clinfo )
+               CALL iom_nf90_check( NF90_INQUIRE_DIMENSION( if90id, 2, len = iom_file(kiomid)%dimsz(2,1) ), clinfo )
                iom_file(kiomid)%dimsz(1:2, 2) = iom_file(kiomid)%dimsz(1:2, 1)
-               CALL iom_nf90_check(NF90_INQUIRE_DIMENSION( if90id, 3, len = iom_file(kiomid)%dimsz(1,3) ), clinfo)
+               CALL iom_nf90_check( NF90_INQUIRE_DIMENSION( if90id, 3, len = iom_file(kiomid)%dimsz(1,3) ), clinfo )
                iom_file(kiomid)%dimsz(1  , 4) = 1   ! unlimited dimension
                IF(lwp) WRITE(numout,*) TRIM(clinfo)//' write dimension variables done'
@@ -837,11 +854,11 @@
          ! =============
          IF(     PRESENT(pv_r0d) ) THEN
-            CALL iom_nf90_check(NF90_PUT_VAR( if90id, idvar, pv_r0d                      ), clinfo)
+            CALL iom_nf90_check( NF90_PUT_VAR( if90id, idvar, pv_r0d                    ), clinfo )
          ELSEIF( PRESENT(pv_r1d) ) THEN
-            CALL iom_nf90_check(NF90_PUT_VAR( if90id, idvar, pv_r1d(                  :) ), clinfo)
+            CALL iom_nf90_check( NF90_PUT_VAR( if90id, idvar, pv_r1d(:)                 ), clinfo )
          ELSEIF( PRESENT(pv_r2d) ) THEN
-            CALL iom_nf90_check(NF90_PUT_VAR( if90id, idvar, pv_r2d(ix1:ix2, iy1:iy2   ) ), clinfo)
+            CALL iom_nf90_check( NF90_PUT_VAR( if90id, idvar, pv_r2d(ix1:ix2,iy1:iy2)   ), clinfo )
          ELSEIF( PRESENT(pv_r3d) ) THEN
-            CALL iom_nf90_check(NF90_PUT_VAR( if90id, idvar, pv_r3d(ix1:ix2, iy1:iy2, :) ), clinfo)
+            CALL iom_nf90_check( NF90_PUT_VAR( if90id, idvar, pv_r3d(ix1:ix2,iy1:iy2,:) ), clinfo )
          ENDIF
          ! add 1 to the size of the temporal dimension (not really useful...)
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/IOM/prtctl.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/IOM/prtctl.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/IOM/prtctl.F90	(revision 9019)
@@ -441,14 +441,14 @@
 
 #if defined key_nemocice_decomp
-      ijpi = ( nx_global+2-2*jpreci + (isplt-1) ) / isplt + 2*jpreci
-      ijpj = ( ny_global+2-2*jprecj + (jsplt-1) ) / jsplt + 2*jprecj 
+      ijpi = ( nx_global+2-2*nn_hls + (isplt-1) ) / isplt + 2*nn_hls
+      ijpj = ( ny_global+2-2*nn_hls + (jsplt-1) ) / jsplt + 2*nn_hls 
 #else
-      ijpi = ( jpiglo-2*jpreci + (isplt-1) ) / isplt + 2*jpreci
-      ijpj = ( jpjglo-2*jprecj + (jsplt-1) ) / jsplt + 2*jprecj
+      ijpi = ( jpiglo-2*nn_hls + (isplt-1) ) / isplt + 2*nn_hls
+      ijpj = ( jpjglo-2*nn_hls + (jsplt-1) ) / jsplt + 2*nn_hls
 #endif
 
 
-      nrecil  = 2 * jpreci
-      nrecjl  = 2 * jprecj
+      nrecil  = 2 * nn_hls
+      nrecjl  = 2 * nn_hls
       irestil = MOD( jpiglo - nrecil , isplt )
       irestjl = MOD( jpjglo - nrecjl , jsplt )
@@ -563,10 +563,10 @@
          ibonitl(jn) = nbondil
          
-         nldil =  1   + jpreci
-         nleil = nlcil - jpreci
+         nldil =  1   + nn_hls
+         nleil = nlcil - nn_hls
          IF( nbondil == -1 .OR. nbondil == 2 )   nldil = 1
          IF( nbondil ==  1 .OR. nbondil == 2 )   nleil = nlcil
-         nldjl =  1   + jprecj
-         nlejl = nlcjl - jprecj
+         nldjl =  1   + nn_hls
+         nlejl = nlcjl - nn_hls
          IF( nbondjl == -1 .OR. nbondjl == 2 )   nldjl = 1
          IF( nbondjl ==  1 .OR. nbondjl == 2 )   nlejl = nlcjl
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_lnk_generic.h90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_lnk_generic.h90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_lnk_generic.h90	(revision 9019)
@@ -0,0 +1,123 @@
+#if defined MULTI
+#   define NAT_IN(k)                cd_nat(k)   
+#   define SGN_IN(k)                psgn(k)
+#   define F_SIZE(ptab)             kfld
+#   define OPT_K(k)                 ,ipf
+#   if defined DIM_2d
+#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_2D)                , INTENT(inout) ::   ptab(f)
+#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt2d(i,j)
+#      define K_SIZE(ptab)             1
+#      define L_SIZE(ptab)             1
+#   endif
+#   if defined DIM_3d
+#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_3D),INTENT(inout)::ptab(f)
+#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt3d(i,j,k)
+#      define K_SIZE(ptab)             SIZE(ptab(1)%pt3d,3)
+#      define L_SIZE(ptab)             1
+#   endif
+#   if defined DIM_4d
+#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_4D),INTENT(inout)::ptab(f)
+#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt4d(i,j,k,l)
+#      define K_SIZE(ptab)             SIZE(ptab(1)%pt4d,3)
+#      define L_SIZE(ptab)             SIZE(ptab(1)%pt4d,4)
+#   endif
+#else
+#   define ARRAY_TYPE(i,j,k,l,f)    REAL(wp)                    , INTENT(inout) ::   ARRAY_IN(i,j,k,l,f)
+#   define NAT_IN(k)                cd_nat
+#   define SGN_IN(k)                psgn
+#   define F_SIZE(ptab)             1
+#   define OPT_K(k)                 
+#   if defined DIM_2d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j)
+#      define K_SIZE(ptab)          1
+#      define L_SIZE(ptab)          1
+#   endif
+#   if defined DIM_3d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k)
+#      define K_SIZE(ptab)          SIZE(ptab,3)
+#      define L_SIZE(ptab)          1
+#   endif
+#   if defined DIM_4d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k,l)
+#      define K_SIZE(ptab)          SIZE(ptab,3)
+#      define L_SIZE(ptab)          SIZE(ptab,4)
+#   endif
+#endif
+
+#if defined MULTI
+   SUBROUTINE ROUTINE_LNK( ptab, cd_nat, psgn, kfld, cd_mpp, pval )
+      INTEGER                     , INTENT(in   ) ::   kfld        ! number of pt3d arrays
+#else
+   SUBROUTINE ROUTINE_LNK( ptab, cd_nat, psgn      , cd_mpp, pval )
+#endif
+      ARRAY_TYPE(:,:,:,:,:)                                        ! array or pointer of arrays on which the boundary condition is applied
+      CHARACTER(len=1)            , INTENT(in   ) ::   NAT_IN(:)   ! nature of array grid-points
+      REAL(wp)                    , INTENT(in   ) ::   SGN_IN(:)   ! sign used across the north fold boundary
+      CHARACTER(len=3), OPTIONAL  , INTENT(in   ) ::   cd_mpp      ! fill the overlap area only
+      REAL(wp)        , OPTIONAL  , INTENT(in   ) ::   pval        ! background value (used at closed boundaries)
+      !
+      INTEGER  ::    ji,  jj,  jk,  jl, jh, jf   ! dummy loop indices
+      INTEGER  ::   ipi, ipj, ipk, ipl, ipf      ! dimension of the input array
+      REAL(wp) ::   zland
+      LOGICAL  ::   ll_Iperio, ll_Jperio, ll_nfd
+      !!----------------------------------------------------------------------
+      !
+      ipk = K_SIZE(ptab)   ! 3rd dimension
+      ipl = L_SIZE(ptab)   ! 4th    -
+      ipf = F_SIZE(ptab)   ! 5th    -      use in "multi" case (array of pointers)
+      !
+      ll_Iperio = nperio==1 .OR. nperio==4 .OR. nperio==6
+      ll_Jperio = jperio==7
+      ll_nfd    = nperio==3 .OR. nperio==4 .OR. nperio==5 .OR. nperio==6
+      !
+      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
+      ELSE                         ;   zland = 0._wp     ! zero by default
+      ENDIF
+
+      ! ------------------------------- !
+      !   standard boundary treatment   !    ! CAUTION: semi-column notation is often impossible
+      ! ------------------------------- !
+      !
+      IF( PRESENT( cd_mpp ) ) THEN     !==  halos filled with inner values  ==!
+         !
+         ! only fill the overlap area and extra allows 
+         ! this is in mpp case. In this module, just do nothing
+         !
+      ELSE                             !==  standard close or cyclic treatment  ==!
+         !
+         DO jf = 1, ipf                   ! number of arrays to be treated
+            !
+            !                                ! East-West boundaries
+            IF( ll_Iperio ) THEN                   !* cyclic
+               ARRAY_IN( 1 ,:,:,:,jf) = ARRAY_IN(jpim1,:,:,:,jf)
+               ARRAY_IN(jpi,:,:,:,jf) = ARRAY_IN(  2  ,:,:,:,jf)
+            ELSE                                   !* closed
+               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN( 1 ,:,:,:,jf) = zland    ! east except F-point
+                                               ARRAY_IN(jpi,:,:,:,jf) = zland    ! west
+            ENDIF
+            !                                ! North-South boundaries
+            IF( ll_Jperio ) THEN                   !* cyclic
+               ARRAY_IN(:, 1 ,:,:,jf) = ARRAY_IN(:, jpjm1,:,:,jf)
+               ARRAY_IN(:,jpj,:,:,jf) = ARRAY_IN(:,   2  ,:,:,jf)
+            ELSEIF( ll_nfd ) THEN                  !* north fold
+               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(:, 1 ,:,:,jf) = zland    ! south except F-point
+               CALL lbc_nfd( ptab, NAT_IN(:), SGN_IN(:) OPT_K(:) )                       ! north fold treatment         
+            ELSE                                   !* closed
+               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(:, 1 ,:,:,jf) = zland    ! south except F-point
+                                               ARRAY_IN(:,jpj,:,:,jf) = zland    ! north
+            ENDIF
+            !
+         END DO
+         !
+      ENDIF
+      !
+   END SUBROUTINE ROUTINE_LNK
+
+#undef ARRAY_TYPE
+#undef NAT_IN
+#undef SGN_IN
+#undef ARRAY_IN
+#undef K_SIZE
+#undef L_SIZE
+#undef F_SIZE
+#undef OPT_K
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_lnk_multi_generic.h90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_lnk_multi_generic.h90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_lnk_multi_generic.h90	(revision 9019)
@@ -0,0 +1,74 @@
+#if defined DIM_2d
+#   define ARRAY_TYPE(i,j,k,l)   REAL(wp), DIMENSION(i,j)
+#   define PTR_TYPE              TYPE(PTR_2D)
+#   define PTR_ptab              pt2d
+#endif
+#if defined DIM_3d
+#   define ARRAY_TYPE(i,j,k,l)   REAL(wp), DIMENSION(i,j,k)
+#   define PTR_TYPE              TYPE(PTR_3D)
+#   define PTR_ptab              pt3d
+#endif
+#if defined DIM_4d
+#   define ARRAY_TYPE(i,j,k,l)   REAL(wp), DIMENSION(i,j,k,l)
+#   define PTR_TYPE              TYPE(PTR_4D)
+#   define PTR_ptab              pt4d
+#endif
+   SUBROUTINE ROUTINE_MULTI( pt1, cdna1, psgn1, pt2, cdna2, psgn2, pt3, cdna3, psgn3   &
+      &                    , pt4, cdna4, psgn4, pt5, cdna5, psgn5, pt6, cdna6, psgn6   &
+      &                    , pt7, cdna7, psgn7, pt8, cdna8, psgn8, pt9, cdna9, psgn9, cd_mpp, pval)
+      !!---------------------------------------------------------------------
+      ARRAY_TYPE(:,:,:,:)          , TARGET, INTENT(inout) ::   pt1     ! arrays on which the lbc is applied
+      ARRAY_TYPE(:,:,:,:), OPTIONAL, TARGET, INTENT(inout) ::   pt2  ,  pt3  , pt4  , pt5  , pt6  , pt7  , pt8  , pt9
+      CHARACTER(len=1)                     , INTENT(in   ) ::   cdna1   ! nature of pt2D. array grid-points
+      CHARACTER(len=1)   , OPTIONAL        , INTENT(in   ) ::   cdna2,  cdna3, cdna4, cdna5, cdna6, cdna7, cdna8, cdna9
+      REAL(wp)                             , INTENT(in   ) ::   psgn1   ! sign used across the north fold
+      REAL(wp)           , OPTIONAL        , INTENT(in   ) ::   psgn2,  psgn3, psgn4, psgn5, psgn6, psgn7, psgn8, psgn9   
+      CHARACTER(len=3)   , OPTIONAL        , INTENT(in   ) ::   cd_mpp  ! fill the overlap area only
+      REAL(wp)           , OPTIONAL        , INTENT(in   ) ::   pval    ! background value (used at closed boundaries)
+      !!
+      INTEGER                         ::   kfld        ! number of elements that will be attributed
+      PTR_TYPE         , DIMENSION(9) ::   ptab_ptr    ! pointer array
+      CHARACTER(len=1) , DIMENSION(9) ::   cdna_ptr    ! nature of ptab_ptr grid-points
+      REAL(wp)         , DIMENSION(9) ::   psgn_ptr    ! sign used across the north fold boundary
+      !!---------------------------------------------------------------------
+      !
+      kfld = 0          ! initial array of pointer size
+      !
+      !                 ! Load the first array
+      CALL ROUTINE_LOAD( pt1, cdna1, psgn1, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      !
+      !                 ! Look if more arrays are added
+      IF( PRESENT(psgn2) )   CALL ROUTINE_LOAD( pt2, cdna2, psgn2, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      IF( PRESENT(psgn3) )   CALL ROUTINE_LOAD( pt3, cdna3, psgn3, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      IF( PRESENT(psgn4) )   CALL ROUTINE_LOAD( pt4, cdna4, psgn4, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      IF( PRESENT(psgn5) )   CALL ROUTINE_LOAD( pt5, cdna5, psgn5, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      IF( PRESENT(psgn6) )   CALL ROUTINE_LOAD( pt6, cdna6, psgn6, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      IF( PRESENT(psgn7) )   CALL ROUTINE_LOAD( pt7, cdna7, psgn7, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      IF( PRESENT(psgn8) )   CALL ROUTINE_LOAD( pt8, cdna8, psgn8, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      IF( PRESENT(psgn9) )   CALL ROUTINE_LOAD( pt9, cdna9, psgn9, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      !
+      CALL lbc_lnk_ptr( ptab_ptr, cdna_ptr, psgn_ptr, kfld, cd_mpp, pval )
+      !
+   END SUBROUTINE ROUTINE_MULTI
+
+
+   SUBROUTINE ROUTINE_LOAD( ptab, cdna, psgn, ptab_ptr, cdna_ptr, psgn_ptr, kfld )
+      !!---------------------------------------------------------------------
+      ARRAY_TYPE(:,:,:,:)   , TARGET, INTENT(inout) ::   ptab       ! arrays on which the lbc is applied
+      CHARACTER(len=1)              , INTENT(in   ) ::   cdna       ! nature of pt2d array grid-points
+      REAL(wp)                      , INTENT(in   ) ::   psgn       ! sign used across the north fold boundary
+      PTR_TYPE        , DIMENSION(:), INTENT(inout) ::   ptab_ptr   ! array of pointers
+      CHARACTER(len=1), DIMENSION(:), INTENT(inout) ::   cdna_ptr   ! nature of pt2d_array array grid-points
+      REAL(wp)        , DIMENSION(:), INTENT(inout) ::   psgn_ptr   ! sign used across the north fold boundary
+      INTEGER                       , INTENT(inout) ::   kfld       ! number of elements that has been attributed
+      !!---------------------------------------------------------------------
+      !
+      kfld                    =  kfld + 1
+      ptab_ptr(kfld)%PTR_ptab => ptab
+      cdna_ptr(kfld)          =  cdna
+      psgn_ptr(kfld)          =  psgn
+      !
+   END SUBROUTINE ROUTINE_LOAD
+#undef ARRAY_TYPE
+#undef PTR_TYPE
+#undef PTR_ptab
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_nfd_ext_generic.h90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_nfd_ext_generic.h90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_nfd_ext_generic.h90	(revision 9019)
@@ -0,0 +1,154 @@
+!                          !==  IN: ptab is an array  ==!
+#define NAT_IN(k)                cd_nat
+#define SGN_IN(k)                psgn
+#define F_SIZE(ptab)             1
+#if defined DIM_2d
+#   define ARRAY_IN(i,j,k,l,f)   ptab(i,j)
+#   define K_SIZE(ptab)          1
+#   define L_SIZE(ptab)          1
+#endif
+#define ARRAY_TYPE(i,j,k,l,f)    REAL(wp),INTENT(inout)::ARRAY_IN(i,j,k,l,f)
+
+   SUBROUTINE ROUTINE_NFD( ptab, cd_nat, psgn, kextj )
+      ARRAY_TYPE(:,:,:,:,:)                             ! array or pointer of arrays on which the boundary condition is applied
+      CHARACTER(len=1) , INTENT(in   ) ::   NAT_IN(:)   ! nature of array grid-points
+      REAL(wp)         , INTENT(in   ) ::   SGN_IN(:)   ! sign used across the north fold boundary
+      INTEGER          , INTENT(in   ) ::   kextj       ! extra halo width at north fold
+      !
+      INTEGER  ::    ji,  jj,  jk,  jl, jh,  jf   ! dummy loop indices
+      INTEGER  ::   ipi, ipj, ipk, ipl,     ipf   ! dimension of the input array
+      INTEGER  ::   ijt, iju, ipjm1
+      !!----------------------------------------------------------------------
+      !
+      ipk = K_SIZE(ptab)   ! 3rd dimension
+      ipl = L_SIZE(ptab)   ! 4th    -
+      ipf = F_SIZE(ptab)   ! 5th    -      use in "multi" case (array of pointers)
+      !
+      !
+      SELECT CASE ( jpni )
+      CASE ( 1 )     ;   ipj = nlcj       ! 1 proc only  along the i-direction
+      CASE DEFAULT   ;   ipj = 4          ! several proc along the i-direction
+      END SELECT
+      !
+      ipjm1 = ipj-1
+
+      !
+      DO jf = 1, ipf                      ! Loop on the number of arrays to be treated
+         !
+         SELECT CASE ( npolj )
+         !
+         CASE ( 3 , 4 )                        ! *  North fold  T-point pivot
+            !
+            SELECT CASE ( NAT_IN(jf)  )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO jh = 0, kextj
+                  DO ji = 2, jpiglo
+                     ijt = jpiglo-ji+2
+                     ARRAY_IN(ji,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipj-2-jh,:,:,jf)
+                  END DO
+                  ARRAY_IN(1,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(3,ipj-2-jh,:,:,jf)
+               END DO
+               DO ji = jpiglo/2+1, jpiglo
+                  ijt = jpiglo-ji+2
+                  ARRAY_IN(ji,ipjm1,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipjm1,:,:,jf)
+               END DO
+            CASE ( 'U' )                               ! U-point
+               DO jh = 0, kextj
+                  DO ji = 1, jpiglo-1
+                     iju = jpiglo-ji+1
+                     ARRAY_IN(ji,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipj-2-jh,:,:,jf)
+                  END DO
+                 ARRAY_IN(   1  ,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(    2   ,ipj-2-jh,:,:,jf)
+                 ARRAY_IN(jpiglo,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(jpiglo-1,ipj-2-jh,:,:,jf) 
+               END DO
+               DO ji = jpiglo/2, jpiglo-1
+                  iju = jpiglo-ji+1
+                  ARRAY_IN(ji,ipjm1,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipjm1,:,:,jf)
+               END DO
+            CASE ( 'V' )                               ! V-point
+               DO jh = 0, kextj
+                  DO ji = 2, jpiglo
+                     ijt = jpiglo-ji+2
+                     ARRAY_IN(ji,ipj-1+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipj-2-jh,:,:,jf)
+                     ARRAY_IN(ji,ipj+jh  ,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipj-3-jh,:,:,jf)
+                  END DO
+                  ARRAY_IN(1,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(3,ipj-3-jh,:,:,jf) 
+               END DO
+            CASE ( 'F' )                               ! F-point
+               DO jh = 0, kextj
+                  DO ji = 1, jpiglo-1
+                     iju = jpiglo-ji+1
+                     ARRAY_IN(ji,ipj-1+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipj-2-jh,:,:,jf)
+                     ARRAY_IN(ji,ipj+jh  ,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipj-3-jh,:,:,jf)
+                  END DO
+                  ARRAY_IN(   1  ,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(    2   ,ipj-3-jh,:,:,jf)
+                  ARRAY_IN(jpiglo,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(jpiglo-1,ipj-3-jh,:,:,jf) 
+               END DO
+            END SELECT
+            !
+         CASE ( 5 , 6 )                        ! *  North fold  F-point pivot
+            !
+            SELECT CASE ( NAT_IN(jf)  )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO jh = 0, kextj
+                  DO ji = 1, jpiglo
+                     ijt = jpiglo-ji+1
+                     ARRAY_IN(ji,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipj-1-jh,:,:,jf)
+                  END DO
+               END DO
+            CASE ( 'U' )                               ! U-point
+               DO jh = 0, kextj
+                  DO ji = 1, jpiglo-1
+                     iju = jpiglo-ji
+                     ARRAY_IN(ji,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipj-1-jh,:,:,jf)
+                  END DO
+                  ARRAY_IN(jpiglo,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(1,ipj-1-jh,:,:,jf)
+               END DO
+            CASE ( 'V' )                               ! V-point
+               DO jh = 0, kextj
+                  DO ji = 1, jpiglo
+                     ijt = jpiglo-ji+1
+                     ARRAY_IN(ji,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipj-2-jh,:,:,jf)
+                  END DO
+               END DO
+               DO ji = jpiglo/2+1, jpiglo
+                  ijt = jpiglo-ji+1
+                  ARRAY_IN(ji,ipjm1,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipjm1,:,:,jf)
+               END DO
+            CASE ( 'F' )                               ! F-point
+               DO jh = 0, kextj
+                  DO ji = 1, jpiglo-1
+                     iju = jpiglo-ji
+                     ARRAY_IN(ji,ipj+jh  ,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipj-2-jh,:,:,jf)
+                  END DO
+                  ARRAY_IN(jpiglo,ipj+jh,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(1,ipj-2-jh,:,:,jf)
+               END DO
+               DO ji = jpiglo/2+1, jpiglo-1
+                  iju = jpiglo-ji
+                  ARRAY_IN(ji,ipjm1,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipjm1,:,:,jf)
+               END DO
+            END SELECT
+            !
+         CASE DEFAULT                           ! *  closed : the code probably never go through
+            !
+            SELECT CASE ( NAT_IN(jf) )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               ARRAY_IN(:,  1:1-kextj  ,:,:,jf) = 0._wp
+               ARRAY_IN(:,ipj:ipj+kextj,:,:,jf) = 0._wp
+            CASE ( 'F' )                               ! F-point
+               ARRAY_IN(:,ipj:ipj+kextj,:,:,jf) = 0._wp
+            END SELECT
+            !
+         END SELECT     !  npolj
+         !
+      END DO
+      !
+   END SUBROUTINE ROUTINE_NFD
+
+#undef ARRAY_TYPE
+#undef ARRAY_IN
+#undef NAT_IN
+#undef SGN_IN
+#undef K_SIZE
+#undef L_SIZE
+#undef F_SIZE
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_nfd_generic.h90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_nfd_generic.h90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_nfd_generic.h90	(revision 9019)
@@ -0,0 +1,175 @@
+#if defined MULTI
+#   define NAT_IN(k)                cd_nat(k)   
+#   define SGN_IN(k)                psgn(k)
+#   define F_SIZE(ptab)             kfld
+#   if defined DIM_2d
+#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_2D),INTENT(inout)::ptab(f)
+#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt2d(i,j)
+#      define K_SIZE(ptab)             1
+#      define L_SIZE(ptab)             1
+#   endif
+#   if defined DIM_3d
+#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_3D),INTENT(inout)::ptab(f)
+#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt3d(i,j,k)
+#      define K_SIZE(ptab)             SIZE(ptab(1)%pt3d,3)
+#      define L_SIZE(ptab)             1
+#   endif
+#   if defined DIM_4d
+#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_4D),INTENT(inout)::ptab(f)
+#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt4d(i,j,k,l)
+#      define K_SIZE(ptab)             SIZE(ptab(1)%pt4d,3)
+#      define L_SIZE(ptab)             SIZE(ptab(1)%pt4d,4)
+#   endif
+#else
+!                          !==  IN: ptab is an array  ==!
+#   define NAT_IN(k)                cd_nat
+#   define SGN_IN(k)                psgn
+#   define F_SIZE(ptab)             1
+#   if defined DIM_2d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j)
+#      define K_SIZE(ptab)          1
+#      define L_SIZE(ptab)          1
+#   endif
+#   if defined DIM_3d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k)
+#      define K_SIZE(ptab)          SIZE(ptab,3)
+#      define L_SIZE(ptab)          1
+#   endif
+#   if defined DIM_4d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k,l)
+#      define K_SIZE(ptab)          SIZE(ptab,3)
+#      define L_SIZE(ptab)          SIZE(ptab,4)
+#   endif
+#   define ARRAY_TYPE(i,j,k,l,f)    REAL(wp),INTENT(inout)::ARRAY_IN(i,j,k,l,f)
+#endif
+
+#if defined MULTI
+   SUBROUTINE ROUTINE_NFD( ptab, cd_nat, psgn, kfld )
+      INTEGER          , INTENT(in   ) ::   kfld        ! number of pt3d arrays
+#else
+   SUBROUTINE ROUTINE_NFD( ptab, cd_nat, psgn       )
+#endif
+      ARRAY_TYPE(:,:,:,:,:)                             ! array or pointer of arrays on which the boundary condition is applied
+      CHARACTER(len=1) , INTENT(in   ) ::   NAT_IN(:)   ! nature of array grid-points
+      REAL(wp)         , INTENT(in   ) ::   SGN_IN(:)   ! sign used across the north fold boundary
+      !
+      INTEGER  ::    ji,  jj,  jk,  jl, jh,  jf   ! dummy loop indices
+      INTEGER  ::   ipi, ipj, ipk, ipl,     ipf   ! dimension of the input array
+      INTEGER  ::   ijt, iju, ipjm1
+      !!----------------------------------------------------------------------
+      !
+      ipk = K_SIZE(ptab)   ! 3rd dimension
+      ipl = L_SIZE(ptab)   ! 4th    -
+      ipf = F_SIZE(ptab)   ! 5th    -      use in "multi" case (array of pointers)
+      !
+      !
+      SELECT CASE ( jpni )
+      CASE ( 1 )     ;   ipj = nlcj       ! 1 proc only  along the i-direction
+      CASE DEFAULT   ;   ipj = 4          ! several proc along the i-direction
+      END SELECT
+      ipjm1 = ipj-1
+
+      !
+      DO jf = 1, ipf                      ! Loop on the number of arrays to be treated
+         !
+         SELECT CASE ( npolj )
+         !
+         CASE ( 3 , 4 )                        ! *  North fold  T-point pivot
+            !
+            SELECT CASE ( NAT_IN(jf)  )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO ji = 2, jpiglo
+                  ijt = jpiglo-ji+2
+                  ARRAY_IN(ji,ipj,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipj-2,:,:,jf)
+               END DO
+               ARRAY_IN(1,ipj,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(3,ipj-2,:,:,jf)
+               DO ji = jpiglo/2+1, jpiglo
+                  ijt = jpiglo-ji+2
+                  ARRAY_IN(ji,ipjm1,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipjm1,:,:,jf)
+               END DO
+            CASE ( 'U' )                               ! U-point
+               DO ji = 1, jpiglo-1
+                  iju = jpiglo-ji+1
+                  ARRAY_IN(ji,ipj,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipj-2,:,:,jf)
+               END DO
+               ARRAY_IN(   1  ,ipj,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(    2   ,ipj-2,:,:,jf)
+               ARRAY_IN(jpiglo,ipj,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(jpiglo-1,ipj-2,:,:,jf) 
+               DO ji = jpiglo/2, jpiglo-1
+                  iju = jpiglo-ji+1
+                  ARRAY_IN(ji,ipjm1,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipjm1,:,:,jf)
+               END DO
+            CASE ( 'V' )                               ! V-point
+               DO ji = 2, jpiglo
+                  ijt = jpiglo-ji+2
+                  ARRAY_IN(ji,ipj-1,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipj-2,:,:,jf)
+                  ARRAY_IN(ji,ipj  ,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipj-3,:,:,jf)
+               END DO
+               ARRAY_IN(1,ipj,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(3,ipj-3,:,:,jf) 
+            CASE ( 'F' )                               ! F-point
+               DO ji = 1, jpiglo-1
+                  iju = jpiglo-ji+1
+                  ARRAY_IN(ji,ipj-1,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipj-2,:,:,jf)
+                  ARRAY_IN(ji,ipj  ,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipj-3,:,:,jf)
+               END DO
+               ARRAY_IN(   1  ,ipj,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(    2   ,ipj-3,:,:,jf)
+               ARRAY_IN(jpiglo,ipj,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(jpiglo-1,ipj-3,:,:,jf) 
+            END SELECT
+            !
+         CASE ( 5 , 6 )                        ! *  North fold  F-point pivot
+            !
+            SELECT CASE ( NAT_IN(jf)  )
+            CASE ( 'T' , 'W' )                         ! T-, W-point
+               DO ji = 1, jpiglo
+                  ijt = jpiglo-ji+1
+                  ARRAY_IN(ji,ipj,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipj-1,:,:,jf)
+               END DO
+            CASE ( 'U' )                               ! U-point
+               DO ji = 1, jpiglo-1
+                  iju = jpiglo-ji
+                  ARRAY_IN(ji,ipj,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipj-1,:,:,jf)
+               END DO
+               ARRAY_IN(jpiglo,ipj,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(1,ipj-1,:,:,jf)
+            CASE ( 'V' )                               ! V-point
+               DO ji = 1, jpiglo
+                  ijt = jpiglo-ji+1
+                  ARRAY_IN(ji,ipj,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipj-2,:,:,jf)
+               END DO
+               DO ji = jpiglo/2+1, jpiglo
+                  ijt = jpiglo-ji+1
+                  ARRAY_IN(ji,ipjm1,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(ijt,ipjm1,:,:,jf)
+               END DO
+            CASE ( 'F' )                               ! F-point
+               DO ji = 1, jpiglo-1
+                  iju = jpiglo-ji
+                  ARRAY_IN(ji,ipj  ,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipj-2,:,:,jf)
+               END DO
+               ARRAY_IN(jpiglo,ipj,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(1,ipj-2,:,:,jf)
+               DO ji = jpiglo/2+1, jpiglo-1
+                  iju = jpiglo-ji
+                  ARRAY_IN(ji,ipjm1,:,:,jf) = SGN_IN(jf)  * ARRAY_IN(iju,ipjm1,:,:,jf)
+               END DO
+            END SELECT
+            !
+         CASE DEFAULT                           ! *  closed : the code probably never go through
+            !
+            SELECT CASE ( NAT_IN(jf) )
+            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
+               ARRAY_IN(:, 1 ,:,:,jf) = 0._wp
+               ARRAY_IN(:,ipj,:,:,jf) = 0._wp
+            CASE ( 'F' )                               ! F-point
+               ARRAY_IN(:,ipj,:,:,jf) = 0._wp
+            END SELECT
+            !
+         END SELECT     !  npolj
+         !
+      END DO
+      !
+   END SUBROUTINE ROUTINE_NFD
+
+#undef ARRAY_TYPE
+#undef ARRAY_IN
+#undef NAT_IN
+#undef SGN_IN
+#undef K_SIZE
+#undef L_SIZE
+#undef F_SIZE
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_nfd_nogather_generic.h90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_nfd_nogather_generic.h90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbc_nfd_nogather_generic.h90	(revision 9019)
@@ -0,0 +1,333 @@
+#if defined MULTI
+#   define NAT_IN(k)                cd_nat(k)   
+#   define SGN_IN(k)                psgn(k)
+#   define F_SIZE(ptab)             kfld
+#   if defined DIM_2d
+#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_2D),INTENT(inout)::ptab(f)
+#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt2d(i,j)
+#      define K_SIZE(ptab)             1
+#      define L_SIZE(ptab)             1
+#      define ARRAY2_TYPE(i,j,k,l,f)   TYPE(PTR_2D),INTENT(inout)::ptab2(f)
+#      define ARRAY2_IN(i,j,k,l,f)     ptab2(f)%pt2d(i,j)
+#   endif
+#   if defined DIM_3d
+#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_3D),INTENT(inout)::ptab(f)
+#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt3d(i,j,k)
+#      define K_SIZE(ptab)             SIZE(ptab(1)%pt3d,3)
+#      define L_SIZE(ptab)             1
+#      define ARRAY2_TYPE(i,j,k,l,f)   TYPE(PTR_3D),INTENT(inout)::ptab2(f)
+#      define ARRAY2_IN(i,j,k,l,f)     ptab2(f)%pt3d(i,j,k)
+#   endif
+#   if defined DIM_4d
+#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_4D),INTENT(inout)::ptab(f)
+#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt4d(i,j,k,l)
+#      define K_SIZE(ptab)             SIZE(ptab(1)%pt4d,3)
+#      define L_SIZE(ptab)             SIZE(ptab(1)%pt4d,4)
+#      define ARRAY2_TYPE(i,j,k,l,f)   TYPE(PTR_4D),INTENT(inout)::ptab2(f)
+#      define ARRAY2_IN(i,j,k,l,f)     ptab2(f)%pt4d(i,j,k,l)
+#   endif
+#else
+!                          !==  IN: ptab is an array  ==!
+#   define NAT_IN(k)                cd_nat
+#   define SGN_IN(k)                psgn
+#   define F_SIZE(ptab)             1
+#   if defined DIM_2d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j)
+#      define K_SIZE(ptab)          1
+#      define L_SIZE(ptab)          1
+#      define ARRAY2_IN(i,j,k,l,f)  ptab2(i,j)
+#   endif
+#   if defined DIM_3d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k)
+#      define K_SIZE(ptab)          SIZE(ptab,3)
+#      define L_SIZE(ptab)          1
+#      define ARRAY2_IN(i,j,k,l,f)  ptab2(i,j,k)
+#   endif
+#   if defined DIM_4d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k,l)
+#      define K_SIZE(ptab)          SIZE(ptab,3)
+#      define L_SIZE(ptab)          SIZE(ptab,4)
+#      define ARRAY2_IN(i,j,k,l,f)  ptab2(i,j,k,l)
+#   endif
+#   define ARRAY_TYPE(i,j,k,l,f)     REAL(wp),INTENT(inout)::ARRAY_IN(i,j,k,l,f)
+#   define ARRAY2_TYPE(i,j,k,l,f)    REAL(wp),INTENT(inout)::ARRAY2_IN(i,j,k,l,f)
+#endif
+
+   SUBROUTINE ROUTINE_NFD( ptab, ptab2, cd_nat, psgn, kfld )
+      !
+      !!----------------------------------------------------------------------
+      !!
+      !! ** Purpose :   lateral boundary condition : North fold treatment
+      !!                without allgather exchanges. 
+      !!
+      !!----------------------------------------------------------------------
+      ARRAY_TYPE(:,:,:,:,:)                             ! array or pointer of arrays on which the boundary condition is applied
+      ARRAY2_TYPE(:,:,:,:,:)                            ! array or pointer of arrays on which the boundary condition is applied
+      CHARACTER(len=1) , INTENT(in   ) ::   NAT_IN(:)   ! nature of array grid-points
+      REAL(wp)         , INTENT(in   ) ::   SGN_IN(:)   ! sign used across the north fold boundary
+      INTEGER, OPTIONAL, INTENT(in   ) ::   kfld        ! number of pt3d arrays
+      !
+      INTEGER  ::    ji,  jj,   jk,     jl,   jh,  jf   ! dummy loop indices
+      INTEGER  ::   ipi, ipj,  ipk,    ipl,  ipf        ! dimension of the input array
+      INTEGER  ::   ijt, iju, ijpj, ijpjm1, ijta, ijua, jia, startloop, endloop
+      !!----------------------------------------------------------------------
+      ipk = K_SIZE(ptab)   ! 3rd dimension
+      ipl = L_SIZE(ptab)   ! 4th    -
+      ipf = F_SIZE(ptab)   ! 5th    -      use in "multi" case (array of pointers)
+      !
+      !
+      SELECT CASE ( jpni )
+      CASE ( 1 )     ;   ijpj = nlcj      ! 1 proc only  along the i-direction
+      CASE DEFAULT   ;   ijpj = 4         ! several proc along the i-direction
+      END SELECT
+      ijpjm1 = ijpj-1
+      !
+      !
+      DO jf = 1, ipf                      ! Loop over the number of arrays to be processed
+         SELECT CASE ( npolj )
+         !
+         CASE ( 3, 4 )                       ! *  North fold  T-point pivot
+            !
+            SELECT CASE ( NAT_IN(jf) )
+               CASE ( 'T' , 'W' )                         ! T-, W-point
+                  IF ( nimpp /= 1 ) THEN   ;   startloop = 1
+                  ELSE                     ;   startloop = 2
+               ENDIF
+                  !
+               DO ji = startloop, nlci
+                 ijt=jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
+                        ARRAY_IN(ji,ijpj,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(ijt,ijpj-2,:,:,jf)
+               END DO
+               IF(nimpp .eq. 1) THEN
+                 ARRAY_IN(1,ijpj,:,:,jf) = SGN_IN(jf) * ARRAY_IN(3,ijpj-2,:,:,jf)
+               ENDIF
+   
+               IF( nimpp >= jpiglo/2+1 ) THEN
+                  startloop = 1
+               ELSEIF( nimpp+nlci-1 >= jpiglo/2+1 .AND. nimpp < jpiglo/2+1 ) THEN
+                  startloop = jpiglo/2+1 - nimpp + 1
+               ELSE
+                  startloop = nlci + 1
+               ENDIF
+               IF(startloop <= nlci) THEN
+               DO ji = startloop, nlci
+                  ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
+                  jia = ji + nimpp - 1
+                  ijta = jpiglo - jia + 2
+                  IF( ijta >= startloop+nimpp-1 .AND. ijta < jia ) THEN
+                             ARRAY_IN(ji,ijpjm1,:,:,jf) = SGN_IN(jf) * ARRAY_IN(ijta-nimpp+1,ijpjm1,:,:,jf)
+                  ELSE
+                             ARRAY_IN(ji,ijpjm1,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(ijt,ijpjm1,:,:,jf)
+                  ENDIF
+               END DO
+               ENDIF
+               !
+            CASE ( 'U' )                                     ! U-point
+               IF( nimpp + nlci - 1 /= jpiglo ) THEN
+                  endloop = nlci
+               ELSE
+                  endloop = nlci - 1
+               ENDIF
+               DO ji = 1, endloop
+                  iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
+                        ARRAY_IN(ji,ijpj,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(iju,ijpj-2,:,:,jf)
+               END DO
+               IF (nimpp .eq. 1) THEN
+                        ARRAY_IN(   1  ,ijpj,:,:,jf) = SGN_IN(jf) * ARRAY_IN(    2   ,ijpj-2,:,:,jf)
+               ENDIF
+               IF((nimpp + nlci - 1) .eq. jpiglo) THEN
+                        ARRAY_IN(nlci,ijpj,:,:,jf) = SGN_IN(jf) * ARRAY_IN(nlci-1,ijpj-2,:,:,jf)
+               ENDIF
+               !
+               IF( nimpp + nlci - 1 /= jpiglo ) THEN
+                  endloop = nlci
+               ELSE
+                  endloop = nlci - 1
+               ENDIF
+               IF( nimpp >= jpiglo/2 ) THEN
+                  startloop = 1
+                  ELSEIF( ( nimpp+nlci-1 >= jpiglo/2 ) .AND. ( nimpp < jpiglo/2 ) ) THEN
+                  startloop = jpiglo/2 - nimpp + 1
+               ELSE
+                  startloop = endloop + 1
+               ENDIF
+               IF( startloop <= endloop ) THEN
+               DO ji = startloop, endloop
+                  iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
+                  jia = ji + nimpp - 1
+                  ijua = jpiglo - jia + 1
+                  IF( ijua >= startloop+nimpp-1 .AND. ijua < jia ) THEN
+                           ARRAY_IN(ji,ijpjm1,:,:,jf) = SGN_IN(jf) * ARRAY_IN(ijua-nimpp+1,ijpjm1,:,:,jf)
+                  ELSE
+                           ARRAY_IN(ji,ijpjm1,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(iju,ijpjm1,:,:,jf)
+                  ENDIF
+               END DO
+               ENDIF
+               !
+            CASE ( 'V' )                                     ! V-point
+               IF( nimpp /= 1 ) THEN
+                 startloop = 1
+               ELSE
+                 startloop = 2
+               ENDIF
+               DO ji = startloop, nlci
+                 ijt=jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
+                        ARRAY_IN(ji,ijpj-1,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(ijt,ijpj-2,:,:,jf)
+                        ARRAY_IN(ji,ijpj  ,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(ijt,ijpj-3,:,:,jf)
+               END DO
+               IF (nimpp .eq. 1) THEN
+                        ARRAY_IN(1,ijpj,:,:,jf) = SGN_IN(jf) * ARRAY_IN(3,ijpj-3,:,:,jf)
+               ENDIF
+            CASE ( 'F' )                                     ! F-point
+               IF( nimpp + nlci - 1 /= jpiglo ) THEN
+                  endloop = nlci
+               ELSE
+                  endloop = nlci - 1
+               ENDIF
+               DO ji = 1, endloop
+                  iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
+                        ARRAY_IN(ji,ijpj-1,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(iju,ijpj-2,:,:,jf)
+                        ARRAY_IN(ji,ijpj  ,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(iju,ijpj-3,:,:,jf)
+               END DO
+               IF (nimpp .eq. 1) THEN
+                        ARRAY_IN(   1  ,ijpj  ,:,:,jf) = SGN_IN(jf) * ARRAY_IN(    2   ,ijpj-3,:,:,jf)
+                        ARRAY_IN(   1  ,ijpj-1,:,:,jf) = SGN_IN(jf) * ARRAY_IN(    2   ,ijpj-2,:,:,jf)
+               ENDIF
+               IF((nimpp + nlci - 1) .eq. jpiglo) THEN
+                        ARRAY_IN(nlci,ijpj  ,:,:,jf) = SGN_IN(jf) * ARRAY_IN(nlci-1,ijpj-3,:,:,jf)
+                        ARRAY_IN(nlci,ijpj-1,:,:,jf) = SGN_IN(jf) * ARRAY_IN(nlci-1,ijpj-2,:,:,jf) 
+               ENDIF
+               !
+            CASE ( 'I' )                                     ! ice U-V point (I-point)
+               IF( nimpp /= 1 ) THEN
+                  startloop = 1
+               ELSE
+                  startloop = 3
+                  ARRAY_IN(2,ijpj,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(3,ijpjm1,:,:,jf)
+               ENDIF
+               DO ji = startloop, nlci
+                  iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 5
+                  ARRAY_IN(ji,ijpj,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(iju,ijpjm1,:,:,jf)
+               END DO
+            END SELECT
+            !
+         CASE ( 5, 6 )                        ! *  North fold  F-point pivot
+            !
+            SELECT CASE ( NAT_IN(jf) )
+            CASE ( 'T' , 'W' )                               ! T-, W-point
+               DO ji = 1, nlci
+                  ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
+                        ARRAY_IN(ji,ijpj,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(ijt,ijpj-1,:,:,jf)
+               END DO
+               !
+            CASE ( 'U' )                                     ! U-point
+               IF( nimpp + nlci - 1 /= jpiglo ) THEN
+                  endloop = nlci
+               ELSE
+                  endloop = nlci - 1
+               ENDIF
+               DO ji = 1, endloop
+                  iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 2
+                        ARRAY_IN(ji,ijpj,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(iju,ijpj-1,:,:,jf)
+               END DO
+               IF((nimpp + nlci - 1) .eq. jpiglo) THEN
+                        ARRAY_IN(nlci,ijpj,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(1,ijpj-1,:,:,jf)
+               ENDIF
+               !
+            CASE ( 'V' )                                     ! V-point
+               DO ji = 1, nlci
+                  ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
+                        ARRAY_IN(ji,ijpj,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(ijt,ijpj-2,:,:,jf)
+               END DO
+                  !
+               IF( nimpp >= jpiglo/2+1 ) THEN
+                  startloop = 1
+               ELSEIF( nimpp+nlci-1 >= jpiglo/2+1 .AND. nimpp < jpiglo/2+1 ) THEN
+                  startloop = jpiglo/2+1 - nimpp + 1
+               ELSE
+                  startloop = nlci + 1
+               ENDIF
+               IF( startloop <= nlci ) THEN
+               DO ji = startloop, nlci
+                  ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
+                          ARRAY_IN(ji,ijpjm1,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(ijt,ijpjm1,:,:,jf)
+               END DO
+               ENDIF
+               !
+            CASE ( 'F' )                               ! F-point
+               IF( nimpp + nlci - 1 /= jpiglo ) THEN
+                  endloop = nlci
+               ELSE
+                  endloop = nlci - 1
+               ENDIF
+               DO ji = 1, endloop
+                  iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 2
+                        ARRAY_IN(ji,ijpj ,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(iju,ijpj-2,:,:,jf)
+               END DO
+               IF((nimpp + nlci - 1) .eq. jpiglo) THEN
+                        ARRAY_IN(nlci,ijpj,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(1,ijpj-2,:,:,jf)
+               ENDIF
+               !
+               IF( nimpp + nlci - 1 /= jpiglo ) THEN
+                  endloop = nlci
+               ELSE
+                  endloop = nlci - 1
+               ENDIF
+               IF( nimpp >= jpiglo/2+1 ) THEN
+                  startloop = 1
+               ELSEIF( nimpp+nlci-1 >= jpiglo/2+1 .AND. nimpp < jpiglo/2+1 ) THEN
+                  startloop = jpiglo/2+1 - nimpp + 1
+               ELSE
+                  startloop = endloop + 1
+               ENDIF
+               IF( startloop <= endloop ) THEN
+                  DO ji = startloop, endloop
+                      iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 2
+                      ARRAY_IN(ji,ijpjm1,:,:,jf) = SGN_IN(jf) * ARRAY2_IN(iju,ijpjm1,:,:,jf)
+                  END DO
+               ENDIF
+               !
+            CASE ( 'I' )                                  ! ice U-V point (I-point)
+                  IF( nimpp /= 1 ) THEN
+                     startloop = 1
+                  ELSE
+                     startloop = 2
+                  ENDIF
+                  IF( nimpp + nlci - 1 /= jpiglo ) THEN
+                     endloop = nlci
+                  ELSE
+                     endloop = nlci - 1
+                  ENDIF
+                  DO ji = startloop , endloop
+                     ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
+                     ARRAY_IN(ji,ijpj,:,:,jf) = 0.5 * (ARRAY_IN(ji,ijpjm1,:,:,jf) + SGN_IN(jf) * ARRAY2_IN(ijt,ijpjm1,:,:,jf))
+                  END DO
+                  !
+            END SELECT
+            !
+         CASE DEFAULT                           ! *  closed : the code probably never go through
+            !
+            SELECT CASE ( NAT_IN(jf))
+            CASE ( 'T' , 'U' , 'V' , 'W' )                 ! T-, U-, V-, W-points
+                  ARRAY_IN(:, 1  ,:,:,jf) = 0._wp
+                  ARRAY_IN(:,ijpj,:,:,jf) = 0._wp
+            CASE ( 'F' )                                   ! F-point
+                  ARRAY_IN(:,ijpj,:,:,jf) = 0._wp
+            CASE ( 'I' )                                   ! ice U-V point
+                  ARRAY_IN(:, 1  ,:,:,jf) = 0._wp
+                  ARRAY_IN(:,ijpj,:,:,jf) = 0._wp
+            END SELECT
+            !
+         END SELECT     !  npolj
+         !
+      END DO            ! End jf loop
+   END SUBROUTINE ROUTINE_NFD
+#undef ARRAY_TYPE
+#undef ARRAY_IN
+#undef NAT_IN
+#undef SGN_IN
+#undef K_SIZE
+#undef L_SIZE
+#undef F_SIZE
+#undef ARRAY2_TYPE
+#undef ARRAY2_IN
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbclnk.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbclnk.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbclnk.F90	(revision 9019)
@@ -2,12 +2,15 @@
    !!======================================================================
    !!                       ***  MODULE  lbclnk  ***
-   !! Ocean        : lateral boundary conditions
+   !! NEMO        : lateral boundary conditions
    !!=====================================================================
    !! History :  OPA  ! 1997-06  (G. Madec)  Original code
    !!   NEMO     1.0  ! 2002-09  (G. Madec)  F90: Free form and module
    !!            3.2  ! 2009-03  (R. Benshila)  External north fold treatment  
-   !!            3.5  ! 2012     (S.Mocavero, I. Epicoco) optimization of BDY comm. via lbc_bdy_lnk and lbc_obc_lnk
+   !!            3.5  ! 2012     (S.Mocavero, I. Epicoco)  optimization of BDY comm. via lbc_bdy_lnk and lbc_obc_lnk
    !!            3.4  ! 2012-12  (R. Bourdalle-Badie, G. Reffray)  add a C1D case  
    !!            3.6  ! 2015-06  (O. Tintó and M. Castrillo)  add lbc_lnk_multi  
+   !!            4.0  ! 2017-03  (G. Madec) automatique allocation of array size (use with any 3rd dim size)
+   !!             -   ! 2017-04  (G. Madec) remove duplicated routines (lbc_lnk_2d_9, lbc_lnk_2d_multiple, lbc_lnk_3d_gather)
+   !!             -   ! 2017-05  (G. Madec) create generic.h90 files to generate all lbc and north fold routines
    !!----------------------------------------------------------------------
 #if defined key_mpp_mpi
@@ -15,21 +18,21 @@
    !!   'key_mpp_mpi'             MPI massively parallel processing library
    !!----------------------------------------------------------------------
-   !!   lbc_lnk      : generic interface for mpp_lnk_3d and mpp_lnk_2d routines defined in lib_mpp
-   !!   lbc_sum      : generic interface for mpp_lnk_sum_3d and mpp_lnk_sum_2d routines defined in lib_mpp
-   !!   lbc_lnk_e    : generic interface for mpp_lnk_2d_e routine defined in lib_mpp
-   !!   lbc_bdy_lnk  : generic interface for mpp_lnk_bdy_2d and mpp_lnk_bdy_3d routines defined in lib_mpp
-   !!----------------------------------------------------------------------
+   !!           define the generic interfaces of lib_mpp routines
+   !!----------------------------------------------------------------------
+   !!   lbc_lnk       : generic interface for mpp_lnk_3d and mpp_lnk_2d routines defined in lib_mpp
+   !!   lbc_bdy_lnk   : generic interface for mpp_lnk_bdy_2d and mpp_lnk_bdy_3d routines defined in lib_mpp
+   !!----------------------------------------------------------------------
+   USE par_oce        ! ocean dynamics and tracers   
    USE lib_mpp        ! distributed memory computing library
-
+   USE lbcnfd         ! north fold
+
+   INTERFACE lbc_lnk
+      MODULE PROCEDURE   mpp_lnk_2d      , mpp_lnk_3d      , mpp_lnk_4d
+   END INTERFACE
+   INTERFACE lbc_lnk_ptr
+      MODULE PROCEDURE   mpp_lnk_2d_ptr  , mpp_lnk_3d_ptr  , mpp_lnk_4d_ptr
+   END INTERFACE
    INTERFACE lbc_lnk_multi
-      MODULE PROCEDURE mpp_lnk_2d_9, mpp_lnk_2d_multiple
-   END INTERFACE
-   !
-   INTERFACE lbc_lnk
-      MODULE PROCEDURE mpp_lnk_3d_gather, mpp_lnk_3d, mpp_lnk_2d
-   END INTERFACE
-   !
-   INTERFACE lbc_sum
-      MODULE PROCEDURE mpp_lnk_sum_3d, mpp_lnk_sum_2d
+      MODULE PROCEDURE   lbc_lnk_2d_multi, lbc_lnk_3d_multi, lbc_lnk_4d_multi
    END INTERFACE
    !
@@ -38,29 +41,27 @@
    END INTERFACE
    !
-   INTERFACE lbc_lnk_e
-      MODULE PROCEDURE mpp_lnk_2d_e
-   END INTERFACE
-   !
    INTERFACE lbc_lnk_icb
       MODULE PROCEDURE mpp_lnk_2d_icb
    END INTERFACE
 
-   PUBLIC   lbc_lnk       ! ocean lateral boundary conditions
-   PUBLIC   lbc_lnk_multi ! modified ocean lateral boundary conditions
-   PUBLIC   lbc_sum
-   PUBLIC   lbc_lnk_e     !
+   PUBLIC   lbc_lnk       ! ocean/ice lateral boundary conditions
+   PUBLIC   lbc_lnk_multi ! modified ocean/ice lateral boundary conditions
    PUBLIC   lbc_bdy_lnk   ! ocean lateral BDY boundary conditions
-   PUBLIC   lbc_lnk_icb   !
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   PUBLIC   lbc_lnk_icb   ! iceberg lateral boundary conditions
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
+CONTAINS
+
 #else
    !!----------------------------------------------------------------------
    !!   Default option                              shared memory computing
    !!----------------------------------------------------------------------
-   !!   lbc_sum       : generic interface for mpp_lnk_sum_3d and mpp_lnk_sum_2d 
+   !!                routines setting the appropriate values
+   !!         on first and last row and column of the global domain
+   !!----------------------------------------------------------------------
    !!   lbc_lnk_sum_3d: compute sum over the halos on a 3D variable on ocean mesh
    !!   lbc_lnk_sum_3d: compute sum over the halos on a 2D variable on ocean mesh
@@ -70,8 +71,8 @@
    !!   lbc_bdy_lnk   : set the lateral BDY boundary condition
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers   
-   USE dom_oce         ! ocean space and time domain 
-   USE in_out_manager  ! I/O manager
-   USE lbcnfd          ! north fold
+   USE oce            ! ocean dynamics and tracers   
+   USE dom_oce        ! ocean space and time domain 
+   USE in_out_manager ! I/O manager
+   USE lbcnfd         ! north fold
 
    IMPLICIT NONE
@@ -79,19 +80,13 @@
 
    INTERFACE lbc_lnk
-      MODULE PROCEDURE lbc_lnk_3d_gather, lbc_lnk_3d, lbc_lnk_2d
-   END INTERFACE
-   !
-   INTERFACE lbc_sum
-      MODULE PROCEDURE lbc_lnk_sum_3d, lbc_lnk_sum_2d
-   END INTERFACE
-
-   INTERFACE lbc_lnk_e
-      MODULE PROCEDURE lbc_lnk_2d_e
-   END INTERFACE
-   !
+      MODULE PROCEDURE   lbc_lnk_2d      , lbc_lnk_3d      , lbc_lnk_4d
+   END INTERFACE
+   INTERFACE lbc_lnk_ptr
+      MODULE PROCEDURE   lbc_lnk_2d_ptr  , lbc_lnk_3d_ptr  , lbc_lnk_4d_ptr
+   END INTERFACE
    INTERFACE lbc_lnk_multi
-      MODULE PROCEDURE lbc_lnk_2d_9, lbc_lnk_2d_multiple
-   END INTERFACE
-
+      MODULE PROCEDURE   lbc_lnk_2d_multi, lbc_lnk_3d_multi, lbc_lnk_4d_multi
+   END INTERFACE
+   !
    INTERFACE lbc_bdy_lnk
       MODULE PROCEDURE lbc_bdy_lnk_2d, lbc_bdy_lnk_3d
@@ -99,21 +94,14 @@
    !
    INTERFACE lbc_lnk_icb
-      MODULE PROCEDURE lbc_lnk_2d_e
-   END INTERFACE
-   
-   TYPE arrayptr
-      REAL , DIMENSION (:,:),  POINTER :: pt2d
-   END TYPE arrayptr
-   PUBLIC   arrayptr
-
+      MODULE PROCEDURE lbc_lnk_2d_icb
+   END INTERFACE
+   
    PUBLIC   lbc_lnk       ! ocean/ice  lateral boundary conditions
-   PUBLIC   lbc_sum       ! ocean/ice  lateral boundary conditions (sum of the overlap region)
-   PUBLIC   lbc_lnk_e     !
-   PUBLIC   lbc_lnk_multi ! modified ocean lateral boundary conditions
+   PUBLIC   lbc_lnk_multi ! modified ocean/ice lateral boundary conditions
    PUBLIC   lbc_bdy_lnk   ! ocean lateral BDY boundary conditions
-   PUBLIC   lbc_lnk_icb   !
-   
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
+   PUBLIC   lbc_lnk_icb   ! iceberg lateral boundary conditions
+   
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -122,26 +110,9 @@
 
 # if defined key_c1d
-   !!----------------------------------------------------------------------
+   !!======================================================================
    !!   'key_c1d'                                          1D configuration
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE lbc_lnk_3d_gather( pt3d1, cd_type1, pt3d2, cd_type2, psgn )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE lbc_lnk_3d_gather  ***
-      !!
-      !! ** Purpose :   set lateral boundary conditions on two 3D arrays (C1D case)
-      !!
-      !! ** Method  :   call lbc_lnk_3d on pt3d1 and pt3d2
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type1, cd_type2   ! nature of pt3d grid-points
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pt3d1   , pt3d2      ! 3D array on which the lbc is applied
-      REAL(wp)                        , INTENT(in   ) ::   psgn                 ! control of the sign 
-      !!----------------------------------------------------------------------
-      !
-      CALL lbc_lnk_3d( pt3d1, cd_type1, psgn)
-      CALL lbc_lnk_3d( pt3d2, cd_type2, psgn)
-      !
-   END SUBROUTINE lbc_lnk_3d_gather
-
+   !!======================================================================
+   !!     central point value replicated over the 8 surrounding points
+   !!----------------------------------------------------------------------
 
    SUBROUTINE lbc_lnk_3d( pt3d, cd_type, psgn, cd_mpp, pval )
@@ -153,9 +124,9 @@
       !! ** Method  :   1D case, the central water column is set everywhere
       !!----------------------------------------------------------------------
-      CHARACTER(len=1)                , INTENT(in   )           ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout)           ::   pt3d      ! 3D array on which the lbc is applied
-      REAL(wp)                        , INTENT(in   )           ::   psgn      ! control of the sign 
-      CHARACTER(len=3)                , INTENT(in   ), OPTIONAL ::   cd_mpp    ! MPP only (here do nothing)
-      REAL(wp)                        , INTENT(in   ), OPTIONAL ::   pval      ! background value (for closed boundaries)
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout)           ::   pt3d      ! 3D array on which the lbc is applied
+      CHARACTER(len=1)          , INTENT(in   )           ::   cd_type   ! nature of pt3d grid-points
+      REAL(wp)                  , INTENT(in   )           ::   psgn      ! sign used across north fold 
+      CHARACTER(len=3)          , INTENT(in   ), OPTIONAL ::   cd_mpp    ! MPP only (here do nothing)
+      REAL(wp)                  , INTENT(in   ), OPTIONAL ::   pval      ! background value (for closed boundaries)
       !
       INTEGER  ::   jk     ! dummy loop index
@@ -163,5 +134,5 @@
       !!----------------------------------------------------------------------
       !
-      DO jk = 1, jpk
+      DO jk = 1, SIZE( pt3d, 3 )
          ztab = pt3d(2,2,jk)
          pt3d(:,:,jk) = ztab
@@ -179,7 +150,7 @@
       !! ** Method  :   1D case, the central water column is set everywhere
       !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout)           ::   pt2d      ! 2D array on which the lbc is applied
       CHARACTER(len=1)            , INTENT(in   )           ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout)           ::   pt2d      ! 2D array on which the lbc is applied
-      REAL(wp)                    , INTENT(in   )           ::   psgn      ! control of the sign 
+      REAL(wp)                    , INTENT(in   )           ::   psgn      ! sign used across north fold 
       CHARACTER(len=3)            , INTENT(in   ), OPTIONAL ::   cd_mpp    ! MPP only (here do nothing)
       REAL(wp)                    , INTENT(in   ), OPTIONAL ::   pval      ! background value (for closed boundaries)
@@ -193,490 +164,166 @@
    END SUBROUTINE lbc_lnk_2d
    
-   SUBROUTINE lbc_lnk_2d_multiple( pt2d_array , type_array , psgn_array , num_fields )
-      !!
-      INTEGER :: num_fields
-      TYPE( arrayptr ), DIMENSION(:) :: pt2d_array
-      CHARACTER(len=1), DIMENSION(:), INTENT(in   ) ::   type_array   ! define the nature of ptab array grid-points
-      !                                                               ! = T , U , V , F , W and I points
-      REAL(wp)        , DIMENSION(:), INTENT(in   ) ::   psgn_array   ! =-1 the sign change across the north fold boundary
-      !                                                               ! =  1. , the sign is kept
-      !
-      INTEGER  ::   ii    !!MULTI SEND DUMMY LOOP INDICES
-      !
-      DO ii = 1, num_fields
-        CALL lbc_lnk_2d( pt2d_array(ii)%pt2d, type_array(ii), psgn_array(ii) )
-      END DO     
-      !
-   END SUBROUTINE lbc_lnk_2d_multiple
-
-   SUBROUTINE lbc_lnk_2d_9( pt2dA, cd_typeA, psgnA, pt2dB, cd_typeB, psgnB, pt2dC, cd_typeC, psgnC   &
-      &                   , pt2dD, cd_typeD, psgnD, pt2dE, cd_typeE, psgnE, pt2dF, cd_typeF, psgnF   &
-      &                   , pt2dG, cd_typeG, psgnG, pt2dH, cd_typeH, psgnH, pt2dI, cd_typeI, psgnI, cd_mpp, pval)
-      !!---------------------------------------------------------------------
-      ! Second 2D array on which the boundary condition is applied
-      REAL(wp), DIMENSION(jpi,jpj), TARGET          , INTENT(inout) ::   pt2dA
-      REAL(wp), DIMENSION(jpi,jpj), TARGET, OPTIONAL, INTENT(inout) ::   pt2dB , pt2dC , pt2dD , pt2dE
-      REAL(wp), DIMENSION(jpi,jpj), TARGET, OPTIONAL, INTENT(inout) ::   pt2dF , pt2dG , pt2dH , pt2dI
-      ! define the nature of ptab array grid-points
-      CHARACTER(len=1)                              , INTENT(in   ) ::   cd_typeA
-      CHARACTER(len=1)                    , OPTIONAL, INTENT(in   ) ::   cd_typeB , cd_typeC , cd_typeD , cd_typeE
-      CHARACTER(len=1)                    , OPTIONAL, INTENT(in   ) ::   cd_typeF , cd_typeG , cd_typeH , cd_typeI
-      ! =-1 the sign change across the north fold boundary
-      REAL(wp)                                      , INTENT(in   ) ::   psgnA
-      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   psgnB , psgnC , psgnD , psgnE
-      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   psgnF , psgnG , psgnH , psgnI
-      CHARACTER(len=3)                    , OPTIONAL, INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
-      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
-      !!
-      !!---------------------------------------------------------------------
-
-      !!The first array
-      CALL lbc_lnk( pt2dA, cd_typeA, psgnA ) 
-
-      !! Look if more arrays to process
-      IF(PRESENT (psgnB) )CALL lbc_lnk( pt2dB, cd_typeB, psgnB )
-      IF(PRESENT (psgnC) )CALL lbc_lnk( pt2dC, cd_typeC, psgnC ) 
-      IF(PRESENT (psgnD) )CALL lbc_lnk( pt2dD, cd_typeD, psgnD ) 
-      IF(PRESENT (psgnE) )CALL lbc_lnk( pt2dE, cd_typeE, psgnE ) 
-      IF(PRESENT (psgnF) )CALL lbc_lnk( pt2dF, cd_typeF, psgnF ) 
-      IF(PRESENT (psgnG) )CALL lbc_lnk( pt2dG, cd_typeG, psgnG ) 
-      IF(PRESENT (psgnH) )CALL lbc_lnk( pt2dH, cd_typeH, psgnH ) 
-      IF(PRESENT (psgnI) )CALL lbc_lnk( pt2dI, cd_typeI, psgnI ) 
-
-   END SUBROUTINE lbc_lnk_2d_9
-
-
-
-
-
 #else
-   !!----------------------------------------------------------------------
+   !!======================================================================
    !!   Default option                           3D shared memory computing
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE lbc_lnk_3d_gather( pt3d1, cd_type1, pt3d2, cd_type2, psgn )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE lbc_lnk_3d_gather  ***
-      !!
-      !! ** Purpose :   set lateral boundary conditions on two 3D arrays (non mpp case)
-      !!
-      !! ** Method  :   psign = -1 :    change the sign across the north fold
-      !!                      =  1 : no change of the sign across the north fold
-      !!                      =  0 : no change of the sign across the north fold and
-      !!                             strict positivity preserved: use inner row/column
-      !!                             for closed boundaries.
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type1, cd_type2   ! nature of pt3d grid-points
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pt3d1   , pt3d2      ! 3D array on which the lbc is applied
-      REAL(wp)                        , INTENT(in   ) ::   psgn                 ! control of the sign 
-      !!----------------------------------------------------------------------
-      !
-      CALL lbc_lnk_3d( pt3d1, cd_type1, psgn)
-      CALL lbc_lnk_3d( pt3d2, cd_type2, psgn)
-      !
-   END SUBROUTINE lbc_lnk_3d_gather
-
-
-   SUBROUTINE lbc_lnk_3d( pt3d, cd_type, psgn, cd_mpp, pval )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE lbc_lnk_3d  ***
-      !!
-      !! ** Purpose :   set lateral boundary conditions on a 3D array (non mpp case)
-      !!
-      !! ** Method  :   psign = -1 :    change the sign across the north fold
-      !!                      =  1 : no change of the sign across the north fold
-      !!                      =  0 : no change of the sign across the north fold and
-      !!                             strict positivity preserved: use inner row/column
-      !!                             for closed boundaries.
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)                , INTENT(in   )           ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout)           ::   pt3d      ! 3D array on which the lbc is applied
-      REAL(wp)                        , INTENT(in   )           ::   psgn      ! control of the sign 
-      CHARACTER(len=3)                , INTENT(in   ), OPTIONAL ::   cd_mpp    ! MPP only (here do nothing)
-      REAL(wp)                        , INTENT(in   ), OPTIONAL ::   pval      ! background value (for closed boundaries)
-      !!
-      REAL(wp) ::   zland
-      !!----------------------------------------------------------------------
-
-      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value (zero by default)
-      ELSE                         ;   zland = 0._wp
-      ENDIF
-
-
-      IF( PRESENT( cd_mpp ) ) THEN
-         ! only fill the overlap area and extra allows 
-         ! this is in mpp case. In this module, just do nothing
-      ELSE
-         !                                     !  East-West boundaries
-         !                                     ! ======================
-         SELECT CASE ( nperio )
-         !
-         CASE ( 1 , 4 , 6 )                       !**  cyclic east-west
-            pt3d( 1 ,:,:) = pt3d(jpim1,:,:)            ! all points
-            pt3d(jpi,:,:) = pt3d(  2  ,:,:)
-            !
-         CASE DEFAULT                             !**  East closed  --  West closed
-            SELECT CASE ( cd_type )
-            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
-               pt3d( 1 ,:,:) = zland
-               pt3d(jpi,:,:) = zland
-            CASE ( 'F' )                               ! F-point
-               pt3d(jpi,:,:) = zland
-            END SELECT
-            !
-         END SELECT
-         !                                     ! North-South boundaries
-         !                                     ! ======================
-         SELECT CASE ( nperio )
-         !
-         CASE ( 2 )                               !**  South symmetric  --  North closed
-            SELECT CASE ( cd_type )
-            CASE ( 'T' , 'U' , 'W' )                   ! T-, U-, W-points
-               pt3d(:, 1 ,:) = pt3d(:,3,:)
-               pt3d(:,jpj,:) = zland
-            CASE ( 'V' , 'F' )                         ! V-, F-points
-               pt3d(:, 1 ,:) = psgn * pt3d(:,2,:)
-               pt3d(:,jpj,:) = zland
-            END SELECT
-            !
-         CASE ( 3 , 4 , 5 , 6 )                   !**  North fold  T or F-point pivot  --  South closed
-            SELECT CASE ( cd_type )                    ! South : closed
-            CASE ( 'T' , 'U' , 'V' , 'W' , 'I' )             ! all points except F-point
-               pt3d(:, 1 ,:) = zland
-            END SELECT
-            !                                          ! North fold
-            CALL lbc_nfd( pt3d(:,:,:), cd_type, psgn )
-            !
-         CASE DEFAULT                             !**  North closed  --  South closed
-            SELECT CASE ( cd_type )
-            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
-               pt3d(:, 1 ,:) = zland
-               pt3d(:,jpj,:) = zland
-            CASE ( 'F' )                               ! F-point
-               pt3d(:,jpj,:) = zland
-            END SELECT
-            !
-         END SELECT
-         !
-      ENDIF
-      !
-   END SUBROUTINE lbc_lnk_3d
-
-
-   SUBROUTINE lbc_lnk_2d( pt2d, cd_type, psgn, cd_mpp, pval )
-      !!---------------------------------------------------------------------
-      !!                 ***  ROUTINE lbc_lnk_2d  ***
-      !!
-      !! ** Purpose :   set lateral boundary conditions on a 2D array (non mpp case)
-      !!
-      !! ** Method  :   psign = -1 :    change the sign across the north fold
-      !!                      =  1 : no change of the sign across the north fold
-      !!                      =  0 : no change of the sign across the north fold and
-      !!                             strict positivity preserved: use inner row/column
-      !!                             for closed boundaries.
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)            , INTENT(in   )           ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout)           ::   pt2d      ! 2D array on which the lbc is applied
-      REAL(wp)                    , INTENT(in   )           ::   psgn      ! control of the sign 
-      CHARACTER(len=3)            , INTENT(in   ), OPTIONAL ::   cd_mpp    ! MPP only (here do nothing)
-      REAL(wp)                    , INTENT(in   ), OPTIONAL ::   pval      ! background value (for closed boundaries)
-      !!
-      REAL(wp) ::   zland
-      !!----------------------------------------------------------------------
-
-      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value (zero by default)
-      ELSE                         ;   zland = 0._wp
-      ENDIF
-
-      IF (PRESENT(cd_mpp)) THEN
-         ! only fill the overlap area and extra allows 
-         ! this is in mpp case. In this module, just do nothing
-      ELSE      
-         !                                     ! East-West boundaries
-         !                                     ! ====================
-         SELECT CASE ( nperio )
-         !
-         CASE ( 1 , 4 , 6 )                       !** cyclic east-west
-            pt2d( 1 ,:) = pt2d(jpim1,:)               ! all points
-            pt2d(jpi,:) = pt2d(  2  ,:)
-            !
-         CASE DEFAULT                             !** East closed  --  West closed
-            SELECT CASE ( cd_type )
-            CASE ( 'T' , 'U' , 'V' , 'W' )            ! T-, U-, V-, W-points
-               pt2d( 1 ,:) = zland
-               pt2d(jpi,:) = zland
-            CASE ( 'F' )                              ! F-point
-               pt2d(jpi,:) = zland
-            END SELECT
-            !
-         END SELECT
-         !                                     ! North-South boundaries
-         !                                     ! ======================
-         SELECT CASE ( nperio )
-         !
-         CASE ( 2 )                               !**  South symmetric  --  North closed
-            SELECT CASE ( cd_type )
-            CASE ( 'T' , 'U' , 'W' )                   ! T-, U-, W-points
-               pt2d(:, 1 ) = pt2d(:,3)
-               pt2d(:,jpj) = zland
-            CASE ( 'V' , 'F' )                         ! V-, F-points
-               pt2d(:, 1 ) = psgn * pt2d(:,2)
-               pt2d(:,jpj) = zland
-            END SELECT
-            !
-         CASE ( 3 , 4 , 5 , 6 )                   !**  North fold  T or F-point pivot  --  South closed
-            SELECT CASE ( cd_type )                    ! South : closed
-            CASE ( 'T' , 'U' , 'V' , 'W' , 'I' )             ! all points except F-point
-               pt2d(:, 1 ) = zland
-            END SELECT
-            !                                          ! North fold
-            CALL lbc_nfd( pt2d(:,:), cd_type, psgn )
-            !
-         CASE DEFAULT                             !**  North closed  --  South closed
-            SELECT CASE ( cd_type )
-            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
-               pt2d(:, 1 ) = zland
-               pt2d(:,jpj) = zland
-            CASE ( 'F' )                               ! F-point
-               pt2d(:,jpj) = zland
-            END SELECT
-            !
-         END SELECT
-         !
-      ENDIF
-      !    
-   END SUBROUTINE lbc_lnk_2d
-   
-   SUBROUTINE lbc_lnk_2d_multiple( pt2d_array , type_array , psgn_array , num_fields )
-      !!
-      INTEGER :: num_fields
-      TYPE( arrayptr ), DIMENSION(:) :: pt2d_array
-      CHARACTER(len=1), DIMENSION(:), INTENT(in   ) ::   type_array   ! define the nature of ptab array grid-points
-      !                                                               ! = T , U , V , F , W and I points
-      REAL(wp)        , DIMENSION(:), INTENT(in   ) ::   psgn_array   ! =-1 the sign change across the north fold boundary
-      !                                                               ! =  1. , the sign is kept
-      !
-      INTEGER  ::   ii    !!MULTI SEND DUMMY LOOP INDICES
-      !
-      DO ii = 1, num_fields
-        CALL lbc_lnk_2d( pt2d_array(ii)%pt2d, type_array(ii), psgn_array(ii) )
-      END DO     
-      !
-   END SUBROUTINE lbc_lnk_2d_multiple
-
-   SUBROUTINE lbc_lnk_2d_9( pt2dA, cd_typeA, psgnA, pt2dB, cd_typeB, psgnB, pt2dC, cd_typeC, psgnC   &
-      &                   , pt2dD, cd_typeD, psgnD, pt2dE, cd_typeE, psgnE, pt2dF, cd_typeF, psgnF   &
-      &                   , pt2dG, cd_typeG, psgnG, pt2dH, cd_typeH, psgnH, pt2dI, cd_typeI, psgnI, cd_mpp, pval)
-      !!---------------------------------------------------------------------
-      ! Second 2D array on which the boundary condition is applied
-      REAL(wp), DIMENSION(jpi,jpj), TARGET          , INTENT(inout) ::   pt2dA
-      REAL(wp), DIMENSION(jpi,jpj), TARGET, OPTIONAL, INTENT(inout) ::   pt2dB , pt2dC , pt2dD , pt2dE
-      REAL(wp), DIMENSION(jpi,jpj), TARGET, OPTIONAL, INTENT(inout) ::   pt2dF , pt2dG , pt2dH , pt2dI
-      ! define the nature of ptab array grid-points
-      CHARACTER(len=1)                              , INTENT(in   ) ::   cd_typeA
-      CHARACTER(len=1)                    , OPTIONAL, INTENT(in   ) ::   cd_typeB , cd_typeC , cd_typeD , cd_typeE
-      CHARACTER(len=1)                    , OPTIONAL, INTENT(in   ) ::   cd_typeF , cd_typeG , cd_typeH , cd_typeI
-      ! =-1 the sign change across the north fold boundary
-      REAL(wp)                                      , INTENT(in   ) ::   psgnA
-      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   psgnB , psgnC , psgnD , psgnE
-      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   psgnF , psgnG , psgnH , psgnI
-      CHARACTER(len=3)                    , OPTIONAL, INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
-      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
-      !!
-      !!---------------------------------------------------------------------
-
-      !!The first array
-      CALL lbc_lnk( pt2dA, cd_typeA, psgnA ) 
-
-      !! Look if more arrays to process
-      IF(PRESENT (psgnB) )CALL lbc_lnk( pt2dB, cd_typeB, psgnB )
-      IF(PRESENT (psgnC) )CALL lbc_lnk( pt2dC, cd_typeC, psgnC ) 
-      IF(PRESENT (psgnD) )CALL lbc_lnk( pt2dD, cd_typeD, psgnD ) 
-      IF(PRESENT (psgnE) )CALL lbc_lnk( pt2dE, cd_typeE, psgnE ) 
-      IF(PRESENT (psgnF) )CALL lbc_lnk( pt2dF, cd_typeF, psgnF ) 
-      IF(PRESENT (psgnG) )CALL lbc_lnk( pt2dG, cd_typeG, psgnG ) 
-      IF(PRESENT (psgnH) )CALL lbc_lnk( pt2dH, cd_typeH, psgnH ) 
-      IF(PRESENT (psgnI) )CALL lbc_lnk( pt2dI, cd_typeI, psgnI ) 
-
-   END SUBROUTINE lbc_lnk_2d_9
-
-   SUBROUTINE lbc_lnk_sum_2d( pt2d, cd_type, psgn, cd_mpp, pval )
-      !!---------------------------------------------------------------------
-      !!                 ***  ROUTINE lbc_lnk_sum_2d  ***
-      !!
-      !! ** Purpose :   set lateral boundary conditions on a 2D array (non mpp case)
-      !!
-      !! ** Comments:   compute the sum of the common cell (overlap region) for the ice sheet/ocean 
-      !!                coupling if conservation option activated. As no ice shelf are present along
-      !!                this line, nothing is done along the north fold.
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)            , INTENT(in   )           ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout)           ::   pt2d      ! 2D array on which the lbc is applied
-      REAL(wp)                    , INTENT(in   )           ::   psgn      ! control of the sign 
-      CHARACTER(len=3)            , INTENT(in   ), OPTIONAL ::   cd_mpp    ! MPP only (here do nothing)
-      REAL(wp)                    , INTENT(in   ), OPTIONAL ::   pval      ! background value (for closed boundaries)
-      !!
-      REAL(wp) ::   zland
-      !!----------------------------------------------------------------------
-
-      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value (zero by default)
-      ELSE                         ;   zland = 0._wp
-      ENDIF
-
-      IF (PRESENT(cd_mpp)) THEN
-         ! only fill the overlap area and extra allows 
-         ! this is in mpp case. In this module, just do nothing
-      ELSE
-         !                                     ! East-West boundaries
-         !                                     ! ====================
-         SELECT CASE ( nperio )
-         !
-         CASE ( 1 , 4 , 6 )                       !** cyclic east-west
-            pt2d(jpim1,:) = pt2d(jpim1,:) + pt2d( 1 ,:)
-            pt2d(  2  ,:) = pt2d(  2  ,:) + pt2d(jpi,:)
-            pt2d( 1 ,:) = 0.0_wp               ! all points
-            pt2d(jpi,:) = 0.0_wp
-            !
-         CASE DEFAULT                             !** East closed  --  West closed
-            SELECT CASE ( cd_type )
-            CASE ( 'T' , 'U' , 'V' , 'W' )            ! T-, U-, V-, W-points
-               pt2d( 1 ,:) = zland
-               pt2d(jpi,:) = zland
-            CASE ( 'F' )                              ! F-point
-               pt2d(jpi,:) = zland
-            END SELECT
-            !
-         END SELECT
-         !                                     ! North-South boundaries
-         !                                     ! ======================
-         ! Nothing to do for the north fold, there is no ice shelf along this line.
-         !
-      END IF
-
-   END SUBROUTINE
-
-   SUBROUTINE lbc_lnk_sum_3d( pt3d, cd_type, psgn, cd_mpp, pval )
-      !!---------------------------------------------------------------------
-      !!                 ***  ROUTINE lbc_lnk_sum_3d  ***
-      !!
-      !! ** Purpose :   set lateral boundary conditions on a 3D array (non mpp case)
-      !!
-      !! ** Comments:   compute the sum of the common cell (overlap region) for the ice sheet/ocean 
-      !!                coupling if conservation option activated. As no ice shelf are present along
-      !!                this line, nothing is done along the north fold.
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)                , INTENT(in   )           ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout)           ::   pt3d      ! 3D array on which the lbc is applied
-      REAL(wp)                        , INTENT(in   )           ::   psgn      ! control of the sign 
-      CHARACTER(len=3)                , INTENT(in   ), OPTIONAL ::   cd_mpp    ! MPP only (here do nothing)
-      REAL(wp)                        , INTENT(in   ), OPTIONAL ::   pval      ! background value (for closed boundaries)
-      !!
-      REAL(wp) ::   zland
-      !!----------------------------------------------------------------------
-
-      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value (zero by default)
-      ELSE                         ;   zland = 0._wp
-      ENDIF
-
-
-      IF( PRESENT( cd_mpp ) ) THEN
-         ! only fill the overlap area and extra allows 
-         ! this is in mpp case. In this module, just do nothing
-      ELSE
-         !                                     !  East-West boundaries
-         !                                     ! ======================
-         SELECT CASE ( nperio )
-         !
-         CASE ( 1 , 4 , 6 )                       !**  cyclic east-west
-            pt3d(jpim1,:,:) = pt3d(jpim1,:,:) + pt3d( 1 ,:,:)
-            pt3d(  2  ,:,:) = pt3d(  2  ,:,:) + pt3d(jpi,:,:) 
-            pt3d( 1 ,:,:) = 0.0_wp            ! all points
-            pt3d(jpi,:,:) = 0.0_wp
-            !
-         CASE DEFAULT                             !**  East closed  --  West closed
-            SELECT CASE ( cd_type )
-            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
-               pt3d( 1 ,:,:) = zland
-               pt3d(jpi,:,:) = zland
-            CASE ( 'F' )                               ! F-point
-               pt3d(jpi,:,:) = zland
-            END SELECT
-            !
-         END SELECT
-         !                                     ! North-South boundaries
-         !                                     ! ======================
-         ! Nothing to do for the north fold, there is no ice shelf along this line.
-         !
-      END IF
-   END SUBROUTINE
-
-
+   !!======================================================================
+   !!          routines setting land point, or east-west cyclic,
+   !!             or north-south cyclic, or north fold values
+   !!         on first and last row and column of the global domain
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!                   ***  routine lbc_lnk_(2,3,4)d  ***
+   !!
+   !!   * Argument : dummy argument use in lbc_lnk_... routines
+   !!                ptab   :   array or pointer of arrays on which the boundary condition is applied
+   !!                cd_nat :   nature of array grid-points
+   !!                psgn   :   sign used across the north fold boundary
+   !!                kfld   :   optional, number of pt3d arrays
+   !!                cd_mpp :   optional, fill the overlap area only
+   !!                pval   :   optional, background value (used at closed boundaries)
+   !!----------------------------------------------------------------------
+   !
+   !                       !==  2D array and array of 2D pointer  ==!
+   !
+#  define DIM_2d
+#     define ROUTINE_LNK           lbc_lnk_2d
+#     include "lbc_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     define MULTI
+#     define ROUTINE_LNK           lbc_lnk_2d_ptr
+#     include "lbc_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     undef MULTI
+#  undef DIM_2d
+   !
+   !                       !==  3D array and array of 3D pointer  ==!
+   !
+#  define DIM_3d
+#     define ROUTINE_LNK           lbc_lnk_3d
+#     include "lbc_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     define MULTI
+#     define ROUTINE_LNK           lbc_lnk_3d_ptr
+#     include "lbc_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     undef MULTI
+#  undef DIM_3d
+   !
+   !                       !==  4D array and array of 4D pointer  ==!
+   !
+#  define DIM_4d
+#     define ROUTINE_LNK           lbc_lnk_4d
+#     include "lbc_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     define MULTI
+#     define ROUTINE_LNK           lbc_lnk_4d_ptr
+#     include "lbc_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     undef MULTI
+#  undef DIM_4d
+   
 #endif
 
+   !!======================================================================
+   !!   identical routines in both C1D and shared memory computing
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!                   ***  routine lbc_bdy_lnk_(2,3)d  ***
+   !!
+   !!   wrapper rountine to 'lbc_lnk_3d'. This wrapper is used
+   !!   to maintain the same interface with regards to the mpp case
+   !!----------------------------------------------------------------------
+   
    SUBROUTINE lbc_bdy_lnk_3d( pt3d, cd_type, psgn, ib_bdy )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE lbc_bdy_lnk  ***
-      !!
-      !! ** Purpose :   wrapper rountine to 'lbc_lnk_3d'. This wrapper is used
-      !!              to maintain the same interface with regards to the mpp case
-      !!
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pt3d      ! 3D array on which the lbc is applied
-      REAL(wp)                        , INTENT(in   ) ::   psgn      ! control of the sign 
-      INTEGER                         , INTENT(in   ) ::   ib_bdy    ! BDY boundary set
-      !!----------------------------------------------------------------------
-      !
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pt3d      ! 3D array on which the lbc is applied
+      CHARACTER(len=1)          , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
+      REAL(wp)                  , INTENT(in   ) ::   psgn      ! sign used across north fold 
+      INTEGER                   , INTENT(in   ) ::   ib_bdy    ! BDY boundary set
+      !!----------------------------------------------------------------------
       CALL lbc_lnk_3d( pt3d, cd_type, psgn)
-      !
    END SUBROUTINE lbc_bdy_lnk_3d
 
 
    SUBROUTINE lbc_bdy_lnk_2d( pt2d, cd_type, psgn, ib_bdy )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE lbc_bdy_lnk  ***
-      !!
-      !! ** Purpose :   wrapper rountine to 'lbc_lnk_3d'. This wrapper is used
-      !!              to maintain the same interface with regards to the mpp case
-      !!
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d      ! 3D array on which the lbc is applied
-      REAL(wp)                    , INTENT(in   ) ::   psgn      ! control of the sign 
-      INTEGER                     , INTENT(in   ) ::   ib_bdy    ! BDY boundary set
-      !!----------------------------------------------------------------------
-      !
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pt2d      ! 3D array on which the lbc is applied
+      CHARACTER(len=1)        , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
+      REAL(wp)                , INTENT(in   ) ::   psgn      ! sign used across north fold 
+      INTEGER                 , INTENT(in   ) ::   ib_bdy    ! BDY boundary set
+      !!----------------------------------------------------------------------
       CALL lbc_lnk_2d( pt2d, cd_type, psgn)
-      !
    END SUBROUTINE lbc_bdy_lnk_2d
 
 
-   SUBROUTINE lbc_lnk_2d_e( pt2d, cd_type, psgn, jpri, jprj )
-      !!---------------------------------------------------------------------
-      !!                 ***  ROUTINE lbc_lnk_2d  ***
-      !!
-      !! ** Purpose :   set lateral boundary conditions on a 2D array (non mpp case)
-      !!                special dummy routine to allow for use of halo indexing in mpp case
-      !!
-      !! ** Method  :   psign = -1 :    change the sign across the north fold
-      !!                      =  1 : no change of the sign across the north fold
-      !!                      =  0 : no change of the sign across the north fold and
-      !!                             strict positivity preserved: use inner row/column
-      !!                             for closed boundaries.
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d      ! 2D array on which the lbc is applied
-      REAL(wp)                    , INTENT(in   ) ::   psgn      ! control of the sign 
-      INTEGER                     , INTENT(in   ) ::   jpri      ! size of extra halo (not needed in non-mpp)
-      INTEGER                     , INTENT(in   ) ::   jprj      ! size of extra halo (not needed in non-mpp)
-      !!----------------------------------------------------------------------
-      !
+!!gm  This routine should be removed with an optional halos size added in argument of generic routines
+
+   SUBROUTINE lbc_lnk_2d_icb( pt2d, cd_type, psgn, ki, kj )
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pt2d      ! 2D array on which the lbc is applied
+      CHARACTER(len=1)        , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
+      REAL(wp)                , INTENT(in   ) ::   psgn      ! sign used across north fold 
+      INTEGER                 , INTENT(in   ) ::   ki, kj    ! sizes of extra halo (not needed in non-mpp)
+      !!----------------------------------------------------------------------
       CALL lbc_lnk_2d( pt2d, cd_type, psgn )
-      !    
-   END SUBROUTINE lbc_lnk_2d_e
+   END SUBROUTINE lbc_lnk_2d_icb
+!!gm end
 
 #endif
 
    !!======================================================================
+   !!   identical routines in both distributed and shared memory computing
+   !!======================================================================
+
+   !!----------------------------------------------------------------------
+   !!                   ***   load_ptr_(2,3,4)d   ***
+   !!
+   !!   * Dummy Argument :
+   !!       in    ==>   ptab       ! array to be loaded (2D, 3D or 4D)
+   !!                   cd_nat     ! nature of pt2d array grid-points
+   !!                   psgn       ! sign used across the north fold boundary
+   !!       inout <=>   ptab_ptr   ! array of 2D, 3D or 4D pointers
+   !!                   cdna_ptr   ! nature of ptab array grid-points
+   !!                   psgn_ptr   ! sign used across the north fold boundary
+   !!                   kfld       ! number of elements that has been attributed
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!                  ***   lbc_lnk_(2,3,4)d_multi   ***
+   !!                     ***   load_ptr_(2,3,4)d   ***
+   !!
+   !!   * Argument : dummy argument use in lbc_lnk_multi_... routines
+   !!
+   !!----------------------------------------------------------------------
+
+#  define DIM_2d
+#     define ROUTINE_MULTI          lbc_lnk_2d_multi
+#     define ROUTINE_LOAD           load_ptr_2d
+#     include "lbc_lnk_multi_generic.h90"
+#     undef ROUTINE_MULTI
+#     undef ROUTINE_LOAD
+#  undef DIM_2d
+
+
+#  define DIM_3d
+#     define ROUTINE_MULTI          lbc_lnk_3d_multi
+#     define ROUTINE_LOAD           load_ptr_3d
+#     include "lbc_lnk_multi_generic.h90"
+#     undef ROUTINE_MULTI
+#     undef ROUTINE_LOAD
+#  undef DIM_3d
+
+
+#  define DIM_4d
+#     define ROUTINE_MULTI          lbc_lnk_4d_multi
+#     define ROUTINE_LOAD           load_ptr_4d
+#     include "lbc_lnk_multi_generic.h90"
+#     undef ROUTINE_MULTI
+#     undef ROUTINE_LOAD
+#  undef DIM_4d
+
+   !!======================================================================
 END MODULE lbclnk
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbcnfd.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbcnfd.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lbcnfd.F90	(revision 9019)
@@ -5,5 +5,6 @@
    !!======================================================================
    !! History :  3.2  ! 2009-03  (R. Benshila)  Original code 
-   !!            3.5  ! 2013-07 (I. Epicoco, S. Mocavero - CMCC) MPP optimization 
+   !!            3.5  ! 2013-07  (I. Epicoco, S. Mocavero - CMCC) MPP optimization
+   !!            4.0  ! 2017-04  (G. Madec) automatique allocation of array argument (use any 3rd dimension)
    !!----------------------------------------------------------------------
 
@@ -12,6 +13,8 @@
    !!   lbc_nfd_3d    : lateral boundary condition: North fold treatment for a 3D arrays   (lbc_nfd)
    !!   lbc_nfd_2d    : lateral boundary condition: North fold treatment for a 2D arrays   (lbc_nfd)
-   !!   mpp_lbc_nfd_3d    : North fold treatment for a 3D arrays optimized for MPP
-   !!   mpp_lbc_nfd_2d    : North fold treatment for a 2D arrays optimized for MPP
+   !!   lbc_nfd_nogather       : generic interface for lbc_nfd_nogather_3d and 
+   !!                            lbc_nfd_nogather_2d routines (designed for use
+   !!                            with ln_nnogather to avoid global width arrays
+   !!                            mpi all gather operations)
    !!----------------------------------------------------------------------
    USE dom_oce        ! ocean space and time domain 
@@ -22,13 +25,29 @@
 
    INTERFACE lbc_nfd
-      MODULE PROCEDURE   lbc_nfd_3d, lbc_nfd_2d
+      MODULE PROCEDURE   lbc_nfd_2d    , lbc_nfd_3d    , lbc_nfd_4d
+      MODULE PROCEDURE   lbc_nfd_2d_ptr, lbc_nfd_3d_ptr, lbc_nfd_4d_ptr
+      MODULE PROCEDURE   lbc_nfd_2d_ext
    END INTERFACE
    !
-   INTERFACE mpp_lbc_nfd
-      MODULE PROCEDURE   mpp_lbc_nfd_3d, mpp_lbc_nfd_2d
+   INTERFACE lbc_nfd_nogather
+!                        ! Currently only 4d array version is needed
+!     MODULE PROCEDURE   lbc_nfd_nogather_2d    , lbc_nfd_nogather_3d
+      MODULE PROCEDURE   lbc_nfd_nogather_4d
+!     MODULE PROCEDURE   lbc_nfd_nogather_2d_ptr, lbc_nfd_nogather_3d_ptr
+!     MODULE PROCEDURE   lbc_nfd_nogather_4d_ptr
    END INTERFACE
 
-   PUBLIC   lbc_nfd       ! north fold conditions
-   PUBLIC   mpp_lbc_nfd   ! north fold conditions (parallel case)
+   TYPE, PUBLIC ::   PTR_2D   !: array of 2D pointers (also used in lib_mpp)
+      REAL(wp), DIMENSION (:,:)    , POINTER ::   pt2d
+   END TYPE PTR_2D
+   TYPE, PUBLIC ::   PTR_3D   !: array of 3D pointers (also used in lib_mpp)
+      REAL(wp), DIMENSION (:,:,:)  , POINTER ::   pt3d
+   END TYPE PTR_3D
+   TYPE, PUBLIC ::   PTR_4D   !: array of 4D pointers (also used in lib_mpp)
+      REAL(wp), DIMENSION (:,:,:,:), POINTER ::   pt4d
+   END TYPE PTR_4D
+
+   PUBLIC   lbc_nfd            ! north fold conditions
+   PUBLIC   lbc_nfd_nogather   ! north fold conditions (no allgather case)
 
    INTEGER, PUBLIC, PARAMETER            ::   jpmaxngh = 3               !:
@@ -43,928 +62,106 @@
 CONTAINS
 
-   SUBROUTINE lbc_nfd_3d( pt3d, cd_type, psgn )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine lbc_nfd_3d  ***
-      !!
-      !! ** Purpose :   3D lateral boundary condition : North fold treatment
-      !!              without processor exchanges. 
-      !!
-      !! ** Method  :   
-      !!
-      !! ** Action  :   pt3d with updated values along the north fold
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)          , INTENT(in   ) ::   cd_type   ! define the nature of ptab array grid-points
-      !                                                        !   = T , U , V , F , W points
-      REAL(wp)                  , INTENT(in   ) ::   psgn      ! control of the sign change
-      !                                                        !   = -1. , the sign is changed if north fold boundary
-      !                                                        !   =  1. , the sign is kept  if north fold boundary
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pt3d      ! 3D array on which the boundary condition is applied
-      !
-      INTEGER  ::   ji, jk
-      INTEGER  ::   ijt, iju, ijpj, ijpjm1
-      !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!                   ***  routine lbc_nfd_(2,3,4)d  ***
+   !!----------------------------------------------------------------------
+   !!
+   !! ** Purpose :   lateral boundary condition 
+   !!                North fold treatment without processor exchanges. 
+   !!
+   !! ** Method  :   
+   !!
+   !! ** Action  :   ptab with updated values along the north fold
+   !!----------------------------------------------------------------------
+   !
+   !                       !==  2D array and array of 2D pointer  ==!
+   !
+#  define DIM_2d
+#     define ROUTINE_NFD           lbc_nfd_2d
+#     include "lbc_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     define MULTI
+#     define ROUTINE_NFD           lbc_nfd_2d_ptr
+#     include "lbc_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     undef MULTI
+#  undef DIM_2d
+   !
+   !                       !==  2D array with extra haloes  ==!
+   !
+#  define DIM_2d
+#     define ROUTINE_NFD           lbc_nfd_2d_ext
+#     include "lbc_nfd_ext_generic.h90"
+#     undef ROUTINE_NFD
+#  undef DIM_2d
+   !
+   !                       !==  3D array and array of 3D pointer  ==!
+   !
+#  define DIM_3d
+#     define ROUTINE_NFD           lbc_nfd_3d
+#     include "lbc_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     define MULTI
+#     define ROUTINE_NFD           lbc_nfd_3d_ptr
+#     include "lbc_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     undef MULTI
+#  undef DIM_3d
+   !
+   !                       !==  4D array and array of 4D pointer  ==!
+   !
+#  define DIM_4d
+#     define ROUTINE_NFD           lbc_nfd_4d
+#     include "lbc_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     define MULTI
+#     define ROUTINE_NFD           lbc_nfd_4d_ptr
+#     include "lbc_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     undef MULTI
+#  undef DIM_4d
+   !
+   !  lbc_nfd_nogather routines
+   !
+   !                       !==  2D array and array of 2D pointer  ==!
+   !
+!#  define DIM_2d
+!#     define ROUTINE_NFD           lbc_nfd_nogather_2d
+!#     include "lbc_nfd_nogather_generic.h90"
+!#     undef ROUTINE_NFD
+!#     define MULTI
+!#     define ROUTINE_NFD           lbc_nfd_nogather_2d_ptr
+!#     include "lbc_nfd_nogather_generic.h90"
+!#     undef ROUTINE_NFD
+!#     undef MULTI
+!#  undef DIM_2d
+   !
+   !                       !==  3D array and array of 3D pointer  ==!
+   !
+!#  define DIM_3d
+!#     define ROUTINE_NFD           lbc_nfd_nogather_3d
+!#     include "lbc_nfd_nogather_generic.h90"
+!#     undef ROUTINE_NFD
+!#     define MULTI
+!#     define ROUTINE_NFD           lbc_nfd_nogather_3d_ptr
+!#     include "lbc_nfd_nogather_generic.h90"
+!#     undef ROUTINE_NFD
+!#     undef MULTI
+!#  undef DIM_3d
+   !
+   !                       !==  4D array and array of 4D pointer  ==!
+   !
+#  define DIM_4d
+#     define ROUTINE_NFD           lbc_nfd_nogather_4d
+#     include "lbc_nfd_nogather_generic.h90"
+#     undef ROUTINE_NFD
+!#     define MULTI
+!#     define ROUTINE_NFD           lbc_nfd_nogather_4d_ptr
+!#     include "lbc_nfd_nogather_generic.h90"
+!#     undef ROUTINE_NFD
+!#     undef MULTI
+#  undef DIM_4d
 
-      SELECT CASE ( jpni )
-      CASE ( 1 )     ;   ijpj = nlcj      ! 1 proc only  along the i-direction
-      CASE DEFAULT   ;   ijpj = 4         ! several proc along the i-direction
-      END SELECT
-      ijpjm1 = ijpj-1
+   !!----------------------------------------------------------------------
 
-      DO jk = 1, jpk
-         !
-         SELECT CASE ( npolj )
-         !
-         CASE ( 3 , 4 )                        ! *  North fold  T-point pivot
-            !
-            SELECT CASE ( cd_type )
-            CASE ( 'T' , 'W' )                         ! T-, W-point
-               DO ji = 2, jpiglo
-                  ijt = jpiglo-ji+2
-                  pt3d(ji,ijpj,jk) = psgn * pt3d(ijt,ijpj-2,jk)
-               END DO
-               pt3d(1,ijpj,jk) = psgn * pt3d(3,ijpj-2,jk)
-               DO ji = jpiglo/2+1, jpiglo
-                  ijt = jpiglo-ji+2
-                  pt3d(ji,ijpjm1,jk) = psgn * pt3d(ijt,ijpjm1,jk)
-               END DO
-            CASE ( 'U' )                               ! U-point
-               DO ji = 1, jpiglo-1
-                  iju = jpiglo-ji+1
-                  pt3d(ji,ijpj,jk) = psgn * pt3d(iju,ijpj-2,jk)
-               END DO
-               pt3d(   1  ,ijpj,jk) = psgn * pt3d(    2   ,ijpj-2,jk)
-               pt3d(jpiglo,ijpj,jk) = psgn * pt3d(jpiglo-1,ijpj-2,jk) 
-               DO ji = jpiglo/2, jpiglo-1
-                  iju = jpiglo-ji+1
-                  pt3d(ji,ijpjm1,jk) = psgn * pt3d(iju,ijpjm1,jk)
-               END DO
-            CASE ( 'V' )                               ! V-point
-               DO ji = 2, jpiglo
-                  ijt = jpiglo-ji+2
-                  pt3d(ji,ijpj-1,jk) = psgn * pt3d(ijt,ijpj-2,jk)
-                  pt3d(ji,ijpj  ,jk) = psgn * pt3d(ijt,ijpj-3,jk)
-               END DO
-               pt3d(1,ijpj,jk) = psgn * pt3d(3,ijpj-3,jk) 
-            CASE ( 'F' )                               ! F-point
-               DO ji = 1, jpiglo-1
-                  iju = jpiglo-ji+1
-                  pt3d(ji,ijpj-1,jk) = psgn * pt3d(iju,ijpj-2,jk)
-                  pt3d(ji,ijpj  ,jk) = psgn * pt3d(iju,ijpj-3,jk)
-               END DO
-               pt3d(   1  ,ijpj,jk) = psgn * pt3d(    2   ,ijpj-3,jk)
-               pt3d(jpiglo,ijpj,jk) = psgn * pt3d(jpiglo-1,ijpj-3,jk) 
-            END SELECT
-            !
-         CASE ( 5 , 6 )                        ! *  North fold  F-point pivot
-            !
-            SELECT CASE ( cd_type )
-            CASE ( 'T' , 'W' )                         ! T-, W-point
-               DO ji = 1, jpiglo
-                  ijt = jpiglo-ji+1
-                  pt3d(ji,ijpj,jk) = psgn * pt3d(ijt,ijpj-1,jk)
-               END DO
-            CASE ( 'U' )                               ! U-point
-               DO ji = 1, jpiglo-1
-                  iju = jpiglo-ji
-                  pt3d(ji,ijpj,jk) = psgn * pt3d(iju,ijpj-1,jk)
-               END DO
-               pt3d(jpiglo,ijpj,jk) = psgn * pt3d(1,ijpj-1,jk)
-            CASE ( 'V' )                               ! V-point
-               DO ji = 1, jpiglo
-                  ijt = jpiglo-ji+1
-                  pt3d(ji,ijpj,jk) = psgn * pt3d(ijt,ijpj-2,jk)
-               END DO
-               DO ji = jpiglo/2+1, jpiglo
-                  ijt = jpiglo-ji+1
-                  pt3d(ji,ijpjm1,jk) = psgn * pt3d(ijt,ijpjm1,jk)
-               END DO
-            CASE ( 'F' )                               ! F-point
-               DO ji = 1, jpiglo-1
-                  iju = jpiglo-ji
-                  pt3d(ji,ijpj  ,jk) = psgn * pt3d(iju,ijpj-2,jk)
-               END DO
-               pt3d(jpiglo,ijpj,jk) = psgn * pt3d(1,ijpj-2,jk)
-               DO ji = jpiglo/2+1, jpiglo-1
-                  iju = jpiglo-ji
-                  pt3d(ji,ijpjm1,jk) = psgn * pt3d(iju,ijpjm1,jk)
-               END DO
-            END SELECT
-            !
-         CASE DEFAULT                           ! *  closed : the code probably never go through
-            !
-            SELECT CASE ( cd_type)
-            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
-               pt3d(:, 1  ,jk) = 0.e0
-               pt3d(:,ijpj,jk) = 0.e0
-            CASE ( 'F' )                               ! F-point
-               pt3d(:,ijpj,jk) = 0.e0
-            END SELECT
-            !
-         END SELECT     !  npolj
-         !
-      END DO
-      !
-   END SUBROUTINE lbc_nfd_3d
-
-
-   SUBROUTINE lbc_nfd_2d( pt2d, cd_type, psgn, pr2dj )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine lbc_nfd_2d  ***
-      !!
-      !! ** Purpose :   2D lateral boundary condition : North fold treatment
-      !!       without processor exchanges. 
-      !!
-      !! ** Method  :   
-      !!
-      !! ** Action  :   pt2d with updated values along the north fold
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)        , INTENT(in   ) ::   cd_type   ! define the nature of ptab array grid-points
-      !                                                      ! = T , U , V , F , W points
-      REAL(wp)                , INTENT(in   ) ::   psgn      ! control of the sign change
-      !                                                      !   = -1. , the sign is changed if north fold boundary
-      !                                                      !   =  1. , the sign is kept  if north fold boundary
-      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pt2d      ! 2D array on which the boundary condition is applied
-      INTEGER , OPTIONAL      , INTENT(in   ) ::   pr2dj     ! number of additional halos
-      !
-      INTEGER  ::   ji, jl, ipr2dj
-      INTEGER  ::   ijt, iju, ijpj, ijpjm1
-      !!----------------------------------------------------------------------
-
-      SELECT CASE ( jpni )
-      CASE ( 1 )     ;   ijpj = nlcj      ! 1 proc only  along the i-direction
-      CASE DEFAULT   ;   ijpj = 4         ! several proc along the i-direction
-      END SELECT
-      !
-      IF( PRESENT(pr2dj) ) THEN           ! use of additional halos
-         ipr2dj = pr2dj
-         IF( jpni > 1 )   ijpj = ijpj + ipr2dj
-      ELSE
-         ipr2dj = 0 
-      ENDIF
-      !
-      ijpjm1 = ijpj-1
-
-
-      SELECT CASE ( npolj )
-      !
-      CASE ( 3, 4 )                       ! *  North fold  T-point pivot
-         !
-         SELECT CASE ( cd_type )
-         !
-         CASE ( 'T' , 'W' )                               ! T- , W-points
-            DO jl = 0, ipr2dj
-               DO ji = 2, jpiglo
-                  ijt=jpiglo-ji+2
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(ijt,ijpj-2-jl)
-               END DO
-            END DO
-            pt2d(1,ijpj)   = psgn * pt2d(3,ijpj-2)
-            DO ji = jpiglo/2+1, jpiglo
-               ijt=jpiglo-ji+2
-               pt2d(ji,ijpj-1) = psgn * pt2d(ijt,ijpj-1)
-            END DO
-         CASE ( 'U' )                                     ! U-point
-            DO jl = 0, ipr2dj
-               DO ji = 1, jpiglo-1
-                  iju = jpiglo-ji+1
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(iju,ijpj-2-jl)
-               END DO
-            END DO
-            pt2d(   1  ,ijpj  ) = psgn * pt2d(    2   ,ijpj-2)
-            pt2d(jpiglo,ijpj  ) = psgn * pt2d(jpiglo-1,ijpj-2)
-            pt2d(1     ,ijpj-1) = psgn * pt2d(jpiglo  ,ijpj-1)   
-            DO ji = jpiglo/2, jpiglo-1
-               iju = jpiglo-ji+1
-               pt2d(ji,ijpjm1) = psgn * pt2d(iju,ijpjm1)
-            END DO
-         CASE ( 'V' )                                     ! V-point
-            DO jl = -1, ipr2dj
-               DO ji = 2, jpiglo
-                  ijt = jpiglo-ji+2
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(ijt,ijpj-3-jl)
-               END DO
-            END DO
-            pt2d( 1 ,ijpj)   = psgn * pt2d( 3 ,ijpj-3) 
-         CASE ( 'F' )                                     ! F-point
-            DO jl = -1, ipr2dj
-               DO ji = 1, jpiglo-1
-                  iju = jpiglo-ji+1
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(iju,ijpj-3-jl)
-               END DO
-            END DO
-            pt2d(   1  ,ijpj)   = psgn * pt2d(    2   ,ijpj-3)
-            pt2d(jpiglo,ijpj)   = psgn * pt2d(jpiglo-1,ijpj-3)
-            pt2d(jpiglo,ijpj-1) = psgn * pt2d(jpiglo-1,ijpj-2)      
-            pt2d(   1  ,ijpj-1) = psgn * pt2d(    2   ,ijpj-2)      
-         CASE ( 'I' )                                     ! ice U-V point (I-point)
-            DO jl = 0, ipr2dj
-               pt2d(2,ijpj+jl) = psgn * pt2d(3,ijpj-1+jl)
-               DO ji = 3, jpiglo
-                  iju = jpiglo - ji + 3
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(iju,ijpj-1-jl)
-               END DO
-            END DO
-         CASE ( 'J' )                                     ! first ice U-V point
-            DO jl =0, ipr2dj
-               pt2d(2,ijpj+jl) = psgn * pt2d(3,ijpj-1+jl)
-               DO ji = 3, jpiglo
-                  iju = jpiglo - ji + 3
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(iju,ijpj-1-jl)
-               END DO
-            END DO
-         CASE ( 'K' )                                     ! second ice U-V point
-            DO jl =0, ipr2dj
-               pt2d(2,ijpj+jl) = psgn * pt2d(3,ijpj-1+jl)
-               DO ji = 3, jpiglo
-                  iju = jpiglo - ji + 3
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(iju,ijpj-1-jl)
-               END DO
-            END DO
-         END SELECT
-         !
-      CASE ( 5, 6 )                        ! *  North fold  F-point pivot
-         !
-         SELECT CASE ( cd_type )
-         CASE ( 'T' , 'W' )                               ! T-, W-point
-            DO jl = 0, ipr2dj
-               DO ji = 1, jpiglo
-                  ijt = jpiglo-ji+1
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(ijt,ijpj-1-jl)
-               END DO
-            END DO
-         CASE ( 'U' )                                     ! U-point
-            DO jl = 0, ipr2dj
-               DO ji = 1, jpiglo-1
-                  iju = jpiglo-ji
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(iju,ijpj-1-jl)
-               END DO
-            END DO
-            pt2d(jpiglo,ijpj) = psgn * pt2d(1,ijpj-1)
-         CASE ( 'V' )                                     ! V-point
-            DO jl = 0, ipr2dj
-               DO ji = 1, jpiglo
-                  ijt = jpiglo-ji+1
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(ijt,ijpj-2-jl)
-               END DO
-            END DO
-            DO ji = jpiglo/2+1, jpiglo
-               ijt = jpiglo-ji+1
-               pt2d(ji,ijpjm1) = psgn * pt2d(ijt,ijpjm1)
-            END DO
-         CASE ( 'F' )                               ! F-point
-            DO jl = 0, ipr2dj
-               DO ji = 1, jpiglo-1
-                  iju = jpiglo-ji
-                  pt2d(ji,ijpj+jl) = psgn * pt2d(iju,ijpj-2-jl)
-               END DO
-            END DO
-            pt2d(jpiglo,ijpj) = psgn * pt2d(1,ijpj-2)
-            DO ji = jpiglo/2+1, jpiglo-1
-               iju = jpiglo-ji
-               pt2d(ji,ijpjm1) = psgn * pt2d(iju,ijpjm1)
-            END DO
-         CASE ( 'I' )                                  ! ice U-V point (I-point)
-            pt2d( 2 ,ijpj:ijpj+ipr2dj) = 0.e0
-            DO jl = 0, ipr2dj
-               DO ji = 2 , jpiglo-1
-                  ijt = jpiglo - ji + 2
-                  pt2d(ji,ijpj+jl)= 0.5 * ( pt2d(ji,ijpj-1-jl) + psgn * pt2d(ijt,ijpj-1-jl) )
-               END DO
-            END DO
-         CASE ( 'J' )                                  ! first ice U-V point
-            pt2d( 2 ,ijpj:ijpj+ipr2dj) = 0.e0
-            DO jl = 0, ipr2dj
-               DO ji = 2 , jpiglo-1
-                  ijt = jpiglo - ji + 2
-                  pt2d(ji,ijpj+jl)= pt2d(ji,ijpj-1-jl)
-               END DO
-            END DO
-         CASE ( 'K' )                                  ! second ice U-V point
-            pt2d( 2 ,ijpj:ijpj+ipr2dj) = 0.e0
-            DO jl = 0, ipr2dj
-               DO ji = 2 , jpiglo-1
-                  ijt = jpiglo - ji + 2
-                  pt2d(ji,ijpj+jl)= pt2d(ijt,ijpj-1-jl)
-               END DO
-            END DO
-         END SELECT
-         !
-      CASE DEFAULT                           ! *  closed : the code probably never go through
-         !
-         SELECT CASE ( cd_type)
-         CASE ( 'T' , 'U' , 'V' , 'W' )                 ! T-, U-, V-, W-points
-            pt2d(:, 1:1-ipr2dj     ) = 0.e0
-            pt2d(:,ijpj:ijpj+ipr2dj) = 0.e0
-         CASE ( 'F' )                                   ! F-point
-            pt2d(:,ijpj:ijpj+ipr2dj) = 0.e0
-         CASE ( 'I' )                                   ! ice U-V point
-            pt2d(:, 1:1-ipr2dj     ) = 0.e0
-            pt2d(:,ijpj:ijpj+ipr2dj) = 0.e0
-         CASE ( 'J' )                                   ! first ice U-V point
-            pt2d(:, 1:1-ipr2dj     ) = 0.e0
-            pt2d(:,ijpj:ijpj+ipr2dj) = 0.e0
-         CASE ( 'K' )                                   ! second ice U-V point
-            pt2d(:, 1:1-ipr2dj     ) = 0.e0
-            pt2d(:,ijpj:ijpj+ipr2dj) = 0.e0
-         END SELECT
-         !
-      END SELECT
-      !
-   END SUBROUTINE lbc_nfd_2d
-
-
-   SUBROUTINE mpp_lbc_nfd_3d( pt3dl, pt3dr, cd_type, psgn )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lbc_nfd_3d  ***
-      !!
-      !! ** Purpose :   3D lateral boundary condition : North fold treatment
-      !!              without processor exchanges. 
-      !!
-      !! ** Method  :   
-      !!
-      !! ** Action  :   pt3d with updated values along the north fold
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)          , INTENT(in   ) ::   cd_type   ! define the nature of ptab array grid-points
-      !                                                        !   = T , U , V , F , W points
-      REAL(wp)                  , INTENT(in   ) ::   psgn      ! control of the sign change
-      !                                                        !   = -1. , the sign is changed if north fold boundary
-      !                                                        !   =  1. , the sign is kept    if north fold boundary
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pt3dl     ! 3D array on which the boundary condition is applied
-      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pt3dr     ! 3D array on which the boundary condition is applied
-      !
-      INTEGER  ::   ji, jk
-      INTEGER  ::   ijt, iju, ijpj, ijpjm1, ijta, ijua, jia, startloop, endloop
-      !!----------------------------------------------------------------------
-      !
-      SELECT CASE ( jpni )
-      CASE ( 1 )     ;   ijpj = nlcj      ! 1 proc only  along the i-direction
-      CASE DEFAULT   ;   ijpj = 4         ! several proc along the i-direction
-      END SELECT
-      ijpjm1 = ijpj-1
-
-         !
-         SELECT CASE ( npolj )
-         !
-         CASE ( 3 , 4 )                        ! *  North fold  T-point pivot
-            !
-            SELECT CASE ( cd_type )
-            CASE ( 'T' , 'W' )                         ! T-, W-point
-               IF (nimpp .ne. 1) THEN
-                 startloop = 1
-               ELSE
-                 startloop = 2
-               ENDIF
-
-               DO jk = 1, jpk
-                  DO ji = startloop, nlci
-                     ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
-                     pt3dl(ji,ijpj,jk) = psgn * pt3dr(ijt,ijpj-2,jk)
-                  END DO
-                  IF(nimpp .eq. 1) THEN
-                     pt3dl(1,ijpj,jk) = psgn * pt3dl(3,ijpj-2,jk)
-                  ENDIF
-               END DO
-
-               IF(nimpp .ge. (jpiglo/2+1)) THEN
-                 startloop = 1
-               ELSEIF(((nimpp+nlci-1) .ge. (jpiglo/2+1)) .AND. (nimpp .lt. (jpiglo/2+1))) THEN
-                 startloop = jpiglo/2+1 - nimpp + 1
-               ELSE
-                 startloop = nlci + 1
-               ENDIF
-               IF(startloop .le. nlci) THEN
-                 DO jk = 1, jpk
-                    DO ji = startloop, nlci
-                       ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
-                       jia = ji + nimpp - 1
-                       ijta = jpiglo - jia + 2
-                       IF((ijta .ge. (startloop + nimpp - 1)) .and. (ijta .lt. jia)) THEN
-                          pt3dl(ji,ijpjm1,jk) = psgn * pt3dl(ijta-nimpp+1,ijpjm1,jk)
-                       ELSE
-                          pt3dl(ji,ijpjm1,jk) = psgn * pt3dr(ijt,ijpjm1,jk)
-                       ENDIF
-                    END DO
-                 END DO
-               ENDIF
-
-
-            CASE ( 'U' )                               ! U-point
-               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
-                  endloop = nlci
-               ELSE
-                  endloop = nlci - 1
-               ENDIF
-               DO jk = 1, jpk
-                  DO ji = 1, endloop
-                     iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
-                     pt3dl(ji,ijpj,jk) = psgn * pt3dr(iju,ijpj-2,jk)
-                  END DO
-                  IF(nimpp .eq. 1) THEN
-                     pt3dl(   1  ,ijpj,jk) = psgn * pt3dl(    2   ,ijpj-2,jk)
-                  ENDIF
-                  IF((nimpp + nlci - 1) .eq. jpiglo) THEN
-                     pt3dl(nlci,ijpj,jk) = psgn * pt3dl(nlci-1,ijpj-2,jk)
-                  ENDIF
-               END DO
-
-               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
-                  endloop = nlci
-               ELSE
-                  endloop = nlci - 1
-               ENDIF
-               IF(nimpp .ge. (jpiglo/2)) THEN
-                  startloop = 1
-               ELSEIF(((nimpp+nlci-1) .ge. (jpiglo/2)) .AND. (nimpp .lt. (jpiglo/2))) THEN
-                  startloop = jpiglo/2 - nimpp + 1
-               ELSE
-                  startloop = endloop + 1
-               ENDIF
-               IF (startloop .le. endloop) THEN
-                 DO jk = 1, jpk
-                    DO ji = startloop, endloop
-                      iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
-                      jia = ji + nimpp - 1
-                      ijua = jpiglo - jia + 1
-                      IF((ijua .ge. (startloop + nimpp - 1)) .and. (ijua .lt. jia)) THEN
-                        pt3dl(ji,ijpjm1,jk) = psgn * pt3dl(ijua-nimpp+1,ijpjm1,jk)
-                      ELSE
-                        pt3dl(ji,ijpjm1,jk) = psgn * pt3dr(iju,ijpjm1,jk)
-                      ENDIF
-                    END DO
-                 END DO
-               ENDIF
-
-            CASE ( 'V' )                               ! V-point
-               IF (nimpp .ne. 1) THEN
-                  startloop = 1
-               ELSE
-                  startloop = 2
-               ENDIF
-               DO jk = 1, jpk
-                  DO ji = startloop, nlci
-                     ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
-                     pt3dl(ji,ijpj-1,jk) = psgn * pt3dr(ijt,ijpj-2,jk)
-                     pt3dl(ji,ijpj  ,jk) = psgn * pt3dr(ijt,ijpj-3,jk)
-                  END DO
-                  IF(nimpp .eq. 1) THEN
-                     pt3dl(1,ijpj,jk) = psgn * pt3dl(3,ijpj-3,jk)
-                  ENDIF
-               END DO
-            CASE ( 'F' )                               ! F-point
-               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
-                  endloop = nlci
-               ELSE
-                  endloop = nlci - 1
-               ENDIF
-               DO jk = 1, jpk
-                  DO ji = 1, endloop
-                     iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
-                     pt3dl(ji,ijpj-1,jk) = psgn * pt3dr(iju,ijpj-2,jk)
-                     pt3dl(ji,ijpj  ,jk) = psgn * pt3dr(iju,ijpj-3,jk)
-                  END DO
-                  IF(nimpp .eq. 1) THEN
-                     pt3dl(   1  ,ijpj,jk) = psgn * pt3dl(    2   ,ijpj-3,jk)
-                  ENDIF
-                  IF((nimpp + nlci - 1) .eq. jpiglo) THEN
-                     pt3dl(nlci,ijpj,jk) = psgn * pt3dl(nlci-1,ijpj-3,jk)
-                  ENDIF
-               END DO
-            END SELECT
-            !
-
-         CASE ( 5 , 6 )                        ! *  North fold  F-point pivot
-            !
-            SELECT CASE ( cd_type )
-            CASE ( 'T' , 'W' )                         ! T-, W-point
-               DO jk = 1, jpk
-                  DO ji = 1, nlci
-                     ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
-                     pt3dl(ji,ijpj,jk) = psgn * pt3dr(ijt,ijpj-1,jk)
-                  END DO
-               END DO
-
-            CASE ( 'U' )                               ! U-point
-               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
-                  endloop = nlci
-               ELSE
-                  endloop = nlci - 1
-               ENDIF
-               DO jk = 1, jpk
-                  DO ji = 1, endloop
-                     iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 2
-                     pt3dl(ji,ijpj,jk) = psgn * pt3dr(iju,ijpj-1,jk)
-                  END DO
-                  IF((nimpp + nlci - 1) .eq. jpiglo) THEN
-                     pt3dl(nlci,ijpj,jk) = psgn * pt3dr(1,ijpj-1,jk)
-                  ENDIF
-               END DO
-
-            CASE ( 'V' )                               ! V-point
-               DO jk = 1, jpk
-                  DO ji = 1, nlci
-                     ijt = jpiglo - ji- nimpp - nfiimpp(isendto(1),jpnj) + 3
-                     pt3dl(ji,ijpj,jk) = psgn * pt3dr(ijt,ijpj-2,jk)
-                  END DO
-               END DO
-
-               IF(nimpp .ge. (jpiglo/2+1)) THEN
-                  startloop = 1
-               ELSEIF(((nimpp+nlci-1) .ge. (jpiglo/2+1)) .AND. (nimpp .lt. (jpiglo/2+1))) THEN
-                  startloop = jpiglo/2+1 - nimpp + 1
-               ELSE
-                  startloop = nlci + 1
-               ENDIF
-               IF(startloop .le. nlci) THEN
-                 DO jk = 1, jpk
-                    DO ji = startloop, nlci
-                       ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
-                       pt3dl(ji,ijpjm1,jk) = psgn * pt3dr(ijt,ijpjm1,jk)
-                    END DO
-                 END DO
-               ENDIF
-
-            CASE ( 'F' )                               ! F-point
-               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
-                  endloop = nlci
-               ELSE
-                  endloop = nlci - 1
-               ENDIF
-               DO jk = 1, jpk
-                  DO ji = 1, endloop
-                     iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 2
-                     pt3dl(ji,ijpj ,jk) = psgn * pt3dr(iju,ijpj-2,jk)
-                  END DO
-                  IF((nimpp + nlci - 1) .eq. jpiglo) THEN
-                     pt3dl(nlci,ijpj,jk) = psgn * pt3dr(1,ijpj-2,jk)
-                  ENDIF
-               END DO
-
-               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
-                  endloop = nlci
-               ELSE
-                  endloop = nlci - 1
-               ENDIF
-               IF(nimpp .ge. (jpiglo/2+1)) THEN
-                  startloop = 1
-               ELSEIF(((nimpp+nlci-1) .ge. (jpiglo/2+1)) .AND. (nimpp .lt. (jpiglo/2+1))) THEN
-                  startloop = jpiglo/2+1 - nimpp + 1
-               ELSE
-                  startloop = endloop + 1
-               ENDIF
-               IF (startloop .le. endloop) THEN
-                  DO jk = 1, jpk
-                     DO ji = startloop, endloop
-                        iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 2
-                        pt3dl(ji,ijpjm1,jk) = psgn * pt3dr(iju,ijpjm1,jk)
-                     END DO
-                  END DO
-               ENDIF
-
-            END SELECT
-
-         CASE DEFAULT                           ! *  closed : the code probably never go through
-            !
-            SELECT CASE ( cd_type)
-            CASE ( 'T' , 'U' , 'V' , 'W' )             ! T-, U-, V-, W-points
-               pt3dl(:, 1  ,jk) = 0.e0
-               pt3dl(:,ijpj,jk) = 0.e0
-            CASE ( 'F' )                               ! F-point
-               pt3dl(:,ijpj,jk) = 0.e0
-            END SELECT
-            !
-         END SELECT     !  npolj
-         !
-      !
-   END SUBROUTINE mpp_lbc_nfd_3d
-
-
-   SUBROUTINE mpp_lbc_nfd_2d( pt2dl, pt2dr, cd_type, psgn )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lbc_nfd_2d  ***
-      !!
-      !! ** Purpose :   2D lateral boundary condition : North fold treatment
-      !!       without processor exchanges. 
-      !!
-      !! ** Method  :   
-      !!
-      !! ** Action  :   pt2d with updated values along the north fold
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)        , INTENT(in   ) ::   cd_type   ! define the nature of ptab array grid-points
-      !                                                      ! = T , U , V , F , W points
-      REAL(wp)                , INTENT(in   ) ::   psgn      ! control of the sign change
-      !                                                      !   = -1. , the sign is changed if north fold boundary
-      !                                                      !   =  1. , the sign is kept  if north fold boundary
-      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pt2dl     ! 2D array on which the boundary condition is applied
-      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   pt2dr     ! 2D array on which the boundary condition is applied
-      !
-      INTEGER  ::   ji
-      INTEGER  ::   ijt, iju, ijpj, ijpjm1, ijta, ijua, jia, startloop, endloop
-      !!----------------------------------------------------------------------
-
-      SELECT CASE ( jpni )
-      CASE ( 1 )     ;   ijpj = nlcj      ! 1 proc only  along the i-direction
-      CASE DEFAULT   ;   ijpj = 4         ! several proc along the i-direction
-      END SELECT
-      !
-      ijpjm1 = ijpj-1
-
-
-      SELECT CASE ( npolj )
-      !
-      CASE ( 3, 4 )                       ! *  North fold  T-point pivot
-         !
-         SELECT CASE ( cd_type )
-         !
-         CASE ( 'T' , 'W' )                               ! T- , W-points
-            IF (nimpp .ne. 1) THEN
-              startloop = 1
-            ELSE
-              startloop = 2
-            ENDIF
-            DO ji = startloop, nlci
-              ijt=jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
-              pt2dl(ji,ijpj) = psgn * pt2dr(ijt,ijpjm1-1)
-            END DO
-            IF (nimpp .eq. 1) THEN
-              pt2dl(1,ijpj)   = psgn * pt2dl(3,ijpj-2)
-            ENDIF
-
-            IF(nimpp .ge. (jpiglo/2+1)) THEN
-               startloop = 1
-            ELSEIF(((nimpp+nlci-1) .ge. (jpiglo/2+1)) .AND. (nimpp .lt. (jpiglo/2+1))) THEN
-               startloop = jpiglo/2+1 - nimpp + 1
-            ELSE
-               startloop = nlci + 1
-            ENDIF
-            DO ji = startloop, nlci
-               ijt=jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
-               jia = ji + nimpp - 1
-               ijta = jpiglo - jia + 2
-               IF((ijta .ge. (startloop + nimpp - 1)) .and. (ijta .lt. jia)) THEN
-                  pt2dl(ji,ijpjm1) = psgn * pt2dl(ijta-nimpp+1,ijpjm1)
-               ELSE
-                  pt2dl(ji,ijpjm1) = psgn * pt2dr(ijt,ijpjm1)
-               ENDIF
-            END DO
-
-         CASE ( 'U' )                                     ! U-point
-            IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
-               endloop = nlci
-            ELSE
-               endloop = nlci - 1
-            ENDIF
-            DO ji = 1, endloop
-               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
-               pt2dl(ji,ijpj) = psgn * pt2dr(iju,ijpjm1-1)
-            END DO
-
-            IF (nimpp .eq. 1) THEN
-              pt2dl(   1  ,ijpj  ) = psgn * pt2dl(    2   ,ijpj-2)
-              pt2dl(1     ,ijpj-1) = psgn * pt2dr(jpiglo - nfiimpp(isendto(1), jpnj) + 1, ijpj-1)
-            ENDIF
-            IF((nimpp + nlci - 1) .eq. jpiglo) THEN
-              pt2dl(nlci,ijpj  ) = psgn * pt2dl(nlci-1,ijpj-2)
-            ENDIF
-
-            IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
-               endloop = nlci
-            ELSE
-               endloop = nlci - 1
-            ENDIF
-            IF(nimpp .ge. (jpiglo/2)) THEN
-               startloop = 1
-            ELSEIF(((nimpp+nlci-1) .ge. (jpiglo/2)) .AND. (nimpp .lt. (jpiglo/2))) THEN
-               startloop = jpiglo/2 - nimpp + 1
-            ELSE
-               startloop = endloop + 1
-            ENDIF
-            DO ji = startloop, endloop
-               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
-               jia = ji + nimpp - 1
-               ijua = jpiglo - jia + 1
-               IF((ijua .ge. (startloop + nimpp - 1)) .and. (ijua .lt. jia)) THEN
-                  pt2dl(ji,ijpjm1) = psgn * pt2dl(ijua-nimpp+1,ijpjm1)
-               ELSE
-                  pt2dl(ji,ijpjm1) = psgn * pt2dr(iju,ijpjm1)
-               ENDIF
-            END DO
-
-         CASE ( 'V' )                                     ! V-point
-            IF (nimpp .ne. 1) THEN
-              startloop = 1
-            ELSE
-              startloop = 2
-            ENDIF
-            DO ji = startloop, nlci
-              ijt=jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
-              pt2dl(ji,ijpjm1) = psgn * pt2dr(ijt,ijpjm1-1)
-              pt2dl(ji,ijpj) = psgn * pt2dr(ijt,ijpjm1-2)
-            END DO
-            IF (nimpp .eq. 1) THEN
-              pt2dl( 1 ,ijpj)   = psgn * pt2dl( 3 ,ijpj-3) 
-            ENDIF
-
-         CASE ( 'F' )                                     ! F-point
-            IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
-               endloop = nlci
-            ELSE
-               endloop = nlci - 1
-            ENDIF
-            DO ji = 1, endloop
-               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
-               pt2dl(ji,ijpjm1) = psgn * pt2dr(iju,ijpjm1-1)
-               pt2dl(ji,ijpj) = psgn * pt2dr(iju,ijpjm1-2)
-            END DO
-            IF (nimpp .eq. 1) THEN
-              pt2dl(   1  ,ijpj)   = psgn * pt2dl(    2   ,ijpj-3)
-              pt2dl(   1  ,ijpj-1) = psgn * pt2dl(    2   ,ijpj-2)
-            ENDIF
-            IF((nimpp + nlci - 1) .eq. jpiglo) THEN
-              pt2dl(nlci,ijpj)   = psgn * pt2dl(nlci-1,ijpj-3)
-              pt2dl(nlci,ijpj-1) = psgn * pt2dl(nlci-1,ijpj-2) 
-            ENDIF
-
-         CASE ( 'I' )                                     ! ice U-V point (I-point)
-            IF (nimpp .ne. 1) THEN
-               startloop = 1
-            ELSE
-               startloop = 3
-               pt2dl(2,ijpj) = psgn * pt2dr(3,ijpjm1)
-            ENDIF
-            DO ji = startloop, nlci
-               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 5
-               pt2dl(ji,ijpj) = psgn * pt2dr(iju,ijpjm1)
-            END DO
-
-         CASE ( 'J' )                                     ! first ice U-V point
-            IF (nimpp .ne. 1) THEN
-               startloop = 1
-            ELSE
-               startloop = 3
-               pt2dl(2,ijpj) = psgn * pt2dl(3,ijpjm1)
-            ENDIF
-            DO ji = startloop, nlci
-               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 5
-               pt2dl(ji,ijpj) = psgn * pt2dr(iju,ijpjm1)
-            END DO
-
-         CASE ( 'K' )                                     ! second ice U-V point
-            IF (nimpp .ne. 1) THEN
-               startloop = 1
-            ELSE
-               startloop = 3
-               pt2dl(2,ijpj) = psgn * pt2dl(3,ijpjm1)
-            ENDIF
-            DO ji = startloop, nlci
-               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 5
-               pt2dl(ji,ijpj) = psgn * pt2dr(iju,ijpjm1)
-            END DO
-
-         END SELECT
-         !
-      CASE ( 5, 6 )                        ! *  North fold  F-point pivot
-         !
-         SELECT CASE ( cd_type )
-         CASE ( 'T' , 'W' )                               ! T-, W-point
-            DO ji = 1, nlci
-               ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
-               pt2dl(ji,ijpj) = psgn * pt2dr(ijt,ijpjm1)
-            END DO
-
-         CASE ( 'U' )                                     ! U-point
-            IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
-               endloop = nlci
-            ELSE
-               endloop = nlci - 1
-            ENDIF
-            DO ji = 1, endloop
-               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 2
-               pt2dl(ji,ijpj) = psgn * pt2dr(iju,ijpjm1)
-            END DO
-            IF((nimpp + nlci - 1) .eq. jpiglo) THEN
-               pt2dl(nlci,ijpj) = psgn * pt2dr(1,ijpj-1)
-            ENDIF
-
-         CASE ( 'V' )                                     ! V-point
-            DO ji = 1, nlci
-               ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
-               pt2dl(ji,ijpj) = psgn * pt2dr(ijt,ijpjm1-1)
-            END DO
-            IF(nimpp .ge. (jpiglo/2+1)) THEN
-               startloop = 1
-            ELSEIF(((nimpp+nlci-1) .ge. (jpiglo/2+1)) .AND. (nimpp .lt. (jpiglo/2+1))) THEN
-               startloop = jpiglo/2+1 - nimpp + 1
-            ELSE
-               startloop = nlci + 1
-            ENDIF
-            DO ji = startloop, nlci
-               ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 3
-               pt2dl(ji,ijpjm1) = psgn * pt2dr(ijt,ijpjm1)
-            END DO
-
-         CASE ( 'F' )                               ! F-point
-            IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
-               endloop = nlci
-            ELSE
-               endloop = nlci - 1
-            ENDIF
-            DO ji = 1, endloop
-               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 2
-               pt2dl(ji,ijpj) = psgn * pt2dr(iju,ijpjm1-1)
-            END DO
-            IF((nimpp + nlci - 1) .eq. jpiglo) THEN
-                pt2dl(nlci,ijpj) = psgn * pt2dr(1,ijpj-2)
-            ENDIF
-
-            IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
-               endloop = nlci
-            ELSE
-               endloop = nlci - 1
-            ENDIF
-            IF(nimpp .ge. (jpiglo/2+1)) THEN
-               startloop = 1
-            ELSEIF(((nimpp+nlci-1) .ge. (jpiglo/2+1)) .AND. (nimpp .lt. (jpiglo/2+1))) THEN
-               startloop = jpiglo/2+1 - nimpp + 1
-            ELSE
-               startloop = endloop + 1
-            ENDIF
-
-            DO ji = startloop, endloop
-               iju = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 2
-               pt2dl(ji,ijpjm1) = psgn * pt2dr(iju,ijpjm1)
-            END DO
-
-         CASE ( 'I' )                                  ! ice U-V point (I-point)
-               IF (nimpp .ne. 1) THEN
-                  startloop = 1
-               ELSE
-                  startloop = 2
-               ENDIF
-               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
-                  endloop = nlci
-               ELSE
-                  endloop = nlci - 1
-               ENDIF
-               DO ji = startloop , endloop
-                  ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
-                  pt2dl(ji,ijpj)= 0.5 * (pt2dl(ji,ijpjm1) + psgn * pt2dr(ijt,ijpjm1))
-               END DO
-
-         CASE ( 'J' )                                  ! first ice U-V point
-               IF (nimpp .ne. 1) THEN
-                  startloop = 1
-               ELSE
-                  startloop = 2
-               ENDIF
-               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
-                  endloop = nlci
-               ELSE
-                  endloop = nlci - 1
-               ENDIF
-               DO ji = startloop , endloop
-                  ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
-                  pt2dl(ji,ijpj) = pt2dl(ji,ijpjm1)
-               END DO
-
-         CASE ( 'K' )                                  ! second ice U-V point
-               IF (nimpp .ne. 1) THEN
-                  startloop = 1
-               ELSE
-                  startloop = 2
-               ENDIF
-               IF ((nimpp + nlci - 1) .ne. jpiglo) THEN
-                  endloop = nlci
-               ELSE
-                  endloop = nlci - 1
-               ENDIF
-               DO ji = startloop, endloop
-                  ijt = jpiglo - ji - nimpp - nfiimpp(isendto(1),jpnj) + 4
-                  pt2dl(ji,ijpj) = pt2dr(ijt,ijpjm1)
-               END DO
-
-         END SELECT
-         !
-      CASE DEFAULT                           ! *  closed : the code probably never go through
-         !
-         SELECT CASE ( cd_type)
-         CASE ( 'T' , 'U' , 'V' , 'W' )                 ! T-, U-, V-, W-points
-            pt2dl(:, 1     ) = 0.e0
-            pt2dl(:,ijpj) = 0.e0
-         CASE ( 'F' )                                   ! F-point
-            pt2dl(:,ijpj) = 0.e0
-         CASE ( 'I' )                                   ! ice U-V point
-            pt2dl(:, 1     ) = 0.e0
-            pt2dl(:,ijpj) = 0.e0
-         CASE ( 'J' )                                   ! first ice U-V point
-            pt2dl(:, 1     ) = 0.e0
-            pt2dl(:,ijpj) = 0.e0
-         CASE ( 'K' )                                   ! second ice U-V point
-            pt2dl(:, 1     ) = 0.e0
-            pt2dl(:,ijpj) = 0.e0
-         END SELECT
-         !
-      END SELECT
-      !
-   END SUBROUTINE mpp_lbc_nfd_2d
 
    !!======================================================================
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 9019)
@@ -8,5 +8,5 @@
    !!            8.0  !  1998  (M. Imbard, J. Escobar, L. Colombet ) SHMEM and MPI
    !!                 !  1998  (J.M. Molines) Open boundary conditions
-   !!   NEMO     1.0  !  2003  (J.-M. Molines, G. Madec)  F90, free form
+   !!   NEMO     1.0  !  2003  (J.M. Molines, G. Madec)  F90, free form
    !!                 !  2003  (J.M. Molines) add mpp_ini_north(_3d,_2d)
    !!             -   !  2004  (R. Bourdalle Badie)  isend option in mpi
@@ -19,10 +19,10 @@
    !!            3.2  !  2009  (O. Marti)    add mpp_ini_znl
    !!            4.0  !  2011  (G. Madec)  move ctl_ routines from in_out_manager
-   !!            3.5  !  2012  (S.Mocavero, I. Epicoco) Add 'mpp_lnk_bdy_3d', 'mpp_lnk_obc_3d', 
-   !!                          'mpp_lnk_bdy_2d' and 'mpp_lnk_obc_2d' routines and update
-   !!                          the mppobc routine to optimize the BDY and OBC communications
-   !!            3.5  !  2013  ( C. Ethe, G. Madec ) message passing arrays as local variables 
+   !!            3.5  !  2012  (S.Mocavero, I. Epicoco) Add mpp_lnk_bdy_3d/2d routines to optimize the BDY comm.
+   !!            3.5  !  2013  (C. Ethe, G. Madec)  message passing arrays as local variables 
    !!            3.5  !  2013  (S.Mocavero, I.Epicoco - CMCC) north fold optimizations
-   !!            3.6  !  2015 (O. Tintó and M. Castrillo - BSC) Added 'mpp_lnk_2d_multiple', 'mpp_lbc_north_2d_multiple', 'mpp_max_multiple' 
+   !!            3.6  !  2015  (O. Tintó and M. Castrillo - BSC) Added '_multiple' case for 2D lbc and max
+   !!            4.0  !  2017  (G. Madec) automatique allocation of array argument (use any 3rd dimension)
+   !!             -   !  2017  (G. Madec) create generic.h90 files to generate all lbc and north fold routines
    !!----------------------------------------------------------------------
 
@@ -41,9 +41,7 @@
    !!   mynode        : indentify the processor unit
    !!   mpp_lnk       : interface (defined in lbclnk) for message passing of 2d or 3d arrays (mpp_lnk_2d, mpp_lnk_3d)
-   !!   mpp_lnk_3d_gather :  Message passing manadgement for two 3D arrays
-   !!   mpp_lnk_e     : interface (defined in lbclnk) for message passing of 2d array with extra halo (mpp_lnk_2d_e)
    !!   mpp_lnk_icb   : interface for message passing of 2d arrays with extra halo for icebergs (mpp_lnk_2d_icb)
    !!   mpprecv       :
-   !!   mppsend       :   SUBROUTINE mpp_ini_znl
+   !!   mppsend       :
    !!   mppscatter    :
    !!   mppgather     :
@@ -56,7 +54,5 @@
    !!   mppstop       :
    !!   mpp_ini_north : initialisation of north fold
-   !!   mpp_lbc_north : north fold processors gathering
-   !!   mpp_lbc_north_e : variant of mpp_lbc_north for extra outer halo
-   !!   mpp_lbc_north_icb : variant of mpp_lbc_north for extra outer halo with icebergs
+   !!   mpp_lbc_north_icb : alternative to mpp_nfd for extra outer halo with icebergs
    !!----------------------------------------------------------------------
    USE dom_oce        ! ocean space and time domain
@@ -67,13 +63,26 @@
    IMPLICIT NONE
    PRIVATE
-   
+
+   INTERFACE mpp_nfd
+      MODULE PROCEDURE   mpp_nfd_2d      , mpp_nfd_3d      , mpp_nfd_4d
+      MODULE PROCEDURE   mpp_nfd_2d_ptr, mpp_nfd_3d_ptr, mpp_nfd_4d_ptr
+   END INTERFACE
+
+   ! Interface associated to the mpp_lnk_... routines is defined in lbclnk
+   PUBLIC   mpp_lnk_2d      , mpp_lnk_3d      , mpp_lnk_4d
+   PUBLIC   mpp_lnk_2d_ptr, mpp_lnk_3d_ptr, mpp_lnk_4d_ptr
+   !
+!!gm  this should be useless
+   PUBLIC   mpp_nfd_2d    , mpp_nfd_3d    , mpp_nfd_4d
+   PUBLIC   mpp_nfd_2d_ptr, mpp_nfd_3d_ptr, mpp_nfd_4d_ptr
+!!gm end
+   !
    PUBLIC   ctl_stop, ctl_warn, get_unit, ctl_opn, ctl_nam
    PUBLIC   mynode, mppstop, mppsync, mpp_comm_free
-   PUBLIC   mpp_ini_north, mpp_lbc_north, mpp_lbc_north_e
+   PUBLIC   mpp_ini_north
+   PUBLIC   mpp_lnk_2d_icb
+   PUBLIC   mpp_lbc_north_icb
    PUBLIC   mpp_min, mpp_max, mpp_sum, mpp_minloc, mpp_maxloc
    PUBLIC   mpp_max_multiple
-   PUBLIC   mpp_lnk_3d, mpp_lnk_3d_gather, mpp_lnk_2d, mpp_lnk_2d_e
-   PUBLIC   mpp_lnk_2d_9 , mpp_lnk_2d_multiple 
-   PUBLIC   mpp_lnk_sum_3d, mpp_lnk_sum_2d
    PUBLIC   mppscatter, mppgather
    PUBLIC   mpp_ini_ice, mpp_ini_znl
@@ -81,11 +90,5 @@
    PUBLIC   mppsend, mpprecv                          ! needed by TAM and ICB routines
    PUBLIC   mpp_lnk_bdy_2d, mpp_lnk_bdy_3d
-   PUBLIC   mpp_lbc_north_icb, mpp_lnk_2d_icb
    PUBLIC   mpprank
-
-   TYPE arrayptr
-      REAL , DIMENSION (:,:),  POINTER :: pt2d
-   END TYPE arrayptr
-   PUBLIC   arrayptr
    
    !! * Interfaces
@@ -101,8 +104,5 @@
    INTERFACE mpp_sum
       MODULE PROCEDURE mppsum_a_int, mppsum_int, mppsum_a_real, mppsum_real,   &
-                       mppsum_realdd, mppsum_a_realdd
-   END INTERFACE
-   INTERFACE mpp_lbc_north
-      MODULE PROCEDURE mpp_lbc_north_3d, mpp_lbc_north_2d
+         &             mppsum_realdd, mppsum_a_realdd
    END INTERFACE
    INTERFACE mpp_minloc
@@ -112,5 +112,4 @@
       MODULE PROCEDURE mpp_maxloc2d ,mpp_maxloc3d
    END INTERFACE
-
    INTERFACE mpp_max_multiple
       MODULE PROCEDURE mppmax_real_multiple
@@ -138,39 +137,39 @@
    ! variables used in case of sea-ice
    INTEGER, PUBLIC ::   ncomm_ice       !: communicator made by the processors with sea-ice (public so that it can be freed in limthd)
-   INTEGER ::   ngrp_iworld     !  group ID for the world processors (for rheology)
-   INTEGER ::   ngrp_ice        !  group ID for the ice processors (for rheology)
-   INTEGER ::   ndim_rank_ice   !  number of 'ice' processors
-   INTEGER ::   n_ice_root      !  number (in the comm_ice) of proc 0 in the ice comm
+   INTEGER         ::   ngrp_iworld     !  group ID for the world processors (for rheology)
+   INTEGER         ::   ngrp_ice        !  group ID for the ice processors (for rheology)
+   INTEGER         ::   ndim_rank_ice   !  number of 'ice' processors
+   INTEGER         ::   n_ice_root      !  number (in the comm_ice) of proc 0 in the ice comm
    INTEGER, DIMENSION(:), ALLOCATABLE, SAVE ::   nrank_ice     ! dimension ndim_rank_ice
 
    ! variables used for zonal integration
    INTEGER, PUBLIC ::   ncomm_znl       !: communicator made by the processors on the same zonal average
-   LOGICAL, PUBLIC ::   l_znl_root      ! True on the 'left'most processor on the same row
-   INTEGER ::   ngrp_znl        ! group ID for the znl processors
-   INTEGER ::   ndim_rank_znl   ! number of processors on the same zonal average
+   LOGICAL, PUBLIC ::   l_znl_root      !: True on the 'left'most processor on the same row
+   INTEGER         ::   ngrp_znl        !  group ID for the znl processors
+   INTEGER         ::   ndim_rank_znl   !  number of processors on the same zonal average
    INTEGER, DIMENSION(:), ALLOCATABLE, SAVE ::   nrank_znl  ! dimension ndim_rank_znl, number of the procs into the same znl domain
 
    ! North fold condition in mpp_mpi with jpni > 1 (PUBLIC for TAM)
-   INTEGER, PUBLIC ::   ngrp_world        ! group ID for the world processors
-   INTEGER, PUBLIC ::   ngrp_opa          ! group ID for the opa processors
-   INTEGER, PUBLIC ::   ngrp_north        ! group ID for the northern processors (to be fold)
-   INTEGER, PUBLIC ::   ncomm_north       ! communicator made by the processors belonging to ngrp_north
-   INTEGER, PUBLIC ::   ndim_rank_north   ! number of 'sea' processor in the northern line (can be /= jpni !)
-   INTEGER, PUBLIC ::   njmppmax          ! value of njmpp for the processors of the northern line
-   INTEGER, PUBLIC ::   north_root        ! number (in the comm_opa) of proc 0 in the northern comm
-   INTEGER, DIMENSION(:), ALLOCATABLE, SAVE, PUBLIC ::   nrank_north   ! dimension ndim_rank_north
+   INTEGER, PUBLIC ::   ngrp_world        !: group ID for the world processors
+   INTEGER, PUBLIC ::   ngrp_opa          !: group ID for the opa processors
+   INTEGER, PUBLIC ::   ngrp_north        !: group ID for the northern processors (to be fold)
+   INTEGER, PUBLIC ::   ncomm_north       !: communicator made by the processors belonging to ngrp_north
+   INTEGER, PUBLIC ::   ndim_rank_north   !: number of 'sea' processor in the northern line (can be /= jpni !)
+   INTEGER, PUBLIC ::   njmppmax          !: value of njmpp for the processors of the northern line
+   INTEGER, PUBLIC ::   north_root        !: number (in the comm_opa) of proc 0 in the northern comm
+   INTEGER, PUBLIC, DIMENSION(:), ALLOCATABLE, SAVE ::   nrank_north   !: dimension ndim_rank_north
 
    ! Type of send : standard, buffered, immediate
-   CHARACTER(len=1), PUBLIC ::   cn_mpi_send   ! type od mpi send/recieve (S=standard, B=bsend, I=isend)
-   LOGICAL, PUBLIC          ::   l_isend = .FALSE.   ! isend use indicator (T if cn_mpi_send='I')
-   INTEGER, PUBLIC          ::   nn_buffer     ! size of the buffer in case of mpi_bsend
-
-   REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE :: tampon  ! buffer in case of bsend
-
-   LOGICAL, PUBLIC                                  ::   ln_nnogather       ! namelist control of northfold comms
-   LOGICAL, PUBLIC                                  ::   l_north_nogather = .FALSE.  ! internal control of northfold comms
-   INTEGER, PUBLIC                                  ::   ityp
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   CHARACTER(len=1), PUBLIC ::   cn_mpi_send        !: type od mpi send/recieve (S=standard, B=bsend, I=isend)
+   LOGICAL         , PUBLIC ::   l_isend = .FALSE.  !: isend use indicator (T if cn_mpi_send='I')
+   INTEGER         , PUBLIC ::   nn_buffer          !: size of the buffer in case of mpi_bsend
+
+   REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE ::   tampon   ! buffer in case of bsend
+
+   LOGICAL, PUBLIC ::   ln_nnogather                !: namelist control of northfold comms
+   LOGICAL, PUBLIC ::   l_north_nogather = .FALSE.  !: internal control of northfold comms
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -178,6 +177,5 @@
 CONTAINS
 
-
-   FUNCTION mynode( ldtxt, ldname, kumnam_ref , kumnam_cfg , kumond , kstop, localComm )
+   FUNCTION mynode( ldtxt, ldname, kumnam_ref, kumnam_cfg, kumond, kstop, localComm )
       !!----------------------------------------------------------------------
       !!                  ***  routine mynode  ***
@@ -204,18 +202,17 @@
       WRITE(ldtxt(ii),*) '~~~~~~ '                                                        ;   ii = ii + 1
       !
-
       REWIND( kumnam_ref )              ! Namelist nammpp in reference namelist: mpi variables
       READ  ( kumnam_ref, nammpp, IOSTAT = ios, ERR = 901)
 901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammpp in reference namelist', lwp )
-
+      !
       REWIND( kumnam_cfg )              ! Namelist nammpp in configuration namelist: mpi variables
       READ  ( kumnam_cfg, nammpp, IOSTAT = ios, ERR = 902 )
 902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammpp in configuration namelist', lwp )
-
+      !
       !                              ! control print
       WRITE(ldtxt(ii),*) '   Namelist nammpp'                                             ;   ii = ii + 1
       WRITE(ldtxt(ii),*) '      mpi send type          cn_mpi_send = ', cn_mpi_send       ;   ii = ii + 1
       WRITE(ldtxt(ii),*) '      size exported buffer   nn_buffer   = ', nn_buffer,' bytes';   ii = ii + 1
-
+      !
 #if defined key_agrif
       IF( .NOT. Agrif_Root() ) THEN
@@ -225,12 +222,10 @@
       ENDIF
 #endif
-
-      IF(jpnij < 1)THEN
-         ! If jpnij is not specified in namelist then we calculate it - this
-         ! means there will be no land cutting out.
-         jpnij = jpni * jpnj
-      END IF
-
-      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
+      !
+      IF( jpnij < 1 ) THEN         ! If jpnij is not specified in namelist then we calculate it
+         jpnij = jpni * jpnj       ! this means there will be no land cutting out.
+      ENDIF
+
+      IF( jpni < 1 .OR. jpnj < 1  ) THEN
          WRITE(ldtxt(ii),*) '      jpni, jpnj and jpnij will be calculated automatically' ;   ii = ii + 1
       ELSE
@@ -238,5 +233,5 @@
          WRITE(ldtxt(ii),*) '      processor grid extent in j         jpnj = ',jpnj       ;   ii = ii + 1
          WRITE(ldtxt(ii),*) '      number of local domains           jpnij = ',jpnij      ;   ii = ii + 1
-      END IF
+      ENDIF
 
       WRITE(ldtxt(ii),*) '      avoid use of mpi_allgather at the north fold  ln_nnogather = ', ln_nnogather  ; ii = ii + 1
@@ -268,5 +263,6 @@
             kstop = kstop + 1
          END SELECT
-      ELSE IF ( PRESENT(localComm) .and. .not. mpi_was_called ) THEN
+         !
+      ELSEIF ( PRESENT(localComm) .AND. .NOT. mpi_was_called ) THEN
          WRITE(ldtxt(ii),*) ' lib_mpp: You cannot provide a local communicator '          ;   ii = ii + 1
          WRITE(ldtxt(ii),*) '          without calling MPI_Init before ! '                ;   ii = ii + 1
@@ -309,5 +305,5 @@
 
 #if defined key_agrif
-      IF (Agrif_Root()) THEN
+      IF( Agrif_Root() ) THEN
          CALL Agrif_MPI_Init(mpi_comm_opa)
       ELSE
@@ -329,1448 +325,153 @@
    END FUNCTION mynode
 
-
-   SUBROUTINE mpp_lnk_3d( ptab, cd_type, psgn, cd_mpp, pval )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_3d  ***
-      !!
-      !! ** Purpose :   Message passing manadgement
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !! ** Action  :   ptab with update value at its periphery
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
-      !                                                             ! = T , U , V , F , W points
-      REAL(wp)                        , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
-      !                                                             ! =  1. , the sign is kept
-      CHARACTER(len=3), OPTIONAL      , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
-      REAL(wp)        , OPTIONAL      , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
-      !
-      INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      REAL(wp) ::   zland
-      INTEGER , DIMENSION(MPI_STATUS_SIZE)      ::   ml_stat        ! for key_mpi_isend
-      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ns, zt3sn   ! 3d for north-south & south-north
-      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ew, zt3we   ! 3d for east-west & west-east
-      !!----------------------------------------------------------------------
-      
-      ALLOCATE( zt3ns(jpi,jprecj,jpk,2), zt3sn(jpi,jprecj,jpk,2),   &
-         &      zt3ew(jpj,jpreci,jpk,2), zt3we(jpj,jpreci,jpk,2)  )
-
-      !
-      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
-      ELSE                         ;   zland = 0._wp     ! zero by default
-      ENDIF
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      IF( PRESENT( cd_mpp ) ) THEN      ! only fill added line/raw with existing values
-         !
-         ! WARNING ptab is defined only between nld and nle
-         DO jk = 1, jpk
-            DO jj = nlcj+1, jpj                 ! added line(s)   (inner only)
-               ptab(nldi  :nlei  , jj          ,jk) = ptab(nldi:nlei,     nlej,jk)
-               ptab(1     :nldi-1, jj          ,jk) = ptab(nldi     ,     nlej,jk)
-               ptab(nlei+1:nlci  , jj          ,jk) = ptab(     nlei,     nlej,jk)
-            END DO
-            DO ji = nlci+1, jpi                 ! added column(s) (full)
-               ptab(ji           ,nldj  :nlej  ,jk) = ptab(     nlei,nldj:nlej,jk)
-               ptab(ji           ,1     :nldj-1,jk) = ptab(     nlei,nldj     ,jk)
-               ptab(ji           ,nlej+1:jpj   ,jk) = ptab(     nlei,     nlej,jk)
-            END DO
-         END DO
-         !
-      ELSE                              ! standard close or cyclic treatment
-         !
-         !                                   ! East-West boundaries
-         !                                        !* Cyclic east-west
-         IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-            ptab( 1 ,:,:) = ptab(jpim1,:,:)
-            ptab(jpi,:,:) = ptab(  2  ,:,:)
-         ELSE                                     !* closed
-            IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:,:) = zland    ! south except F-point
-                                         ptab(nlci-jpreci+1:jpi   ,:,:) = zland    ! north
-         ENDIF
-                                          ! North-south cyclic
-         IF ( nbondj == 2 .AND. jperio == 7 )    THEN !* cyclic north south only with no mpp split in latitude
-            ptab(:,1 , :) = ptab(:, jpjm1,:)
-            ptab(:,jpj,:) = ptab(:,     2,:)
-         ELSE   !                                   ! North-South boundaries (closed)
-            IF( .NOT. cd_type == 'F' )   ptab(:,     1       :jprecj,:) = zland       ! south except F-point
-                                         ptab(:,nlcj-jprecj+1:jpj   ,:) = zland       ! north
-         ENDIF
-         !
-      ENDIF
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity
-      !
-      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci
-         DO jl = 1, jpreci
-            zt3ew(:,jl,:,1) = ptab(jpreci+jl,:,:)
-            zt3we(:,jl,:,1) = ptab(iihom +jl,:,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = jpreci * jpj * jpk
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
-         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci-jpreci
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jl = 1, jpreci
-            ptab(iihom+jl,:,:) = zt3ew(:,jl,:,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jpreci
-            ptab(jl      ,:,:) = zt3we(:,jl,:,2)
-            ptab(iihom+jl,:,:) = zt3ew(:,jl,:,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jpreci
-            ptab(jl      ,:,:) = zt3we(:,jl,:,2)
-         END DO
-      END SELECT
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj-nrecj
-         DO jl = 1, jprecj
-            zt3sn(:,jl,:,1) = ptab(:,ijhom +jl,:)
-            zt3ns(:,jl,:,1) = ptab(:,jprecj+jl,:)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = jprecj * jpi * jpk
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
-         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj-jprecj
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jl = 1, jprecj
-            ptab(:,ijhom+jl,:) = zt3ns(:,jl,:,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jprecj
-            ptab(:,jl      ,:) = zt3sn(:,jl,:,2)
-            ptab(:,ijhom+jl,:) = zt3ns(:,jl,:,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jprecj
-            ptab(:,jl,:) = zt3sn(:,jl,:,2)
-         END DO
-      END SELECT
-
-      ! 4. north fold treatment
-      ! -----------------------
-      !
-      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd      ( ptab, cd_type, psgn )   ! only 1 northern proc, no mpp
-         CASE DEFAULT   ;   CALL mpp_lbc_north( ptab, cd_type, psgn )   ! for all northern procs.
-         END SELECT
-         !
-      ENDIF
-      !
-      DEALLOCATE( zt3ns, zt3sn, zt3ew, zt3we )
-      !
-   END SUBROUTINE mpp_lnk_3d
-
-
-   SUBROUTINE mpp_lnk_2d_multiple( pt2d_array , type_array , psgn_array , num_fields , cd_mpp, pval )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_2d_multiple  ***
-      !!
-      !! ** Purpose :   Message passing management for multiple 2d arrays
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1), DIMENSION(:), INTENT(in   ) ::   type_array   ! define the nature of ptab array grid-points
-      !                                                               ! = T , U , V , F , W and I points
-      REAL(wp)        , DIMENSION(:), INTENT(in   ) ::   psgn_array   ! =-1 the sign change across the north fold boundary
-      !                                                               ! =  1. , the sign is kept
-      CHARACTER(len=3), OPTIONAL    , INTENT(in   ) ::   cd_mpp       ! fill the overlap area only
-      REAL(wp)        , OPTIONAL    , INTENT(in   ) ::   pval         ! background value (used at closed boundaries)
-      !!
-      INTEGER  ::   ji, jj, jl   ! dummy loop indices
-      INTEGER  ::   ii    !!MULTI SEND DUMMY LOOP INDICES
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      INTEGER :: num_fields
-      TYPE( arrayptr ), DIMENSION(:) :: pt2d_array
-      REAL(wp) ::   zland
-      INTEGER , DIMENSION(MPI_STATUS_SIZE)    ::   ml_stat       ! for key_mpi_isend
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ns, zt2sn   ! 2d for north-south & south-north
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ew, zt2we   ! 2d for east-west & west-east
-
-      !!----------------------------------------------------------------------
-      !
-      ALLOCATE( zt2ns(jpi,jprecj,2*num_fields), zt2sn(jpi,jprecj,2*num_fields),  &
-         &      zt2ew(jpj,jpreci,2*num_fields), zt2we(jpj,jpreci,2*num_fields)   )
-      !
-      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
-      ELSE                         ;   zland = 0._wp     ! zero by default
-      ENDIF
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      !
-      !First Array
-      DO ii = 1 , num_fields
-         IF( PRESENT( cd_mpp ) ) THEN      ! only fill added line/raw with existing values
-            !
-            ! WARNING pt2d is defined only between nld and nle
-            DO jj = nlcj+1, jpj                 ! added line(s)   (inner only)
-               pt2d_array(ii)%pt2d(nldi  :nlei  , jj) = pt2d_array(ii)%pt2d(nldi:nlei, nlej)
-               pt2d_array(ii)%pt2d(1     :nldi-1, jj) = pt2d_array(ii)%pt2d(nldi     , nlej)
-               pt2d_array(ii)%pt2d(nlei+1:nlci  , jj) = pt2d_array(ii)%pt2d(     nlei, nlej) 
-            END DO
-            DO ji = nlci+1, jpi                 ! added column(s) (full)
-               pt2d_array(ii)%pt2d(ji, nldj  :nlej  ) = pt2d_array(ii)%pt2d(nlei, nldj:nlej)
-               pt2d_array(ii)%pt2d(ji, 1     :nldj-1) = pt2d_array(ii)%pt2d(nlei, nldj     )
-               pt2d_array(ii)%pt2d(ji, nlej+1:jpj   ) = pt2d_array(ii)%pt2d(nlei,      nlej)
-            END DO
-            !
-         ELSE                              ! standard close or cyclic treatment
-            !
-            !                                   ! East-West boundaries
-            IF( nbondi == 2 .AND.   &                ! Cyclic east-west
-               &    (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-               pt2d_array(ii)%pt2d(  1  , : ) = pt2d_array(ii)%pt2d( jpim1, : )                                    ! west
-               pt2d_array(ii)%pt2d( jpi , : ) = pt2d_array(ii)%pt2d(   2  , : )                                    ! east
-            ELSE                                     ! closed
-               IF( .NOT. type_array(ii) == 'F' )   pt2d_array(ii)%pt2d(            1 : jpreci,:) = zland    ! south except F-point
-                                                   pt2d_array(ii)%pt2d(nlci-jpreci+1 : jpi   ,:) = zland    ! north
-            ENDIF
-                                                ! Noth-South boundaries
-            IF ( nbondj == 2 .AND. jperio == 7 )    THEN !* cyclic north south
-               pt2d_array(ii)%pt2d(:, 1   ) =   pt2d_array(ii)%pt2d(:, jpjm1 )
-               pt2d_array(ii)%pt2d(:, jpj ) =   pt2d_array(ii)%pt2d(:, 2 )          
-            ELSE   !             
-               !                                   ! North-South boundaries (closed)
-               IF( .NOT. type_array(ii) == 'F' )   pt2d_array(ii)%pt2d(:,             1:jprecj ) = zland    ! south except F-point
-                                                   pt2d_array(ii)%pt2d(:, nlcj-jprecj+1:jpj    ) = zland    ! north
-            !
-            ENDIF
-          ENDIF
-      END DO
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity
-      !
-      DO ii = 1 , num_fields
-         SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-         CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-            iihom = nlci-nreci
-            DO jl = 1, jpreci
-               zt2ew( : , jl , ii ) = pt2d_array(ii)%pt2d( jpreci+jl , : )
-               zt2we( : , jl , ii ) = pt2d_array(ii)%pt2d( iihom +jl , : )
-            END DO
-         END SELECT
-      END DO
-      !
-      !                           ! Migrations
-      imigr = jpreci * jpj
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, zt2we(1,1,1), num_fields*imigr, noea, ml_req1 )
-         CALL mpprecv( 1, zt2ew(1,1,num_fields+1), num_fields*imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, zt2ew(1,1,1), num_fields*imigr, nowe, ml_req1 )
-         CALL mppsend( 2, zt2we(1,1,1), num_fields*imigr, noea, ml_req2 )
-         CALL mpprecv( 1, zt2ew(1,1,num_fields+1), num_fields*imigr, noea )
-         CALL mpprecv( 2, zt2we(1,1,num_fields+1), num_fields*imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, zt2ew(1,1,1), num_fields*imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, zt2we(1,1,num_fields+1), num_fields*imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci - jpreci
-      !
-
-      DO ii = 1 , num_fields
-         SELECT CASE ( nbondi )
-         CASE ( -1 )
-            DO jl = 1, jpreci
-               pt2d_array(ii)%pt2d( iihom+jl , : ) = zt2ew(:,jl,num_fields+ii)
-            END DO
-         CASE ( 0 )
-            DO jl = 1, jpreci
-               pt2d_array(ii)%pt2d( jl , : ) = zt2we(:,jl,num_fields+ii)
-               pt2d_array(ii)%pt2d( iihom+jl , : ) = zt2ew(:,jl,num_fields+ii)
-            END DO
-         CASE ( 1 )
-            DO jl = 1, jpreci
-               pt2d_array(ii)%pt2d( jl , : )= zt2we(:,jl,num_fields+ii)
-            END DO
-         END SELECT
-      END DO
-      
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      !First Array
-      DO ii = 1 , num_fields
-         IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-            ijhom = nlcj-nrecj
-            DO jl = 1, jprecj
-               zt2sn(:,jl , ii) = pt2d_array(ii)%pt2d( : , ijhom +jl )
-               zt2ns(:,jl , ii) = pt2d_array(ii)%pt2d( : , jprecj+jl )
-            END DO
-         ENDIF
-      END DO
-      !
-      !                           ! Migrations
-      imigr = jprecj * jpi
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, zt2sn(1,1,1), num_fields*imigr, nono, ml_req1 )
-         CALL mpprecv( 3, zt2ns(1,1,num_fields+1), num_fields*imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, zt2ns(1,1,1), num_fields*imigr, noso, ml_req1 )
-         CALL mppsend( 4, zt2sn(1,1,1), num_fields*imigr, nono, ml_req2 )
-         CALL mpprecv( 3, zt2ns(1,1,num_fields+1), num_fields*imigr, nono )
-         CALL mpprecv( 4, zt2sn(1,1,num_fields+1), num_fields*imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 3, zt2ns(1,1,1), num_fields*imigr, noso, ml_req1 )
-         CALL mpprecv( 4, zt2sn(1,1,num_fields+1), num_fields*imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj - jprecj
-      !
-
-      DO ii = 1 , num_fields
-         !First Array
-         SELECT CASE ( nbondj )
-         CASE ( -1 )
-            DO jl = 1, jprecj
-               pt2d_array(ii)%pt2d( : , ijhom+jl ) = zt2ns( : , jl , num_fields+ii )
-            END DO
-         CASE ( 0 )
-            DO jl = 1, jprecj
-               pt2d_array(ii)%pt2d( : , jl ) = zt2sn( : , jl , num_fields + ii)
-               pt2d_array(ii)%pt2d( : , ijhom + jl ) = zt2ns( : , jl , num_fields + ii )
-            END DO
-         CASE ( 1 )
-            DO jl = 1, jprecj
-               pt2d_array(ii)%pt2d( : , jl ) = zt2sn( : , jl , num_fields + ii )
-            END DO
-         END SELECT
-      END DO
-      
-      ! 4. north fold treatment
-      ! -----------------------
-      !
-         !First Array
-      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   
-             DO ii = 1 , num_fields  
-                       CALL lbc_nfd      ( pt2d_array(ii)%pt2d( : , : ), type_array(ii) , psgn_array(ii) )   ! only 1 northern proc, no mpp
-             END DO
-         CASE DEFAULT   ;   CALL mpp_lbc_north_2d_multiple( pt2d_array, type_array, psgn_array, num_fields )   ! for all northern procs.
-         END SELECT
-         !
-      ENDIF
-        !
-      !
-      DEALLOCATE( zt2ns, zt2sn, zt2ew, zt2we )
-      !
-   END SUBROUTINE mpp_lnk_2d_multiple
-
-   
-   SUBROUTINE load_array( pt2d, cd_type, psgn, pt2d_array, type_array, psgn_array, num_fields )
-      !!---------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), TARGET, INTENT(inout) ::   pt2d    ! Second 2D array on which the boundary condition is applied
-      CHARACTER(len=1)                    , INTENT(in   ) ::   cd_type ! define the nature of ptab array grid-points
-      REAL(wp)                            , INTENT(in   ) ::   psgn    ! =-1 the sign change across the north fold boundary
-      TYPE(arrayptr)   , DIMENSION(9) ::   pt2d_array
-      CHARACTER(len=1) , DIMENSION(9) ::   type_array    ! define the nature of ptab array grid-points
-      REAL(wp)         , DIMENSION(9) ::   psgn_array    ! =-1 the sign change across the north fold boundary
-      INTEGER                            , INTENT (inout) :: num_fields 
-      !!---------------------------------------------------------------------
-      num_fields = num_fields + 1
-      pt2d_array(num_fields)%pt2d => pt2d
-      type_array(num_fields)      =  cd_type
-      psgn_array(num_fields)      =  psgn
-   END SUBROUTINE load_array
+   !!----------------------------------------------------------------------
+   !!                   ***  routine mpp_lnk_(2,3,4)d  ***
+   !!
+   !!   * Argument : dummy argument use in mpp_lnk_... routines
+   !!                ptab   :   array or pointer of arrays on which the boundary condition is applied
+   !!                cd_nat :   nature of array grid-points
+   !!                psgn   :   sign used across the north fold boundary
+   !!                kfld   :   optional, number of pt3d arrays
+   !!                cd_mpp :   optional, fill the overlap area only
+   !!                pval   :   optional, background value (used at closed boundaries)
+   !!----------------------------------------------------------------------
+   !
+   !                       !==  2D array and array of 2D pointer  ==!
+   !
+#  define DIM_2d
+#     define ROUTINE_LNK           mpp_lnk_2d
+#     include "mpp_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     define MULTI
+#     define ROUTINE_LNK           mpp_lnk_2d_ptr
+#     include "mpp_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     undef MULTI
+#  undef DIM_2d
+   !
+   !                       !==  3D array and array of 3D pointer  ==!
+   !
+#  define DIM_3d
+#     define ROUTINE_LNK           mpp_lnk_3d
+#     include "mpp_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     define MULTI
+#     define ROUTINE_LNK           mpp_lnk_3d_ptr
+#     include "mpp_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     undef MULTI
+#  undef DIM_3d
+   !
+   !                       !==  4D array and array of 4D pointer  ==!
+   !
+#  define DIM_4d
+#     define ROUTINE_LNK           mpp_lnk_4d
+#     include "mpp_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     define MULTI
+#     define ROUTINE_LNK           mpp_lnk_4d_ptr
+#     include "mpp_lnk_generic.h90"
+#     undef ROUTINE_LNK
+#     undef MULTI
+#  undef DIM_4d
+
+   !!----------------------------------------------------------------------
+   !!                   ***  routine mpp_nfd_(2,3,4)d  ***
+   !!
+   !!   * Argument : dummy argument use in mpp_nfd_... routines
+   !!                ptab   :   array or pointer of arrays on which the boundary condition is applied
+   !!                cd_nat :   nature of array grid-points
+   !!                psgn   :   sign used across the north fold boundary
+   !!                kfld   :   optional, number of pt3d arrays
+   !!                cd_mpp :   optional, fill the overlap area only
+   !!                pval   :   optional, background value (used at closed boundaries)
+   !!----------------------------------------------------------------------
+   !
+   !                       !==  2D array and array of 2D pointer  ==!
+   !
+#  define DIM_2d
+#     define ROUTINE_NFD           mpp_nfd_2d
+#     include "mpp_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     define MULTI
+#     define ROUTINE_NFD           mpp_nfd_2d_ptr
+#     include "mpp_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     undef MULTI
+#  undef DIM_2d
+   !
+   !                       !==  3D array and array of 3D pointer  ==!
+   !
+#  define DIM_3d
+#     define ROUTINE_NFD           mpp_nfd_3d
+#     include "mpp_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     define MULTI
+#     define ROUTINE_NFD           mpp_nfd_3d_ptr
+#     include "mpp_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     undef MULTI
+#  undef DIM_3d
+   !
+   !                       !==  4D array and array of 4D pointer  ==!
+   !
+#  define DIM_4d
+#     define ROUTINE_NFD           mpp_nfd_4d
+#     include "mpp_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     define MULTI
+#     define ROUTINE_NFD           mpp_nfd_4d_ptr
+#     include "mpp_nfd_generic.h90"
+#     undef ROUTINE_NFD
+#     undef MULTI
+#  undef DIM_4d
+
+
+   !!----------------------------------------------------------------------
+   !!                   ***  routine mpp_lnk_bdy_(2,3,4)d  ***
+   !!
+   !!   * Argument : dummy argument use in mpp_lnk_... routines
+   !!                ptab   :   array or pointer of arrays on which the boundary condition is applied
+   !!                cd_nat :   nature of array grid-points
+   !!                psgn   :   sign used across the north fold boundary
+   !!                kb_bdy :   BDY boundary set
+   !!                kfld   :   optional, number of pt3d arrays
+   !!----------------------------------------------------------------------
+   !
+   !                       !==  2D array and array of 2D pointer  ==!
+   !
+#  define DIM_2d
+#     define ROUTINE_BDY           mpp_lnk_bdy_2d
+#     include "mpp_bdy_generic.h90"
+#     undef ROUTINE_BDY
+#  undef DIM_2d
+   !
+   !                       !==  3D array and array of 3D pointer  ==!
+   !
+#  define DIM_3d
+#     define ROUTINE_BDY           mpp_lnk_bdy_3d
+#     include "mpp_bdy_generic.h90"
+#     undef ROUTINE_BDY
+#  undef DIM_3d
+   !
+   !                       !==  4D array and array of 4D pointer  ==!
+   !
+!!#  define DIM_4d
+!!#     define ROUTINE_BDY           mpp_lnk_bdy_4d
+!!#     include "mpp_bdy_generic.h90"
+!!#     undef ROUTINE_BDY
+!!#  undef DIM_4d
+
+   !!----------------------------------------------------------------------
+   !!
+   !!   load_array  &   mpp_lnk_2d_9    à generaliser a 3D et 4D
    
    
-   SUBROUTINE mpp_lnk_2d_9( pt2dA, cd_typeA, psgnA, pt2dB, cd_typeB, psgnB, pt2dC, cd_typeC, psgnC   &
-      &                   , pt2dD, cd_typeD, psgnD, pt2dE, cd_typeE, psgnE, pt2dF, cd_typeF, psgnF   &
-      &                   , pt2dG, cd_typeG, psgnG, pt2dH, cd_typeH, psgnH, pt2dI, cd_typeI, psgnI, cd_mpp, pval)
-      !!---------------------------------------------------------------------
-      ! Second 2D array on which the boundary condition is applied
-      REAL(wp), DIMENSION(jpi,jpj), TARGET          , INTENT(inout) ::   pt2dA    
-      REAL(wp), DIMENSION(jpi,jpj), TARGET, OPTIONAL, INTENT(inout) ::   pt2dB , pt2dC , pt2dD , pt2dE
-      REAL(wp), DIMENSION(jpi,jpj), TARGET, OPTIONAL, INTENT(inout) ::   pt2dF , pt2dG , pt2dH , pt2dI 
-      ! define the nature of ptab array grid-points
-      CHARACTER(len=1)                              , INTENT(in   ) ::   cd_typeA
-      CHARACTER(len=1)                    , OPTIONAL, INTENT(in   ) ::   cd_typeB , cd_typeC , cd_typeD , cd_typeE
-      CHARACTER(len=1)                    , OPTIONAL, INTENT(in   ) ::   cd_typeF , cd_typeG , cd_typeH , cd_typeI
-      ! =-1 the sign change across the north fold boundary
-      REAL(wp)                                      , INTENT(in   ) ::   psgnA    
-      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   psgnB , psgnC , psgnD , psgnE
-      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   psgnF , psgnG , psgnH , psgnI   
-      CHARACTER(len=3)                    , OPTIONAL, INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
-      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
-      !!
-      TYPE(arrayptr)   , DIMENSION(9) ::   pt2d_array 
-      CHARACTER(len=1) , DIMENSION(9) ::   type_array    ! define the nature of ptab array grid-points
-      !                                                         ! = T , U , V , F , W and I points
-      REAL(wp)         , DIMENSION(9) ::   psgn_array    ! =-1 the sign change across the north fold boundary
-      INTEGER :: num_fields
-      !!---------------------------------------------------------------------
-      !
-      num_fields = 0
-      !
-      ! Load the first array
-      CALL load_array( pt2dA, cd_typeA, psgnA, pt2d_array, type_array, psgn_array, num_fields )
-      !
-      ! Look if more arrays are added
-      IF( PRESENT(psgnB) )   CALL load_array(pt2dB,cd_typeB,psgnB,pt2d_array, type_array, psgn_array,num_fields)
-      IF( PRESENT(psgnC) )   CALL load_array(pt2dC,cd_typeC,psgnC,pt2d_array, type_array, psgn_array,num_fields)
-      IF( PRESENT(psgnD) )   CALL load_array(pt2dD,cd_typeD,psgnD,pt2d_array, type_array, psgn_array,num_fields)
-      IF( PRESENT(psgnE) )   CALL load_array(pt2dE,cd_typeE,psgnE,pt2d_array, type_array, psgn_array,num_fields)
-      IF( PRESENT(psgnF) )   CALL load_array(pt2dF,cd_typeF,psgnF,pt2d_array, type_array, psgn_array,num_fields)
-      IF( PRESENT(psgnG) )   CALL load_array(pt2dG,cd_typeG,psgnG,pt2d_array, type_array, psgn_array,num_fields)
-      IF( PRESENT(psgnH) )   CALL load_array(pt2dH,cd_typeH,psgnH,pt2d_array, type_array, psgn_array,num_fields)
-      IF( PRESENT(psgnI) )   CALL load_array(pt2dI,cd_typeI,psgnI,pt2d_array, type_array, psgn_array,num_fields)
-      !
-      CALL mpp_lnk_2d_multiple( pt2d_array, type_array, psgn_array, num_fields, cd_mpp,pval )
-      !
-   END SUBROUTINE mpp_lnk_2d_9
-
-
-   SUBROUTINE mpp_lnk_2d( pt2d, cd_type, psgn, cd_mpp, pval )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_2d  ***
-      !!
-      !! ** Purpose :   Message passing manadgement for 2d array
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d     ! 2D array on which the boundary condition is applied
-      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
-      !                                                         ! = T , U , V , F , W and I points
-      REAL(wp)                    , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
-      !                                                         ! =  1. , the sign is kept
-      CHARACTER(len=3), OPTIONAL  , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
-      REAL(wp)        , OPTIONAL  , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
-      !!
-      INTEGER  ::   ji, jj, jl   ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      REAL(wp) ::   zland
-      INTEGER, DIMENSION(MPI_STATUS_SIZE)     ::   ml_stat       ! for key_mpi_isend
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ns, zt2sn   ! 2d for north-south & south-north
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ew, zt2we   ! 2d for east-west & west-east
-      !!----------------------------------------------------------------------
-      !
-      ALLOCATE( zt2ns(jpi,jprecj,2), zt2sn(jpi,jprecj,2),  &
-         &      zt2ew(jpj,jpreci,2), zt2we(jpj,jpreci,2)   )
-      !
-      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
-      ELSE                         ;   zland = 0._wp     ! zero by default
-      ENDIF
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      !
-      IF( PRESENT( cd_mpp ) ) THEN      ! only fill added line/raw with existing values
-         !
-         ! WARNING pt2d is defined only between nld and nle
-         DO jj = nlcj+1, jpj                 ! added line(s)   (inner only)
-            pt2d(nldi  :nlei  , jj          ) = pt2d(nldi:nlei,     nlej)
-            pt2d(1     :nldi-1, jj          ) = pt2d(nldi     ,     nlej)
-            pt2d(nlei+1:nlci  , jj          ) = pt2d(     nlei,     nlej)
-         END DO
-         DO ji = nlci+1, jpi                 ! added column(s) (full)
-            pt2d(ji           ,nldj  :nlej  ) = pt2d(     nlei,nldj:nlej)
-            pt2d(ji           ,1     :nldj-1) = pt2d(     nlei,nldj     )
-            pt2d(ji           ,nlej+1:jpj   ) = pt2d(     nlei,     nlej)
-         END DO
-         !
-      ELSE                              ! standard close or cyclic treatment
-         !
-         !                                   ! East-West boundaries
-         IF( nbondi == 2 .AND.   &                ! Cyclic east-west
-            &    (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-            pt2d( 1 ,:) = pt2d(jpim1,:)                                    ! west
-            pt2d(jpi,:) = pt2d(  2  ,:)                                    ! east
-         ELSE                                     ! closed
-            IF( .NOT. cd_type == 'F' )   pt2d(     1       :jpreci,:) = zland    ! south except F-point
-                                         pt2d(nlci-jpreci+1:jpi   ,:) = zland    ! north
-         ENDIF
-                                            ! North-South boudaries
-         IF ( nbondj == 2 .AND. jperio == 7 )    THEN !* cyclic north south
-            pt2d(:,  1 ) = pt2d(:,jpjm1)
-            pt2d(:, jpj) = pt2d(:,    2)
-         ELSE    
-         !                                   ! North-South boundaries (closed)
-            IF( .NOT. cd_type == 'F' )   pt2d(:,     1       :jprecj) = zland    !south except F-point
-                                         pt2d(:,nlcj-jprecj+1:jpj   ) = zland    ! north
-         ENDIF     
-      ENDIF
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity
-      !
-      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci
-         DO jl = 1, jpreci
-            zt2ew(:,jl,1) = pt2d(jpreci+jl,:)
-            zt2we(:,jl,1) = pt2d(iihom +jl,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = jpreci * jpj
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
-         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci - jpreci
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jl = 1, jpreci
-            pt2d(iihom+jl,:) = zt2ew(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jpreci
-            pt2d(jl      ,:) = zt2we(:,jl,2)
-            pt2d(iihom+jl,:) = zt2ew(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jpreci
-            pt2d(jl      ,:) = zt2we(:,jl,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj-nrecj
-         DO jl = 1, jprecj
-            zt2sn(:,jl,1) = pt2d(:,ijhom +jl)
-            zt2ns(:,jl,1) = pt2d(:,jprecj+jl)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = jprecj * jpi
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
-         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj - jprecj
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jl = 1, jprecj
-            pt2d(:,ijhom+jl) = zt2ns(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jprecj
-            pt2d(:,jl      ) = zt2sn(:,jl,2)
-            pt2d(:,ijhom+jl) = zt2ns(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jprecj
-            pt2d(:,jl      ) = zt2sn(:,jl,2)
-         END DO
-      END SELECT
-
-
-      ! 4. north fold treatment
-      ! -----------------------
-      !
-      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd      ( pt2d, cd_type, psgn )   ! only 1 northern proc, no mpp
-         CASE DEFAULT   ;   CALL mpp_lbc_north( pt2d, cd_type, psgn )   ! for all northern procs.
-         END SELECT
-         !
-      ENDIF
-      !
-      DEALLOCATE( zt2ns, zt2sn, zt2ew, zt2we )
-      !
-   END SUBROUTINE mpp_lnk_2d
-
-
-   SUBROUTINE mpp_lnk_3d_gather( ptab1, cd_type1, ptab2, cd_type2, psgn )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_3d_gather  ***
-      !!
-      !! ** Purpose :   Message passing manadgement for two 3D arrays
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !! ** Action  :   ptab1 and ptab2  with update value at its periphery
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab1     ! first and second 3D array on which
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab2     ! the boundary condition is applied
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type1  ! nature of ptab1 and ptab2 arrays
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type2  ! i.e. grid-points = T , U , V , F or W points
-      REAL(wp)                        , INTENT(in   ) ::   psgn      ! =-1 the sign change across the north fold boundary
-      !!                                                             ! =  1. , the sign is kept
-      INTEGER  ::   jl   ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      INTEGER , DIMENSION(MPI_STATUS_SIZE)        ::   ml_stat   ! for key_mpi_isend
-      REAL(wp), DIMENSION(:,:,:,:,:), ALLOCATABLE ::   zt4ns, zt4sn   ! 2 x 3d for north-south & south-north
-      REAL(wp), DIMENSION(:,:,:,:,:), ALLOCATABLE ::   zt4ew, zt4we   ! 2 x 3d for east-west & west-east
-      !!----------------------------------------------------------------------
-      !
-      ALLOCATE( zt4ns(jpi,jprecj,jpk,2,2), zt4sn(jpi,jprecj,jpk,2,2) ,    &
-         &      zt4ew(jpj,jpreci,jpk,2,2), zt4we(jpj,jpreci,jpk,2,2) )
-      !
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      !                                      ! East-West boundaries
-      !                                           !* Cyclic east-west
-      IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-         ptab1( 1 ,:,:) = ptab1(jpim1,:,:)
-         ptab1(jpi,:,:) = ptab1(  2  ,:,:)
-         ptab2( 1 ,:,:) = ptab2(jpim1,:,:)
-         ptab2(jpi,:,:) = ptab2(  2  ,:,:)
-      ELSE                                        !* closed
-         IF( .NOT. cd_type1 == 'F' )   ptab1(     1       :jpreci,:,:) = 0.e0    ! south except at F-point
-         IF( .NOT. cd_type2 == 'F' )   ptab2(     1       :jpreci,:,:) = 0.e0
-                                       ptab1(nlci-jpreci+1:jpi   ,:,:) = 0.e0    ! north
-                                       ptab2(nlci-jpreci+1:jpi   ,:,:) = 0.e0
-      ENDIF
-                                            ! North-South boundaries
-      IF ( nbondj == 2 .AND. jperio == 7 )    THEN !* cyclic north south
-         ptab1(:,     1       ,:) = ptab1(: ,  jpjm1 , :)
-         ptab1(:,   jpj       ,:) = ptab1(: ,      2 , :)
-         ptab2(:,     1       ,:) = ptab2(: ,  jpjm1 , :)
-         ptab2(:,   jpj       ,:) = ptab2(: ,      2 , :)
-      ELSE     
-      !                                      ! North-South boundaries closed
-      IF( .NOT. cd_type1 == 'F' )   ptab1(:,     1       :jprecj,:) = 0.e0    ! south except at F-point
-      IF( .NOT. cd_type2 == 'F' )   ptab2(:,     1       :jprecj,:) = 0.e0
-                                    ptab1(:,nlcj-jprecj+1:jpj   ,:) = 0.e0    ! north
-                                    ptab2(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
-      ENDIF     
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity
-      !
-      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci
-         DO jl = 1, jpreci
-            zt4ew(:,jl,:,1,1) = ptab1(jpreci+jl,:,:)
-            zt4we(:,jl,:,1,1) = ptab1(iihom +jl,:,:)
-            zt4ew(:,jl,:,2,1) = ptab2(jpreci+jl,:,:)
-            zt4we(:,jl,:,2,1) = ptab2(iihom +jl,:,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = jpreci * jpj * jpk *2
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, zt4we(1,1,1,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, zt4ew(1,1,1,1,2), imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, zt4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, zt4we(1,1,1,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, zt4ew(1,1,1,1,2), imigr, noea )
-         CALL mpprecv( 2, zt4we(1,1,1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, zt4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, zt4we(1,1,1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci - jpreci
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jl = 1, jpreci
-            ptab1(iihom+jl,:,:) = zt4ew(:,jl,:,1,2)
-            ptab2(iihom+jl,:,:) = zt4ew(:,jl,:,2,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jpreci
-            ptab1(jl      ,:,:) = zt4we(:,jl,:,1,2)
-            ptab1(iihom+jl,:,:) = zt4ew(:,jl,:,1,2)
-            ptab2(jl      ,:,:) = zt4we(:,jl,:,2,2)
-            ptab2(iihom+jl,:,:) = zt4ew(:,jl,:,2,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jpreci
-            ptab1(jl      ,:,:) = zt4we(:,jl,:,1,2)
-            ptab2(jl      ,:,:) = zt4we(:,jl,:,2,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj - nrecj
-         DO jl = 1, jprecj
-            zt4sn(:,jl,:,1,1) = ptab1(:,ijhom +jl,:)
-            zt4ns(:,jl,:,1,1) = ptab1(:,jprecj+jl,:)
-            zt4sn(:,jl,:,2,1) = ptab2(:,ijhom +jl,:)
-            zt4ns(:,jl,:,2,1) = ptab2(:,jprecj+jl,:)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = jprecj * jpi * jpk * 2
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, zt4sn(1,1,1,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, zt4ns(1,1,1,1,2), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, zt4ns(1,1,1,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, zt4sn(1,1,1,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, zt4ns(1,1,1,1,2), imigr, nono )
-         CALL mpprecv( 4, zt4sn(1,1,1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         CALL mppsend( 3, zt4ns(1,1,1,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, zt4sn(1,1,1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj - jprecj
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jl = 1, jprecj
-            ptab1(:,ijhom+jl,:) = zt4ns(:,jl,:,1,2)
-            ptab2(:,ijhom+jl,:) = zt4ns(:,jl,:,2,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jprecj
-            ptab1(:,jl      ,:) = zt4sn(:,jl,:,1,2)
-            ptab1(:,ijhom+jl,:) = zt4ns(:,jl,:,1,2)
-            ptab2(:,jl      ,:) = zt4sn(:,jl,:,2,2)
-            ptab2(:,ijhom+jl,:) = zt4ns(:,jl,:,2,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jprecj
-            ptab1(:,jl,:) = zt4sn(:,jl,:,1,2)
-            ptab2(:,jl,:) = zt4sn(:,jl,:,2,2)
-         END DO
-      END SELECT
-
-
-      ! 4. north fold treatment
-      ! -----------------------
-      IF( npolj /= 0 ) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )
-            CALL lbc_nfd      ( ptab1, cd_type1, psgn )   ! only for northern procs.
-            CALL lbc_nfd      ( ptab2, cd_type2, psgn )
-         CASE DEFAULT
-            CALL mpp_lbc_north( ptab1, cd_type1, psgn )   ! for all northern procs.
-            CALL mpp_lbc_north (ptab2, cd_type2, psgn)
-         END SELECT
-         !
-      ENDIF
-      !
-      DEALLOCATE( zt4ns, zt4sn, zt4ew, zt4we )
-      !
-   END SUBROUTINE mpp_lnk_3d_gather
-
-
-   SUBROUTINE mpp_lnk_2d_e( pt2d, cd_type, psgn, jpri, jprj )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_2d_e  ***
-      !!
-      !! ** Purpose :   Message passing manadgement for 2d array (with halo)
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    jpri   : number of rows for extra outer halo
-      !!                    jprj   : number of columns for extra outer halo
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER                                             , INTENT(in   ) ::   jpri
-      INTEGER                                             , INTENT(in   ) ::   jprj
-      REAL(wp), DIMENSION(1-jpri:jpi+jpri,1-jprj:jpj+jprj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
-      CHARACTER(len=1)                                    , INTENT(in   ) ::   cd_type  ! nature of ptab array grid-points
-      !                                                                                 ! = T , U , V , F , W and I points
-      REAL(wp)                                            , INTENT(in   ) ::   psgn     ! =-1 the sign change across the
-      !!                                                                                ! north boundary, =  1. otherwise
-      INTEGER  ::   jl   ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ipreci, iprecj             ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !!
-      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dns
-      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dsn
-      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dwe
-      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dew
-      !!----------------------------------------------------------------------
-
-      ipreci = jpreci + jpri      ! take into account outer extra 2D overlap area
-      iprecj = jprecj + jprj
-
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      ! Order matters Here !!!!
-      !
-                                           ! North-South cyclic
-      IF ( nbondj == 2 .AND. jperio == 7 )    THEN !* cyclic north south
-         pt2d(:, 1-jprj:  1     ) = pt2d ( :, jpjm1-jprj:jpjm1)
-         pt2d(:, jpj   :jpj+jprj) = pt2d ( :, 2         :2+jprj)
-      ELSE
-        
-      !                                      !* North-South boundaries (closed)
-      IF( .NOT. cd_type == 'F' )   pt2d(:,  1-jprj   :  jprecj  ) = 0.e0    ! south except at F-point
-                                   pt2d(:,nlcj-jprecj+1:jpj+jprj) = 0.e0    ! north
-      ENDIF
-                                
-      !                                      ! East-West boundaries
-      !                                           !* Cyclic east-west
-      IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-         pt2d(1-jpri:     1    ,:) = pt2d(jpim1-jpri:  jpim1 ,:)       ! east
-         pt2d(   jpi  :jpi+jpri,:) = pt2d(     2      :2+jpri,:)       ! west
-         !
-      ELSE                                        !* closed
-         IF( .NOT. cd_type == 'F' )   pt2d(  1-jpri   :jpreci    ,:) = 0.e0    ! south except at F-point
-                                      pt2d(nlci-jpreci+1:jpi+jpri,:) = 0.e0    ! north
-      ENDIF
-      !
-
-      ! north fold treatment
-      ! -----------------------
-      IF( npolj /= 0 ) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd        ( pt2d(1:jpi,1:jpj+jprj), cd_type, psgn, pr2dj=jprj )
-         CASE DEFAULT   ;   CALL mpp_lbc_north_e( pt2d                    , cd_type, psgn               )
-         END SELECT
-         !
-      ENDIF
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity
-      !
-      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci-jpri
-         DO jl = 1, ipreci
-            r2dew(:,jl,1) = pt2d(jpreci+jl,:)
-            r2dwe(:,jl,1) = pt2d(iihom +jl,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = ipreci * ( jpj + 2*jprj)
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
-         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci - jpreci
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jl = 1, ipreci
-            pt2d(iihom+jl,:) = r2dew(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, ipreci
-            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
-            pt2d( iihom+jl,:) = r2dew(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, ipreci
-            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj-nrecj-jprj
-         DO jl = 1, iprecj
-            r2dsn(:,jl,1) = pt2d(:,ijhom +jl)
-            r2dns(:,jl,1) = pt2d(:,jprecj+jl)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = iprecj * ( jpi + 2*jpri )
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
-         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj - jprecj
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jl = 1, iprecj
-            pt2d(:,ijhom+jl) = r2dns(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, iprecj
-            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
-            pt2d(:,ijhom+jl ) = r2dns(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, iprecj
-            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
-         END DO
-      END SELECT
-      !
-   END SUBROUTINE mpp_lnk_2d_e
-
-   SUBROUTINE mpp_lnk_sum_3d( ptab, cd_type, psgn, cd_mpp, pval )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_sum_3d  ***
-      !!
-      !! ** Purpose :   Message passing manadgement (sum the overlap region)
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !! ** Action  :   ptab with update value at its periphery
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
-      !                                                             ! = T , U , V , F , W points
-      REAL(wp)                        , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
-      !                                                             ! =  1. , the sign is kept
-      CHARACTER(len=3), OPTIONAL      , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
-      REAL(wp)        , OPTIONAL      , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
-      !!
-      INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      REAL(wp) ::   zland
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !
-      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ns, zt3sn   ! 3d for north-south & south-north
-      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ew, zt3we   ! 3d for east-west & west-east
-
-      !!----------------------------------------------------------------------
-      
-      ALLOCATE( zt3ns(jpi,jprecj,jpk,2), zt3sn(jpi,jprecj,jpk,2),   &
-         &      zt3ew(jpj,jpreci,jpk,2), zt3we(jpj,jpreci,jpk,2)  )
-
-      !
-      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
-      ELSE                         ;   zland = 0.e0      ! zero by default
-      ENDIF
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity
-      !
-      SELECT CASE ( nbondi )      ! Read lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-      iihom = nlci-jpreci
-         DO jl = 1, jpreci
-            zt3ew(:,jl,:,1) = ptab(jl      ,:,:) ; ptab(jl      ,:,:) = 0.0_wp
-            zt3we(:,jl,:,1) = ptab(iihom+jl,:,:) ; ptab(iihom+jl,:,:) = 0.0_wp 
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = jpreci * jpj * jpk
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
-         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write lateral conditions
-      iihom = nlci-nreci
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jl = 1, jpreci
-            ptab(iihom+jl,:,:) = ptab(iihom+jl,:,:) + zt3ew(:,jl,:,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jpreci
-            ptab(jpreci+jl,:,:) = ptab(jpreci+jl,:,:) + zt3we(:,jl,:,2)
-            ptab(iihom +jl,:,:) = ptab(iihom +jl,:,:) + zt3ew(:,jl,:,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jpreci
-            ptab(jpreci+jl,:,:) = ptab(jpreci+jl,:,:) + zt3we(:,jl,:,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj /= 2 ) THEN      ! Read lateral conditions
-         ijhom = nlcj-jprecj
-         DO jl = 1, jprecj
-            zt3sn(:,jl,:,1) = ptab(:,ijhom+jl,:) ; ptab(:,ijhom+jl,:) = 0.0_wp
-            zt3ns(:,jl,:,1) = ptab(:,jl      ,:) ; ptab(:,jl      ,:) = 0.0_wp
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = jprecj * jpi * jpk
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
-         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write lateral conditions
-      ijhom = nlcj-nrecj
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jl = 1, jprecj
-            ptab(:,ijhom+jl,:) = ptab(:,ijhom+jl,:) + zt3ns(:,jl,:,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jprecj
-            ptab(:,jprecj+jl,:) = ptab(:,jprecj+jl,:) + zt3sn(:,jl,:,2)
-            ptab(:,ijhom +jl,:) = ptab(:,ijhom +jl,:) + zt3ns(:,jl,:,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jprecj
-            ptab(:,jprecj+jl,:) = ptab(:,jprecj+jl,:) + zt3sn(:,jl   ,:,2)
-         END DO
-      END SELECT
-
-
-      ! 4. north fold treatment
-      ! -----------------------
-      !
-      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd      ( ptab, cd_type, psgn )   ! only 1 northern proc, no mpp
-         CASE DEFAULT   ;   CALL mpp_lbc_north( ptab, cd_type, psgn )   ! for all northern procs.
-         END SELECT
-         !
-      ENDIF
-      !
-      DEALLOCATE( zt3ns, zt3sn, zt3ew, zt3we )
-      !
-   END SUBROUTINE mpp_lnk_sum_3d
-
-   SUBROUTINE mpp_lnk_sum_2d( pt2d, cd_type, psgn, cd_mpp, pval )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_sum_2d  ***
-      !!
-      !! ** Purpose :   Message passing manadgement for 2d array (sum the overlap region)
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d     ! 2D array on which the boundary condition is applied
-      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
-      !                                                         ! = T , U , V , F , W and I points
-      REAL(wp)                    , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
-      !                                                         ! =  1. , the sign is kept
-      CHARACTER(len=3), OPTIONAL  , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
-      REAL(wp)        , OPTIONAL  , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
-      !!
-      INTEGER  ::   ji, jj, jl   ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      REAL(wp) ::   zland
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ns, zt2sn   ! 2d for north-south & south-north
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ew, zt2we   ! 2d for east-west & west-east
-
-      !!----------------------------------------------------------------------
-
-      ALLOCATE( zt2ns(jpi,jprecj,2), zt2sn(jpi,jprecj,2),  &
-         &      zt2ew(jpj,jpreci,2), zt2we(jpj,jpreci,2)   )
-
-      !
-      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
-      ELSE                         ;   zland = 0.e0      ! zero by default
-      ENDIF
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity
-      !
-      SELECT CASE ( nbondi )      ! Read lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci - jpreci
-         DO jl = 1, jpreci
-            zt2ew(:,jl,1) = pt2d(jl       ,:) ; pt2d(jl       ,:) = 0.0_wp
-            zt2we(:,jl,1) = pt2d(iihom +jl,:) ; pt2d(iihom +jl,:) = 0.0_wp
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = jpreci * jpj
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
-         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write lateral conditions
-      iihom = nlci-nreci
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jl = 1, jpreci
-            pt2d(iihom+jl,:) = pt2d(iihom+jl,:) + zt2ew(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jpreci
-            pt2d(jpreci+jl,:) = pt2d(jpreci+jl,:) + zt2we(:,jl,2)
-            pt2d(iihom +jl,:) = pt2d(iihom +jl,:) + zt2ew(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jpreci
-            pt2d(jpreci+jl,:) = pt2d(jpreci+jl,:) + zt2we(:,jl,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj /= 2 ) THEN      ! Read lateral conditions
-         ijhom = nlcj - jprecj
-         DO jl = 1, jprecj
-            zt2sn(:,jl,1) = pt2d(:,ijhom +jl) ; pt2d(:,ijhom +jl) = 0.0_wp
-            zt2ns(:,jl,1) = pt2d(:,jl       ) ; pt2d(:,jl       ) = 0.0_wp
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = jprecj * jpi
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
-         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write lateral conditions
-      ijhom = nlcj-nrecj
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jl = 1, jprecj
-            pt2d(:,ijhom+jl) = pt2d(:,ijhom+jl) + zt2ns(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jprecj
-            pt2d(:,jprecj+jl) = pt2d(:,jprecj+jl) + zt2sn(:,jl,2)
-            pt2d(:,ijhom +jl) = pt2d(:,ijhom +jl) + zt2ns(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jprecj
-            pt2d(:,jprecj+jl) = pt2d(:,jprecj+jl) + zt2sn(:,jl,2)
-         END DO
-      END SELECT
-
-
-      ! 4. north fold treatment
-      ! -----------------------
-      !
-      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd      ( pt2d, cd_type, psgn )   ! only 1 northern proc, no mpp
-         CASE DEFAULT   ;   CALL mpp_lbc_north( pt2d, cd_type, psgn )   ! for all northern procs.
-         END SELECT
-         !
-      ENDIF
-      !
-      DEALLOCATE( zt2ns, zt2sn, zt2ew, zt2we )
-      !
-   END SUBROUTINE mpp_lnk_sum_2d
+   !!    mpp_lnk_sum_2d et 3D   ====>>>>>>   à virer du code !!!!
+   
+   
+   !!----------------------------------------------------------------------
+
+
 
    SUBROUTINE mppsend( ktyp, pmess, kbytes, kdest, md_req )
@@ -1874,59 +575,69 @@
    END SUBROUTINE mppscatter
 
-
+   !!----------------------------------------------------------------------
+   !!    ***  mppmax_a_int, mppmax_int, mppmax_a_real, mppmax_real  ***
+   !!   
+   !!----------------------------------------------------------------------
+   !!
    SUBROUTINE mppmax_a_int( ktab, kdim, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmax_a_int  ***
-      !!
-      !! ** Purpose :   Find maximum value in an integer layout array
-      !!
       !!----------------------------------------------------------------------
       INTEGER , INTENT(in   )                  ::   kdim   ! size of array
       INTEGER , INTENT(inout), DIMENSION(kdim) ::   ktab   ! input array
       INTEGER , INTENT(in   ), OPTIONAL        ::   kcom   !
-      !
-      INTEGER :: ierror, localcomm   ! temporary integer
+      INTEGER :: ierror, ilocalcomm   ! temporary integer
       INTEGER, DIMENSION(kdim) ::   iwork
       !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_max, localcomm, ierror )
-      !
+      ilocalcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   ilocalcomm = kcom
+      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_max, ilocalcomm, ierror )
       ktab(:) = iwork(:)
-      !
    END SUBROUTINE mppmax_a_int
-
-
+   !!
    SUBROUTINE mppmax_int( ktab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmax_int  ***
-      !!
-      !! ** Purpose :   Find maximum value in an integer layout array
-      !!
       !!----------------------------------------------------------------------
       INTEGER, INTENT(inout)           ::   ktab   ! ???
       INTEGER, INTENT(in   ), OPTIONAL ::   kcom   ! ???
-      !
-      INTEGER ::   ierror, iwork, localcomm   ! temporary integer
-      !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_max, localcomm, ierror )
-      !
+      INTEGER ::   ierror, iwork, ilocalcomm   ! temporary integer
+      !!----------------------------------------------------------------------
+      ilocalcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   ilocalcomm = kcom
+      CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_max, ilocalcomm, ierror )
       ktab = iwork
-      !
    END SUBROUTINE mppmax_int
-
-
+   !!
+   SUBROUTINE mppmax_a_real( ptab, kdim, kcom )
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(kdim), INTENT(inout) ::   ptab
+      INTEGER                  , INTENT(in   ) ::   kdim
+      INTEGER , OPTIONAL       , INTENT(in   ) ::   kcom
+      INTEGER :: ierror, ilocalcomm
+      REAL(wp), DIMENSION(kdim) ::  zwork
+      !!----------------------------------------------------------------------
+      ilocalcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   ilocalcomm = kcom
+      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_max, ilocalcomm, ierror )
+      ptab(:) = zwork(:)
+   END SUBROUTINE mppmax_a_real
+   !!
+   SUBROUTINE mppmax_real( ptab, kcom )
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(inout)           ::   ptab   ! ???
+      INTEGER , INTENT(in   ), OPTIONAL ::   kcom   ! ???
+      INTEGER  ::   ierror, ilocalcomm
+      REAL(wp) ::   zwork
+      !!----------------------------------------------------------------------
+      ilocalcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   ilocalcomm = kcom!
+      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_max, ilocalcomm, ierror )
+      ptab = zwork
+   END SUBROUTINE mppmax_real
+
+
+   !!----------------------------------------------------------------------
+   !!    ***  mppmin_a_int, mppmin_int, mppmin_a_real, mppmin_real  ***
+   !!   
+   !!----------------------------------------------------------------------
+   !!
    SUBROUTINE mppmin_a_int( ktab, kdim, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmin_a_int  ***
-      !!
-      !! ** Purpose :   Find minimum value in an integer layout array
-      !!
       !!----------------------------------------------------------------------
       INTEGER , INTENT( in  )                  ::   kdim   ! size of array
@@ -1934,298 +645,156 @@
       INTEGER , INTENT( in  ), OPTIONAL        ::   kcom   ! input array
       !!
-      INTEGER ::   ierror, localcomm   ! temporary integer
+      INTEGER ::   ierror, ilocalcomm   ! temporary integer
       INTEGER, DIMENSION(kdim) ::   iwork
       !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_min, localcomm, ierror )
-      !
+      ilocalcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   ilocalcomm = kcom
+      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_min, ilocalcomm, ierror )
       ktab(:) = iwork(:)
-      !
    END SUBROUTINE mppmin_a_int
-
-
+   !!
    SUBROUTINE mppmin_int( ktab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmin_int  ***
-      !!
-      !! ** Purpose :   Find minimum value in an integer layout array
-      !!
       !!----------------------------------------------------------------------
       INTEGER, INTENT(inout) ::   ktab      ! ???
       INTEGER , INTENT( in  ), OPTIONAL        ::   kcom        ! input array
       !!
-      INTEGER ::  ierror, iwork, localcomm
-      !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_min, localcomm, ierror )
-      !
+      INTEGER ::  ierror, iwork, ilocalcomm
+      !!----------------------------------------------------------------------
+      ilocalcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   ilocalcomm = kcom
+      CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_min, ilocalcomm, ierror )
       ktab = iwork
-      !
    END SUBROUTINE mppmin_int
-
-
-   SUBROUTINE mppsum_a_int( ktab, kdim )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsum_a_int  ***
-      !!
-      !! ** Purpose :   Global integer sum, 1D array case
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in   )                   ::   kdim   ! ???
-      INTEGER, INTENT(inout), DIMENSION (kdim) ::   ktab   ! ???
-      !
-      INTEGER :: ierror
-      INTEGER, DIMENSION (kdim) ::  iwork
-      !!----------------------------------------------------------------------
-      !
-      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_sum, mpi_comm_opa, ierror )
-      !
-      ktab(:) = iwork(:)
-      !
-   END SUBROUTINE mppsum_a_int
-
-
-   SUBROUTINE mppsum_int( ktab )
-      !!----------------------------------------------------------------------
-      !!                 ***  routine mppsum_int  ***
-      !!
-      !! ** Purpose :   Global integer sum
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(inout) ::   ktab
-      !!
-      INTEGER :: ierror, iwork
-      !!----------------------------------------------------------------------
-      !
-      CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_sum, mpi_comm_opa, ierror )
-      !
-      ktab = iwork
-      !
-   END SUBROUTINE mppsum_int
-
-
-   SUBROUTINE mppmax_a_real( ptab, kdim, kcom )
-      !!----------------------------------------------------------------------
-      !!                 ***  routine mppmax_a_real  ***
-      !!
-      !! ** Purpose :   Maximum
-      !!
+   !!
+   SUBROUTINE mppmin_a_real( ptab, kdim, kcom )
       !!----------------------------------------------------------------------
       INTEGER , INTENT(in   )                  ::   kdim
       REAL(wp), INTENT(inout), DIMENSION(kdim) ::   ptab
       INTEGER , INTENT(in   ), OPTIONAL        ::   kcom
-      !
-      INTEGER :: ierror, localcomm
-      REAL(wp), DIMENSION(kdim) ::  zwork
-      !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) ) localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_max, localcomm, ierror )
-      ptab(:) = zwork(:)
-      !
-   END SUBROUTINE mppmax_a_real
-
-
-   SUBROUTINE mppmax_real( ptab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmax_real  ***
-      !!
-      !! ** Purpose :   Maximum
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), INTENT(inout)           ::   ptab   ! ???
-      INTEGER , INTENT(in   ), OPTIONAL ::   kcom   ! ???
-      !!
-      INTEGER  ::   ierror, localcomm
-      REAL(wp) ::   zwork
-      !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_max, localcomm, ierror )
-      ptab = zwork
-      !
-   END SUBROUTINE mppmax_real
-
-   SUBROUTINE mppmax_real_multiple( ptab, NUM , kcom  )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmax_real  ***
-      !!
-      !! ** Purpose :   Maximum
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:) ,  INTENT(inout)           ::   ptab   ! ???
-      INTEGER , INTENT(in   )           ::   NUM
-      INTEGER , INTENT(in   ), OPTIONAL ::   kcom   ! ???
-      !!
-      INTEGER  ::   ierror, localcomm
-      REAL(wp) , POINTER , DIMENSION(:) ::   zwork
-      !!----------------------------------------------------------------------
-      !
-      CALL wrk_alloc(NUM , zwork)
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, NUM, mpi_double_precision, mpi_max, localcomm, ierror )
-      ptab = zwork
-      CALL wrk_dealloc(NUM , zwork)
-      !
-   END SUBROUTINE mppmax_real_multiple
-
-
-   SUBROUTINE mppmin_a_real( ptab, kdim, kcom )
-      !!----------------------------------------------------------------------
-      !!                 ***  routine mppmin_a_real  ***
-      !!
-      !! ** Purpose :   Minimum of REAL, array case
-      !!
-      !!-----------------------------------------------------------------------
-      INTEGER , INTENT(in   )                  ::   kdim
-      REAL(wp), INTENT(inout), DIMENSION(kdim) ::   ptab
-      INTEGER , INTENT(in   ), OPTIONAL        ::   kcom
-      !!
-      INTEGER :: ierror, localcomm
+      INTEGER :: ierror, ilocalcomm
       REAL(wp), DIMENSION(kdim) ::   zwork
       !!-----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) ) localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_min, localcomm, ierror )
+      ilocalcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   ilocalcomm = kcom
+      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_min, ilocalcomm, ierror )
       ptab(:) = zwork(:)
-      !
    END SUBROUTINE mppmin_a_real
-
-
+   !!
    SUBROUTINE mppmin_real( ptab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmin_real  ***
-      !!
-      !! ** Purpose :   minimum of REAL, scalar case
-      !!
       !!-----------------------------------------------------------------------
       REAL(wp), INTENT(inout)           ::   ptab        !
       INTEGER , INTENT(in   ), OPTIONAL :: kcom
-      !!
-      INTEGER  ::   ierror
-      REAL(wp) ::   zwork
-      INTEGER :: localcomm
-      !!-----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_min, localcomm, ierror )
-      ptab = zwork
-      !
-   END SUBROUTINE mppmin_real
-
-
-   SUBROUTINE mppsum_a_real( ptab, kdim, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsum_a_real  ***
-      !!
-      !! ** Purpose :   global sum, REAL ARRAY argument case
-      !!
-      !!-----------------------------------------------------------------------
-      INTEGER , INTENT( in )                     ::   kdim      ! size of ptab
-      REAL(wp), DIMENSION(kdim), INTENT( inout ) ::   ptab      ! input array
-      INTEGER , INTENT( in ), OPTIONAL           :: kcom
-      !!
-      INTEGER                   ::   ierror    ! temporary integer
-      INTEGER                   ::   localcomm
-      REAL(wp), DIMENSION(kdim) ::   zwork     ! temporary workspace
-      !!-----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_sum, localcomm, ierror )
-      ptab(:) = zwork(:)
-      !
-   END SUBROUTINE mppsum_a_real
-
-
-   SUBROUTINE mppsum_real( ptab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsum_real  ***
-      !!
-      !! ** Purpose :   global sum, SCALAR argument case
-      !!
-      !!-----------------------------------------------------------------------
-      REAL(wp), INTENT(inout)           ::   ptab   ! input scalar
-      INTEGER , INTENT(in   ), OPTIONAL ::   kcom
-      !!
-      INTEGER  ::   ierror, localcomm
+      INTEGER  ::   ierror, ilocalcomm
       REAL(wp) ::   zwork
       !!-----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) ) localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_sum, localcomm, ierror )
+      ilocalcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   ilocalcomm = kcom
+      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_min, ilocalcomm, ierror )
       ptab = zwork
-      !
+   END SUBROUTINE mppmin_real
+
+
+   !!----------------------------------------------------------------------
+   !!    ***  mppsum_a_int, mppsum_int, mppsum_a_real, mppsum_real  ***
+   !!   
+   !!   Global sum of 1D array or a variable (integer, real or complex)
+   !!----------------------------------------------------------------------
+   !!
+   SUBROUTINE mppsum_a_int( ktab, kdim )
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in   )                   ::   kdim   ! ???
+      INTEGER, INTENT(inout), DIMENSION (kdim) ::   ktab   ! ???
+      INTEGER :: ierror
+      INTEGER, DIMENSION (kdim) ::  iwork
+      !!----------------------------------------------------------------------
+      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_sum, mpi_comm_opa, ierror )
+      ktab(:) = iwork(:)
+   END SUBROUTINE mppsum_a_int
+   !!
+   SUBROUTINE mppsum_int( ktab )
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(inout) ::   ktab
+      INTEGER :: ierror, iwork
+      !!----------------------------------------------------------------------
+      CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_sum, mpi_comm_opa, ierror )
+      ktab = iwork
+   END SUBROUTINE mppsum_int
+   !!
+   SUBROUTINE mppsum_a_real( ptab, kdim, kcom )
+      !!-----------------------------------------------------------------------
+      INTEGER                  , INTENT(in   ) ::   kdim   ! size of ptab
+      REAL(wp), DIMENSION(kdim), INTENT(inout) ::   ptab   ! input array
+      INTEGER , OPTIONAL       , INTENT(in   ) ::   kcom   ! specific communicator
+      INTEGER  ::   ierror, ilocalcomm    ! local integer
+      REAL(wp) ::   zwork(kdim)           ! local workspace
+      !!-----------------------------------------------------------------------
+      ilocalcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   ilocalcomm = kcom
+      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_sum, ilocalcomm, ierror )
+      ptab(:) = zwork(:)
+   END SUBROUTINE mppsum_a_real
+   !!
+   SUBROUTINE mppsum_real( ptab, kcom )
+      !!-----------------------------------------------------------------------
+      REAL(wp)          , INTENT(inout)           ::   ptab   ! input scalar
+      INTEGER , OPTIONAL, INTENT(in   ) ::   kcom
+      INTEGER  ::   ierror, ilocalcomm
+      REAL(wp) ::   zwork
+      !!-----------------------------------------------------------------------
+      ilocalcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   ilocalcomm = kcom
+      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_sum, ilocalcomm, ierror )
+      ptab = zwork
    END SUBROUTINE mppsum_real
-
-
+   !!
    SUBROUTINE mppsum_realdd( ytab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsum_realdd ***
-      !!
-      !! ** Purpose :   global sum in Massively Parallel Processing
-      !!                SCALAR argument case for double-double precision
-      !!
       !!-----------------------------------------------------------------------
-      COMPLEX(wp), INTENT(inout)           ::   ytab    ! input scalar
-      INTEGER    , INTENT(in   ), OPTIONAL ::   kcom
-      !
-      INTEGER     ::   ierror
-      INTEGER     ::   localcomm
+      COMPLEX(wp)          , INTENT(inout) ::   ytab    ! input scalar
+      INTEGER    , OPTIONAL, INTENT(in   ) ::   kcom
+      INTEGER     ::   ierror, ilocalcomm
       COMPLEX(wp) ::   zwork
       !!-----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      ! reduce local sums into global sum
-      CALL MPI_ALLREDUCE (ytab, zwork, 1, MPI_DOUBLE_COMPLEX, MPI_SUMDD, localcomm, ierror )
+      ilocalcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   ilocalcomm = kcom
+      CALL MPI_ALLREDUCE( ytab, zwork, 1, MPI_DOUBLE_COMPLEX, MPI_SUMDD, ilocalcomm, ierror )
       ytab = zwork
-      !
    END SUBROUTINE mppsum_realdd
-
-
+   !!
    SUBROUTINE mppsum_a_realdd( ytab, kdim, kcom )
       !!----------------------------------------------------------------------
-      !!                  ***  routine mppsum_a_realdd  ***
-      !!
-      !! ** Purpose :   global sum in Massively Parallel Processing
-      !!                COMPLEX ARRAY case for double-double precision
-      !!
-      !!-----------------------------------------------------------------------
       INTEGER                     , INTENT(in   ) ::   kdim   ! size of ytab
       COMPLEX(wp), DIMENSION(kdim), INTENT(inout) ::   ytab   ! input array
       INTEGER    , OPTIONAL       , INTENT(in   ) ::   kcom
-      !
-      INTEGER:: ierror, localcomm    ! local integer
+      INTEGER:: ierror, ilocalcomm    ! local integer
       COMPLEX(wp), DIMENSION(kdim) :: zwork     ! temporary workspace
       !!-----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL MPI_ALLREDUCE( ytab, zwork, kdim, MPI_DOUBLE_COMPLEX, MPI_SUMDD, localcomm, ierror )
+      ilocalcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   ilocalcomm = kcom
+      CALL MPI_ALLREDUCE( ytab, zwork, kdim, MPI_DOUBLE_COMPLEX, MPI_SUMDD, ilocalcomm, ierror )
       ytab(:) = zwork(:)
-      !
    END SUBROUTINE mppsum_a_realdd
+   
+
+   SUBROUTINE mppmax_real_multiple( pt1d, kdim, kcom  )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmax_real  ***
+      !!
+      !! ** Purpose :   Maximum across processor of each element of a 1D arrays
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(kdim), INTENT(inout) ::   pt1d   ! 1D arrays
+      INTEGER                  , INTENT(in   ) ::   kdim
+      INTEGER , OPTIONAL       , INTENT(in   ) ::   kcom   ! local communicator
+      !!
+      INTEGER  ::   ierror, ilocalcomm
+      REAL(wp), DIMENSION(kdim) ::  zwork
+      !!----------------------------------------------------------------------
+      ilocalcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   ilocalcomm = kcom
+      !
+      CALL mpi_allreduce( pt1d, zwork, kdim, mpi_double_precision, mpi_max, ilocalcomm, ierror )
+      pt1d(:) = zwork(:)
+      !
+   END SUBROUTINE mppmax_real_multiple
 
 
@@ -2243,5 +812,5 @@
       REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   pmask   ! Local mask
       REAL(wp)                     , INTENT(  out) ::   pmin    ! Global minimum of ptab
-      INTEGER                      , INTENT(  out) ::   ki, kj   ! index of minimum in global frame
+      INTEGER                      , INTENT(  out) ::   ki, kj  ! index of minimum in global frame
       !
       INTEGER :: ierror
@@ -2251,6 +820,6 @@
       !!-----------------------------------------------------------------------
       !
-      zmin  = MINVAL( ptab(:,:) , mask= pmask == 1.e0 )
-      ilocs = MINLOC( ptab(:,:) , mask= pmask == 1.e0 )
+      zmin  = MINVAL( ptab(:,:) , mask= pmask == 1._wp )
+      ilocs = MINLOC( ptab(:,:) , mask= pmask == 1._wp )
       !
       ki = ilocs(1) + nimpp - 1
@@ -2279,9 +848,9 @@
       !!
       !!--------------------------------------------------------------------------
-      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   ptab         ! Local 2D array
-      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   pmask        ! Local mask
-      REAL(wp)                         , INTENT(  out) ::   pmin         ! Global minimum of ptab
-      INTEGER                          , INTENT(  out) ::   ki, kj, kk   ! index of minimum in global frame
-      !!
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   ptab         ! Local 2D array
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pmask        ! Local mask
+      REAL(wp)                  , INTENT(  out) ::   pmin         ! Global minimum of ptab
+      INTEGER                   , INTENT(  out) ::   ki, kj, kk   ! index of minimum in global frame
+      !
       INTEGER  ::   ierror
       REAL(wp) ::   zmin     ! local minimum
@@ -2290,6 +859,6 @@
       !!-----------------------------------------------------------------------
       !
-      zmin  = MINVAL( ptab(:,:,:) , mask= pmask == 1.e0 )
-      ilocs = MINLOC( ptab(:,:,:) , mask= pmask == 1.e0 )
+      zmin  = MINVAL( ptab(:,:,:) , mask= pmask == 1._wp )
+      ilocs = MINLOC( ptab(:,:,:) , mask= pmask == 1._wp )
       !
       ki = ilocs(1) + nimpp - 1
@@ -2297,6 +866,6 @@
       kk = ilocs(3)
       !
-      zain(1,:)=zmin
-      zain(2,:)=ki+10000.*kj+100000000.*kk
+      zain(1,:) = zmin
+      zain(2,:) = ki + 10000.*kj + 100000000.*kk
       !
       CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MINLOC,MPI_COMM_OPA,ierror)
@@ -2331,6 +900,6 @@
       !!-----------------------------------------------------------------------
       !
-      zmax  = MAXVAL( ptab(:,:) , mask= pmask == 1.e0 )
-      ilocs = MAXLOC( ptab(:,:) , mask= pmask == 1.e0 )
+      zmax  = MAXVAL( ptab(:,:) , mask= pmask == 1._wp )
+      ilocs = MAXLOC( ptab(:,:) , mask= pmask == 1._wp )
       !
       ki = ilocs(1) + nimpp - 1
@@ -2359,17 +928,17 @@
       !!
       !!--------------------------------------------------------------------------
-      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   ptab         ! Local 2D array
-      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   pmask        ! Local mask
-      REAL(wp)                         , INTENT(  out) ::   pmax         ! Global maximum of ptab
-      INTEGER                          , INTENT(  out) ::   ki, kj, kk   ! index of maximum in global frame
-      !!
-      REAL(wp) :: zmax   ! local maximum
+      REAL(wp), DIMENSION (:,:,:), INTENT(in   ) ::   ptab         ! Local 2D array
+      REAL(wp), DIMENSION (:,:,:), INTENT(in   ) ::   pmask        ! Local mask
+      REAL(wp)                   , INTENT(  out) ::   pmax         ! Global maximum of ptab
+      INTEGER                    , INTENT(  out) ::   ki, kj, kk   ! index of maximum in global frame
+      !
+      INTEGER  ::   ierror   ! local integer
+      REAL(wp) ::   zmax     ! local maximum
       REAL(wp), DIMENSION(2,1) ::   zain, zaout
       INTEGER , DIMENSION(3)   ::   ilocs
-      INTEGER :: ierror
       !!-----------------------------------------------------------------------
       !
-      zmax  = MAXVAL( ptab(:,:,:) , mask= pmask == 1.e0 )
-      ilocs = MAXLOC( ptab(:,:,:) , mask= pmask == 1.e0 )
+      zmax  = MAXVAL( ptab(:,:,:) , mask= pmask == 1._wp )
+      ilocs = MAXLOC( ptab(:,:,:) , mask= pmask == 1._wp )
       !
       ki = ilocs(1) + nimpp - 1
@@ -2377,6 +946,6 @@
       kk = ilocs(3)
       !
-      zain(1,:)=zmax
-      zain(2,:)=ki+10000.*kj+100000000.*kk
+      zain(1,:) = zmax
+      zain(2,:) = ki + 10000.*kj + 100000000.*kk
       !
       CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MAXLOC,MPI_COMM_OPA,ierror)
@@ -2422,5 +991,4 @@
 
    SUBROUTINE mpp_comm_free( kcom )
-      !!----------------------------------------------------------------------
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kcom
@@ -2680,971 +1248,4 @@
 
 
-   SUBROUTINE mpp_lbc_north_3d( pt3d, cd_type, psgn )
-      !!---------------------------------------------------------------------
-      !!                   ***  routine mpp_lbc_north_3d  ***
-      !!
-      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
-      !!              in mpp configuration in case of jpn1 > 1
-      !!
-      !! ** Method  :   North fold condition and mpp with more than one proc
-      !!              in i-direction require a specific treatment. We gather
-      !!              the 4 northern lines of the global domain on 1 processor
-      !!              and apply lbc north-fold on this sub array. Then we
-      !!              scatter the north fold array back to the processors.
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pt3d      ! 3D array on which the b.c. is applied
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
-      !                                                              !   = T ,  U , V , F or W  gridpoints
-      REAL(wp)                        , INTENT(in   ) ::   psgn      ! = -1. the sign change across the north fold 
-      !!                                                             ! =  1. , the sign is kept
-      INTEGER ::   ji, jj, jr, jk
-      INTEGER ::   ierr, itaille, ildi, ilei, iilb
-      INTEGER ::   ijpj, ijpjm1, ij, iproc
-      INTEGER, DIMENSION (jpmaxngh)          ::   ml_req_nf          !for mpi_isend when avoiding mpi_allgather
-      INTEGER                                ::   ml_err             ! for mpi_isend when avoiding mpi_allgather
-      INTEGER, DIMENSION(MPI_STATUS_SIZE)    ::   ml_stat            ! for mpi_isend when avoiding mpi_allgather
-      !                                                              ! Workspace for message transfers avoiding mpi_allgather
-      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: ztab
-      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: znorthloc, zfoldwk      
-      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE   :: znorthgloio
-      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: ztabl, ztabr
-
-      INTEGER :: istatus(mpi_status_size)
-      INTEGER :: iflag
-      !!----------------------------------------------------------------------
-      !
-      ALLOCATE( ztab(jpiglo,4,jpk) , znorthloc(jpi,4,jpk), zfoldwk(jpi,4,jpk), znorthgloio(jpi,4,jpk,jpni) )
-      ALLOCATE( ztabl(jpi,4,jpk), ztabr(jpi*jpmaxngh, 4, jpk) ) 
-
-      ijpj   = 4
-      ijpjm1 = 3
-      !
-      znorthloc(:,:,:) = 0
-      DO jk = 1, jpk
-         DO jj = nlcj - ijpj +1, nlcj          ! put in xnorthloc the last 4 jlines of pt3d
-            ij = jj - nlcj + ijpj
-            znorthloc(:,ij,jk) = pt3d(:,jj,jk)
-         END DO
-      END DO
-      !
-      !                                     ! Build in procs of ncomm_north the znorthgloio
-      itaille = jpi * jpk * ijpj
-
-      IF ( l_north_nogather ) THEN
-         !
-        ztabr(:,:,:) = 0
-        ztabl(:,:,:) = 0
-
-        DO jk = 1, jpk
-           DO jj = nlcj-ijpj+1, nlcj          ! First put local values into the global array
-              ij = jj - nlcj + ijpj
-              DO ji = nfsloop, nfeloop
-                 ztabl(ji,ij,jk) = pt3d(ji,jj,jk)
-              END DO
-           END DO
-        END DO
-
-         DO jr = 1,nsndto
-            IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
-              CALL mppsend( 5, znorthloc, itaille, nfipproc(isendto(jr),jpnj), ml_req_nf(jr) )
-            ENDIF
-         END DO
-         DO jr = 1,nsndto
-            iproc = nfipproc(isendto(jr),jpnj)
-            IF(iproc .ne. -1) THEN
-               ilei = nleit (iproc+1)
-               ildi = nldit (iproc+1)
-               iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj)
-            ENDIF
-            IF((iproc .ne. (narea-1)) .and. (iproc .ne. -1)) THEN
-              CALL mpprecv(5, zfoldwk, itaille, iproc)
-              DO jk = 1, jpk
-                 DO jj = 1, ijpj
-                    DO ji = ildi, ilei
-                       ztabr(iilb+ji,jj,jk) = zfoldwk(ji,jj,jk)
-                    END DO
-                 END DO
-              END DO
-           ELSE IF (iproc .eq. (narea-1)) THEN
-              DO jk = 1, jpk
-                 DO jj = 1, ijpj
-                    DO ji = ildi, ilei
-                       ztabr(iilb+ji,jj,jk) = pt3d(ji,nlcj-ijpj+jj,jk)
-                    END DO
-                 END DO
-              END DO
-           ENDIF
-         END DO
-         IF (l_isend) THEN
-            DO jr = 1,nsndto
-               IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
-                  CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
-               ENDIF    
-            END DO
-         ENDIF
-         CALL mpp_lbc_nfd( ztabl, ztabr, cd_type, psgn )   ! North fold boundary condition
-         DO jk = 1, jpk
-            DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt3d
-               ij = jj - nlcj + ijpj
-               DO ji= 1, nlci
-                  pt3d(ji,jj,jk) = ztabl(ji,ij,jk)
-               END DO
-            END DO
-         END DO
-         !
-
-      ELSE
-         CALL MPI_ALLGATHER( znorthloc  , itaille, MPI_DOUBLE_PRECISION,                &
-            &                znorthgloio, itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
-         !
-         ztab(:,:,:) = 0.e0
-         DO jr = 1, ndim_rank_north         ! recover the global north array
-            iproc = nrank_north(jr) + 1
-            ildi  = nldit (iproc)
-            ilei  = nleit (iproc)
-            iilb  = nimppt(iproc)
-            DO jk = 1, jpk
-               DO jj = 1, ijpj
-                  DO ji = ildi, ilei
-                    ztab(ji+iilb-1,jj,jk) = znorthgloio(ji,jj,jk,jr)
-                  END DO
-               END DO
-            END DO
-         END DO
-         CALL lbc_nfd( ztab, cd_type, psgn )   ! North fold boundary condition
-         !
-         DO jk = 1, jpk
-            DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt3d
-               ij = jj - nlcj + ijpj
-               DO ji= 1, nlci
-                  pt3d(ji,jj,jk) = ztab(ji+nimpp-1,ij,jk)
-               END DO
-            END DO
-         END DO
-         !
-      ENDIF
-      !
-      ! The ztab array has been either:
-      !  a. Fully populated by the mpi_allgather operation or
-      !  b. Had the active points for this domain and northern neighbours populated
-      !     by peer to peer exchanges
-      ! Either way the array may be folded by lbc_nfd and the result for the span of
-      ! this domain will be identical.
-      !
-      DEALLOCATE( ztab, znorthloc, zfoldwk, znorthgloio )
-      DEALLOCATE( ztabl, ztabr ) 
-      !
-   END SUBROUTINE mpp_lbc_north_3d
-
-
-   SUBROUTINE mpp_lbc_north_2d( pt2d, cd_type, psgn)
-      !!---------------------------------------------------------------------
-      !!                   ***  routine mpp_lbc_north_2d  ***
-      !!
-      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
-      !!              in mpp configuration in case of jpn1 > 1 (for 2d array )
-      !!
-      !! ** Method  :   North fold condition and mpp with more than one proc
-      !!              in i-direction require a specific treatment. We gather
-      !!              the 4 northern lines of the global domain on 1 processor
-      !!              and apply lbc north-fold on this sub array. Then we
-      !!              scatter the north fold array back to the processors.
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d      ! 2D array on which the b.c. is applied
-      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type   ! nature of pt2d grid-points
-      !                                                          !   = T ,  U , V , F or W  gridpoints
-      REAL(wp)                    , INTENT(in   ) ::   psgn      ! = -1. the sign change across the north fold 
-      !!                                                             ! =  1. , the sign is kept
-      INTEGER ::   ji, jj, jr
-      INTEGER ::   ierr, itaille, ildi, ilei, iilb
-      INTEGER ::   ijpj, ijpjm1, ij, iproc
-      INTEGER, DIMENSION (jpmaxngh)      ::   ml_req_nf          !for mpi_isend when avoiding mpi_allgather
-      INTEGER                            ::   ml_err             ! for mpi_isend when avoiding mpi_allgather
-      INTEGER, DIMENSION(MPI_STATUS_SIZE)::   ml_stat            ! for mpi_isend when avoiding mpi_allgather
-      !                                                              ! Workspace for message transfers avoiding mpi_allgather
-      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE   :: ztab
-      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE   :: znorthloc, zfoldwk      
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   :: znorthgloio
-      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE   :: ztabl, ztabr
-      INTEGER :: istatus(mpi_status_size)
-      INTEGER :: iflag
-      !!----------------------------------------------------------------------
-      !
-      ALLOCATE( ztab(jpiglo,4), znorthloc(jpi,4), zfoldwk(jpi,4), znorthgloio(jpi,4,jpni) )
-      ALLOCATE( ztabl(jpi,4), ztabr(jpi*jpmaxngh, 4) ) 
-      !
-      ijpj   = 4
-      ijpjm1 = 3
-      !
-      DO jj = nlcj-ijpj+1, nlcj             ! put in znorthloc the last 4 jlines of pt2d
-         ij = jj - nlcj + ijpj
-         znorthloc(:,ij) = pt2d(:,jj)
-      END DO
-
-      !                                     ! Build in procs of ncomm_north the znorthgloio
-      itaille = jpi * ijpj
-      IF ( l_north_nogather ) THEN
-         !
-         ! Avoid the use of mpi_allgather by exchanging only with the processes already identified 
-         ! (in nemo_northcomms) as being  involved in this process' northern boundary exchange
-         !
-         ztabr(:,:) = 0
-         ztabl(:,:) = 0
-
-         DO jj = nlcj-ijpj+1, nlcj          ! First put local values into the global array
-            ij = jj - nlcj + ijpj
-              DO ji = nfsloop, nfeloop
-               ztabl(ji,ij) = pt2d(ji,jj)
-            END DO
-         END DO
-
-         DO jr = 1,nsndto
-            IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
-               CALL mppsend(5, znorthloc, itaille, nfipproc(isendto(jr),jpnj), ml_req_nf(jr))
-            ENDIF
-         END DO
-         DO jr = 1,nsndto
-            iproc = nfipproc(isendto(jr),jpnj)
-            IF(iproc .ne. -1) THEN
-               ilei = nleit (iproc+1)
-               ildi = nldit (iproc+1)
-               iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj)
-            ENDIF
-            IF((iproc .ne. (narea-1)) .and. (iproc .ne. -1)) THEN
-              CALL mpprecv(5, zfoldwk, itaille, iproc)
-              DO jj = 1, ijpj
-                 DO ji = ildi, ilei
-                    ztabr(iilb+ji,jj) = zfoldwk(ji,jj)
-                 END DO
-              END DO
-            ELSE IF (iproc .eq. (narea-1)) THEN
-              DO jj = 1, ijpj
-                 DO ji = ildi, ilei
-                    ztabr(iilb+ji,jj) = pt2d(ji,nlcj-ijpj+jj)
-                 END DO
-              END DO
-            ENDIF
-         END DO
-         IF (l_isend) THEN
-            DO jr = 1,nsndto
-               IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
-                  CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
-               ENDIF
-            END DO
-         ENDIF
-         CALL mpp_lbc_nfd( ztabl, ztabr, cd_type, psgn )   ! North fold boundary condition
-         !
-         DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
-            ij = jj - nlcj + ijpj
-            DO ji = 1, nlci
-               pt2d(ji,jj) = ztabl(ji,ij)
-            END DO
-         END DO
-         !
-      ELSE
-         CALL MPI_ALLGATHER( znorthloc  , itaille, MPI_DOUBLE_PRECISION,        &
-            &                znorthgloio, itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
-         !
-         ztab(:,:) = 0.e0
-         DO jr = 1, ndim_rank_north            ! recover the global north array
-            iproc = nrank_north(jr) + 1
-            ildi = nldit (iproc)
-            ilei = nleit (iproc)
-            iilb = nimppt(iproc)
-            DO jj = 1, ijpj
-               DO ji = ildi, ilei
-                  ztab(ji+iilb-1,jj) = znorthgloio(ji,jj,jr)
-               END DO
-            END DO
-         END DO
-         CALL lbc_nfd( ztab, cd_type, psgn )   ! North fold boundary condition
-         !
-         DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
-            ij = jj - nlcj + ijpj
-            DO ji = 1, nlci
-               pt2d(ji,jj) = ztab(ji+nimpp-1,ij)
-            END DO
-         END DO
-         !
-      ENDIF
-      DEALLOCATE( ztab, znorthloc, zfoldwk, znorthgloio )
-      DEALLOCATE( ztabl, ztabr ) 
-      !
-   END SUBROUTINE mpp_lbc_north_2d
-
-   SUBROUTINE mpp_lbc_north_2d_multiple( pt2d_array, cd_type, psgn, num_fields)
-      !!---------------------------------------------------------------------
-      !!                   ***  routine mpp_lbc_north_2d  ***
-      !!
-      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
-      !!              in mpp configuration in case of jpn1 > 1
-      !!              (for multiple 2d arrays )
-      !!
-      !! ** Method  :   North fold condition and mpp with more than one proc
-      !!              in i-direction require a specific treatment. We gather
-      !!              the 4 northern lines of the global domain on 1 processor
-      !!              and apply lbc north-fold on this sub array. Then we
-      !!              scatter the north fold array back to the processors.
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER ,  INTENT (in   ) ::   num_fields  ! number of variables contained in pt2d
-      TYPE( arrayptr ), DIMENSION(:) :: pt2d_array
-      CHARACTER(len=1), DIMENSION(:), INTENT(in   ) ::   cd_type   ! nature of pt2d grid-points
-      !                                                          !   = T ,  U , V , F or W  gridpoints
-      REAL(wp), DIMENSION(:), INTENT(in   ) ::   psgn      ! = -1. the sign change across the north fold 
-      !!                                                             ! =  1. , the sign is kept
-      INTEGER ::   ji, jj, jr, jk
-      INTEGER ::   ierr, itaille, ildi, ilei, iilb
-      INTEGER ::   ijpj, ijpjm1, ij, iproc
-      INTEGER, DIMENSION (jpmaxngh)      ::   ml_req_nf          !for mpi_isend when avoiding mpi_allgather
-      INTEGER                            ::   ml_err             ! for mpi_isend when avoiding mpi_allgather
-      INTEGER, DIMENSION(MPI_STATUS_SIZE)::   ml_stat            ! for mpi_isend when avoiding mpi_allgather
-      !                                                              ! Workspace for message transfers avoiding mpi_allgather
-      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: ztab
-      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: znorthloc, zfoldwk
-      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE   :: znorthgloio
-      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: ztabl, ztabr
-      INTEGER :: istatus(mpi_status_size)
-      INTEGER :: iflag
-      !!----------------------------------------------------------------------
-      !
-      ALLOCATE( ztab(jpiglo,4,num_fields), znorthloc(jpi,4,num_fields), zfoldwk(jpi,4,num_fields),   &
-            &   znorthgloio(jpi,4,num_fields,jpni) )   ! expanded to 3 dimensions
-      ALLOCATE( ztabl(jpi,4,num_fields), ztabr(jpi*jpmaxngh, 4,num_fields) )
-      !
-      ijpj   = 4
-      ijpjm1 = 3
-      !
-      
-      DO jk = 1, num_fields
-         DO jj = nlcj-ijpj+1, nlcj             ! put in znorthloc the last 4 jlines of pt2d (for every variable)
-            ij = jj - nlcj + ijpj
-            znorthloc(:,ij,jk) = pt2d_array(jk)%pt2d(:,jj)
-         END DO
-      END DO
-      !                                     ! Build in procs of ncomm_north the znorthgloio
-      itaille = jpi * ijpj
-                                                                  
-      IF ( l_north_nogather ) THEN
-         !
-         ! Avoid the use of mpi_allgather by exchanging only with the processes already identified 
-         ! (in nemo_northcomms) as being  involved in this process' northern boundary exchange
-         !
-         ztabr(:,:,:) = 0
-         ztabl(:,:,:) = 0
-
-         DO jk = 1, num_fields
-            DO jj = nlcj-ijpj+1, nlcj          ! First put local values into the global array
-               ij = jj - nlcj + ijpj
-               DO ji = nfsloop, nfeloop
-                  ztabl(ji,ij,jk) = pt2d_array(jk)%pt2d(ji,jj)
-               END DO
-            END DO
-         END DO
-
-         DO jr = 1,nsndto
-            IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
-               CALL mppsend(5, znorthloc, itaille*num_fields, nfipproc(isendto(jr),jpnj), ml_req_nf(jr)) ! Buffer expanded "num_fields" times
-            ENDIF
-         END DO
-         DO jr = 1,nsndto
-            iproc = nfipproc(isendto(jr),jpnj)
-            IF(iproc .ne. -1) THEN
-               ilei = nleit (iproc+1)
-               ildi = nldit (iproc+1)
-               iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj)
-            ENDIF
-            IF((iproc .ne. (narea-1)) .and. (iproc .ne. -1)) THEN
-              CALL mpprecv(5, zfoldwk, itaille*num_fields, iproc) ! Buffer expanded "num_fields" times
-              DO jk = 1 , num_fields
-                 DO jj = 1, ijpj
-                    DO ji = ildi, ilei
-                       ztabr(iilb+ji,jj,jk) = zfoldwk(ji,jj,jk)       ! Modified to 3D
-                    END DO
-                 END DO
-              END DO
-            ELSE IF (iproc .eq. (narea-1)) THEN
-              DO jk = 1, num_fields
-                 DO jj = 1, ijpj
-                    DO ji = ildi, ilei
-                          ztabr(iilb+ji,jj,jk) = pt2d_array(jk)%pt2d(ji,nlcj-ijpj+jj)       ! Modified to 3D
-                    END DO
-                 END DO
-              END DO
-            ENDIF
-         END DO
-         IF (l_isend) THEN
-            DO jr = 1,nsndto
-               IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
-                  CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
-               ENDIF
-            END DO
-         ENDIF
-         !
-         DO ji = 1, num_fields     ! Loop to manage 3D variables
-            CALL mpp_lbc_nfd( ztabl(:,:,ji), ztabr(:,:,ji), cd_type(ji), psgn(ji) )  ! North fold boundary condition
-         END DO
-         !
-         DO jk = 1, num_fields
-            DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
-               ij = jj - nlcj + ijpj
-               DO ji = 1, nlci
-                  pt2d_array(jk)%pt2d(ji,jj) = ztabl(ji,ij,jk)       ! Modified to 3D
-               END DO
-            END DO
-         END DO
-         
-         !
-      ELSE
-         !
-         CALL MPI_ALLGATHER( znorthloc  , itaille*num_fields, MPI_DOUBLE_PRECISION,        &
-            &                znorthgloio, itaille*num_fields, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
-         !
-         ztab(:,:,:) = 0.e0
-         DO jk = 1, num_fields
-            DO jr = 1, ndim_rank_north            ! recover the global north array
-               iproc = nrank_north(jr) + 1
-               ildi = nldit (iproc)
-               ilei = nleit (iproc)
-               iilb = nimppt(iproc)
-               DO jj = 1, ijpj
-                  DO ji = ildi, ilei
-                     ztab(ji+iilb-1,jj,jk) = znorthgloio(ji,jj,jk,jr)
-                  END DO
-               END DO
-            END DO
-         END DO
-         
-         DO ji = 1, num_fields
-            CALL lbc_nfd( ztab(:,:,ji), cd_type(ji), psgn(ji) )   ! North fold boundary condition
-         END DO
-         !
-         DO jk = 1, num_fields
-            DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
-               ij = jj - nlcj + ijpj
-               DO ji = 1, nlci
-                  pt2d_array(jk)%pt2d(ji,jj) = ztab(ji+nimpp-1,ij,jk)
-               END DO
-            END DO
-         END DO
-         !
-         !
-      ENDIF
-      DEALLOCATE( ztab, znorthloc, zfoldwk, znorthgloio )
-      DEALLOCATE( ztabl, ztabr )
-      !
-   END SUBROUTINE mpp_lbc_north_2d_multiple
-
-   SUBROUTINE mpp_lbc_north_e( pt2d, cd_type, psgn)
-      !!---------------------------------------------------------------------
-      !!                   ***  routine mpp_lbc_north_2d  ***
-      !!
-      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
-      !!              in mpp configuration in case of jpn1 > 1 and for 2d
-      !!              array with outer extra halo
-      !!
-      !! ** Method  :   North fold condition and mpp with more than one proc
-      !!              in i-direction require a specific treatment. We gather
-      !!              the 4+2*jpr2dj northern lines of the global domain on 1
-      !!              processor and apply lbc north-fold on this sub array.
-      !!              Then we scatter the north fold array back to the processors.
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
-      CHARACTER(len=1)                                            , INTENT(in   ) ::   cd_type  ! nature of pt3d grid-points
-      !                                                                                         !   = T ,  U , V , F or W -points
-      REAL(wp)                                                    , INTENT(in   ) ::   psgn     ! = -1. the sign change across the
-      !!                                                                                        ! north fold, =  1. otherwise
-      INTEGER ::   ji, jj, jr
-      INTEGER ::   ierr, itaille, ildi, ilei, iilb
-      INTEGER ::   ijpj, ij, iproc
-      !
-      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE  ::  ztab_e, znorthloc_e
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE  ::  znorthgloio_e
-
-      !!----------------------------------------------------------------------
-      !
-      ALLOCATE( ztab_e(jpiglo,4+2*jpr2dj), znorthloc_e(jpi,4+2*jpr2dj), znorthgloio_e(jpi,4+2*jpr2dj,jpni) )
-
-      !
-      ijpj=4
-      ztab_e(:,:) = 0.e0
-
-      ij=0
-      ! put in znorthloc_e the last 4 jlines of pt2d
-      DO jj = nlcj - ijpj + 1 - jpr2dj, nlcj +jpr2dj
-         ij = ij + 1
-         DO ji = 1, jpi
-            znorthloc_e(ji,ij)=pt2d(ji,jj)
-         END DO
-      END DO
-      !
-      itaille = jpi * ( ijpj + 2 * jpr2dj )
-      CALL MPI_ALLGATHER( znorthloc_e(1,1)  , itaille, MPI_DOUBLE_PRECISION,    &
-         &                znorthgloio_e(1,1,1), itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
-      !
-      DO jr = 1, ndim_rank_north            ! recover the global north array
-         iproc = nrank_north(jr) + 1
-         ildi = nldit (iproc)
-         ilei = nleit (iproc)
-         iilb = nimppt(iproc)
-         DO jj = 1, ijpj+2*jpr2dj
-            DO ji = ildi, ilei
-               ztab_e(ji+iilb-1,jj) = znorthgloio_e(ji,jj,jr)
-            END DO
-         END DO
-      END DO
-
-
-      ! 2. North-Fold boundary conditions
-      ! ----------------------------------
-      CALL lbc_nfd( ztab_e(:,:), cd_type, psgn, pr2dj = jpr2dj )
-
-      ij = jpr2dj
-      !! Scatter back to pt2d
-      DO jj = nlcj - ijpj + 1 , nlcj +jpr2dj
-      ij  = ij +1
-         DO ji= 1, nlci
-            pt2d(ji,jj) = ztab_e(ji+nimpp-1,ij)
-         END DO
-      END DO
-      !
-      DEALLOCATE( ztab_e, znorthloc_e, znorthgloio_e )
-      !
-   END SUBROUTINE mpp_lbc_north_e
-
-
-   SUBROUTINE mpp_lnk_bdy_3d( ptab, cd_type, psgn, ib_bdy )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_bdy_3d  ***
-      !!
-      !! ** Purpose :   Message passing management
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing BDY boundaries 
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi_bdy : mark for "east-west local boundary"
-      !!                    nbondj_bdy : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors 
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !! ** Action  :   ptab with update value at its periphery
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
-      !                                                             ! = T , U , V , F , W points
-      REAL(wp)                        , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
-      !                                                             ! =  1. , the sign is kept
-      INTEGER                         , INTENT(in   ) ::   ib_bdy   ! BDY boundary set
-      !
-      INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! local integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      REAL(wp) ::   zland                      ! local scalar
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !
-      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ns, zt3sn   ! 3d for north-south & south-north
-      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ew, zt3we   ! 3d for east-west & west-east
-      !!----------------------------------------------------------------------
-      !
-      ALLOCATE( zt3ns(jpi,jprecj,jpk,2), zt3sn(jpi,jprecj,jpk,2),   &
-         &      zt3ew(jpj,jpreci,jpk,2), zt3we(jpj,jpreci,jpk,2)  )
-
-      zland = 0._wp
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      !                                   ! East-West boundaries
-      !                                        !* Cyclic east-west
-      IF( nbondi == 2) THEN
-         IF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6 ) THEN
-            ptab( 1 ,:,:) = ptab(jpim1,:,:)
-            ptab(jpi,:,:) = ptab(  2  ,:,:)
-         ELSE
-            IF( .NOT. cd_type == 'F' )   ptab(1:jpreci,:,:) = zland    ! south except F-point
-            ptab(nlci-jpreci+1:jpi,:,:) = zland    ! north
-         ENDIF
-      ELSEIF(nbondi == -1) THEN
-         IF( .NOT. cd_type == 'F' )   ptab(1:jpreci,:,:) = zland    ! south except F-point
-      ELSEIF(nbondi == 1) THEN
-         ptab(nlci-jpreci+1:jpi,:,:) = zland    ! north
-      ENDIF                                     !* closed
-
-      IF (nbondj == 2 .OR. nbondj == -1) THEN
-        IF( .NOT. cd_type == 'F' )   ptab(:,1:jprecj,:) = zland       ! south except F-point
-      ELSEIF (nbondj == 2 .OR. nbondj == 1) THEN
-        ptab(:,nlcj-jprecj+1:jpj,:) = zland       ! north
-      ENDIF
-      !
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity 
-      !
-      SELECT CASE ( nbondi_bdy(ib_bdy) )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci
-         DO jl = 1, jpreci
-            zt3ew(:,jl,:,1) = ptab(jpreci+jl,:,:)
-            zt3we(:,jl,:,1) = ptab(iihom +jl,:,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = jpreci * jpj * jpk
-      !
-      SELECT CASE ( nbondi_bdy(ib_bdy) )
-      CASE ( -1 )
-         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req1 )
-      CASE ( 0 )
-         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req2 )
-      CASE ( 1 )
-         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
-      END SELECT
-      !
-      SELECT CASE ( nbondi_bdy_b(ib_bdy) )
-      CASE ( -1 )
-         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
-      CASE ( 0 )
-         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
-         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
-      CASE ( 1 )
-         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
-      END SELECT
-      !
-      SELECT CASE ( nbondi_bdy(ib_bdy) )
-      CASE ( -1 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci-jpreci
-      !
-      SELECT CASE ( nbondi_bdy_b(ib_bdy) )
-      CASE ( -1 )
-         DO jl = 1, jpreci
-            ptab(iihom+jl,:,:) = zt3ew(:,jl,:,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jpreci
-            ptab(      jl,:,:) = zt3we(:,jl,:,2)
-            ptab(iihom+jl,:,:) = zt3ew(:,jl,:,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jpreci
-            ptab(      jl,:,:) = zt3we(:,jl,:,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj_bdy(ib_bdy) /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj-nrecj
-         DO jl = 1, jprecj
-            zt3sn(:,jl,:,1) = ptab(:,ijhom +jl,:)
-            zt3ns(:,jl,:,1) = ptab(:,jprecj+jl,:)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = jprecj * jpi * jpk
-      !
-      SELECT CASE ( nbondj_bdy(ib_bdy) )
-      CASE ( -1 )
-         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req1 )
-      CASE ( 0 )
-         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req2 )
-      CASE ( 1 )
-         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
-      END SELECT
-      !
-      SELECT CASE ( nbondj_bdy_b(ib_bdy) )
-      CASE ( -1 )
-         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
-      CASE ( 0 )
-         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
-         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
-      CASE ( 1 )
-         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
-      END SELECT
-      !
-      SELECT CASE ( nbondj_bdy(ib_bdy) )
-      CASE ( -1 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj-jprecj
-      !
-      SELECT CASE ( nbondj_bdy_b(ib_bdy) )
-      CASE ( -1 )
-         DO jl = 1, jprecj
-            ptab(:,ijhom+jl,:) = zt3ns(:,jl,:,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jprecj
-            ptab(:,jl      ,:) = zt3sn(:,jl,:,2)
-            ptab(:,ijhom+jl,:) = zt3ns(:,jl,:,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jprecj
-            ptab(:,jl,:) = zt3sn(:,jl,:,2)
-         END DO
-      END SELECT
-
-
-      ! 4. north fold treatment
-      ! -----------------------
-      !
-      IF( npolj /= 0) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd      ( ptab, cd_type, psgn )   ! only 1 northern proc, no mpp
-         CASE DEFAULT   ;   CALL mpp_lbc_north( ptab, cd_type, psgn )   ! for all northern procs.
-         END SELECT
-         !
-      ENDIF
-      !
-      DEALLOCATE( zt3ns, zt3sn, zt3ew, zt3we  )
-      !
-   END SUBROUTINE mpp_lnk_bdy_3d
-
-
-   SUBROUTINE mpp_lnk_bdy_2d( ptab, cd_type, psgn, ib_bdy )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_bdy_2d  ***
-      !!
-      !! ** Purpose :   Message passing management
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing BDY boundaries 
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi_bdy : mark for "east-west local boundary"
-      !!                    nbondj_bdy : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors 
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !! ** Action  :   ptab with update value at its periphery
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
-      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
-      !                                                         ! = T , U , V , F , W points
-      REAL(wp)                    , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
-      !                                                         ! =  1. , the sign is kept
-      INTEGER                     , INTENT(in   ) ::   ib_bdy   ! BDY boundary set
-      !
-      INTEGER  ::   ji, jj, jl             ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! local integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      REAL(wp) ::   zland
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ns, zt2sn   ! 2d for north-south & south-north
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ew, zt2we   ! 2d for east-west & west-east
-      !!----------------------------------------------------------------------
-
-      ALLOCATE( zt2ns(jpi,jprecj,2), zt2sn(jpi,jprecj,2),  &
-         &      zt2ew(jpj,jpreci,2), zt2we(jpj,jpreci,2)   )
-
-      zland = 0._wp
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      !                                   ! East-West boundaries
-      !                                      !* Cyclic east-west
-      IF( nbondi == 2 ) THEN
-         IF (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) THEN
-            ptab( 1 ,:) = ptab(jpim1,:)
-            ptab(jpi,:) = ptab(  2  ,:)
-         ELSE
-            IF(.NOT.cd_type == 'F' )  ptab(     1       :jpreci,:) = zland    ! south except F-point
-                                      ptab(nlci-jpreci+1:jpi   ,:) = zland    ! north
-         ENDIF
-      ELSEIF(nbondi == -1) THEN
-         IF( .NOT.cd_type == 'F' )    ptab(     1       :jpreci,:) = zland    ! south except F-point
-      ELSEIF(nbondi == 1) THEN
-                                      ptab(nlci-jpreci+1:jpi   ,:) = zland    ! north
-      ENDIF
-      !                                      !* closed
-      IF( nbondj == 2 .OR. nbondj == -1 ) THEN
-         IF( .NOT.cd_type == 'F' )    ptab(:,     1       :jprecj) = zland    ! south except F-point
-      ELSEIF (nbondj == 2 .OR. nbondj == 1) THEN
-                                      ptab(:,nlcj-jprecj+1:jpj   ) = zland    ! north
-      ENDIF
-      !
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity 
-      !
-      SELECT CASE ( nbondi_bdy(ib_bdy) )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci
-         DO jl = 1, jpreci
-            zt2ew(:,jl,1) = ptab(jpreci+jl,:)
-            zt2we(:,jl,1) = ptab(iihom +jl,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = jpreci * jpj
-      !
-      SELECT CASE ( nbondi_bdy(ib_bdy) )
-      CASE ( -1 )
-         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req1 )
-      CASE ( 0 )
-         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req2 )
-      CASE ( 1 )
-         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
-      END SELECT
-      !
-      SELECT CASE ( nbondi_bdy_b(ib_bdy) )
-      CASE ( -1 )
-         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
-      CASE ( 0 )
-         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
-         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
-      CASE ( 1 )
-         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
-      END SELECT
-      !
-      SELECT CASE ( nbondi_bdy(ib_bdy) )
-      CASE ( -1 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci-jpreci
-      !
-      SELECT CASE ( nbondi_bdy_b(ib_bdy) )
-      CASE ( -1 )
-         DO jl = 1, jpreci
-            ptab(iihom+jl,:) = zt2ew(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jpreci
-            ptab(jl      ,:) = zt2we(:,jl,2)
-            ptab(iihom+jl,:) = zt2ew(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jpreci
-            ptab(jl      ,:) = zt2we(:,jl,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj_bdy(ib_bdy) /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj-nrecj
-         DO jl = 1, jprecj
-            zt2sn(:,jl,1) = ptab(:,ijhom +jl)
-            zt2ns(:,jl,1) = ptab(:,jprecj+jl)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = jprecj * jpi
-      !
-      SELECT CASE ( nbondj_bdy(ib_bdy) )
-      CASE ( -1 )
-         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req1 )
-      CASE ( 0 )
-         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req2 )
-      CASE ( 1 )
-         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
-      END SELECT
-      !
-      SELECT CASE ( nbondj_bdy_b(ib_bdy) )
-      CASE ( -1 )
-         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
-      CASE ( 0 )
-         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
-         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
-      CASE ( 1 )
-         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
-      END SELECT
-      !
-      SELECT CASE ( nbondj_bdy(ib_bdy) )
-      CASE ( -1 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj-jprecj
-      !
-      SELECT CASE ( nbondj_bdy_b(ib_bdy) )
-      CASE ( -1 )
-         DO jl = 1, jprecj
-            ptab(:,ijhom+jl) = zt2ns(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jprecj
-            ptab(:,jl      ) = zt2sn(:,jl,2)
-            ptab(:,ijhom+jl) = zt2ns(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jprecj
-            ptab(:,jl) = zt2sn(:,jl,2)
-         END DO
-      END SELECT
-
-
-      ! 4. north fold treatment
-      ! -----------------------
-      !
-      IF( npolj /= 0) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd      ( ptab, cd_type, psgn )   ! only 1 northern proc, no mpp
-         CASE DEFAULT   ;   CALL mpp_lbc_north( ptab, cd_type, psgn )   ! for all northern procs.
-         END SELECT
-         !
-      ENDIF
-      !
-      DEALLOCATE( zt2ns, zt2sn, zt2ew, zt2we  )
-      !
-   END SUBROUTINE mpp_lnk_bdy_2d
-
-
    SUBROUTINE mpi_init_opa( ldtxt, ksft, code )
       !!---------------------------------------------------------------------
@@ -3706,5 +1307,6 @@
    END SUBROUTINE mpi_init_opa
 
-   SUBROUTINE DDPDD_MPI (ydda, yddb, ilen, itype)
+
+   SUBROUTINE DDPDD_MPI( ydda, yddb, ilen, itype )
       !!---------------------------------------------------------------------
       !!   Routine DDPDD_MPI: used by reduction operator MPI_SUMDD
@@ -3713,13 +1315,14 @@
       !!   This subroutine computes yddb(i) = ydda(i)+yddb(i)
       !!---------------------------------------------------------------------
-      INTEGER, INTENT(in)                         :: ilen, itype
-      COMPLEX(wp), DIMENSION(ilen), INTENT(in)     :: ydda
-      COMPLEX(wp), DIMENSION(ilen), INTENT(inout)  :: yddb
+      INTEGER                     , INTENT(in)    ::   ilen, itype
+      COMPLEX(wp), DIMENSION(ilen), INTENT(in)    ::   ydda
+      COMPLEX(wp), DIMENSION(ilen), INTENT(inout) ::   yddb
       !
       REAL(wp) :: zerr, zt1, zt2    ! local work variables
-      INTEGER :: ji, ztmp           ! local scalar
-
+      INTEGER  :: ji, ztmp           ! local scalar
+      !!---------------------------------------------------------------------
+      !
       ztmp = itype   ! avoid compilation warning
-
+      !
       DO ji=1,ilen
       ! Compute ydda + yddb using Knuth's trick.
@@ -3732,9 +1335,9 @@
          yddb(ji) = cmplx ( zt1 + zt2, zt2 - ((zt1 + zt2) - zt1),wp )
       END DO
-
+      !
    END SUBROUTINE DDPDD_MPI
 
 
-   SUBROUTINE mpp_lbc_north_icb( pt2d, cd_type, psgn, pr2dj)
+   SUBROUTINE mpp_lbc_north_icb( pt2d, cd_type, psgn, kextj)
       !!---------------------------------------------------------------------
       !!                   ***  routine mpp_lbc_north_icb  ***
@@ -3746,8 +1349,9 @@
       !! ** Method  :   North fold condition and mpp with more than one proc
       !!              in i-direction require a specific treatment. We gather
-      !!              the 4+2*jpr2dj northern lines of the global domain on 1
+      !!              the 4+kextj northern lines of the global domain on 1
       !!              processor and apply lbc north-fold on this sub array.
       !!              Then we scatter the north fold array back to the processors.
-      !!              This version accounts for an extra halo with icebergs.
+      !!              This routine accounts for an extra halo with icebergs
+      !!              and assumes ghost rows and columns have been suppressed.
       !!
       !!----------------------------------------------------------------------
@@ -3757,9 +1361,9 @@
       REAL(wp)                , INTENT(in   ) ::   psgn     ! = -1. the sign change across the
       !!                                                    ! north fold, =  1. otherwise
-      INTEGER, OPTIONAL       , INTENT(in   ) ::   pr2dj
+      INTEGER                 , INTENT(in   ) ::   kextj    ! Extra halo width at north fold
       !
       INTEGER ::   ji, jj, jr
       INTEGER ::   ierr, itaille, ildi, ilei, iilb
-      INTEGER ::   ijpj, ij, iproc, ipr2dj
+      INTEGER ::   ipj, ij, iproc
       !
       REAL(wp), DIMENSION(:,:)  , ALLOCATABLE  ::  ztab_e, znorthloc_e
@@ -3767,24 +1371,19 @@
       !!----------------------------------------------------------------------
       !
-      ijpj=4
-      IF( PRESENT(pr2dj) ) THEN           ! use of additional halos
-         ipr2dj = pr2dj
-      ELSE
-         ipr2dj = 0
-      ENDIF
-      ALLOCATE( ztab_e(jpiglo,4+2*ipr2dj), znorthloc_e(jpi,4+2*ipr2dj), znorthgloio_e(jpi,4+2*ipr2dj,jpni) )
-      !
-      ztab_e(:,:) = 0._wp
+      ipj=4
+      ALLOCATE( ztab_e(jpiglo,ipj+kextj), znorthloc_e(  jpimax,ipj+kextj), &
+     &                                    znorthgloio_e(jpimax,ipj+kextj,jpni) )
+      !
+      ztab_e(:,:)      = 0._wp
+      znorthloc_e(:,:) = 0._wp
       !
       ij = 0
-      ! put in znorthloc_e the last 4 jlines of pt2d
-      DO jj = nlcj - ijpj + 1 - ipr2dj, nlcj +ipr2dj
+      ! put the last ipj+kextj lines of pt2d into znorthloc_e 
+      DO jj = jpj - ipj + 1, jpj + kextj
          ij = ij + 1
-         DO ji = 1, jpi
-            znorthloc_e(ji,ij)=pt2d(ji,jj)
-         END DO
+         znorthloc_e(1:jpi,ij)=pt2d(1:jpi,jj)
       END DO
       !
-      itaille = jpi * ( ijpj + 2 * ipr2dj )
+      itaille = jpimax * ( ipj + kextj )
       CALL MPI_ALLGATHER( znorthloc_e(1,1)  , itaille, MPI_DOUBLE_PRECISION,    &
          &                znorthgloio_e(1,1,1), itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
@@ -3795,5 +1394,5 @@
          ilei = nleit (iproc)
          iilb = nimppt(iproc)
-         DO jj = 1, ijpj+2*ipr2dj
+         DO jj = 1, ipj+kextj
             DO ji = ildi, ilei
                ztab_e(ji+iilb-1,jj) = znorthgloio_e(ji,jj,jr)
@@ -3802,14 +1401,13 @@
       END DO
 
-
       ! 2. North-Fold boundary conditions
       ! ----------------------------------
-      CALL lbc_nfd( ztab_e(:,:), cd_type, psgn, pr2dj = ipr2dj )
-
-      ij = ipr2dj
+      CALL lbc_nfd( ztab_e(:,:), cd_type, psgn, kextj )
+
+      ij = 0
       !! Scatter back to pt2d
-      DO jj = nlcj - ijpj + 1 , nlcj +ipr2dj
+      DO jj = jpj - ipj + 1 , jpj + kextj
       ij  = ij +1
-         DO ji= 1, nlci
+         DO ji= 1, jpi
             pt2d(ji,jj) = ztab_e(ji+nimpp-1,ij)
          END DO
@@ -3821,17 +1419,19 @@
 
 
-   SUBROUTINE mpp_lnk_2d_icb( pt2d, cd_type, psgn, jpri, jprj )
+   SUBROUTINE mpp_lnk_2d_icb( pt2d, cd_type, psgn, kexti, kextj )
       !!----------------------------------------------------------------------
       !!                  ***  routine mpp_lnk_2d_icb  ***
       !!
-      !! ** Purpose :   Message passing manadgement for 2d array (with extra halo and icebergs)
+      !! ** Purpose :   Message passing management for 2d array (with extra halo for icebergs)
+      !!                This routine receives a (1-kexti:jpi+kexti,1-kexti:jpj+kextj)
+      !!                array (usually (0:jpi+1, 0:jpj+1)) from lbc_lnk_icb calls.
       !!
       !! ** Method  :   Use mppsend and mpprecv function for passing mask
       !!      between processors following neighboring subdomains.
       !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    jpri   : number of rows for extra outer halo
-      !!                    jprj   : number of columns for extra outer halo
+      !!                    jpi    : first dimension of the local subdomain
+      !!                    jpj    : second dimension of the local subdomain
+      !!                    kexti  : number of columns for extra outer halo
+      !!                    kextj  : number of rows for extra outer halo
       !!                    nbondi : mark for "east-west local boundary"
       !!                    nbondj : mark for "north-south local boundary"
@@ -3841,25 +1441,22 @@
       !!                    nono   : number for local neighboring processors
       !!----------------------------------------------------------------------
-      INTEGER                                             , INTENT(in   ) ::   jpri
-      INTEGER                                             , INTENT(in   ) ::   jprj
-      REAL(wp), DIMENSION(1-jpri:jpi+jpri,1-jprj:jpj+jprj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
-      CHARACTER(len=1)                                    , INTENT(in   ) ::   cd_type  ! nature of ptab array grid-points
-      !                                                                                 ! = T , U , V , F , W and I points
-      REAL(wp)                                            , INTENT(in   ) ::   psgn     ! =-1 the sign change across the
-      !!                                                                                ! north boundary, =  1. otherwise
+      REAL(wp), DIMENSION(1-kexti:jpi+kexti,1-kextj:jpj+kextj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
+      CHARACTER(len=1)                                        , INTENT(in   ) ::   cd_type  ! nature of ptab array grid-points
+      REAL(wp)                                                , INTENT(in   ) ::   psgn     ! sign used across the north fold
+      INTEGER                                                 , INTENT(in   ) ::   kexti    ! extra i-halo width
+      INTEGER                                                 , INTENT(in   ) ::   kextj    ! extra j-halo width
+      !
       INTEGER  ::   jl   ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ipreci, iprecj             ! temporary integers
+      INTEGER  ::   imigr, iihom, ijhom        ! local integers
+      INTEGER  ::   ipreci, iprecj             !   -       -
       INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
       INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
       !!
-      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dns
-      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dsn
-      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dwe
-      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dew
-      !!----------------------------------------------------------------------
-
-      ipreci = jpreci + jpri      ! take into account outer extra 2D overlap area
-      iprecj = jprecj + jprj
+      REAL(wp), DIMENSION(1-kexti:jpi+kexti,nn_hls+kextj,2) ::   r2dns, r2dsn
+      REAL(wp), DIMENSION(1-kextj:jpj+kextj,nn_hls+kexti,2) ::   r2dwe, r2dew
+      !!----------------------------------------------------------------------
+
+      ipreci = nn_hls + kexti      ! take into account outer extra 2D overlap area
+      iprecj = nn_hls + kextj
 
 
@@ -3871,10 +1468,10 @@
       !                                           !* Cyclic east-west
       IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-         pt2d(1-jpri:     1    ,:) = pt2d(jpim1-jpri:  jpim1 ,:)       ! east
-         pt2d(   jpi  :jpi+jpri,:) = pt2d(     2      :2+jpri,:)       ! west
+         pt2d(1-kexti:     1    ,:) = pt2d(jpim1-kexti:  jpim1 ,:)       ! east
+         pt2d(   jpi  :jpi+kexti,:) = pt2d(     2      :2+kexti,:)       ! west
          !
       ELSE                                        !* closed
-         IF( .NOT. cd_type == 'F' )   pt2d(  1-jpri   :jpreci    ,:) = 0.e0    ! south except at F-point
-                                      pt2d(nlci-jpreci+1:jpi+jpri,:) = 0.e0    ! north
+         IF( .NOT. cd_type == 'F' )   pt2d(  1-kexti   :nn_hls    ,:) = 0._wp    ! south except at F-point
+                                      pt2d(jpi-nn_hls+1:jpi+kexti,:) = 0._wp    ! north
       ENDIF
       !
@@ -3885,6 +1482,6 @@
          !
          SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd        ( pt2d(1:jpi,1:jpj+jprj), cd_type, psgn, pr2dj=jprj )
-         CASE DEFAULT   ;   CALL mpp_lbc_north_icb( pt2d(1:jpi,1:jpj+jprj)  , cd_type, psgn , pr2dj=jprj  )
+                   CASE ( 1 )     ;   CALL lbc_nfd          ( pt2d(1:jpi,1:jpj+kextj), cd_type, psgn, kextj )
+                   CASE DEFAULT   ;   CALL mpp_lbc_north_icb( pt2d(1:jpi,1:jpj+kextj), cd_type, psgn, kextj )
          END SELECT
          !
@@ -3897,7 +1494,7 @@
       SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
       CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci-jpri
+         iihom = jpi-nreci-kexti
          DO jl = 1, ipreci
-            r2dew(:,jl,1) = pt2d(jpreci+jl,:)
+            r2dew(:,jl,1) = pt2d(nn_hls+jl,:)
             r2dwe(:,jl,1) = pt2d(iihom +jl,:)
          END DO
@@ -3905,26 +1502,26 @@
       !
       !                           ! Migrations
-      imigr = ipreci * ( jpj + 2*jprj)
+      imigr = ipreci * ( jpj + 2*kextj )
       !
       SELECT CASE ( nbondi )
       CASE ( -1 )
-         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
+         CALL mppsend( 2, r2dwe(1-kextj,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, r2dew(1-kextj,1,2), imigr, noea )
          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
       CASE ( 0 )
-         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
-         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
+         CALL mppsend( 1, r2dew(1-kextj,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, r2dwe(1-kextj,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, r2dew(1-kextj,1,2), imigr, noea )
+         CALL mpprecv( 2, r2dwe(1-kextj,1,2), imigr, nowe )
          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
          IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
       CASE ( 1 )
-         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
+         CALL mppsend( 1, r2dew(1-kextj,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, r2dwe(1-kextj,1,2), imigr, nowe )
          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
       END SELECT
       !
       !                           ! Write Dirichlet lateral conditions
-      iihom = nlci - jpreci
+      iihom = jpi - nn_hls
       !
       SELECT CASE ( nbondi )
@@ -3935,10 +1532,10 @@
       CASE ( 0 )
          DO jl = 1, ipreci
-            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
-            pt2d( iihom+jl,:) = r2dew(:,jl,2)
+            pt2d(jl-kexti,:) = r2dwe(:,jl,2)
+            pt2d(iihom+jl,:) = r2dew(:,jl,2)
          END DO
       CASE ( 1 )
          DO jl = 1, ipreci
-            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
+            pt2d(jl-kexti,:) = r2dwe(:,jl,2)
          END DO
       END SELECT
@@ -3950,34 +1547,34 @@
       !
       IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj-nrecj-jprj
+         ijhom = jpj-nrecj-kextj
          DO jl = 1, iprecj
             r2dsn(:,jl,1) = pt2d(:,ijhom +jl)
-            r2dns(:,jl,1) = pt2d(:,jprecj+jl)
+            r2dns(:,jl,1) = pt2d(:,nn_hls+jl)
          END DO
       ENDIF
       !
       !                           ! Migrations
-      imigr = iprecj * ( jpi + 2*jpri )
+      imigr = iprecj * ( jpi + 2*kexti )
       !
       SELECT CASE ( nbondj )
       CASE ( -1 )
-         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
+         CALL mppsend( 4, r2dsn(1-kexti,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, r2dns(1-kexti,1,2), imigr, nono )
          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
       CASE ( 0 )
-         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
-         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
+         CALL mppsend( 3, r2dns(1-kexti,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, r2dsn(1-kexti,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, r2dns(1-kexti,1,2), imigr, nono )
+         CALL mpprecv( 4, r2dsn(1-kexti,1,2), imigr, noso )
          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
          IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
       CASE ( 1 )
-         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
+         CALL mppsend( 3, r2dns(1-kexti,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, r2dsn(1-kexti,1,2), imigr, noso )
          IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
       END SELECT
       !
       !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj - jprecj
+      ijhom = jpj - nn_hls
       !
       SELECT CASE ( nbondj )
@@ -3988,13 +1585,13 @@
       CASE ( 0 )
          DO jl = 1, iprecj
-            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
-            pt2d(:,ijhom+jl ) = r2dns(:,jl,2)
+            pt2d(:,jl-kextj) = r2dsn(:,jl,2)
+            pt2d(:,ijhom+jl) = r2dns(:,jl,2)
          END DO
       CASE ( 1 )
          DO jl = 1, iprecj
-            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
+            pt2d(:,jl-kextj) = r2dsn(:,jl,2)
          END DO
       END SELECT
-
+      !
    END SUBROUTINE mpp_lnk_2d_icb
    
@@ -4020,4 +1617,7 @@
       MODULE PROCEDURE mpp_maxloc2d ,mpp_maxloc3d
    END INTERFACE
+   INTERFACE mpp_max_multiple
+      MODULE PROCEDURE mppmax_real_multiple
+   END INTERFACE
 
    LOGICAL, PUBLIC, PARAMETER ::   lk_mpp = .FALSE.      !: mpp flag
@@ -4191,4 +1791,12 @@
       WRITE(*,*) 'mpp_comm_free: You should not have seen this print! error?', kcom
    END SUBROUTINE mpp_comm_free
+   
+   SUBROUTINE mppmax_real_multiple( ptab, kdim , kcom  )
+      REAL, DIMENSION(:) ::   ptab   ! 
+      INTEGER            ::   kdim   ! 
+      INTEGER, OPTIONAL  ::   kcom   ! 
+      WRITE(*,*) 'mppmax_real_multiple: You should not have seen this print! error?', ptab(1), kdim
+   END SUBROUTINE mppmax_real_multiple
+
 #endif
 
@@ -4225,5 +1833,5 @@
                                CALL FLUSH(numout    )
       IF( numstp     /= -1 )   CALL FLUSH(numstp    )
-      IF( numsol     /= -1 )   CALL FLUSH(numsol    )
+      IF( numrun     /= -1 )   CALL FLUSH(numrun    )
       IF( numevo_ice /= -1 )   CALL FLUSH(numevo_ice)
       !
@@ -4332,5 +1940,5 @@
             WRITE(kout,*)
          ENDIF
-         CALL FLUSH(kout) 
+         CALL FLUSH( kout ) 
          STOP 'ctl_opn bad opening'
       ENDIF
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_bdy_generic.h90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_bdy_generic.h90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_bdy_generic.h90	(revision 9019)
@@ -0,0 +1,270 @@
+#   define ARRAY_TYPE(i,j,k,l,f)    REAL(wp)                    , INTENT(inout) ::   ARRAY_IN(i,j,k,l,f)
+#   define NAT_IN(k)                cd_nat
+#   define SGN_IN(k)                psgn
+#   define IBD_IN(k)                kb_bdy
+#   define F_SIZE(ptab)             1
+#   define OPT_K(k)                 
+#   if defined DIM_2d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j)
+#      define K_SIZE(ptab)          1
+#      define L_SIZE(ptab)          1
+#   endif
+#   if defined DIM_3d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k)
+#      define K_SIZE(ptab)          SIZE(ptab,3)
+#      define L_SIZE(ptab)          1
+#   endif
+#   if defined DIM_4d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k,l)
+#      define K_SIZE(ptab)          SIZE(ptab,3)
+#      define L_SIZE(ptab)          SIZE(ptab,4)
+#   endif
+
+   SUBROUTINE ROUTINE_BDY( ptab, cd_nat, psgn      , kb_bdy )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_bdy_3d  ***
+      !!
+      !! ** Purpose :   Message passing management
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing BDY boundaries 
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi_bdy : mark for "east-west local boundary"
+      !!                    nbondj_bdy : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors 
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !! ** Action  :   ptab with update value at its periphery
+      !!
+      !!----------------------------------------------------------------------
+      ARRAY_TYPE(:,:,:,:,:)   ! array or pointer of arrays on which the boundary condition is applied
+      CHARACTER(len=1)            , INTENT(in   ) ::   NAT_IN(:)   ! nature of array grid-points
+      REAL(wp)                    , INTENT(in   ) ::   SGN_IN(:)   ! sign used across the north fold boundary
+      INTEGER                     , INTENT(in   ) ::   IBD_IN(:)   ! BDY boundary set
+      !
+      INTEGER  ::   ji, jj, jk, jl, jh, jf     ! dummy loop indices
+      INTEGER  ::   ipk, ipl, ipf              ! 3dimension of the input array
+      INTEGER  ::   imigr, iihom, ijhom        ! local integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      REAL(wp) ::   zland                      ! local scalar
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !
+      REAL(wp), DIMENSION(:,:,:,:,:,:), ALLOCATABLE ::   zt3ns, zt3sn   ! 3d for north-south & south-north
+      REAL(wp), DIMENSION(:,:,:,:,:,:), ALLOCATABLE ::   zt3ew, zt3we   ! 3d for east-west & west-east
+      !!----------------------------------------------------------------------
+      !
+      ipk = K_SIZE(ptab)   ! 3rd dimension
+      ipl = L_SIZE(ptab)   ! 4th    -
+      ipf = F_SIZE(ptab)   ! 5th    -      use in "multi" case (array of pointers)
+      !      
+      ALLOCATE( zt3ns(jpi,nn_hls,ipk,ipl,ipf,2), zt3sn(jpi,nn_hls,ipk,ipl,ipf,2),   &
+         &      zt3ew(jpj,nn_hls,ipk,ipl,ipf,2), zt3we(jpj,nn_hls,ipk,ipl,ipf,2)  )
+
+      zland = 0._wp
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      !
+      DO jf = 1, ipf                   ! number of arrays to be treated
+         !
+         !                                ! East-West boundaries
+         !                    
+         IF( nbondi == 2) THEN                  ! neither subdomain to the east nor to the west
+            !                                      !* Cyclic
+            IF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6 ) THEN
+               ARRAY_IN( 1 ,:,:,:,jf) = ARRAY_IN(jpim1,:,:,:,jf)
+               ARRAY_IN(jpi,:,:,:,jf) = ARRAY_IN(  2  ,:,:,:,jf)
+            ELSE                                   !* Closed
+               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(     1       :nn_hls,:,:,:,jf) = zland  ! east except F-point
+                                               ARRAY_IN(nlci-nn_hls+1:jpi   ,:,:,:,jf) = zland  ! west
+            ENDIF
+         ELSEIF(nbondi == -1) THEN              ! subdomain to the east only
+            IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(1:nn_hls,:,:,:,jf) = zland     ! south except F-point
+            !
+         ELSEIF(nbondi == 1) THEN               ! subdomain to the west only
+            ARRAY_IN(nlci-nn_hls+1:jpi,:,:,:,jf) = zland    ! north
+         ENDIF
+         !                                ! North-South boundaries
+         !
+         IF (nbondj == 2 .OR. nbondj == -1) THEN      !* closed
+           IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(:,1:nn_hls,:,:,jf) = zland            ! south except F-point
+         ELSEIF (nbondj == 2 .OR. nbondj == 1) THEN
+                                           ARRAY_IN(:,nlcj-nn_hls+1:jpj,:,:,jf) = zland   ! north
+         ENDIF
+      END DO
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity 
+      !
+      !
+      DO jf = 1, ipf
+         SELECT CASE ( nbondi_bdy(IBD_IN(jf)) )      ! Read Dirichlet lateral conditions
+         CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+            iihom = nlci-nreci
+               DO jl = 1, ipl
+                  DO jk = 1, ipk
+                     DO jh = 1, nn_hls
+                        zt3ew(:,jh,jk,jl,jf,1) = ARRAY_IN(nn_hls+jh,:,jk,jl,jf)
+                        zt3we(:,jh,jk,jl,jf,1) = ARRAY_IN(iihom +jh,:,jk,jl,jf)
+                     END DO
+                  END DO
+               END DO
+         END SELECT
+         !
+         !                           ! Migrations
+!!gm      imigr = nn_hls * jpj * ipk * ipl * ipf
+         imigr = nn_hls * jpj * ipk * ipl
+         !
+         SELECT CASE ( nbondi_bdy(IBD_IN(jf)) )
+         CASE ( -1 )
+            CALL mppsend( 2, zt3we(1,1,1,1,1,1), imigr, noea, ml_req1 )
+            CALL mpprecv( 1, zt3ew(1,1,1,1,1,2), imigr, noea )
+            IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         CASE ( 0 )
+            CALL mppsend( 1, zt3ew(1,1,1,1,1,1), imigr, nowe, ml_req1 )
+            CALL mppsend( 2, zt3we(1,1,1,1,1,1), imigr, noea, ml_req2 )
+            CALL mpprecv( 1, zt3ew(1,1,1,1,1,2), imigr, noea )
+            CALL mpprecv( 2, zt3we(1,1,1,1,1,2), imigr, nowe )
+            IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+            IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+         CASE ( 1 )
+            CALL mppsend( 1, zt3ew(1,1,1,1,1,1), imigr, nowe, ml_req1 )
+            CALL mpprecv( 2, zt3we(1,1,1,1,1,2), imigr, nowe )
+            IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         END SELECT
+         !
+         !                           ! Write Dirichlet lateral conditions
+         iihom = nlci-nn_hls
+         !
+         !
+         SELECT CASE ( nbondi_bdy_b(IBD_IN(jf)) )
+         CASE ( -1 )
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jh = 1, nn_hls
+                     ARRAY_IN(iihom+jh,:,jk,jl,jf) = zt3ew(:,jh,jk,jl,jf,2)
+                  END DO
+               END DO
+            END DO
+         CASE ( 0 )
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jh = 1, nn_hls
+                     ARRAY_IN(jh      ,:,jk,jl,jf) = zt3we(:,jh,jk,jl,jf,2)
+                     ARRAY_IN(iihom+jh,:,jk,jl,jf) = zt3ew(:,jh,jk,jl,jf,2)
+                  END DO
+               END DO
+            END DO
+         CASE ( 1 )
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jh = 1, nn_hls
+                     ARRAY_IN(jh      ,:,jk,jl,jf) = zt3we(:,jh,jk,jl,jf,2)
+                  END DO
+               END DO
+            END DO
+         END SELECT
+         !
+      END DO
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      DO jf = 1, ipf
+         IF( nbondj_bdy(IBD_IN(jf)) /= 2 ) THEN      ! Read Dirichlet lateral conditions
+            ijhom = nlcj-nrecj
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jh = 1, nn_hls
+                     zt3sn(:,jh,jk,jl,jf,1) = ARRAY_IN(:,ijhom +jh,jk,jl,jf)
+                     zt3ns(:,jh,jk,jl,jf,1) = ARRAY_IN(:,nn_hls+jh,jk,jl,jf)
+                  END DO
+               END DO
+            END DO
+         ENDIF
+         !
+         !                           ! Migrations
+!!gm      imigr = nn_hls * jpi * ipk * ipl * ipf
+         imigr = nn_hls * jpi * ipk * ipl
+         !
+         SELECT CASE ( nbondj_bdy(IBD_IN(jf)) )
+         CASE ( -1 )
+            CALL mppsend( 4, zt3sn(1,1,1,1,1,1), imigr, nono, ml_req1 )
+            CALL mpprecv( 3, zt3ns(1,1,1,1,1,2), imigr, nono )
+            IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         CASE ( 0 )
+            CALL mppsend( 3, zt3ns(1,1,1,1,1,1), imigr, noso, ml_req1 )
+            CALL mppsend( 4, zt3sn(1,1,1,1,1,1), imigr, nono, ml_req2 )
+            CALL mpprecv( 3, zt3ns(1,1,1,1,1,2), imigr, nono )
+            CALL mpprecv( 4, zt3sn(1,1,1,1,1,2), imigr, noso )
+            IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+            IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+         CASE ( 1 )
+            CALL mppsend( 3, zt3ns(1,1,1,1,1,1), imigr, noso, ml_req1 )
+            CALL mpprecv( 4, zt3sn(1,1,1,1,1,2), imigr, noso )
+            IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         END SELECT
+         !
+         !                           ! Write Dirichlet lateral conditions
+         ijhom = nlcj-nn_hls
+         !
+         SELECT CASE ( nbondj_bdy_b(IBD_IN(jf)) )
+         CASE ( -1 )
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jh = 1, nn_hls
+                     ARRAY_IN(:,ijhom+jh,jk,jl,jf) = zt3ns(:,jh,jk,jl,jf,2)
+                  END DO
+               END DO
+            END DO
+         CASE ( 0 )
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jh = 1, nn_hls
+                     ARRAY_IN(:,      jh,jk,jl,jf) = zt3sn(:,jh,jk,jl,jf,2)
+                     ARRAY_IN(:,ijhom+jh,jk,jl,jf) = zt3ns(:,jh,jk,jl,jf,2)
+                  END DO
+               END DO
+            END DO
+         CASE ( 1 )
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jh = 1, nn_hls
+                     ARRAY_IN(:,jh,jk,jl,jf) = zt3sn(:,jh,jk,jl,jf,2)
+                  END DO
+               END DO
+            END DO
+         END SELECT
+      END DO
+
+      ! 4. north fold treatment
+      ! -----------------------
+      !
+      IF( npolj /= 0) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd( ptab, NAT_IN(:), SGN_IN(:) OPT_K(:) )   ! only 1 northern proc, no mpp
+         CASE DEFAULT   ;   CALL mpp_nfd( ptab, NAT_IN(:), SGN_IN(:) OPT_K(:) )   ! for all northern procs.
+         END SELECT
+         !
+      ENDIF
+      !
+      DEALLOCATE( zt3ns, zt3sn, zt3ew, zt3we  )
+      !
+   END SUBROUTINE ROUTINE_BDY
+
+#undef ARRAY_TYPE
+#undef NAT_IN
+#undef SGN_IN
+#undef IBD_IN
+#undef ARRAY_IN
+#undef K_SIZE
+#undef L_SIZE
+#undef F_SIZE
+#undef OPT_K
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_lnk_generic.h90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_lnk_generic.h90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_lnk_generic.h90	(revision 9019)
@@ -0,0 +1,310 @@
+#if defined MULTI
+#   define NAT_IN(k)                cd_nat(k)   
+#   define SGN_IN(k)                psgn(k)
+#   define F_SIZE(ptab)             kfld
+#   define OPT_K(k)                 ,ipf
+#   if defined DIM_2d
+#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_2D)                , INTENT(inout) ::   ptab(f)
+#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt2d(i,j)
+#      define K_SIZE(ptab)             1
+#      define L_SIZE(ptab)             1
+#   endif
+#   if defined DIM_3d
+#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_3D)                , INTENT(inout) ::   ptab(f)
+#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt3d(i,j,k)
+#      define K_SIZE(ptab)             SIZE(ptab(1)%pt3d,3)
+#      define L_SIZE(ptab)             1
+#   endif
+#   if defined DIM_4d
+#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_4D)                , INTENT(inout) ::   ptab(f)
+#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt4d(i,j,k,l)
+#      define K_SIZE(ptab)             SIZE(ptab(1)%pt4d,3)
+#      define L_SIZE(ptab)             SIZE(ptab(1)%pt4d,4)
+#   endif
+#else
+#   define ARRAY_TYPE(i,j,k,l,f)    REAL(wp)                    , INTENT(inout) ::   ARRAY_IN(i,j,k,l,f)
+#   define NAT_IN(k)                cd_nat
+#   define SGN_IN(k)                psgn
+#   define F_SIZE(ptab)             1
+#   define OPT_K(k)                 
+#   if defined DIM_2d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j)
+#      define K_SIZE(ptab)          1
+#      define L_SIZE(ptab)          1
+#   endif
+#   if defined DIM_3d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k)
+#      define K_SIZE(ptab)          SIZE(ptab,3)
+#      define L_SIZE(ptab)          1
+#   endif
+#   if defined DIM_4d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k,l)
+#      define K_SIZE(ptab)          SIZE(ptab,3)
+#      define L_SIZE(ptab)          SIZE(ptab,4)
+#   endif
+#endif
+
+#if defined MULTI
+   SUBROUTINE ROUTINE_LNK( ptab, cd_nat, psgn, kfld, cd_mpp, pval )
+      INTEGER                     , INTENT(in   ) ::   kfld        ! number of pt3d arrays
+#else
+   SUBROUTINE ROUTINE_LNK( ptab, cd_nat, psgn      , cd_mpp, pval )
+#endif
+      ARRAY_TYPE(:,:,:,:,:)                                        ! array or pointer of arrays on which the boundary condition is applied
+      CHARACTER(len=1)            , INTENT(in   ) ::   NAT_IN(:)   ! nature of array grid-points
+      REAL(wp)                    , INTENT(in   ) ::   SGN_IN(:)   ! sign used across the north fold boundary
+      CHARACTER(len=3), OPTIONAL  , INTENT(in   ) ::   cd_mpp      ! fill the overlap area only
+      REAL(wp)        , OPTIONAL  , INTENT(in   ) ::   pval        ! background value (used at closed boundaries)
+      !
+      INTEGER  ::    ji,  jj,  jk,  jl, jh, jf   ! dummy loop indices
+      INTEGER  ::   ipi, ipj, ipk, ipl, ipf      ! dimension of the input array
+      INTEGER  ::   imigr, iihom, ijhom          ! local integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err     ! for key_mpi_isend
+      REAL(wp) ::   zland
+      LOGICAL  ::   ll_Iperio, ll_Jperio
+      INTEGER , DIMENSION(MPI_STATUS_SIZE)      ::   ml_stat        ! for key_mpi_isend
+      REAL(wp), DIMENSION(:,:,:,:,:,:), ALLOCATABLE ::   zt3ns, zt3sn   ! north-south & south-north  halos
+      REAL(wp), DIMENSION(:,:,:,:,:,:), ALLOCATABLE ::   zt3ew, zt3we   ! east -west  & west - east  halos
+      !!----------------------------------------------------------------------
+      !
+      ipk = K_SIZE(ptab)   ! 3rd dimension
+      ipl = L_SIZE(ptab)   ! 4th    -
+      ipf = F_SIZE(ptab)   ! 5th    -      use in "multi" case (array of pointers)
+      !
+      ALLOCATE( zt3ns(jpi,nn_hls,ipk,ipl,ipf,2), zt3sn(jpi,nn_hls,ipk,ipl,ipf,2),   &
+         &      zt3ew(jpj,nn_hls,ipk,ipl,ipf,2), zt3we(jpj,nn_hls,ipk,ipl,ipf,2)  )
+      !
+      ll_Iperio = nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6)
+      ll_Jperio = nbondj == 2 .AND.  jperio == 7
+      !
+      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
+      ELSE                         ;   zland = 0._wp     ! zero by default
+      ENDIF
+
+      ! ------------------------------- !
+      !   standard boundary treatment   !    ! CAUTION: semi-column notation is often impossible
+      ! ------------------------------- !
+      !
+      IF( PRESENT( cd_mpp ) ) THEN     !==  halos filled with inner values  ==!
+         !
+         DO jf = 1, ipf                      ! number of arrays to be treated
+            !
+            DO jl = 1, ipl                   ! CAUTION: ptab is defined only between nld and nle
+               DO jk = 1, ipk
+                  DO jj = nlcj+1, jpj                 ! added line(s)   (inner only)
+                     ARRAY_IN(nldi  :nlei  ,jj,jk,jl,jf) = ARRAY_IN(nldi:nlei,nlej,jk,jl,jf)
+                     ARRAY_IN(1     :nldi-1,jj,jk,jl,jf) = ARRAY_IN(nldi     ,nlej,jk,jl,jf)
+                     ARRAY_IN(nlei+1:nlci  ,jj,jk,jl,jf) = ARRAY_IN(     nlei,nlej,jk,jl,jf)
+                  END DO
+                  DO ji = nlci+1, jpi                 ! added column(s) (full)
+                     ARRAY_IN(ji,nldj  :nlej  ,jk,jl,jf) = ARRAY_IN(nlei,nldj:nlej,jk,jl,jf)
+                     ARRAY_IN(ji,1     :nldj-1,jk,jl,jf) = ARRAY_IN(nlei,nldj     ,jk,jl,jf)
+                     ARRAY_IN(ji,nlej+1:jpj   ,jk,jl,jf) = ARRAY_IN(nlei,     nlej,jk,jl,jf)
+                  END DO
+               END DO
+            END DO
+            !
+         END DO
+         !
+      ELSE                              !==  standard close or cyclic treatment  ==!
+         !
+         DO jf = 1, ipf                      ! number of arrays to be treated
+            !
+            !                             ! East-West boundaries
+            IF( ll_Iperio ) THEN                   !* cyclic
+               ARRAY_IN( 1 ,:,:,:,jf) = ARRAY_IN(jpim1,:,:,:,jf)
+               ARRAY_IN(jpi,:,:,:,jf) = ARRAY_IN(  2  ,:,:,:,jf)
+            ELSE                                   !* closed
+               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(     1       :nn_hls,:,:,:,jf) = zland    ! east except F-point
+                                               ARRAY_IN(nlci-nn_hls+1:jpi   ,:,:,:,jf) = zland    ! west
+            ENDIF
+            !                                ! North-South boundaries
+            IF( ll_Jperio ) THEN                   !* cyclic (only with no mpp j-split)
+               ARRAY_IN(:, 1 ,:,:,jf) = ARRAY_IN(:, jpjm1,:,:,jf)
+               ARRAY_IN(:,jpj,:,:,jf) = ARRAY_IN(:,   2  ,:,:,jf)
+            ELSE                                   !* closed
+               IF( .NOT. NAT_IN(jf) == 'F' )   ARRAY_IN(:,     1       :nn_hls,:,:,jf) = zland    ! south except F-point
+                                               ARRAY_IN(:,nlcj-nn_hls+1:jpj   ,:,:,jf) = zland    ! north
+            ENDIF
+         END DO
+         !
+      ENDIF
+
+      ! ------------------------------- !
+      !      East and west exchange     !
+      ! ------------------------------- !
+      ! we play with the neigbours AND the row number because of the periodicity
+      !
+      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci
+         DO jf = 1, ipf
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jh = 1, nn_hls
+                     zt3ew(:,jh,jk,jl,jf,1) = ARRAY_IN(nn_hls+jh,:,jk,jl,jf)
+                     zt3we(:,jh,jk,jl,jf,1) = ARRAY_IN(iihom +jh,:,jk,jl,jf)
+                  END DO
+               END DO
+            END DO
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = nn_hls * jpj * ipk * ipl * ipf
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, zt3we(1,1,1,1,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, zt3ew(1,1,1,1,1,2), imigr, noea )
+         IF(l_isend)   CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, zt3ew(1,1,1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, zt3we(1,1,1,1,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, zt3ew(1,1,1,1,1,2), imigr, noea )
+         CALL mpprecv( 2, zt3we(1,1,1,1,1,2), imigr, nowe )
+         IF(l_isend)   CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend)   CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, zt3ew(1,1,1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, zt3we(1,1,1,1,1,2), imigr, nowe )
+         IF(l_isend)   CALL mpi_wait(ml_req1, ml_stat, ml_err )
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci-nn_hls
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jf = 1, ipf
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jh = 1, nn_hls
+                     ARRAY_IN(iihom+jh,:,jk,jl,jf) = zt3ew(:,jh,jk,jl,jf,2)
+                  END DO
+               END DO
+            END DO
+         END DO
+      CASE ( 0 )
+         DO jf = 1, ipf
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jh = 1, nn_hls
+                     ARRAY_IN(jh      ,:,jk,jl,jf) = zt3we(:,jh,jk,jl,jf,2)
+                     ARRAY_IN(iihom+jh,:,jk,jl,jf) = zt3ew(:,jh,jk,jl,jf,2)
+                  END DO
+               END DO
+            END DO
+         END DO
+      CASE ( 1 )
+         DO jf = 1, ipf
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jh = 1, nn_hls
+                     ARRAY_IN(jh      ,:,jk,jl,jf) = zt3we(:,jh,jk,jl,jf,2)
+                  END DO
+               END DO
+            END DO
+         END DO
+      END SELECT
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj-nrecj
+         DO jf = 1, ipf
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jh = 1, nn_hls
+                     zt3sn(:,jh,jk,jl,jf,1) = ARRAY_IN(:,ijhom +jh,jk,jl,jf)
+                     zt3ns(:,jh,jk,jl,jf,1) = ARRAY_IN(:,nn_hls+jh,jk,jl,jf)
+                  END DO
+               END DO
+            END DO
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = nn_hls * jpi * ipk * ipl * ipf
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, zt3sn(1,1,1,1,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, zt3ns(1,1,1,1,1,2), imigr, nono )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err )
+      CASE ( 0 )
+         CALL mppsend( 3, zt3ns(1,1,1,1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, zt3sn(1,1,1,1,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, zt3ns(1,1,1,1,1,2), imigr, nono )
+         CALL mpprecv( 4, zt3sn(1,1,1,1,1,2), imigr, noso )
+         IF(l_isend)   CALL mpi_wait(ml_req1, ml_stat, ml_err )
+         IF(l_isend)   CALL mpi_wait(ml_req2, ml_stat, ml_err )
+      CASE ( 1 )
+         CALL mppsend( 3, zt3ns(1,1,1,1,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, zt3sn(1,1,1,1,1,2), imigr, noso )
+         IF(l_isend)   CALL mpi_wait(ml_req1, ml_stat, ml_err )
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj-nn_hls
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jf = 1, ipf
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jh = 1, nn_hls
+                     ARRAY_IN(:,ijhom+jh,jk,jl,jf) = zt3ns(:,jh,jk,jl,jf,2)
+                  END DO
+               END DO
+            END DO
+         END DO
+      CASE ( 0 )
+         DO jf = 1, ipf
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jh = 1, nn_hls
+                     ARRAY_IN(:,      jh,jk,jl,jf) = zt3sn(:,jh,jk,jl,jf,2)
+                     ARRAY_IN(:,ijhom+jh,jk,jl,jf) = zt3ns(:,jh,jk,jl,jf,2)
+                  END DO
+               END DO
+            END DO
+         END DO
+      CASE ( 1 )
+         DO jf = 1, ipf
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jh = 1, nn_hls
+                     ARRAY_IN(:,jh,jk,jl,jf) = zt3sn(:,jh,jk,jl,jf,2)
+                  END DO
+               END DO
+            END DO
+         END DO
+      END SELECT
+
+      ! 4. north fold treatment
+      ! -----------------------
+      !
+      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd( ptab, NAT_IN(:), SGN_IN(:) OPT_K(:) )   ! only 1 northern proc, no mpp
+         CASE DEFAULT   ;   CALL mpp_nfd( ptab, NAT_IN(:), SGN_IN(:) OPT_K(:) )   ! for all northern procs.
+         END SELECT
+         !
+      ENDIF
+      !
+      DEALLOCATE( zt3ns, zt3sn, zt3ew, zt3we )
+      !
+   END SUBROUTINE ROUTINE_LNK
+
+#undef ARRAY_TYPE
+#undef NAT_IN
+#undef SGN_IN
+#undef ARRAY_IN
+#undef K_SIZE
+#undef L_SIZE
+#undef F_SIZE
+#undef OPT_K
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_nfd_generic.h90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_nfd_generic.h90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mpp_nfd_generic.h90	(revision 9019)
@@ -0,0 +1,235 @@
+#if defined MULTI
+#   define NAT_IN(k)                cd_nat(k)   
+#   define SGN_IN(k)                psgn(k)
+#   define F_SIZE(ptab)             kfld
+#   define LBC_ARG                  (jf)
+#   if defined DIM_2d
+#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_2D)     , INTENT(inout) ::   ptab(f)
+#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt2d(i,j)
+#      define K_SIZE(ptab)             1
+#      define L_SIZE(ptab)             1
+#   endif
+#   if defined DIM_3d
+#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_3D)     , INTENT(inout) ::   ptab(f)
+#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt3d(i,j,k)
+#      define K_SIZE(ptab)             SIZE(ptab(1)%pt3d,3)
+#      define L_SIZE(ptab)             1
+#   endif
+#   if defined DIM_4d
+#      define ARRAY_TYPE(i,j,k,l,f)    TYPE(PTR_4D)     , INTENT(inout) ::   ptab(f)
+#      define ARRAY_IN(i,j,k,l,f)      ptab(f)%pt4d(i,j,k,l)
+#      define K_SIZE(ptab)             SIZE(ptab(1)%pt4d,3)
+#      define L_SIZE(ptab)             SIZE(ptab(1)%pt4d,4)
+#   endif
+#else
+!                          !==  IN: ptab is an array  ==!
+#   define ARRAY_TYPE(i,j,k,l,f)    REAL(wp)         , INTENT(inout) ::   ARRAY_IN(i,j,k,l,f)
+#   define NAT_IN(k)                cd_nat
+#   define SGN_IN(k)                psgn
+#   define F_SIZE(ptab)             1
+#   define LBC_ARG
+#   if defined DIM_2d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j)
+#      define K_SIZE(ptab)          1
+#      define L_SIZE(ptab)          1
+#   endif
+#   if defined DIM_3d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k)
+#      define K_SIZE(ptab)          SIZE(ptab,3)
+#      define L_SIZE(ptab)          1
+#   endif
+#   if defined DIM_4d
+#      define ARRAY_IN(i,j,k,l,f)   ptab(i,j,k,l)
+#      define K_SIZE(ptab)          SIZE(ptab,3)
+#      define L_SIZE(ptab)          SIZE(ptab,4)
+#   endif
+#endif
+
+   SUBROUTINE ROUTINE_NFD( ptab, cd_nat, psgn, kfld )
+      !!----------------------------------------------------------------------
+      ARRAY_TYPE(:,:,:,:,:)   ! array or pointer of arrays on which the boundary condition is applied
+      CHARACTER(len=1) , INTENT(in   ) ::   NAT_IN(:)   ! nature of array grid-points
+      REAL(wp)         , INTENT(in   ) ::   SGN_IN(:)   ! sign used across the north fold boundary
+      INTEGER, OPTIONAL, INTENT(in   ) ::   kfld        ! number of pt3d arrays
+      !
+      INTEGER  ::   ji,  jj,  jk,  jl, jh, jf, jr   ! dummy loop indices
+      INTEGER  ::   ipi, ipj, ipk, ipl, ipf         ! dimension of the input array
+      INTEGER  ::   imigr, iihom, ijhom             ! local integers
+      INTEGER  ::   ierr, itaille, ildi, ilei, iilb
+      INTEGER  ::   ij, iproc
+      INTEGER, DIMENSION (jpmaxngh)       ::   ml_req_nf   ! for mpi_isend when avoiding mpi_allgather
+      INTEGER                             ::   ml_err      ! for mpi_isend when avoiding mpi_allgather
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat     ! for mpi_isend when avoiding mpi_allgather
+      !                                                    ! Workspace for message transfers avoiding mpi_allgather
+      REAL(wp), DIMENSION(:,:,:,:,:)  , ALLOCATABLE ::   ztab, ztabl, ztabr
+      REAL(wp), DIMENSION(:,:,:,:,:)  , ALLOCATABLE ::   znorthloc, zfoldwk      
+      REAL(wp), DIMENSION(:,:,:,:,:,:), ALLOCATABLE ::   znorthgloio
+      !!----------------------------------------------------------------------
+      !
+      ipk = K_SIZE(ptab)   ! 3rd dimension
+      ipl = L_SIZE(ptab)   ! 4th    -
+      ipf = F_SIZE(ptab)   ! 5th    -      use in "multi" case (array of pointers)
+      !
+      ipj   = 4            ! 2nd dimension of message transfers (last j-lines)
+      !
+      ALLOCATE( znorthloc(jpimax,4,ipk,ipl,ipf) )
+      !
+      znorthloc(:,:,:,:,:) = 0._wp
+      !
+      DO jf = 1, ipf                ! put in znorthloc the last ipj j-lines of ptab
+         DO jl = 1, ipl
+            DO jk = 1, ipk
+               DO jj = nlcj - ipj +1, nlcj
+                  ij = jj - nlcj + ipj
+                  znorthloc(1:jpi,ij,jk,jl,jf) = ARRAY_IN(1:jpi,jj,jk,jl,jf)
+               END DO
+            END DO
+         END DO
+      END DO
+      !
+      !
+      itaille = jpimax * ipj * ipk * ipl * ipf
+      !
+      IF( l_north_nogather ) THEN      !==  ????  ==!
+         ALLOCATE( zfoldwk(jpi,4,ipk,ipl,ipf) )
+         ALLOCATE( ztabl(jpi   ,4,ipk,ipl,ipf) , ztabr(jpi*jpmaxngh,4,ipk,ipl,ipf) ) 
+         !
+         ztabr(:,:,:,:,:) = 0._wp
+         ztabl(:,:,:,:,:) = 0._wp
+         !
+         DO jf = 1, ipf
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jj = nlcj-ipj+1, nlcj          ! First put local values into the global array
+                     ij = jj - nlcj + ipj
+                     DO ji = nfsloop, nfeloop
+                        ztabl(ji,ij,jk,jl,jf) = ARRAY_IN(ji,jj,jk,jl,jf)
+                     END DO
+                  END DO
+               END DO
+            END DO
+         END DO
+         !
+         DO jr = 1, nsndto
+            IF( nfipproc(isendto(jr),jpnj) /= narea-1 .AND. nfipproc(isendto(jr),jpnj) /= -1 ) THEN
+              CALL mppsend( 5, znorthloc, itaille, nfipproc(isendto(jr),jpnj), ml_req_nf(jr) )
+            ENDIF
+         END DO
+         DO jr = 1,nsndto
+            iproc = nfipproc(isendto(jr),jpnj)
+            IF(iproc /= -1) THEN
+               ilei = nleit (iproc+1)
+               ildi = nldit (iproc+1)
+               iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj)
+            ENDIF
+            IF( iproc /= narea-1 .AND. iproc /= -1 ) THEN
+              CALL mpprecv(5, zfoldwk, itaille, iproc)
+               DO jf = 1, ipf
+                  DO jl = 1, ipl
+                     DO jk = 1, ipk
+                        DO jj = 1, ipj
+                           DO ji = ildi, ilei
+                              ztabr(iilb+ji,jj,jk,jl,jf) = zfoldwk(ji,jj,jk,jl,jf)
+                           END DO
+                        END DO
+                     END DO
+                  END DO
+               END DO
+            ELSE IF( iproc == narea-1 ) THEN
+               DO jf = 1, ipf
+                  DO jl = 1, ipl
+                     DO jk = 1, ipk
+                        DO jj = 1, ipj
+                           DO ji = ildi, ilei
+                              ztabr(iilb+ji,jj,jk,jl,jf) = ARRAY_IN(ji,nlcj-ipj+jj,jk,jl,jf)
+                           END DO
+                        END DO
+                     END DO
+                  END DO
+               END DO
+            ENDIF
+         END DO
+         IF( l_isend ) THEN
+            DO jr = 1,nsndto
+               IF( nfipproc(isendto(jr),jpnj) /= narea-1 .AND. nfipproc(isendto(jr),jpnj) /= -1 ) THEN
+                  CALL mpi_wait( ml_req_nf(jr), ml_stat, ml_err )
+               ENDIF    
+            END DO
+         ENDIF
+         DO jf = 1, ipf
+            CALL lbc_nfd_nogather( ztabl(:,:,:,:,jf), ztabr(:,:,:,:,jf), cd_nat LBC_ARG, psgn LBC_ARG )   ! North fold boundary condition
+         END DO
+         DO jf = 1, ipf
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jj = nlcj-ipj+1, nlcj             ! Scatter back to ARRAY_IN
+                     ij = jj - nlcj + ipj
+                     DO ji= 1, nlci
+                        ARRAY_IN(ji,jj,jk,jl,jf) = ztabl(ji,ij,jk,jl,jf)
+                     END DO
+                  END DO
+               END DO
+            END DO
+         END DO
+         !
+         DEALLOCATE( zfoldwk )
+         DEALLOCATE( ztabl, ztabr ) 
+      ELSE                             !==  ????  ==!
+         ALLOCATE( ztab       (jpiglo,4,ipk,ipl,ipf     ) )
+         ALLOCATE( znorthgloio(jpimax,4,ipk,ipl,ipf,jpni) )
+         !
+         CALL MPI_ALLGATHER( znorthloc  , itaille, MPI_DOUBLE_PRECISION,                &
+            &                znorthgloio, itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
+         !
+         ztab(:,:,:,:,:) = 0._wp
+         DO jr = 1, ndim_rank_north         ! recover the global north array
+            iproc = nrank_north(jr) + 1
+            ildi  = nldit (iproc)
+            ilei  = nleit (iproc)
+            iilb  = nimppt(iproc)
+            DO jf = 1, ipf
+               DO jl = 1, ipl
+                  DO jk = 1, ipk
+                     DO jj = 1, ipj
+                        DO ji = ildi, ilei
+                           ztab(ji+iilb-1,jj,jk,jl,jf) = znorthgloio(ji,jj,jk,jl,jf,jr)
+                        END DO
+                     END DO
+                  END DO
+               END DO
+            END DO
+         END DO
+         DO jf = 1, ipf
+            CALL lbc_nfd( ztab(:,:,:,:,jf), cd_nat LBC_ARG, psgn LBC_ARG )   ! North fold boundary condition
+         END DO
+         !
+         DO jf = 1, ipf
+            DO jl = 1, ipl
+               DO jk = 1, ipk
+                  DO jj = nlcj-ipj+1, nlcj             ! Scatter back to ARRAY_IN
+                     ij = jj - nlcj + ipj
+                     DO ji= 1, nlci
+                        ARRAY_IN(ji,jj,jk,jl,jf) = ztab(ji+nimpp-1,ij,jk,jl,jf)
+                     END DO
+                  END DO
+               END DO
+            END DO
+         END DO
+         !
+      !
+         DEALLOCATE( ztab )
+         DEALLOCATE( znorthgloio )
+      ENDIF
+      !
+      DEALLOCATE( znorthloc )
+      !
+   END SUBROUTINE ROUTINE_NFD
+
+#undef ARRAY_TYPE
+#undef NAT_IN
+#undef SGN_IN
+#undef ARRAY_IN
+#undef K_SIZE
+#undef L_SIZE
+#undef F_SIZE
+#undef LBC_ARG
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mppini.F90	(revision 9019)
@@ -1,18 +1,27 @@
 MODULE mppini
-   !!==============================================================================
+   !!======================================================================
    !!                       ***  MODULE mppini   ***
    !! Ocean initialization : distributed memory computing initialization
-   !!==============================================================================
-
-   !!----------------------------------------------------------------------
-   !!   mpp_init       : Lay out the global domain over processors
-   !!   mpp_init2      : Lay out the global domain over processors 
-   !!                    with land processor elimination
-   !!   mpp_init_ioispl: IOIPSL initialization in mpp
-   !!----------------------------------------------------------------------
-   USE dom_oce         ! ocean space and time domain 
-   USE in_out_manager  ! I/O Manager
-   USE lib_mpp         ! distribued memory computing library
-   USE ioipsl
+   !!======================================================================
+   !! History :  6.0  !  1994-11  (M. Guyon)  Original code
+   !!  OPA       7.0  !  1995-04  (J. Escobar, M. Imbard)
+   !!            8.0  !  1998-05  (M. Imbard, J. Escobar, L. Colombet )  SHMEM and MPI versions
+   !!  NEMO      1.0  !  2004-01  (G. Madec, J.M Molines)  F90 : free form , north fold jpni > 1
+   !!            4.0  !  2016-06  (G. Madec)  use domain configuration file instead of bathymetry file
+   !!            4.0  !  2017-06  (J.M. Molines, T. Lovato) merge of mppini and mppini_2
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!  mpp_init       : Lay out the global domain over processors with/without land processor elimination
+   !!  mpp_init_mask  : 
+   !!  mpp_init_ioipsl: IOIPSL initialization in mpp 
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean space and time domain
+   USE bdy_oce        ! open BounDarY  
+   !
+   USE lib_mpp        ! distribued memory computing library
+   USE iom            ! nemo I/O library 
+   USE ioipsl         ! I/O IPSL library
+   USE in_out_manager ! I/O Manager
 
    IMPLICIT NONE
@@ -20,8 +29,7 @@
 
    PUBLIC mpp_init       ! called by opa.F90
-   PUBLIC mpp_init2      ! called by opa.F90
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -41,12 +49,8 @@
       !!
       !! ** Method  :   Shared memory computing, set the local processor
-      !!      variables to the value of the global domain
-      !!
-      !! History :
-      !!   9.0  !  04-01  (G. Madec, J.M. Molines)  F90 : free form, north fold jpni >1
-      !!----------------------------------------------------------------------
-
-      ! No mpp computation
-      nimpp  = 1
+      !!              variables to the value of the global domain
+      !!----------------------------------------------------------------------
+      !
+      nimpp  = 1           ! 
       njmpp  = 1
       nlci   = jpi
@@ -61,31 +65,25 @@
       nidom  = FLIO_DOM_NONE
       npolj = jperio
-
+      !
       IF(lwp) THEN
          WRITE(numout,*)
-         WRITE(numout,*) 'mpp_init(2) : NO massively parallel processing'
-         WRITE(numout,*) '~~~~~~~~~~~ '
-         WRITE(numout,*) '         nperio = ', nperio
-         WRITE(numout,*) '         npolj  = ', npolj
-         WRITE(numout,*) '         nimpp  = ', nimpp
-         WRITE(numout,*) '         njmpp  = ', njmpp
-      ENDIF
-
-      IF(  jpni /= 1 .OR. jpnj /= 1 .OR. jpnij /= 1 ) &
-          CALL ctl_stop( 'equality  jpni = jpnj = jpnij = 1 is not satisfied',   &
-          &              'the domain is lay out for distributed memory computing! ' )
-
-      IF( jperio == 7 ) CALL ctl_stop( ' jperio = 7 needs distributed memory computing ',   &
-          &              ' with 1 process. Add key_mpp_mpi in the list of active cpp keys ' )
+         WRITE(numout,*) 'mpp_init : NO massively parallel processing'
+         WRITE(numout,*) '~~~~~~~~ '
+         WRITE(numout,*) '   nperio = ', nperio, '   nimpp  = ', nimpp
+         WRITE(numout,*) '   npolj  = ', npolj , '   njmpp  = ', njmpp
+      ENDIF
+      !
+      IF(  jpni /= 1 .OR. jpnj /= 1 .OR. jpnij /= 1 )                                     &
+         CALL ctl_stop( 'mpp_init: equality  jpni = jpnj = jpnij = 1 is not satisfied',   &
+            &           'the domain is lay out for distributed memory computing!' )
+         !
+      IF( jperio == 7 ) CALL ctl_stop( 'mpp_init: jperio = 7 needs distributed memory computing ',       &
+         &                             'with 1 process. Add key_mpp_mpi in the list of active cpp keys ' )
+         !
    END SUBROUTINE mpp_init
 
-
-   SUBROUTINE mpp_init2 
-      CALL mpp_init                             ! same routine as mpp_init
-   END SUBROUTINE mpp_init2
-
 #else
    !!----------------------------------------------------------------------
-   !!   'key_mpp_mpi'          OR         MPI massively parallel processing
+   !!   'key_mpp_mpi'                     MPI massively parallel processing
    !!----------------------------------------------------------------------
 
@@ -95,4 +93,8 @@
       !!                    
       !! ** Purpose :   Lay out the global domain over processors.
+      !!      If land processors are to be eliminated, this program requires the
+      !!      presence of the domain configuration file. Land processors elimination
+      !!      is performed if jpni x jpnj /= jpnij. In this case, using the MPP_PREP
+      !!      preprocessing tool, help for defining the best cutting out.
       !!
       !! ** Method  :   Global domain is distributed in smaller local domains.
@@ -103,5 +105,5 @@
       !!                     nperio local  periodic condition
       !!
-      !! ** Action  : - set domain parameters
+      !! ** Action : - set domain parameters
       !!                    nimpp     : longitudinal index 
       !!                    njmpp     : latitudinal  index
@@ -117,344 +119,453 @@
       !!                    noso      : number for local neighboring processor
       !!                    nono      : number for local neighboring processor
-      !!
-      !! History :
-      !!        !  94-11  (M. Guyon)  Original code
-      !!        !  95-04  (J. Escobar, M. Imbard)
-      !!        !  98-02  (M. Guyon)  FETI method
-      !!        !  98-05  (M. Imbard, J. Escobar, L. Colombet )  SHMEM and MPI versions
-      !!   8.5  !  02-08  (G. Madec)  F90 : free form
-      !!   3.4  !  11-11  (C. Harris) decomposition changes for running with CICE
-      !!----------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jn   ! dummy loop indices
-      INTEGER  ::   ii, ij, ifreq, il1, il2            ! local integers
-      INTEGER  ::   iresti, irestj, ijm1, imil, inum   !   -      -
-      REAL(wp) ::   zidom, zjdom                       ! local scalars
-      INTEGER, DIMENSION(jpni,jpnj) ::   iimppt, ijmppt, ilcit, ilcjt   ! local workspace
-      !!----------------------------------------------------------------------
-
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'mpp_init : Message Passing MPI'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~'
-
-
+      !!----------------------------------------------------------------------
+      INTEGER ::   ji, jj, jn, jproc, jarea   ! dummy loop indices
+      INTEGER ::   inum                       ! local logical unit
+      INTEGER ::   idir, ifreq, icont, isurf  ! local integers
+      INTEGER ::   ii, il1, ili, imil         !   -       -
+      INTEGER ::   ij, il2, ilj, ijm1         !   -       -
+      INTEGER ::   iino, ijno, iiso, ijso     !   -       -
+      INTEGER ::   iiea, ijea, iiwe, ijwe     !   -       -
+      INTEGER ::   iresti, irestj, iproc      !   -       -
+      INTEGER, DIMENSION(jpnij) ::   iin, ii_nono, ii_noea   ! 1D workspace
+      INTEGER, DIMENSION(jpnij) ::   ijn, ii_noso, ii_nowe   !  -     -
+      INTEGER, DIMENSION(jpni,jpnj) ::   iimppt, ilci, ibondi, ipproc   ! 2D workspace
+      INTEGER, DIMENSION(jpni,jpnj) ::   ijmppt, ilcj, ibondj, ipolj    !  -     -
+      INTEGER, DIMENSION(jpni,jpnj) ::   ilei, ildi, iono, ioea         !  -     -
+      INTEGER, DIMENSION(jpni,jpnj) ::   ilej, ildj, ioso, iowe         !  -     -
+      INTEGER, DIMENSION(jpiglo,jpjglo) ::   imask   ! 2D golbal domain workspace
+      REAL(wp) ::   zidom, zjdom   ! local scalars
+      !!----------------------------------------------------------------------
+      !
+      IF ( jpni * jpnj == jpnij ) THEN    ! regular domain lay out over processors
+         imask(:,:) = 1               
+      ELSEIF ( jpni*jpnj > jpnij ) THEN   ! remove land-only processor (i.e. where imask(:,:)=0)
+         CALL mpp_init_mask( imask )   
+      ELSE                                ! error
+         CALL ctl_stop( 'mpp_init: jpnij > jpni x jpnj. Check namelist setting!' )
+      ENDIF
+      !
       !  1. Dimension arrays for subdomains
       ! -----------------------------------
-      !  Computation of local domain sizes ilcit() ilcjt()
+      !  Computation of local domain sizes ilci() ilcj()
       !  These dimensions depend on global sizes jpni,jpnj and jpiglo,jpjglo
-      !  The subdomains are squares leeser than or equal to the global
-      !  dimensions divided by the number of processors minus the overlap
-      !  array (cf. par_oce.F90).
-      
-      nreci  = 2 * jpreci
-      nrecj  = 2 * jprecj
-      iresti = MOD( jpiglo - nreci , jpni )
-      irestj = MOD( jpjglo - nrecj , jpnj )
-
-      IF(  iresti == 0 )   iresti = jpni
-
+      !  The subdomains are squares lesser than or equal to the global
+      !  dimensions divided by the number of processors minus the overlap array.
+      !
+      nreci = 2 * nn_hls
+      nrecj = 2 * nn_hls
+      iresti = 1 + MOD( jpiglo - nreci -1 , jpni )
+      irestj = 1 + MOD( jpjglo - nrecj -1 , jpnj )
+      !
+      !  Need to use jpimax and jpjmax here since jpi and jpj have already been
+      !  shrunk to local sizes in nemogcm
 #if defined key_nemocice_decomp
-      ! In order to match CICE the size of domains in NEMO has to be changed
-      ! The last line of blocks (west) will have fewer points
-
-      DO jj = 1, jpnj
-         DO ji=1, jpni-1
-            ilcit(ji,jj) = jpi
-         END DO
-         ilcit(jpni,jj) = jpiglo - (jpni - 1) * (jpi - nreci)
-      END DO
-
+      ! Change padding to be consistent with CICE
+      ilci(1:jpni-1      ,:) = jpimax
+      ilci(jpni          ,:) = jpiglo - (jpni - 1) * (jpimax - nreci)
+      !
+      ilcj(:,      1:jpnj-1) = jpjmax
+      ilcj(:,          jpnj) = jpjglo - (jpnj - 1) * (jpjmax - nrecj)
 #else
-
-      DO jj = 1, jpnj
-         DO ji = 1, iresti
-            ilcit(ji,jj) = jpi
-         END DO
-         DO ji = iresti+1, jpni
-            ilcit(ji,jj) = jpi -1
-         END DO
-      END DO
-      
+      ilci(1:iresti      ,:) = jpimax
+      ilci(iresti+1:jpni ,:) = jpimax-1
+
+      ilcj(:,      1:irestj) = jpjmax
+      ilcj(:, irestj+1:jpnj) = jpjmax-1
 #endif
-      nfilcit(:,:) = ilcit(:,:)
-      IF( irestj == 0 )   irestj = jpnj
-
-#if defined key_nemocice_decomp
-      ! Same change to domains in North-South direction as in East-West. 
-      DO ji=1,jpni
-         DO jj=1,jpnj-1
-            ilcjt(ji,jj) = jpj
-         END DO
-         ilcjt(ji,jpnj) = jpjglo - (jpnj - 1) * (jpj - nrecj)
-      END DO
-
-#else
-
-      DO ji = 1, jpni
-         DO jj = 1, irestj
-            ilcjt(ji,jj) = jpj
-         END DO
-         DO jj = irestj+1, jpnj
-            ilcjt(ji,jj) = jpj -1
-         END DO
-      END DO
-      
-#endif
+      !
+      nfilcit(:,:) = ilci(:,:)
+      !
+      zidom = nreci + sum(ilci(:,1) - nreci )
+      zjdom = nrecj + sum(ilcj(1,:) - nrecj )
+      !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'mpp_init : MPI Message Passing MPI - domain lay out over processors'
+         WRITE(numout,*) '~~~~~~~~ '
+         WRITE(numout,*) '   defines mpp subdomains'
+         WRITE(numout,*) '      iresti = ', iresti, ' jpni = ', jpni  
+         WRITE(numout,*) '      irestj = ', irestj, ' jpnj = ', jpnj
+         WRITE(numout,*)
+         WRITE(numout,*) '      sum ilci(i,1) = ', zidom, ' jpiglo = ', jpiglo
+         WRITE(numout,*) '      sum ilcj(1,j) = ', zjdom, ' jpjglo = ', jpjglo
+      ENDIF
 
       !  2. Index arrays for subdomains
       ! -------------------------------
-      
-      iimppt(:,:) = 1
-      ijmppt(:,:) = 1
-      
+      iimppt(:,:) =  1
+      ijmppt(:,:) =  1
+      ipproc(:,:) = -1
+      !
       IF( jpni > 1 ) THEN
          DO jj = 1, jpnj
             DO ji = 2, jpni
-               iimppt(ji,jj) = iimppt(ji-1,jj) + ilcit(ji-1,jj) - nreci
+               iimppt(ji,jj) = iimppt(ji-1,jj) + ilci(ji-1,jj) - nreci
             END DO
          END DO
       ENDIF
-      nfiimpp(:,:)=iimppt(:,:)
-
-      IF( jpnj > 1 ) THEN
+      nfiimpp(:,:) = iimppt(:,:)
+      !
+      IF( jpnj > 1 )THEN
          DO jj = 2, jpnj
             DO ji = 1, jpni
-               ijmppt(ji,jj) = ijmppt(ji,jj-1)+ilcjt(ji,jj-1)-nrecj
+               ijmppt(ji,jj) = ijmppt(ji,jj-1) + ilcj(ji,jj-1) - nrecj
             END DO
          END DO
       ENDIF
-      
-      ! 3. Subdomain description
-      ! ------------------------
-
-      DO jn = 1, jpnij
-         ii = 1 + MOD( jn-1, jpni )
-         ij = 1 + (jn-1) / jpni
-         nfipproc(ii,ij) = jn - 1
-         nimppt(jn) = iimppt(ii,ij)
-         njmppt(jn) = ijmppt(ii,ij)
-         nlcit (jn) = ilcit (ii,ij)     
-         nlci       = nlcit (jn)     
-         nlcjt (jn) = ilcjt (ii,ij)     
-         nlcj       = nlcjt (jn)
-         nbondj = -1                                   ! general case
-         IF( jn   >  jpni          )   nbondj = 0      ! first row of processor
-         IF( jn   >  (jpnj-1)*jpni )   nbondj = 1      ! last  row of processor
-         IF( jpnj == 1             )   nbondj = 2      ! one processor only in j-direction
-         ibonjt(jn) = nbondj
-         
-         nbondi = 0                                    ! 
-         IF( MOD( jn, jpni ) == 1 )   nbondi = -1      !
-         IF( MOD( jn, jpni ) == 0 )   nbondi =  1      !
-         IF( jpni            == 1 )   nbondi =  2      ! one processor only in i-direction
-         ibonit(jn) = nbondi
-         
-         nldi =  1   + jpreci
-         nlei = nlci - jpreci
-         IF( nbondi == -1 .OR. nbondi == 2 )   nldi = 1
-         IF( nbondi ==  1 .OR. nbondi == 2 )   nlei = nlci
-         nldj =  1   + jprecj
-         nlej = nlcj - jprecj
-         IF( nbondj == -1 .OR. nbondj == 2 )   nldj = 1
-         IF( nbondj ==  1 .OR. nbondj == 2 )   nlej = nlcj
-         nldit(jn) = nldi
-         nleit(jn) = nlei
-         nldjt(jn) = nldj
-         nlejt(jn) = nlej
+
+      ! 3. Subdomain description in the Regular Case
+      ! --------------------------------------------
+      nperio = 0
+      icont = -1
+      DO jarea = 1, jpni*jpnj
+         ii = 1 + MOD(jarea-1,jpni)
+         ij = 1 +    (jarea-1)/jpni
+         ili = ilci(ii,ij)
+         ilj = ilcj(ii,ij)
+         ibondj(ii,ij) = -1
+         IF( jarea >  jpni          )   ibondj(ii,ij) = 0
+         IF( jarea >  (jpnj-1)*jpni )   ibondj(ii,ij) = 1
+         IF( jpnj  == 1             )   ibondj(ii,ij) = 2
+         ibondi(ii,ij) = 0
+         IF( MOD(jarea,jpni) == 1 )   ibondi(ii,ij) = -1
+         IF( MOD(jarea,jpni) == 0 )   ibondi(ii,ij) =  1
+         IF( jpni            == 1 )   ibondi(ii,ij) =  2
+
+         ! Subdomain neighbors
+         iproc = jarea - 1
+         ioso(ii,ij) = iproc - jpni
+         iowe(ii,ij) = iproc - 1
+         ioea(ii,ij) = iproc + 1
+         iono(ii,ij) = iproc + jpni
+         ildi(ii,ij) =  1  + nn_hls
+         ilei(ii,ij) = ili - nn_hls
+
+         IF( ibondi(ii,ij) == -1 .OR. ibondi(ii,ij) == 2 ) ildi(ii,ij) =  1
+         IF( ibondi(ii,ij) ==  1 .OR. ibondi(ii,ij) == 2 ) ilei(ii,ij) = ili
+         ildj(ii,ij) =  1  + nn_hls
+         ilej(ii,ij) = ilj - nn_hls
+         IF( ibondj(ii,ij) == -1 .OR. ibondj(ii,ij) == 2 ) ildj(ii,ij) =  1
+         IF( ibondj(ii,ij) ==  1 .OR. ibondj(ii,ij) == 2 ) ilej(ii,ij) = ilj
+
+         ! warning ii*ij (zone) /= nproc (processors)!
+
+         IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 ) THEN
+            IF( jpni == 1 )THEN
+               ibondi(ii,ij) = 2
+               nperio = 1
+            ELSE
+               ibondi(ii,ij) = 0
+            ENDIF
+            IF( MOD(jarea,jpni) == 0 ) THEN
+               ioea(ii,ij) = iproc - (jpni-1)
+            ENDIF
+            IF( MOD(jarea,jpni) == 1 ) THEN
+               iowe(ii,ij) = iproc + jpni - 1
+            ENDIF
+         ENDIF
+         ipolj(ii,ij) = 0
+         IF( jperio == 3 .OR. jperio == 4 ) THEN
+            ijm1 = jpni*(jpnj-1)
+            imil = ijm1+(jpni+1)/2
+            IF( jarea > ijm1 ) ipolj(ii,ij) = 3
+            IF( MOD(jpni,2) == 1 .AND. jarea == imil ) ipolj(ii,ij) = 4
+            IF( ipolj(ii,ij) == 3 ) iono(ii,ij) = jpni*jpnj-jarea+ijm1   ! MPI rank of northern neighbour
+         ENDIF
+         IF( jperio == 5 .OR. jperio == 6 ) THEN
+            ijm1 = jpni*(jpnj-1)
+            imil = ijm1+(jpni+1)/2
+            IF( jarea > ijm1) ipolj(ii,ij) = 5
+            IF( MOD(jpni,2) == 1 .AND. jarea == imil ) ipolj(ii,ij) = 6
+            IF( ipolj(ii,ij) == 5) iono(ii,ij) = jpni*jpnj-jarea+ijm1    ! MPI rank of northern neighbour
+         ENDIF
+         !
+         ! Check wet points over the entire domain to preserve the MPI communication stencil
+         isurf = 0
+         DO jj = 1, ilj
+            DO  ji = 1, ili
+               IF( imask(ji+iimppt(ii,ij)-1, jj+ijmppt(ii,ij)-1) == 1)   isurf = isurf+1
+            END DO
+         END DO
+         !
+         IF( isurf /= 0 ) THEN
+            icont = icont + 1
+            ipproc(ii,ij) = icont
+            iin(icont+1) = ii
+            ijn(icont+1) = ij
+         ENDIF
       END DO
+      !
+      nfipproc(:,:) = ipproc(:,:)
+
+      ! Check potential error
+      IF( icont+1 /= jpnij ) THEN
+         WRITE(ctmp1,*) ' jpni =',jpni,' jpnj =',jpnj
+         WRITE(ctmp2,*) ' jpnij =',jpnij, '< jpni x jpnj' 
+         WRITE(ctmp3,*) ' ***********, mpp_init2 finds jpnij=',icont+1
+         CALL ctl_stop( 'mpp_init: Eliminate land processors algorithm', '', ctmp1, ctmp2, '', ctmp3 )
+      ENDIF
 
       ! 4. Subdomain print
       ! ------------------
-      
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) '   defines mpp subdomains'
-      IF(lwp) WRITE(numout,*) '      jpni=', jpni, ' iresti=', iresti
-      IF(lwp) WRITE(numout,*) '      jpnj=', jpnj, ' irestj=', irestj
-      zidom = nreci
-      DO ji = 1, jpni
-         zidom = zidom + ilcit(ji,1) - nreci
-      END DO
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*)'      sum ilcit(i,1)=', zidom, ' jpiglo=', jpiglo
-
-      zjdom = nrecj
-      DO jj = 1, jpnj
-         zjdom = zjdom + ilcjt(1,jj) - nrecj
-      END DO
-      IF(lwp) WRITE(numout,*)'      sum ilcit(1,j)=', zjdom, ' jpjglo=', jpjglo
-
       IF(lwp) THEN
          ifreq = 4
-         il1   = 1
+         il1 = 1
          DO jn = 1, (jpni-1)/ifreq+1
-            il2 = MIN( jpni, il1+ifreq-1 )
+            il2 = MIN(jpni,il1+ifreq-1)
             WRITE(numout,*)
-            WRITE(numout,9200) ('***',ji = il1,il2-1)
+            WRITE(numout,9400) ('***',ji=il1,il2-1)
             DO jj = jpnj, 1, -1
-               WRITE(numout,9203) ('   ',ji = il1,il2-1)
-               WRITE(numout,9202) jj, ( ilcit(ji,jj),ilcjt(ji,jj),ji = il1,il2 )
-               WRITE(numout,9204) (nfipproc(ji,jj),ji=il1,il2)
-               WRITE(numout,9203) ('   ',ji = il1,il2-1)
-               WRITE(numout,9200) ('***',ji = il1,il2-1)
+               WRITE(numout,9403) ('   ',ji=il1,il2-1)
+               WRITE(numout,9402) jj, (ilci(ji,jj),ilcj(ji,jj),ji=il1,il2)
+               WRITE(numout,9404) (ipproc(ji,jj),ji=il1,il2)
+               WRITE(numout,9403) ('   ',ji=il1,il2-1)
+               WRITE(numout,9400) ('***',ji=il1,il2-1)
             END DO
-            WRITE(numout,9201) (ji,ji = il1,il2)
+            WRITE(numout,9401) (ji,ji=il1,il2)
             il1 = il1+ifreq
          END DO
- 9200     FORMAT('     ***',20('*************',a3))
- 9203     FORMAT('     *     ',20('         *   ',a3))
- 9201     FORMAT('        ',20('   ',i3,'          '))
- 9202     FORMAT(' ',i3,' *  ',20(i3,'  x',i3,'   *   '))
- 9204     FORMAT('     *  ',20('      ',i3,'   *   '))
-      ENDIF
-
-      ! 5. From global to local
-      ! -----------------------
-
-      nperio = 0
-      IF( jperio == 2 .AND. nbondj == -1 )   nperio = 2
-
-
-      ! 6. Subdomain neighbours
+ 9400    FORMAT('     ***',20('*************',a3))
+ 9403    FORMAT('     *     ',20('         *   ',a3))
+ 9401    FORMAT('        ',20('   ',i3,'          '))
+ 9402    FORMAT(' ',i3,' *  ',20(i3,'  x',i3,'   *   '))
+ 9404    FORMAT('     *  ',20('      ',i3,'   *   '))
+      ENDIF
+
+      ! 5. neighbour treatment
       ! ----------------------
-
-      nproc = narea - 1
-      noso  = nproc - jpni
-      nowe  = nproc - 1
-      noea  = nproc + 1
-      nono  = nproc + jpni
-      ! great neighbours
-      npnw = nono - 1
-      npne = nono + 1
-      npsw = noso - 1
-      npse = noso + 1
-      nbsw = 1
-      nbnw = 1
-      IF( MOD( nproc, jpni ) == 0 ) THEN
-         nbsw = 0
-         nbnw = 0
-      ENDIF
-      nbse = 1
-      nbne = 1
-      IF( MOD( nproc, jpni ) == jpni-1 ) THEN
-         nbse = 0
-         nbne = 0
-      ENDIF
-      IF(nproc < jpni) THEN
-         nbsw = 0
-         nbse = 0
-      ENDIF
-      IF( nproc >= (jpnj-1)*jpni ) THEN
-         nbnw = 0
-         nbne = 0
-      ENDIF
-      nlcj = nlcjt(narea)  
-      nlci = nlcit(narea)  
-      nldi = nldit(narea)
-      nlei = nleit(narea)
-      nldj = nldjt(narea)
-      nlej = nlejt(narea)
-      nbondi = ibonit(narea)
-      nbondj = ibonjt(narea)
-      nimpp  = nimppt(narea)  
-      njmpp  = njmppt(narea)  
-
-      ! Save processor layout in layout.dat file 
-      IF(lwp) THEN
+      DO jarea = 1, jpni*jpnj
+         iproc = jarea-1
+         ii = 1 + MOD( jarea-1  , jpni )
+         ij = 1 +     (jarea-1) / jpni
+         IF ( ipproc(ii,ij) == -1 .AND. 0 <= iono(ii,ij) .AND. iono(ii,ij) <= jpni*jpnj-1 ) THEN
+            iino = 1 + MOD( iono(ii,ij) , jpni )
+            ijno = 1 +      iono(ii,ij) / jpni
+            ! Need to reverse the logical direction of communication 
+            ! for northern neighbours of northern row processors (north-fold)
+            ! i.e. need to check that the northern neighbour only communicates
+            ! to the SOUTH (or not at all) if this area is land-only (#1057)
+            idir = 1
+            IF( ij == jpnj .AND. ijno == jpnj )   idir = -1    
+            IF( ibondj(iino,ijno) == idir     )   ibondj(iino,ijno) =   2
+            IF( ibondj(iino,ijno) == 0        )   ibondj(iino,ijno) = -idir
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. 0 <= ioso(ii,ij) .AND. ioso(ii,ij) <= jpni*jpnj-1 ) THEN
+            iiso = 1 + MOD( ioso(ii,ij) , jpni )
+            ijso = 1 +      ioso(ii,ij) / jpni
+            IF( ibondj(iiso,ijso) == -1 )   ibondj(iiso,ijso) = 2
+            IF( ibondj(iiso,ijso) ==  0 )   ibondj(iiso,ijso) = 1
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. 0 <= ioea(ii,ij) .AND. ioea(ii,ij) <= jpni*jpnj-1 ) THEN
+            iiea = 1 + MOD( ioea(ii,ij) , jpni )
+            ijea = 1 +      ioea(ii,ij) / jpni
+            IF( ibondi(iiea,ijea) == 1 )   ibondi(iiea,ijea) =  2
+            IF( ibondi(iiea,ijea) == 0 )   ibondi(iiea,ijea) = -1
+         ENDIF
+         IF( ipproc(ii,ij) == -1 .AND. 0 <= iowe(ii,ij) .AND. iowe(ii,ij) <= jpni*jpnj-1) THEN
+            iiwe = 1 + MOD( iowe(ii,ij) , jpni )
+            ijwe = 1 +      iowe(ii,ij) / jpni
+            IF( ibondi(iiwe,ijwe) == -1 )   ibondi(iiwe,ijwe) = 2
+            IF( ibondi(iiwe,ijwe) ==  0 )   ibondi(iiwe,ijwe) = 1
+         ENDIF
+      END DO
+
+      ! just to save nono etc for all proc
+      ii_noso(:) = -1
+      ii_nono(:) = -1
+      ii_noea(:) = -1
+      ii_nowe(:) = -1 
+      nproc = narea-1
+      DO jarea = 1, jpnij
+         ii = iin(jarea)
+         ij = ijn(jarea)
+         IF( 0 <= ioso(ii,ij) .AND. ioso(ii,ij) <= (jpni*jpnj-1) ) THEN
+            iiso = 1 + MOD( ioso(ii,ij) , jpni )
+            ijso = 1 +      ioso(ii,ij) / jpni
+            noso = ipproc(iiso,ijso)
+            ii_noso(jarea)= noso
+         ENDIF
+         IF( 0 <= iowe(ii,ij) .AND. iowe(ii,ij) <= (jpni*jpnj-1) ) THEN
+          iiwe = 1 + MOD( iowe(ii,ij) , jpni )
+          ijwe = 1 +      iowe(ii,ij) / jpni
+          nowe = ipproc(iiwe,ijwe)
+          ii_nowe(jarea)= nowe
+         ENDIF
+         IF( 0 <= ioea(ii,ij) .AND. ioea(ii,ij) <= (jpni*jpnj-1) ) THEN
+            iiea = 1 + MOD( ioea(ii,ij) , jpni )
+            ijea = 1 +      ioea(ii,ij) / jpni
+            noea = ipproc(iiea,ijea)
+            ii_noea(jarea)= noea
+         ENDIF
+         IF( 0 <= iono(ii,ij) .AND. iono(ii,ij) <= (jpni*jpnj-1) ) THEN
+            iino = 1 + MOD( iono(ii,ij) , jpni )
+            ijno = 1 +      iono(ii,ij) / jpni
+            nono = ipproc(iino,ijno)
+            ii_nono(jarea)= nono
+         ENDIF
+      END DO
+    
+      ! 6. Change processor name
+      ! ------------------------
+      nproc = narea-1
+      ii = iin(narea)
+      ij = ijn(narea)
+      !
+      ! set default neighbours
+      noso = ii_noso(narea)
+      nowe = ii_nowe(narea)
+      noea = ii_noea(narea)
+      nono = ii_nono(narea)
+      nlcj = ilcj(ii,ij)  
+      nlci = ilci(ii,ij)  
+      nldi = ildi(ii,ij)
+      nlei = ilei(ii,ij)
+      nldj = ildj(ii,ij)
+      nlej = ilej(ii,ij)
+      nbondi = ibondi(ii,ij)
+      nbondj = ibondj(ii,ij)
+      nimpp = iimppt(ii,ij)  
+      njmpp = ijmppt(ii,ij)  
+      DO jproc = 1, jpnij
+         ii = iin(jproc)
+         ij = ijn(jproc)
+         nimppt(jproc) = iimppt(ii,ij)  
+         njmppt(jproc) = ijmppt(ii,ij) 
+         nlcjt(jproc) = ilcj(ii,ij)
+         nlcit(jproc) = ilci(ii,ij)
+         nldit(jproc) = ildi(ii,ij)
+         nleit(jproc) = ilei(ii,ij)
+         nldjt(jproc) = ildj(ii,ij)
+         nlejt(jproc) = ilej(ii,ij)
+      END DO
+
+      ! Save processor layout in ascii file
+      IF (lwp) THEN
          CALL ctl_opn( inum, 'layout.dat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE., narea )
-         WRITE(inum,'(a)') '   jpnij     jpi     jpj     jpk  jpiglo  jpjglo'
-         WRITE(inum,'(6i8)') jpnij,jpi,jpj,jpk,jpiglo,jpjglo
-         WRITE(inum,'(a)') 'NAREA nlci nlcj nldi nldj nlei nlej nimpp njmpp'
-         !
-         DO jn = 1, jpnij
-            WRITE(inum,'(9i5)') jn, nlcit(jn), nlcjt(jn), &
-               &                    nldit(jn), nldjt(jn), &
-               &                    nleit(jn), nlejt(jn), &
-               &                    nimppt(jn), njmppt(jn)
+         WRITE(inum,'(a)') '   jpnij   jpimax  jpjmax    jpk  jpiglo  jpjglo'//&
+   &           ' ( local:    narea     jpi     jpj)'
+         WRITE(inum,'(6i8,a,3i8,a)') jpnij,jpimax,jpjmax,jpk,jpiglo,jpjglo,&
+   &           ' ( local: ',narea,jpi,jpj,' )'
+         WRITE(inum,'(a)') 'NAREA nlci nlcj nldi nldj nlei nlej nimp njmp nono noso nowe noea nbondi nbondj '
+
+         DO jproc = 1, jpnij
+            ii = iin(jproc)
+            ij = ijn(jproc)
+            WRITE(inum,'(15i5)') jproc-1, nlcit  (jproc), nlcjt  (jproc),   &
+               &                          nldit  (jproc), nldjt  (jproc),   &
+               &                          nleit  (jproc), nlejt  (jproc),   &
+               &                          nimppt (jproc), njmppt (jproc),   & 
+               &                          ii_nono(jproc), ii_noso(jproc),   &
+               &                          ii_nowe(jproc), ii_noea(jproc),   &
+               &                          ibondi (ii,ij), ibondj (ii,ij) 
          END DO
          CLOSE(inum)   
       END IF
 
-      ! w a r n i n g  narea (zone) /= nproc (processors)!
-
-      IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 .OR. jperio == 7 ) THEN
-         IF( jpni == 1 )THEN
-            nbondi = 2
-            nperio = 1
-         ELSE
-            nbondi = 0
-         ENDIF
-         IF( MOD( narea, jpni ) == 0 ) THEN
-            noea = nproc-(jpni-1)
-            npne = npne-jpni
-            npse = npse-jpni
-         ENDIF
-         IF( MOD( narea, jpni ) == 1 ) THEN
-            nowe = nproc+(jpni-1)
-            npnw = npnw+jpni
-            npsw = npsw+jpni
-         ENDIF
-         nbsw = 1
-         nbnw = 1
-         nbse = 1
-         nbne = 1
-         IF( nproc < jpni ) THEN
-            nbsw = 0
-            nbse = 0
-         ENDIF
-         IF( nproc >= (jpnj-1)*jpni ) THEN
-            nbnw = 0
-            nbne = 0
-         ENDIF
-      ENDIF
+      !                          ! north fold parameter
+      ! Defined npolj, either 0, 3 , 4 , 5 , 6
+      ! In this case the important thing is that npolj /= 0
+      ! Because if we go through these line it is because jpni >1 and thus
+      ! we must use lbcnorthmpp, which tests only npolj =0 or npolj /= 0
       npolj = 0
+      ij = ijn(narea)
       IF( jperio == 3 .OR. jperio == 4 ) THEN
-         ijm1 = jpni*(jpnj-1)
-         imil = ijm1+(jpni+1)/2
-         IF( narea > ijm1 ) npolj = 3
-         IF( MOD(jpni,2) == 1 .AND. narea == imil ) npolj = 4
-         IF( npolj == 3 ) nono = jpni*jpnj-narea+ijm1
+         IF( ij == jpnj )   npolj = 3
       ENDIF
       IF( jperio == 5 .OR. jperio == 6 ) THEN
-          ijm1 = jpni*(jpnj-1)
-          imil = ijm1+(jpni+1)/2
-          IF( narea > ijm1) npolj = 5
-          IF( MOD(jpni,2) == 1 .AND. narea == imil ) npolj = 6
-          IF( npolj == 5 ) nono = jpni*jpnj-narea+ijm1
-      ENDIF
-
-      ! Periodicity : no corner if nbondi = 2 and nperio != 1
-
+         IF( ij == jpnj )   npolj = 5
+      ENDIF
+      !
       IF(lwp) THEN
-         WRITE(numout,*) '      nproc  = ', nproc
-         WRITE(numout,*) '      nowe   = ', nowe  , '      noea   =  ', noea
-         WRITE(numout,*) '      nono   = ', nono  , '      noso   =  ', noso
-         WRITE(numout,*) '      nbondi = ', nbondi, '      nbondj = ', nbondj
-         WRITE(numout,*) '      npolj  = ', npolj
-         WRITE(numout,*) '      nperio = ', nperio
-         WRITE(numout,*) '      nlci   = ', nlci  , '      nlcj   = ', nlcj
-         WRITE(numout,*) '      nimpp  = ', nimpp , '      njmpp  = ', njmpp
-         WRITE(numout,*) '      nreci  = ', nreci , '      npse   = ', npse
-         WRITE(numout,*) '      nrecj  = ', nrecj , '      npsw   = ', npsw
-         WRITE(numout,*) '      jpreci = ', jpreci, '      npne   = ', npne
-         WRITE(numout,*) '      jprecj = ', jprecj, '      npnw   = ', npnw
          WRITE(numout,*)
-      ENDIF
-
-      IF( jperio == 7 .AND. ( jpni /= 1 .OR. jpnj /= 1 ) ) &
-         &                  CALL ctl_stop( ' mpp_init: error jperio = 7 works only with jpni = jpnj = 1' )
-      IF( nperio == 1 .AND. jpni /= 1 ) CALL ctl_stop( ' mpp_init: error on cyclicity' )
-
-      ! Prepare mpp north fold
-
+         WRITE(numout,*) ' nproc  = ', nproc
+         WRITE(numout,*) ' nowe   = ', nowe  , ' noea   =  ', noea
+         WRITE(numout,*) ' nono   = ', nono  , ' noso   =  ', noso
+         WRITE(numout,*) ' nbondi = ', nbondi
+         WRITE(numout,*) ' nbondj = ', nbondj
+         WRITE(numout,*) ' npolj  = ', npolj
+         WRITE(numout,*) ' nperio = ', nperio
+         WRITE(numout,*) ' nlci   = ', nlci
+         WRITE(numout,*) ' nlcj   = ', nlcj
+         WRITE(numout,*) ' nimpp  = ', nimpp
+         WRITE(numout,*) ' njmpp  = ', njmpp
+         WRITE(numout,*) ' nreci  = ', nreci  
+         WRITE(numout,*) ' nrecj  = ', nrecj  
+         WRITE(numout,*) ' nn_hls = ', nn_hls 
+      ENDIF
+
+      IF( nperio == 1 .AND. jpni /= 1 ) CALL ctl_stop( 'mpp_init: error on cyclicity' )
+
+      !                          ! Prepare mpp north fold
       IF( jperio >= 3 .AND. jperio <= 6 .AND. jpni > 1 ) THEN
          CALL mpp_ini_north
          IF(lwp) WRITE(numout,*) ' mpp_init : North fold boundary prepared for jpni >1'
       ENDIF
-
-      ! Prepare NetCDF output file (if necessary)
-      CALL mpp_init_ioipsl
-
-   END SUBROUTINE mpp_init
-
-#  include "mppini_2.h90"
+      !
+      CALL mpp_init_ioipsl       ! Prepare NetCDF output file (if necessary)
+      !
+    END SUBROUTINE mpp_init
+
+
+    SUBROUTINE mpp_init_mask( kmask )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE mpp_init_mask  ***
+      !!
+      !! ** Purpose : Read relevant bathymetric information in a global array
+      !!              in order to provide a land/sea mask used for the elimination
+      !!              of land domains, in an mpp computation.
+      !!
+      !! ** Method  : Read the namelist ln_zco and ln_isfcav in namelist namzgr
+      !!              in order to choose the correct bathymetric information
+      !!              (file and variables)  
+      !!----------------------------------------------------------------------
+      INTEGER, DIMENSION(jpiglo,jpjglo), INTENT(out) ::   kmask   ! global domain 
+  
+      INTEGER :: inum   !: logical unit for configuration file
+      INTEGER :: ios    !: iostat error flag
+      INTEGER ::  ijstartrow                   ! temporary integers
+      REAL(wp), DIMENSION(jpiglo,jpjglo) ::   zbot, zbdy          ! global workspace
+      REAL(wp) ::   zidom , zjdom          ! local scalars
+      NAMELIST/nambdy/ ln_bdy, nb_bdy, ln_coords_file, cn_coords_file,         &
+           &             ln_mask_file, cn_mask_file, cn_dyn2d, nn_dyn2d_dta,     &
+           &             cn_dyn3d, nn_dyn3d_dta, cn_tra, nn_tra_dta,             &  
+           &             ln_tra_dmp, ln_dyn3d_dmp, rn_time_dmp, rn_time_dmp_out, &
+           &             cn_ice_lim, nn_ice_lim_dta,                           &
+           &             rn_ice_tem, rn_ice_sal, rn_ice_age,                 &
+           &             ln_vol, nn_volctl, nn_rimwidth, nb_jpk_bdy
+      !!----------------------------------------------------------------------
+      ! 0. initialisation
+      ! -----------------
+      CALL iom_open( cn_domcfg, inum )
+      !
+      ! ocean bottom level
+      CALL iom_get( inum, jpdom_unknown, 'bottom_level' , zbot , lrowattr=ln_use_jattr )  ! nb of ocean T-points
+      !
+      CALL iom_close( inum )
+      !
+      ! 2D ocean mask (=1 if at least one level of the water column is ocean, =0 otherwise)
+      WHERE( zbot(:,:) > 0 )   ;   kmask(:,:) = 1
+      ELSEWHERE                ;   kmask(:,:) = 0
+      END WHERE
+  
+      ! Adjust kmask with bdy_msk if it exists
+  
+      REWIND( numnam_ref )              ! Namelist nambdy in reference namelist : BDY
+      READ  ( numnam_ref, nambdy, IOSTAT = ios, ERR = 903)
+903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambdy in reference namelist (mppini)', lwp )
+
+      REWIND( numnam_cfg )              ! Namelist nambdy in configuration namelist : BDY
+      READ  ( numnam_cfg, nambdy, IOSTAT = ios, ERR = 904 )
+904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambdy in configuration namelist (mppini)', lwp )
+
+      IF( ln_bdy .AND. ln_mask_file ) THEN
+         CALL iom_open( cn_mask_file, inum )
+         CALL iom_get ( inum, jpdom_unknown, 'bdy_msk', zbdy )
+         CALL iom_close( inum )
+         WHERE ( zbdy(:,:) <= 0. ) kmask = 0
+      ENDIF
+      !
+   END SUBROUTINE mpp_init_mask
+
 
    SUBROUTINE mpp_init_ioipsl
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mppini_2.h90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LBC/mppini_2.h90	(revision 9018)
+++ 	(revision )
@@ -1,572 +1,0 @@
-   SUBROUTINE mpp_init2
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE mpp_init2  ***
-      !!
-      !! * Purpose :   Lay out the global domain over processors.
-      !!     FOR USING THIS VERSION, A PREPROCESSING TRAITMENT IS RECOMMENDED
-      !!     FOR DEFINING BETTER CUTTING OUT.
-      !!       This routine requires the presence of the domain configuration file.
-      !!       In this version, the land processors are avoided and the adress
-      !!     processor (nproc, narea,noea, ...) are calculated again.
-      !!     The jpnij parameter can be lesser than jpni x jpnj
-      !!     and this jpnij parameter must be calculated before with an
-      !!     algoritmic preprocessing program.
-      !!
-      !! ** Method  :   Global domain is distributed in smaller local domains.
-      !!      Periodic condition is a function of the local domain position
-      !!      (global boundary or neighbouring domain) and of the global
-      !!      periodic
-      !!      Type :         jperio global periodic condition
-      !!                     nperio local  periodic condition
-      !!
-      !! ** Action :        nimpp     : longitudinal index 
-      !!                    njmpp     : latitudinal  index
-      !!                    nperio    : lateral condition type 
-      !!                    narea     : number for local area
-      !!                    nlci      : first dimension
-      !!                    nlcj      : second dimension
-      !!                    nproc     : number for local processor
-      !!                    noea      : number for local neighboring processor
-      !!                    nowe      : number for local neighboring processor
-      !!                    noso      : number for local neighboring processor
-      !!                    nono      : number for local neighboring processor
-      !!
-      !! History :       !  1994-11  (M. Guyon)  Original code
-      !!  OPA            !  1995-04  (J. Escobar, M. Imbard)
-      !!                 !  1998-02  (M. Guyon)  FETI method
-      !!                 !  1998-05  (M. Imbard, J. Escobar, L. Colombet )  SHMEM and MPI versions
-      !!  NEMO      1.0  !  2004-01  (G. Madec, J.M Molines)  F90 : free form , north fold jpni > 1
-      !!            4.0  !  2016-06  (G. Madec)  use domain configuration file instead of bathymetry file
-      !!----------------------------------------------------------------------
-      USE in_out_manager  ! I/O Manager
-      USE iom
-      USE bdy_oce
-      !! 
-      INTEGER :: ji, jj, jn, jproc, jarea     ! dummy loop indices
-      INTEGER ::  inum                        ! temporary logical unit
-      INTEGER ::  idir                        ! temporary integers
-      INTEGER ::  jstartrow                   ! temporary integers
-      INTEGER ::   ios                        ! Local integer output status for namelist read
-      INTEGER ::   &
-         ii, ij, ifreq, il1, il2,          &  ! temporary integers
-         icont, ili, ilj,                  &  !    "          "
-         isurf, ijm1, imil,                &  !    "          "
-         iino, ijno, iiso, ijso,           &  !    "          " 
-         iiea, ijea, iiwe, ijwe,           &  !    "          "
-         iinw, ijnw, iine, ijne,           &  !    "          "
-         iisw, ijsw, iise, ijse,           &  !    "          "
-         iresti, irestj, iproc                !    "          "
-      INTEGER, DIMENSION(jpnij) ::   &
-         iin, ijn          
-      INTEGER, DIMENSION(jpni,jpnj) ::   &
-         iimppt, ijmppt, ilci  , ilcj  ,   &  ! temporary workspace
-         ipproc, ibondj, ibondi, ipolj ,   &  !    "           "
-         ilei  , ilej  , ildi  , ildj  ,   &  !    "           "
-         ioea  , iowe  , ioso  , iono  ,   &  !    "           "
-         ione  , ionw  , iose  , iosw  ,   &  !    "           "
-         ibne  , ibnw  , ibse  , ibsw         !    "           "
-      INTEGER,  DIMENSION(jpiglo,jpjglo) ::   imask               ! global workspace
-      REAL(wp), DIMENSION(jpiglo,jpjglo) ::   zbot, ztop, zbdy          ! global workspace
-      REAL(wp) ::   zidom , zjdom          ! local scalars
-      NAMELIST/nambdy/ ln_bdy, nb_bdy, ln_coords_file, cn_coords_file,         &
-         &             ln_mask_file, cn_mask_file, cn_dyn2d, nn_dyn2d_dta,     &
-         &             cn_dyn3d, nn_dyn3d_dta, cn_tra, nn_tra_dta,             &  
-         &             ln_tra_dmp, ln_dyn3d_dmp, rn_time_dmp, rn_time_dmp_out, &
-         &             cn_ice_lim, nn_ice_lim_dta,                           &
-         &             rn_ice_tem, rn_ice_sal, rn_ice_age,                 &
-         &             ln_vol, nn_volctl, nn_rimwidth, nb_jpk_bdy
-      !!----------------------------------------------------------------------
-      !! NEMO/OPA 4.0 , NEMO Consortium (2016)
-      !! $Id$
-      !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-      !!----------------------------------------------------------------------
-
-      IF(lwp)WRITE(numout,*)
-      IF(lwp)WRITE(numout,*) 'mpp_init_2 : Message Passing MPI'
-      IF(lwp)WRITE(numout,*) '~~~~~~~~~~'
-      IF(lwp)WRITE(numout,*) ' '
-
-      IF( jpni*jpnj < jpnij )   CALL ctl_stop( ' jpnij > jpni x jpnj impossible' )
-
-      ! 0. initialisation
-      ! -----------------
-      CALL iom_open( cn_domcfg, inum )
-      !
-      !                                   ! ocean top and bottom level
-      CALL iom_get( inum, jpdom_unknown, 'bottom_level' , zbot    )  ! nb of ocean T-points
-      CALL iom_get( inum, jpdom_unknown, 'top_level'    , ztop    )  ! nb of ocean T-points (ISF)
-      !
-      CALL iom_close( inum )
-      !
-      ! 2D ocean mask (=1 if at least one level of the water column is ocean, =0 otherwise)
-      WHERE( zbot(:,:) > 0 )                   ;   imask(:,:) = 1
-      ELSEWHERE                                ;   imask(:,:) = 0
-      END WHERE
-
-      ! Adjust imask with bdy_msk if exists
-
-      REWIND( numnam_ref )              ! Namelist nambdy in reference namelist : BDY
-      READ  ( numnam_ref, nambdy, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambdy in reference namelist (mppini_2)', lwp )
-
-      REWIND( numnam_cfg )              ! Namelist nambdy in configuration namelist : BDY
-      READ  ( numnam_cfg, nambdy, IOSTAT = ios, ERR = 904 )
-904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambdy in configuration namelist (mppini_2)', lwp )
-
-      IF( ln_bdy .AND. ln_mask_file ) THEN
-         CALL iom_open( cn_mask_file, inum )
-         CALL iom_get ( inum, jpdom_unknown, 'bdy_msk', zbdy)
-         CALL iom_close( inum )
-         WHERE ( zbdy(:,:) <= 0. ) imask = 0
-      ENDIF
-
-      !  1. Dimension arrays for subdomains
-      ! -----------------------------------
-
-      !  Computation of local domain sizes ilci() ilcj()
-      !  These dimensions depend on global sizes jpni,jpnj and jpiglo,jpjglo
-      !  The subdomains are squares leeser than or equal to the global
-      !  dimensions divided by the number of processors minus the overlap
-      !  array.
-
-      nreci=2*jpreci
-      nrecj=2*jprecj
-      iresti = 1 + MOD( jpiglo - nreci -1 , jpni )
-      irestj = 1 + MOD( jpjglo - nrecj -1 , jpnj )
-
-#if defined key_nemocice_decomp
-      ! Change padding to be consistent with CICE
-      ilci(1:jpni-1      ,:) = jpi
-      ilci(jpni          ,:) = jpiglo - (jpni - 1) * (jpi - nreci)
-
-      ilcj(:,      1:jpnj-1) = jpj
-      ilcj(:,          jpnj) = jpjglo - (jpnj - 1) * (jpj - nrecj)
-#else
-      ilci(1:iresti      ,:) = jpi
-      ilci(iresti+1:jpni ,:) = jpi-1
-
-      ilcj(:,      1:irestj) = jpj
-      ilcj(:, irestj+1:jpnj) = jpj-1
-#endif
-
-      nfilcit(:,:) = ilci(:,:)
-
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) ' mpp_init2: defines mpp subdomains'
-      IF(lwp) WRITE(numout,*) ' ~~~~~~  ----------------------'
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'iresti=',iresti,' irestj=',irestj
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'jpni=',jpni,' jpnj=',jpnj
-
-      zidom = nreci + sum(ilci(:,1) - nreci ) 
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*)' sum ilci(i,1)=',zidom,' jpiglo=',jpiglo
-
-      zjdom = nrecj + sum(ilcj(1,:) - nrecj ) 
-      IF(lwp) WRITE(numout,*) ' sum ilcj(1,j)=',zjdom,' jpjglo=',jpjglo
-      IF(lwp) WRITE(numout,*)
-
-
-      !  2. Index arrays for subdomains
-      ! -------------------------------
-
-      iimppt(:,:) = 1
-      ijmppt(:,:) = 1
-      ipproc(:,:) = -1
-
-      IF( jpni > 1 )THEN
-         DO jj = 1, jpnj
-            DO ji = 2, jpni
-               iimppt(ji,jj) = iimppt(ji-1,jj) + ilci(ji-1,jj) - nreci
-            END DO
-         END DO
-      ENDIF
-      nfiimpp(:,:) = iimppt(:,:)
-
-      IF( jpnj > 1 )THEN
-         DO jj = 2, jpnj
-            DO ji = 1, jpni
-               ijmppt(ji,jj) = ijmppt(ji,jj-1) + ilcj(ji,jj-1) - nrecj
-            END DO
-         END DO
-      ENDIF
-
-
-      ! 3. Subdomain description in the Regular Case
-      ! --------------------------------------------
-
-      nperio = 0
-      icont = -1
-      DO jarea = 1, jpni*jpnj
-         ii = 1 + MOD(jarea-1,jpni)
-         ij = 1 +    (jarea-1)/jpni
-         ili = ilci(ii,ij)
-         ilj = ilcj(ii,ij)
-         ibondj(ii,ij) = -1
-         IF( jarea >  jpni          )   ibondj(ii,ij) = 0
-         IF( jarea >  (jpnj-1)*jpni )   ibondj(ii,ij) = 1
-         IF( jpnj  == 1             )   ibondj(ii,ij) = 2
-         ibondi(ii,ij) = 0
-         IF( MOD(jarea,jpni) == 1 )   ibondi(ii,ij) = -1
-         IF( MOD(jarea,jpni) == 0 )   ibondi(ii,ij) =  1
-         IF( jpni            == 1 )   ibondi(ii,ij) =  2
-
-         ! 2.4 Subdomain neighbors
-
-         iproc = jarea - 1
-         ioso(ii,ij) = iproc - jpni
-         iowe(ii,ij) = iproc - 1
-         ioea(ii,ij) = iproc + 1
-         iono(ii,ij) = iproc + jpni
-         ildi(ii,ij) = 1 + jpreci
-         ilei(ii,ij) = ili -jpreci
-         ionw(ii,ij) = iono(ii,ij) - 1
-         ione(ii,ij) = iono(ii,ij) + 1
-         iosw(ii,ij) = ioso(ii,ij) - 1
-         iose(ii,ij) = ioso(ii,ij) + 1
-         ibsw(ii,ij) = 1
-         ibnw(ii,ij) = 1
-         IF( MOD(iproc,jpni) == 0 ) THEN
-            ibsw(ii,ij) = 0
-            ibnw(ii,ij) = 0
-         ENDIF
-         ibse(ii,ij) = 1
-         ibne(ii,ij) = 1
-         IF( MOD(iproc,jpni) == jpni-1 ) THEN
-            ibse(ii,ij) = 0
-            ibne(ii,ij) = 0
-         ENDIF
-         IF( iproc < jpni ) THEN
-            ibsw(ii,ij) = 0
-            ibse(ii,ij) = 0
-         ENDIF
-         IF( iproc >= (jpnj-1)*jpni ) THEN
-            ibnw(ii,ij) = 0
-            ibne(ii,ij) = 0
-         ENDIF
-         IF( ibondi(ii,ij) == -1 .OR. ibondi(ii,ij) == 2 ) ildi(ii,ij) = 1
-         IF( ibondi(ii,ij) ==  1 .OR. ibondi(ii,ij) == 2 ) ilei(ii,ij) = ili
-         ildj(ii,ij) =  1  + jprecj
-         ilej(ii,ij) = ilj - jprecj
-         IF( ibondj(ii,ij) == -1 .OR. ibondj(ii,ij) == 2 ) ildj(ii,ij) = 1
-         IF( ibondj(ii,ij) ==  1 .OR. ibondj(ii,ij) == 2 ) ilej(ii,ij) = ilj
-
-         ! warning ii*ij (zone) /= nproc (processors)!
-
-         IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 ) THEN
-            IF( jpni == 1 )THEN
-               ibondi(ii,ij) = 2
-               nperio = 1
-            ELSE
-               ibondi(ii,ij) = 0
-            ENDIF
-            IF( MOD(jarea,jpni) == 0 ) THEN
-               ioea(ii,ij) = iproc - (jpni-1)
-               ione(ii,ij) = ione(ii,ij) - jpni
-               iose(ii,ij) = iose(ii,ij) - jpni
-            ENDIF
-            IF( MOD(jarea,jpni) == 1 ) THEN
-               iowe(ii,ij) = iproc + jpni - 1
-               ionw(ii,ij) = ionw(ii,ij) + jpni
-               iosw(ii,ij) = iosw(ii,ij) + jpni 
-            ENDIF
-            ibsw(ii,ij) = 1
-            ibnw(ii,ij) = 1
-            ibse(ii,ij) = 1
-            ibne(ii,ij) = 1
-            IF( iproc < jpni ) THEN
-               ibsw(ii,ij) = 0
-               ibse(ii,ij) = 0
-            ENDIF
-            IF( iproc >= (jpnj-1)*jpni ) THEN
-               ibnw(ii,ij) = 0
-               ibne(ii,ij) = 0
-            ENDIF
-         ENDIF
-         ipolj(ii,ij) = 0
-         IF( jperio == 3 .OR. jperio == 4 ) THEN
-            ijm1 = jpni*(jpnj-1)
-            imil = ijm1+(jpni+1)/2
-            IF( jarea > ijm1 ) ipolj(ii,ij) = 3
-            IF( MOD(jpni,2) == 1 .AND. jarea == imil ) ipolj(ii,ij) = 4
-            IF( ipolj(ii,ij) == 3 ) iono(ii,ij) = jpni*jpnj-jarea+ijm1   ! MPI rank of northern neighbour
-         ENDIF
-         IF( jperio == 5 .OR. jperio == 6 ) THEN
-            ijm1 = jpni*(jpnj-1)
-            imil = ijm1+(jpni+1)/2
-            IF( jarea > ijm1) ipolj(ii,ij) = 5
-            IF( MOD(jpni,2) == 1 .AND. jarea == imil ) ipolj(ii,ij) = 6
-            IF( ipolj(ii,ij) == 5) iono(ii,ij) = jpni*jpnj-jarea+ijm1    ! MPI rank of northern neighbour
-         ENDIF
-
-         ! Check wet points over the entire domain to preserve the MPI communication stencil
-         isurf = 0
-         DO jj = 1, ilj
-            DO  ji = 1, ili
-               IF( imask(ji+iimppt(ii,ij)-1, jj+ijmppt(ii,ij)-1) == 1)   isurf = isurf+1
-            END DO
-         END DO
-
-         IF(isurf /= 0) THEN
-            icont = icont + 1
-            ipproc(ii,ij) = icont
-            iin(icont+1) = ii
-            ijn(icont+1) = ij
-         ENDIF
-      END DO
-
-      nfipproc(:,:) = ipproc(:,:)
-
-      ! Control
-      IF(icont+1 /= jpnij) THEN
-         WRITE(ctmp1,*) ' jpni =',jpni,' jpnj =',jpnj
-         WRITE(ctmp2,*) ' jpnij =',jpnij, '< jpni x jpnj' 
-         WRITE(ctmp3,*) ' ***********, mpp_init2 finds jpnij=',icont+1
-         CALL ctl_stop( ' Eliminate land processors algorithm', '', ctmp1, ctmp2, '', ctmp3 )
-      ENDIF
-
-      ! 4. Subdomain print
-      ! ------------------
-
-      IF(lwp) THEN
-         ifreq = 4
-         il1 = 1
-         DO jn = 1,(jpni-1)/ifreq+1
-            il2 = MIN(jpni,il1+ifreq-1)
-            WRITE(numout,*)
-            WRITE(numout,9400) ('***',ji=il1,il2-1)
-            DO jj = jpnj, 1, -1
-               WRITE(numout,9403) ('   ',ji=il1,il2-1)
-               WRITE(numout,9402) jj, (ilci(ji,jj),ilcj(ji,jj),ji=il1,il2)
-               WRITE(numout,9404) (ipproc(ji,jj),ji=il1,il2)
-               WRITE(numout,9403) ('   ',ji=il1,il2-1)
-               WRITE(numout,9400) ('***',ji=il1,il2-1)
-            END DO
-            WRITE(numout,9401) (ji,ji=il1,il2)
-            il1 = il1+ifreq
-         END DO
- 9400     FORMAT('     ***',20('*************',a3))
- 9403     FORMAT('     *     ',20('         *   ',a3))
- 9401     FORMAT('        ',20('   ',i3,'          '))
- 9402     FORMAT(' ',i3,' *  ',20(i3,'  x',i3,'   *   '))
- 9404     FORMAT('     *  ',20('      ',i3,'   *   '))
-      ENDIF
-
-
-      ! 5. neighbour treatment
-      ! ----------------------
-
-      DO jarea = 1, jpni*jpnj
-         iproc = jarea-1
-         ii = 1 + MOD(jarea-1,jpni)
-         ij = 1 +    (jarea-1)/jpni
-         IF( ipproc(ii,ij) == -1 .AND. iono(ii,ij) >= 0   &
-            .AND. iono(ii,ij) <= jpni*jpnj-1 ) THEN
-            iino = 1 + MOD(iono(ii,ij),jpni)
-            ijno = 1 +    (iono(ii,ij))/jpni
-              ! Need to reverse the logical direction of communication 
-              ! for northern neighbours of northern row processors (north-fold)
-              ! i.e. need to check that the northern neighbour only communicates
-              ! to the SOUTH (or not at all) if this area is land-only (#1057)
-            idir = 1
-            IF( ij .eq. jpnj .AND. ijno .eq. jpnj ) idir = -1    
-            IF( ibondj(iino,ijno) == idir ) ibondj(iino,ijno)=2
-            IF( ibondj(iino,ijno) == 0 ) ibondj(iino,ijno) = -idir
-         ENDIF
-         IF( ipproc(ii,ij) == -1 .AND. ioso(ii,ij) >= 0   &
-            .AND. ioso(ii,ij) <= jpni*jpnj-1 ) THEN
-            iiso = 1 + MOD(ioso(ii,ij),jpni)
-            ijso = 1 +    (ioso(ii,ij))/jpni
-            IF( ibondj(iiso,ijso) == -1 ) ibondj(iiso,ijso) = 2
-            IF( ibondj(iiso,ijso) ==  0 ) ibondj(iiso,ijso) = 1
-         ENDIF
-         IF( ipproc(ii,ij) == -1 .AND. ioea(ii,ij) >= 0   &
-            .AND. ioea(ii,ij) <= jpni*jpnj-1) THEN
-            iiea = 1 + MOD(ioea(ii,ij),jpni)
-            ijea = 1 +    (ioea(ii,ij))/jpni
-            IF( ibondi(iiea,ijea) == 1 ) ibondi(iiea,ijea) = 2
-            IF( ibondi(iiea,ijea) == 0 ) ibondi(iiea,ijea) = -1
-         ENDIF
-         IF( ipproc(ii,ij) == -1 .AND. iowe(ii,ij) >= 0   &
-            .AND. iowe(ii,ij) <= jpni*jpnj-1) THEN
-            iiwe = 1 + MOD(iowe(ii,ij),jpni)
-            ijwe = 1 +    (iowe(ii,ij))/jpni
-            IF( ibondi(iiwe,ijwe) == -1 ) ibondi(iiwe,ijwe) = 2
-            IF( ibondi(iiwe,ijwe) ==  0 ) ibondi(iiwe,ijwe) = 1
-         ENDIF
-         IF( ipproc(ii,ij) == -1 .AND. ibne(ii,ij) == 1 ) THEN
-            iine = 1 + MOD(ione(ii,ij),jpni)
-            ijne = 1 +    (ione(ii,ij))/jpni
-            IF( ibsw(iine,ijne) == 1 ) ibsw(iine,ijne) = 0
-         ENDIF
-         IF( ipproc(ii,ij) == -1 .AND. ibsw(ii,ij) == 1 ) THEN
-            iisw = 1 + MOD(iosw(ii,ij),jpni)
-            ijsw = 1 +    (iosw(ii,ij))/jpni
-            IF( ibne(iisw,ijsw) == 1 ) ibne(iisw,ijsw) = 0
-         ENDIF
-         IF( ipproc(ii,ij) == -1 .AND. ibnw(ii,ij) == 1 ) THEN
-            iinw = 1 + MOD(ionw(ii,ij),jpni)
-            ijnw = 1 +    (ionw(ii,ij))/jpni
-            IF( ibse(iinw,ijnw) == 1 ) ibse(iinw,ijnw)=0
-         ENDIF
-         IF( ipproc(ii,ij) == -1 .AND. ibse(ii,ij) == 1 ) THEN
-            iise = 1 + MOD(iose(ii,ij),jpni)
-            ijse = 1 +    (iose(ii,ij))/jpni
-            IF( ibnw(iise,ijse) == 1 ) ibnw(iise,ijse) = 0
-         ENDIF
-      END DO
-
-
-      ! 6. Change processor name
-      ! ------------------------
-
-      nproc = narea-1
-      ii = iin(narea)
-      ij = ijn(narea)
-
-      ! set default neighbours
-      noso = ioso(ii,ij)
-      nowe = iowe(ii,ij)
-      noea = ioea(ii,ij)
-      nono = iono(ii,ij) 
-      npse = iose(ii,ij)
-      npsw = iosw(ii,ij)
-      npne = ione(ii,ij)
-      npnw = ionw(ii,ij)
-
-      ! check neighbours location
-      IF( ioso(ii,ij) >= 0 .AND. ioso(ii,ij) <= (jpni*jpnj-1) ) THEN 
-         iiso = 1 + MOD(ioso(ii,ij),jpni)
-         ijso = 1 +    (ioso(ii,ij))/jpni
-         noso = ipproc(iiso,ijso)
-      ENDIF
-      IF( iowe(ii,ij) >= 0 .AND. iowe(ii,ij) <= (jpni*jpnj-1) ) THEN 
-         iiwe = 1 + MOD(iowe(ii,ij),jpni)
-         ijwe = 1 +    (iowe(ii,ij))/jpni
-         nowe = ipproc(iiwe,ijwe)
-      ENDIF
-      IF( ioea(ii,ij) >= 0 .AND. ioea(ii,ij) <= (jpni*jpnj-1) ) THEN 
-         iiea = 1 + MOD(ioea(ii,ij),jpni)
-         ijea = 1 +    (ioea(ii,ij))/jpni
-         noea = ipproc(iiea,ijea)
-      ENDIF
-      IF( iono(ii,ij) >= 0 .AND. iono(ii,ij) <= (jpni*jpnj-1) ) THEN 
-         iino = 1 + MOD(iono(ii,ij),jpni)
-         ijno = 1 +    (iono(ii,ij))/jpni
-         nono = ipproc(iino,ijno)
-      ENDIF
-      IF( iose(ii,ij) >= 0 .AND. iose(ii,ij) <= (jpni*jpnj-1) ) THEN 
-         iise = 1 + MOD(iose(ii,ij),jpni)
-         ijse = 1 +    (iose(ii,ij))/jpni
-         npse = ipproc(iise,ijse)
-      ENDIF
-      IF( iosw(ii,ij) >= 0 .AND. iosw(ii,ij) <= (jpni*jpnj-1) ) THEN 
-         iisw = 1 + MOD(iosw(ii,ij),jpni)
-         ijsw = 1 +    (iosw(ii,ij))/jpni
-         npsw = ipproc(iisw,ijsw)
-      ENDIF
-      IF( ione(ii,ij) >= 0 .AND. ione(ii,ij) <= (jpni*jpnj-1) ) THEN 
-         iine = 1 + MOD(ione(ii,ij),jpni)
-         ijne = 1 +    (ione(ii,ij))/jpni
-         npne = ipproc(iine,ijne)
-      ENDIF
-      IF( ionw(ii,ij) >= 0 .AND. ionw(ii,ij) <= (jpni*jpnj-1) ) THEN 
-         iinw = 1 + MOD(ionw(ii,ij),jpni)
-         ijnw = 1 +    (ionw(ii,ij))/jpni
-         npnw = ipproc(iinw,ijnw)
-      ENDIF
-      nbnw = ibnw(ii,ij)
-      nbne = ibne(ii,ij)
-      nbsw = ibsw(ii,ij)
-      nbse = ibse(ii,ij)
-      nlcj = ilcj(ii,ij)  
-      nlci = ilci(ii,ij)  
-      nldi = ildi(ii,ij)
-      nlei = ilei(ii,ij)
-      nldj = ildj(ii,ij)
-      nlej = ilej(ii,ij)
-      nbondi = ibondi(ii,ij)
-      nbondj = ibondj(ii,ij)
-      nimpp = iimppt(ii,ij)  
-      njmpp = ijmppt(ii,ij)  
-      DO jproc = 1, jpnij
-         ii = iin(jproc)
-         ij = ijn(jproc)
-         nimppt(jproc) = iimppt(ii,ij)  
-         njmppt(jproc) = ijmppt(ii,ij)  
-         nlcjt(jproc) = ilcj(ii,ij)
-         nlcit(jproc) = ilci(ii,ij)
-         nldit(jproc) = ildi(ii,ij)
-         nleit(jproc) = ilei(ii,ij)
-         nldjt(jproc) = ildj(ii,ij)
-         nlejt(jproc) = ilej(ii,ij)
-      END DO
-
-      ! Save processor layout in ascii file
-      IF (lwp) THEN
-         CALL ctl_opn( inum, 'layout.dat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE., narea )
-         WRITE(inum,'(a)') '   jpnij     jpi     jpj     jpk  jpiglo  jpjglo'
-         WRITE(inum,'(6i8)') jpnij,jpi,jpj,jpk,jpiglo,jpjglo
-         WRITE(inum,'(a)') 'NAREA nlci nlcj nldi nldj nlei nlej nimpp njmpp'
-
-        DO  jproc = 1, jpnij
-         WRITE(inum,'(9i5)') jproc, nlcit(jproc), nlcjt(jproc), &
-                                      nldit(jproc), nldjt(jproc), &
-                                      nleit(jproc), nlejt(jproc), &
-                                      nimppt(jproc), njmppt(jproc)
-        END DO
-        CLOSE(inum)   
-      END IF
-
-      ! Defined npolj, either 0, 3 , 4 , 5 , 6
-      ! In this case the important thing is that npolj /= 0
-      ! Because if we go through these line it is because jpni >1 and thus
-      ! we must use lbcnorthmpp, which tests only npolj =0 or npolj /= 0
-
-      npolj = 0
-      ij = ijn(narea)
-
-      IF( jperio == 3 .OR. jperio == 4 ) THEN
-         IF( ij == jpnj ) npolj = 3
-      ENDIF
-
-      IF( jperio == 5 .OR. jperio == 6 ) THEN
-         IF( ij == jpnj ) npolj = 5
-      ENDIF
-
-      ! Periodicity : no corner if nbondi = 2 and nperio != 1
-
-      IF(lwp) THEN
-         WRITE(numout,*) ' nproc  = ', nproc
-         WRITE(numout,*) ' nowe   = ', nowe  , ' noea   =  ', noea
-         WRITE(numout,*) ' nono   = ', nono  , ' noso   =  ', noso
-         WRITE(numout,*) ' nbondi = ', nbondi
-         WRITE(numout,*) ' nbondj = ', nbondj
-         WRITE(numout,*) ' npolj  = ', npolj
-         WRITE(numout,*) ' nperio = ', nperio
-         WRITE(numout,*) ' nlci   = ', nlci
-         WRITE(numout,*) ' nlcj   = ', nlcj
-         WRITE(numout,*) ' nimpp  = ', nimpp
-         WRITE(numout,*) ' njmpp  = ', njmpp
-         WRITE(numout,*) ' nreci  = ', nreci  , ' npse   = ', npse
-         WRITE(numout,*) ' nrecj  = ', nrecj  , ' npsw   = ', npsw
-         WRITE(numout,*) ' jpreci = ', jpreci , ' npne   = ', npne
-         WRITE(numout,*) ' jprecj = ', jprecj , ' npnw   = ', npnw
-         WRITE(numout,*)
-      ENDIF
-
-      IF( nperio == 1 .AND. jpni /= 1 ) CALL ctl_stop( ' mpp_init2: error on cyclicity' )
-
-      ! Prepare mpp north fold
-
-      IF( jperio >= 3 .AND. jperio <= 6 .AND. jpni > 1 ) THEN
-         CALL mpp_ini_north
-         IF(lwp) WRITE(numout,*) ' mpp_init2 : North fold boundary prepared for jpni >1'
-      ENDIF
-
-      ! Prepare NetCDF output file (if necessary)
-      CALL mpp_init_ioipsl
-
-
-   END SUBROUTINE mpp_init2
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn.F90	(revision 9019)
@@ -24,5 +24,4 @@
    USE lib_mpp         ! distribued memory computing library
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE wrk_nemo        ! Memory Allocation
 
    IMPLICIT NONE
@@ -33,4 +32,5 @@
 
    !                                                !!* Namelist namdyn_ldf : lateral mixing on momentum *
+   LOGICAL , PUBLIC ::   ln_dynldf_NONE  !: No operator (i.e. no explicit diffusion)
    LOGICAL , PUBLIC ::   ln_dynldf_lap   !: laplacian operator
    LOGICAL , PUBLIC ::   ln_dynldf_blp   !: bilaplacian operator
@@ -96,8 +96,8 @@
       REAL(wp) ::   zah0              ! local scalar
       !
-      NAMELIST/namdyn_ldf/ ln_dynldf_lap, ln_dynldf_blp,                  &
-         &                 ln_dynldf_lev, ln_dynldf_hor, ln_dynldf_iso,   &
-         &                 nn_ahm_ijk_t , rn_ahm_0, rn_ahm_b, rn_bhm_0,   &
-         &                 rn_csmc      , rn_minfac, rn_maxfac
+      NAMELIST/namdyn_ldf/ ln_dynldf_NONE, ln_dynldf_lap, ln_dynldf_blp,   &   ! type of operator
+         &                 ln_dynldf_lev, ln_dynldf_hor, ln_dynldf_iso ,   &   ! acting direction of the operator
+         &                 nn_ahm_ijk_t , rn_ahm_0, rn_ahm_b, rn_bhm_0 ,   &   ! lateral eddy coefficient
+         &                 rn_csmc      , rn_minfac, rn_maxfac                 ! Smagorinsky settings
       !!----------------------------------------------------------------------
       !
@@ -118,4 +118,5 @@
          !
          WRITE(numout,*) '      type :'
+         WRITE(numout,*) '         no explicit diffusion                ln_dynldf_NONE= ', ln_dynldf_NONE
          WRITE(numout,*) '         laplacian operator                   ln_dynldf_lap = ', ln_dynldf_lap
          WRITE(numout,*) '         bilaplacian operator                 ln_dynldf_blp = ', ln_dynldf_blp
@@ -131,5 +132,5 @@
          WRITE(numout,*) '         background viscosity (iso case)      rn_ahm_b      = ', rn_ahm_b, ' m2/s'
          WRITE(numout,*) '         lateral bilaplacian eddy viscosity   rn_bhm_0      = ', rn_bhm_0, ' m4/s'
-         WRITE(numout,*) '      smagorinsky settings (nn_ahm_ijk_t  = 32) :'
+         WRITE(numout,*) '      Smagorinsky settings (nn_ahm_ijk_t  = 32) :'
          WRITE(numout,*) '         Smagorinsky coefficient              rn_csmc       = ', rn_csmc
          WRITE(numout,*) '         factor multiplier for theorectical lower limit for '
@@ -140,5 +141,5 @@
 
       !                                ! Parameter control
-      IF( .NOT.ln_dynldf_lap .AND. .NOT.ln_dynldf_blp ) THEN
+      IF( ln_dynldf_NONE ) THEN
          IF(lwp) WRITE(numout,*) '   No viscous operator selected. ahmt and ahmf are not allocated'
          l_ldfdyn_time = .FALSE.
@@ -284,5 +285,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('ldf_dyn')
+      IF( ln_timing )   CALL timing_start('ldf_dyn')
       !
       SELECT CASE(  nn_ahm_ijk_t  )       !== Eddy vicosity coefficients ==!
@@ -411,5 +412,5 @@
       CALL iom_put( "ahmf_3d", ahmf(:,:,:) )   ! 3D      v-eddy diffusivity coeff.
       !
-      IF( nn_timing == 1 )  CALL timing_stop('ldf_dyn')
+      IF( ln_timing )   CALL timing_stop('ldf_dyn')
       !
    END SUBROUTINE ldf_dyn
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LDF/ldfslp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LDF/ldfslp.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LDF/ldfslp.F90	(revision 9019)
@@ -32,5 +32,4 @@
    USE lib_mpp        ! distribued memory computing library
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
-   USE wrk_nemo       ! work arrays
    USE timing         ! Timing
 
@@ -118,15 +117,11 @@
       REAL(wp) ::   zck, zfk,      zbw             !   -      -
       REAL(wp) ::   zdepu, zdepv                   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::  zslpml_hmlpu, zslpml_hmlpv
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zwz, zww
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zdzr
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zgru, zgrv
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('ldf_slp')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk, zwz, zww, zdzr, zgru, zgrv )
-      CALL wrk_alloc( jpi,jpj, zslpml_hmlpu, zslpml_hmlpv )
-
+      REAL(wp), DIMENSION(jpi,jpj)     ::  zslpml_hmlpu, zslpml_hmlpv
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  zgru, zwz, zdzr
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  zgrv, zww
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('ldf_slp')
+      !
       zeps   =  1.e-20_wp        !==   Local constant initialization   ==!
       z1_16  =  1.0_wp / 16._wp
@@ -157,6 +152,6 @@
          DO jj = 1, jpjm1
             DO ji = 1, jpim1
-               IF ( miku(ji,jj) > 1 ) zgru(ji,jj,miku(ji,jj)) = grui(ji,jj) 
-               IF ( mikv(ji,jj) > 1 ) zgrv(ji,jj,mikv(ji,jj)) = grvi(ji,jj)
+               IF( miku(ji,jj) > 1 )   zgru(ji,jj,miku(ji,jj)) = grui(ji,jj) 
+               IF( mikv(ji,jj) > 1 )   zgrv(ji,jj,mikv(ji,jj)) = grvi(ji,jj)
             END DO
          END DO
@@ -375,8 +370,5 @@
       ENDIF
       !
-      CALL wrk_dealloc( jpi,jpj,jpk, zwz, zww, zdzr, zgru, zgrv )
-      CALL wrk_dealloc( jpi,jpj, zslpml_hmlpu, zslpml_hmlpv )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('ldf_slp')
+      IF( ln_timing )   CALL timing_stop('ldf_slp')
       !
    END SUBROUTINE ldf_slp
@@ -409,16 +401,12 @@
       REAL(wp) ::   zdzrho_raw
       REAL(wp) ::   zbeta0, ze3_e1, ze3_e2
-      REAL(wp), POINTER, DIMENSION(:,:)     ::   z1_mlbw
-      REAL(wp), POINTER, DIMENSION(:,:,:)   ::   zalbet
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   zdxrho , zdyrho, zdzrho     ! Horizontal and vertical density gradients
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   zti_mlb, ztj_mlb            ! for Griffies operator only
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('ldf_slp_triad')
-      !
-      CALL wrk_alloc( jpi,jpj, z1_mlbw )
-      CALL wrk_alloc( jpi,jpj,jpk, zalbet )
-      CALL wrk_alloc( jpi,jpj,jpk,2, zdxrho , zdyrho, zdzrho,              klstart = 0  )
-      CALL wrk_alloc( jpi,jpj,  2,2, zti_mlb, ztj_mlb,        kkstart = 0, klstart = 0  )
+      REAL(wp), DIMENSION(jpi,jpj)     ::   z1_mlbw
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zalbet
+      REAL(wp), DIMENSION(jpi,jpj,jpk,0:1) ::   zdxrho , zdyrho, zdzrho     ! Horizontal and vertical density gradients
+      REAL(wp), DIMENSION(jpi,jpj,0:1,0:1) ::   zti_mlb, ztj_mlb            ! for Griffies operator only
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('ldf_slp_triad')
+      !
       !
       !--------------------------------!
@@ -624,10 +612,5 @@
       CALL lbc_lnk( wslp2, 'W', 1. )      ! lateral boundary confition on wslp2 only   ==>>> gm : necessary ? to be checked
       !
-      CALL wrk_dealloc( jpi,jpj, z1_mlbw )
-      CALL wrk_dealloc( jpi,jpj,jpk, zalbet )
-      CALL wrk_dealloc( jpi,jpj,jpk,2, zdxrho , zdyrho, zdzrho,              klstart = 0  )
-      CALL wrk_dealloc( jpi,jpj,  2,2, zti_mlb, ztj_mlb,        kkstart = 0, klstart = 0  )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('ldf_slp_triad')
+      IF( ln_timing )   CALL timing_stop('ldf_slp_triad')
       !
    END SUBROUTINE ldf_slp_triad
@@ -663,5 +646,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('ldf_slp_mxl')
+      IF( ln_timing )   CALL timing_start('ldf_slp_mxl')
       !
       zeps   =  1.e-20_wp        !==   Local constant initialization   ==!
@@ -746,5 +729,5 @@
       CALL lbc_lnk( wslpiml, 'W', -1. )   ;   CALL lbc_lnk( wslpjml, 'W', -1. )   ! lateral boundary conditions
       !
-      IF( nn_timing == 1 )  CALL timing_stop('ldf_slp_mxl')
+      IF( ln_timing )   CALL timing_stop('ldf_slp_mxl')
       !
    END SUBROUTINE ldf_slp_mxl
@@ -763,5 +746,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('ldf_slp_init')
+      IF( ln_timing )   CALL timing_start('ldf_slp_init')
       !
       IF(lwp) THEN
@@ -821,5 +804,5 @@
       ENDIF
       !
-      IF( nn_timing == 1 )  CALL timing_stop('ldf_slp_init')
+      IF( ln_timing )   CALL timing_stop('ldf_slp_init')
       !
    END SUBROUTINE ldf_slp_init
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LDF/ldftra.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LDF/ldftra.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/LDF/ldftra.F90	(revision 9019)
@@ -30,5 +30,4 @@
    USE lib_mpp         ! distribued memory computing library
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE wrk_nemo        ! work arrays
    USE timing          ! timing
 
@@ -45,4 +44,5 @@
    !                                   !!* Namelist namtra_ldf : lateral mixing on tracers * 
    !                                    != Operator type =!
+   LOGICAL , PUBLIC ::   ln_traldf_NONE      !: no operator: No explicit diffusion
    LOGICAL , PUBLIC ::   ln_traldf_lap       !: laplacian operator
    LOGICAL , PUBLIC ::   ln_traldf_blp       !: bilaplacian operator
@@ -119,10 +119,10 @@
       INTEGER  ::   ierr, inum, ios   ! local integer
       REAL(wp) ::   zah0              ! local scalar
-      !
-      NAMELIST/namtra_ldf/ ln_traldf_lap, ln_traldf_blp  ,                   &   ! type of operator
-         &                 ln_traldf_lev, ln_traldf_hor  , ln_traldf_triad,  &   ! acting direction of the operator
-         &                 ln_traldf_iso, ln_traldf_msc  ,  rn_slpmax     ,  &   ! option for iso-neutral operator
-         &                 ln_triad_iso , ln_botmix_triad, rn_sw_triad    ,  &   ! option for triad operator
-         &                 rn_aht_0     , rn_bht_0       , nn_aht_ijk_t          ! lateral eddy coefficient
+      !!
+      NAMELIST/namtra_ldf/ ln_traldf_NONE, ln_traldf_lap  , ln_traldf_blp  ,  &   ! type of operator
+         &                 ln_traldf_lev , ln_traldf_hor  , ln_traldf_triad,  &   ! acting direction of the operator
+         &                 ln_traldf_iso , ln_traldf_msc  ,  rn_slpmax     ,  &   ! option for iso-neutral operator
+         &                 ln_triad_iso  , ln_botmix_triad, rn_sw_triad    ,  &   ! option for triad operator
+         &                 rn_aht_0      , rn_bht_0       , nn_aht_ijk_t          ! lateral eddy coefficient
       !!----------------------------------------------------------------------
       !
@@ -144,9 +144,8 @@
          WRITE(numout,*) '~~~~~~~~~~~~ '
          WRITE(numout,*) '   Namelist namtra_ldf : lateral mixing parameters (type, direction, coefficients)'
-         !
          WRITE(numout,*) '      type :'
+         WRITE(numout,*) '         no explicit diffusion                   ln_traldf_NONE  = ', ln_traldf_NONE
          WRITE(numout,*) '         laplacian operator                      ln_traldf_lap   = ', ln_traldf_lap
          WRITE(numout,*) '         bilaplacian operator                    ln_traldf_blp   = ', ln_traldf_blp
-         !
          WRITE(numout,*) '      direction of action :'
          WRITE(numout,*) '         iso-level                               ln_traldf_lev   = ', ln_traldf_lev
@@ -159,5 +158,4 @@
          WRITE(numout,*) '            switching triad or not               rn_sw_triad     = ', rn_sw_triad
          WRITE(numout,*) '            lateral mixing on bottom             ln_botmix_triad = ', ln_botmix_triad
-         !
          WRITE(numout,*) '      coefficients :'
          WRITE(numout,*) '         lateral eddy diffusivity   (lap case)   rn_aht_0        = ', rn_aht_0
@@ -168,5 +166,5 @@
       !                                ! Parameter control
       !
-      IF( .NOT.ln_traldf_lap .AND. .NOT.ln_traldf_blp ) THEN
+      IF( ln_traldf_NONE ) THEN
          IF(lwp) WRITE(numout,*) '   No diffusive operator selected. ahtu and ahtv are not allocated'
          l_ldftra_time = .FALSE.
@@ -490,12 +488,10 @@
       !
       INTEGER  ::   ji, jj, jk    ! dummy loop indices
-      REAL(wp) ::   zfw, ze3w, zn2, z1_f20, zaht, zaht_min, zzaei   ! local scalars
-      REAL(wp), DIMENSION(:,:), POINTER ::   zn, zah, zhw, zross, zaeiw   ! 2D workspace
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )   CALL timing_start('ldf_eiv')
-      !
-      CALL wrk_alloc( jpi,jpj,   zn, zah, zhw, zross, zaeiw )
-      !      
+      REAL(wp) ::   zfw, ze3w, zn2, z1_f20, zaht, zaht_min, zzaei    ! local scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   zn, zah, zhw, zross, zaeiw   ! 2D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('ldf_eiv')
+      !
       zn   (:,:) = 0._wp      ! Local initialization
       zhw  (:,:) = 5._wp
@@ -575,7 +571,5 @@
       END DO
       !  
-      CALL wrk_dealloc( jpi,jpj,   zn, zah, zhw, zross, zaeiw )
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('ldf_eiv')
+      IF( ln_timing )   CALL timing_stop('ldf_eiv')
       !
    END SUBROUTINE ldf_eiv
@@ -610,11 +604,9 @@
       REAL(wp) ::   zuwk, zuwk1, zuwi, zuwi1   ! local scalars
       REAL(wp) ::   zvwk, zvwk1, zvwj, zvwj1   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zpsi_uw, zpsi_vw
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )   CALL timing_start( 'ldf_eiv_trp')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   zpsi_uw, zpsi_vw )
-
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zpsi_uw, zpsi_vw
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start( 'ldf_eiv_trp')
+      !
       IF( kt == kit000 )  THEN
          IF(lwp) WRITE(numout,*)
@@ -658,7 +650,5 @@
       IF( ln_ldfeiv_dia .AND. cdtype == 'TRA' )   CALL ldf_eiv_dia( zpsi_uw, zpsi_vw )
       !
-      CALL wrk_dealloc( jpi,jpj,jpk,   zpsi_uw, zpsi_vw )
-      !
-      IF( nn_timing == 1 )   CALL timing_stop( 'ldf_eiv_trp')
+      IF( ln_timing )   CALL timing_stop( 'ldf_eiv_trp')
       !
     END SUBROUTINE ldf_eiv_trp
@@ -679,9 +669,11 @@
       INTEGER  ::   ji, jj, jk    ! dummy loop indices
       REAL(wp) ::   zztmp   ! local scalar
-      REAL(wp), DIMENSION(:,:)  , POINTER ::   zw2d   ! 2D workspace
-      REAL(wp), DIMENSION(:,:,:), POINTER ::   zw3d   ! 3D workspace
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start( 'ldf_eiv_dia')
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zw2d   ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zw3d   ! 3D workspace
+      !!----------------------------------------------------------------------
+      !
+!!gm I don't like this routine....   Crazy  way of doing things, not optimal at all...
+!!gm     to be redesigned....   
+      IF( ln_timing )   CALL timing_start( 'ldf_eiv_dia')
       !
       !                                                  !==  eiv stream function: output  ==!
@@ -693,5 +685,4 @@
       !
       !                                                  !==  eiv velocities: calculate and output  ==!
-      CALL wrk_alloc( jpi,jpj,jpk,   zw3d )
       !
       zw3d(:,:,jpk) = 0._wp                                    ! bottom value always 0
@@ -718,7 +709,4 @@
       CALL iom_put( "woce_eiv", zw3d )
       !
-      !      
-      !
-      CALL wrk_alloc( jpi,jpj,   zw2d )
       !
       zztmp = 0.5_wp * rau0 * rcp 
@@ -792,8 +780,6 @@
       IF( ln_diaptr ) CALL dia_ptr_hst( jp_sal, 'eiv', 0.5 * zw3d )
       !
-      CALL wrk_dealloc( jpi,jpj,   zw2d )
-      CALL wrk_dealloc( jpi,jpj,jpk,   zw3d )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop( 'ldf_eiv_dia')      
+      !
+      IF( ln_timing )   CALL timing_stop( 'ldf_eiv_dia')      
       !
    END SUBROUTINE ldf_eiv_dia
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 9019)
@@ -14,5 +14,4 @@
    !!   fin_date     : Compute the final date YYYYMMDD.HHMMSS
    !!----------------------------------------------------------------------
-   !! * Modules used
    USE wrk_nemo                 ! Memory Allocation
    USE par_kind                 ! Precision variables
@@ -36,12 +35,11 @@
 
    IMPLICIT NONE
-
-   !! * Routine accessibility
    PRIVATE
-   PUBLIC dia_obs_init, &  ! Initialize and read observations
-      &   dia_obs,      &  ! Compute model equivalent to observations
-      &   dia_obs_wri,  &  ! Write model equivalent to observations
-      &   dia_obs_dealloc, &  ! Deallocate dia_obs data
-      &   calc_date           ! Compute the date of a timestep
+
+   PUBLIC dia_obs_init     ! Initialize and read observations
+   PUBLIC dia_obs          ! Compute model equivalent to observations
+   PUBLIC dia_obs_wri      ! Write model equivalent to observations
+   PUBLIC dia_obs_dealloc  ! Deallocate dia_obs data
+   PUBLIC calc_date        ! Compute the date of a timestep
 
    !! * Module variables
@@ -51,25 +49,14 @@
    INTEGER :: nn_1dint       !: Vertical interpolation method
    INTEGER :: nn_2dint       !: Horizontal interpolation method
-   INTEGER, DIMENSION(imaxavtypes) :: &
-      & nn_profdavtypes      !: Profile data types representing a daily average
+   INTEGER, DIMENSION(imaxavtypes) ::   nn_profdavtypes   !: Profile data types representing a daily average
    INTEGER :: nproftypes     !: Number of profile obs types
    INTEGER :: nsurftypes     !: Number of surface obs types
-   INTEGER, DIMENSION(:), ALLOCATABLE :: &
-      & nvarsprof, &         !: Number of profile variables
-      & nvarssurf            !: Number of surface variables
-   INTEGER, DIMENSION(:), ALLOCATABLE :: &
-      & nextrprof, &         !: Number of profile extra variables
-      & nextrsurf            !: Number of surface extra variables
-   INTEGER, PUBLIC, ALLOCATABLE, DIMENSION(:) :: sstbias_type !SST bias type    
-   TYPE(obs_surf), PUBLIC, POINTER, DIMENSION(:) :: &
-      & surfdata, &          !: Initial surface data
-      & surfdataqc           !: Surface data after quality control
-   TYPE(obs_prof), PUBLIC, POINTER, DIMENSION(:) :: &
-      & profdata, &          !: Initial profile data
-      & profdataqc           !: Profile data after quality control
-
-   CHARACTER(len=6), PUBLIC, DIMENSION(:), ALLOCATABLE :: &
-      & cobstypesprof, &     !: Profile obs types
-      & cobstypessurf        !: Surface obs types
+   INTEGER, DIMENSION(:), ALLOCATABLE ::   nvarsprof, nvarssurf   !: Number of profile & surface variables
+   INTEGER, DIMENSION(:), ALLOCATABLE ::   nextrprof, nextrsurf   !: Number of profile & surface extra variables
+   INTEGER, PUBLIC, ALLOCATABLE, DIMENSION(:) ::   sstbias_type   !: SST bias type    
+   TYPE(obs_surf), PUBLIC, POINTER, DIMENSION(:) ::   surfdata, surfdataqc   !: Initial surface data before & after quality control
+   TYPE(obs_prof), PUBLIC, POINTER, DIMENSION(:) ::   profdata, profdataqc   !: Initial profile data before & after quality control
+
+   CHARACTER(len=6), PUBLIC, DIMENSION(:), ALLOCATABLE ::   cobstypesprof, cobstypessurf   !: Profile & surface obs types
 
    !!----------------------------------------------------------------------
@@ -78,5 +65,4 @@
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -99,13 +85,6 @@
       !!        !  15-02  (M. Martin) Simplification of namelist and code
       !!----------------------------------------------------------------------
-
-      IMPLICIT NONE
-
-      !! * Local declarations
-      INTEGER, PARAMETER :: &
-         & jpmaxnfiles = 1000    ! Maximum number of files for each obs type
-      INTEGER, DIMENSION(:), ALLOCATABLE :: &
-         & ifilesprof, &         ! Number of profile files
-         & ifilessurf            ! Number of surface files
+      INTEGER, PARAMETER ::   jpmaxnfiles = 1000    ! Maximum number of files for each obs type
+      INTEGER, DIMENSION(:), ALLOCATABLE ::   ifilesprof, ifilessurf   ! Number of profile & surface files
       INTEGER :: ios             ! Local integer output status for namelist read
       INTEGER :: jtype           ! Counter for obs types
@@ -134,5 +113,5 @@
       LOGICAL :: ln_nea          ! Logical switch to remove obs near land
       LOGICAL :: ln_altbias      ! Logical switch for altimeter bias
-      LOGICAL :: ln_sstbias     !: Logical switch for bias corection of SST 
+      LOGICAL :: ln_sstbias      ! Logical switch for bias corection of SST 
       LOGICAL :: ln_ignmis       ! Logical switch for ignoring missing files
       LOGICAL :: ln_s_at_t       ! Logical switch to compute model S at T obs
@@ -291,5 +270,5 @@
             END DO
          ENDIF
-#if defined key_lim2 || defined key_lim3
+#if defined key_lim3
          IF (ln_sic) THEN
             jtype = jtype + 1
@@ -501,4 +480,5 @@
    END SUBROUTINE dia_obs_init
 
+
    SUBROUTINE dia_obs( kstp )
       !!----------------------------------------------------------------------
@@ -525,23 +505,10 @@
       !!        !  15-08  (M. Martin) Combined surface/profile routines.
       !!----------------------------------------------------------------------
-      !! * Modules used
-      USE dom_oce, ONLY : &             ! Ocean space and time domain variables
-         & gdept_n,       &      
-         & gdept_1d      
-      USE phycst, ONLY : &              ! Physical constants
-         & rday                         
-      USE oce, ONLY : &                 ! Ocean dynamics and tracers variables
-         & tsn,  &             
-         & un, vn, &
-         & sshn  
-      USE phycst, ONLY : &         ! Physical constants
-         & rday
+      USE dom_oce, ONLY : gdept_n, gdept_1d   ! Ocean space and time domain variables
+      USE phycst , ONLY : rday                ! Physical constants
+      USE oce    , ONLY : tsn, un, vn, sshn   ! Ocean dynamics and tracers variables
+      USE phycst , ONLY : rday                ! Physical constants
 #if defined  key_lim3
-      USE ice, ONLY : &            ! LIM3 Ice model variables
-         & frld
-#endif
-#if defined key_lim2
-      USE ice_2, ONLY : &          ! LIM2 Ice model variables
-         & frld
+      USE ice    , ONLY : at_i                ! LIM3 Ice model variables
 #endif
       IMPLICIT NONE
@@ -567,6 +534,6 @@
          & zgphi1,    &            ! Model latitudes for prof variable 1
          & zgphi2                  ! Model latitudes for prof variable 2
-#if ! defined key_lim2 && ! defined key_lim3
-      REAL(wp), POINTER, DIMENSION(:,:) :: frld
+#if ! defined key_lim3
+      REAL(wp), POINTER, DIMENSION(:,:) :: at_i
 #endif
       LOGICAL :: llnightav        ! Logical for calculating night-time average
@@ -582,7 +549,8 @@
       CALL wrk_alloc( jpi, jpj, zgphi1 )
       CALL wrk_alloc( jpi, jpj, zgphi2 )
-#if ! defined key_lim2 && ! defined key_lim3
-      CALL wrk_alloc(jpi,jpj,frld) 
+#if ! defined key_lim3
+      CALL wrk_alloc(jpi,jpj,at_i) 
 #endif
+      !-----------------------------------------------------------------------
 
       IF(lwp) THEN
@@ -595,8 +563,8 @@
 
       !-----------------------------------------------------------------------
-      ! No LIM => frld == 0.0_wp
-      !-----------------------------------------------------------------------
-#if ! defined key_lim2 && ! defined key_lim3
-      frld(:,:) = 0.0_wp
+      ! No LIM => at_i == 0.0_wp
+      !-----------------------------------------------------------------------
+#if ! defined key_lim3
+      at_i(:,:) = 0.0_wp
 #endif
       !-----------------------------------------------------------------------
@@ -665,5 +633,5 @@
                zsurfvar(:,:) = sshn(:,:)
                llnightav = .FALSE.
-#if defined key_lim2 || defined key_lim3
+#if defined key_lim3
             CASE('sic')
                IF ( kstp == 0 ) THEN
@@ -678,5 +646,5 @@
                   CYCLE
                ELSE
-                  zsurfvar(:,:) = 1._wp - frld(:,:)
+                  zsurfvar(:,:) = at_i(:,:)
                ENDIF
 
@@ -702,6 +670,6 @@
       CALL wrk_dealloc( jpi, jpj, zgphi1 )
       CALL wrk_dealloc( jpi, jpj, zgphi2 )
-#if ! defined key_lim2 && ! defined key_lim3
-      CALL wrk_dealloc(jpi,jpj,frld)
+#if ! defined key_lim3
+      CALL wrk_dealloc(jpi,jpj,at_i)
 #endif
 
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/albedo.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/albedo.F90	(revision 9018)
+++ 	(revision )
@@ -1,270 +1,0 @@
-MODULE albedo
-   !!======================================================================
-   !!                       ***  MODULE  albedo  ***
-   !! Ocean forcing:  bulk thermohaline forcing of the ocean (or ice)
-   !!=====================================================================
-   !! History :  8.0  ! 2001-04  (LIM 1.0)
-   !!   NEMO     1.0  ! 2003-07  (C. Ethe, G. Madec)  Optimization (old name:shine)
-   !!             -   ! 2004-11  (C. Talandier)  add albedo_init
-   !!             -   ! 2001-06  (M. Vancoppenolle) LIM 3.0
-   !!             -   ! 2006-08  (G. Madec)  cleaning for surface module
-   !!            3.6  ! 2016-01  (C. Rousset) new parameterization for sea ice albedo
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   albedo_ice    : albedo for   ice (clear and overcast skies)
-   !!   albedo_oce    : albedo for ocean (clear and overcast skies)
-   !!   albedo_init   : initialisation of albedo computation
-   !!----------------------------------------------------------------------
-   USE phycst         ! physical constants
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   albedo_ice   ! routine called sbcice_lim.F90
-   PUBLIC   albedo_oce   ! routine called by ???
-
-   INTEGER  ::   albd_init = 0      !: control flag for initialization
-  
-   REAL(wp) ::   rmue     = 0.40    !  cosine of local solar altitude
-   REAL(wp) ::   ralb_oce = 0.066   ! ocean or lead albedo (Pegau and Paulson, Ann. Glac. 2001)
-   REAL(wp) ::   c1       = 0.05    ! snow thickness (only for nn_ice_alb=0)
-   REAL(wp) ::   c2       = 0.10    !  "        "
-   REAL(wp) ::   rcloud   = 0.06    ! cloud effect on albedo (only-for nn_ice_alb=0)
- 
-   !                             !!* namelist namsbc_alb
-   INTEGER  ::   nn_ice_alb
-   REAL(wp) ::   rn_alb_sdry, rn_alb_smlt, rn_alb_idry, rn_alb_imlt
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE albedo_ice( pt_ice, ph_ice, ph_snw, pa_ice_cs, pa_ice_os )
-      !!----------------------------------------------------------------------
-      !!               ***  ROUTINE albedo_ice  ***
-      !!          
-      !! ** Purpose :   Computation of the albedo of the snow/ice system 
-      !!       
-      !! ** Method  :   Two schemes are available (from namelist parameter nn_ice_alb)
-      !!                  0: the scheme is that of Shine & Henderson-Sellers (JGR 1985) for clear-skies
-      !!                  1: the scheme is "home made" (for cloudy skies) and based on Brandt et al. (J. Climate 2005)
-      !!                                                                           and Grenfell & Perovich (JGR 2004)
-      !!                Description of scheme 1:
-      !!                  1) Albedo dependency on ice thickness follows the findings from Brandt et al (2005)
-      !!                     which are an update of Allison et al. (JGR 1993) ; Brandt et al. 1999
-      !!                     0-5cm  : linear function of ice thickness
-      !!                     5-150cm: log    function of ice thickness
-      !!                     > 150cm: constant
-      !!                  2) Albedo dependency on snow thickness follows the findings from Grenfell & Perovich (2004)
-      !!                     i.e. it increases as -EXP(-snw_thick/0.02) during freezing and -EXP(-snw_thick/0.03) during melting
-      !!                  3) Albedo dependency on clouds is speculated from measurements of Grenfell and Perovich (2004)
-      !!                     i.e. cloudy-clear albedo depend on cloudy albedo following a 2d order polynomial law
-      !!                  4) The needed 4 parameters are: dry and melting snow, freezing ice and bare puddled ice
-      !!
-      !! ** Note    :   The parameterization from Shine & Henderson-Sellers presents several misconstructions:
-      !!                  1) ice albedo when ice thick. tends to 0 is different than ocean albedo
-      !!                  2) for small ice thick. covered with some snow (<3cm?), albedo is larger 
-      !!                     under melting conditions than under freezing conditions
-      !!                  3) the evolution of ice albedo as a function of ice thickness shows  
-      !!                     3 sharp inflexion points (at 5cm, 100cm and 150cm) that look highly unrealistic
-      !!
-      !! References :   Shine & Henderson-Sellers 1985, JGR, 90(D1), 2243-2250.
-      !!                Brandt et al. 2005, J. Climate, vol 18
-      !!                Grenfell & Perovich 2004, JGR, vol 109 
-      !!----------------------------------------------------------------------
-      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   pt_ice      !  ice surface temperature (Kelvin)
-      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   ph_ice      !  sea-ice thickness
-      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   ph_snw      !  snow thickness
-      REAL(wp), INTENT(  out), DIMENSION(:,:,:) ::   pa_ice_cs   !  albedo of ice under clear    sky
-      REAL(wp), INTENT(  out), DIMENSION(:,:,:) ::   pa_ice_os   !  albedo of ice under overcast sky
-      !!
-      INTEGER  ::   ji, jj, jl         ! dummy loop indices
-      INTEGER  ::   ijpl               ! number of ice categories (3rd dim of ice input arrays)
-      REAL(wp)            ::   zswitch, z1_c1, z1_c2
-      REAL(wp)                            ::   zalb_sm, zalb_sf, zalb_st ! albedo of snow melting, freezing, total
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zalb, zalb_it             ! intermediate variable & albedo of ice (snow free)
-      !!---------------------------------------------------------------------
-
-      ijpl = SIZE( pt_ice, 3 )                     ! number of ice categories
-      
-      CALL wrk_alloc( jpi,jpj,ijpl, zalb, zalb_it )
-
-      IF( albd_init == 0 )   CALL albedo_init      ! initialization 
-      
-      SELECT CASE ( nn_ice_alb )
-
-      !------------------------------------------
-      !  Shine and Henderson-Sellers (1985)
-      !------------------------------------------
-      CASE( 0 )
-       
-         !  Computation of ice albedo (free of snow)
-         WHERE     ( ph_snw == 0._wp .AND. pt_ice >= rt0_ice )   ;   zalb(:,:,:) = rn_alb_imlt
-         ELSE WHERE                                              ;   zalb(:,:,:) = rn_alb_idry
-         END  WHERE
-      
-         WHERE     ( 1.5  < ph_ice                     )  ;  zalb_it = zalb
-         ELSE WHERE( 1.0  < ph_ice .AND. ph_ice <= 1.5 )  ;  zalb_it = 0.472  + 2.0 * ( zalb - 0.472 ) * ( ph_ice - 1.0 )
-         ELSE WHERE( 0.05 < ph_ice .AND. ph_ice <= 1.0 )  ;  zalb_it = 0.2467 + 0.7049 * ph_ice              &
-            &                                                                 - 0.8608 * ph_ice * ph_ice     &
-            &                                                                 + 0.3812 * ph_ice * ph_ice * ph_ice
-         ELSE WHERE                                       ;  zalb_it = 0.1    + 3.6    * ph_ice
-         END WHERE
-     
-         DO jl = 1, ijpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  ! freezing snow
-                  ! no effect of underlying ice layer IF snow thickness > c1. Albedo does not depend on snow thick if > c2
-                  zswitch   = 1._wp - MAX( 0._wp , SIGN( 1._wp , - ( ph_snw(ji,jj,jl) - c1 ) ) )
-                  zalb_sf   = ( 1._wp - zswitch ) * (  zalb_it(ji,jj,jl)  &
-                     &                           + ph_snw(ji,jj,jl) * ( rn_alb_sdry - zalb_it(ji,jj,jl) ) / c1  )   &
-                     &        +         zswitch   * rn_alb_sdry  
-
-                  ! melting snow
-                  ! no effect of underlying ice layer. Albedo does not depend on snow thick IF > c2
-                  zswitch   = MAX( 0._wp , SIGN( 1._wp , ph_snw(ji,jj,jl) - c2 ) )
-                  zalb_sm = ( 1._wp - zswitch ) * ( rn_alb_imlt + ph_snw(ji,jj,jl) * ( rn_alb_smlt - rn_alb_imlt ) / c2 )   &
-                      &     +         zswitch   *   rn_alb_smlt 
-                  !
-                  ! snow albedo
-                  zswitch  =  MAX( 0._wp , SIGN( 1._wp , pt_ice(ji,jj,jl) - rt0_snow ) )   
-                  zalb_st  =  zswitch * zalb_sm + ( 1._wp - zswitch ) * zalb_sf
-               
-                  ! Ice/snow albedo
-                  zswitch   = 1._wp - MAX( 0._wp , SIGN( 1._wp , - ph_snw(ji,jj,jl) ) )
-                  pa_ice_cs(ji,jj,jl) =  zswitch * zalb_st + ( 1._wp - zswitch ) * zalb_it(ji,jj,jl)
-                  !
-               END DO
-            END DO
-         END DO
-
-         pa_ice_os(:,:,:) = pa_ice_cs(:,:,:) + rcloud       ! Oberhuber correction for overcast sky
-
-      !------------------------------------------
-      !  New parameterization (2016)
-      !------------------------------------------
-      CASE( 1 ) 
-
-! compilation of values from literature
-!        rn_alb_sdry = 0.85      ! dry snow
-!        rn_alb_smlt = 0.75      ! melting snow
-!        rn_alb_idry = 0.60      ! bare frozen ice
-! Perovich et al 2002 (Sheba) => the only dataset for which all types of ice/snow were retrieved
-!        rn_alb_sdry = 0.85      ! dry snow
-!        rn_alb_smlt = 0.72      ! melting snow
-!        rn_alb_idry = 0.65      ! bare frozen ice
-! Brandt et al 2005 (East Antarctica)
-!        rn_alb_sdry = 0.87      ! dry snow
-!        rn_alb_smlt = 0.82      ! melting snow
-!        rn_alb_idry = 0.54      ! bare frozen ice
-! 
-         !  Computation of ice albedo (free of snow)
-         z1_c1 = 1. / ( LOG(1.5) - LOG(0.05) ) 
-         z1_c2 = 1. / 0.05
-         WHERE     ( ph_snw == 0._wp .AND. pt_ice >= rt0_ice )   ;   zalb = rn_alb_imlt
-         ELSE WHERE                                              ;   zalb = rn_alb_idry
-         END  WHERE
-         
-         WHERE     ( 1.5  < ph_ice                     )  ;  zalb_it = zalb
-         ELSE WHERE( 0.05 < ph_ice .AND. ph_ice <= 1.5 )  ;  zalb_it = zalb     + ( 0.18 - zalb     ) * z1_c1 *  &
-            &                                                                     ( LOG(1.5) - LOG(ph_ice) )
-         ELSE WHERE                                       ;  zalb_it = ralb_oce + ( 0.18 - ralb_oce ) * z1_c2 * ph_ice
-         END WHERE
-
-         z1_c1 = 1. / 0.02
-         z1_c2 = 1. / 0.03
-         !  Computation of the snow/ice albedo
-         DO jl = 1, ijpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zalb_sf = rn_alb_sdry - ( rn_alb_sdry - zalb_it(ji,jj,jl)) * EXP( - ph_snw(ji,jj,jl) * z1_c1 );
-                  zalb_sm = rn_alb_smlt - ( rn_alb_smlt - zalb_it(ji,jj,jl)) * EXP( - ph_snw(ji,jj,jl) * z1_c2 );
-
-                  ! snow albedo
-                  zswitch = MAX( 0._wp , SIGN( 1._wp , pt_ice(ji,jj,jl) - rt0_snow ) )   
-                  zalb_st = zswitch * zalb_sm + ( 1._wp - zswitch ) * zalb_sf
-
-                  ! Ice/snow albedo   
-                  zswitch             = MAX( 0._wp , SIGN( 1._wp , - ph_snw(ji,jj,jl) ) )
-                  pa_ice_os(ji,jj,jl) = ( 1._wp - zswitch ) * zalb_st + zswitch *  zalb_it(ji,jj,jl)
-
-              END DO
-            END DO
-         END DO
-         ! Effect of the clouds (2d order polynomial)
-         pa_ice_cs = pa_ice_os - ( - 0.1010 * pa_ice_os * pa_ice_os + 0.1933 * pa_ice_os - 0.0148 ); 
-
-      END SELECT
-      
-      CALL wrk_dealloc( jpi,jpj,ijpl, zalb, zalb_it )
-      !
-   END SUBROUTINE albedo_ice
-
-
-   SUBROUTINE albedo_oce( pa_oce_os , pa_oce_cs )
-      !!----------------------------------------------------------------------
-      !!               ***  ROUTINE albedo_oce  ***
-      !! 
-      !! ** Purpose :   Computation of the albedo of the ocean
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:), INTENT(out) ::   pa_oce_os   !  albedo of ocean under overcast sky
-      REAL(wp), DIMENSION(:,:), INTENT(out) ::   pa_oce_cs   !  albedo of ocean under clear sky
-      !!
-      REAL(wp) :: zcoef 
-      !!----------------------------------------------------------------------
-      !
-      zcoef = 0.05 / ( 1.1 * rmue**1.4 + 0.15 )   ! Parameterization of Briegled and Ramanathan, 1982
-      pa_oce_cs(:,:) = zcoef 
-      pa_oce_os(:,:) = 0.06                       ! Parameterization of Kondratyev, 1969 and Payne, 1972
-      !
-   END SUBROUTINE albedo_oce
-
-
-   SUBROUTINE albedo_init
-      !!----------------------------------------------------------------------
-      !!                 ***  ROUTINE albedo_init  ***
-      !!
-      !! ** Purpose :   initializations for the albedo parameters
-      !!
-      !! ** Method  :   Read the namelist namsbc_alb
-      !!----------------------------------------------------------------------
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namsbc_alb/ nn_ice_alb, rn_alb_sdry, rn_alb_smlt, rn_alb_idry , rn_alb_imlt
-      !!----------------------------------------------------------------------
-      !
-      albd_init = 1                     ! indicate that the initialization has been done
-      !
-      REWIND( numnam_ref )              ! Namelist namsbc_alb in reference namelist : Albedo parameters
-      READ  ( numnam_ref, namsbc_alb, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_alb in reference namelist', lwp )
-
-      REWIND( numnam_cfg )              ! Namelist namsbc_alb in configuration namelist : Albedo parameters
-      READ  ( numnam_cfg, namsbc_alb, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_alb in configuration namelist', lwp )
-      IF(lwm) WRITE ( numond, namsbc_alb )
-      !
-      IF(lwp) THEN                      ! Control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'albedo : set albedo parameters'
-         WRITE(numout,*) '~~~~~~~'
-         WRITE(numout,*) '   Namelist namsbc_alb : albedo '
-         WRITE(numout,*) '      choose the albedo parameterization                  nn_ice_alb  = ', nn_ice_alb
-         WRITE(numout,*) '      albedo of dry snow                                  rn_alb_sdry = ', rn_alb_sdry
-         WRITE(numout,*) '      albedo of melting snow                              rn_alb_smlt = ', rn_alb_smlt
-         WRITE(numout,*) '      albedo of dry ice                                   rn_alb_idry = ', rn_alb_idry
-         WRITE(numout,*) '      albedo of bare puddled ice                          rn_alb_imlt = ', rn_alb_imlt
-      ENDIF
-      !
-   END SUBROUTINE albedo_init
-
-   !!======================================================================
-END MODULE albedo
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/fldread.F90	(revision 9019)
@@ -116,5 +116,5 @@
    END TYPE WGT
 
-   INTEGER,     PARAMETER             ::   tot_wgts = 10
+   INTEGER,     PARAMETER             ::   tot_wgts = 20
    TYPE( WGT ), DIMENSION(tot_wgts)   ::   ref_wgts     ! array of wgts
    INTEGER                            ::   nxt_wgt = 1  ! point to next available space in ref_wgts array
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/ocealb.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/ocealb.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/ocealb.F90	(revision 9019)
@@ -0,0 +1,49 @@
+MODULE ocealb
+   !!======================================================================
+   !!                       ***  MODULE  ocealb  ***
+   !! Ocean forcing:  bulk thermohaline forcing of the ocean
+   !!=====================================================================
+   !! History :
+   !!   NEMO     4.0  ! 2017-07  (C. Rousset) Split ocean and ice albedos
+   !!----------------------------------------------------------------------
+   !!   oce_alb    : albedo for ocean (clear and overcast skies)
+   !!----------------------------------------------------------------------
+   USE phycst         ! physical constants
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! work arrays
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   oce_alb   ! routine called by sbccpl
+  
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2010)
+   !! $Id: ocealb.F90 8268 2017-07-03 15:01:04Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE oce_alb( palb_os , palb_cs )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE oce_alb  ***
+      !! 
+      !! ** Purpose :   Computation of the albedo of the ocean
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:), INTENT(out) ::   palb_os   !  albedo of ocean under overcast sky
+      REAL(wp), DIMENSION(:,:), INTENT(out) ::   palb_cs   !  albedo of ocean under clear sky
+      !!
+      REAL(wp) ::   zcoef 
+      REAL(wp) ::   rmue = 0.40    !  cosine of local solar altitude
+      !!----------------------------------------------------------------------
+      !
+      zcoef = 0.05 / ( 1.1 * rmue**1.4 + 0.15 )   ! Parameterization of Briegled and Ramanathan, 1982
+      palb_cs(:,:) = zcoef 
+      palb_os(:,:) = 0.06                         ! Parameterization of Kondratyev, 1969 and Payne, 1972
+      !
+   END SUBROUTINE oce_alb
+
+   !!======================================================================
+END MODULE ocealb
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_ice.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_ice.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_ice.F90	(revision 9019)
@@ -9,7 +9,7 @@
    !!            3.4  ! 2011-11  (C. Harris) CICE added as an option
    !!----------------------------------------------------------------------
-#if defined key_lim3 || defined key_lim2 || defined key_cice
-   !!----------------------------------------------------------------------
-   !!   'key_lim2' or 'key_lim3' :             LIM-2 or LIM-3 sea-ice model
+#if defined key_lim3 || defined key_cice
+   !!----------------------------------------------------------------------
+   !!   'key_lim3' or 'key_cice' :              LIM-3 or CICE sea-ice model
    !!----------------------------------------------------------------------
    USE par_oce          ! ocean parameters
@@ -18,8 +18,4 @@
    USE ice              ! LIM-3 parameters
 # endif
-# if defined key_lim2
-   USE par_ice_2        ! LIM-2 parameters
-   USE ice_2
-# endif
 # if defined key_cice
    USE ice_domain_size, only: ncat 
@@ -31,18 +27,7 @@
    PRIVATE
 
-   PUBLIC sbc_ice_alloc ! called in iceini(_2).F90
-
-# if defined  key_lim2
-   LOGICAL         , PUBLIC, PARAMETER ::   lk_lim2    = .TRUE.   !: LIM-2 ice model
-   LOGICAL         , PUBLIC, PARAMETER ::   lk_lim3    = .FALSE.  !: no LIM-3
-   LOGICAL         , PUBLIC, PARAMETER ::   lk_cice    = .FALSE.  !: no CICE 
-#  if defined key_lim2_vp
-   CHARACTER(len=1), PUBLIC, PARAMETER ::   cp_ice_msh = 'I'      !: VP : 'I'-grid ice-velocity (B-grid lower left corner)
-#  else
-   CHARACTER(len=1), PUBLIC, PARAMETER ::   cp_ice_msh = 'C'      !: EVP: 'C'-grid ice-velocity
-#  endif
-# endif
+   PUBLIC   sbc_ice_alloc   ! called in sbcmod.F90 or sbcice_cice.F90
+
 # if defined  key_lim3
-   LOGICAL         , PUBLIC, PARAMETER ::   lk_lim2    = .FALSE.  !: no LIM-2
    LOGICAL         , PUBLIC, PARAMETER ::   lk_lim3    = .TRUE.   !: LIM-3 ice model
    LOGICAL         , PUBLIC, PARAMETER ::   lk_cice    = .FALSE.  !: no CICE 
@@ -50,5 +35,4 @@
 # endif
 # if defined  key_cice
-   LOGICAL         , PUBLIC, PARAMETER ::   lk_lim2    = .FALSE.  !: no LIM-2
    LOGICAL         , PUBLIC, PARAMETER ::   lk_lim3    = .FALSE.  !: no LIM-3
    LOGICAL         , PUBLIC, PARAMETER ::   lk_cice    = .TRUE.   !: CICE ice model
@@ -64,8 +48,10 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   alb_ice        !: ice albedo                                       [-]
 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qml_ice        !: heat available for snow / ice surface melting     [W/m2] 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qcn_ice        !: heat conduction flux in the layer below surface   [W/m2] 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qsr_ice_tr     !: solar flux transmitted below the ice surface      [W/m2]
+
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   utau_ice       !: atmos-ice u-stress. VP: I-pt ; EVP: U,V-pts   [N/m2]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   vtau_ice       !: atmos-ice v-stress. VP: I-pt ; EVP: U,V-pts   [N/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   fr1_i0         !: Solar surface transmission parameter, thick ice  [-]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   fr2_i0         !: Solar surface transmission parameter, thin ice   [-]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   emp_ice        !: sublimation - precip over sea ice          [kg/m2/s]
 
@@ -83,7 +69,7 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   qprec_ice      !: enthalpy of precip over ice                 [J/m3]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   emp_oce        !: evap - precip over ocean                 [kg/m2/s]
-#endif
-#if defined key_lim3 || defined key_lim2
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   wndm_ice       !: wind speed module at T-point                 [m/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   sstfrz         !: wind speed module at T-point                 [m/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   tsfc_ice       !: sea ice surface skin temperature (on categories)
 #endif
 
@@ -106,17 +92,18 @@
    INTEGER , PUBLIC, PARAMETER ::   jpl = ncat
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   u_ice, v_ice          ! jpi, jpj
-#endif
    
-#if defined key_lim2 || defined key_cice
    ! already defined in ice.F90 for LIM3
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  a_i
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  ht_i, ht_s
-#endif
-
-#if defined key_cice
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::  h_i, h_s
+
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   tatm_ice       !: air temperature [K]
 #endif
 
    REAL(wp), PUBLIC, SAVE ::   cldf_ice = 0.81    !: cloud fraction over sea ice, summer CLIO value   [-]
+
+   !! arrays relating to embedding ice in the ocean
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   snwice_mass        !: mass of snow and ice at current  ice time step   [Kg/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   snwice_mass_b      !: mass of snow and ice at previous ice time step   [Kg/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   snwice_fmass       !: time evolution of mass of snow+ice               [Kg/m2/s]
 
    !!----------------------------------------------------------------------
@@ -131,23 +118,20 @@
       !!                     ***  FUNCTION sbc_ice_alloc  ***
       !!----------------------------------------------------------------------
-      INTEGER :: ierr(5)
+      INTEGER :: ierr(4)
       !!----------------------------------------------------------------------
       ierr(:) = 0
 
-#if defined key_lim3 || defined key_lim2
-      ALLOCATE( qns_ice (jpi,jpj,jpl) , qsr_ice (jpi,jpj,jpl) ,     &
-         &      qla_ice (jpi,jpj,jpl) , dqla_ice(jpi,jpj,jpl) ,     &
-         &      dqns_ice(jpi,jpj,jpl) , tn_ice  (jpi,jpj,jpl) , alb_ice (jpi,jpj,jpl) ,   &
-         &      utau_ice(jpi,jpj)     , vtau_ice(jpi,jpj)     , wndm_ice(jpi,jpj)     ,   &
-         &      fr1_i0  (jpi,jpj)     , fr2_i0  (jpi,jpj)     ,     &
-#if defined key_lim2
-         &      a_i(jpi,jpj,jpl)      ,                             &
-#endif
+      ALLOCATE( snwice_mass(jpi,jpj) , snwice_mass_b(jpi,jpj), snwice_fmass(jpi,jpj) , STAT=ierr(1) )
+
 #if defined key_lim3
-         &      evap_ice(jpi,jpj,jpl) , devap_ice(jpi,jpj,jpl) , qprec_ice(jpi,jpj) ,   &
-         &      qemp_ice(jpi,jpj)     , qevap_ice(jpi,jpj,jpl) , qemp_oce (jpi,jpj) ,   &
-         &      qns_oce (jpi,jpj)     , qsr_oce  (jpi,jpj)     , emp_oce (jpi,jpj)  ,   &
-#endif
-         &      emp_ice(jpi,jpj)      ,  STAT= ierr(1) )
+      ALLOCATE( qns_ice (jpi,jpj,jpl) , qsr_ice  (jpi,jpj,jpl) ,     &
+         &      qla_ice (jpi,jpj,jpl) , dqla_ice (jpi,jpj,jpl) ,     &
+         &      dqns_ice(jpi,jpj,jpl) , tn_ice   (jpi,jpj,jpl) , alb_ice   (jpi,jpj,jpl) ,   &
+         &      qml_ice (jpi,jpj,jpl) , qcn_ice  (jpi,jpj,jpl) , qsr_ice_tr(jpi,jpj,jpl) ,   &
+         &      utau_ice(jpi,jpj)     , vtau_ice (jpi,jpj)     , wndm_ice  (jpi,jpj)     ,   &
+         &      evap_ice(jpi,jpj,jpl) , devap_ice(jpi,jpj,jpl) , qprec_ice (jpi,jpj)     ,   &
+         &      qemp_ice(jpi,jpj)     , qevap_ice(jpi,jpj,jpl) , qemp_oce  (jpi,jpj)     ,   &
+         &      qns_oce (jpi,jpj)     , qsr_oce  (jpi,jpj)     , emp_oce   (jpi,jpj)     ,   &
+         &      emp_ice (jpi,jpj)     , tsfc_ice (jpi,jpj,jpl) , sstfrz    (jpi,jpj)     , STAT= ierr(2) )
 #endif
 
@@ -158,14 +142,10 @@
                 ss_iov(jpi,jpj)       , fr_iu(jpi,jpj)        , fr_iv(jpi,jpj)        , &
                 a_i(jpi,jpj,ncat)     , topmelt(jpi,jpj,ncat) , botmelt(jpi,jpj,ncat) , &
-                STAT= ierr(1) )
-      IF( ln_cpl )   ALLOCATE( u_ice(jpi,jpj)        , fr1_i0(jpi,jpj)       , tn_ice (jpi,jpj,1)    , &
-         &                     v_ice(jpi,jpj)        , fr2_i0(jpi,jpj)       , alb_ice(jpi,jpj,1)    , &
+                STAT= ierr(2) )
+      IF( ln_cpl )   ALLOCATE( u_ice(jpi,jpj)        , tn_ice (jpi,jpj,1)    , &
+         &                     v_ice(jpi,jpj)        , alb_ice(jpi,jpj,1)    , &
          &                     emp_ice(jpi,jpj)      , qns_ice(jpi,jpj,1)    , dqns_ice(jpi,jpj,1)   , &
-         &                     STAT= ierr(2) )
-      
-#endif
-         !
-#if defined key_cice || defined key_lim2
-      IF( ln_cpl )   ALLOCATE( ht_i(jpi,jpj,jpl) , ht_s(jpi,jpj,jpl) , STAT=ierr(5) )
+         &                     STAT= ierr(3) )      
+      IF( ln_cpl )   ALLOCATE( h_i(jpi,jpj,jpl) , h_s(jpi,jpj,jpl) , STAT=ierr(4) )
 #endif
 
@@ -177,20 +157,49 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option                      NO LIM 2.0 or 3.0 or CICE sea-ice model
-   !!----------------------------------------------------------------------
+   !!   Default option                      NO LIM3 or CICE sea-ice model
+   !!----------------------------------------------------------------------
+   USE lib_mpp          ! MPP library
    USE in_out_manager   ! I/O manager
-   LOGICAL         , PUBLIC, PARAMETER ::   lk_lim2    = .FALSE.  !: no LIM-2 ice model
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   sbc_ice_alloc   !
+
    LOGICAL         , PUBLIC, PARAMETER ::   lk_lim3    = .FALSE.  !: no LIM-3 ice model
    LOGICAL         , PUBLIC, PARAMETER ::   lk_cice    = .FALSE.  !: no CICE  ice model
    CHARACTER(len=1), PUBLIC, PARAMETER ::   cp_ice_msh = '-'      !: no grid ice-velocity
-   REAL            , PUBLIC, PARAMETER ::   cldf_ice = 0.81       !: cloud fraction over sea ice, summer CLIO value   [-]
+   REAL(wp)        , PUBLIC, PARAMETER ::   cldf_ice = 0.81       !: cloud fraction over sea ice, summer CLIO value   [-]
    INTEGER         , PUBLIC, PARAMETER ::   jpl = 1 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   u_ice, v_ice,fr1_i0,fr2_i0          ! jpi, jpj
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   u_ice, v_ice                        ! jpi, jpj
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   tn_ice, alb_ice, qns_ice, dqns_ice  ! (jpi,jpj,jpl)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   a_i
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   emp_ice
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qsr_ice
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ht_i, ht_s
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   h_i, h_s
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   topmelt, botmelt
+   !
+   !! arrays related to embedding ice in the ocean. 
+   !! These arrays need to be declared even if no ice model is required. 
+   !! In the no ice model or traditional levitating ice cases they contain only zeros
+   !! ---------------------
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   snwice_mass        !: mass of snow and ice at current  ice time step   [Kg/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   snwice_mass_b      !: mass of snow and ice at previous ice time step   [Kg/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   snwice_fmass       !: time evolution of mass of snow+ice               [Kg/m2/s]
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION sbc_ice_alloc()
+      !!----------------------------------------------------------------------
+      !!                     ***  FUNCTION sbc_ice_alloc  ***
+      !!----------------------------------------------------------------------
+      INTEGER :: ierr(1)
+      !!----------------------------------------------------------------------
+      ierr(:) = 0
+      ALLOCATE( snwice_mass(jpi,jpj) , snwice_mass_b(jpi,jpj), snwice_fmass(jpi,jpj) , STAT=ierr(1) )
+      sbc_ice_alloc = MAXVAL( ierr )
+      IF( lk_mpp            )   CALL mpp_sum ( sbc_ice_alloc )
+      IF( sbc_ice_alloc > 0 )   CALL ctl_warn('sbc_ice_alloc: allocation of arrays failed')
+   END FUNCTION sbc_ice_alloc
 #endif
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_oce.F90	(revision 9019)
@@ -47,14 +47,8 @@
    LOGICAL , PUBLIC ::   ln_apr_dyn     !: Atmospheric pressure forcing used on dynamics (ocean & ice)
    INTEGER , PUBLIC ::   nn_ice         !: flag for ice in the surface boundary condition (=0/1/2/3)
-   INTEGER , PUBLIC ::   nn_ice_embd    !: flag for levitating/embedding sea-ice in the ocean
-   !                                             !: =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)
+   LOGICAL , PUBLIC ::   ln_ice_embd    !: flag for levitating/embedding sea-ice in the ocean
+   !                                             !: =F levitating ice (no presure effect) with mass and salt exchanges
+   !                                             !: =T embedded sea-ice (pressure effect + mass and salt exchanges)
    INTEGER , PUBLIC ::   nn_components  !: flag for sbc module (including sea-ice) coupling mode (see component definition below) 
-   INTEGER , PUBLIC ::   nn_limflx      !: LIM3 Multi-category heat flux formulation
-   !                                             !: =-1  Use of per-category fluxes
-   !                                             !: = 0  Average per-category fluxes
-   !                                             !: = 1  Average then redistribute per-category fluxes
-   !                                             !: = 2  Redistribute a single flux over categories
    INTEGER , PUBLIC ::   nn_fwb         !: FreshWater Budget: 
    !                                             !:  = 0 unchecked 
@@ -70,4 +64,8 @@
    !
    INTEGER , PUBLIC ::   nn_lsm         !: Number of iteration if seaoverland is applied
+   !
+   !                                   !!* namsbc_cpl namelist *
+   INTEGER , PUBLIC ::   nn_cats_cpl    !: Number of sea ice categories over which the coupling is carried out
+
    !!----------------------------------------------------------------------
    !!           switch definition (improve readability)
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk.F90	(revision 9019)
@@ -15,6 +15,7 @@
    !!            3.7  !  2014-06  (L. Brodeau)  simplification and optimization of CORE bulk
    !!            4.0  !  2016-06  (L. Brodeau)  sbcblk_core becomes sbcblk and is not restricted to the CORE algorithm anymore
-   !!                                          ==> based on AeroBulk (http://aerobulk.sourceforge.net/)
+   !!                 !                        ==> based on AeroBulk (http://aerobulk.sourceforge.net/)
    !!            4.0  !  2016-10  (G. Madec)  introduce a sbc_blk_init routine
+   !!            4.0  !  2016-10  (M. Vancoppenolle)  Introduce Jules emulator (M. Vancoppenolle) 
    !!----------------------------------------------------------------------
 
@@ -23,9 +24,14 @@
    !!   sbc_blk       : bulk formulation as ocean surface boundary condition
    !!   blk_oce       : computes momentum, heat and freshwater fluxes over ocean
-   !!   blk_ice       : computes momentum, heat and freshwater fluxes over sea ice
    !!   rho_air       : density of (moist) air (depends on T_air, q_air and SLP
    !!   cp_air        : specific heat of (moist) air (depends spec. hum. q_air)
    !!   q_sat         : saturation humidity as a function of SLP and temperature
    !!   L_vap         : latent heat of vaporization of water as a function of temperature
+   !!             sea-ice case only : 
+   !!   blk_ice_tau   : provide the air-ice stress
+   !!   blk_ice_flx   : provide the heat and mass fluxes at air-ice interface
+   !!   blk_ice_qcn   : provide ice surface temperature and snow/ice conduction flux (emulating JULES coupler)
+   !!   Cdn10_Lupkes2012 : Lupkes et al. (2012) air-ice drag
+   !!   Cdn10_Lupkes2015 : Lupkes et al. (2015) air-ice drag 
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and tracers
@@ -40,9 +46,6 @@
    USE lib_fortran    ! to use key_nosignedzero
 #if defined key_lim3
-   USE ice     , ONLY :   u_ice, v_ice, jpl, pfrld, a_i_b, at_i_b
-   USE limthd_dh      ! for CALL lim_thd_snwblow
-#elif defined key_lim2
-   USE ice_2   , ONLY :   u_ice, v_ice
-   USE par_ice_2      ! LIM-2 parameters
+   USE ice     , ONLY :   u_ice, v_ice, jpl, a_i_b, at_i_b, tm_su, rn_cnd_s
+   USE icethd_dh      ! for CALL ice_thd_snwblow
 #endif
    USE sbcblk_algo_ncar     ! => turb_ncar     : NCAR - CORE (Large & Yeager, 2009) 
@@ -54,5 +57,4 @@
    USE in_out_manager ! I/O manager
    USE lib_mpp        ! distribued memory computing library
-   USE wrk_nemo       ! work arrays
    USE timing         ! Timing
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
@@ -64,8 +66,9 @@
    PUBLIC   sbc_blk_init  ! called in sbcmod
    PUBLIC   sbc_blk       ! called in sbcmod
-#if defined key_lim2 || defined key_lim3
-   PUBLIC   blk_ice_tau   ! routine called in sbc_ice_lim module
-   PUBLIC   blk_ice_flx   ! routine called in sbc_ice_lim module
-#endif
+#if defined key_lim3
+   PUBLIC   blk_ice_tau   ! routine called in iceforcing
+   PUBLIC   blk_ice_flx   ! routine called in iceforcing
+   PUBLIC   blk_ice_qcn   ! routine called in iceforcing
+#endif 
 
 !!Lolo: should ultimately be moved in the module with all physical constants ?
@@ -96,5 +99,5 @@
    REAL(wp), PARAMETER ::   Ls     =    2.839e6     ! latent heat of sublimation
    REAL(wp), PARAMETER ::   Stef   =    5.67e-8     ! Stefan Boltzmann constant
-   REAL(wp), PARAMETER ::   Cd_ice =    1.4e-3      ! iovi 1.63e-3     ! transfer coefficient over ice
+   REAL(wp), PARAMETER ::   Cd_ice =    1.4e-3      ! transfer coefficient over ice
    REAL(wp), PARAMETER ::   albo   =    0.066       ! ocean albedo assumed to be constant
    !
@@ -107,11 +110,18 @@
    LOGICAL  ::   ln_taudif      ! logical flag to use the "mean of stress module - module of mean stress" data
    REAL(wp) ::   rn_pfac        ! multiplication factor for precipitation
-   REAL(wp) ::   rn_efac        ! multiplication factor for evaporation (clem)
-   REAL(wp) ::   rn_vfac        ! multiplication factor for ice/ocean velocity in the calculation of wind stress (clem)
+   REAL(wp) ::   rn_efac        ! multiplication factor for evaporation
+   REAL(wp) ::   rn_vfac        ! multiplication factor for ice/ocean velocity in the calculation of wind stress
    REAL(wp) ::   rn_zqt         ! z(q,t) : height of humidity and temperature measurements
    REAL(wp) ::   rn_zu          ! z(u)   : height of wind measurements
-   LOGICAL  ::   ln_Cd_L12 = .FALSE. !  Modify the drag ice-atm and oce-atm depending on ice concentration (from Lupkes et al. JGR2012)
+!!gm ref namelist initialize it so remove the setting to false below
+   LOGICAL  ::   ln_Cd_L12 = .FALSE. !  Modify the drag ice-atm depending on ice concentration (from Lupkes et al. JGR2012)
+   LOGICAL  ::   ln_Cd_L15 = .FALSE. !  Modify the drag ice-atm depending on ice concentration (from Lupkes et al. JGR2015)
    !
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   Cd_oce   ! air-ocean drag (clem)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   Cd_atm                    ! transfer coefficient for momentum      (tau)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   Ch_atm                    ! transfer coefficient for sensible heat (Q_sens)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   Ce_atm                    ! tansfert coefficient for evaporation   (Q_lat)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   t_zu                      ! air temperature at wind speed height (needed by Lupkes 2015 bulk scheme)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   q_zu                      ! air spec. hum.  at wind speed height (needed by Lupkes 2015 bulk scheme)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   cdn_oce, chn_oce, cen_oce ! needed by Lupkes 2015 bulk scheme
 
    INTEGER  ::   nblk           ! choice of the bulk algorithm
@@ -135,5 +145,6 @@
       !!             ***  ROUTINE sbc_blk_alloc ***
       !!-------------------------------------------------------------------
-      ALLOCATE( Cd_oce(jpi,jpj) , STAT=sbc_blk_alloc )
+      ALLOCATE( Cd_atm (jpi,jpj), Ch_atm (jpi,jpj), Ce_atm (jpi,jpj), t_zu(jpi,jpj), q_zu(jpi,jpj), &
+         &      cdn_oce(jpi,jpj), chn_oce(jpi,jpj), cen_oce(jpi,jpj), STAT=sbc_blk_alloc )
       !
       IF( lk_mpp             )   CALL mpp_sum ( sbc_blk_alloc )
@@ -141,4 +152,5 @@
    END FUNCTION sbc_blk_alloc
 
+
    SUBROUTINE sbc_blk_init
       !!---------------------------------------------------------------------
@@ -148,9 +160,4 @@
       !!
       !! ** Method  : 
-      !!
-      !!      C A U T I O N : never mask the surface stress fields
-      !!                      the stress is assumed to be in the (i,j) mesh referential
-      !!
-      !! ** Action  :   
       !!
       !!----------------------------------------------------------------------
@@ -167,5 +174,5 @@
          &                 ln_NCAR, ln_COARE_3p0, ln_COARE_3p5, ln_ECMWF,             &   ! bulk algorithm
          &                 cn_dir , ln_taudif, rn_zqt, rn_zu,                         & 
-         &                 rn_pfac, rn_efac, rn_vfac, ln_Cd_L12
+         &                 rn_pfac, rn_efac, rn_vfac, ln_Cd_L12, ln_Cd_L15
       !!---------------------------------------------------------------------
       !
@@ -262,4 +269,6 @@
          WRITE(numout,*) '      factor applied on ocean/ice velocity                rn_vfac      = ', rn_vfac
          WRITE(numout,*) '         (form absolute (=0) to relative winds(=1))'
+         WRITE(numout,*) '      use ice-atm drag from Lupkes2012                    ln_Cd_L12    = ', ln_Cd_L12
+         WRITE(numout,*) '      use ice-atm drag from Lupkes2015                    ln_Cd_L15    = ', ln_Cd_L15
          !
          WRITE(numout,*)
@@ -281,5 +290,5 @@
       !!
       !! ** Purpose :   provide at each time step the surface ocean fluxes
-      !!      (momentum, heat, freshwater and runoff)
+      !!              (momentum, heat, freshwater and runoff)
       !!
       !! ** Method  : (1) READ each fluxes in NetCDF files:
@@ -364,26 +373,16 @@
       INTEGER  ::   ji, jj               ! dummy loop indices
       REAL(wp) ::   zztmp                ! local variable
-      REAL(wp), DIMENSION(:,:), POINTER ::   zwnd_i, zwnd_j    ! wind speed components at T-point
-      REAL(wp), DIMENSION(:,:), POINTER ::   zsq               ! specific humidity at pst
-      REAL(wp), DIMENSION(:,:), POINTER ::   zqlw, zqsb        ! long wave and sensible heat fluxes
-      REAL(wp), DIMENSION(:,:), POINTER ::   zqla, zevap       ! latent heat fluxes and evaporation
-      REAL(wp), DIMENSION(:,:), POINTER ::   Cd                ! transfer coefficient for momentum      (tau)
-      REAL(wp), DIMENSION(:,:), POINTER ::   Ch                ! transfer coefficient for sensible heat (Q_sens)
-      REAL(wp), DIMENSION(:,:), POINTER ::   Ce                ! tansfert coefficient for evaporation   (Q_lat)
-      REAL(wp), DIMENSION(:,:), POINTER ::   zst               ! surface temperature in Kelvin
-      REAL(wp), DIMENSION(:,:), POINTER ::   zt_zu             ! air temperature at wind speed height
-      REAL(wp), DIMENSION(:,:), POINTER ::   zq_zu             ! air spec. hum.  at wind speed height
-      REAL(wp), DIMENSION(:,:), POINTER ::   zU_zu             ! bulk wind speed at height zu  [m/s]
-      REAL(wp), DIMENSION(:,:), POINTER ::   ztpot             ! potential temperature of air at z=rn_zqt [K]
-      REAL(wp), DIMENSION(:,:), POINTER ::   zrhoa             ! density of air   [kg/m^3]
-      !!---------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('blk_oce')
-      !
-      CALL wrk_alloc( jpi,jpj,   zwnd_i, zwnd_j, zsq, zqlw, zqsb, zqla, zevap )
-      CALL wrk_alloc( jpi,jpj,   Cd, Ch, Ce, zst, zt_zu, zq_zu )
-      CALL wrk_alloc( jpi,jpj,   zU_zu, ztpot, zrhoa )
-      !
-
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwnd_i, zwnd_j    ! wind speed components at T-point
+      REAL(wp), DIMENSION(jpi,jpj) ::   zsq               ! specific humidity at pst
+      REAL(wp), DIMENSION(jpi,jpj) ::   zqlw, zqsb        ! long wave and sensible heat fluxes
+      REAL(wp), DIMENSION(jpi,jpj) ::   zqla, zevap       ! latent heat fluxes and evaporation
+      REAL(wp), DIMENSION(jpi,jpj) ::   zst               ! surface temperature in Kelvin
+      REAL(wp), DIMENSION(jpi,jpj) ::   zU_zu             ! bulk wind speed at height zu  [m/s]
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztpot             ! potential temperature of air at z=rn_zqt [K]
+      REAL(wp), DIMENSION(jpi,jpj) ::   zrhoa             ! density of air   [kg/m^3]
+      !!---------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('blk_oce')
+      !
       ! local scalars ( place there for vector optimisation purposes)
       zst(:,:) = pst(:,:) + rt0      ! convert SST from Celcius to Kelvin (and set minimum value far above 0 K)
@@ -430,6 +429,4 @@
       zqlw(:,:) = (  sf(jp_qlw)%fnow(:,:,1) - Stef * zst(:,:)*zst(:,:)*zst(:,:)*zst(:,:)  ) * tmask(:,:,1)   ! Long  Wave
 
-
-
       ! ----------------------------------------------------------------------------- !
       !     II    Turbulent FLUXES                                                    !
@@ -447,11 +444,11 @@
       !
       CASE( np_NCAR      )   ;   CALL turb_ncar    ( rn_zqt, rn_zu, zst, ztpot, zsq, sf(jp_humi)%fnow, wndm,   &  ! NCAR-COREv2
-         &                                               Cd, Ch, Ce, zt_zu, zq_zu, zU_zu )
+         &                                           Cd_atm, Ch_atm, Ce_atm, t_zu, q_zu, zU_zu, cdn_oce, chn_oce, cen_oce )
       CASE( np_COARE_3p0 )   ;   CALL turb_coare   ( rn_zqt, rn_zu, zst, ztpot, zsq, sf(jp_humi)%fnow, wndm,   &  ! COARE v3.0
-         &                                               Cd, Ch, Ce, zt_zu, zq_zu, zU_zu )
+         &                                           Cd_atm, Ch_atm, Ce_atm, t_zu, q_zu, zU_zu, cdn_oce, chn_oce, cen_oce )
       CASE( np_COARE_3p5 )   ;   CALL turb_coare3p5( rn_zqt, rn_zu, zst, ztpot, zsq, sf(jp_humi)%fnow, wndm,   &  ! COARE v3.5
-         &                                               Cd, Ch, Ce, zt_zu, zq_zu, zU_zu )
+         &                                           Cd_atm, Ch_atm, Ce_atm, t_zu, q_zu, zU_zu, cdn_oce, chn_oce, cen_oce )
       CASE( np_ECMWF     )   ;   CALL turb_ecmwf   ( rn_zqt, rn_zu, zst, ztpot, zsq, sf(jp_humi)%fnow, wndm,   &  ! ECMWF
-         &                                               Cd, Ch, Ce, zt_zu, zq_zu, zU_zu )
+         &                                           Cd_atm, Ch_atm, Ce_atm, t_zu, q_zu, zU_zu, cdn_oce, chn_oce, cen_oce )
       CASE DEFAULT
          CALL ctl_stop( 'STOP', 'sbc_oce: non-existing bulk formula selected' )
@@ -460,14 +457,15 @@
       !                          ! Compute true air density :
       IF( ABS(rn_zu - rn_zqt) > 0.01 ) THEN     ! At zu: (probably useless to remove zrho*grav*rn_zu from SLP...)
-         zrhoa(:,:) = rho_air( zt_zu(:,:)             , zq_zu(:,:)             , sf(jp_slp)%fnow(:,:,1) )
+         zrhoa(:,:) = rho_air( t_zu(:,:)              , q_zu(:,:)              , sf(jp_slp)%fnow(:,:,1) )
       ELSE                                      ! At zt:
          zrhoa(:,:) = rho_air( sf(jp_tair)%fnow(:,:,1), sf(jp_humi)%fnow(:,:,1), sf(jp_slp)%fnow(:,:,1) )
       END IF
 
-      Cd_oce(:,:) = Cd(:,:)  ! record value of pure ocean-atm. drag (clem)
+!!      CALL iom_put( "Cd_oce", Cd_atm)  ! output value of pure ocean-atm. transfer coef.
+!!      CALL iom_put( "Ch_oce", Ch_atm)  ! output value of pure ocean-atm. transfer coef.
 
       DO jj = 1, jpj             ! tau module, i and j component
          DO ji = 1, jpi
-            zztmp = zrhoa(ji,jj)  * zU_zu(ji,jj) * Cd(ji,jj)   ! using bulk wind speed
+            zztmp = zrhoa(ji,jj)  * zU_zu(ji,jj) * Cd_atm(ji,jj)   ! using bulk wind speed
             taum  (ji,jj) = zztmp * wndm  (ji,jj)
             zwnd_i(ji,jj) = zztmp * zwnd_i(ji,jj)
@@ -504,11 +502,11 @@
       IF( ABS( rn_zu - rn_zqt) < 0.01_wp ) THEN
          !! q_air and t_air are given at 10m (wind reference height)
-         zevap(:,:) = rn_efac*MAX( 0._wp,             zqla(:,:)*Ce(:,:)*(zsq(:,:) - sf(jp_humi)%fnow(:,:,1)) ) ! Evaporation, using bulk wind speed
-         zqsb (:,:) = cp_air(sf(jp_humi)%fnow(:,:,1))*zqla(:,:)*Ch(:,:)*(zst(:,:) - ztpot(:,:)             )   ! Sensible Heat, using bulk wind speed
+         zevap(:,:) = rn_efac*MAX( 0._wp,             zqla(:,:)*Ce_atm(:,:)*(zsq(:,:) - sf(jp_humi)%fnow(:,:,1)) ) ! Evaporation, using bulk wind speed
+         zqsb (:,:) = cp_air(sf(jp_humi)%fnow(:,:,1))*zqla(:,:)*Ch_atm(:,:)*(zst(:,:) - ztpot(:,:)             )   ! Sensible Heat, using bulk wind speed
       ELSE
          !! q_air and t_air are not given at 10m (wind reference height)
          ! Values of temp. and hum. adjusted to height of wind during bulk algorithm iteration must be used!!!
-         zevap(:,:) = rn_efac*MAX( 0._wp,             zqla(:,:)*Ce(:,:)*(zsq(:,:) - zq_zu(:,:) ) ) ! Evaporation ! using bulk wind speed
-         zqsb (:,:) = cp_air(sf(jp_humi)%fnow(:,:,1))*zqla(:,:)*Ch(:,:)*(zst(:,:) - zt_zu(:,:) )   ! Sensible Heat ! using bulk wind speed
+         zevap(:,:) = rn_efac*MAX( 0._wp,             zqla(:,:)*Ce_atm(:,:)*(zsq(:,:) - q_zu(:,:) ) ) ! Evaporation, using bulk wind speed
+         zqsb (:,:) = cp_air(sf(jp_humi)%fnow(:,:,1))*zqla(:,:)*Ch_atm(:,:)*(zst(:,:) - t_zu(:,:) )   ! Sensible Heat, using bulk wind speed
       ENDIF
 
@@ -517,6 +515,6 @@
 
       IF(ln_ctl) THEN
-         CALL prt_ctl( tab2d_1=zqla  , clinfo1=' blk_oce: zqla   : ', tab2d_2=Ce , clinfo2=' Ce  : ' )
-         CALL prt_ctl( tab2d_1=zqsb  , clinfo1=' blk_oce: zqsb   : ', tab2d_2=Ch , clinfo2=' Ch  : ' )
+         CALL prt_ctl( tab2d_1=zqla  , clinfo1=' blk_oce: zqla   : ', tab2d_2=Ce_atm , clinfo2=' Ce_oce  : ' )
+         CALL prt_ctl( tab2d_1=zqsb  , clinfo1=' blk_oce: zqsb   : ', tab2d_2=Ch_atm , clinfo2=' Ch_oce  : ' )
          CALL prt_ctl( tab2d_1=zqlw  , clinfo1=' blk_oce: zqlw   : ', tab2d_2=qsr, clinfo2=' qsr : ' )
          CALL prt_ctl( tab2d_1=zsq   , clinfo1=' blk_oce: zsq    : ', tab2d_2=zst, clinfo2=' zst : ' )
@@ -557,6 +555,6 @@
          tprecip(:,:) = sf(jp_prec)%fnow(:,:,1) * rn_pfac   ! output total precipitation [kg/m2/s]
          sprecip(:,:) = sf(jp_snow)%fnow(:,:,1) * rn_pfac   ! output solid precipitation [kg/m2/s]
-         CALL iom_put( 'snowpre', sprecip * 86400. )        ! Snow
-         CALL iom_put( 'precip' , tprecip * 86400. )        ! Total precipitation
+         CALL iom_put( 'snowpre', sprecip )                 ! Snow
+         CALL iom_put( 'precip' , tprecip )                 ! Total precipitation
       ENDIF
       !
@@ -569,13 +567,137 @@
       ENDIF
       !
-      CALL wrk_dealloc( jpi,jpj,   zwnd_i, zwnd_j, zsq, zqlw, zqsb, zqla, zevap )
-      CALL wrk_dealloc( jpi,jpj,   Cd, Ch, Ce, zst, zt_zu, zq_zu )
-      CALL wrk_dealloc( jpi,jpj,   zU_zu, ztpot, zrhoa )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('blk_oce')
+      IF( ln_timing )   CALL timing_stop('blk_oce')
       !
    END SUBROUTINE blk_oce
 
-#if defined key_lim2 || defined key_lim3
+
+
+   FUNCTION rho_air( ptak, pqa, pslp )
+      !!-------------------------------------------------------------------------------
+      !!                           ***  FUNCTION rho_air  ***
+      !!
+      !! ** Purpose : compute density of (moist) air using the eq. of state of the atmosphere
+      !!
+      !! ** Author: L. Brodeau, june 2016 / AeroBulk (https://sourceforge.net/p/aerobulk) 
+      !!-------------------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   ptak      ! air temperature             [K]
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pqa       ! air specific humidity   [kg/kg]
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pslp      ! pressure in                [Pa]
+      REAL(wp), DIMENSION(jpi,jpj)             ::   rho_air   ! density of moist air   [kg/m^3]
+      !!-------------------------------------------------------------------------------
+      !
+      rho_air = pslp / (  R_dry*ptak * ( 1._wp + rctv0*pqa )  )
+      !
+   END FUNCTION rho_air
+
+
+   FUNCTION cp_air( pqa )
+      !!-------------------------------------------------------------------------------
+      !!                           ***  FUNCTION cp_air  ***
+      !!
+      !! ** Purpose : Compute specific heat (Cp) of moist air
+      !!
+      !! ** Author: L. Brodeau, june 2016 / AeroBulk (https://sourceforge.net/p/aerobulk)
+      !!-------------------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pqa      ! air specific humidity         [kg/kg]
+      REAL(wp), DIMENSION(jpi,jpj)             ::   cp_air   ! specific heat of moist air   [J/K/kg]
+      !!-------------------------------------------------------------------------------
+      !
+      Cp_air = Cp_dry + Cp_vap * pqa
+      !
+   END FUNCTION cp_air
+
+
+   FUNCTION q_sat( ptak, pslp )
+      !!----------------------------------------------------------------------------------
+      !!                           ***  FUNCTION q_sat  ***
+      !!
+      !! ** Purpose : Specific humidity at saturation in [kg/kg]
+      !!              Based on accurate estimate of "e_sat"
+      !!              aka saturation water vapor (Goff, 1957)
+      !!
+      !! ** Author: L. Brodeau, june 2016 / AeroBulk (https://sourceforge.net/p/aerobulk)
+      !!----------------------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   ptak    ! air temperature                       [K]
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pslp    ! sea level atmospheric pressure       [Pa]
+      REAL(wp), DIMENSION(jpi,jpj)             ::   q_sat   ! Specific humidity at saturation   [kg/kg]
+      !
+      INTEGER  ::   ji, jj         ! dummy loop indices
+      REAL(wp) ::   ze_sat, ztmp   ! local scalar
+      !!----------------------------------------------------------------------------------
+      !
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            !
+            ztmp = rt0 / ptak(ji,jj)
+            !
+            ! Vapour pressure at saturation [hPa] : WMO, (Goff, 1957)
+            ze_sat = 10.**( 10.79574*(1. - ztmp) - 5.028*LOG10(ptak(ji,jj)/rt0)        &
+               &    + 1.50475*10.**(-4)*(1. - 10.**(-8.2969*(ptak(ji,jj)/rt0 - 1.)) )  &
+               &    + 0.42873*10.**(-3)*(10.**(4.76955*(1. - ztmp)) - 1.) + 0.78614  )
+               !
+            q_sat(ji,jj) = reps0 * ze_sat/( 0.01_wp*pslp(ji,jj) - (1._wp - reps0)*ze_sat )   ! 0.01 because SLP is in [Pa]
+            !
+         END DO
+      END DO
+      !
+   END FUNCTION q_sat
+
+
+   FUNCTION gamma_moist( ptak, pqa )
+      !!----------------------------------------------------------------------------------
+      !!                           ***  FUNCTION gamma_moist  ***
+      !!
+      !! ** Purpose : Compute the moist adiabatic lapse-rate.
+      !!     => http://glossary.ametsoc.org/wiki/Moist-adiabatic_lapse_rate
+      !!     => http://www.geog.ucsb.edu/~joel/g266_s10/lecture_notes/chapt03/oh10_3_01/oh10_3_01.html
+      !!
+      !! ** Author: L. Brodeau, june 2016 / AeroBulk (https://sourceforge.net/p/aerobulk)
+      !!----------------------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   ptak          ! air temperature       [K]
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pqa           ! specific humidity [kg/kg]
+      REAL(wp), DIMENSION(jpi,jpj)             ::   gamma_moist   ! moist adiabatic lapse-rate
+      !
+      INTEGER  ::   ji, jj         ! dummy loop indices
+      REAL(wp) :: zrv, ziRT        ! local scalar
+      !!----------------------------------------------------------------------------------
+      !
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            zrv = pqa(ji,jj) / (1. - pqa(ji,jj))
+            ziRT = 1. / (R_dry*ptak(ji,jj))    ! 1/RT
+            gamma_moist(ji,jj) = grav * ( 1. + cevap*zrv*ziRT ) / ( Cp_dry + cevap*cevap*zrv*reps0*ziRT/ptak(ji,jj) )
+         END DO
+      END DO
+      !
+   END FUNCTION gamma_moist
+
+
+   FUNCTION L_vap( psst )
+      !!---------------------------------------------------------------------------------
+      !!                           ***  FUNCTION L_vap  ***
+      !!
+      !! ** Purpose : Compute the latent heat of vaporization of water from temperature
+      !!
+      !! ** Author: L. Brodeau, june 2016 / AeroBulk (https://sourceforge.net/p/aerobulk)
+      !!----------------------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj)             ::   L_vap   ! latent heat of vaporization   [J/kg]
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   psst   ! water temperature                [K]
+      !!----------------------------------------------------------------------------------
+      !
+      L_vap = (  2.501 - 0.00237 * ( psst(:,:) - rt0)  ) * 1.e6
+      !
+   END FUNCTION L_vap
+
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       ESIM sea-ice model
+   !!----------------------------------------------------------------------
+   !!   blk_ice_tau : provide the air-ice stress
+   !!   blk_ice_flx : provide the heat and mass fluxes at air-ice interface
+   !!   blk_ice_qcn : provide ice surface temperature and snow/ice conduction flux (emulating JULES coupler)
+   !!   Cdn10_Lupkes2012 : Lupkes et al. (2012) air-ice drag
+   !!   Cdn10_Lupkes2015 : Lupkes et al. (2015) air-ice drag 
+   !!----------------------------------------------------------------------
 
    SUBROUTINE blk_ice_tau
@@ -590,29 +712,61 @@
       !!---------------------------------------------------------------------
       INTEGER  ::   ji, jj    ! dummy loop indices
-      !
-      REAL(wp), DIMENSION(:,:)  , POINTER :: zrhoa
-      !
-      REAL(wp) ::   zwnorm_f, zwndi_f , zwndj_f               ! relative wind module and components at F-point
-      REAL(wp) ::             zwndi_t , zwndj_t               ! relative wind components at T-point
-      REAL(wp), DIMENSION(:,:), POINTER ::   Cd               ! transfer coefficient for momentum      (tau)
-      !!---------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('blk_ice_tau')
-      !
-      CALL wrk_alloc( jpi,jpj, zrhoa )
-      CALL wrk_alloc( jpi,jpj, Cd )
-
-      Cd(:,:) = Cd_ice
-
-      ! Make ice-atm. drag dependent on ice concentration (see Lupkes et al. 2012) (clem)
-#if defined key_lim3
-      IF( ln_Cd_L12 ) THEN
-         CALL Cdn10_Lupkes2012( Cd ) ! calculate new drag from Lupkes(2012) equations
+      REAL(wp) ::   zwndi_f , zwndj_f, zwnorm_f   ! relative wind module and components at F-point
+      REAL(wp) ::   zwndi_t , zwndj_t             ! relative wind components at T-point
+      REAL(wp), DIMENSION(jpi,jpj) ::   zrhoa     ! transfer coefficient for momentum      (tau)
+      !!---------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('blk_ice_tau')
+      !
+      ! set transfer coefficients to default sea-ice values
+      Cd_atm(:,:) = Cd_ice
+      Ch_atm(:,:) = Cd_ice
+      Ce_atm(:,:) = Cd_ice
+
+      wndm_ice(:,:) = 0._wp      !!gm brutal....
+
+      ! ------------------------------------------------------------ !
+      !    Wind module relative to the moving ice ( U10m - U_ice )   !
+      ! ------------------------------------------------------------ !
+      SELECT CASE( cp_ice_msh )
+      CASE( 'I' )                  ! B-grid ice dynamics :   I-point (i.e. F-point with sea-ice indexation)
+         !                           and scalar wind at T-point ( = | U10m - U_ice | ) (masked)
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1   ! B grid : NO vector opt
+               ! ... scalar wind at T-point (fld being at T-point)
+               zwndi_t = sf(jp_wndi)%fnow(ji,jj,1) - rn_vfac * 0.25 * (  u_ice(ji,jj+1) + u_ice(ji+1,jj+1)   &
+                  &                                                    + u_ice(ji,jj  ) + u_ice(ji+1,jj  )  )
+               zwndj_t = sf(jp_wndj)%fnow(ji,jj,1) - rn_vfac * 0.25 * (  v_ice(ji,jj+1) + v_ice(ji+1,jj+1)   &
+                  &                                                    + v_ice(ji,jj  ) + v_ice(ji+1,jj  )  )
+               wndm_ice(ji,jj) = SQRT( zwndi_t * zwndi_t + zwndj_t * zwndj_t ) * tmask(ji,jj,1)
+            END DO
+         END DO
+         CALL lbc_lnk( wndm_ice, 'T',  1. )
+         !
+      CASE( 'C' )                  ! C-grid ice dynamics :   U & V-points (same as ocean)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vect. opt.
+               zwndi_t = (  sf(jp_wndi)%fnow(ji,jj,1) - rn_vfac * 0.5 * ( u_ice(ji-1,jj  ) + u_ice(ji,jj) )  )
+               zwndj_t = (  sf(jp_wndj)%fnow(ji,jj,1) - rn_vfac * 0.5 * ( v_ice(ji  ,jj-1) + v_ice(ji,jj) )  )
+               wndm_ice(ji,jj) = SQRT( zwndi_t * zwndi_t + zwndj_t * zwndj_t ) * tmask(ji,jj,1)
+            END DO
+         END DO
+         CALL lbc_lnk( wndm_ice, 'T',  1. )
+         !
+      END SELECT
+
+      ! Make ice-atm. drag dependent on ice concentration
+      IF    ( ln_Cd_L12 ) THEN   ! calculate new drag from Lupkes(2012) equations
+         CALL Cdn10_Lupkes2012( Cd_atm )
+         Ch_atm(:,:) = Cd_atm(:,:)       ! momentum and heat transfer coef. are considered identical
+      ELSEIF( ln_Cd_L15 ) THEN   ! calculate new drag from Lupkes(2015) equations
+         CALL Cdn10_Lupkes2015( Cd_atm, Ch_atm ) 
       ENDIF
-#endif
+
+!!      CALL iom_put( "Cd_ice", Cd_atm)  ! output value of pure ice-atm. transfer coef.
+!!      CALL iom_put( "Ch_ice", Ch_atm)  ! output value of pure ice-atm. transfer coef.
 
       ! local scalars ( place there for vector optimisation purposes)
       ! Computing density of air! Way denser that 1.2 over sea-ice !!!
-      !!
       zrhoa (:,:) =  rho_air(sf(jp_tair)%fnow(:,:,1), sf(jp_humi)%fnow(:,:,1), sf(jp_slp)%fnow(:,:,1))
 
@@ -620,13 +774,11 @@
       utau_ice  (:,:) = 0._wp
       vtau_ice  (:,:) = 0._wp
-      wndm_ice  (:,:) = 0._wp
       !!gm end
 
-      ! ----------------------------------------------------------------------------- !
-      !    Wind components and module relative to the moving ocean ( U10m - U_ice )   !
-      ! ----------------------------------------------------------------------------- !
+      ! ------------------------------------------------------------ !
+      !    Wind stress relative to the moving ice ( U10m - U_ice )   !
+      ! ------------------------------------------------------------ !
       SELECT CASE( cp_ice_msh )
       CASE( 'I' )                  ! B-grid ice dynamics :   I-point (i.e. F-point with sea-ice indexation)
-         !                           and scalar wind at T-point ( = | U10m - U_ice | ) (masked)
          DO jj = 2, jpjm1
             DO ji = 2, jpim1   ! B grid : NO vector opt
@@ -636,33 +788,19 @@
                zwndj_f = 0.25 * (  sf(jp_wndj)%fnow(ji-1,jj  ,1) + sf(jp_wndj)%fnow(ji  ,jj  ,1)   &
                   &              + sf(jp_wndj)%fnow(ji-1,jj-1,1) + sf(jp_wndj)%fnow(ji  ,jj-1,1)  ) - rn_vfac * v_ice(ji,jj)
-               zwnorm_f = zrhoa(ji,jj) * Cd(ji,jj) * SQRT( zwndi_f * zwndi_f + zwndj_f * zwndj_f )
                ! ... ice stress at I-point
+               zwnorm_f = zrhoa(ji,jj) * Cd_atm(ji,jj) * SQRT( zwndi_f * zwndi_f + zwndj_f * zwndj_f )
                utau_ice(ji,jj) = zwnorm_f * zwndi_f
                vtau_ice(ji,jj) = zwnorm_f * zwndj_f
-               ! ... scalar wind at T-point (fld being at T-point)
-               zwndi_t = sf(jp_wndi)%fnow(ji,jj,1) - rn_vfac * 0.25 * (  u_ice(ji,jj+1) + u_ice(ji+1,jj+1)   &
-                  &                                                    + u_ice(ji,jj  ) + u_ice(ji+1,jj  )  )
-               zwndj_t = sf(jp_wndj)%fnow(ji,jj,1) - rn_vfac * 0.25 * (  v_ice(ji,jj+1) + v_ice(ji+1,jj+1)   &
-                  &                                                    + v_ice(ji,jj  ) + v_ice(ji+1,jj  )  )
-               wndm_ice(ji,jj) = SQRT( zwndi_t * zwndi_t + zwndj_t * zwndj_t ) * tmask(ji,jj,1)
             END DO
          END DO
          CALL lbc_lnk( utau_ice, 'I', -1. )
          CALL lbc_lnk( vtau_ice, 'I', -1. )
-         CALL lbc_lnk( wndm_ice, 'T',  1. )
          !
       CASE( 'C' )                  ! C-grid ice dynamics :   U & V-points (same as ocean)
-         DO jj = 2, jpj
-            DO ji = fs_2, jpi   ! vect. opt.
-               zwndi_t = (  sf(jp_wndi)%fnow(ji,jj,1) - rn_vfac * 0.5 * ( u_ice(ji-1,jj  ) + u_ice(ji,jj) )  )
-               zwndj_t = (  sf(jp_wndj)%fnow(ji,jj,1) - rn_vfac * 0.5 * ( v_ice(ji  ,jj-1) + v_ice(ji,jj) )  )
-               wndm_ice(ji,jj) = SQRT( zwndi_t * zwndi_t + zwndj_t * zwndj_t ) * tmask(ji,jj,1)
-            END DO
-         END DO
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vect. opt.
-               utau_ice(ji,jj) = 0.5 * zrhoa(ji,jj) * Cd(ji,jj) * ( wndm_ice(ji+1,jj  ) + wndm_ice(ji,jj) )                          &
+               utau_ice(ji,jj) = 0.5 * zrhoa(ji,jj) * Cd_atm(ji,jj) * ( wndm_ice(ji+1,jj  ) + wndm_ice(ji,jj) )            &
                   &          * ( 0.5 * (sf(jp_wndi)%fnow(ji+1,jj,1) + sf(jp_wndi)%fnow(ji,jj,1) ) - rn_vfac * u_ice(ji,jj) )
-               vtau_ice(ji,jj) = 0.5 * zrhoa(ji,jj) * Cd(ji,jj) * ( wndm_ice(ji,jj+1  ) + wndm_ice(ji,jj) )                          &
+               vtau_ice(ji,jj) = 0.5 * zrhoa(ji,jj) * Cd_atm(ji,jj) * ( wndm_ice(ji,jj+1  ) + wndm_ice(ji,jj) )            &
                   &          * ( 0.5 * (sf(jp_wndj)%fnow(ji,jj+1,1) + sf(jp_wndj)%fnow(ji,jj,1) ) - rn_vfac * v_ice(ji,jj) )
             END DO
@@ -670,23 +808,22 @@
          CALL lbc_lnk( utau_ice, 'U', -1. )
          CALL lbc_lnk( vtau_ice, 'V', -1. )
-         CALL lbc_lnk( wndm_ice, 'T',  1. )
          !
       END SELECT
-
+      !
       IF(ln_ctl) THEN
          CALL prt_ctl(tab2d_1=utau_ice  , clinfo1=' blk_ice: utau_ice : ', tab2d_2=vtau_ice  , clinfo2=' vtau_ice : ')
          CALL prt_ctl(tab2d_1=wndm_ice  , clinfo1=' blk_ice: wndm_ice : ')
       ENDIF
-
-      IF( nn_timing == 1 )  CALL timing_stop('blk_ice_tau')
-
+      !
+      IF( ln_timing )   CALL timing_stop('blk_ice_tau')
+      !
    END SUBROUTINE blk_ice_tau
 
 
-   SUBROUTINE blk_ice_flx( ptsu, palb )
+   SUBROUTINE blk_ice_flx( ptsu, phs, phi, palb )
       !!---------------------------------------------------------------------
       !!                     ***  ROUTINE blk_ice_flx  ***
       !!
-      !! ** Purpose :   provide the surface boundary condition over sea-ice
+      !! ** Purpose :   provide the heat and mass fluxes at air-ice interface
       !!
       !! ** Method  :   compute heat and freshwater exchanged
@@ -697,4 +834,6 @@
       !!---------------------------------------------------------------------
       REAL(wp), DIMENSION(:,:,:), INTENT(in)  ::   ptsu   ! sea ice surface temperature
+      REAL(wp), DIMENSION(:,:,:), INTENT(in)  ::   phs    ! snow thickness
+      REAL(wp), DIMENSION(:,:,:), INTENT(in)  ::   phi    ! ice thickness
       REAL(wp), DIMENSION(:,:,:), INTENT(in)  ::   palb   ! ice albedo (all skies)
       !!
@@ -703,32 +842,17 @@
       REAL(wp) ::   zcoef_dqlw, zcoef_dqla   !   -      -
       REAL(wp) ::   zztmp, z1_lsub           !   -      -
-      REAL(wp), DIMENSION(:,:,:), POINTER ::   z_qlw         ! long wave heat flux over ice
-      REAL(wp), DIMENSION(:,:,:), POINTER ::   z_qsb         ! sensible  heat flux over ice
-      REAL(wp), DIMENSION(:,:,:), POINTER ::   z_dqlw        ! long wave heat sensitivity over ice
-      REAL(wp), DIMENSION(:,:,:), POINTER ::   z_dqsb        ! sensible  heat sensitivity over ice
-      REAL(wp), DIMENSION(:,:)  , POINTER ::   zevap, zsnw   ! evaporation and snw distribution after wind blowing (LIM3)
-      REAL(wp), DIMENSION(:,:)  , POINTER ::   zrhoa
-      REAL(wp), DIMENSION(:,:)  , POINTER ::   Cd            ! transfer coefficient for momentum      (tau)
-      !!---------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('blk_ice_flx')
-      !
-      CALL wrk_alloc( jpi,jpj,jpl,   z_qlw, z_qsb, z_dqlw, z_dqsb )
-      CALL wrk_alloc( jpi,jpj,       zrhoa)
-      CALL wrk_alloc( jpi,jpj, Cd )
-
-      Cd(:,:) = Cd_ice
-
-      ! Make ice-atm. drag dependent on ice concentration (see Lupkes et al.  2012) (clem)
-#if defined key_lim3
-      IF( ln_Cd_L12 ) THEN
-         CALL Cdn10_Lupkes2012( Cd ) ! calculate new drag from Lupkes(2012) equations
-      ENDIF
-#endif
-
-      !
-      ! local scalars ( place there for vector optimisation purposes)
-      zcoef_dqlw   = 4.0 * 0.95 * Stef
-      zcoef_dqla   = -Ls * 11637800. * (-5897.8)
+      REAL(wp) ::   zfr1, zfr2               ! local variables
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z_qlw         ! long wave heat flux over ice
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z_qsb         ! sensible  heat flux over ice
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z_dqlw        ! long wave heat sensitivity over ice
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z_dqsb        ! sensible  heat sensitivity over ice
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zevap, zsnw   ! evaporation and snw distribution after wind blowing (LIM3)
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zrhoa
+      !!---------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('blk_ice_flx')
+      !
+      zcoef_dqlw = 4.0 * 0.95 * Stef             ! local scalars
+      zcoef_dqla = -Ls * 11637800. * (-5897.8)
       !
       zrhoa(:,:) = rho_air( sf(jp_tair)%fnow(:,:,1), sf(jp_humi)%fnow(:,:,1), sf(jp_slp)%fnow(:,:,1) )
@@ -756,13 +880,13 @@
                ! ----------------------------!
 
-               ! ... turbulent heat fluxes
+               ! ... turbulent heat fluxes with Ch_atm recalculated in blk_ice_tau
                ! Sensible Heat
-               z_qsb(ji,jj,jl) = zrhoa(ji,jj) * cpa * Cd(ji,jj) * wndm_ice(ji,jj) * ( ptsu(ji,jj,jl) - sf(jp_tair)%fnow(ji,jj,1) )
+               z_qsb(ji,jj,jl) = zrhoa(ji,jj) * cpa * Ch_atm(ji,jj) * wndm_ice(ji,jj) * (ptsu(ji,jj,jl) - sf(jp_tair)%fnow(ji,jj,1))
                ! Latent Heat
-               qla_ice(ji,jj,jl) = rn_efac * MAX( 0.e0, zrhoa(ji,jj) * Ls  * Cd(ji,jj) * wndm_ice(ji,jj)   &
-                  &                         * (  11637800. * EXP( -5897.8 / ptsu(ji,jj,jl) ) / zrhoa(ji,jj) - sf(jp_humi)%fnow(ji,jj,1)  ) )
+               qla_ice(ji,jj,jl) = rn_efac * MAX( 0.e0, zrhoa(ji,jj) * Ls  * Ch_atm(ji,jj) * wndm_ice(ji,jj) *  &
+                  &                ( 11637800. * EXP( -5897.8 / ptsu(ji,jj,jl) ) / zrhoa(ji,jj) - sf(jp_humi)%fnow(ji,jj,1) ) )
                ! Latent heat sensitivity for ice (Dqla/Dt)
                IF( qla_ice(ji,jj,jl) > 0._wp ) THEN
-                  dqla_ice(ji,jj,jl) = rn_efac * zcoef_dqla * Cd(ji,jj) * wndm_ice(ji,jj) / ( zst2 ) * EXP( -5897.8 / ptsu(ji,jj,jl) )
+                  dqla_ice(ji,jj,jl) = rn_efac * zcoef_dqla * Ch_atm(ji,jj) * wndm_ice(ji,jj) / zst2 * EXP(-5897.8 / ptsu(ji,jj,jl))
                ELSE
                   dqla_ice(ji,jj,jl) = 0._wp
@@ -770,5 +894,5 @@
 
                ! Sensible heat sensitivity (Dqsb_ice/Dtn_ice)
-               z_dqsb(ji,jj,jl) = zrhoa(ji,jj) * cpa * Cd(ji,jj) * wndm_ice(ji,jj)
+               z_dqsb(ji,jj,jl) = zrhoa(ji,jj) * cpa * Ch_atm(ji,jj) * wndm_ice(ji,jj)
 
                ! ----------------------------!
@@ -787,9 +911,6 @@
       tprecip(:,:) = sf(jp_prec)%fnow(:,:,1) * rn_pfac      ! total precipitation [kg/m2/s]
       sprecip(:,:) = sf(jp_snow)%fnow(:,:,1) * rn_pfac      ! solid precipitation [kg/m2/s]
-      CALL iom_put( 'snowpre', sprecip * 86400. )                  ! Snow precipitation
-      CALL iom_put( 'precip' , tprecip * 86400. )                  ! Total precipitation
-
-#if defined  key_lim3
-      CALL wrk_alloc( jpi,jpj,   zevap, zsnw )
+      CALL iom_put( 'snowpre', sprecip )                    ! Snow precipitation
+      CALL iom_put( 'precip' , tprecip )                    ! Total precipitation
 
       ! --- evaporation --- !
@@ -801,11 +922,11 @@
       ! --- evaporation minus precipitation --- !
       zsnw(:,:) = 0._wp
-      CALL lim_thd_snwblow( pfrld, zsnw )  ! snow distribution over ice after wind blowing
-      emp_oce(:,:) = pfrld(:,:) * zevap(:,:) - ( tprecip(:,:) - sprecip(:,:) ) - sprecip(:,:) * (1._wp - zsnw )
+      CALL ice_thd_snwblow( (1.-at_i_b(:,:)), zsnw )  ! snow distribution over ice after wind blowing
+      emp_oce(:,:) = ( 1._wp - at_i_b(:,:) ) * zevap(:,:) - ( tprecip(:,:) - sprecip(:,:) ) - sprecip(:,:) * (1._wp - zsnw )
       emp_ice(:,:) = SUM( a_i_b(:,:,:) * evap_ice(:,:,:), dim=3 ) - sprecip(:,:) * zsnw
       emp_tot(:,:) = emp_oce(:,:) + emp_ice(:,:)
 
       ! --- heat flux associated with emp --- !
-      qemp_oce(:,:) = - pfrld(:,:) * zevap(:,:) * sst_m(:,:) * rcp                               & ! evap at sst
+      qemp_oce(:,:) = - ( 1._wp - at_i_b(:,:) ) * zevap(:,:) * sst_m(:,:) * rcp                  & ! evap at sst
          &          + ( tprecip(:,:) - sprecip(:,:) ) * ( sf(jp_tair)%fnow(:,:,1) - rt0 ) * rcp  & ! liquid precip at Tair
          &          +   sprecip(:,:) * ( 1._wp - zsnw ) *                                        & ! solid precip at min(Tair,Tsnow)
@@ -815,6 +936,7 @@
 
       ! --- total solar and non solar fluxes --- !
-      qns_tot(:,:) = pfrld(:,:) * qns_oce(:,:) + SUM( a_i_b(:,:,:) * qns_ice(:,:,:), dim=3 ) + qemp_ice(:,:) + qemp_oce(:,:)
-      qsr_tot(:,:) = pfrld(:,:) * qsr_oce(:,:) + SUM( a_i_b(:,:,:) * qsr_ice(:,:,:), dim=3 )
+      qns_tot(:,:) = ( 1._wp - at_i_b(:,:) ) * qns_oce(:,:) + SUM( a_i_b(:,:,:) * qns_ice(:,:,:), dim=3 )  &
+         &           + qemp_ice(:,:) + qemp_oce(:,:)
+      qsr_tot(:,:) = ( 1._wp - at_i_b(:,:) ) * qsr_oce(:,:) + SUM( a_i_b(:,:,:) * qsr_ice(:,:,:), dim=3 )
 
       ! --- heat content of precip over ice in J/m3 (to be used in 1D-thermo) --- !
@@ -824,18 +946,18 @@
       DO jl = 1, jpl
          qevap_ice(:,:,jl) = 0._wp ! should be -evap_ice(:,:,jl)*( ( Tice - rt0 ) * cpic * tmask(:,:,1) )
-                                   ! But we do not have Tice => consider it at 0degC => evap=0 
+         !                         ! But we do not have Tice => consider it at 0degC => evap=0 
       END DO
 
-      CALL wrk_dealloc( jpi,jpj,   zevap, zsnw )
-#endif
-
-      !--------------------------------------------------------------------
-      ! FRACTIONs of net shortwave radiation which is not absorbed in the
-      ! thin surface layer and penetrates inside the ice cover
-      ! ( Maykut and Untersteiner, 1971 ; Ebert and Curry, 1993 )
-      !
-      fr1_i0(:,:) = ( 0.18 * ( 1.0 - cldf_ice ) + 0.35 * cldf_ice )
-      fr2_i0(:,:) = ( 0.82 * ( 1.0 - cldf_ice ) + 0.65 * cldf_ice )
-      !
+      ! --- shortwave radiation transmitted below the surface (W/m2, see Grenfell Maykut 77) --- !
+      zfr1 = ( 0.18 * ( 1.0 - cldf_ice ) + 0.35 * cldf_ice )            ! transmission when hi>10cm
+      zfr2 = ( 0.82 * ( 1.0 - cldf_ice ) + 0.65 * cldf_ice )            ! zfr2 such that zfr1 + zfr2 to equal 1
+      !
+      WHERE    ( phs(:,:,:) <= 0._wp .AND. phi(:,:,:) <  0.1_wp )       ! linear decrease from hi=0 to 10cm  
+         qsr_ice_tr(:,:,:) = qsr_ice(:,:,:) * ( zfr1 + zfr2 * ( 1._wp - phi(:,:,:) * 10._wp ) )
+      ELSEWHERE( phs(:,:,:) <= 0._wp .AND. phi(:,:,:) >= 0.1_wp )       ! constant (zfr1) when hi>10cm
+         qsr_ice_tr(:,:,:) = qsr_ice(:,:,:) * zfr1
+      ELSEWHERE                                                         ! zero when hs>0
+         qsr_ice_tr(:,:,:) = 0._wp 
+      END WHERE
       !
       IF(ln_ctl) THEN
@@ -847,140 +969,116 @@
          CALL prt_ctl(tab2d_1=tprecip , clinfo1=' blk_ice: tprecip  : ', tab2d_2=sprecip , clinfo2=' sprecip  : ')
       ENDIF
-
-      CALL wrk_dealloc( jpi,jpj,jpl,   z_qlw, z_qsb, z_dqlw, z_dqsb )
-      CALL wrk_dealloc( jpi,jpj,       zrhoa )
-      CALL wrk_dealloc( jpi,jpj, Cd )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('blk_ice_flx')
-
+      !
+      IF( ln_timing )   CALL timing_stop('blk_ice_flx')
+      !
    END SUBROUTINE blk_ice_flx
    
-#endif
-
-   FUNCTION rho_air( ptak, pqa, pslp )
-      !!-------------------------------------------------------------------------------
-      !!                           ***  FUNCTION rho_air  ***
-      !!
-      !! ** Purpose : compute density of (moist) air using the eq. of state of the atmosphere
-      !!
-      !! ** Author: L. Brodeau, june 2016 / AeroBulk (https://sourceforge.net/p/aerobulk) 
-      !!-------------------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   ptak      ! air temperature             [K]
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pqa       ! air specific humidity   [kg/kg]
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pslp      ! pressure in                [Pa]
-      REAL(wp), DIMENSION(jpi,jpj)             ::   rho_air   ! density of moist air   [kg/m^3]
-      !!-------------------------------------------------------------------------------
-      !
-      rho_air = pslp / (  R_dry*ptak * ( 1._wp + rctv0*pqa )  )
-      !
-   END FUNCTION rho_air
-
-
-   FUNCTION cp_air( pqa )
-      !!-------------------------------------------------------------------------------
-      !!                           ***  FUNCTION cp_air  ***
-      !!
-      !! ** Purpose : Compute specific heat (Cp) of moist air
-      !!
-      !! ** Author: L. Brodeau, june 2016 / AeroBulk (https://sourceforge.net/p/aerobulk)
-      !!-------------------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pqa      ! air specific humidity         [kg/kg]
-      REAL(wp), DIMENSION(jpi,jpj)             ::   cp_air   ! specific heat of moist air   [J/K/kg]
-      !!-------------------------------------------------------------------------------
-      !
-      Cp_air = Cp_dry + Cp_vap * pqa
-      !
-   END FUNCTION cp_air
-
-
-   FUNCTION q_sat( ptak, pslp )
-      !!----------------------------------------------------------------------------------
-      !!                           ***  FUNCTION q_sat  ***
-      !!
-      !! ** Purpose : Specific humidity at saturation in [kg/kg]
-      !!              Based on accurate estimate of "e_sat"
-      !!              aka saturation water vapor (Goff, 1957)
-      !!
-      !! ** Author: L. Brodeau, june 2016 / AeroBulk (https://sourceforge.net/p/aerobulk)
-      !!----------------------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   ptak    ! air temperature                       [K]
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pslp    ! sea level atmospheric pressure       [Pa]
-      REAL(wp), DIMENSION(jpi,jpj)             ::   q_sat   ! Specific humidity at saturation   [kg/kg]
-      !
-      INTEGER  ::   ji, jj         ! dummy loop indices
-      REAL(wp) ::   ze_sat, ztmp   ! local scalar
-      !!----------------------------------------------------------------------------------
-      !
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            !
-            ztmp = rt0 / ptak(ji,jj)
-            !
-            ! Vapour pressure at saturation [hPa] : WMO, (Goff, 1957)
-            ze_sat = 10.**( 10.79574*(1. - ztmp) - 5.028*LOG10(ptak(ji,jj)/rt0)        &
-               &    + 1.50475*10.**(-4)*(1. - 10.**(-8.2969*(ptak(ji,jj)/rt0 - 1.)) )  &
-               &    + 0.42873*10.**(-3)*(10.**(4.76955*(1. - ztmp)) - 1.) + 0.78614  )
+
+   SUBROUTINE blk_ice_qcn( k_monocat, ptsu, ptb, phs, phi )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE blk_ice_qcn  ***
+      !!
+      !! ** Purpose :   Compute surface temperature and snow/ice conduction flux
+      !!                to force sea ice / snow thermodynamics
+      !!                in the case JULES coupler is emulated
+      !!                
+      !! ** Method  :   compute surface energy balance assuming neglecting heat storage
+      !!                following the 0-layer Semtner (1976) approach
+      !!
+      !! ** Outputs : - ptsu    : sea-ice / snow surface temperature (K)
+      !!              - qcn_ice : surface inner conduction flux (W/m2)
+      !!
+      !!---------------------------------------------------------------------
+      INTEGER                   , INTENT(in   ) ::   k_monocat   ! single-category option
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptsu        ! sea ice / snow surface temperature
+      REAL(wp), DIMENSION(:,:)  , INTENT(in   ) ::   ptb         ! sea ice base temperature
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   phs         ! snow thickness
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   phi         ! sea ice thickness
+      !
+      INTEGER , PARAMETER ::   nit = 10                  ! number of iterations
+      REAL(wp), PARAMETER ::   zepsilon = 0.1_wp         ! characteristic thickness for enhanced conduction
+      !
+      INTEGER  ::   ji, jj, jl           ! dummy loop indices
+      INTEGER  ::   iter                 ! local integer
+      REAL(wp) ::   zfac, zfac2, zfac3   ! local scalars
+      REAL(wp) ::   zkeff_h, ztsu, ztsu0 !
+      REAL(wp) ::   zqc, zqnet           !
+      REAL(wp) ::   zhe, zqa0            !
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zgfac   ! enhanced conduction factor
+      !!---------------------------------------------------------------------
+
+      IF( ln_timing )  CALL timing_start('blk_ice_qcn')
+      
+      ! -------------------------------------!
+      !      I   Enhanced conduction factor  !
+      ! -------------------------------------!
+      ! Emulates the enhancement of conduction by unresolved thin ice (k_monocat = 1/3)
+      ! Fichefet and Morales Maqueda, JGR 1997
+      !
+      zgfac(:,:,:) = 1._wp
+      
+      SELECT CASE ( k_monocat ) 
+      !
+      CASE ( 1 , 3 )
+         !
+         zfac  = 1._wp /  ( rn_cnd_s + rcdic )
+         zfac2 = EXP(1._wp) * 0.5_wp * zepsilon
+         zfac3 = 2._wp / zepsilon
+         !   
+         DO jl = 1, jpl                
+            DO jj = 1 , jpj
+               DO ji = 1, jpi
+                  zhe = ( rn_cnd_s * phi(ji,jj,jl) + rcdic * phs(ji,jj,jl) ) * zfac                             ! Effective thickness
+                  IF( zhe >=  zfac2 )   zgfac(ji,jj,jl) = MIN( 2._wp, 0.5_wp * ( 1._wp + LOG( zhe * zfac3 ) ) ) ! Enhanced conduction factor
+               END DO
+            END DO
+         END DO
+         !      
+      END SELECT
+      
+      ! -------------------------------------------------------------!
+      !      II   Surface temperature and conduction flux            !
+      ! -------------------------------------------------------------!
+      !
+      zfac = rcdic * rn_cnd_s
+      !
+      DO jl = 1, jpl
+         DO jj = 1 , jpj
+            DO ji = 1, jpi
+               !                    
+               zkeff_h = zfac * zgfac(ji,jj,jl) / &                                    ! Effective conductivity of the snow-ice system divided by thickness
+                  &      ( rcdic * phs(ji,jj,jl) + rn_cnd_s * MAX( 0.01, phi(ji,jj,jl) ) )
+               ztsu    = ptsu(ji,jj,jl)                                                ! Store current iteration temperature
+               ztsu0   = ptsu(ji,jj,jl)                                                ! Store initial surface temperature
+               zqa0    = qsr_ice(ji,jj,jl) - qsr_ice_tr(ji,jj,jl) + qns_ice(ji,jj,jl)  ! Net initial atmospheric heat flux
                !
-            q_sat(ji,jj) = reps0 * ze_sat/( 0.01_wp*pslp(ji,jj) - (1._wp - reps0)*ze_sat )   ! 0.01 because SLP is in [Pa]
-            !
-         END DO
-      END DO
-      !
-   END FUNCTION q_sat
-
-
-   FUNCTION gamma_moist( ptak, pqa )
-      !!----------------------------------------------------------------------------------
-      !!                           ***  FUNCTION gamma_moist  ***
-      !!
-      !! ** Purpose : Compute the moist adiabatic lapse-rate.
-      !!     => http://glossary.ametsoc.org/wiki/Moist-adiabatic_lapse_rate
-      !!     => http://www.geog.ucsb.edu/~joel/g266_s10/lecture_notes/chapt03/oh10_3_01/oh10_3_01.html
-      !!
-      !! ** Author: L. Brodeau, june 2016 / AeroBulk (https://sourceforge.net/p/aerobulk)
-      !!----------------------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   ptak          ! air temperature       [K]
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   pqa           ! specific humidity [kg/kg]
-      REAL(wp), DIMENSION(jpi,jpj)             ::   gamma_moist   ! moist adiabatic lapse-rate
-      !
-      INTEGER  ::   ji, jj         ! dummy loop indices
-      REAL(wp) :: zrv, ziRT        ! local scalar
-      !!----------------------------------------------------------------------------------
-      !
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            zrv = pqa(ji,jj) / (1. - pqa(ji,jj))
-            ziRT = 1. / (R_dry*ptak(ji,jj))    ! 1/RT
-            gamma_moist(ji,jj) = grav * ( 1. + cevap*zrv*ziRT ) / ( Cp_dry + cevap*cevap*zrv*reps0*ziRT/ptak(ji,jj) )
-         END DO
-      END DO
-      !
-   END FUNCTION gamma_moist
-
-
-   FUNCTION L_vap( psst )
-      !!---------------------------------------------------------------------------------
-      !!                           ***  FUNCTION L_vap  ***
-      !!
-      !! ** Purpose : Compute the latent heat of vaporization of water from temperature
-      !!
-      !! ** Author: L. Brodeau, june 2016 / AeroBulk (https://sourceforge.net/p/aerobulk)
-      !!----------------------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj)             ::   L_vap   ! latent heat of vaporization   [J/kg]
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in) ::   psst   ! water temperature                [K]
-      !!----------------------------------------------------------------------------------
-      !
-      L_vap = (  2.501 - 0.00237 * ( psst(:,:) - rt0)  ) * 1.e6
-      !
-   END FUNCTION L_vap
-
-
-#if defined key_lim3
+               DO iter = 1, nit     ! --- Iterative loop
+                  zqc   = zkeff_h * ( ztsu - ptb(ji,jj) )                              ! Conduction heat flux through snow-ice system (>0 downwards)
+                  zqnet = zqa0 + dqns_ice(ji,jj,jl) * ( ztsu - ptsu(ji,jj,jl) ) - zqc  ! Surface energy budget
+                  ztsu  = ztsu - zqnet / ( dqns_ice(ji,jj,jl) - zkeff_h )              ! Temperature update
+               END DO
+               !
+               ptsu   (ji,jj,jl) = MIN( rt0, ztsu )
+               qcn_ice(ji,jj,jl) = zkeff_h * ( ptsu(ji,jj,jl) - ptb(ji,jj) )
+               qns_ice(ji,jj,jl) = qns_ice(ji,jj,jl) + dqns_ice(ji,jj,jl) * ( ptsu(ji,jj,jl) - ztsu0 )
+               qml_ice(ji,jj,jl) = ( qsr_ice(ji,jj,jl) - qsr_ice_tr(ji,jj,jl) + qns_ice(ji,jj,jl) - qcn_ice(ji,jj,jl) )   &
+                             &   * MAX( 0._wp , SIGN( 1._wp, ptsu(ji,jj,jl) - rt0 ) )
+
+            END DO
+         END DO
+         !
+      END DO 
+      !      
+      IF( ln_timing )  CALL timing_stop('blk_ice_qcn')
+      !
+   END SUBROUTINE blk_ice_qcn
+   
+
    SUBROUTINE Cdn10_Lupkes2012( Cd )
       !!----------------------------------------------------------------------
       !!                      ***  ROUTINE  Cdn10_Lupkes2012  ***
       !!
-      !! ** Purpose :    Recompute the ice-atm drag at 10m height to make
-      !!                 it dependent on edges at leads, melt ponds and flows.
+      !! ** Purpose :    Recompute the neutral air-ice drag referenced at 10m 
+      !!                 to make it dependent on edges at leads, melt ponds and flows.
       !!                 After some approximations, this can be resumed to a dependency
       !!                 on ice concentration.
@@ -1026,6 +1124,121 @@
       
    END SUBROUTINE Cdn10_Lupkes2012
+
+
+   SUBROUTINE Cdn10_Lupkes2015( Cd, Ch )
+      !!----------------------------------------------------------------------
+      !!                      ***  ROUTINE  Cdn10_Lupkes2015  ***
+      !!
+      !! ** pUrpose :    Alternative turbulent transfert coefficients formulation
+      !!                 between sea-ice and atmosphere with distinct momentum 
+      !!                 and heat coefficients depending on sea-ice concentration 
+      !!                 and atmospheric stability (no meltponds effect for now).
+      !!                
+      !! ** Method :     The parameterization is adapted from Lupkes et al. (2015)
+      !!                 and ECHAM6 atmospheric model. Compared to Lupkes2012 scheme,
+      !!                 it considers specific skin and form drags (Andreas et al. 2010)
+      !!                 to compute neutral transfert coefficients for both heat and 
+      !!                 momemtum fluxes. Atmospheric stability effect on transfert
+      !!                 coefficient is also taken into account following Louis (1979).
+      !!
+      !! ** References : Lupkes et al. JGR 2015 (theory)
+      !!                 Lupkes et al. ECHAM6 documentation 2015 (implementation)
+      !!
+      !!----------------------------------------------------------------------
+      !
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   Cd
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   Ch
+      REAL(wp), DIMENSION(jpi,jpj)            ::   zst, zqo_sat, zqi_sat
+      !
+      ! ECHAM6 constants
+      REAL(wp), PARAMETER ::   z0_skin_ice  = 0.69e-3_wp  ! Eq. 43 [m]
+      REAL(wp), PARAMETER ::   z0_form_ice  = 0.57e-3_wp  ! Eq. 42 [m]
+      REAL(wp), PARAMETER ::   z0_ice       = 1.00e-3_wp  ! Eq. 15 [m]
+      REAL(wp), PARAMETER ::   zce10        = 2.80e-3_wp  ! Eq. 41
+      REAL(wp), PARAMETER ::   zbeta        = 1.1_wp      ! Eq. 41
+      REAL(wp), PARAMETER ::   zc           = 5._wp       ! Eq. 13
+      REAL(wp), PARAMETER ::   zc2          = zc * zc
+      REAL(wp), PARAMETER ::   zam          = 2. * zc     ! Eq. 14
+      REAL(wp), PARAMETER ::   zah          = 3. * zc     ! Eq. 30
+      REAL(wp), PARAMETER ::   z1_alpha     = 1._wp / 0.2_wp  ! Eq. 51
+      REAL(wp), PARAMETER ::   z1_alphaf    = z1_alpha    ! Eq. 56
+      REAL(wp), PARAMETER ::   zbetah       = 1.e-3_wp    ! Eq. 26
+      REAL(wp), PARAMETER ::   zgamma       = 1.25_wp     ! Eq. 26
+      REAL(wp), PARAMETER ::   z1_gamma     = 1._wp / zgamma
+      REAL(wp), PARAMETER ::   r1_3         = 1._wp / 3._wp
+      !
+      INTEGER  ::   ji, jj         ! dummy loop indices
+      REAL(wp) ::   zthetav_os, zthetav_is, zthetav_zu
+      REAL(wp) ::   zrib_o, zrib_i
+      REAL(wp) ::   zCdn_skin_ice, zCdn_form_ice, zCdn_ice
+      REAL(wp) ::   zChn_skin_ice, zChn_form_ice
+      REAL(wp) ::   z0w, z0i, zfmi, zfmw, zfhi, zfhw
+      REAL(wp) ::   zCdn_form_tmp
+      !!----------------------------------------------------------------------
+
+      ! Momentum Neutral Transfert Coefficients (should be a constant)
+      zCdn_form_tmp = zce10 * ( LOG( 10._wp / z0_form_ice + 1._wp ) / LOG( rn_zu / z0_form_ice + 1._wp ) )**2   ! Eq. 40
+      zCdn_skin_ice = ( vkarmn                                      / LOG( rn_zu / z0_skin_ice + 1._wp ) )**2   ! Eq. 7
+      zCdn_ice      = zCdn_skin_ice   ! Eq. 7 (cf Lupkes email for details)
+      !zCdn_ice     = 1.89e-3         ! old ECHAM5 value (cf Eq. 32)
+
+      ! Heat Neutral Transfert Coefficients
+      zChn_skin_ice = vkarmn**2 / ( LOG( rn_zu / z0_ice + 1._wp ) * LOG( rn_zu * z1_alpha / z0_skin_ice + 1._wp ) )   ! Eq. 50 + Eq. 52 (cf Lupkes email for details)
+     
+      ! Atmospheric and Surface Variables
+      zst(:,:)     = sst_m(:,:) + rt0                                       ! convert SST from Celcius to Kelvin
+      zqo_sat(:,:) = 0.98_wp * q_sat( zst(:,:)  , sf(jp_slp)%fnow(:,:,1) )  ! saturation humidity over ocean [kg/kg]
+      zqi_sat(:,:) = 0.98_wp * q_sat( tm_su(:,:), sf(jp_slp)%fnow(:,:,1) )  ! saturation humidity over ice   [kg/kg]
+      !
+      DO jj = 2, jpjm1           ! reduced loop is necessary for reproducibility
+         DO ji = fs_2, fs_jpim1
+            ! Virtual potential temperature [K]
+            zthetav_os = zst(ji,jj)   * ( 1._wp + rctv0 * zqo_sat(ji,jj) )   ! over ocean
+            zthetav_is = tm_su(ji,jj) * ( 1._wp + rctv0 * zqi_sat(ji,jj) )   ! ocean ice
+            zthetav_zu = t_zu (ji,jj) * ( 1._wp + rctv0 * q_zu(ji,jj)    )   ! at zu
+            
+            ! Bulk Richardson Number (could use Ri_bulk function from aerobulk instead)
+            zrib_o = grav / zthetav_os * ( zthetav_zu - zthetav_os ) * rn_zu / MAX( 0.5, wndm(ji,jj)     )**2   ! over ocean
+            zrib_i = grav / zthetav_is * ( zthetav_zu - zthetav_is ) * rn_zu / MAX( 0.5, wndm_ice(ji,jj) )**2   ! over ice
+            
+            ! Momentum and Heat Neutral Transfert Coefficients
+            zCdn_form_ice = zCdn_form_tmp * at_i_b(ji,jj) * ( 1._wp - at_i_b(ji,jj) )**zbeta  ! Eq. 40
+            zChn_form_ice = zCdn_form_ice / ( 1._wp + ( LOG( z1_alphaf ) / vkarmn ) * SQRT( zCdn_form_ice ) )               ! Eq. 53 
+                       
+            ! Momentum and Heat Stability functions (possibility to use psi_m_ecmwf instead)
+            z0w = rn_zu * EXP( -1._wp * vkarmn / SQRT( Cdn_oce(ji,jj) ) ) ! over water
+            z0i = z0_skin_ice                                             ! over ice (cf Lupkes email for details)
+            IF( zrib_o <= 0._wp ) THEN
+               zfmw = 1._wp - zam * zrib_o / ( 1._wp + 3._wp * zc2 * Cdn_oce(ji,jj) * SQRT( -zrib_o * ( rn_zu / z0w + 1._wp ) ) )  ! Eq. 10
+               zfhw = ( 1._wp + ( zbetah * ( zthetav_os - zthetav_zu )**r1_3 / ( Chn_oce(ji,jj) * MAX(0.01, wndm(ji,jj)) )   &     ! Eq. 26
+                  &             )**zgamma )**z1_gamma
+            ELSE
+               zfmw = 1._wp / ( 1._wp + zam * zrib_o / SQRT( 1._wp + zrib_o ) )   ! Eq. 12
+               zfhw = 1._wp / ( 1._wp + zah * zrib_o / SQRT( 1._wp + zrib_o ) )   ! Eq. 28
+            ENDIF
+            
+            IF( zrib_i <= 0._wp ) THEN
+               zfmi = 1._wp - zam * zrib_i / (1._wp + 3._wp * zc2 * zCdn_ice * SQRT( -zrib_i * ( rn_zu / z0i + 1._wp)))   ! Eq.  9
+               zfhi = 1._wp - zah * zrib_i / (1._wp + 3._wp * zc2 * zCdn_ice * SQRT( -zrib_i * ( rn_zu / z0i + 1._wp)))   ! Eq. 25
+            ELSE
+               zfmi = 1._wp / ( 1._wp + zam * zrib_i / SQRT( 1._wp + zrib_i ) )   ! Eq. 11
+               zfhi = 1._wp / ( 1._wp + zah * zrib_i / SQRT( 1._wp + zrib_i ) )   ! Eq. 27
+            ENDIF
+            
+            ! Momentum Transfert Coefficients (Eq. 38)
+            Cd(ji,jj) = zCdn_skin_ice *   zfmi +  &
+               &        zCdn_form_ice * ( zfmi * at_i_b(ji,jj) + zfmw * ( 1._wp - at_i_b(ji,jj) ) ) / MAX( 1.e-06, at_i_b(ji,jj) )
+            
+            ! Heat Transfert Coefficients (Eq. 49)
+            Ch(ji,jj) = zChn_skin_ice *   zfhi +  &
+               &        zChn_form_ice * ( zfhi * at_i_b(ji,jj) + zfhw * ( 1._wp - at_i_b(ji,jj) ) ) / MAX( 1.e-06, at_i_b(ji,jj) )
+            !
+         END DO
+      END DO
+      CALL lbc_lnk_multi( Cd, 'T',  1., Ch, 'T', 1. )
+      !
+   END SUBROUTINE Cdn10_Lupkes2015
+
 #endif
-   
 
    !!======================================================================
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_algo_coare.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_algo_coare.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_algo_coare.F90	(revision 9019)
@@ -44,5 +44,4 @@
    USE lib_fortran    ! to use key_nosignedzero
 
-
    IMPLICIT NONE
    PRIVATE
@@ -50,15 +49,15 @@
    PUBLIC ::   TURB_COARE   ! called by sbcblk.F90
 
-   !! COARE own values for given constants:
-   REAL(wp), PARAMETER :: &
-      &   zi0     = 600.,  &   !: scale height of the atmospheric boundary layer...1
-      &  Beta0    = 1.25, &   !: gustiness parameter
-      &  rctv0    = 0.608     !: constant to obtain virtual temperature...
-
-
+   !                                              !! COARE own values for given constants:
+   REAL(wp), PARAMETER ::   zi0     = 600._wp      ! scale height of the atmospheric boundary layer...
+   REAL(wp), PARAMETER ::   Beta0   =   1.250_wp   ! gustiness parameter
+   REAL(wp), PARAMETER ::   rctv0   =   0.608_wp   ! constant to obtain virtual temperature...
+
+   !!----------------------------------------------------------------------
 CONTAINS
 
    SUBROUTINE turb_coare( zt, zu, sst, t_zt, ssq, q_zt, U_zu, &
-      &                   Cd, Ch, Ce, t_zu, q_zu, U_blk )
+      &                   Cd, Ch, Ce, t_zu, q_zu, U_blk,      &
+      &                   Cdn, Chn, Cen                       )
       !!----------------------------------------------------------------------
       !!                      ***  ROUTINE  turb_coare  ***
@@ -106,4 +105,5 @@
       REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   q_zu     ! spec. humidity adjusted at zu           [kg/kg]
       REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   U_blk    ! bulk wind at 10m                          [m/s]
+      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   Cdn, Chn, Cen ! neutral transfer coefficients
       !
       INTEGER :: j_itt
@@ -246,4 +246,9 @@
       Ce   = ztmp0*q_star/dq_zu
       !
+      ztmp1 = zu + z0
+      Cdn = vkarmn*vkarmn / (log(ztmp1/z0 )*log(ztmp1/z0 ))
+      Chn = vkarmn*vkarmn / (log(ztmp1/z0t)*log(ztmp1/z0t))
+      Cen = Chn
+      !
       CALL wrk_dealloc( jpi,jpj, u_star, t_star, q_star, zeta_u, dt_zu, dq_zu )
       CALL wrk_dealloc( jpi,jpj, znu_a, z0, z0t, ztmp0, ztmp1, ztmp2 )
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_algo_coare3p5.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_algo_coare3p5.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_algo_coare3p5.F90	(revision 9019)
@@ -58,6 +58,7 @@
 CONTAINS
 
-   SUBROUTINE turb_coare3p5( zt, zu, sst, t_zt, ssq, q_zt, U_zu, &
-      &                   Cd, Ch, Ce, t_zu, q_zu, U_blk )
+   SUBROUTINE turb_coare3p5( zt, zu, sst, t_zt, ssq, q_zt, U_zu,  &
+      &                      Cd, Ch, Ce, t_zu, q_zu, U_blk,       &
+      &                      Cdn, Chn, Cen                        )
       !!----------------------------------------------------------------------------------
       !!                      ***  ROUTINE  turb_coare3p5  ***
@@ -105,4 +106,5 @@
       REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   q_zu     ! spec. humidity adjusted at zu             [kg/kg]
       REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   U_blk    ! bulk wind at 10m                          [m/s]
+      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   Cdn, Chn, Cen ! neutral transfer coefficients
       !
       INTEGER :: j_itt
@@ -252,4 +254,9 @@
       Ce   = ztmp0*q_star/dq_zu
       !
+      ztmp1 = zu + z0
+      Cdn = vkarmn*vkarmn / (log(ztmp1/z0 )*log(ztmp1/z0 ))
+      Chn = vkarmn*vkarmn / (log(ztmp1/z0t)*log(ztmp1/z0t))
+      Cen = Chn
+      !
       CALL wrk_dealloc( jpi,jpj, u_star, t_star, q_star, zeta_u, dt_zu, dq_zu )
       CALL wrk_dealloc( jpi,jpj, znu_a, z0, z0t, ztmp0, ztmp1, ztmp2 )
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_algo_ecmwf.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_algo_ecmwf.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_algo_ecmwf.F90	(revision 9019)
@@ -64,5 +64,6 @@
 
    SUBROUTINE TURB_ECMWF( zt, zu, sst, t_zt, ssq , q_zt , U_zu,   &
-      &                   Cd, Ch, Ce , t_zu, q_zu, U_blk )
+      &                   Cd, Ch, Ce , t_zu, q_zu, U_blk,         &
+      &                   Cdn, Chn, Cen                           )
       !!----------------------------------------------------------------------------------
       !!                      ***  ROUTINE  turb_ecmwf  ***
@@ -112,4 +113,5 @@
       REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   q_zu     ! spec. humidity adjusted at zu           [kg/kg]
       REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   U_blk    ! bulk wind at 10m                          [m/s]
+      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   Cdn, Chn, Cen ! neutral transfer coefficients
       !
       INTEGER :: j_itt
@@ -266,4 +268,5 @@
             dt_zu = t_zu - sst ;  dt_zu = SIGN( MAX(ABS(dt_zu),1.E-6), dt_zu )
             dq_zu = q_zu - ssq ;  dq_zu = SIGN( MAX(ABS(dq_zu),1.E-9), dq_zu )
+
          END IF
 
@@ -271,5 +274,5 @@
          ztmp1 = zu + z0
          ztmp0 = ztmp1*Linv
-         func_m = log(ztmp1) - LOG(z0) - psi_m_ecmwf(ztmp0) + psi_m_ecmwf(z0*Linv)
+         func_m = log(ztmp1) - LOG(z0 ) - psi_m_ecmwf(ztmp0) + psi_m_ecmwf(z0 *Linv)
          func_h = log(ztmp1) - LOG(z0t) - psi_h_ecmwf(ztmp0) + psi_h_ecmwf(z0t*Linv)
 
@@ -280,4 +283,9 @@
       ztmp1 = log((zu + z0)/z0q) - psi_h_ecmwf((zu + z0)*Linv) + psi_h_ecmwf(z0q*Linv)   ! func_q
       Ce = vkarmn*vkarmn/(func_m*ztmp1)
+
+      ztmp1 = zu + z0
+      Cdn = vkarmn*vkarmn / (log(ztmp1/z0 )*log(ztmp1/z0 ))
+      Chn = vkarmn*vkarmn / (log(ztmp1/z0t)*log(ztmp1/z0t))
+      Cen = vkarmn*vkarmn / (log(ztmp1/z0q)*log(ztmp1/z0q))
 
       CALL wrk_dealloc( jpi,jpj,   u_star, t_star, q_star, func_m, func_h, dt_zu, dq_zu, Linv )
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_algo_ncar.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_algo_ncar.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk_algo_ncar.F90	(revision 9019)
@@ -53,5 +53,6 @@
 
    SUBROUTINE turb_ncar( zt, zu, sst, t_zt, ssq, q_zt, U_zu, &
-      &                  Cd, Ch, Ce, t_zu, q_zu, U_blk )
+      &                  Cd, Ch, Ce, t_zu, q_zu, U_blk,      &
+      &                  Cdn, Chn, Cen                       )
       !!----------------------------------------------------------------------------------
       !!                      ***  ROUTINE  turb_ncar  ***
@@ -112,4 +113,5 @@
       REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   q_zu     ! spec. humidity adjusted at zu           [kg/kg]
       REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   U_blk    ! bulk wind at 10m                          [m/s]
+      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   Cdn, Chn, Cen ! neutral transfer coefficients
       !
       INTEGER ::   j_itt
@@ -199,8 +201,10 @@
             ztmp0 = MAX( 0.25 , U_blk/(1. + sqrt_Cd_n10/vkarmn*(LOG(zu/10.) - ztmp2)) ) ! U_n10 (ztmp2 == psi_m(zeta_u))
             ztmp0 = cd_neutral_10m(ztmp0)                                               ! Cd_n10
+            Cdn(:,:) = ztmp0
             sqrt_Cd_n10 = sqrt(ztmp0)
 
             stab    = 0.5 + sign(0.5,zeta_u)                           ! update stability
             Cx_n10  = 1.e-3*sqrt_Cd_n10*(18.*stab + 32.7*(1. - stab))  ! L&Y 2004 eq. (6c-6d)    (Cx_n10 == Ch_n10)
+            Chn(:,:) = Cx_n10
 
             !! Update of transfer coefficients:
@@ -216,14 +220,15 @@
 
          Cx_n10  = 1.e-3 * (34.6 * sqrt_Cd_n10)  ! L&Y 2004 eq. (6b)    ! Cx_n10 == Ce_n10
+         Cen(:,:) = Cx_n10
          ztmp1 = 1. + Cx_n10*ztmp0
          Ce  = Cx_n10*ztmp2 / ztmp1  ! L&Y 2004 eq. (10c)
-
+         !
       END DO
-
+      !
       CALL wrk_dealloc( jpi,jpj,   Cx_n10, sqrt_Cd_n10, zeta_u, stab )
       CALL wrk_dealloc( jpi,jpj,   zpsi_h_u, ztmp0, ztmp1, ztmp2 )
-
+      !
       IF( nn_timing == 1 )   CALL timing_stop('turb_ncar')
-
+      !
    END SUBROUTINE turb_ncar
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 9019)
@@ -9,4 +9,5 @@
    !!            3.4  ! 2011_11  (C. Harris) more flexibility + multi-category fields
    !!----------------------------------------------------------------------
+
    !!----------------------------------------------------------------------
    !!   namsbc_cpl      : coupled formulation namlist
@@ -29,20 +30,16 @@
    USE ice            ! ice variables
 #endif
-#if defined key_lim2
-   USE par_ice_2      ! ice parameters
-   USE ice_2          ! ice variables
-#endif
    USE cpl_oasis3     ! OASIS3 coupling
    USE geo2ocean      ! 
-   USE oce   , ONLY : tsn, un, vn, sshn, ub, vb, sshb, fraqsr_1lev
-   USE albedo         ! 
+   USE oce     , ONLY : tsn, un, vn, sshn, ub, vb, sshb, fraqsr_1lev
+   USE ocealb         ! 
    USE eosbn2         ! 
-   USE sbcrnf, ONLY : l_rnfcpl
-   USE sbcisf   , ONLY : l_isfcpl
+   USE sbcrnf  , ONLY : l_rnfcpl
+   USE sbcisf  , ONLY : l_isfcpl
 #if defined key_cice
    USE ice_domain_size, only: ncat
 #endif
 #if defined key_lim3
-   USE limthd_dh      ! for CALL lim_thd_snwblow
+   USE icethd_dh      ! for CALL ice_thd_snwblow
 #endif
    !
@@ -50,5 +47,4 @@
    USE iom            ! NetCDF library
    USE lib_mpp        ! distribued memory computing library
-   USE wrk_nemo       ! work arrays
    USE timing         ! Timing
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
@@ -58,8 +54,8 @@
 
    PUBLIC   sbc_cpl_init      ! routine called by sbcmod.F90
-   PUBLIC   sbc_cpl_rcv       ! routine called by sbc_ice_lim(_2).F90
+   PUBLIC   sbc_cpl_rcv       ! routine called by icestp.F90
    PUBLIC   sbc_cpl_snd       ! routine called by step.F90
-   PUBLIC   sbc_cpl_ice_tau   ! routine called by sbc_ice_lim(_2).F90
-   PUBLIC   sbc_cpl_ice_flx   ! routine called by sbc_ice_lim(_2).F90
+   PUBLIC   sbc_cpl_ice_tau   ! routine called by icestp.F90
+   PUBLIC   sbc_cpl_ice_flx   ! routine called by icestp.F90
    PUBLIC   sbc_cpl_alloc     ! routine called in sbcice_cice.F90
 
@@ -117,6 +113,7 @@
    INTEGER, PARAMETER ::   jpr_isf    = 52
    INTEGER, PARAMETER ::   jpr_icb    = 53
-
-   INTEGER, PARAMETER ::   jprcv      = 53   ! total number of fields received  
+   INTEGER, PARAMETER ::   jpr_ts_ice = 54   ! Sea ice surface temp
+
+   INTEGER, PARAMETER ::   jprcv      = 54   ! total number of fields received  
 
    INTEGER, PARAMETER ::   jps_fice   =  1   ! ice fraction sent to the atmosphere
@@ -152,5 +149,12 @@
    INTEGER, PARAMETER ::   jps_ocyw   = 31   ! currents on grid 2
    INTEGER, PARAMETER ::   jps_wlev   = 32   ! water level 
-   INTEGER, PARAMETER ::   jpsnd      = 32   ! total number of fields sent 
+   INTEGER, PARAMETER ::   jps_fice1  = 33   ! first-order ice concentration (for semi-implicit coupling of atmos-ice fluxes)
+   INTEGER, PARAMETER ::   jps_a_p    = 34   ! meltpond area
+   INTEGER, PARAMETER ::   jps_ht_p   = 35   ! meltpond thickness
+   INTEGER, PARAMETER ::   jps_kice   = 36   ! sea ice effective conductivity
+   INTEGER, PARAMETER ::   jps_sstfrz = 37   ! sea surface freezing temperature
+   INTEGER, PARAMETER ::   jps_ttilyr = 38   ! sea ice top layer temp
+
+   INTEGER, PARAMETER ::   jpsnd      = 38   ! total number of fields sent 
 
    !                                  !!** namelist namsbc_cpl **
@@ -163,28 +167,30 @@
    END TYPE FLD_C
    !                                   ! Send to the atmosphere  
-   TYPE(FLD_C) ::   sn_snd_temp, sn_snd_alb, sn_snd_thick, sn_snd_crt, sn_snd_co2                        
+   TYPE(FLD_C) ::   sn_snd_temp  , sn_snd_alb , sn_snd_thick, sn_snd_crt   , sn_snd_co2,  &
+      &             sn_snd_thick1, sn_snd_cond, sn_snd_mpnd , sn_snd_sstfrz, sn_snd_ttilyr
    !                                   ! Received from the atmosphere
-   TYPE(FLD_C) ::   sn_rcv_w10m, sn_rcv_taumod, sn_rcv_tau, sn_rcv_dqnsdt, sn_rcv_qsr, sn_rcv_qns, sn_rcv_emp, sn_rcv_rnf
-   TYPE(FLD_C) ::   sn_rcv_cal, sn_rcv_iceflx, sn_rcv_co2, sn_rcv_mslp, sn_rcv_icb, sn_rcv_isf                              
+   TYPE(FLD_C) ::   sn_rcv_w10m, sn_rcv_taumod, sn_rcv_tau, sn_rcv_dqnsdt, sn_rcv_qsr,  &
+      &             sn_rcv_qns , sn_rcv_emp   , sn_rcv_rnf, sn_rcv_ts_ice
+   TYPE(FLD_C) ::   sn_rcv_cal, sn_rcv_iceflx, sn_rcv_co2, sn_rcv_mslp, sn_rcv_icb, sn_rcv_isf
    ! Send to waves 
    TYPE(FLD_C) ::   sn_snd_ifrac, sn_snd_crtw, sn_snd_wlev 
    ! Received from waves 
-   TYPE(FLD_C) ::   sn_rcv_hsig,sn_rcv_phioc,sn_rcv_sdrfx,sn_rcv_sdrfy,sn_rcv_wper,sn_rcv_wnum,sn_rcv_wstrf,sn_rcv_wdrag
+   TYPE(FLD_C) ::   sn_rcv_hsig, sn_rcv_phioc, sn_rcv_sdrfx, sn_rcv_sdrfy, sn_rcv_wper, sn_rcv_wnum, sn_rcv_wstrf, sn_rcv_wdrag
    !                                   ! Other namelist parameters
    INTEGER     ::   nn_cplmodel           ! Maximum number of models to/from which NEMO is potentialy sending/receiving data
    LOGICAL     ::   ln_usecplmask         !  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)
+                                          !   -> file cplmask.nc with the float variable called cplmask (jpi,jpj,nn_cplmodel)
    TYPE ::   DYNARR     
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   z3   
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   z3   
    END TYPE DYNARR
 
-   TYPE( DYNARR ), SAVE, DIMENSION(jprcv) ::   frcv                     ! all fields recieved from the atmosphere
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   albedo_oce_mix    ! ocean albedo sent to atmosphere (mix clear/overcast sky)
+   TYPE( DYNARR ), SAVE, DIMENSION(jprcv) ::   frcv                ! all fields recieved from the atmosphere
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   alb_oce_mix    ! ocean albedo sent to atmosphere (mix clear/overcast sky)
 
    REAL(wp) ::   rpref = 101000._wp   ! reference atmospheric pressure[N/m2] 
    REAL(wp) ::   r1_grau              ! = 1.e0 / (grav * rau0) 
 
-   INTEGER , ALLOCATABLE, SAVE, DIMENSION(    :) ::   nrcvinfo           ! OASIS info argument
+   INTEGER , ALLOCATABLE, SAVE, DIMENSION(:) ::   nrcvinfo           ! OASIS info argument
 
    !! Substitution
@@ -205,7 +211,7 @@
       ierr(:) = 0
       !
-      ALLOCATE( albedo_oce_mix(jpi,jpj), nrcvinfo(jprcv),  STAT=ierr(1) )
+      ALLOCATE( alb_oce_mix(jpi,jpj), nrcvinfo(jprcv),  STAT=ierr(1) )
       
-#if ! defined key_lim3 && ! defined key_lim2 && ! defined key_cice
+#if ! defined key_lim3 && ! defined key_cice
       ALLOCATE( a_i(jpi,jpj,1) , STAT=ierr(2) )  ! used in sbcice_if.F90 (done here as there is no sbc_ice_if_init)
 #endif
@@ -237,13 +243,13 @@
       INTEGER ::   jn          ! dummy loop index
       INTEGER ::   ios, inum   ! Local integer
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zacs, zaos
+      REAL(wp), DIMENSION(jpi,jpj) ::   zacs, zaos
       !!
-      NAMELIST/namsbc_cpl/  sn_snd_temp , sn_snd_alb  , sn_snd_thick , sn_snd_crt   , sn_snd_co2,      & 
-         &                  sn_rcv_w10m, sn_rcv_taumod, sn_rcv_tau   , sn_rcv_dqnsdt, sn_rcv_qsr,      & 
-         &                  sn_snd_ifrac, sn_snd_crtw , sn_snd_wlev  , sn_rcv_hsig  , sn_rcv_phioc ,   & 
-         &                  sn_rcv_sdrfx, sn_rcv_sdrfy, sn_rcv_wper  , sn_rcv_wnum  , sn_rcv_wstrf ,   &
-         &                  sn_rcv_wdrag, sn_rcv_qns  , sn_rcv_emp   , sn_rcv_rnf   , sn_rcv_cal   ,   &
-         &                  sn_rcv_iceflx,sn_rcv_co2  , nn_cplmodel  , ln_usecplmask, sn_rcv_mslp  ,   &
-         &                  sn_rcv_icb , sn_rcv_isf
+      NAMELIST/namsbc_cpl/  sn_snd_temp  , sn_snd_alb   , sn_snd_thick, sn_snd_crt   , sn_snd_co2  ,   & 
+         &                  sn_rcv_w10m  , sn_rcv_taumod, sn_rcv_tau  , sn_rcv_dqnsdt, sn_rcv_qsr  ,   & 
+         &                  sn_snd_ifrac , sn_snd_crtw  , sn_snd_wlev , sn_rcv_hsig  , sn_rcv_phioc,   & 
+         &                  sn_rcv_sdrfx , sn_rcv_sdrfy , sn_rcv_wper , sn_rcv_wnum  , sn_rcv_wstrf,   &
+         &                  sn_rcv_wdrag , sn_rcv_qns   , sn_rcv_emp  , sn_rcv_rnf   , sn_rcv_cal  ,   &
+         &                  sn_rcv_iceflx, sn_rcv_co2   , nn_cplmodel , ln_usecplmask, sn_rcv_mslp ,   &
+         &                  sn_rcv_icb   , sn_rcv_isf   , nn_cats_cpl  
 
       !!---------------------------------------------------------------------
@@ -251,6 +257,4 @@
       IF( nn_timing == 1 )   CALL timing_start('sbc_cpl_init')
       !
-      CALL wrk_alloc( jpi,jpj,   zacs, zaos )
-
       ! ================================ !
       !      Namelist informations       !
@@ -297,6 +301,8 @@
          WRITE(numout,*)'      Stress frac adsorbed by waves   = ', TRIM(sn_rcv_wstrf%cldes ), ' (', TRIM(sn_rcv_wstrf%clcat ), ')' 
          WRITE(numout,*)'      Neutral surf drag coefficient   = ', TRIM(sn_rcv_wdrag%cldes ), ' (', TRIM(sn_rcv_wdrag%clcat ), ')' 
+         WRITE(numout,*)'      Sea ice surface skin temperature= ', TRIM(sn_rcv_ts_ice%cldes), ' (', TRIM(sn_rcv_ts_ice%clcat), ')' 
          WRITE(numout,*)'  sent fields (multiple ice categories)'
          WRITE(numout,*)'      surface temperature             = ', TRIM(sn_snd_temp%cldes  ), ' (', TRIM(sn_snd_temp%clcat  ), ')'
+         WRITE(numout,*)'      top ice layer temperature       = ', TRIM(sn_snd_ttilyr%cldes), ' (', TRIM(sn_snd_ttilyr%clcat), ')'
          WRITE(numout,*)'      albedo                          = ', TRIM(sn_snd_alb%cldes   ), ' (', TRIM(sn_snd_alb%clcat   ), ')'
          WRITE(numout,*)'      ice/snow thickness              = ', TRIM(sn_snd_thick%cldes ), ' (', TRIM(sn_snd_thick%clcat ), ')'
@@ -307,4 +313,7 @@
          WRITE(numout,*)'                      - mesh          = ', sn_snd_crt%clvgrd
          WRITE(numout,*)'      oce co2 flux                    = ', TRIM(sn_snd_co2%cldes   ), ' (', TRIM(sn_snd_co2%clcat   ), ')'
+         WRITE(numout,*)'      ice effective conductivity      = ', TRIM(sn_snd_cond%cldes  ), ' (', TRIM(sn_snd_cond%clcat  ), ')'
+         WRITE(numout,*)'      meltponds fraction and depth    = ', TRIM(sn_snd_mpnd%cldes  ), ' (', TRIM(sn_snd_mpnd%clcat  ), ')'
+         WRITE(numout,*)'      sea surface freezing temp       = ', TRIM(sn_snd_sstfrz%cldes), ' (', TRIM(sn_snd_sstfrz%clcat), ')'
          WRITE(numout,*)'      water level                     = ', TRIM(sn_snd_wlev%cldes  ), ' (', TRIM(sn_snd_wlev%clcat  ), ')' 
          WRITE(numout,*)'      mean sea level pressure         = ', TRIM(sn_rcv_mslp%cldes  ), ' (', TRIM(sn_rcv_mslp%clcat  ), ')' 
@@ -315,4 +324,5 @@
          WRITE(numout,*)'  nn_cplmodel                         = ', nn_cplmodel
          WRITE(numout,*)'  ln_usecplmask                       = ', ln_usecplmask
+         WRITE(numout,*)'  nn_cats_cpl                         = ', nn_cats_cpl
       ENDIF
 
@@ -435,5 +445,5 @@
       SELECT CASE( TRIM( sn_rcv_emp%cldes ) )
       CASE( 'none'          )       ! nothing to do
-      CASE( 'oce only'      )   ;   srcv(                                 jpr_oemp   )%laction = .TRUE. 
+      CASE( 'oce only'      )   ;   srcv(jpr_oemp)%laction = .TRUE. 
       CASE( 'conservative'  )
          srcv( (/jpr_rain, jpr_snow, jpr_ievp, jpr_tevp/) )%laction = .TRUE.
@@ -479,6 +489,7 @@
       CASE default              ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_rcv_qns%cldes' )
       END SELECT
-      IF( TRIM( sn_rcv_qns%cldes ) == 'mixed oce-ice' .AND. jpl > 1 ) &
+      IF( TRIM( sn_rcv_qns%cldes ) == 'mixed oce-ice' .AND. nn_cats_cpl > 1 ) &
          CALL ctl_stop( 'sbc_cpl_init: sn_rcv_qns%cldes not currently allowed to be mixed oce-ice for multi-category ice' )
+      !
       !                                                      ! ------------------------- !
       !                                                      !    solar radiation        !   Qsr
@@ -495,6 +506,7 @@
       CASE default              ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_rcv_qsr%cldes' )
       END SELECT
-      IF( TRIM( sn_rcv_qsr%cldes ) == 'mixed oce-ice' .AND. jpl > 1 ) &
+      IF( TRIM( sn_rcv_qsr%cldes ) == 'mixed oce-ice' .AND. nn_cats_cpl > 1 ) &
          CALL ctl_stop( 'sbc_cpl_init: sn_rcv_qsr%cldes not currently allowed to be mixed oce-ice for multi-category ice' )
+      !
       !                                                      ! ------------------------- !
       !                                                      !   non solar sensitivity   !   d(Qns)/d(T)
@@ -503,10 +515,8 @@
       IF( TRIM( sn_rcv_dqnsdt%cldes ) == 'coupled' )   srcv(jpr_dqnsdt)%laction = .TRUE.
       !
-      ! non solar sensitivity mandatory for LIM ice model
-      IF( TRIM( sn_rcv_dqnsdt%cldes ) == 'none' .AND. k_ice /= 0 .AND. k_ice /= 4 .AND. nn_components /= jp_iam_sas ) &
-         CALL ctl_stop( 'sbc_cpl_init: sn_rcv_dqnsdt%cldes must be coupled in namsbc_cpl namelist' )
       ! non solar sensitivity mandatory for mixed oce-ice solar radiation coupling technique
-      IF( TRIM( sn_rcv_dqnsdt%cldes ) == 'none' .AND. TRIM( sn_rcv_qns%cldes ) == 'mixed oce-ice' ) &
-         CALL ctl_stop( 'sbc_cpl_init: namsbc_cpl namelist mismatch between sn_rcv_qns%cldes and sn_rcv_dqnsdt%cldes' )
+      IF( TRIM( sn_rcv_dqnsdt%cldes ) == 'none' .AND. TRIM( sn_rcv_qns%cldes ) == 'mixed oce-ice' )  &
+         &   CALL ctl_stop( 'sbc_cpl_init: namsbc_cpl namelist mismatch between sn_rcv_qns%cldes and sn_rcv_dqnsdt%cldes' )
+      !
       !                                                      ! ------------------------- !
       !                                                      !      10m wind module      !   
@@ -519,5 +529,5 @@
       srcv(jpr_taum)%clname = 'O_TauMod'   ;   IF( TRIM(sn_rcv_taumod%cldes) == 'coupled' )   srcv(jpr_taum)%laction = .TRUE.
       lhftau = srcv(jpr_taum)%laction
-
+      !
       !                                                      ! ------------------------- !
       !                                                      !      Atmospheric CO2      !
@@ -531,12 +541,12 @@
          IF(lwp) WRITE(numout,*)
       ENDIF
-
+      !
       !                                                      ! ------------------------- ! 
       !                                                      ! Mean Sea Level Pressure   ! 
       !                                                      ! ------------------------- ! 
       srcv(jpr_mslp)%clname = 'O_MSLP'     ;   IF( TRIM(sn_rcv_mslp%cldes  ) == 'coupled' )    srcv(jpr_mslp)%laction = .TRUE. 
-
-      !                                                      ! ------------------------- !
-      !                                                      !   topmelt and botmelt     !   
+      !
+      !                                                      ! ------------------------- !
+      !                                                      !  ice topmelt and botmelt  !   
       !                                                      ! ------------------------- !
       srcv(jpr_topm )%clname = 'OTopMlt'
@@ -544,5 +554,5 @@
       IF( TRIM(sn_rcv_iceflx%cldes) == 'coupled' ) THEN
          IF ( TRIM( sn_rcv_iceflx%clcat ) == 'yes' ) THEN
-            srcv(jpr_topm:jpr_botm)%nct = jpl
+            srcv(jpr_topm:jpr_botm)%nct = nn_cats_cpl
          ELSE
             CALL ctl_stop( 'sbc_cpl_init: sn_rcv_iceflx%clcat should always be set to yes currently' )
@@ -550,4 +560,12 @@
          srcv(jpr_topm:jpr_botm)%laction = .TRUE.
       ENDIF
+      !                                                      ! ------------------------- !
+      !                                                      !    ice skin temperature   !   
+      !                                                      ! ------------------------- !
+      srcv(jpr_ts_ice)%clname = 'OTsfIce'    ! needed by Met Office
+      IF ( TRIM( sn_rcv_ts_ice%cldes ) == 'ice' )   srcv(jpr_ts_ice)%laction = .TRUE.
+      IF ( TRIM( sn_rcv_ts_ice%clcat ) == 'yes' )   srcv(jpr_ts_ice)%nct     = nn_cats_cpl
+      IF ( TRIM( sn_rcv_emp%clcat    ) == 'yes' )   srcv(jpr_ievp)%nct       = nn_cats_cpl
+
       !                                                      ! ------------------------- !
       !                                                      !      Wave breaking        !    
@@ -593,5 +611,4 @@
          cpl_wdrag = .TRUE.
       ENDIF
-      ! 
       !                                                      ! ------------------------------- !
       !                                                      !   OPA-SAS coupling - rcv by opa !   
@@ -710,13 +727,14 @@
       !                                                      !    Surface temperature    !
       !                                                      ! ------------------------- !
-      ssnd(jps_toce)%clname = 'O_SSTSST'
-      ssnd(jps_tice)%clname = 'O_TepIce'
-      ssnd(jps_tmix)%clname = 'O_TepMix'
+      ssnd(jps_toce)%clname   = 'O_SSTSST'
+      ssnd(jps_tice)%clname   = 'O_TepIce'
+      ssnd(jps_ttilyr)%clname = 'O_TtiLyr'
+      ssnd(jps_tmix)%clname   = 'O_TepMix'
       SELECT CASE( TRIM( sn_snd_temp%cldes ) )
       CASE( 'none'                                 )       ! nothing to do
       CASE( 'oce only'                             )   ;   ssnd( jps_toce )%laction = .TRUE.
-      CASE( 'oce and ice' , 'weighted oce and ice' )
+      CASE( 'oce and ice' , 'weighted oce and ice' , 'oce and weighted ice' )
          ssnd( (/jps_toce, jps_tice/) )%laction = .TRUE.
-         IF ( TRIM( sn_snd_temp%clcat ) == 'yes' )  ssnd(jps_tice)%nct = jpl
+         IF ( TRIM( sn_snd_temp%clcat ) == 'yes' )  ssnd(jps_tice)%nct = nn_cats_cpl
       CASE( 'mixed oce-ice'                        )   ;   ssnd( jps_tmix )%laction = .TRUE.
       CASE default   ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_snd_temp%cldes' )
@@ -739,20 +757,24 @@
       !     2. receiving mixed oce-ice solar radiation 
       IF ( TRIM ( sn_snd_alb%cldes ) == 'mixed oce-ice' .OR. TRIM ( sn_rcv_qsr%cldes ) == 'mixed oce-ice' ) THEN
-         CALL albedo_oce( zaos, zacs )
+         CALL oce_alb( zaos, zacs )
          ! Due to lack of information on nebulosity : mean clear/overcast sky
-         albedo_oce_mix(:,:) = ( zacs(:,:) + zaos(:,:) ) * 0.5
-      ENDIF
-
+         alb_oce_mix(:,:) = ( zacs(:,:) + zaos(:,:) ) * 0.5
+      ENDIF
       !                                                      ! ------------------------- !
       !                                                      !  Ice fraction & Thickness ! 
       !                                                      ! ------------------------- !
-      ssnd(jps_fice)%clname = 'OIceFrc'
+      ssnd(jps_fice)%clname  = 'OIceFrc'
       ssnd(jps_ficet)%clname = 'OIceFrcT' 
-      ssnd(jps_hice)%clname = 'OIceTck'
-      ssnd(jps_hsnw)%clname = 'OSnwTck'
+      ssnd(jps_hice)%clname  = 'OIceTck'
+      ssnd(jps_a_p)%clname   = 'OPndFrc'
+      ssnd(jps_ht_p)%clname  = 'OPndTck'
+      ssnd(jps_hsnw)%clname  = 'OSnwTck'
+      ssnd(jps_fice1)%clname = 'OIceFrd'
       IF( k_ice /= 0 ) THEN
-         ssnd(jps_fice)%laction = .TRUE.                  ! if ice treated in the ocean (even in climato case)
+         ssnd(jps_fice)%laction  = .TRUE.                 ! if ice treated in the ocean (even in climato case)
+         ssnd(jps_fice1)%laction = .TRUE.                 ! First-order regridded ice concentration, to be used producing atmos-to-ice fluxes (Met Office requirement)
 ! Currently no namelist entry to determine sending of multi-category ice fraction so use the thickness entry for now
-         IF ( TRIM( sn_snd_thick%clcat ) == 'yes' ) ssnd(jps_fice)%nct = jpl
+         IF ( TRIM( sn_snd_thick%clcat  ) == 'yes' ) ssnd(jps_fice)%nct  = nn_cats_cpl
+         IF ( TRIM( sn_snd_thick1%clcat ) == 'yes' ) ssnd(jps_fice1)%nct = nn_cats_cpl
       ENDIF
       
@@ -764,12 +786,43 @@
          ssnd(jps_hice:jps_hsnw)%laction = .TRUE.
          IF ( TRIM( sn_snd_thick%clcat ) == 'yes' ) THEN
-            ssnd(jps_hice:jps_hsnw)%nct = jpl
+            ssnd(jps_hice:jps_hsnw)%nct = nn_cats_cpl
          ENDIF
       CASE ( 'weighted ice and snow' ) 
          ssnd(jps_hice:jps_hsnw)%laction = .TRUE.
-         IF ( TRIM( sn_snd_thick%clcat ) == 'yes' ) ssnd(jps_hice:jps_hsnw)%nct = jpl
+         IF ( TRIM( sn_snd_thick%clcat ) == 'yes' ) ssnd(jps_hice:jps_hsnw)%nct = nn_cats_cpl
       CASE default   ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_snd_thick%cldes' )
       END SELECT
 
+      !                                                      ! ------------------------- ! 
+      !                                                      !      Ice Meltponds        ! 
+      !                                                      ! ------------------------- ! 
+      ! Needed by Met Office
+      ssnd(jps_a_p)%clname  = 'OPndFrc'    
+      ssnd(jps_ht_p)%clname = 'OPndTck'    
+      SELECT CASE ( TRIM( sn_snd_mpnd%cldes ) ) 
+      CASE ( 'none' ) 
+         ssnd(jps_a_p)%laction  = .FALSE. 
+         ssnd(jps_ht_p)%laction = .FALSE. 
+      CASE ( 'ice only' )  
+         ssnd(jps_a_p)%laction  = .TRUE. 
+         ssnd(jps_ht_p)%laction = .TRUE. 
+         IF ( TRIM( sn_snd_mpnd%clcat ) == 'yes' ) THEN 
+            ssnd(jps_a_p)%nct  = nn_cats_cpl 
+            ssnd(jps_ht_p)%nct = nn_cats_cpl 
+         ELSE 
+            IF ( nn_cats_cpl > 1 ) THEN 
+               CALL ctl_stop( 'sbc_cpl_init: use weighted ice option for sn_snd_mpnd%cldes if not exchanging category fields' ) 
+            ENDIF 
+         ENDIF 
+      CASE ( 'weighted ice' )  
+         ssnd(jps_a_p)%laction  = .TRUE. 
+         ssnd(jps_ht_p)%laction = .TRUE. 
+         IF ( TRIM( sn_snd_mpnd%clcat ) == 'yes' ) THEN 
+            ssnd(jps_a_p)%nct  = nn_cats_cpl  
+            ssnd(jps_ht_p)%nct = nn_cats_cpl  
+         ENDIF 
+      CASE default   ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_snd_mpnd%cldes; '//sn_snd_mpnd%cldes ) 
+      END SELECT 
+ 
       !                                                      ! ------------------------- !
       !                                                      !      Surface current      !
@@ -821,5 +874,55 @@
       !                                                      ! ------------------------- !
       ssnd(jps_co2)%clname = 'O_CO2FLX' ;  IF( TRIM(sn_snd_co2%cldes) == 'coupled' )    ssnd(jps_co2 )%laction = .TRUE.
-
+      ! 
+      !                                                      ! ------------------------- ! 
+      !                                                      ! Sea surface freezing temp ! 
+      !                                                      ! ------------------------- ! 
+      ! needed by Met Office
+      ssnd(jps_sstfrz)%clname = 'O_SSTFrz' ; IF( TRIM(sn_snd_sstfrz%cldes) == 'coupled' )  ssnd(jps_sstfrz)%laction = .TRUE. 
+      ! 
+      !                                                      ! ------------------------- ! 
+      !                                                      !    Ice conductivity       ! 
+      !                                                      ! ------------------------- ! 
+      ! needed by Met Office
+      ! Note that ultimately we will move to passing an ocean effective conductivity as well so there 
+      ! will be some changes to the parts of the code which currently relate only to ice conductivity 
+      ssnd(jps_ttilyr )%clname = 'O_TtiLyr' 
+      SELECT CASE ( TRIM( sn_snd_ttilyr%cldes ) ) 
+      CASE ( 'none' ) 
+         ssnd(jps_ttilyr)%laction = .FALSE. 
+      CASE ( 'ice only' ) 
+         ssnd(jps_ttilyr)%laction = .TRUE. 
+         IF ( TRIM( sn_snd_ttilyr%clcat ) == 'yes' ) THEN 
+            ssnd(jps_ttilyr)%nct = nn_cats_cpl 
+         ELSE 
+            IF ( nn_cats_cpl > 1 ) THEN 
+               CALL ctl_stop( 'sbc_cpl_init: use weighted ice option for sn_snd_ttilyr%cldes if not exchanging category fields' ) 
+            ENDIF 
+         ENDIF 
+      CASE ( 'weighted ice' ) 
+         ssnd(jps_ttilyr)%laction = .TRUE. 
+         IF ( TRIM( sn_snd_ttilyr%clcat ) == 'yes' ) ssnd(jps_ttilyr)%nct = nn_cats_cpl 
+      CASE default   ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_snd_ttilyr%cldes;'//sn_snd_ttilyr%cldes ) 
+      END SELECT 
+
+      ssnd(jps_kice )%clname = 'OIceKn' 
+      SELECT CASE ( TRIM( sn_snd_cond%cldes ) ) 
+      CASE ( 'none' ) 
+         ssnd(jps_kice)%laction = .FALSE. 
+      CASE ( 'ice only' ) 
+         ssnd(jps_kice)%laction = .TRUE. 
+         IF ( TRIM( sn_snd_cond%clcat ) == 'yes' ) THEN 
+            ssnd(jps_kice)%nct = nn_cats_cpl 
+         ELSE 
+            IF ( nn_cats_cpl > 1 ) THEN 
+               CALL ctl_stop( 'sbc_cpl_init: use weighted ice option for sn_snd_cond%cldes if not exchanging category fields' ) 
+            ENDIF 
+         ENDIF 
+      CASE ( 'weighted ice' ) 
+         ssnd(jps_kice)%laction = .TRUE. 
+         IF ( TRIM( sn_snd_cond%clcat ) == 'yes' ) ssnd(jps_kice)%nct = nn_cats_cpl 
+      CASE default   ;   CALL ctl_stop( 'sbc_cpl_init: wrong definition of sn_snd_cond%cldes;'//sn_snd_cond%cldes ) 
+      END SELECT 
+      ! 
       !                                                      ! ------------------------- ! 
       !                                                      !     Sea surface height    ! 
@@ -922,5 +1025,4 @@
       IF( ln_dm2dc .AND. ln_cpl ) ncpl_qsr_freq = 86400 / ncpl_qsr_freq
 
-      CALL wrk_dealloc( jpi,jpj,   zacs, zaos )
       !
       IF( nn_timing == 1 )   CALL timing_stop('sbc_cpl_init')
@@ -974,11 +1076,9 @@
       !!                        emp          upward mass flux [evap. - precip. (- runoffs) (- calving)] (ocean only case)
       !!----------------------------------------------------------------------
-      USE zdf_oce,  ONLY : ln_zdfqiao
-
-      IMPLICIT NONE
-
-      INTEGER, INTENT(in)           ::   kt          ! ocean model time step index
-      INTEGER, INTENT(in)           ::   k_fsbc      ! frequency of sbc (-> ice model) computation 
-      INTEGER, INTENT(in)           ::   k_ice       ! ice management in the sbc (=0/1/2/3)
+      USE zdf_oce,  ONLY :   ln_zdfswm
+      !
+      INTEGER, INTENT(in) ::   kt          ! ocean model time step index
+      INTEGER, INTENT(in) ::   k_fsbc      ! frequency of sbc (-> ice model) computation 
+      INTEGER, INTENT(in) ::   k_ice       ! ice management in the sbc (=0/1/2/3)
       !!
       LOGICAL  ::   llnewtx, llnewtau      ! update wind stress components and module??
@@ -990,10 +1090,8 @@
       REAL(wp) ::   zcdrag = 1.5e-3        ! drag coefficient
       REAL(wp) ::   zzx, zzy               ! temporary variables
-      REAL(wp), POINTER, DIMENSION(:,:) ::   ztx, zty, zmsk, zemp, zqns, zqsr
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztx, zty, zmsk, zemp, zqns, zqsr
       !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )   CALL timing_start('sbc_cpl_rcv')
-      !
-      CALL wrk_alloc( jpi,jpj,   ztx, zty, zmsk, zemp, zqns, zqsr )
       !
       IF( ln_mixcpl )   zmsk(:,:) = 1. - xcplmask(:,:,0)
@@ -1067,5 +1165,4 @@
       !                                                      !    wind stress module     !   (taum)
       !                                                      ! ========================= !
-      !
       IF( .NOT. srcv(jpr_taum)%laction ) THEN                    ! compute wind stress module from its components if not received 
          ! => need to be done only when otx1 was changed
@@ -1094,5 +1191,4 @@
       !                                                      !      10 m wind speed      !   (wndm)
       !                                                      ! ========================= !
-      !
       IF( .NOT. srcv(jpr_w10m)%laction ) THEN                    ! compute wind spreed from wind stress module if not received  
          ! => need to be done only when taumod was changed
@@ -1130,9 +1226,20 @@
       !                                                      ! ================== !
       IF( srcv(jpr_co2)%laction )   atm_co2(:,:) = frcv(jpr_co2)%z3(:,:,1)
-      ! 
+      !
+      !                                                      ! ================== !
+      !                                                      !   ice skin temp.   !
+      !                                                      ! ================== !
+#if defined key_lim3
+      ! needed by Met Office
+      IF( srcv(jpr_ts_ice)%laction ) THEN 
+         WHERE    ( frcv(jpr_ts_ice)%z3(:,:,:) > 0.0  )   ;   tsfc_ice(:,:,:) = 0.0 
+         ELSEWHERE( frcv(jpr_ts_ice)%z3(:,:,:) < -60. )   ;   tsfc_ice(:,:,:) = -60.
+         ELSEWHERE                                        ;   tsfc_ice(:,:,:) = frcv(jpr_ts_ice)%z3(:,:,:)
+         END WHERE
+      ENDIF 
+#endif
       !                                                      ! ========================= ! 
       !                                                      ! Mean Sea Level Pressure   !   (taum) 
       !                                                      ! ========================= ! 
-      ! 
       IF( srcv(jpr_mslp)%laction ) THEN                    ! UKMO SHELF effect of atmospheric pressure on SSH 
           IF( kt /= nit000 )   ssh_ibb(:,:) = ssh_ib(:,:)    !* Swap of ssh_ib fields 
@@ -1146,32 +1253,32 @@
       !
       IF( ln_sdw ) THEN  ! Stokes Drift correction activated
-      !                                                      ! ========================= ! 
-      !                                                      !       Stokes drift u      !
-      !                                                      ! ========================= ! 
-         IF( srcv(jpr_sdrftx)%laction ) ut0sd(:,:) = frcv(jpr_sdrftx)%z3(:,:,1)
-      !
-      !                                                      ! ========================= ! 
-      !                                                      !       Stokes drift v      !
-      !                                                      ! ========================= ! 
-         IF( srcv(jpr_sdrfty)%laction ) vt0sd(:,:) = frcv(jpr_sdrfty)%z3(:,:,1)
-      !
-      !                                                      ! ========================= ! 
-      !                                                      !      Wave mean period     !
-      !                                                      ! ========================= ! 
-         IF( srcv(jpr_wper)%laction ) wmp(:,:) = frcv(jpr_wper)%z3(:,:,1)
-      !
-      !                                                      ! ========================= ! 
-      !                                                      !  Significant wave height  !
-      !                                                      ! ========================= ! 
-         IF( srcv(jpr_hsig)%laction ) hsw(:,:) = frcv(jpr_hsig)%z3(:,:,1)
-      !
-      !                                                      ! ========================= ! 
-      !                                                      !    Vertical mixing Qiao   !
-      !                                                      ! ========================= ! 
-         IF( srcv(jpr_wnum)%laction .AND. ln_zdfqiao ) wnum(:,:) = frcv(jpr_wnum)%z3(:,:,1)
+         !                                                   ! ========================= ! 
+         !                                                   !       Stokes drift u      !
+         !                                                   ! ========================= ! 
+         IF( srcv(jpr_sdrftx)%laction )   ut0sd(:,:) = frcv(jpr_sdrftx)%z3(:,:,1)
+         !
+         !                                                   ! ========================= ! 
+         !                                                   !       Stokes drift v      !
+         !                                                   ! ========================= ! 
+         IF( srcv(jpr_sdrfty)%laction )   vt0sd(:,:) = frcv(jpr_sdrfty)%z3(:,:,1)
+         !
+         !                                                   ! ========================= ! 
+         !                                                   !      Wave mean period     !
+         !                                                   ! ========================= ! 
+         IF( srcv(jpr_wper)%laction   )   wmp(:,:) = frcv(jpr_wper)%z3(:,:,1)
+         !
+         !                                                   ! ========================= ! 
+         !                                                   !  Significant wave height  !
+         !                                                   ! ========================= ! 
+         IF( srcv(jpr_hsig)%laction   )   hsw(:,:) = frcv(jpr_hsig)%z3(:,:,1)
+         !
+         !                                                   ! ========================= ! 
+         !                                                   !    surface wave mixing    !
+         !                                                   ! ========================= ! 
+         IF( srcv(jpr_wnum)%laction .AND. ln_zdfswm )   wnum(:,:) = frcv(jpr_wnum)%z3(:,:,1)
 
          ! Calculate the 3D Stokes drift both in coupled and not fully uncoupled mode
          IF( srcv(jpr_sdrftx)%laction .OR. srcv(jpr_sdrfty)%laction .OR. srcv(jpr_wper)%laction &
-                                                                    .OR. srcv(jpr_hsig)%laction ) THEN
+            &                                                       .OR. srcv(jpr_hsig)%laction ) THEN
             CALL sbc_stokes()
          ENDIF
@@ -1180,10 +1287,10 @@
       !                                                      ! Stress adsorbed by waves  !
       !                                                      ! ========================= ! 
-      IF( srcv(jpr_wstrf)%laction .AND. ln_tauoc ) tauoc_wave(:,:) = frcv(jpr_wstrf)%z3(:,:,1)
+      IF( srcv(jpr_wstrf)%laction .AND. ln_tauoc )   tauoc_wave(:,:) = frcv(jpr_wstrf)%z3(:,:,1)
 
       !                                                      ! ========================= ! 
       !                                                      !   Wave drag coefficient   !
       !                                                      ! ========================= ! 
-      IF( srcv(jpr_wdrag)%laction .AND. ln_cdgw ) cdn_wave(:,:) = frcv(jpr_wdrag)%z3(:,:,1)
+      IF( srcv(jpr_wdrag)%laction .AND. ln_cdgw )   cdn_wave(:,:) = frcv(jpr_wdrag)%z3(:,:,1)
 
       !  Fields received by SAS when OASIS coupling
@@ -1218,5 +1325,5 @@
       IF( srcv(jpr_ocx1)%laction ) THEN                      ! received by sas in case of opa <-> sas coupling
          ssu_m(:,:) = frcv(jpr_ocx1)%z3(:,:,1)
-         ub (:,:,1) = ssu_m(:,:)                             ! will be used in sbcice_lim in the call of lim_sbc_tau
+         ub (:,:,1) = ssu_m(:,:)                             ! will be used in icestp in the call of lim_sbc_tau
          un (:,:,1) = ssu_m(:,:)                             ! will be used in sbc_cpl_snd if atmosphere coupling
          CALL iom_put( 'ssu_m', ssu_m )
@@ -1224,5 +1331,5 @@
       IF( srcv(jpr_ocy1)%laction ) THEN
          ssv_m(:,:) = frcv(jpr_ocy1)%z3(:,:,1)
-         vb (:,:,1) = ssv_m(:,:)                             ! will be used in sbcice_lim in the call of lim_sbc_tau
+         vb (:,:,1) = ssv_m(:,:)                             ! will be used in icestp in the call of lim_sbc_tau
          vn (:,:,1) = ssv_m(:,:)                             ! will be used in sbc_cpl_snd if atmosphere coupling
          CALL iom_put( 'ssv_m', ssv_m )
@@ -1310,6 +1417,4 @@
          !
       ENDIF
-      !
-      CALL wrk_dealloc( jpi,jpj,   ztx, zty, zmsk, zemp, zqns, zqsr )
       !
       IF( nn_timing == 1 )   CALL timing_stop('sbc_cpl_rcv')
@@ -1356,11 +1461,9 @@
       INTEGER ::   ji, jj   ! dummy loop indices
       INTEGER ::   itx      ! index of taux over ice
-      REAL(wp), POINTER, DIMENSION(:,:) ::   ztx, zty 
+      REAL(wp), DIMENSION(jpi,jpj) ::   ztx, zty 
       !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )   CALL timing_start('sbc_cpl_ice_tau')
       !
-      CALL wrk_alloc( jpi,jpj,   ztx, zty )
-
       IF( srcv(jpr_itx1)%laction ) THEN   ;   itx =  jpr_itx1   
       ELSE                                ;   itx =  jpr_otx1
@@ -1521,6 +1624,4 @@
       ENDIF
       !   
-      CALL wrk_dealloc( jpi,jpj,   ztx, zty )
-      !
       IF( nn_timing == 1 )   CALL timing_stop('sbc_cpl_ice_tau')
       !
@@ -1528,5 +1629,5 @@
    
 
-   SUBROUTINE sbc_cpl_ice_flx( p_frld, palbi, psst, pist )
+   SUBROUTINE sbc_cpl_ice_flx( picefr, palbi, psst, pist, phs, phi )
       !!----------------------------------------------------------------------
       !!             ***  ROUTINE sbc_cpl_ice_flx  ***
@@ -1561,8 +1662,8 @@
       !!
       !! ** Details
-      !!             qns_tot = pfrld * qns_oce + ( 1 - pfrld ) * qns_ice   => provided
+      !!             qns_tot = (1-a) * qns_oce + a * qns_ice               => provided
       !!                     + qemp_oce + qemp_ice                         => recalculated and added up to qns
       !!
-      !!             qsr_tot = pfrld * qsr_oce + ( 1 - pfrld ) * qsr_ice   => provided
+      !!             qsr_tot = (1-a) * qsr_oce + a * qsr_ice               => provided
       !!
       !!             emp_tot = emp_oce + emp_ice                           => calving is provided and added to emp_tot (and emp_oce).
@@ -1578,27 +1679,25 @@
       !!                   sprecip           solid precipitation over the ocean  
       !!----------------------------------------------------------------------
-      REAL(wp), INTENT(in   ), DIMENSION(:,:)   ::   p_frld     ! lead fraction                [0 to 1]
-      ! optional arguments, used only in 'mixed oce-ice' case
-      REAL(wp), INTENT(in   ), DIMENSION(:,:,:), OPTIONAL ::   palbi      ! all skies ice albedo 
-      REAL(wp), INTENT(in   ), DIMENSION(:,:  ), OPTIONAL ::   psst       ! sea surface temperature     [Celsius]
-      REAL(wp), INTENT(in   ), DIMENSION(:,:,:), OPTIONAL ::   pist       ! ice surface temperature     [Kelvin]
-      !
-      INTEGER ::   jl         ! dummy loop index
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::   zcptn, zcptrain, zcptsnw, zicefr, zmsk, zsnw
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::   zemp_tot, zemp_ice, zemp_oce, ztprecip, zsprecip, zevap_oce, zevap_ice, zdevap_ice
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::   zqns_tot, zqns_oce, zqsr_tot, zqsr_oce, zqprec_ice, zqemp_oce, zqemp_ice
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zqns_ice, zqsr_ice, zdqns_ice, zqevap_ice
+      REAL(wp), INTENT(in), DIMENSION(:,:)             ::   picefr     ! ice fraction                [0 to 1]
+      !                                                !!           ! optional arguments, used only in 'mixed oce-ice' case
+      REAL(wp), INTENT(in), DIMENSION(:,:,:), OPTIONAL ::   palbi      ! all skies ice albedo 
+      REAL(wp), INTENT(in), DIMENSION(:,:  ), OPTIONAL ::   psst       ! sea surface temperature     [Celsius]
+      REAL(wp), INTENT(in), DIMENSION(:,:,:), OPTIONAL ::   pist       ! ice surface temperature     [Kelvin]
+      REAL(wp), INTENT(in), DIMENSION(:,:,:), OPTIONAL ::   phs        ! snow depth                  [m]
+      REAL(wp), INTENT(in), DIMENSION(:,:,:), OPTIONAL ::   phi        ! ice thickness               [m]
+      !
+      INTEGER  ::   ji, jj, jl   ! dummy loop index
+      REAL(wp) ::   ztri         ! local scalar
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zcptn, zcptrain, zcptsnw, ziceld, zmsk, zsnw
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zemp_tot, zemp_ice, zemp_oce, ztprecip, zsprecip  , zevap_oce, zdevap_ice
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zqns_tot, zqns_oce, zqsr_tot, zqsr_oce, zqprec_ice, zqemp_oce, zqemp_ice
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zqns_ice, zqsr_ice, zdqns_ice, zqevap_ice, zevap_ice    !!gm , zfrqsr_tr_i
       !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('sbc_cpl_ice_flx')
       !
-      CALL wrk_alloc( jpi,jpj,     zcptn, zcptrain, zcptsnw, zicefr, zmsk, zsnw )
-      CALL wrk_alloc( jpi,jpj,     zemp_tot, zemp_ice, zemp_oce, ztprecip, zsprecip, zevap_oce, zevap_ice, zdevap_ice )
-      CALL wrk_alloc( jpi,jpj,     zqns_tot, zqns_oce, zqsr_tot, zqsr_oce, zqprec_ice, zqemp_oce, zqemp_ice )
-      CALL wrk_alloc( jpi,jpj,jpl, zqns_ice, zqsr_ice, zdqns_ice, zqevap_ice )
-
       IF( ln_mixcpl )   zmsk(:,:) = 1. - xcplmask(:,:,0)
-      zicefr(:,:) = 1.- p_frld(:,:)
-      zcptn(:,:) = rcp * sst_m(:,:)
+      ziceld(:,:) = 1._wp - picefr(:,:)
+      zcptn (:,:) = rcp * sst_m(:,:)
       !
       !                                                      ! ========================= !
@@ -1615,8 +1714,8 @@
          ztprecip(:,:) =   frcv(jpr_rain)%z3(:,:,1) + zsprecip(:,:)  ! May need to ensure positive here
          zemp_tot(:,:) =   frcv(jpr_tevp)%z3(:,:,1) - ztprecip(:,:)
-         zemp_ice(:,:) = ( frcv(jpr_ievp)%z3(:,:,1) - frcv(jpr_snow)%z3(:,:,1) ) * zicefr(:,:)
+         zemp_ice(:,:) = ( frcv(jpr_ievp)%z3(:,:,1) - frcv(jpr_snow)%z3(:,:,1) ) * picefr(:,:)
       CASE( 'oce and ice'   )   ! received fields: jpr_sbpr, jpr_semp, jpr_oemp, jpr_ievp
-         zemp_tot(:,:) = p_frld(:,:) * frcv(jpr_oemp)%z3(:,:,1) + zicefr(:,:) * frcv(jpr_sbpr)%z3(:,:,1)
-         zemp_ice(:,:) = frcv(jpr_semp)%z3(:,:,1) * zicefr(:,:)
+         zemp_tot(:,:) = ziceld(:,:) * frcv(jpr_oemp)%z3(:,:,1) + picefr(:,:) * frcv(jpr_sbpr)%z3(:,:,1)
+         zemp_ice(:,:) = frcv(jpr_semp)%z3(:,:,1) * picefr(:,:)
          zsprecip(:,:) = frcv(jpr_ievp)%z3(:,:,1) - frcv(jpr_semp)%z3(:,:,1)
          ztprecip(:,:) = frcv(jpr_semp)%z3(:,:,1) - frcv(jpr_sbpr)%z3(:,:,1) + zsprecip(:,:)
@@ -1624,16 +1723,20 @@
 
 #if defined key_lim3
-      ! zsnw = snow fraction over ice after wind blowing (=zicefr if no blowing)
-      zsnw(:,:) = 0._wp  ;  CALL lim_thd_snwblow( p_frld, zsnw )
+      ! zsnw = snow fraction over ice after wind blowing (=picefr if no blowing)
+      zsnw(:,:) = 0._wp   ;   CALL ice_thd_snwblow( ziceld, zsnw )
       
       ! --- evaporation minus precipitation corrected (because of wind blowing on snow) --- !
-      zemp_ice(:,:) = zemp_ice(:,:) + zsprecip(:,:) * ( zicefr(:,:) - zsnw(:,:) )  ! emp_ice = A * sublimation - zsnw * sprecip
+      zemp_ice(:,:) = zemp_ice(:,:) + zsprecip(:,:) * ( picefr(:,:) - zsnw(:,:) )  ! emp_ice = A * sublimation - zsnw * sprecip
       zemp_oce(:,:) = zemp_tot(:,:) - zemp_ice(:,:)                                ! emp_oce = emp_tot - emp_ice
 
       ! --- evaporation over ocean (used later for qemp) --- !
-      zevap_oce(:,:) = frcv(jpr_tevp)%z3(:,:,1) - frcv(jpr_ievp)%z3(:,:,1) * zicefr(:,:)
+      zevap_oce(:,:) = frcv(jpr_tevp)%z3(:,:,1) - frcv(jpr_ievp)%z3(:,:,1) * picefr(:,:)
 
       ! --- evaporation over ice (kg/m2/s) --- !
-      zevap_ice(:,:) = frcv(jpr_ievp)%z3(:,:,1)
+      DO jl=1,jpl
+         IF (sn_rcv_emp%clcat == 'yes') THEN   ;   zevap_ice(:,:,jl) = frcv(jpr_ievp)%z3(:,:,jl)
+         ELSE                                  ;   zevap_ice(:,:,jl) = frcv(jpr_ievp)%z3(:,:,1 )   ;   ENDIF
+      ENDDO
+
       ! since the sensitivity of evap to temperature (devap/dT) is not prescribed by the atmosphere, we set it to 0
       ! therefore, sublimation is not redistributed over the ice categories when no subgrid scale fluxes are provided by atm.
@@ -1662,22 +1765,22 @@
          sprecip(:,:) = sprecip(:,:) * xcplmask(:,:,0) + zsprecip(:,:) * zmsk(:,:)
          tprecip(:,:) = tprecip(:,:) * xcplmask(:,:,0) + ztprecip(:,:) * zmsk(:,:)
-         DO jl=1,jpl
-            evap_ice (:,:,jl) = evap_ice (:,:,jl) * xcplmask(:,:,0) + zevap_ice (:,:) * zmsk(:,:)
-            devap_ice(:,:,jl) = devap_ice(:,:,jl) * xcplmask(:,:,0) + zdevap_ice(:,:) * zmsk(:,:)
-         ENDDO
+         DO jl = 1, jpl
+            evap_ice (:,:,jl) = evap_ice (:,:,jl) * xcplmask(:,:,0) + zevap_ice (:,:,jl) * zmsk(:,:)
+            devap_ice(:,:,jl) = devap_ice(:,:,jl) * xcplmask(:,:,0) + zdevap_ice(:,:)    * zmsk(:,:)
+         END DO
       ELSE
-         emp_tot(:,:) =         zemp_tot(:,:)
-         emp_ice(:,:) =         zemp_ice(:,:)
-         emp_oce(:,:) =         zemp_oce(:,:)     
-         sprecip(:,:) =         zsprecip(:,:)
-         tprecip(:,:) =         ztprecip(:,:)
-         DO jl=1,jpl
-            evap_ice (:,:,jl) = zevap_ice (:,:)
+         emp_tot (:,:)   = zemp_tot (:,:)
+         emp_ice (:,:)   = zemp_ice (:,:)
+         emp_oce (:,:)   = zemp_oce (:,:)     
+         sprecip (:,:)   = zsprecip (:,:)
+         tprecip (:,:)   = ztprecip (:,:)
+         evap_ice(:,:,:) = zevap_ice(:,:,:)
+         DO jl = 1, jpl
             devap_ice(:,:,jl) = zdevap_ice(:,:)
-         ENDDO
+         END DO
       ENDIF
 
 #else
-      zsnw(:,:) = zicefr(:,:)
+      zsnw(:,:) = picefr(:,:)
       ! --- Continental fluxes --- !
       IF( srcv(jpr_rnf)%laction ) THEN   ! runoffs (included in emp later on)
@@ -1694,5 +1797,5 @@
         fwfisf(:,:) = - frcv(jpr_isf)%z3(:,:,1)
       ENDIF
-
+      !
       IF( ln_mixcpl ) THEN
          emp_tot(:,:) = emp_tot(:,:) * xcplmask(:,:,0) + zemp_tot(:,:) * zmsk(:,:)
@@ -1706,6 +1809,7 @@
          tprecip(:,:) =                                  ztprecip(:,:)
       ENDIF
-
+      !
 #endif
+
       ! outputs
 !!      IF( srcv(jpr_rnf)%laction )   CALL iom_put( 'runoffs' , rnf(:,:) * tmask(:,:,1)                                 )  ! runoff
@@ -1718,7 +1822,7 @@
       IF( iom_use('snow_ao_cea') )  CALL iom_put( 'snow_ao_cea' , sprecip(:,:) * ( 1._wp - zsnw(:,:) )                  )  ! Snow over ice-free ocean  (cell average)
       IF( iom_use('snow_ai_cea') )  CALL iom_put( 'snow_ai_cea' , sprecip(:,:) *           zsnw(:,:)                    )  ! Snow over sea-ice         (cell average)
-      IF( iom_use('subl_ai_cea') )  CALL iom_put( 'subl_ai_cea' , frcv(jpr_ievp)%z3(:,:,1) * zicefr(:,:) * tmask(:,:,1) )  ! Sublimation over sea-ice (cell average)
+      IF( iom_use('subl_ai_cea') )  CALL iom_put( 'subl_ai_cea' , frcv(jpr_ievp)%z3(:,:,1) * picefr(:,:) * tmask(:,:,1) )  ! Sublimation over sea-ice (cell average)
       IF( iom_use('evap_ao_cea') )  CALL iom_put( 'evap_ao_cea' , ( frcv(jpr_tevp)%z3(:,:,1)  &
-         &                                                        - frcv(jpr_ievp)%z3(:,:,1) * zicefr(:,:) ) * tmask(:,:,1) )  ! ice-free oce evap (cell average)
+         &                                                        - frcv(jpr_ievp)%z3(:,:,1) * picefr(:,:) ) * tmask(:,:,1) )  ! ice-free oce evap (cell average)
       ! note: runoff output is done in sbcrnf (which includes icebergs too) and iceshelf output is done in sbcisf
       !
@@ -1733,10 +1837,10 @@
             zqns_ice(:,:,1:jpl) = frcv(jpr_qnsice)%z3(:,:,1:jpl)
          ELSE
-            DO jl=1,jpl
+            DO jl = 1, jpl
                zqns_ice(:,:,jl) = frcv(jpr_qnsice)%z3(:,:,1) ! Set all category values equal
-            ENDDO
+            END DO
          ENDIF
       CASE( 'oce and ice' )      ! the total flux is computed from ocean and ice fluxes
-         zqns_tot(:,:) =  p_frld(:,:) * frcv(jpr_qnsoce)%z3(:,:,1)
+         zqns_tot(:,:) =  ziceld(:,:) * frcv(jpr_qnsoce)%z3(:,:,1)
          IF ( TRIM(sn_rcv_qns%clcat) == 'yes' ) THEN
             DO jl=1,jpl
@@ -1745,9 +1849,9 @@
             ENDDO
          ELSE
-            qns_tot(:,:) = qns_tot(:,:) + zicefr(:,:) * frcv(jpr_qnsice)%z3(:,:,1)
-            DO jl=1,jpl
-               zqns_tot(:,:   ) = zqns_tot(:,:) + zicefr(:,:) * frcv(jpr_qnsice)%z3(:,:,1)
+            qns_tot(:,:) = qns_tot(:,:) + picefr(:,:) * frcv(jpr_qnsice)%z3(:,:,1)
+            DO jl = 1, jpl
+               zqns_tot(:,:   ) = zqns_tot(:,:) + picefr(:,:) * frcv(jpr_qnsice)%z3(:,:,1)
                zqns_ice(:,:,jl) = frcv(jpr_qnsice)%z3(:,:,1)
-            ENDDO
+            END DO
          ENDIF
       CASE( 'mixed oce-ice' )    ! the ice flux is cumputed from the total flux, the SST and ice informations
@@ -1755,6 +1859,6 @@
          zqns_tot(:,:  ) = frcv(jpr_qnsmix)%z3(:,:,1)
          zqns_ice(:,:,1) = frcv(jpr_qnsmix)%z3(:,:,1)    &
-            &            + frcv(jpr_dqnsdt)%z3(:,:,1) * ( pist(:,:,1) - ( (rt0 + psst(:,:  ) ) * p_frld(:,:)   &
-            &                                           + pist(:,:,1) * zicefr(:,:) ) )
+            &            + frcv(jpr_dqnsdt)%z3(:,:,1) * ( pist(:,:,1) - ( (rt0 + psst(:,:  ) ) * ziceld(:,:)   &
+            &                                           + pist(:,:,1) * picefr(:,:) ) )
       END SELECT
       !                                     
@@ -1767,7 +1871,7 @@
 #if defined key_lim3      
       ! --- non solar flux over ocean --- !
-      !         note: p_frld cannot be = 0 since we limit the ice concentration to amax
+      !         note: ziceld cannot be = 0 since we limit the ice concentration to amax
       zqns_oce = 0._wp
-      WHERE( p_frld /= 0._wp )  zqns_oce(:,:) = ( zqns_tot(:,:) - SUM( a_i * zqns_ice, dim=3 ) ) / p_frld(:,:)
+      WHERE( ziceld /= 0._wp )   zqns_oce(:,:) = ( zqns_tot(:,:) - SUM( a_i * zqns_ice, dim=3 ) ) / ziceld(:,:)
 
       ! Heat content per unit mass of snow (J/kg)
@@ -1776,5 +1880,5 @@
       ENDWHERE
       ! Heat content per unit mass of rain (J/kg)
-      zcptrain(:,:) = rcp * ( SUM( (tn_ice(:,:,:) - rt0) * a_i(:,:,:), dim=3 ) + sst_m(:,:) * p_frld(:,:) ) 
+      zcptrain(:,:) = rcp * ( SUM( (tn_ice(:,:,:) - rt0) * a_i(:,:,:), dim=3 ) + sst_m(:,:) * ziceld(:,:) ) 
 
       ! --- enthalpy of snow precip over ice in J/m3 (to be used in 1D-thermo) --- !
@@ -1791,5 +1895,5 @@
          &             +   zsprecip(:,:)                   * ( 1._wp - zsnw ) * ( zcptsnw (:,:) - lfus )   ! solid precip over ocean + snow melting
       zqemp_ice(:,:) =     zsprecip(:,:)                   * zsnw             * ( zcptsnw (:,:) - lfus )   ! solid precip over ice (qevap_ice=0 since atm. does not take it into account)
-!!    zqemp_ice(:,:) = -   frcv(jpr_ievp)%z3(:,:,1)        * zicefr(:,:)      *   zcptsnw (:,:)   &        ! ice evap
+!!    zqemp_ice(:,:) = -   frcv(jpr_ievp)%z3(:,:,1)        * picefr(:,:)      *   zcptsnw (:,:)   &        ! ice evap
 !!       &             +   zsprecip(:,:)                   * zsnw             * zqprec_ice(:,:) * r1_rhosn ! solid precip over ice
       
@@ -1824,10 +1928,10 @@
       ! clem: this formulation is certainly wrong... but better than it was...
       zqns_tot(:,:) = zqns_tot(:,:)                            &          ! zqns_tot update over free ocean with:
-         &          - (  p_frld(:,:) * zsprecip(:,:) * lfus )  &          ! remove the latent heat flux of solid precip. melting
+         &          - (  ziceld(:,:) * zsprecip(:,:) * lfus )  &          ! remove the latent heat flux of solid precip. melting
          &          - (  zemp_tot(:,:)                         &          ! remove the heat content of mass flux (assumed to be at SST)
          &             - zemp_ice(:,:) ) * zcptn(:,:) 
 
      IF( ln_mixcpl ) THEN
-         qns_tot(:,:) = qns(:,:) * p_frld(:,:) + SUM( qns_ice(:,:,:) * a_i(:,:,:), dim=3 )   ! total flux from blk
+         qns_tot(:,:) = qns(:,:) * ziceld(:,:) + SUM( qns_ice(:,:,:) * a_i(:,:,:), dim=3 )   ! total flux from blk
          qns_tot(:,:) = qns_tot(:,:) * xcplmask(:,:,0) +  zqns_tot(:,:)* zmsk(:,:)
          DO jl=1,jpl
@@ -1841,16 +1945,12 @@
 #endif
       ! outputs
-      IF( srcv(jpr_cal)%laction )    CALL iom_put('hflx_cal_cea' ,   &
-                                             &   - frcv(jpr_cal)%z3(:,:,1) * lfus) ! latent heat from calving
-      IF( srcv(jpr_icb)%laction )    CALL iom_put('hflx_icb_cea' , - frcv(jpr_icb)%z3(:,:,1) * lfus) ! latent heat from icebergs melting
-      IF( iom_use('hflx_snow_cea') ) CALL iom_put('hflx_snow_cea',  sprecip(:,:) * ( zcptsnw(:,:) - Lfus )) ! heat flux from snow (cell average)
-      IF( iom_use('hflx_rain_cea') ) CALL iom_put('hflx_rain_cea',( tprecip(:,:) - sprecip(:,:) ) * zcptrain(:,:)) ! heat flux from rain (cell average)
-      IF( iom_use('hflx_evap_cea') ) CALL iom_put('hflx_evap_cea',(frcv(jpr_tevp)%z3(:,:,1)   &
-                                             &    - frcv(jpr_ievp)%z3(:,:,1) * zicefr(:,:) & ! heat flux from from evap (cell average)
+      IF( srcv(jpr_cal)%laction )    CALL iom_put('hflx_cal_cea' , - frcv(jpr_cal)%z3(:,:,1) * lfus                                  ) ! latent heat from calving
+      IF( srcv(jpr_icb)%laction )    CALL iom_put('hflx_icb_cea' , - frcv(jpr_icb)%z3(:,:,1) * lfus                                  ) ! latent heat from icebergs melting
+      IF( iom_use('hflx_snow_cea') ) CALL iom_put('hflx_snow_cea',  sprecip(:,:) * ( zcptsnw(:,:) - Lfus )                           ) ! heat flux from snow (cell average)
+      IF( iom_use('hflx_rain_cea') ) CALL iom_put('hflx_rain_cea',( tprecip(:,:) - sprecip(:,:) ) * zcptrain(:,:)                    ) ! heat flux from rain (cell average)
+      IF( iom_use('hflx_evap_cea') ) CALL iom_put('hflx_evap_cea',(frcv(jpr_tevp)%z3(:,:,1) - frcv(jpr_ievp)%z3(:,:,1) * picefr(:,:) & ! heat flux from from evap (cell average)
          &                                                        ) * zcptn(:,:) * tmask(:,:,1) )
-      IF( iom_use('hflx_snow_ao_cea') ) CALL iom_put('hflx_snow_ao_cea',sprecip(:,:)   &
-                                             & * (zcptsnw(:,:) - Lfus) * (1._wp - zsnw(:,:))   ) ! heat flux from snow (over ocean)
-      IF( iom_use('hflx_snow_ai_cea') ) CALL iom_put('hflx_snow_ai_cea',sprecip(:,:) * (zcptsnw(:,:) - Lfus)   &
-                                             & *          zsnw(:,:)    ) ! heat flux from snow (over ice)
+      IF( iom_use('hflx_snow_ao_cea') ) CALL iom_put('hflx_snow_ao_cea',sprecip(:,:) * (zcptsnw(:,:) - Lfus) * (1._wp - zsnw(:,:))   ) ! heat flux from snow (over ocean)
+      IF( iom_use('hflx_snow_ai_cea') ) CALL iom_put('hflx_snow_ai_cea',sprecip(:,:) * (zcptsnw(:,:) - Lfus) *          zsnw(:,:)    ) ! heat flux from snow (over ice)
       ! note: hflx for runoff and iceshelf are done in sbcrnf and sbcisf resp.
       !
@@ -1866,23 +1966,23 @@
          ELSE
             ! Set all category values equal for the moment
-            DO jl=1,jpl
+            DO jl = 1, jpl
                zqsr_ice(:,:,jl) = frcv(jpr_qsrice)%z3(:,:,1)
-            ENDDO
+            END DO
          ENDIF
          zqsr_tot(:,:  ) = frcv(jpr_qsrmix)%z3(:,:,1)
          zqsr_ice(:,:,1) = frcv(jpr_qsrice)%z3(:,:,1)
       CASE( 'oce and ice' )
-         zqsr_tot(:,:  ) =  p_frld(:,:) * frcv(jpr_qsroce)%z3(:,:,1)
+         zqsr_tot(:,:  ) =  ziceld(:,:) * frcv(jpr_qsroce)%z3(:,:,1)
          IF ( TRIM(sn_rcv_qsr%clcat) == 'yes' ) THEN
-            DO jl=1,jpl
+            DO jl = 1, jpl
                zqsr_tot(:,:   ) = zqsr_tot(:,:) + a_i(:,:,jl) * frcv(jpr_qsrice)%z3(:,:,jl)   
                zqsr_ice(:,:,jl) = frcv(jpr_qsrice)%z3(:,:,jl)
-            ENDDO
+            END DO
          ELSE
-            qsr_tot(:,:   ) = qsr_tot(:,:) + zicefr(:,:) * frcv(jpr_qsrice)%z3(:,:,1)
-            DO jl=1,jpl
-               zqsr_tot(:,:   ) = zqsr_tot(:,:) + zicefr(:,:) * frcv(jpr_qsrice)%z3(:,:,1)
+            qsr_tot(:,:   ) = qsr_tot(:,:) + picefr(:,:) * frcv(jpr_qsrice)%z3(:,:,1)
+            DO jl = 1, jpl
+               zqsr_tot(:,:   ) = zqsr_tot(:,:) + picefr(:,:) * frcv(jpr_qsrice)%z3(:,:,1)
                zqsr_ice(:,:,jl) = frcv(jpr_qsrice)%z3(:,:,1)
-            ENDDO
+            END DO
          ENDIF
       CASE( 'mixed oce-ice' )
@@ -1892,19 +1992,19 @@
 !       ( see OASIS3 user guide, 5th edition, p39 )
          zqsr_ice(:,:,1) = frcv(jpr_qsrmix)%z3(:,:,1) * ( 1.- palbi(:,:,1) )   &
-            &            / (  1.- ( albedo_oce_mix(:,:  ) * p_frld(:,:)       &
-            &                     + palbi         (:,:,1) * zicefr(:,:) ) )
+            &            / (  1.- ( alb_oce_mix(:,:  ) * ziceld(:,:)       &
+            &                     + palbi      (:,:,1) * picefr(:,:) ) )
       END SELECT
       IF( ln_dm2dc .AND. ln_cpl ) THEN   ! modify qsr to include the diurnal cycle
          zqsr_tot(:,:  ) = sbc_dcy( zqsr_tot(:,:  ) )
-         DO jl=1,jpl
+         DO jl = 1, jpl
             zqsr_ice(:,:,jl) = sbc_dcy( zqsr_ice(:,:,jl) )
-         ENDDO
+         END DO
       ENDIF
 
 #if defined key_lim3
       ! --- solar flux over ocean --- !
-      !         note: p_frld cannot be = 0 since we limit the ice concentration to amax
+      !         note: ziceld cannot be = 0 since we limit the ice concentration to amax
       zqsr_oce = 0._wp
-      WHERE( p_frld /= 0._wp )  zqsr_oce(:,:) = ( zqsr_tot(:,:) - SUM( a_i * zqsr_ice, dim=3 ) ) / p_frld(:,:)
+      WHERE( ziceld /= 0._wp )  zqsr_oce(:,:) = ( zqsr_tot(:,:) - SUM( a_i * zqsr_ice, dim=3 ) ) / ziceld(:,:)
 
       IF( ln_mixcpl ) THEN   ;   qsr_oce(:,:) = qsr_oce(:,:) * xcplmask(:,:,0) +  zqsr_oce(:,:)* zmsk(:,:)
@@ -1913,9 +2013,9 @@
 
       IF( ln_mixcpl ) THEN
-         qsr_tot(:,:) = qsr(:,:) * p_frld(:,:) + SUM( qsr_ice(:,:,:) * a_i(:,:,:), dim=3 )   ! total flux from blk
+         qsr_tot(:,:) = qsr(:,:) * ziceld(:,:) + SUM( qsr_ice(:,:,:) * a_i(:,:,:), dim=3 )   ! total flux from blk
          qsr_tot(:,:) = qsr_tot(:,:) * xcplmask(:,:,0) +  zqsr_tot(:,:)* zmsk(:,:)
-         DO jl=1,jpl
+         DO jl = 1, jpl
             qsr_ice(:,:,jl) = qsr_ice(:,:,jl) * xcplmask(:,:,0) +  zqsr_ice(:,:,jl)* zmsk(:,:)
-         ENDDO
+         END DO
       ELSE
          qsr_tot(:,:  ) = zqsr_tot(:,:  )
@@ -1944,25 +2044,36 @@
          dqns_ice(:,:,:) = zdqns_ice(:,:,:)
       ENDIF
-      
+
+#if defined key_lim3      
       !                                                      ! ========================= !
-      SELECT CASE( TRIM( sn_rcv_iceflx%cldes ) )             !    topmelt and botmelt    !
+      SELECT CASE( TRIM( sn_rcv_iceflx%cldes ) )             !  ice topmelt and botmelt  !
       !                                                      ! ========================= !
       CASE ('coupled')
-         topmelt(:,:,:)=frcv(jpr_topm)%z3(:,:,:)
-         botmelt(:,:,:)=frcv(jpr_botm)%z3(:,:,:)
+         qml_ice(:,:,:) = frcv(jpr_topm)%z3(:,:,:) * a_i(:,:,:)
+         qcn_ice(:,:,:) = frcv(jpr_botm)%z3(:,:,:) * a_i(:,:,:)
       END SELECT
-
-      ! Surface transimission parameter io (Maykut Untersteiner , 1971 ; Ebert and Curry, 1993 )
-      ! Used for LIM2 and LIM3
-      ! Coupled case: since cloud cover is not received from atmosphere 
-      !               ===> used prescribed cloud fraction representative for polar oceans in summer (0.81)
-      fr1_i0(:,:) = ( 0.18 * ( 1.0 - cldf_ice ) + 0.35 * cldf_ice )
-      fr2_i0(:,:) = ( 0.82 * ( 1.0 - cldf_ice ) + 0.65 * cldf_ice )
-
-      CALL wrk_dealloc( jpi,jpj,     zcptn, zcptrain, zcptsnw, zicefr, zmsk, zsnw )
-      CALL wrk_dealloc( jpi,jpj,     zemp_tot, zemp_ice, zemp_oce, ztprecip, zsprecip, zevap_oce, zevap_ice, zdevap_ice )
-      CALL wrk_dealloc( jpi,jpj,     zqns_tot, zqns_oce, zqsr_tot, zqsr_oce, zqprec_ice, zqemp_oce, zqemp_ice )
-      CALL wrk_dealloc( jpi,jpj,jpl, zqns_ice, zqsr_ice, zdqns_ice, zqevap_ice )
-      !
+      !
+      !                                                      ! ========================= !
+      !                                                      !      Transmitted Qsr      !   [W/m2]
+      !                                                      ! ========================= !
+      SELECT CASE( nice_jules )
+      CASE( np_jules_OFF    )       !==  No Jules coupler  ==!
+         !
+         !                    ! ===> used prescribed cloud fraction representative for polar oceans in summer (0.81)
+         ztri = 0.18 * ( 1.0 - cldf_ice ) + 0.35 * cldf_ice    ! surface transmission parameter (Grenfell Maykut 77)
+         !
+         qsr_ice_tr(:,:,:) = ztri * qsr_ice(:,:,:)
+         WHERE( phs(:,:,:) >= 0.0_wp )   qsr_ice_tr(:,:,:) = 0._wp            ! snow fully opaque
+         WHERE( phi(:,:,:) <= 0.1_wp )   qsr_ice_tr(:,:,:) = qsr_ice(:,:,:)   ! thin ice transmits all solar radiation
+         !     
+      CASE( np_jules_ACTIVE )       !==  Jules coupler is active  ==!
+         !
+         !                    ! ===> here we must receive the qsr_ice_tr array from the coupler
+         !                           for now just assume zero (fully opaque ice)
+         qsr_ice_tr(:,:,:) = 0._wp
+         !
+      END SELECT
+      !
+#endif
       IF( nn_timing == 1 )   CALL timing_stop('sbc_cpl_ice_flx')
       !
@@ -1984,13 +2095,10 @@
       INTEGER ::   isec, info   ! local integer
       REAL(wp) ::   zumax, zvmax
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zfr_l, ztmp1, ztmp2, zotx1, zoty1, zotz1, zitx1, zity1, zitz1
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztmp3, ztmp4   
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zfr_l, ztmp1, ztmp2, zotx1, zoty1, zotz1, zitx1, zity1, zitz1
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   ztmp3, ztmp4   
       !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )   CALL timing_start('sbc_cpl_snd')
       !
-      CALL wrk_alloc( jpi,jpj,       zfr_l, ztmp1, ztmp2, zotx1, zoty1, zotz1, zitx1, zity1, zitz1 )
-      CALL wrk_alloc( jpi,jpj,jpl,   ztmp3, ztmp4 )
-
       isec = ( kt - nit000 ) * NINT( rdt )        ! date of exchanges
 
@@ -2006,5 +2114,5 @@
             ! we must send the surface potential temperature 
             IF( l_useCT )  THEN    ;   ztmp1(:,:) = eos_pt_from_ct( tsn(:,:,1,jp_tem), tsn(:,:,1,jp_sal) )
-            ELSE                    ;   ztmp1(:,:) = tsn(:,:,1,jp_tem)
+            ELSE                   ;   ztmp1(:,:) = tsn(:,:,1,jp_tem)
             ENDIF
             !
@@ -2034,4 +2142,15 @@
                CASE default                  ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_temp%clcat' )
                END SELECT
+            CASE( 'oce and weighted ice')    ;   ztmp1(:,:) =   tsn(:,:,1,jp_tem) + rt0  
+               SELECT CASE( sn_snd_temp%clcat ) 
+               CASE( 'yes' )    
+                  ztmp3(:,:,1:jpl) = tn_ice(:,:,1:jpl) * a_i(:,:,1:jpl) 
+               CASE( 'no' ) 
+                  ztmp3(:,:,:) = 0.0 
+                  DO jl=1,jpl 
+                     ztmp3(:,:,1) = ztmp3(:,:,1) + tn_ice(:,:,jl) * a_i(:,:,jl) 
+                  ENDDO 
+               CASE default                  ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_temp%clcat' ) 
+               END SELECT 
             CASE( 'mixed oce-ice'        )   
                ztmp1(:,:) = ( ztmp1(:,:) + rt0 ) * zfr_l(:,:) 
@@ -2046,4 +2165,19 @@
          IF( ssnd(jps_tmix)%laction )   CALL cpl_snd( jps_tmix, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info )
       ENDIF
+      !
+      !                                                      ! ------------------------- !
+      !                                                      ! 1st layer ice/snow temp.  !
+      !                                                      ! ------------------------- !
+#if defined key_lim3
+      ! needed by  Met Office
+      IF( ssnd(jps_ttilyr)%laction) THEN
+         SELECT CASE( sn_snd_ttilyr%cldes)
+         CASE ('weighted ice')
+            ztmp3(:,:,1:jpl) = t1_ice(:,:,1:jpl) * a_i(:,:,1:jpl) 
+         CASE default                     ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_ttilyr%cldes' )
+         END SELECT
+         IF( ssnd(jps_ttilyr)%laction )   CALL cpl_snd( jps_ttilyr, isec, ztmp3, info )
+      ENDIF
+#endif
       !                                                      ! ------------------------- !
       !                                                      !           Albedo          !
@@ -2059,5 +2193,5 @@
                    ztmp1(:,:) = SUM( alb_ice (:,:,1:jpl) * a_i(:,:,1:jpl), dim=3 ) / SUM( a_i(:,:,1:jpl), dim=3 )
                 ELSEWHERE
-                   ztmp1(:,:) = albedo_oce_mix(:,:)
+                   ztmp1(:,:) = alb_oce_mix(:,:)
                 END WHERE
              CASE default   ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_alb%clcat' )
@@ -2087,8 +2221,8 @@
 
       IF( ssnd(jps_albmix)%laction ) THEN                         ! mixed ice-ocean
-         ztmp1(:,:) = albedo_oce_mix(:,:) * zfr_l(:,:)
-         DO jl=1,jpl
+         ztmp1(:,:) = alb_oce_mix(:,:) * zfr_l(:,:)
+         DO jl = 1, jpl
             ztmp1(:,:) = ztmp1(:,:) + alb_ice(:,:,jl) * a_i(:,:,jl)
-         ENDDO
+         END DO
          CALL cpl_snd( jps_albmix, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info )
       ENDIF
@@ -2105,4 +2239,13 @@
          IF( ssnd(jps_fice)%laction )   CALL cpl_snd( jps_fice, isec, ztmp3, info )
       ENDIF
+
+      IF( ssnd(jps_fice1)%laction ) THEN
+         SELECT CASE( sn_snd_thick1%clcat )
+         CASE( 'yes' )   ;   ztmp3(:,:,1:jpl) =  a_i(:,:,1:jpl)
+         CASE( 'no'  )   ;   ztmp3(:,:,1    ) = fr_i(:,:      )
+         CASE default    ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_thick1%clcat' )
+         END SELECT
+         CALL cpl_snd( jps_fice1, isec, ztmp3, info )
+      ENDIF
       
       ! Send ice fraction field to OPA (sent by SAS in SAS-OPA coupling)
@@ -2119,11 +2262,11 @@
             SELECT CASE( sn_snd_thick%clcat )
             CASE( 'yes' )   
-               ztmp3(:,:,1:jpl) =  ht_i(:,:,1:jpl) * a_i(:,:,1:jpl)
-               ztmp4(:,:,1:jpl) =  ht_s(:,:,1:jpl) * a_i(:,:,1:jpl)
+               ztmp3(:,:,1:jpl) =  h_i(:,:,1:jpl) * a_i(:,:,1:jpl)
+               ztmp4(:,:,1:jpl) =  h_s(:,:,1:jpl) * a_i(:,:,1:jpl)
             CASE( 'no' )
                ztmp3(:,:,:) = 0.0   ;  ztmp4(:,:,:) = 0.0
                DO jl=1,jpl
-                  ztmp3(:,:,1) = ztmp3(:,:,1) + ht_i(:,:,jl) * a_i(:,:,jl)
-                  ztmp4(:,:,1) = ztmp4(:,:,1) + ht_s(:,:,jl) * a_i(:,:,jl)
+                  ztmp3(:,:,1) = ztmp3(:,:,1) + h_i(:,:,jl) * a_i(:,:,jl)
+                  ztmp4(:,:,1) = ztmp4(:,:,1) + h_s(:,:,jl) * a_i(:,:,jl)
                ENDDO
             CASE default                  ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_thick%clcat' )
@@ -2132,10 +2275,10 @@
             SELECT CASE( sn_snd_thick%clcat )
             CASE( 'yes' )
-               ztmp3(:,:,1:jpl) = ht_i(:,:,1:jpl)
-               ztmp4(:,:,1:jpl) = ht_s(:,:,1:jpl)
+               ztmp3(:,:,1:jpl) = h_i(:,:,1:jpl)
+               ztmp4(:,:,1:jpl) = h_s(:,:,1:jpl)
             CASE( 'no' )
                WHERE( SUM( a_i, dim=3 ) /= 0. )
-                  ztmp3(:,:,1) = SUM( ht_i * a_i, dim=3 ) / SUM( a_i, dim=3 )
-                  ztmp4(:,:,1) = SUM( ht_s * a_i, dim=3 ) / SUM( a_i, dim=3 )
+                  ztmp3(:,:,1) = SUM( h_i * a_i, dim=3 ) / SUM( a_i, dim=3 )
+                  ztmp4(:,:,1) = SUM( h_s * a_i, dim=3 ) / SUM( a_i, dim=3 )
                ELSEWHERE
                  ztmp3(:,:,1) = 0.
@@ -2149,4 +2292,57 @@
          IF( ssnd(jps_hsnw)%laction )   CALL cpl_snd( jps_hsnw, isec, ztmp4, info )
       ENDIF
+
+#if defined key_lim3
+      !                                                      ! ------------------------- !
+      !                                                      !      Ice melt ponds       ! 
+      !                                                      ! ------------------------- !
+      ! needed by Met Office
+      IF( ssnd(jps_a_p)%laction .OR. ssnd(jps_ht_p)%laction ) THEN 
+         SELECT CASE( sn_snd_mpnd%cldes)  
+         CASE( 'ice only' )  
+            SELECT CASE( sn_snd_mpnd%clcat )  
+            CASE( 'yes' )  
+               ztmp3(:,:,1:jpl) =  a_ip(:,:,1:jpl)
+               ztmp4(:,:,1:jpl) =  v_ip(:,:,1:jpl)  
+            CASE( 'no' )  
+               ztmp3(:,:,:) = 0.0  
+               ztmp4(:,:,:) = 0.0  
+               DO jl=1,jpl  
+                 ztmp3(:,:,1) = ztmp3(:,:,1) + a_ip(:,:,jpl)  
+                 ztmp4(:,:,1) = ztmp4(:,:,1) + v_ip(:,:,jpl) 
+               ENDDO  
+            CASE default   ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_mpnd%clcat' )  
+            END SELECT  
+         CASE default      ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_mpnd%cldes' )     
+         END SELECT  
+         IF( ssnd(jps_a_p)%laction  )   CALL cpl_snd( jps_a_p , isec, ztmp3, info )     
+         IF( ssnd(jps_ht_p)%laction )   CALL cpl_snd( jps_ht_p, isec, ztmp4, info )     
+      ENDIF 
+      ! 
+      !                                                      ! ------------------------- !
+      !                                                      !     Ice conductivity      ! 
+      !                                                      ! ------------------------- !
+      ! needed by Met Office
+      IF( ssnd(jps_kice)%laction ) THEN 
+         SELECT CASE( sn_snd_cond%cldes) 
+         CASE( 'weighted ice' )    
+            SELECT CASE( sn_snd_cond%clcat ) 
+            CASE( 'yes' )    
+	       ztmp3(:,:,1:jpl) =  cnd_ice(:,:,1:jpl) * a_i(:,:,1:jpl) 
+            CASE( 'no' ) 
+               ztmp3(:,:,:) = 0.0 
+               DO jl=1,jpl 
+                 ztmp3(:,:,1) = ztmp3(:,:,1) + cnd_ice(:,:,jl) * a_i(:,:,jl) 
+               ENDDO 
+            CASE default   ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_cond%clcat' ) 
+            END SELECT 
+         CASE( 'ice only' )    
+           ztmp3(:,:,1:jpl) = cnd_ice(:,:,1:jpl) 
+         CASE default      ;   CALL ctl_stop( 'sbc_cpl_snd: wrong definition of sn_snd_cond%cldes' )     
+         END SELECT 
+         IF( ssnd(jps_kice)%laction )   CALL cpl_snd( jps_kice, isec, ztmp3, info ) 
+      ENDIF 
+#endif
+
       !                                                      ! ------------------------- !
       !                                                      !  CO2 flux from PISCES     ! 
@@ -2470,6 +2666,13 @@
       IF( ssnd(jps_taum  )%laction )  CALL cpl_snd( jps_taum  , isec, RESHAPE ( taum, (/jpi,jpj,1/) ), info )
 
-      CALL wrk_dealloc( jpi,jpj,       zfr_l, ztmp1, ztmp2, zotx1, zoty1, zotz1, zitx1, zity1, zitz1 )
-      CALL wrk_dealloc( jpi,jpj,jpl,   ztmp3, ztmp4 )
+#if defined key_lim3
+      !                                                      ! ------------------------- !
+      !                                                      ! Sea surface freezing temp ! 
+      !                                                      ! ------------------------- !
+      ! needed by Met Office
+      CALL eos_fzp(tsn(:,:,1,jp_sal), sstfrz)
+      ztmp1(:,:) = sstfrz(:,:) + rt0
+      IF( ssnd(jps_sstfrz)%laction )  CALL cpl_snd( jps_sstfrz, isec, RESHAPE ( ztmp1, (/jpi,jpj,1/) ), info)
+#endif
       !
       IF( nn_timing == 1 )   CALL timing_stop('sbc_cpl_snd')
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcfwb.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcfwb.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcfwb.F90	(revision 9019)
@@ -17,4 +17,5 @@
    USE dom_oce        ! ocean space and time domain
    USE sbc_oce        ! surface ocean boundary condition
+   USE sbc_ice , ONLY : snwice_mass, snwice_mass_b, snwice_fmass
    USE phycst         ! physical constants
    USE sbcrnf         ! ocean runoffs
@@ -94,5 +95,5 @@
          ! and in case of no melt, it can generate HSSW.
          !
-#if ! defined key_lim2 &&  ! defined key_lim3 && ! defined key_cice
+#if ! defined key_lim3 && ! defined key_cice
          snwice_mass_b(:,:) = 0.e0               ! no sea-ice model is being used : no snow+ice mass
          snwice_mass  (:,:) = 0.e0
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90	(revision 9019)
@@ -137,5 +137,5 @@
             CALL cice_sbc_force(kt)
          ELSE IF ( ksbc == jp_purecpl ) THEN
-            CALL sbc_cpl_ice_flx( 1.0-fr_i  )
+            CALL sbc_cpl_ice_flx( fr_i )
          ENDIF
 
@@ -230,16 +230,12 @@
       CALL lbc_lnk ( fr_iv , 'V', 1. )
 
-      !                                      ! embedded sea ice
-      IF( nn_ice_embd /= 0 ) THEN            ! mass exchanges between ice and ocean (case 1 or 2) set the snow+ice mass
-         CALL cice2nemo(vsno(:,:,:),ztmp1,'T', 1. )
-         CALL cice2nemo(vice(:,:,:),ztmp2,'T', 1. )
-         snwice_mass  (:,:) = ( rhosn * ztmp1(:,:) + rhoic * ztmp2(:,:)  )
-         snwice_mass_b(:,:) = snwice_mass(:,:)
-      ELSE
-         snwice_mass  (:,:) = 0.0_wp         ! no mass exchanges
-         snwice_mass_b(:,:) = 0.0_wp         ! no mass exchanges
-      ENDIF
+      ! set the snow+ice mass
+      CALL cice2nemo(vsno(:,:,:),ztmp1,'T', 1. )
+      CALL cice2nemo(vice(:,:,:),ztmp2,'T', 1. )
+      snwice_mass  (:,:) = ( rhosn * ztmp1(:,:) + rhoic * ztmp2(:,:)  )
+      snwice_mass_b(:,:) = snwice_mass(:,:)
+
       IF( .NOT.ln_rstart ) THEN
-         IF( nn_ice_embd == 2 ) THEN            ! full embedment (case 2) deplete the initial ssh below sea-ice area
+         IF( ln_ice_embd ) THEN            ! embedded sea-ice: deplete the initial ssh below sea-ice area
             sshn(:,:) = sshn(:,:) - snwice_mass(:,:) * r1_rau0
             sshb(:,:) = sshb(:,:) - snwice_mass(:,:) * r1_rau0
@@ -473,5 +469,5 @@
       CALL nemo2cice(ztmp,vocn,'F', -1. )
 
-      IF( nn_ice_embd == 2 ) THEN             !== embedded sea ice: compute representative ice top surface ==!
+      IF( ln_ice_embd ) THEN             !== embedded sea ice: compute representative ice top surface ==!
           !
           ! average interpolation coeff as used in dynspg = (1/nn_fsbc) * {SUM[n/nn_fsbc], n=0,nn_fsbc-1}
@@ -676,12 +672,10 @@
       CALL lbc_lnk ( fr_iv , 'V', 1. )
 
-      !                                      ! embedded sea ice
-      IF( nn_ice_embd /= 0 ) THEN            ! mass exchanges between ice and ocean (case 1 or 2) set the snow+ice mass
-         CALL cice2nemo(vsno(:,:,:),ztmp1,'T', 1. )
-         CALL cice2nemo(vice(:,:,:),ztmp2,'T', 1. )
-         snwice_mass  (:,:) = ( rhosn * ztmp1(:,:) + rhoic * ztmp2(:,:)  )
-         snwice_mass_b(:,:) = snwice_mass(:,:)
-         snwice_fmass (:,:) = ( snwice_mass(:,:) - snwice_mass_b(:,:) ) / dt
-      ENDIF
+      ! set the snow+ice mass
+      CALL cice2nemo(vsno(:,:,:),ztmp1,'T', 1. )
+      CALL cice2nemo(vice(:,:,:),ztmp2,'T', 1. )
+      snwice_mass  (:,:) = ( rhosn * ztmp1(:,:) + rhoic * ztmp2(:,:)  )
+      snwice_mass_b(:,:) = snwice_mass(:,:)
+      snwice_fmass (:,:) = ( snwice_mass(:,:) - snwice_mass_b(:,:) ) / dt
 
 ! Release work space
@@ -716,18 +710,18 @@
       !                                         !   Prepare Coupling fields   !
       !                                         ! =========================== !
-
-! x and y comp of ice velocity
-
+      !
+      ! x and y comp of ice velocity
+      !
       CALL cice2nemo(uvel,u_ice,'F', -1. )
       CALL cice2nemo(vvel,v_ice,'F', -1. )
-
-! Ice concentration (CO_1) = a_i calculated at end of cice_sbc_out  
-
-! Snow and ice thicknesses (CO_2 and CO_3)
-
-      DO jl = 1,ncat
-         CALL cice2nemo(vsnon(:,:,jl,:),ht_s(:,:,jl),'T', 1. )
-         CALL cice2nemo(vicen(:,:,jl,:),ht_i(:,:,jl),'T', 1. )
-      ENDDO
+      !
+      ! Ice concentration (CO_1) = a_i calculated at end of cice_sbc_out  
+      !
+      ! Snow and ice thicknesses (CO_2 and CO_3)
+      !
+      DO jl = 1, ncat
+         CALL cice2nemo( vsnon(:,:,jl,:), h_s(:,:,jl),'T', 1. )
+         CALL cice2nemo( vicen(:,:,jl,:), h_i(:,:,jl),'T', 1. )
+      END DO
       !
       IF( nn_timing == 1 )  CALL timing_stop('cice_sbc_hadgam')
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 9018)
+++ 	(revision )
@@ -1,688 +1,0 @@
-MODULE sbcice_lim
-   !!======================================================================
-   !!                       ***  MODULE  sbcice_lim  ***
-   !! Surface module :  update the ocean surface boundary condition over ice
-   !!       &           covered area using LIM sea-ice model
-   !! Sea-Ice model  :  LIM-3 Sea ice model time-stepping
-   !!=====================================================================
-   !! History :  2.0  ! 2006-12  (M. Vancoppenolle) Original code
-   !!            3.0  ! 2008-02  (C. Talandier)  Surface module from icestp.F90
-   !!             -   ! 2008-04  (G. Madec)  sltyle and lim_ctl routine
-   !!            3.3  ! 2010-11  (G. Madec) ice-ocean stress always computed at each ocean time-step
-   !!            3.4  ! 2011-01  (A Porter)  dynamical allocation
-   !!             -   ! 2012-10  (C. Rousset)  add lim_diahsb
-   !!            3.6  ! 2014-07  (M. Vancoppenolle, G. Madec, O. Marti) revise coupled interface
-   !!            4.0  ! 2016-06  (L. Brodeau) new unified bulk routine (based on AeroBulk)
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                  LIM 3.0 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   sbc_ice_lim  : sea-ice model time-stepping and update ocean sbc over ice-covered area
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE ice             ! LIM-3: ice variables
-   USE thd_ice         ! LIM-3: thermodynamical variables
-   !
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice   fields
-   USE usrdef_sbc      ! user defined: surface boundary condition
-   USE sbcblk          ! Surface boundary condition: bulk
-   USE sbccpl          ! Surface boundary condition: coupled interface
-   USE albedo          ! ocean & ice albedo
-   !
-   USE phycst          ! Define parameters for the routines
-   USE eosbn2          ! equation of state
-   USE limdyn          ! Ice dynamics
-   USE limtrp          ! Ice transport
-   USE limhdf          ! Ice horizontal diffusion
-   USE limthd          ! Ice thermodynamics
-   USE limitd_me       ! Mechanics on ice thickness distribution
-   USE limsbc          ! sea surface boundary condition
-   USE limdiahsb       ! Ice budget diagnostics
-   USE limwri          ! Ice outputs
-   USE limrst          ! Ice restarts
-   USE limupdate1      ! update of global variables
-   USE limupdate2      ! update of global variables
-   USE limvar          ! Ice variables switch
-   USE limctl          !
-   USE limistate       ! LIM initial state
-   USE limthd_sal      ! LIM ice thermodynamics: salinity
-   !
-   USE c1d             ! 1D vertical configuration
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O manager library
-   USE prtctl          ! Print control
-   USE lib_fortran     !
-   USE lbclnk          ! lateral boundary condition - MPP link
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! work arrays
-   USE timing          ! Timing
-
-   USE bdy_oce   , ONLY: ln_bdy
-   USE bdyice_lim      ! unstructured open boundary data  (bdy_ice_lim routine)
-# if defined key_agrif
-   USE agrif_ice
-   USE agrif_lim3_update
-   USE agrif_lim3_interp
-# endif
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC sbc_ice_lim  ! routine called by sbcmod.F90
-   PUBLIC sbc_lim_init ! routine called by sbcmod.F90
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , UCL NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE sbc_ice_lim( kt, ksbc )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE sbc_ice_lim  ***
-      !!
-      !! ** Purpose :   update the ocean surface boundary condition via the
-      !!                Louvain la Neuve Sea Ice Model time stepping
-      !!
-      !! ** Method  :   ice model time stepping
-      !!              - call the ice dynamics routine
-      !!              - call the ice advection/diffusion routine
-      !!              - call the ice thermodynamics routine
-      !!              - call the routine that computes mass and
-      !!                heat fluxes at the ice/ocean interface
-      !!              - save the outputs
-      !!              - save the outputs for restart when necessary
-      !!
-      !! ** Action  : - time evolution of the LIM sea-ice model
-      !!              - update all sbc variables below sea-ice:
-      !!                utau, vtau, taum, wndm, qns , qsr, emp , sfx
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt      ! ocean time step
-      INTEGER, INTENT(in) ::   ksbc    ! type of sbc flux ( 1 = user defined formulation, 
-                                       !                    3 = bulk formulation,
-                                       !                    4 = Pure Coupled formulation)
-      !!
-      INTEGER  ::   jl                 ! dummy loop index
-      REAL(wp), POINTER, DIMENSION(:,:,:)   ::   zalb_os, zalb_cs  ! ice albedo under overcast/clear sky
-      REAL(wp), POINTER, DIMENSION(:,:  )   ::   zutau_ice, zvtau_ice 
-      !!----------------------------------------------------------------------
-
-      IF( nn_timing == 1 )   CALL timing_start('sbc_ice_lim')
-
-      !-----------------------!
-      ! --- Ice time step --- !
-      !-----------------------!
-      IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN
-
-# if defined key_agrif
-         IF( .NOT. Agrif_Root() )  lim_nbstep = MOD( lim_nbstep, Agrif_irhot() * Agrif_Parent(nn_fsbc) / nn_fsbc ) + 1
-# endif
-
-         ! mean surface ocean current at ice velocity point (C-grid dynamics :  U- & V-points as the ocean)
-         u_oce(:,:) = ssu_m(:,:) * umask(:,:,1)
-         v_oce(:,:) = ssv_m(:,:) * vmask(:,:,1)
-
-         ! masked sea surface freezing temperature [Kelvin] (set to rt0 over land)
-         CALL eos_fzp( sss_m(:,:) , t_bo(:,:) )
-         t_bo(:,:) = ( t_bo(:,:) + rt0 ) * tmask(:,:,1) + rt0 * ( 1._wp - tmask(:,:,1) )
-
-         ! Mask sea ice surface temperature (set to rt0 over land)
-         DO jl = 1, jpl
-            t_su(:,:,jl) = t_su(:,:,jl) * tmask(:,:,1) + rt0 * ( 1._wp - tmask(:,:,1) )
-         END DO
-         !
-         !------------------------------------------------!
-         ! --- Dynamical coupling with the atmosphere --- !
-         !------------------------------------------------!
-         ! It provides the following fields:
-         ! utau_ice, vtau_ice : surface ice stress (U- & V-points)   [N/m2]
-         !-----------------------------------------------------------------
-                                      CALL sbc_lim_bef         ! Store previous ice values
-         SELECT CASE( ksbc )
-            CASE( jp_usr     )   ;    CALL usrdef_sbc_ice_tau( kt )                 ! user defined formulation
-            CASE( jp_blk     )   ;    CALL blk_ice_tau                              ! Bulk formulation
-            CASE( jp_purecpl )   ;    CALL sbc_cpl_ice_tau( utau_ice , vtau_ice )   ! Coupled   formulation
-         END SELECT
-
-         IF( ln_mixcpl) THEN                                                       ! Case of a mixed Bulk/Coupled formulation
-            CALL wrk_alloc( jpi,jpj    , zutau_ice, zvtau_ice)
-                                      CALL sbc_cpl_ice_tau( zutau_ice , zvtau_ice )
-            utau_ice(:,:) = utau_ice(:,:) * xcplmask(:,:,0) + zutau_ice(:,:) * ( 1. - xcplmask(:,:,0) )
-            vtau_ice(:,:) = vtau_ice(:,:) * xcplmask(:,:,0) + zvtau_ice(:,:) * ( 1. - xcplmask(:,:,0) )
-            CALL wrk_dealloc( jpi,jpj  , zutau_ice, zvtau_ice)
-         ENDIF
-
-         !-------------------------------------------------------!
-         ! --- ice dynamics and transport (except in 1D case) ---!
-         !-------------------------------------------------------!
-         numit = numit + nn_fsbc                  ! Ice model time step
-         !
-                                      CALL sbc_lim_diag0       ! set diag of mass, heat and salt fluxes to 0
-                                      CALL lim_rst_opn( kt )   ! Open Ice restart file
-         !
-         ! --- zap this if no ice dynamics --- !
-         IF( .NOT. lk_c1d .AND. ln_limdyn ) THEN
-            !
-            IF( nn_limdyn /= 0 ) THEN                          ! -- Ice dynamics
-                                      CALL lim_dyn( kt )       !     rheology  
-            ELSE
-               u_ice(:,:) = rn_uice * umask(:,:,1)             !     or prescribed velocity
-               v_ice(:,:) = rn_vice * vmask(:,:,1)
-            ENDIF
-                                      CALL lim_trp( kt )       ! -- Ice transport (Advection/diffusion)
-            IF( nn_limdyn == 2 .AND. nn_monocat /= 2 )  &      ! -- Mechanical redistribution (ridging/rafting)
-               &                      CALL lim_itd_me         
-            IF( nn_limdyn == 2 )      CALL lim_update1( kt )   ! -- Corrections
-            !
-         ENDIF
-
-         ! ---
-#if defined key_agrif
-         IF( .NOT. Agrif_Root() )     CALL agrif_interp_lim3('T')
-#endif
-         IF( ln_limthd .AND. ln_bdy ) CALL bdy_ice_lim( kt )   ! -- bdy ice thermo 
-         ! previous lead fraction and ice volume for flux calculations
-                                      CALL sbc_lim_bef                        
-                                      CALL lim_var_glo2eqv     ! ht_i and ht_s for ice albedo calculation
-                                      CALL lim_var_agg(1)      ! at_i for coupling (via pfrld) 
-         !
-         pfrld(:,:)   = 1._wp - at_i(:,:)
-         phicif(:,:)  = vt_i(:,:)
-
-         !------------------------------------------------------!
-         ! --- Thermodynamical coupling with the atmosphere --- !
-         !------------------------------------------------------!
-         ! It provides the following fields:
-         ! qsr_ice , qns_ice  : solar & non solar heat flux over ice   (T-point)         [W/m2]
-         ! qla_ice            : latent heat flux over ice              (T-point)         [W/m2]
-         ! dqns_ice, dqla_ice : non solar & latent heat sensistivity   (T-point)         [W/m2]
-         ! tprecip , sprecip  : total & solid precipitation            (T-point)         [Kg/m2/s]
-         ! fr1_i0  , fr2_i0   : 1sr & 2nd fraction of qsr penetration in ice             [%]
-         !----------------------------------------------------------------------------------------
-         CALL wrk_alloc( jpi,jpj,jpl, zalb_os, zalb_cs )
-         
-                                      CALL albedo_ice( t_su, ht_i, ht_s, zalb_cs, zalb_os ) ! cloud-sky and overcast-sky ice albedos
-         SELECT CASE( ksbc )
-            CASE( jp_usr )   ;        CALL usrdef_sbc_ice_flx( kt ) ! user defined formulation
-            CASE( jp_blk )                                          ! bulk formulation
-               ! albedo depends on cloud fraction because of non-linear spectral effects
-               alb_ice(:,:,:) = ( 1. - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:)
-                                      CALL blk_ice_flx( t_su, alb_ice )
-               IF( ln_mixcpl      )   CALL sbc_cpl_ice_flx( p_frld=pfrld, palbi=alb_ice, psst=sst_m, pist=t_su )
-               IF( nn_limflx /= 2 )   CALL ice_lim_flx( t_su, alb_ice, qns_ice, qsr_ice, dqns_ice, evap_ice, devap_ice, nn_limflx )
-            CASE ( jp_purecpl )
-               ! albedo depends on cloud fraction because of non-linear spectral effects
-               alb_ice(:,:,:) = ( 1. - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:)
-                                      CALL sbc_cpl_ice_flx( p_frld=pfrld, palbi=alb_ice, psst=sst_m, pist=t_su )
-               IF( nn_limflx == 2 )   CALL ice_lim_flx( t_su, alb_ice, qns_ice, qsr_ice, dqns_ice, evap_ice, devap_ice, nn_limflx )
-         END SELECT
-
-         CALL wrk_dealloc( jpi,jpj,jpl, zalb_os, zalb_cs )
-
-         !----------------------------!
-         ! --- ice thermodynamics --- !
-         !----------------------------!
-         ! --- zap this if no ice thermo --- !
-         IF( ln_limthd )              CALL lim_thd( kt )        ! -- Ice thermodynamics      
-         IF( ln_limthd )              CALL lim_update2( kt )    ! -- Corrections
-         ! ---
-# if defined key_agrif
-         IF( .NOT. Agrif_Root() )     CALL agrif_update_lim3( kt )
-# endif
-                                      CALL lim_var_glo2eqv      ! necessary calls (at least for coupling)
-                                      CALL lim_var_agg( 2 )     ! necessary calls (at least for coupling)
-                                      !
-!! clem: one should switch the calculation of the fluxes onto the parent grid but the following calls do not work
-!!       moreover it should only be called at the update frequency (as in agrif_lim3_update.F90)
-!!# if defined key_agrif
-!!         IF( .NOT. Agrif_Root() )   CALL Agrif_ChildGrid_To_ParentGrid()
-!!# endif
-                                      CALL lim_sbc_flx( kt )    ! -- Update surface ocean mass, heat and salt fluxes
-!!# if defined key_agrif
-!!         IF( .NOT. Agrif_Root() )   CALL Agrif_ParentGrid_To_ChildGrid()
-!!# endif
-         IF( ln_limdiahsb )           CALL lim_diahsb( kt )     ! -- Diagnostics and outputs 
-         !
-                                      CALL lim_wri( 1 )         ! -- Ice outputs 
-         !
-         IF( kt == nit000 .AND. ln_rstart )   &
-            &                         CALL iom_close( numrir )  ! close input ice restart file
-         !
-         IF( lrst_ice )               CALL lim_rst_write( kt )  ! -- Ice restart file 
-         !
-         IF( ln_limctl )              CALL lim_ctl( kt )        ! alerts in case of model crash
-         !
-      ENDIF   ! End sea-ice time step only
-
-      !-------------------------!
-      ! --- Ocean time step --- !
-      !-------------------------!
-      ! Update surface ocean stresses (only in ice-dynamic case) otherwise the atm.-ocean stresses are used everywhere
-      !    using before instantaneous surf. currents
-      IF( ln_limdyn )                 CALL lim_sbc_tau( kt, ub(:,:,1), vb(:,:,1) )
-!!gm   remark, the ocean-ice stress is not saved in ice diag call above .....  find a solution!!!
-      !
-      IF( nn_timing == 1 ) CALL timing_stop('sbc_ice_lim')
-      !
-   END SUBROUTINE sbc_ice_lim
-
-
-   SUBROUTINE sbc_lim_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE sbc_lim_init  ***
-      !!
-      !! ** purpose :   Allocate all the dynamic arrays of the LIM-3 modules
-      !!----------------------------------------------------------------------
-      INTEGER :: ji, jj, ierr
-      !!----------------------------------------------------------------------
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'sbc_lim_init : update ocean surface boudary condition' 
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   via Louvain la Neuve Ice Model (LIM-3) time stepping'
-      !
-      !                                ! Open the reference and configuration namelist files and namelist output file
-      CALL ctl_opn( numnam_ice_ref, 'namelist_ice_ref',    'OLD',     'FORMATTED', 'SEQUENTIAL', -1, numout, lwp )
-      CALL ctl_opn( numnam_ice_cfg, 'namelist_ice_cfg',    'OLD',     'FORMATTED', 'SEQUENTIAL', -1, numout, lwp )
-      IF(lwm) CALL ctl_opn( numoni, 'output.namelist.ice', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, 1 )
-      !
-      CALL lim_run_init                ! set some ice run parameters
-      !
-      !                                ! Allocate the ice arrays
-      ierr =        ice_alloc        ()      ! ice variables
-      ierr = ierr + sbc_ice_alloc    ()      ! surface forcing
-      ierr = ierr + thd_ice_alloc    ()      ! thermodynamics
-      IF( ln_limdyn )   ierr = ierr + lim_itd_me_alloc ()      ! ice thickness distribution - mechanics
-      !
-      IF( lk_mpp    )   CALL mpp_sum( ierr )
-      IF( ierr /= 0 )   CALL ctl_stop('STOP', 'sbc_lim_init : unable to allocate ice arrays')
-      !
-      CALL lim_dyn_init                ! set ice dynamics parameters
-      !
-      CALL lim_itd_init                ! ice thickness distribution initialization
-      !
-      CALL lim_hdf_init                ! set ice horizontal diffusion computation parameters
-      !
-      CALL lim_thd_init                ! set ice thermodynics parameters
-      !
-      CALL lim_thd_sal_init            ! set ice salinity parameters
-      !
-      IF( ln_limdyn )   CALL lim_itd_me_init             ! ice thickness distribution initialization for mecanical deformation
-      !                                ! Initial sea-ice state
-      IF( .NOT. ln_rstart ) THEN              ! start from rest: sea-ice deduced from sst
-         numit = 0
-         numit = nit000 - 1
-         CALL lim_istate
-      ELSE                                    ! start from a restart file
-         CALL lim_rst_read
-         numit = nit000 - 1
-      ENDIF
-      CALL lim_var_agg(2)
-      CALL lim_var_glo2eqv
-      !
-      CALL lim_sbc_init                 ! ice surface boundary condition
-      !
-      IF( ln_limdiahsb) CALL lim_diahsb_init  ! initialization for diags
-      !
-      fr_i(:,:)     = at_i(:,:)         ! initialisation of sea-ice fraction
-      tn_ice(:,:,:) = t_su(:,:,:)       ! initialisation of surface temp for coupled simu
-      !
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( gphit(ji,jj) > 0._wp ) THEN  ;  rn_amax_2d(ji,jj) = rn_amax_n  ! NH
-            ELSE                             ;  rn_amax_2d(ji,jj) = rn_amax_s  ! SH
-            ENDIF
-         END DO
-      END DO
-      !
-      nstart = numit  + nn_fsbc
-      nitrun = nitend - nit000 + 1
-      nlast  = numit  + nitrun
-      !
-      IF( nstock == 0 )   nstock = nlast + 1
-      !
-   END SUBROUTINE sbc_lim_init
-
-
-   SUBROUTINE lim_run_init
-      !!-------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_run_init ***
-      !!
-      !! ** Purpose :   Definition some run parameter for ice model
-      !!
-      !! ** Method  :   Read the namicerun namelist and check the parameter
-      !!              values called at the first timestep (nit000)
-      !!
-      !! ** input   :   Namelist namicerun
-      !!-------------------------------------------------------------------
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namicerun/ jpl, nlay_i, nlay_s, rn_amax_n, rn_amax_s, cn_icerst_in, cn_icerst_indir,   &
-         &                cn_icerst_out, cn_icerst_outdir, ln_limthd, ln_limdyn, nn_limdyn, rn_uice, rn_vice  
-      NAMELIST/namicediag/ ln_limdiachk, ln_limdiahsb, ln_limctl, iiceprt, jiceprt  
-      !!-------------------------------------------------------------------
-      !
-      REWIND( numnam_ice_ref )              ! Namelist namicerun in reference namelist : Parameters for ice
-      READ  ( numnam_ice_ref, namicerun, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicerun in reference namelist', lwp )
-
-      REWIND( numnam_ice_cfg )              ! Namelist namicerun in configuration namelist : Parameters for ice
-      READ  ( numnam_ice_cfg, namicerun, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicerun in configuration namelist', lwp )
-      IF(lwm) WRITE ( numoni, namicerun )
-      !
-      REWIND( numnam_ice_ref )              ! Namelist namicediag in reference namelist : Parameters for ice
-      READ  ( numnam_ice_ref, namicediag, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicediag in reference namelist', lwp )
-
-      REWIND( numnam_ice_cfg )              ! Namelist namicediag in configuration namelist : Parameters for ice
-      READ  ( numnam_ice_cfg, namicediag, IOSTAT = ios, ERR = 904 )
-904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicediag in configuration namelist', lwp )
-      IF(lwm) WRITE ( numoni, namicediag )
-      !
-      IF(lwp) THEN                        ! control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_run_init : ice share parameters for dynamics/advection/thermo of sea-ice'
-         WRITE(numout,*) ' ~~~~~~'
-         WRITE(numout,*) '   number of ice  categories                               = ', jpl
-         WRITE(numout,*) '   number of ice  layers                                   = ', nlay_i
-         WRITE(numout,*) '   number of snow layers                                   = ', nlay_s
-         WRITE(numout,*) '   maximum ice concentration for NH                        = ', rn_amax_n 
-         WRITE(numout,*) '   maximum ice concentration for SH                        = ', rn_amax_s
-         WRITE(numout,*) '   Ice thermodynamics (T) or not (F)            ln_limthd  = ', ln_limthd
-         WRITE(numout,*) '   Ice dynamics       (T) or not (F)            ln_limdyn  = ', ln_limdyn
-         WRITE(numout,*) '     (ln_limdyn=T) Ice dynamics switch          nn_limdyn  = ', nn_limdyn
-         WRITE(numout,*) '       2: total'
-         WRITE(numout,*) '       1: advection only (no diffusion, no ridging/rafting)'
-         WRITE(numout,*) '       0: advection only (as 1 + prescribed velocity, bypass rheology)'
-         WRITE(numout,*) '     (ln_limdyn=T) prescribed u-vel (case nn_limdyn=0)     = ', rn_uice
-         WRITE(numout,*) '     (ln_limdyn=T) prescribed v-vel (case nn_limdyn=0)     = ', rn_vice
-         WRITE(numout,*)
-         WRITE(numout,*) '...and ice diagnostics'
-         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~'
-         WRITE(numout,*) '   Diagnose online heat/mass/salt budget     ln_limdiachk  = ', ln_limdiachk
-         WRITE(numout,*) '   Output          heat/mass/salt budget     ln_limdiahsb  = ', ln_limdiahsb
-         WRITE(numout,*) '   control prints in ocean.out for (i,j)=(iiceprt,jiceprt) = ', ln_limctl
-         WRITE(numout,*) '   i-index for control prints (ln_limctl=true)             = ', iiceprt
-         WRITE(numout,*) '   j-index for control prints (ln_limctl=true)             = ', jiceprt
-      ENDIF
-      !
-      ! sea-ice timestep and inverse
-      rdt_ice   = REAL(nn_fsbc) * rdt  
-      r1_rdtice = 1._wp / rdt_ice 
-
-      ! inverse of nlay_i and nlay_s
-      r1_nlay_i = 1._wp / REAL( nlay_i, wp )
-      r1_nlay_s = 1._wp / REAL( nlay_s, wp )
-      !
-      IF( lwp .AND. ln_bdy .AND. ln_limdiachk )  &
-         &   CALL ctl_warn('online conservation check activated but it does not work with BDY')
-      !
-      IF( lwp ) WRITE(numout,*) '   ice timestep rdt_ice  = ', rdt_ice
-      !
-   END SUBROUTINE lim_run_init
-
-
-   SUBROUTINE lim_itd_init
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_init ***
-      !!
-      !! ** Purpose :   Initializes the ice thickness distribution
-      !! ** Method  :   ...
-      !! ** input   :   Namelist namiceitd
-      !!-------------------------------------------------------------------
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namiceitd/ nn_catbnd, rn_himean
-      !
-      INTEGER  ::   jl                   ! dummy loop index
-      REAL(wp) ::   zc1, zc2, zc3, zx1   ! local scalars
-      REAL(wp) ::   zhmax, znum, zden, zalpha !
-      !!------------------------------------------------------------------
-      !
-      REWIND( numnam_ice_ref )              ! Namelist namiceitd in reference namelist : Parameters for ice
-      READ  ( numnam_ice_ref, namiceitd, IOSTAT = ios, ERR = 905)
-905   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namiceitd in reference namelist', lwp )
-
-      REWIND( numnam_ice_cfg )              ! Namelist namiceitd in configuration namelist : Parameters for ice
-      READ  ( numnam_ice_cfg, namiceitd, IOSTAT = ios, ERR = 906 )
-906   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namiceitd in configuration namelist', lwp )
-      IF(lwm) WRITE ( numoni, namiceitd )
-      !
-      IF(lwp) THEN                        ! control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_itd_init : Initialization of ice cat distribution '
-         WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) '   shape of ice categories distribution                          nn_catbnd = ', nn_catbnd
-         WRITE(numout,*) '   mean ice thickness in the domain (only active if nn_catbnd=2) rn_himean = ', rn_himean
-      ENDIF
-      !
-      !----------------------------------
-      !- Thickness categories boundaries
-      !----------------------------------
-      !
-      hi_max(:) = 0._wp
-      !
-      SELECT CASE ( nn_catbnd  )    ! type of ice categories distribution
-      !
-      CASE (1)                            !==  tanh function (CICE)  ==!
-         zc1 =  3._wp / REAL( jpl, wp )
-         zc2 = 10._wp * zc1
-         zc3 =  3._wp
-         DO jl = 1, jpl
-            zx1 = REAL( jl-1, wp ) / REAL( jpl, wp )
-            hi_max(jl) = hi_max(jl-1) + zc1 + zc2 * (1._wp + TANH( zc3 * (zx1 - 1._wp ) ) )
-         END DO
-         !
-      CASE (2)                            !==  h^(-alpha) function  ==!
-         zalpha = 0.05_wp
-         zhmax  = 3._wp * rn_himean
-         DO jl = 1, jpl
-            znum = jpl * ( zhmax+1 )**zalpha
-            zden = REAL( jpl-jl , wp ) * ( zhmax + 1._wp )**zalpha + REAL( jl , wp )
-            hi_max(jl) = ( znum / zden )**(1./zalpha) - 1
-         END DO
-         !
-      END SELECT
-      !
-      DO jl = 1, jpl                ! mean thickness by category
-         hi_mean(jl) = ( hi_max(jl) + hi_max(jl-1) ) * 0.5_wp
-      END DO
-      !
-      hi_max(jpl) = 99._wp          ! set to a big value to ensure that all ice is thinner than hi_max(jpl)
-      !
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) '      Thickness category boundaries '
-      IF(lwp) WRITE(numout,*) '         hi_max ', hi_max(0:jpl)
-      !
-   END SUBROUTINE lim_itd_init
-
-
-   SUBROUTINE ice_lim_flx( ptn_ice, palb_ice, pqns_ice, pqsr_ice, pdqn_ice, pevap_ice, pdevap_ice, k_limflx )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE ice_lim_flx  ***
-      !!
-      !! ** Purpose :   update the ice surface boundary condition by averaging and / or
-      !!                redistributing fluxes on ice categories
-      !!
-      !! ** Method  :   average then redistribute
-      !!
-      !! ** Action  :
-      !!---------------------------------------------------------------------
-      INTEGER                   , INTENT(in   ) ::   k_limflx   ! =-1 do nothing; =0 average ;
-      !                                                         ! = 1 average and redistribute ; =2 redistribute
-      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   ptn_ice    ! ice surface temperature
-      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   palb_ice   ! ice albedo
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pqns_ice   ! non solar flux
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pqsr_ice   ! net solar flux
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdqn_ice   ! non solar flux sensitivity
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pevap_ice  ! sublimation
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdevap_ice ! sublimation sensitivity
-      !
-      INTEGER  ::   jl      ! dummy loop index
-      !
-      REAL(wp), POINTER, DIMENSION(:,:) :: zalb_m    ! Mean albedo over all categories
-      REAL(wp), POINTER, DIMENSION(:,:) :: ztem_m    ! Mean temperature over all categories
-      !
-      REAL(wp), POINTER, DIMENSION(:,:) :: z_qsr_m   ! Mean solar heat flux over all categories
-      REAL(wp), POINTER, DIMENSION(:,:) :: z_qns_m   ! Mean non solar heat flux over all categories
-      REAL(wp), POINTER, DIMENSION(:,:) :: z_evap_m  ! Mean sublimation over all categories
-      REAL(wp), POINTER, DIMENSION(:,:) :: z_dqn_m   ! Mean d(qns)/dT over all categories
-      REAL(wp), POINTER, DIMENSION(:,:) :: z_devap_m ! Mean d(evap)/dT over all categories
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('ice_lim_flx')
-      !
-      SELECT CASE( k_limflx )                              !==  averaged on all ice categories  ==!
-      CASE( 0 , 1 )
-         CALL wrk_alloc( jpi,jpj, z_qsr_m, z_qns_m, z_evap_m, z_dqn_m, z_devap_m)
-         !
-         z_qns_m  (:,:) = fice_ice_ave ( pqns_ice (:,:,:) )
-         z_qsr_m  (:,:) = fice_ice_ave ( pqsr_ice (:,:,:) )
-         z_dqn_m  (:,:) = fice_ice_ave ( pdqn_ice (:,:,:) )
-         z_evap_m (:,:) = fice_ice_ave ( pevap_ice (:,:,:) )
-         z_devap_m(:,:) = fice_ice_ave ( pdevap_ice (:,:,:) )
-         DO jl = 1, jpl
-            pdqn_ice  (:,:,jl) = z_dqn_m(:,:)
-            pdevap_ice(:,:,jl) = z_devap_m(:,:)
-         END DO
-         !
-         DO jl = 1, jpl
-            pqns_ice (:,:,jl) = z_qns_m(:,:)
-            pqsr_ice (:,:,jl) = z_qsr_m(:,:)
-            pevap_ice(:,:,jl) = z_evap_m(:,:)
-         END DO
-         !
-         CALL wrk_dealloc( jpi,jpj, z_qsr_m, z_qns_m, z_evap_m, z_dqn_m, z_devap_m)
-      END SELECT
-      !
-      SELECT CASE( k_limflx )                              !==  redistribution on all ice categories  ==!
-      CASE( 1 , 2 )
-         CALL wrk_alloc( jpi,jpj, zalb_m, ztem_m )
-         !
-         zalb_m(:,:) = fice_ice_ave ( palb_ice (:,:,:) )
-         ztem_m(:,:) = fice_ice_ave ( ptn_ice  (:,:,:) )
-         DO jl = 1, jpl
-            pqns_ice (:,:,jl) = pqns_ice (:,:,jl) + pdqn_ice  (:,:,jl) * ( ptn_ice(:,:,jl) - ztem_m(:,:) )
-            pevap_ice(:,:,jl) = pevap_ice(:,:,jl) + pdevap_ice(:,:,jl) * ( ptn_ice(:,:,jl) - ztem_m(:,:) )
-            pqsr_ice (:,:,jl) = pqsr_ice (:,:,jl) * ( 1._wp - palb_ice(:,:,jl) ) / ( 1._wp - zalb_m(:,:) )
-         END DO
-         !
-         CALL wrk_dealloc( jpi,jpj, zalb_m, ztem_m )
-      END SELECT
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('ice_lim_flx')
-      !
-   END SUBROUTINE ice_lim_flx
-
-
-   SUBROUTINE sbc_lim_bef
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE sbc_lim_bef  ***
-      !!
-      !! ** purpose :  store ice variables at "before" time step
-      !!----------------------------------------------------------------------
-      a_i_b  (:,:,:)   = a_i  (:,:,:)     ! ice area
-      e_i_b  (:,:,:,:) = e_i  (:,:,:,:)   ! ice thermal energy
-      v_i_b  (:,:,:)   = v_i  (:,:,:)     ! ice volume
-      v_s_b  (:,:,:)   = v_s  (:,:,:)     ! snow volume
-      e_s_b  (:,:,:,:) = e_s  (:,:,:,:)   ! snow thermal energy
-      smv_i_b(:,:,:)   = smv_i(:,:,:)     ! salt content
-      oa_i_b (:,:,:)   = oa_i (:,:,:)     ! areal age content
-      u_ice_b(:,:)     = u_ice(:,:)
-      v_ice_b(:,:)     = v_ice(:,:)
-      !
-      at_i_b (:,:)     = SUM( a_i_b(:,:,:), dim=3 )
-      
-   END SUBROUTINE sbc_lim_bef
-
-
-   SUBROUTINE sbc_lim_diag0
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE sbc_lim_diag0  ***
-      !!
-      !! ** purpose :  set ice-ocean and ice-atm. fluxes to zeros at the beggining
-      !!               of the time step
-      !!----------------------------------------------------------------------
-      sfx    (:,:) = 0._wp   ;
-      sfx_bri(:,:) = 0._wp   ;   sfx_lam(:,:) = 0._wp
-      sfx_sni(:,:) = 0._wp   ;   sfx_opw(:,:) = 0._wp
-      sfx_bog(:,:) = 0._wp   ;   sfx_dyn(:,:) = 0._wp
-      sfx_bom(:,:) = 0._wp   ;   sfx_sum(:,:) = 0._wp
-      sfx_res(:,:) = 0._wp   ;   sfx_sub(:,:) = 0._wp
-      !
-      wfx_snw(:,:) = 0._wp   ;   wfx_ice(:,:) = 0._wp
-      wfx_sni(:,:) = 0._wp   ;   wfx_opw(:,:) = 0._wp
-      wfx_bog(:,:) = 0._wp   ;   wfx_dyn(:,:) = 0._wp
-      wfx_bom(:,:) = 0._wp   ;   wfx_sum(:,:) = 0._wp
-      wfx_res(:,:) = 0._wp   ;   wfx_sub(:,:) = 0._wp
-      wfx_spr(:,:) = 0._wp   ;   wfx_lam(:,:) = 0._wp  
-      
-      hfx_thd(:,:) = 0._wp   ;
-      hfx_snw(:,:) = 0._wp   ;   hfx_opw(:,:) = 0._wp
-      hfx_bog(:,:) = 0._wp   ;   hfx_dyn(:,:) = 0._wp
-      hfx_bom(:,:) = 0._wp   ;   hfx_sum(:,:) = 0._wp
-      hfx_res(:,:) = 0._wp   ;   hfx_sub(:,:) = 0._wp
-      hfx_spr(:,:) = 0._wp   ;   hfx_dif(:,:) = 0._wp
-      hfx_err(:,:) = 0._wp   ;   hfx_err_rem(:,:) = 0._wp
-      hfx_err_dif(:,:) = 0._wp
-      wfx_err_sub(:,:) = 0._wp
-      !
-      afx_tot(:,:) = 0._wp   ;
-      afx_dyn(:,:) = 0._wp   ;   afx_thd(:,:) = 0._wp
-      !
-      diag_heat(:,:) = 0._wp ;   diag_smvi(:,:) = 0._wp
-      diag_vice(:,:) = 0._wp ;   diag_vsnw(:,:) = 0._wp
-
-      tau_icebfr(:,:) = 0._wp; ! landfast ice param only (clem: important to keep the init here)
-      
-   END SUBROUTINE sbc_lim_diag0
-
-
-   FUNCTION fice_cell_ave ( ptab )
-      !!--------------------------------------------------------------------------
-      !! * Compute average over categories, for grid cell (ice covered and free ocean)
-      !!--------------------------------------------------------------------------
-      REAL (wp), DIMENSION (jpi,jpj) :: fice_cell_ave
-      REAL (wp), DIMENSION (jpi,jpj,jpl), INTENT (in) :: ptab
-      INTEGER :: jl ! Dummy loop index
-
-      fice_cell_ave (:,:) = 0._wp
-      DO jl = 1, jpl
-         fice_cell_ave (:,:) = fice_cell_ave (:,:) + a_i (:,:,jl) * ptab (:,:,jl)
-      END DO
-
-   END FUNCTION fice_cell_ave
-
-
-   FUNCTION fice_ice_ave ( ptab )
-      !!--------------------------------------------------------------------------
-      !! * Compute average over categories, for ice covered part of grid cell
-      !!--------------------------------------------------------------------------
-      REAL (kind=wp), DIMENSION (jpi,jpj) :: fice_ice_ave
-      REAL (kind=wp), DIMENSION (jpi,jpj,jpl), INTENT(in) :: ptab
-
-      fice_ice_ave (:,:) = 0.0_wp
-      WHERE ( at_i (:,:) > 0.0_wp ) fice_ice_ave (:,:) = fice_cell_ave ( ptab (:,:,:)) / at_i (:,:)
-
-   END FUNCTION fice_ice_ave
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option           Dummy module      NO LIM 3.0 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   !
-   SUBROUTINE sbc_ice_lim ( kt, ksbc )     ! Dummy routine
-      INTEGER, INTENT(in) ::   kt, ksbc
-      WRITE(*,*) 'sbc_ice_lim: You should not have seen this print! error?', kt
-   END SUBROUTINE sbc_ice_lim
-   !
-   SUBROUTINE sbc_lim_init                 ! Dummy routine
-   END SUBROUTINE sbc_lim_init
-#endif
-
-   !!======================================================================
-END MODULE sbcice_lim
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim_2.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim_2.F90	(revision 9018)
+++ 	(revision )
@@ -1,274 +1,0 @@
-MODULE sbcice_lim_2
-   !!======================================================================
-   !!                       ***  MODULE  sbcice_lim_2  ***
-   !! Surface module :  update surface ocean boundary condition over ice covered area using LIM sea-ice model
-   !! Sea-Ice model  :  LIM-2 Sea ice model time-stepping
-   !!======================================================================
-   !! History :  1.0   !  06-2006  (G. Madec)  from icestp_2.F90
-   !!            3.0   !  08-2008  (S. Masson, E. .... ) coupled interface
-   !!            3.3   !  05-2009  (G.Garric) addition of the lim2_evp case
-   !!----------------------------------------------------------------------
-#if defined key_lim2
-   !!----------------------------------------------------------------------
-   !!   'key_lim2' :                                    LIM-2 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   sbc_ice_lim_2   : sea-ice model time-stepping and update ocean sbc over ice-covered area
-   !!----------------------------------------------------------------------
-   USE oce              ! ocean dynamics and tracers
-   USE dom_oce          ! ocean space and time domain
-   USE ice_2
-   USE par_ice_2
-   USE iceini_2
-   USE dom_ice_2
-
-   USE sbc_oce          ! Surface boundary condition: ocean fields
-   USE sbc_ice          ! Surface boundary condition: ice   fields
-   USE sbcblk           ! Surface boundary condition: bulk
-   USE sbccpl           ! Surface boundary condition: coupled interface
-   USE albedo
-
-   USE phycst           ! Define parameters for the routines
-   USE eosbn2           ! equation of state
-   USE limdyn_2
-   USE limtrp_2
-   USE limdmp_2
-   USE limthd_2
-   USE limsbc_2         ! sea surface boundary condition
-   USE limdia_2
-   USE limwri_2
-   USE limrst_2
-
-   USE c1d              ! 1D vertical configuration
-
-   USE lbclnk           ! lateral boundary condition - MPP link
-   USE lib_mpp          ! MPP library
-   USE wrk_nemo         ! work arrays
-   USE iom              ! I/O manager library
-   USE in_out_manager   ! I/O manager
-   USE prtctl           ! Print control
-
-# if defined key_agrif
-   USE agrif_ice
-   USE agrif_lim2_update
-# endif
-
-   USE bdy_oce   , ONLY: ln_bdy
-   USE bdyice_lim       ! unstructured open boundary data  (bdy_ice_lim routine)
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC sbc_ice_lim_2 ! routine called by sbcmod.F90
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE sbc_ice_lim_2( kt, ksbc )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE sbc_ice_lim_2  ***
-      !!                   
-      !! ** Purpose :   update the ocean surface boundary condition via the 
-      !!                Louvain la Neuve Sea Ice Model time stepping 
-      !!
-      !! ** Method  :   ice model time stepping
-      !!              - call the ice dynamics routine 
-      !!              - call the ice advection/diffusion routine 
-      !!              - call the ice thermodynamics routine 
-      !!              - call the routine that computes mass and 
-      !!                heat fluxes at the ice/ocean interface
-      !!              - save the outputs 
-      !!              - save the outputs for restart when necessary
-      !!
-      !! ** Action  : - time evolution of the LIM sea-ice model
-      !!              - update all sbc variables below sea-ice:
-      !!                utau, vtau, taum, wndm, qns , qsr, emp , sfx 
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt      ! ocean time step
-      INTEGER, INTENT(in) ::   ksbc    ! type of sbc ( =4 bulk ; =5 coupled )
-      !!
-      INTEGER  ::   ji, jj   ! dummy loop indices
-      REAL(wp), DIMENSION(:,:,:), POINTER :: zalb_os   ! ice albedo under overcast sky
-      REAL(wp), DIMENSION(:,:,:), POINTER :: zalb_cs   ! ice albedo under clear sky
-      REAL(wp), DIMENSION(:,:,:), POINTER :: zalb_ice  ! mean ice albedo
-      REAL(wp), DIMENSION(:,:,:), POINTER :: zsist     ! ice surface temperature (K)
-      REAL(wp), DIMENSION(:,:  ), POINTER :: zutau_ice, zvtau_ice 
-      !!----------------------------------------------------------------------
-
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'sbc_ice_lim_2 : update ocean surface boudary condition' 
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~   via Louvain la Neuve Ice Model (LIM) time stepping'
-         !
-         CALL ice_init_2
-         !
-# if defined key_agrif
-         IF( .NOT. Agrif_Root() ) CALL Agrif_InitValues_cont_lim2   ! AGRIF: set the meshes
-# endif
-      ENDIF
-
-      !                                        !----------------------!
-      IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN     !  Ice time-step only  !
-         !                                     !----------------------!
-# if defined key_agrif
-         IF( .NOT. Agrif_Root() ) lim_nbstep = MOD(lim_nbstep,Agrif_rhot()&
-         &*Agrif_PArent(nn_fsbc)/REAL(nn_fsbc)) + 1
-# endif
-
-         CALL wrk_alloc( jpi,jpj  , zutau_ice, zvtau_ice)
-         CALL wrk_alloc( jpi,jpj,1, zalb_os, zalb_cs, zalb_ice, zsist )
-
-         !  Bulk Formulea !
-         !----------------!
-         ! ... mean surface ocean current at ice dynamics point
-         SELECT CASE( cp_ice_msh )
-         CASE( 'I' )                  !== B-grid ice dynamics :   I-point (i.e. F-point with sea-ice indexation)
-            DO jj = 2, jpj
-               DO ji = 2, jpi   ! NO vector opt. possible
-                  u_oce(ji,jj) = 0.5_wp * ( ssu_m(ji-1,jj  ) * umask(ji-1,jj  ,1) &
-                     &                    + ssu_m(ji-1,jj-1) * umask(ji-1,jj-1,1) ) * tmu(ji,jj)
-                  v_oce(ji,jj) = 0.5_wp * ( ssv_m(ji  ,jj-1) * vmask(ji  ,jj-1,1) &
-                     &                    + ssv_m(ji-1,jj-1) * vmask(ji-1,jj-1,1) ) * tmu(ji,jj)
-               END DO
-            END DO
-            CALL lbc_lnk( u_oce, 'I', -1. )   ! I-point (i.e. F-point with ice indices)
-            CALL lbc_lnk( v_oce, 'I', -1. )   ! I-point (i.e. F-point with ice indices)
-            !
-         CASE( 'C' )                  !== C-grid ice dynamics :   U & V-points (same as ocean)
-            u_oce(:,:) = ssu_m(:,:) * umask(:,:,1)                     ! mean surface ocean current at ice velocity point
-            v_oce(:,:) = ssv_m(:,:) * vmask(:,:,1)
-            !
-         END SELECT
-
-         ! ... masked sea surface freezing temperature [Kelvin] (set to rt0 over land)
-         CALL eos_fzp( sss_m(:,:), tfu(:,:) )
-         tfu(:,:) = tfu(:,:) + rt0
-
-         zsist (:,:,1) = sist (:,:) + rt0 * ( 1. - tmask(:,:,1) )
-
-         ! Ice albedo
-
-         CALL albedo_ice( zsist, reshape( hicif, (/jpi,jpj,1/) ), &
-                                 reshape( hsnif, (/jpi,jpj,1/) ), &
-                          zalb_cs, zalb_os )
-
-         SELECT CASE( ksbc )
-         CASE( jp_blk , jp_purecpl )   ! BULK and COUPLED bulk formulations
-
-            ! albedo depends on cloud fraction because of non-linear spectral effects
-            zalb_ice(:,:,:) = ( 1. - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:)
-
-         END SELECT
-
-         ! ... Sea-ice surface boundary conditions output from bulk formulae :
-         !     - utau_ice   ! surface ice stress i-component (I-point)   [N/m2]
-         !     - vtau_ice   ! surface ice stress j-component (I-point)   [N/m2]
-         !     - qns_ice    ! non solar heat flux over ice   (T-point)   [W/m2]
-         !     - qsr_ice    !     solar heat flux over ice   (T-point)   [W/m2]
-         !     - qla_ice    ! latent    heat flux over ice   (T-point)   [W/m2]
-         !     - dqns_ice   ! non solar heat sensistivity    (T-point)   [W/m2]
-         !     - dqla_ice   ! latent    heat sensistivity    (T-point)   [W/m2]
-         !     - tprecip    ! total precipitation            (T-point)   [Kg/m2/s]
-         !     - sprecip    ! solid precipitation            (T-point)   [Kg/m2/s]
-         !     - fr1_i0     ! 1sr fraction of qsr penetration in ice     [%]
-         !     - fr2_i0     ! 2nd fraction of qsr penetration in ice     [%]
-         !
-         SELECT CASE( ksbc )
-         !
-         CASE( jp_blk )           ! Bulk formulation
-            CALL blk_ice_tau
-            CALL blk_ice_flx( zsist, zalb_ice )
-            !
-         CASE( jp_purecpl )            ! Coupled formulation : atmosphere-ice stress only (fluxes provided after ice dynamics)
-            CALL sbc_cpl_ice_tau( utau_ice , vtau_ice )
-            !
-         END SELECT
-         
-         IF( ln_mixcpl) THEN
-            CALL sbc_cpl_ice_tau( zutau_ice , zvtau_ice )
-            utau_ice(:,:) = utau_ice(:,:) * xcplmask(:,:,0) + zutau_ice(:,:) * ( 1. - xcplmask(:,:,0) )
-            vtau_ice(:,:) = vtau_ice(:,:) * xcplmask(:,:,0) + zvtau_ice(:,:) * ( 1. - xcplmask(:,:,0) )
-         ENDIF
-
-         CALL iom_put( 'utau_ice', utau_ice )     ! Wind stress over ice along i-axis at I-point
-         CALL iom_put( 'vtau_ice', vtau_ice )     ! Wind stress over ice along j-axis at I-point
-
-         IF(ln_ctl) THEN         ! print mean trends (used for debugging)
-            CALL prt_ctl_info( 'Ice Forcings ' )
-            CALL prt_ctl( tab2d_1=tprecip ,clinfo1=' sbc_ice_lim: precip  : ', tab2d_2=sprecip , clinfo2=' Snow    : ' )
-            CALL prt_ctl( tab2d_1=utau_ice,clinfo1=' sbc_ice_lim: utau_ice: ', tab2d_2=vtau_ice, clinfo2=' vtau_ice: ' )
-            CALL prt_ctl( tab2d_1=sst_m   ,clinfo1=' sbc_ice_lim: sst     : ', tab2d_2=sss_m   , clinfo2=' sss     : ' )
-            CALL prt_ctl( tab2d_1=u_oce   ,clinfo1=' sbc_ice_lim: u_io    : ', tab2d_2=v_oce   , clinfo2=' v_io    : ' )
-            CALL prt_ctl( tab2d_1=hsnif   ,clinfo1=' sbc_ice_lim: hsnif  1: ', tab2d_2=hicif   , clinfo2=' hicif   : ' )
-            CALL prt_ctl( tab2d_1=frld    ,clinfo1=' sbc_ice_lim: frld   1: ', tab2d_2=sist    , clinfo2=' sist    : ' )
-         ENDIF
-
-         ! ---------------- !
-         !  Ice model step  !
-         ! ---------------- !
-         numit = numit + nn_fsbc                           ! Ice model time step
-
-                           CALL lim_rst_opn_2  ( kt )  ! Open Ice restart file
-         IF( .NOT. lk_c1d ) THEN                       ! Ice dynamics & transport (except in 1D case)
-                           CALL lim_dyn_2      ( kt )      ! Ice dynamics    ( rheology/dynamics )
-                           CALL lim_trp_2      ( kt )      ! Ice transport   ( Advection/diffusion )
-           IF( ln_limdmp ) CALL lim_dmp_2      ( kt )      ! Ice damping 
-           IF( ln_bdy    ) CALL bdy_ice_lim( kt ) ! bdy ice thermo
-         END IF
-         !                                             ! Ice surface fluxes in coupled mode 
-         IF( ln_cpl ) THEN   ! pure coupled and mixed forced-coupled configurations
-            a_i(:,:,1)=fr_i
-            CALL sbc_cpl_ice_flx( frld,                                              &
-            !                                optional arguments, used only in 'mixed oce-ice' case
-            &                                             palbi=zalb_ice, psst=sst_m, pist=zsist )
-            sprecip(:,:) = - emp_ice(:,:)   ! Ugly patch, WARNING, in coupled mode, sublimation included in snow (parsub = 0.)
-         ENDIF
-                           CALL lim_thd_2      ( kt )      ! Ice thermodynamics 
-                           CALL lim_sbc_flx_2  ( kt )      ! update surface ocean mass, heat & salt fluxes 
-
-         IF(  .NOT. lk_mpp )THEN
-            IF( MOD( kt+nn_fsbc-1, ninfo ) == 0 .OR. ntmoy == 1 )   &
-            &              CALL lim_dia_2      ( kt )      ! Ice Diagnostics
-         ENDIF
-# if ! defined key_iomput
-                           CALL lim_wri_2      ( kt )      ! Ice outputs
-# endif
-         IF( lrst_ice  )   CALL lim_rst_write_2( kt )      ! Ice restart file
-         !
-# if defined key_agrif && defined key_lim2
-         IF( .NOT. Agrif_Root() )   CALL agrif_update_lim2( kt )
-# endif
-         !
-         CALL wrk_dealloc( jpi,jpj  , zutau_ice, zvtau_ice)
-         CALL wrk_dealloc( jpi,jpj,1, zalb_os, zalb_cs, zalb_ice, zsist )
-         !
-      ENDIF                                    ! End sea-ice time step only
-      !
-      !                                        !--------------------------!
-      !                                        !  at all ocean time step  !
-      !                                        !--------------------------!
-      !                                               
-      !                                              ! Update surface ocean stresses (only in ice-dynamic case)
-      !                                                   ! otherwise the atm.-ocean stresses are used everywhere
-      IF( ln_limdyn    )   CALL lim_sbc_tau_2( kt, ub(:,:,1), vb(:,:,1) )  ! using before instantaneous surf. currents
-      !
-   END SUBROUTINE sbc_ice_lim_2
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option           Dummy module      NO LIM 2.0 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE sbc_ice_lim_2 ( kt, ksbc )     ! Dummy routine
-      INTEGER, INTENT(in) ::   kt, ksbc    
-      WRITE(*,*) 'sbc_ice_lim_2: You should not have seen this print! error?', kt, ksbc
-   END SUBROUTINE sbc_ice_lim_2
-#endif
-
-   !!======================================================================
-END MODULE sbcice_lim_2
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90	(revision 9019)
@@ -5,26 +5,25 @@
    !!                   shelf
    !!======================================================================
-   !! History :  3.2   !  2011-02  (C.Harris  ) Original code isf cav
-   !!            X.X   !  2006-02  (C. Wang   ) Original code bg03
-   !!            3.4   !  2013-03  (P. Mathiot) Merging + parametrization
+   !! History :  3.2  !  2011-02  (C.Harris  ) Original code isf cav
+   !!            X.X  !  2006-02  (C. Wang   ) Original code bg03
+   !!            3.4  !  2013-03  (P. Mathiot) Merging + parametrization
    !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
-   !!   sbc_isf        : update sbc under ice shelf
+   !!   sbc_isf       : update sbc under ice shelf
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE eosbn2          ! equation of state
-   USE sbc_oce         ! surface boundary condition: ocean fields
-   USE zdfbfr          !
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE eosbn2         ! equation of state
+   USE sbc_oce        ! surface boundary condition: ocean fields
+   USE zdfdrg         ! vertical physics: top/bottom drag coef.
    !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O manager library
-   USE fldread         ! read input field at current time step
-   USE lbclnk          !
-   USE wrk_nemo        ! Memory allocation
-   USE timing          ! Timing
-   USE lib_fortran     ! glob_sum
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O library
+   USE fldread        ! read input field at current time step
+   USE lbclnk         !
+   USE timing         ! Timing
+   USE lib_fortran    ! glob_sum
 
    IMPLICIT NONE
@@ -35,6 +34,4 @@
    ! public in order to be able to output then 
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   risf_tsc_b, risf_tsc  !: before and now T & S isf contents [K.m/s & PSU.m/s]  
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   qisf                  !: net heat flux from ice shelf      [W/m2]
    REAL(wp), PUBLIC ::   rn_hisf_tbl                 !: thickness of top boundary layer [m]
    INTEGER , PUBLIC ::   nn_isf                      !: flag to choose between explicit/param/specified  
@@ -44,19 +41,21 @@
    REAL(wp), PUBLIC ::   rn_gammas0                  !: salinity    exchange coeficient []
 
-   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  rzisf_tbl              !:depth of calving front (shallowest point) nn_isf ==2/3
-   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  rhisf_tbl, rhisf_tbl_0 !:thickness of tbl  [m]
-   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  r1_hisf_tbl            !:1/thickness of tbl
-   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  ralpha                 !:proportion of bottom cell influenced by tbl 
-   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  risfLeff               !:effective length (Leff) BG03 nn_isf==2
-   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  ttbl, stbl, utbl, vtbl !:top boundary layer variable at T point
-   INTEGER,    PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)      ::  misfkt, misfkb         !:Level of ice shelf base
-
-   LOGICAL, PUBLIC ::   l_isfcpl = .false.       ! isf recieved from oasis
-
-   REAL(wp), PUBLIC, SAVE ::   rcpi     = 2000.0_wp     ! specific heat of ice shelf             [J/kg/K]
-   REAL(wp), PUBLIC, SAVE ::   rkappa   = 1.54e-6_wp    ! heat diffusivity through the ice-shelf [m2/s]
-   REAL(wp), PUBLIC, SAVE ::   rhoisf   = 920.0_wp      ! volumic mass of ice shelf              [kg/m3]
-   REAL(wp), PUBLIC, SAVE ::   tsurf    = -20.0_wp      ! air temperature on top of ice shelf    [C]
-   REAL(wp), PUBLIC, SAVE ::   rlfusisf = 0.334e6_wp    ! latent heat of fusion of ice shelf     [J/kg]
+   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   misfkt   , misfkb        !: Level of ice shelf base
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   rzisf_tbl                !: depth of calving front (shallowest point) nn_isf ==2/3
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   rhisf_tbl, rhisf_tbl_0   !: thickness of tbl  [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   r1_hisf_tbl              !: 1/thickness of tbl
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ralpha                   !: proportion of bottom cell influenced by tbl 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   risfLeff                 !: effective length (Leff) BG03 nn_isf==2
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ttbl, stbl, utbl, vtbl   !: top boundary layer variable at T point
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   qisf                     !: net heat flux from ice shelf      [W/m2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   risf_tsc_b, risf_tsc     !: before and now T & S isf contents [K.m/s & PSU.m/s]  
+
+   LOGICAL, PUBLIC ::   l_isfcpl = .false.       !: isf recieved from oasis
+
+   REAL(wp), PUBLIC, SAVE ::   rcpi     = 2000.0_wp     !: specific heat of ice shelf             [J/kg/K]
+   REAL(wp), PUBLIC, SAVE ::   rkappa   = 1.54e-6_wp    !: heat diffusivity through the ice-shelf [m2/s]
+   REAL(wp), PUBLIC, SAVE ::   rhoisf   = 920.0_wp      !: volumic mass of ice shelf              [kg/m3]
+   REAL(wp), PUBLIC, SAVE ::   tsurf    = -20.0_wp      !: air temperature on top of ice shelf    [C]
+   REAL(wp), PUBLIC, SAVE ::   rlfusisf = 0.334e6_wp    !: latent heat of fusion of ice shelf     [J/kg]
 
 !: Variable used in fldread to read the forcing file (nn_isf == 4 .OR. nn_isf == 3)
@@ -71,5 +70,5 @@
    
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , LOCEAN-IPSL (2015)
+   !! NEMO/OPA 4.0 , LOCEAN-IPSL (2017)
    !! $Id$
    !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
@@ -77,5 +76,5 @@
 CONTAINS
  
-  SUBROUTINE sbc_isf(kt)
+  SUBROUTINE sbc_isf( kt )
       !!---------------------------------------------------------------------
       !!                  ***  ROUTINE sbc_isf  ***
@@ -90,18 +89,15 @@
       !!                        4 : specified fwf and heat flux forcing beneath the ice shelf
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) :: kt                   ! ocean time step
-      !
-      INTEGER               :: ji, jj, jk           ! loop index
-      INTEGER               :: ikt, ikb             ! loop index
-      REAL(wp), DIMENSION (:,:), POINTER :: zt_frz, zdep ! freezing temperature (zt_frz) at depth (zdep) 
-      REAL(wp), DIMENSION(:,:,:), POINTER :: zfwfisf3d, zqhcisf3d, zqlatisf3d
-      REAL(wp), DIMENSION(:,:  ), POINTER :: zqhcisf2d
+      INTEGER, INTENT(in) ::   kt   ! ocean time step
+      !
+      INTEGER ::   ji, jj, jk   ! loop index
+      INTEGER ::   ikt, ikb     ! local integers
+      REAL(wp), DIMENSION(jpi,jpj) ::   zt_frz, zdep   ! freezing temperature (zt_frz) at depth (zdep) 
+      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE ::   zqhcisf2d
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   zfwfisf3d, zqhcisf3d, zqlatisf3d
       !!---------------------------------------------------------------------
       !
-      IF( MOD( kt-1, nn_fsbc) == 0 ) THEN
-         ! allocation
-         CALL wrk_alloc( jpi,jpj, zt_frz, zdep  )
-
-         ! compute salt and heat flux
+      IF( MOD( kt-1, nn_fsbc) == 0 ) THEN    ! compute salt and heat flux
+         !
          SELECT CASE ( nn_isf )
          CASE ( 1 )    ! realistic ice shelf formulation
@@ -121,9 +117,9 @@
             ELSE                        ;   qisf(:,:)  = fwfisf(:,:) * rlfusisf  ! heat        flux
             ENDIF
-
+            !
          CASE ( 2 )    ! Beckmann and Goosse parametrisation 
             stbl(:,:)   = soce
             CALL sbc_isf_bg03(kt)
-
+            !
          CASE ( 3 )    ! specified runoff in depth (Mathiot et al., XXXX in preparation)
             ! specified runoff in depth (Mathiot et al., XXXX in preparation)
@@ -134,7 +130,7 @@
             qisf(:,:)   = fwfisf(:,:) * rlfusisf             ! heat flux
             stbl(:,:)   = soce
-
+            !
          CASE ( 4 )    ! specified fwf and heat flux forcing beneath the ice shelf
-           ! specified fwf and heat flux forcing beneath the ice shelf
+            !          ! specified fwf and heat flux forcing beneath the ice shelf
             IF( .NOT.l_isfcpl ) THEN
                CALL fld_read ( kt, nn_fsbc, sf_fwfisf   )
@@ -144,5 +140,5 @@
             qisf(:,:)   = fwfisf(:,:) * rlfusisf               ! heat flux
             stbl(:,:)   = soce
-
+            !
          END SELECT
 
@@ -162,8 +158,8 @@
 
          ! lbclnk
-         CALL lbc_lnk(risf_tsc(:,:,jp_tem),'T',1.)
-         CALL lbc_lnk(risf_tsc(:,:,jp_sal),'T',1.)
-         CALL lbc_lnk(fwfisf(:,:)   ,'T',1.)
-         CALL lbc_lnk(qisf(:,:)     ,'T',1.)
+         CALL lbc_lnk( risf_tsc(:,:,jp_tem),'T',1.)
+         CALL lbc_lnk( risf_tsc(:,:,jp_sal),'T',1.)
+         CALL lbc_lnk( fwfisf  (:,:)       ,'T',1.)
+         CALL lbc_lnk( qisf    (:,:)       ,'T',1.)
 
          ! output
@@ -173,14 +169,14 @@
          IF( iom_use('fwfisf'  ) )       CALL iom_put( 'fwfisf'      , fwfisf(:,:)                       )   ! isf mass flux (opposite sign)
 
-        ! Diagnostics
-        IF ( iom_use('fwfisf3d') .OR. iom_use('qlatisf3d') .OR. iom_use('qhcisf3d') .OR. iom_use('qhcisf')) THEN
-            CALL wrk_alloc( jpi,jpj,jpk, zfwfisf3d, zqhcisf3d, zqlatisf3d )
-            CALL wrk_alloc( jpi,jpj,     zqhcisf2d                        )
-
-            zfwfisf3d(:,:,:) = 0.0_wp                         ! 3d ice shelf melting (kg/m2/s)
-            zqhcisf3d(:,:,:) = 0.0_wp                         ! 3d heat content flux (W/m2)
-            zqlatisf3d(:,:,:)= 0.0_wp                         ! 3d ice shelf melting latent heat flux (W/m2)
-            zqhcisf2d(:,:)   = fwfisf(:,:) * zt_frz * rcp     ! 2d heat content flux (W/m2)
-
+         ! Diagnostics
+         IF( iom_use('fwfisf3d') .OR. iom_use('qlatisf3d') .OR. iom_use('qhcisf3d') .OR. iom_use('qhcisf')) THEN
+            ALLOCATE( zfwfisf3d(jpi,jpj,jpk) , zqhcisf3d(jpi,jpj,jpk) , zqlatisf3d(jpi,jpj,jpk) )
+            ALLOCATE( zqhcisf2d(jpi,jpj) )
+            !
+            zfwfisf3d (:,:,:) = 0._wp                         ! 3d ice shelf melting (kg/m2/s)
+            zqhcisf3d (:,:,:) = 0._wp                         ! 3d heat content flux (W/m2)
+            zqlatisf3d(:,:,:) = 0._wp                         ! 3d ice shelf melting latent heat flux (W/m2)
+            zqhcisf2d (:,:)   = fwfisf(:,:) * zt_frz * rcp    ! 2d heat content flux (W/m2)
+            !
             DO jj = 1,jpj
                DO ji = 1,jpi
@@ -200,45 +196,43 @@
                END DO
             END DO
-
+            !
             CALL iom_put('fwfisf3d' , zfwfisf3d (:,:,:))
             CALL iom_put('qlatisf3d', zqlatisf3d(:,:,:))
             CALL iom_put('qhcisf3d' , zqhcisf3d (:,:,:))
             CALL iom_put('qhcisf'   , zqhcisf2d (:,:  ))
-
-            CALL wrk_dealloc( jpi,jpj,jpk, zfwfisf3d, zqhcisf3d, zqlatisf3d )
-            CALL wrk_dealloc( jpi,jpj,     zqhcisf2d                        )
-          END IF
-          ! deallocation
-          CALL wrk_dealloc( jpi,jpj, zt_frz, zdep  )
-          !
-        END IF
-
-        IF( kt == nit000 ) THEN                         !   set the forcing field at nit000 - 1    !
-           IF( ln_rstart .AND.    &                     ! Restart: read in restart file
-                 & iom_varid( numror, 'fwf_isf_b', ldstop = .FALSE. ) > 0 ) THEN
-               IF(lwp) WRITE(numout,*) '          nit000-1 isf tracer content forcing fields read in the restart file'
-               CALL iom_get( numror, jpdom_autoglo, 'fwf_isf_b', fwfisf_b(:,:) )   ! before salt content isf_tsc trend
-               CALL iom_get( numror, jpdom_autoglo, 'isf_sc_b', risf_tsc_b(:,:,jp_sal) )   ! before salt content isf_tsc trend
-               CALL iom_get( numror, jpdom_autoglo, 'isf_hc_b', risf_tsc_b(:,:,jp_tem) )   ! before salt content isf_tsc trend
-           ELSE
-               fwfisf_b(:,:)    = fwfisf(:,:)
-               risf_tsc_b(:,:,:)= risf_tsc(:,:,:)
-           END IF
-         END IF
-         ! 
-         IF( lrst_oce ) THEN
-            IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) 'sbc : isf surface tracer content forcing fields written in ocean restart file ',   &
-               &                    'at it= ', kt,' date= ', ndastp
-            IF(lwp) WRITE(numout,*) '~~~~'
-            CALL iom_rstput( kt, nitrst, numrow, 'fwf_isf_b', fwfisf(:,:) )
-            CALL iom_rstput( kt, nitrst, numrow, 'isf_hc_b' , risf_tsc(:,:,jp_tem) )
-            CALL iom_rstput( kt, nitrst, numrow, 'isf_sc_b' , risf_tsc(:,:,jp_sal) )
+            !
+            DEALLOCATE( zfwfisf3d, zqhcisf3d, zqlatisf3d )
+            DEALLOCATE( zqhcisf2d )
          ENDIF
          !
-  END SUBROUTINE sbc_isf
-
-
-  INTEGER FUNCTION sbc_isf_alloc()
+      ENDIF
+
+      IF( kt == nit000 ) THEN                         !   set the forcing field at nit000 - 1    !
+         IF( ln_rstart .AND.    &                     ! Restart: read in restart file
+            &   iom_varid( numror, 'fwf_isf_b', ldstop = .FALSE. ) > 0 ) THEN
+            IF(lwp) WRITE(numout,*) '          nit000-1 isf tracer content forcing fields read in the restart file'
+            CALL iom_get( numror, jpdom_autoglo, 'fwf_isf_b', fwfisf_b(:,:) )   ! before salt content isf_tsc trend
+            CALL iom_get( numror, jpdom_autoglo, 'isf_sc_b', risf_tsc_b(:,:,jp_sal) )   ! before salt content isf_tsc trend
+            CALL iom_get( numror, jpdom_autoglo, 'isf_hc_b', risf_tsc_b(:,:,jp_tem) )   ! before salt content isf_tsc trend
+         ELSE
+            fwfisf_b(:,:)    = fwfisf(:,:)
+            risf_tsc_b(:,:,:)= risf_tsc(:,:,:)
+         ENDIF
+      ENDIF
+      ! 
+      IF( lrst_oce ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'sbc : isf surface tracer content forcing fields written in ocean restart file ',   &
+            &                    'at it= ', kt,' date= ', ndastp
+         IF(lwp) WRITE(numout,*) '~~~~'
+         CALL iom_rstput( kt, nitrst, numrow, 'fwf_isf_b', fwfisf(:,:) )
+         CALL iom_rstput( kt, nitrst, numrow, 'isf_hc_b' , risf_tsc(:,:,jp_tem) )
+         CALL iom_rstput( kt, nitrst, numrow, 'isf_sc_b' , risf_tsc(:,:,jp_sal) )
+      ENDIF
+      !
+   END SUBROUTINE sbc_isf
+
+
+   INTEGER FUNCTION sbc_isf_alloc()
       !!----------------------------------------------------------------------
       !!               ***  FUNCTION sbc_isf_rnf_alloc  ***
@@ -256,6 +250,7 @@
          IF( sbc_isf_alloc /= 0 )   CALL ctl_warn('sbc_isf_alloc: failed to allocate arrays.')
          !
-      END IF
-  END FUNCTION
+      ENDIF
+   END FUNCTION
+
 
   SUBROUTINE sbc_isf_init
@@ -294,8 +289,6 @@
 
       IF ( lwp ) WRITE(numout,*)
-      IF ( lwp ) WRITE(numout,*) 'sbc_isf: heat flux of the ice shelf'
-      IF ( lwp ) WRITE(numout,*) '~~~~~~~~~'
-      IF ( lwp ) WRITE(numout,*) 'sbcisf :' 
-      IF ( lwp ) WRITE(numout,*) '~~~~~~~~'
+      IF ( lwp ) WRITE(numout,*) 'sbc_isf_init : heat flux of the ice shelf'
+      IF ( lwp ) WRITE(numout,*) '~~~~~~~~~~~'
       IF ( lwp ) WRITE(numout,*) '        nn_isf      = ', nn_isf
       IF ( lwp ) WRITE(numout,*) '        nn_isfblk   = ', nn_isfblk
@@ -304,5 +297,5 @@
       IF ( lwp ) WRITE(numout,*) '        rn_gammat0  = ', rn_gammat0  
       IF ( lwp ) WRITE(numout,*) '        rn_gammas0  = ', rn_gammas0  
-      IF ( lwp ) WRITE(numout,*) '        rn_tfri2    = ', rn_tfri2 
+      IF ( lwp ) WRITE(numout,*) '        rn_Cd0      = ', r_Cdmin_top 
       !
       ! Allocate public variable
@@ -310,6 +303,6 @@
       !
       ! initialisation
-      qisf(:,:)        = 0._wp  ; fwfisf  (:,:) = 0._wp
-      risf_tsc(:,:,:)  = 0._wp  ; fwfisf_b(:,:) = 0._wp
+      qisf    (:,:)    = 0._wp   ;   fwfisf  (:,:) = 0._wp
+      risf_tsc(:,:,:)  = 0._wp   ;   fwfisf_b(:,:) = 0._wp
       !
       ! define isf tbl tickness, top and bottom indice
@@ -317,5 +310,5 @@
       CASE ( 1 ) 
          rhisf_tbl(:,:) = rn_hisf_tbl
-         misfkt(:,:)    = mikt(:,:)         ! same indice for bg03 et cav => used in isfdiv
+         misfkt   (:,:) = mikt(:,:)         ! same indice for bg03 et cav => used in isfdiv
 
       CASE ( 2 , 3 )
@@ -351,4 +344,5 @@
             DO jj = 1, jpj
                 ik = 2
+!!gm potential bug: use gdepw_0 not _n
                 DO WHILE ( ik <= mbkt(ji,jj) .AND. gdepw_n(ji,jj,ik) < rzisf_tbl(ji,jj) ) ;  ik = ik + 1 ;  END DO
                 misfkt(ji,jj) = ik-1
@@ -359,5 +353,5 @@
          ! as in nn_isf == 1
          rhisf_tbl(:,:) = rn_hisf_tbl
-         misfkt(:,:)    = mikt(:,:)         ! same indice for bg03 et cav => used in isfdiv
+         misfkt   (:,:) = mikt(:,:)         ! same indice for bg03 et cav => used in isfdiv
          
          ! load variable used in fldread (use for temporal interpolation of isf fwf forcing)
@@ -382,5 +376,5 @@
             ! determine the deepest level influenced by the boundary layer
             DO jk = ikt+1, mbkt(ji,jj)
-               IF ( (SUM(e3t_n(ji,jj,ikt:jk-1)) < rhisf_tbl(ji,jj)) .AND. (tmask(ji,jj,jk) == 1) ) ikb = jk
+               IF( (SUM(e3t_n(ji,jj,ikt:jk-1)) < rhisf_tbl(ji,jj)) .AND. (tmask(ji,jj,jk) == 1) )   ikb = jk
             END DO
             rhisf_tbl(ji,jj) = MIN(rhisf_tbl(ji,jj), SUM(e3t_n(ji,jj,ikt:ikb))) ! limit the tbl to water thickness.
@@ -395,4 +389,5 @@
   END SUBROUTINE sbc_isf_init
 
+
   SUBROUTINE sbc_isf_bg03(kt)
       !!---------------------------------------------------------------------
@@ -407,6 +402,5 @@
       !!         interaction for climate models", Ocean Modelling 5(2003) 157-170.
       !!         (hereafter BG)
-      !! History :
-      !!         06-02  (C. Wang) Original code
+      !! History :  06-02  (C. Wang) Original code
       !!----------------------------------------------------------------------
       INTEGER, INTENT ( in ) :: kt
@@ -420,5 +414,5 @@
       !!----------------------------------------------------------------------
 
-      IF ( nn_timing == 1 ) CALL timing_start('sbc_isf_bg03')
+      IF( nn_timing == 1 )   CALL timing_start('sbc_isf_bg03')
       !
       DO ji = 1, jpi
@@ -446,12 +440,13 @@
                !add to salinity trend
             ELSE
-               qisf(ji,jj) = 0._wp ; fwfisf(ji,jj) = 0._wp
+               qisf(ji,jj) = 0._wp   ;   fwfisf(ji,jj) = 0._wp
             END IF
          END DO
       END DO
       !
-      IF( nn_timing == 1 )  CALL timing_stop('sbc_isf_bg03')
+      IF( nn_timing == 1 )   CALL timing_stop('sbc_isf_bg03')
       !
   END SUBROUTINE sbc_isf_bg03
+
 
   SUBROUTINE sbc_isf_cav( kt )
@@ -468,8 +463,9 @@
       !!                emp, emps  : update freshwater flux below ice shelf
       !!---------------------------------------------------------------------
-      INTEGER, INTENT(in)          ::   kt         ! ocean time step
+      INTEGER, INTENT(in) ::   kt   ! ocean time step
       !
       INTEGER  ::   ji, jj     ! dummy loop indices
       INTEGER  ::   nit
+      LOGICAL  ::   lit
       REAL(wp) ::   zlamb1, zlamb2, zlamb3
       REAL(wp) ::   zeps1,zeps2,zeps3,zeps4,zeps6,zeps7
@@ -477,8 +473,7 @@
       REAL(wp) ::   zeps = 1.e-20_wp        
       REAL(wp) ::   zerr
-      REAL(wp), DIMENSION(:,:), POINTER ::   zfrz
-      REAL(wp), DIMENSION(:,:), POINTER ::   zgammat, zgammas 
-      REAL(wp), DIMENSION(:,:), POINTER ::   zfwflx, zhtflx, zhtflx_b
-      LOGICAL  ::   lit
+      REAL(wp), DIMENSION(jpi,jpj) ::   zfrz
+      REAL(wp), DIMENSION(jpi,jpj) ::   zgammat, zgammas 
+      REAL(wp), DIMENSION(jpi,jpj) ::   zfwflx, zhtflx, zhtflx_b
       !!---------------------------------------------------------------------
       ! coeficient for linearisation of potential tfreez
@@ -489,7 +484,4 @@
       IF( nn_timing == 1 )  CALL timing_start('sbc_isf_cav')
       !
-      CALL wrk_alloc( jpi,jpj, zfrz  , zgammat, zgammas  )
-      CALL wrk_alloc( jpi,jpj, zfwflx, zhtflx , zhtflx_b )
-
       ! initialisation
       zgammat(:,:) = rn_gammat0 ; zgammas (:,:) = rn_gammas0
@@ -583,7 +575,4 @@
       CALL iom_put('isfgammas', zgammas)
       ! 
-      CALL wrk_dealloc( jpi,jpj, zfrz  , zgammat, zgammas  )
-      CALL wrk_dealloc( jpi,jpj, zfwflx, zhtflx , zhtflx_b )
-      !
       IF( nn_timing == 1 )  CALL timing_stop('sbc_isf_cav')
       !
@@ -605,5 +594,4 @@
       INTEGER  :: ikt                        
       INTEGER  :: ji, jj                     ! loop index
-      REAL(wp), DIMENSION(:,:), POINTER :: zustar           ! U, V at T point and friction velocity
       REAL(wp) :: zdku, zdkv                 ! U, V shear 
       REAL(wp) :: zPr, zSc, zRc              ! Prandtl, Scmidth and Richardson number 
@@ -619,6 +607,6 @@
       REAL(wp), PARAMETER :: znu   = 1.95e-6_wp ! kinamatic viscosity of sea water (m2.s-1)
       REAL(wp), DIMENSION(2) :: zts, zab
+      REAL(wp), DIMENSION(jpi,jpj) :: zustar   ! U, V at T point and friction velocity
       !!---------------------------------------------------------------------
-      CALL wrk_alloc( jpi,jpj, zustar )
       !
       SELECT CASE ( nn_gammablk )
@@ -631,7 +619,9 @@
          !! Jenkins et al., 2010, JPO, p2298-2312
          !! Adopted by Asay-Davis et al. (2015)
-
-         !! compute ustar (eq. 24)
-         zustar(:,:) = SQRT( rn_tfri2 * (utbl(:,:) * utbl(:,:) + vtbl(:,:) * vtbl(:,:) + rn_tfeb2) )
+!!gm  I don't understand the u* expression in those papers... (see for example zdfglf module)
+!!    for me ustar= Cd0 * |U|  not  (Cd0)^1/2 * |U| ....  which is what you can find in Jenkins et al.
+
+         !! compute ustar (eq. 24)           !! NB: here r_Cdmin_top = rn_Cd0 read in namdrg_top namelist)
+         zustar(:,:) = SQRT( r_Cdmin_top * (utbl(:,:) * utbl(:,:) + vtbl(:,:) * vtbl(:,:) + r_ke0_top) )
 
          !! Compute gammats
@@ -643,5 +633,5 @@
          !! as MOL depends of flux and flux depends of MOL, best will be iteration (TO DO)
          !! compute ustar
-         zustar(:,:) = SQRT( rn_tfri2 * (utbl(:,:) * utbl(:,:) + vtbl(:,:) * vtbl(:,:) + rn_tfeb2) )
+         zustar(:,:) = SQRT( r_Cdmin_top * (utbl(:,:) * utbl(:,:) + vtbl(:,:) * vtbl(:,:) + r_ke0_top) )
 
          !! compute Pr and Sc number (can be improved)
@@ -654,13 +644,15 @@
 
          !! compute gamma
-         DO ji=2,jpi
-            DO jj=2,jpj
+         DO ji = 2, jpi
+            DO jj = 2, jpj
                ikt = mikt(ji,jj)
 
-               IF (zustar(ji,jj) == 0._wp) THEN           ! only for kt = 1 I think
+               IF( zustar(ji,jj) == 0._wp ) THEN           ! only for kt = 1 I think
                   pgt = rn_gammat0
                   pgs = rn_gammas0
                ELSE
                   !! compute Rc number (as done in zdfric.F90)
+!!gm better to do it like in the new zdfric.F90   i.e. avm weighted Ri computation
+!!gm moreover, use Max(rn2,0) to take care of static instabilities....
                   zcoef = 0.5_wp / e3w_n(ji,jj,ikt)
                   !                                            ! shear of horizontal velocity
@@ -708,8 +700,8 @@
          CALL lbc_lnk(pgs(:,:),'T',1.)
       END SELECT
-      CALL wrk_dealloc( jpi,jpj, zustar )
       !
    END SUBROUTINE sbc_isf_gammats
 
+
    SUBROUTINE sbc_isf_tbl( pvarin, pvarout, cd_ptin )
       !!----------------------------------------------------------------------
@@ -719,16 +711,13 @@
       !!
       !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:,:), INTENT( in  ) :: pvarin
-      REAL(wp), DIMENSION(:,:)  , INTENT( out ) :: pvarout
-      CHARACTER(len=1),           INTENT( in  ) :: cd_ptin ! point of variable in/out
-      !
-      REAL(wp) :: ze3, zhk
-      REAL(wp), DIMENSION(:,:), POINTER :: zhisf_tbl ! thickness of the tbl
-
-      INTEGER :: ji, jj, jk                  ! loop index
-      INTEGER :: ikt, ikb                    ! top and bottom index of the tbl
-      !!----------------------------------------------------------------------
-      ! allocation
-      CALL wrk_alloc( jpi,jpj, zhisf_tbl)
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) :: pvarin
+      REAL(wp), DIMENSION(:,:)  , INTENT(  out) :: pvarout
+      CHARACTER(len=1),           INTENT(in   ) :: cd_ptin ! point of variable in/out
+      !
+      INTEGER ::   ji, jj, jk                ! loop index
+      INTEGER ::   ikt, ikb                    ! top and bottom index of the tbl
+      REAL(wp) ::   ze3, zhk
+      REAL(wp), DIMENSION(jpi,jpj) :: zhisf_tbl ! thickness of the tbl
+      !!----------------------------------------------------------------------
       
       ! initialisation
@@ -741,5 +730,5 @@
                ikt = miku(ji,jj) ; ikb = miku(ji,jj)
                ! thickness of boundary layer at least the top level thickness
-               zhisf_tbl(ji,jj) = MAX(rhisf_tbl_0(ji,jj), e3u_n(ji,jj,ikt))
+               zhisf_tbl(ji,jj) = MAX( rhisf_tbl_0(ji,jj) , e3u_n(ji,jj,ikt) )
 
                ! determine the deepest level influenced by the boundary layer
@@ -760,6 +749,7 @@
             END DO
          END DO
-         DO jj = 2,jpj
-            DO ji = 2,jpi
+         DO jj = 2, jpj
+            DO ji = 2, jpi
+!!gm a wet-point only average should be used here !!!
                pvarout(ji,jj) = 0.5_wp * (pvarout(ji,jj) + pvarout(ji-1,jj))
             END DO
@@ -791,6 +781,7 @@
             END DO
          END DO
-         DO jj = 2,jpj
-            DO ji = 2,jpi
+         DO jj = 2, jpj
+            DO ji = 2, jpi
+!!gm a wet-point only average should be used here !!!
                pvarout(ji,jj) = 0.5_wp * (pvarout(ji,jj) + pvarout(ji,jj-1))
             END DO
@@ -816,10 +807,7 @@
          END DO
       END SELECT
-
+      !
       ! mask mean tbl value
       pvarout(:,:) = pvarout(:,:) * ssmask(:,:)
-
-      ! deallocation
-      CALL wrk_dealloc( jpi,jpj, zhisf_tbl )      
       !
    END SUBROUTINE sbc_isf_tbl
@@ -887,4 +875,5 @@
       !
    END SUBROUTINE sbc_isf_div
+
    !!======================================================================
 END MODULE sbcisf
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 9019)
@@ -33,6 +33,7 @@
    USE sbcblk         ! surface boundary condition: bulk formulation
    USE sbcice_if      ! surface boundary condition: ice-if sea-ice model
-   USE sbcice_lim     ! surface boundary condition: LIM 3.0 sea-ice model
-   USE sbcice_lim_2   ! surface boundary condition: LIM 2.0 sea-ice model
+#if defined key_lim3
+   USE icestp         ! surface boundary condition: LIM 3.0 sea-ice model
+#endif
    USE sbcice_cice    ! surface boundary condition: CICE    sea-ice model
    USE sbcisf         ! surface boundary condition: ice-shelf
@@ -91,6 +92,6 @@
       NAMELIST/namsbc/ nn_fsbc  ,                                                    &
          &             ln_usr   , ln_flx   , ln_blk       ,                          &
-         &             ln_cpl   , ln_mixcpl, nn_components, nn_limflx,               &
-         &             nn_ice   , nn_ice_embd,                                       &
+         &             ln_cpl   , ln_mixcpl, nn_components,                          &
+         &             nn_ice   , ln_ice_embd,                                       &
          &             ln_traqsr, ln_dm2dc ,                                         &
          &             ln_rnf   , nn_fwb   , ln_ssr   , ln_isf    , ln_apr_dyn ,     &
@@ -118,12 +119,10 @@
 #if defined key_agrif
       IF( Agrif_Root() ) THEN                ! AGRIF zoom (cf r1242: possibility to run without ice in fine grid)
-         IF( lk_lim2 )   nn_ice      = 2
-         IF( lk_lim3 )   nn_ice      = 3
-         IF( lk_cice )   nn_ice      = 4
+         IF( lk_lim3 )   nn_ice      = 2
+         IF( lk_cice )   nn_ice      = 3
       ENDIF
 #else
-      IF( lk_lim2 )   nn_ice      = 2
-      IF( lk_lim3 )   nn_ice      = 3
-      IF( lk_cice )   nn_ice      = 4
+      IF( lk_lim3 )   nn_ice      = 2
+      IF( lk_cice )   nn_ice      = 3
 #endif
       !
@@ -141,8 +140,7 @@
          WRITE(numout,*) '         OASIS coupling (with atm or sas)           lk_oasis      = ', lk_oasis
          WRITE(numout,*) '         components of your executable              nn_components = ', nn_components
-         WRITE(numout,*) '         Multicategory heat flux formulation (LIM3) nn_limflx     = ', nn_limflx
          WRITE(numout,*) '      Sea-ice : '
          WRITE(numout,*) '         ice management in the sbc (=0/1/2/3)       nn_ice        = ', nn_ice
-         WRITE(numout,*) '         ice-ocean embedded/levitating (=0/1/2)     nn_ice_embd   = ', nn_ice_embd
+         WRITE(numout,*) '         ice embedded into ocean                    ln_ice_embd   = ', ln_ice_embd
          WRITE(numout,*) '      Misc. options of sbc : '
          WRITE(numout,*) '         Light penetration in temperature Eq.       ln_traqsr     = ', ln_traqsr
@@ -202,40 +200,18 @@
       CASE( 0 )                        !- no ice in the domain
       CASE( 1 )                        !- Ice-cover climatology ("Ice-if" model)  
-      CASE( 2 )                        !- LIM2 ice model
-         IF( .NOT.( ln_blk .OR. ln_cpl ) )   CALL ctl_stop( 'sbc_init : LIM2 sea-ice model requires ln_blk or ln_cpl = T' )
-      CASE( 3 )                        !- LIM3 ice model
-         IF( nn_ice_embd == 0            )   CALL ctl_stop( 'sbc_init : LIM3 sea-ice models require nn_ice_embd = 1 or 2' )
-      CASE( 4 )                        !- CICE ice model
+      CASE( 2 )                        !- LIM3 ice model
+      CASE( 3 )                        !- CICE ice model
          IF( .NOT.( ln_blk .OR. ln_cpl ) )   CALL ctl_stop( 'sbc_init : CICE sea-ice model requires ln_blk or ln_cpl = T' )
-         IF( nn_ice_embd == 0            )   CALL ctl_stop( 'sbc_init : CICE sea-ice models require nn_ice_embd = 1 or 2' )
          IF( lk_agrif                    )   CALL ctl_stop( 'sbc_init : CICE sea-ice model not currently available with AGRIF' ) 
       CASE DEFAULT                     !- not supported
       END SELECT
       !
-      IF( nn_ice == 3 ) THEN           !- LIM3 case: multi-category flux option
-         IF(lwp) WRITE(numout,*)
-         SELECT CASE( nn_limflx )         ! LIM3 Multi-category heat flux formulation
-         CASE ( -1 )
-            IF(lwp) WRITE(numout,*) '   LIM3: use per-category fluxes (nn_limflx = -1) '
-            IF( ln_cpl )   CALL ctl_stop( 'sbc_init : the chosen nn_limflx for LIM3 in coupled mode must be 0 or 2' )
-         CASE ( 0  )
-            IF(lwp) WRITE(numout,*) '   LIM3: use average per-category fluxes (nn_limflx = 0) '
-         CASE ( 1  )
-            IF(lwp) WRITE(numout,*) '   LIM3: use average then redistribute per-category fluxes (nn_limflx = 1) '
-            IF( ln_cpl )   CALL ctl_stop( 'sbc_init : the chosen nn_limflx for LIM3 in coupled mode must be 0 or 2' )
-         CASE ( 2  )
-            IF(lwp) WRITE(numout,*) '   LIM3: Redistribute a single flux over categories (nn_limflx = 2) '
-            IF( .NOT.ln_cpl )   CALL ctl_stop( 'sbc_init : the chosen nn_limflx for LIM3 in forced mode cannot be 2' )
-         CASE DEFAULT
-            CALL ctl_stop( 'sbcmod: LIM3 option, nn_limflx, should be between -1 and 2' )
-         END SELECT
-      ELSE                             ! other sea-ice model
-         IF( nn_limflx >= 0  )   CALL ctl_warn( 'sbc_init : multi-category flux option (nn_limflx) only available in LIM3' )
-      ENDIF
-      !
       !                       !**  allocate and set required variables
       !
       !                             !* allocate sbc arrays
       IF( sbc_oce_alloc() /= 0 )   CALL ctl_stop( 'sbc_init : unable to allocate sbc_oce arrays' )
+#if ! defined key_lim3 && ! defined key_cice
+      IF( sbc_ice_alloc() /= 0 )   CALL ctl_stop( 'sbc_init : unable to allocate sbc_ice arrays' )
+#endif
       !
       IF( .NOT.ln_isf ) THEN        !* No ice-shelf in the domain : allocate and set to zero
@@ -329,5 +305,5 @@
       IF( ln_ssr      )   CALL sbc_ssr_init            ! Sea-Surface Restoring initialization
       !
-      IF( ln_isf      )   CALL sbc_isf_init               ! Compute iceshelves
+      IF( ln_isf      )   CALL sbc_isf_init            ! Compute iceshelves
       !
                           CALL sbc_rnf_init            ! Runof initialization
@@ -335,9 +311,14 @@
       IF( ln_apr_dyn )    CALL sbc_apr_init            ! Atmo Pressure Forcing initialization
       !
-      IF( nn_ice == 3 )   CALL sbc_lim_init            ! LIM3 initialization
-      !
-      IF( nn_ice == 4 )   CALL cice_sbc_init( nsbc )   ! CICE initialization
-      !
-      IF( ln_wave     )   CALL sbc_wave_init              ! surface wave initialisation
+#if defined key_lim3
+      IF( lk_agrif .AND. nn_ice == 0 ) THEN            ! allocate ice arrays in case agrif + ice-model + no-ice in child grid
+                          IF( sbc_ice_alloc() /= 0 )   CALL ctl_stop('STOP', 'sbc_ice_alloc : unable to allocate arrays' )
+      ELSEIF( nn_ice == 2 ) THEN
+                          CALL ice_init                ! ICE initialization
+      ENDIF
+#endif
+      IF( nn_ice == 3 )   CALL cice_sbc_init( nsbc )   ! CICE initialization
+      !
+      IF( ln_wave     )   CALL sbc_wave_init           ! surface wave initialisation
       !
    END SUBROUTINE sbc_init
@@ -428,8 +409,9 @@
       !
       SELECT CASE( nn_ice )                                       ! Update heat and freshwater fluxes over sea-ice areas
-      CASE(  1 )   ;         CALL sbc_ice_if   ( kt )                ! Ice-cover climatology ("Ice-if" model)
-      CASE(  2 )   ;         CALL sbc_ice_lim_2( kt, nsbc )          ! LIM-2 ice model
-      CASE(  3 )   ;         CALL sbc_ice_lim  ( kt, nsbc )          ! LIM-3 ice model
-      CASE(  4 )   ;         CALL sbc_ice_cice ( kt, nsbc )          ! CICE ice model
+      CASE(  1 )   ;         CALL sbc_ice_if   ( kt )             ! Ice-cover climatology ("Ice-if" model)
+#if defined key_lim3
+      CASE(  2 )   ;         CALL ice_stp  ( kt, nsbc )           ! LIM-3 ice model
+#endif
+      CASE(  3 )   ;         CALL sbc_ice_cice ( kt, nsbc )       ! CICE ice model
       END SELECT
 
@@ -539,5 +521,5 @@
       !!---------------------------------------------------------------------
       !
-      IF( nn_ice == 4 )   CALL cice_sbc_final
+      IF( nn_ice == 3 )   CALL cice_sbc_final
       !
    END SUBROUTINE sbc_final
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90	(revision 9019)
@@ -121,5 +121,5 @@
          ssu_m(:,:) = ssu_m(:,:) + ub(:,:,1)
          ssv_m(:,:) = ssv_m(:,:) + vb(:,:,1)
-         IF( l_useCT )  THEN    ;   sst_m(:,:) = sst_m(:,:) + eos_pt_from_ct( zts(:,:,jp_tem), zts(:,:,jp_sal) )
+         IF( l_useCT )  THEN     ;   sst_m(:,:) = sst_m(:,:) + eos_pt_from_ct( zts(:,:,jp_tem), zts(:,:,jp_sal) )
          ELSE                    ;   sst_m(:,:) = sst_m(:,:) + zts(:,:,jp_tem)
          ENDIF
@@ -236,5 +236,5 @@
       ENDIF
       !
-      IF( .NOT. l_ssm_mean ) THEN   ! default initialisation. needed by lim_istate
+      IF( .NOT.l_ssm_mean ) THEN   ! default initialisation. needed by iceistate
          !
          IF(lwp) WRITE(numout,*) '   default initialisation of ss._m arrays'
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcwave.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcwave.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/SBC/sbcwave.F90	(revision 9019)
@@ -19,5 +19,5 @@
    USE oce            ! ocean variables
    USE sbc_oce	       ! Surface boundary condition: ocean fields
-   USE zdf_oce,  ONLY : ln_zdfqiao
+   USE zdf_oce,  ONLY : ln_zdfswm
    USE bdy_oce        ! open boundary condition variables
    USE domvvl         ! domain: variable volume layers
@@ -87,7 +87,10 @@
       INTEGER  ::   jj, ji, jk   ! dummy loop argument
       INTEGER  ::   ik           ! local integer 
-      REAL(wp) ::  ztransp, zfac, ztemp, zsp0
-      REAL(wp) ::  zdep_u, zdep_v, zkh_u, zkh_v, zda_u, zda_v
+      REAL(wp) ::  ztransp, zfac, zsp0
+      REAL(wp) ::  zdepth, zsqrt_depth,  zexp_depth, z_two_thirds, zsqrtpi !sqrt of pi
+      REAL(wp) ::  zbot_u, zbot_v, zkb_u, zkb_v, zke3_u, zke3_v, zda_u, zda_v
+      REAL(wp) ::  zstokes_psi_u_bot, zstokes_psi_v_bot
       REAL(wp), DIMENSION(:,:)  , POINTER ::   zk_t, zk_u, zk_v, zu0_sd, zv0_sd   ! 2D workspace
+      REAL(wp), DIMENSION(:,:)  , POINTER ::   zstokes_psi_u_top, zstokes_psi_v_top   ! 2D workspace
       REAL(wp), DIMENSION(:,:,:), POINTER ::   ze3divh                            ! 3D workspace
       !!---------------------------------------------------------------------
@@ -95,6 +98,9 @@
       CALL wrk_alloc( jpi,jpj,jpk,   ze3divh )
       CALL wrk_alloc( jpi,jpj,       zk_t, zk_u, zk_v, zu0_sd, zv0_sd )
-      !
-      !
+      CALL wrk_alloc( jpi,jpj,       zstokes_psi_u_top, zstokes_psi_v_top)
+      !
+      !
+      zsqrtpi = SQRT(rpi)
+      z_two_thirds = 2.0_wp / 3.0_wp
       zfac =  2.0_wp * rpi / 16.0_wp
       DO jj = 1, jpj                ! exp. wave number at t-point    (Eq. (19) in Breivick et al. (2014) )
@@ -106,7 +112,8 @@
                tsd2d(ji,jj) = zsp0
                ! Wavenumber scale
-               zk_t(ji,jj) = ABS( zsp0 ) / MAX( ABS( 5.97_wp*ztransp ) , 0.0000001_wp )
-         END DO
-      END DO      
+               zk_t(ji,jj) =  (1.0_wp-2.0_wp/3.0_wp)*zsp0/MAX(2.0_wp*ztransp,0.0000001_wp)
+         END DO
+      END DO
+      !
       DO jj = 1, jpjm1              ! exp. wave number & Stokes drift velocity at u- & v-points
          DO ji = 1, jpim1
@@ -120,16 +127,42 @@
       !
       !                       !==  horizontal Stokes Drift 3D velocity  ==!
+      DO jj = 1, jpjm1              ! exp. wave number & Stokes drift velocity at u- & v-points
+         DO ji = 1, jpim1
+            zstokes_psi_u_top(ji,jj) = 0._wp
+            zstokes_psi_v_top(ji,jj) = 0._wp
+         END DO
+      END DO
+
       DO jk = 1, jpkm1
          DO jj = 2, jpjm1
             DO ji = 2, jpim1
-               zdep_u = 0.5_wp * ( gdept_n(ji,jj,jk) + gdept_n(ji+1,jj,jk) )
-               zdep_v = 0.5_wp * ( gdept_n(ji,jj,jk) + gdept_n(ji,jj+1,jk) )
-               !                          
-               zkh_u = zk_u(ji,jj) * zdep_u     ! k * depth
-               zkh_v = zk_v(ji,jj) * zdep_v
-               !                                ! Depth attenuation
-               zda_u = EXP( -2.0_wp*zkh_u ) / ( 1.0_wp + 8.0_wp*zkh_u )
-               zda_v = EXP( -2.0_wp*zkh_v ) / ( 1.0_wp + 8.0_wp*zkh_v )
+               zbot_u = 0.5_wp * ( gdepw_n(ji,jj,jk+1) + gdepw_n(ji+1,jj,jk+1) )
+               zbot_v = 0.5_wp * ( gdepw_n(ji,jj,jk+1) + gdepw_n(ji,jj+1,jk+1) )
+               zkb_u = 2.0_wp * zk_u(ji,jj) * zbot_u     ! 2k * bottom depth
+               zkb_v = 2.0_wp * zk_v(ji,jj) * zbot_v     ! 2k * bottom depth
                !
+               zke3_u = MAX(1.e-8_wp, 2.0_wp * zk_u(ji,jj) * e3u_n(ji,jj,jk))     ! 2k * thickness
+               zke3_v = MAX(1.e-8_wp, 2.0_wp * zk_v(ji,jj) * e3v_n(ji,jj,jk))     ! 2k * thickness
+
+               ! Depth attenuation .... do u component first..
+               zdepth=zkb_u
+               zsqrt_depth = SQRT(zdepth)
+               zexp_depth = EXP(-zdepth)
+               zstokes_psi_u_bot = 1.0_wp - zexp_depth  &
+                    & - z_two_thirds*(zsqrtpi*zsqrt_depth*zdepth*ERFC(zsqrt_depth) &
+                    &                  + 1.0_wp - (1.0_wp + zdepth)*zexp_depth)
+               zda_u = (zstokes_psi_u_bot - zstokes_psi_u_top(ji,jj))/zke3_u
+               zstokes_psi_u_top(ji,jj) = zstokes_psi_u_bot
+
+               !         ... and then v component
+               zdepth=zkb_v
+               zsqrt_depth = SQRT(zdepth)
+               zexp_depth = EXP(-zdepth)
+               zstokes_psi_v_bot = 1.0_wp - zexp_depth  &
+                    & - z_two_thirds*(zsqrtpi*zsqrt_depth*zdepth*ERFC(zsqrt_depth) &
+                    &                  + 1.0_wp - (1.0_wp + zdepth)*zexp_depth)
+               zda_v = (zstokes_psi_v_bot - zstokes_psi_v_top(ji,jj))/zke3_v
+               zstokes_psi_v_top(ji,jj) = zstokes_psi_v_bot
+              !
                usd(ji,jj,jk) = zda_u * zu0_sd(ji,jj) * umask(ji,jj,jk)
                vsd(ji,jj,jk) = zda_v * zv0_sd(ji,jj) * vmask(ji,jj,jk)
@@ -137,5 +170,8 @@
          END DO
       END DO   
-      CALL lbc_lnk( usd(:,:,:), 'U', vsd(:,:,:), 'V', -1. )
+      CALL lbc_lnk( usd(:,:,:), 'U', -1. )
+      CALL lbc_lnk( vsd(:,:,:), 'V', -1. )
+
+
       !
       !                       !==  vertical Stokes Drift 3D velocity  ==!
@@ -152,10 +188,12 @@
       END DO
       !
-      IF( .NOT. AGRIF_Root() ) THEN
-         IF( nbondi ==  1 .OR. nbondi == 2 )   ze3divh(nlci-1,   :  ,:) = 0._wp      ! east
-         IF( nbondi == -1 .OR. nbondi == 2 )   ze3divh(  2   ,   :  ,:) = 0._wp      ! west
-         IF( nbondj ==  1 .OR. nbondj == 2 )   ze3divh(  :   ,nlcj-1,:) = 0._wp      ! north
-         IF( nbondj == -1 .OR. nbondj == 2 )   ze3divh(  :   ,  2   ,:) = 0._wp      ! south
-      ENDIF
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() ) THEN
+         IF( nbondi == -1 .OR. nbondi == 2 )   ze3divh( 2:nbghostcells+1,:        ,:) = 0._wp      ! west
+         IF( nbondi ==  1 .OR. nbondi == 2 )   ze3divh( nlci-nbghostcells:nlci-1,:,:) = 0._wp      ! east
+         IF( nbondj == -1 .OR. nbondj == 2 )   ze3divh( :,2:nbghostcells+1        ,:) = 0._wp      ! south
+         IF( nbondj ==  1 .OR. nbondj == 2 )   ze3divh( :,nlcj-nbghostcells:nlcj-1,:) = 0._wp      ! north
+      ENDIF
+#endif
       !
       CALL lbc_lnk( ze3divh, 'T', 1. )
@@ -185,4 +223,5 @@
       CALL wrk_dealloc( jpi,jpj,jpk,   ze3divh )
       CALL wrk_dealloc( jpi,jpj,       zk_t, zk_u, zk_v, zu0_sd, zv0_sd )
+      CALL wrk_dealloc( jpi,jpj,       zstokes_psi_u_top, zstokes_psi_v_top)
       !
    END SUBROUTINE sbc_stokes
@@ -227,5 +266,5 @@
          !
          ! Read also wave number if needed, so that it is available in coupling routines
-         IF( ln_zdfqiao .AND. .NOT.cpl_wnum ) THEN
+         IF( ln_zdfswm .AND. .NOT.cpl_wnum ) THEN
             CALL fld_read( kt, nn_fsbc, sf_wn )          ! read wave parameters from external forcing
             wnum(:,:) = sf_wn(1)%fnow(:,:,1)
@@ -342,8 +381,14 @@
          ALLOCATE( div_sd(jpi,jpj) )
          ALLOCATE( tsd2d (jpi,jpj) )
+
+         ut0sd(:,:) = 0._wp
+         vt0sd(:,:) = 0._wp
+         hsw(:,:) = 0._wp
+         wmp(:,:) = 0._wp
+
          usd(:,:,:) = 0._wp
          vsd(:,:,:) = 0._wp
          wsd(:,:,:) = 0._wp
-         ! Wave number needed only if ln_zdfqiao=T
+         ! Wave number needed only if ln_zdfswm=T
          IF( .NOT. cpl_wnum ) THEN
             ALLOCATE( sf_wn(1), STAT=ierror )           !* allocate and fill sf_wave with sn_wnum
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/STO/stopar.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/STO/stopar.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/STO/stopar.F90	(revision 9019)
@@ -159,5 +159,5 @@
       INTEGER  :: ji, jj, jk, jsto, jflt
       REAL(wp) :: stomax
-
+      !!----------------------------------------------------------------------
       !
       ! Update 2D stochastic arrays
@@ -235,5 +235,5 @@
          CALL lbc_lnk( sto3d(:,:,:,jsto), sto3d_typ(jsto), sto3d_sgn(jsto) )
       END DO
-
+      !
    END SUBROUTINE sto_par
 
@@ -267,6 +267,15 @@
       REWIND( numnam_cfg )              ! Namelist namdyn_adv in configuration namelist : Momentum advection scheme
       READ  ( numnam_cfg, namsto, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsto in configuration namelist', lwp )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namsto in configuration namelist', lwp )
       IF(lwm) WRITE ( numond, namsto )
+
+      IF( .NOT.ln_rststo ) THEN   ! no use of stochastic parameterization
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'sto_par_init : NO use of stochastic parameterization'
+            WRITE(numout,*) '~~~~~~~~~~~~'
+         ENDIF
+         RETURN
+      ENDIF
 
       !IF(ln_ens_rst_in) cn_storst_in = cn_mem//cn_storst_in
@@ -673,8 +682,6 @@
       !!                  ***  ROUTINE sto_rst_read  ***
       !!
-
       !! ** Purpose :   read stochastic parameters from restart file
       !!----------------------------------------------------------------------
-
       INTEGER  :: jsto, jseed
       INTEGER(KIND=8)     ::   ziseed(4)           ! RNG seeds in integer type
@@ -683,4 +690,5 @@
       CHARACTER(LEN=9)    ::   clsto3d='sto3d_000' ! stochastic parameter variable name
       CHARACTER(LEN=10)   ::   clseed='seed0_0000' ! seed variable name
+      !!----------------------------------------------------------------------
 
       IF ( jpsto2d > 0 .OR. jpsto3d > 0 ) THEN
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/eosbn2.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/eosbn2.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/eosbn2.F90	(revision 9019)
@@ -46,5 +46,4 @@
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
    USE prtctl         ! Print control
-   USE wrk_nemo       ! Memory Allocation
    USE lbclnk         ! ocean lateral boundary conditions
    USE timing         ! Timing
@@ -231,5 +230,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start('eos-insitu')
+      IF( ln_timing )   CALL timing_start('eos-insitu')
       !
       SELECT CASE( neos )
@@ -298,5 +297,5 @@
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=prd, clinfo1=' eos-insitu  : ', ovlap=1, kdim=jpk )
       !
-      IF( nn_timing == 1 )   CALL timing_stop('eos-insitu')
+      IF( ln_timing )   CALL timing_stop('eos-insitu')
       !
    END SUBROUTINE eos_insitu
@@ -329,5 +328,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start('eos-pot')
+      IF( ln_timing )   CALL timing_start('eos-pot')
       !
       SELECT CASE ( neos )
@@ -465,5 +464,5 @@
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=prd, clinfo1=' eos-pot: ', tab3d_2=prhop, clinfo2=' pot : ', ovlap=1, kdim=jpk )
       !
-      IF( nn_timing == 1 )   CALL timing_stop('eos-pot')
+      IF( ln_timing )   CALL timing_stop('eos-pot')
       !
    END SUBROUTINE eos_insitu_pot
@@ -491,5 +490,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start('eos2d')
+      IF( ln_timing )   CALL timing_start('eos2d')
       !
       prd(:,:) = 0._wp
@@ -560,5 +559,5 @@
       IF(ln_ctl)   CALL prt_ctl( tab2d_1=prd, clinfo1=' eos2d: ' )
       !
-      IF( nn_timing == 1 )   CALL timing_stop('eos2d')
+      IF( ln_timing )   CALL timing_stop('eos2d')
       !
    END SUBROUTINE eos_insitu_2d
@@ -583,5 +582,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start('rab_3d')
+      IF( ln_timing )   CALL timing_start('rab_3d')
       !
       SELECT CASE ( neos )
@@ -674,5 +673,5 @@
          &                       tab3d_2=pab(:,:,:,jp_sal), clinfo2=' rab_3d_s : ', ovlap=1, kdim=jpk )
       !
-      IF( nn_timing == 1 )   CALL timing_stop('rab_3d')
+      IF( ln_timing )   CALL timing_stop('rab_3d')
       !
    END SUBROUTINE rab_3d
@@ -696,5 +695,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 ) CALL timing_start('rab_2d')
+      IF( ln_timing )   CALL timing_start('rab_2d')
       !
       pab(:,:,:) = 0._wp
@@ -791,5 +790,5 @@
          &                       tab2d_2=pab(:,:,jp_sal), clinfo2=' rab_2d_s : ' )
       !
-      IF( nn_timing == 1 )   CALL timing_stop('rab_2d')
+      IF( ln_timing )   CALL timing_stop('rab_2d')
       !
    END SUBROUTINE rab_2d
@@ -812,5 +811,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 ) CALL timing_start('rab_2d')
+      IF( ln_timing )   CALL timing_start('rab_2d')
       !
       pab(:) = 0._wp
@@ -888,5 +887,5 @@
       END SELECT
       !
-      IF( nn_timing == 1 )   CALL timing_stop('rab_2d')
+      IF( ln_timing )   CALL timing_stop('rab_2d')
       !
    END SUBROUTINE rab_0d
@@ -915,5 +914,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 ) CALL timing_start('bn2')
+      IF( ln_timing )   CALL timing_start('bn2')
       !
       DO jk = 2, jpkm1           ! interior points only (2=< jk =< jpkm1 )
@@ -928,5 +927,5 @@
                pn2(ji,jj,jk) = grav * (  zaw * ( pts(ji,jj,jk-1,jp_tem) - pts(ji,jj,jk,jp_tem) )     &
                   &                    - zbw * ( pts(ji,jj,jk-1,jp_sal) - pts(ji,jj,jk,jp_sal) )  )  &
-                  &            / e3w_n(ji,jj,jk) * tmask(ji,jj,jk)
+                  &            / e3w_n(ji,jj,jk) * wmask(ji,jj,jk)
             END DO
          END DO
@@ -935,5 +934,5 @@
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=pn2, clinfo1=' bn2  : ', ovlap=1, kdim=jpk )
       !
-      IF( nn_timing == 1 )   CALL timing_stop('bn2')
+      IF( ln_timing )   CALL timing_stop('bn2')
       !
    END SUBROUTINE bn2
@@ -963,5 +962,5 @@
       !!----------------------------------------------------------------------
       !
-      IF ( nn_timing == 1 )   CALL timing_start('eos_pt_from_ct')
+      IF( ln_timing )   CALL timing_start('eos_pt_from_ct')
       !
       zdeltaS = 5._wp
@@ -994,5 +993,5 @@
       END DO
       !
-      IF( nn_timing == 1 )   CALL timing_stop('eos_pt_from_ct')
+      IF( ln_timing )   CALL timing_stop('eos_pt_from_ct')
       !
    END FUNCTION eos_pt_from_ct
@@ -1128,5 +1127,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start('eos_pen')
+      IF( ln_timing )   CALL timing_start('eos_pen')
       !
       SELECT CASE ( neos )
@@ -1222,5 +1221,5 @@
       END SELECT
       !
-      IF( nn_timing == 1 )   CALL timing_stop('eos_pen')
+      IF( ln_timing )   CALL timing_stop('eos_pen')
       !
    END SUBROUTINE eos_pen
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv.F90	(revision 9019)
@@ -14,9 +14,11 @@
    !!----------------------------------------------------------------------
    !!   tra_adv       : compute ocean tracer advection trend
-   !!   tra_adv_ctl   : control the different options of advection scheme
+   !!   tra_adv_init  : control the different options of advection scheme
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and active tracers
    USE dom_oce        ! ocean space and time domain
    USE domvvl         ! variable vertical scale factors
+   USE sbcwave        ! wave module
+   USE sbc_oce        ! surface boundary condition: ocean
    USE traadv_cen     ! centered scheme           (tra_adv_cen  routine)
    USE traadv_fct     ! FCT      scheme           (tra_adv_fct  routine)
@@ -27,6 +29,7 @@
    USE ldftra         ! lateral diffusion: eddy diffusivity & EIV coeff.
    USE ldfslp         ! Lateral diffusion: slopes of neutral surfaces
-   USE trd_oce         ! trends: ocean variables
-   USE trdtra          ! trends manager: tracers 
+   USE trd_oce        ! trends: ocean variables
+   USE trdtra         ! trends manager: tracers 
+   USE diaptr         ! Poleward heat transport 
    !
    USE in_out_manager ! I/O manager
@@ -34,22 +37,18 @@
    USE prtctl         ! Print control
    USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
-   USE sbcwave        ! wave module
-   USE sbc_oce        ! surface boundary condition: ocean
-   USE diaptr         ! Poleward heat transport 
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   tra_adv        ! routine called by step module
-   PUBLIC   tra_adv_init   ! routine called by opa module
+   PUBLIC   tra_adv        ! called by step.F90
+   PUBLIC   tra_adv_init   ! called by nemogcm.F90
 
    !                            !!* Namelist namtra_adv *
+   LOGICAL ::   ln_traadv_NONE   ! no advection on T and S
    LOGICAL ::   ln_traadv_cen    ! centered scheme flag
    INTEGER ::      nn_cen_h, nn_cen_v   ! =2/4 : horizontal and vertical choices of the order of CEN scheme
    LOGICAL ::   ln_traadv_fct    ! FCT scheme flag
    INTEGER ::      nn_fct_h, nn_fct_v   ! =2/4 : horizontal and vertical choices of the order of FCT scheme
-   INTEGER ::      nn_fct_zts           ! >=1 : 2nd order FCT with vertical sub-timestepping
    LOGICAL ::   ln_traadv_mus    ! MUSCL scheme flag
    LOGICAL ::      ln_mus_ups           ! use upstream scheme in vivcinity of river mouths
@@ -58,19 +57,17 @@
    LOGICAL ::   ln_traadv_qck    ! QUICKEST scheme flag
 
-   INTEGER ::              nadv             ! choice of the type of advection scheme
-   !
-   !                                        ! associated indices:
+   INTEGER ::   nadv             ! choice of the type of advection scheme
+   !                             ! associated indices:
    INTEGER, PARAMETER ::   np_NO_adv  = 0   ! no T-S advection
    INTEGER, PARAMETER ::   np_CEN     = 1   ! 2nd/4th order centered scheme
    INTEGER, PARAMETER ::   np_FCT     = 2   ! 2nd/4th order Flux Corrected Transport scheme
-   INTEGER, PARAMETER ::   np_FCT_zts = 3   ! 2nd order FCT scheme with vertical sub-timestepping
-   INTEGER, PARAMETER ::   np_MUS     = 4   ! MUSCL scheme
-   INTEGER, PARAMETER ::   np_UBS     = 5   ! 3rd order Upstream Biased Scheme
-   INTEGER, PARAMETER ::   np_QCK     = 6   ! QUICK scheme
+   INTEGER, PARAMETER ::   np_MUS     = 3   ! MUSCL scheme
+   INTEGER, PARAMETER ::   np_UBS     = 4   ! 3rd order Upstream Biased Scheme
+   INTEGER, PARAMETER ::   np_QCK     = 5   ! QUICK scheme
    
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -86,27 +83,22 @@
       !! ** Method  : - Update (ua,va) with the advection term following nadv
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       !
       INTEGER ::   jk   ! dummy loop index
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zun, zvn, zwn
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrdt, ztrds   ! 3D workspace
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_adv')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   zun, zvn, zwn )
+      REAL(wp), DIMENSION(jpi,jpj,jpk)        :: zun, zvn, zwn   ! 3D workspace
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ztrdt, ztrds
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('tra_adv')
       !
       !                                          ! set time step
-      zun(:,:,:) = 0.0
-      zvn(:,:,:) = 0.0
-      zwn(:,:,:) = 0.0
-      !    
-      IF( neuler == 0 .AND. kt == nit000 ) THEN     ! at nit000
-         r2dt = rdt                                 ! = rdt (restarting with Euler time stepping)
-      ELSEIF( kt <= nit000 + 1) THEN                ! at nit000 or nit000+1
-         r2dt = 2._wp * rdt                         ! = 2 rdt (leapfrog)
+      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;   r2dt =        rdt   ! at nit000             (Euler)
+      ELSEIF( kt <= nit000 + 1 )           THEN   ;   r2dt = 2._wp* rdt   ! at nit000 or nit000+1 (Leapfrog)
       ENDIF
       !
       !                                         !==  effective transport  ==!
+      zun(:,:,jpk) = 0._wp
+      zvn(:,:,jpk) = 0._wp
+      zwn(:,:,jpk) = 0._wp
       IF( ln_wave .AND. ln_sdw )  THEN
          DO jk = 1, jpkm1                                                       ! eulerian transport + Stokes Drift
@@ -146,5 +138,5 @@
       !
       IF( l_trdtra )   THEN                    !* Save ta and sa trends
-         CALL wrk_alloc( jpi, jpj, jpk, ztrdt, ztrds )
+         ALLOCATE( ztrdt(jpi,jpj,jpk), ztrds(jpi,jpj,jpk) )
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem)
          ztrds(:,:,:) = tsa(:,:,:,jp_sal)
@@ -153,15 +145,13 @@
       SELECT CASE ( nadv )                      !==  compute advection trend and add it to general trend  ==!
       !
-      CASE ( np_CEN )                                    ! Centered scheme : 2nd / 4th order
+      CASE ( np_CEN )                                 ! Centered scheme : 2nd / 4th order
          CALL tra_adv_cen    ( kt, nit000, 'TRA',         zun, zvn, zwn     , tsn, tsa, jpts, nn_cen_h, nn_cen_v )
-      CASE ( np_FCT )                                    ! FCT scheme      : 2nd / 4th order
+      CASE ( np_FCT )                                 ! FCT scheme      : 2nd / 4th order
          CALL tra_adv_fct    ( kt, nit000, 'TRA', r2dt, zun, zvn, zwn, tsb, tsn, tsa, jpts, nn_fct_h, nn_fct_v )
-      CASE ( np_FCT_zts )                                ! 2nd order FCT with vertical time-splitting
-         CALL tra_adv_fct_zts( kt, nit000, 'TRA', r2dt, zun, zvn, zwn, tsb, tsn, tsa, jpts        , nn_fct_zts )
-      CASE ( np_MUS )                                    ! MUSCL
+      CASE ( np_MUS )                                 ! MUSCL
          CALL tra_adv_mus    ( kt, nit000, 'TRA', r2dt, zun, zvn, zwn, tsb,      tsa, jpts        , ln_mus_ups ) 
-      CASE ( np_UBS )                                    ! UBS
+      CASE ( np_UBS )                                 ! UBS
          CALL tra_adv_ubs    ( kt, nit000, 'TRA', r2dt, zun, zvn, zwn, tsb, tsn, tsa, jpts        , nn_ubs_v   )
-      CASE ( np_QCK )                                    ! QUICKEST
+      CASE ( np_QCK )                                 ! QUICKEST
          CALL tra_adv_qck    ( kt, nit000, 'TRA', r2dt, zun, zvn, zwn, tsb, tsn, tsa, jpts                     )
       !
@@ -175,5 +165,5 @@
          CALL trd_tra( kt, 'TRA', jp_tem, jptra_totad, ztrdt )
          CALL trd_tra( kt, 'TRA', jp_sal, jptra_totad, ztrds )
-         CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds )
+         DEALLOCATE( ztrdt, ztrds )
       ENDIF
       !                                              ! print mean trends (used for debugging)
@@ -181,8 +171,6 @@
          &                       tab3d_2=tsa(:,:,:,jp_sal), clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
       !
-      IF( nn_timing == 1 )  CALL timing_stop( 'tra_adv' )
-      !
-      CALL wrk_dealloc( jpi,jpj,jpk,   zun, zvn, zwn )
-      !                                          
+      IF( ln_timing )   CALL timing_stop( 'tra_adv' )
+      !
    END SUBROUTINE tra_adv
 
@@ -197,9 +185,10 @@
       INTEGER ::   ioptio, ios   ! Local integers
       !
-      NAMELIST/namtra_adv/ ln_traadv_cen, nn_cen_h, nn_cen_v,               &   ! CEN
-         &                 ln_traadv_fct, nn_fct_h, nn_fct_v, nn_fct_zts,   &   ! FCT
-         &                 ln_traadv_mus,                     ln_mus_ups,   &   ! MUSCL
-         &                 ln_traadv_ubs,           nn_ubs_v,               &   ! UBS
-         &                 ln_traadv_qck                                        ! QCK
+      NAMELIST/namtra_adv/ ln_traadv_NONE,                       &   ! No advection
+         &                 ln_traadv_cen , nn_cen_h, nn_cen_v,   &   ! CEN
+         &                 ln_traadv_fct , nn_fct_h, nn_fct_v,   &   ! FCT
+         &                 ln_traadv_mus , ln_mus_ups,           &   ! MUSCL
+         &                 ln_traadv_ubs ,           nn_ubs_v,   &   ! UBS
+         &                 ln_traadv_qck                             ! QCK
       !!----------------------------------------------------------------------
       !
@@ -217,6 +206,7 @@
          WRITE(numout,*)
          WRITE(numout,*) 'tra_adv_init : choice/control of the tracer advection scheme'
-         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*) '~~~~~~~~~~~~'
          WRITE(numout,*) '   Namelist namtra_adv : chose a advection scheme for tracers'
+         WRITE(numout,*) '      No advection on T & S                     ln_traadv_NONE= ', ln_traadv_NONE
          WRITE(numout,*) '      centered scheme                           ln_traadv_cen = ', ln_traadv_cen
          WRITE(numout,*) '            horizontal 2nd/4th order               nn_cen_h   = ', nn_fct_h
@@ -225,5 +215,4 @@
          WRITE(numout,*) '            horizontal 2nd/4th order               nn_fct_h   = ', nn_fct_h
          WRITE(numout,*) '            vertical   2nd/4th order               nn_fct_v   = ', nn_fct_v
-         WRITE(numout,*) '            2nd order + vertical sub-timestepping  nn_fct_zts = ', nn_fct_zts
          WRITE(numout,*) '      MUSCL scheme                              ln_traadv_mus = ', ln_traadv_mus
          WRITE(numout,*) '            + upstream scheme near river mouths    ln_mus_ups = ', ln_mus_ups
@@ -233,16 +222,14 @@
       ENDIF
       !
-      ioptio = 0                       !==  Parameter control  ==!
-      IF( ln_traadv_cen )   ioptio = ioptio + 1
-      IF( ln_traadv_fct )   ioptio = ioptio + 1
-      IF( ln_traadv_mus )   ioptio = ioptio + 1
-      IF( ln_traadv_ubs )   ioptio = ioptio + 1
-      IF( ln_traadv_qck )   ioptio = ioptio + 1
-      !
-      IF( ioptio == 0 ) THEN
-         nadv = np_NO_adv
-         CALL ctl_warn( 'tra_adv_init: You are running without tracer advection.' )
-      ENDIF
-      IF( ioptio /= 1 )   CALL ctl_stop( 'tra_adv_init: Choose ONE advection scheme in namelist namtra_adv' )
+      !                                !==  Parameter control & set nadv ==!
+      ioptio = 0                       
+      IF( ln_traadv_NONE ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_NO_adv   ;   ENDIF
+      IF( ln_traadv_cen  ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_CEN      ;   ENDIF
+      IF( ln_traadv_fct  ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_FCT      ;   ENDIF
+      IF( ln_traadv_mus  ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_MUS      ;   ENDIF
+      IF( ln_traadv_ubs  ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_UBS      ;   ENDIF
+      IF( ln_traadv_qck  ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_QCK      ;   ENDIF
+      !
+      IF( ioptio /= 1 )   CALL ctl_stop( 'tra_adv_init: Choose ONE advection option in namelist namtra_adv' )
       !
       IF( ln_traadv_cen .AND. ( nn_cen_h /= 2 .AND. nn_cen_h /= 4 )   &          ! Centered
@@ -254,14 +241,4 @@
         CALL ctl_stop( 'tra_adv_init: FCT scheme, choose 2nd or 4th order' )
       ENDIF
-      IF( ln_traadv_fct .AND. nn_fct_zts > 0 ) THEN
-         IF( nn_fct_h == 4 ) THEN
-            nn_fct_h = 2
-            CALL ctl_stop( 'tra_adv_init: force 2nd order FCT scheme, 4th order does not exist with sub-timestepping' )
-         ENDIF
-         IF( .NOT.ln_linssh ) THEN
-            CALL ctl_stop( 'tra_adv_init: vertical sub-timestepping not allow in non-linear free surface' )
-         ENDIF
-         IF( nn_fct_zts == 1 )   CALL ctl_warn( 'tra_adv_init: FCT with ONE sub-timestep = FCT without sub-timestep' )
-      ENDIF
       IF( ln_traadv_ubs .AND. ( nn_ubs_v /= 2 .AND. nn_ubs_v /= 4 )   ) THEN     ! UBS
         CALL ctl_stop( 'tra_adv_init: UBS scheme, choose 2nd or 4th order' )
@@ -275,14 +252,6 @@
       ENDIF
       !
-      !                                !==  used advection scheme  ==!  
-      !                                      ! set nadv
-      IF( ln_traadv_cen                      )   nadv = np_CEN
-      IF( ln_traadv_fct                      )   nadv = np_FCT
-      IF( ln_traadv_fct .AND. nn_fct_zts > 0 )   nadv = np_FCT_zts
-      IF( ln_traadv_mus                      )   nadv = np_MUS
-      IF( ln_traadv_ubs                      )   nadv = np_UBS
-      IF( ln_traadv_qck                      )   nadv = np_QCK
-      !
-      IF(lwp) THEN                           ! Print the choice
+      !                                !==  Print the choice  ==!  
+      IF(lwp) THEN
          WRITE(numout,*)
          SELECT CASE ( nadv )
@@ -292,5 +261,4 @@
          CASE( np_FCT     )   ;   WRITE(numout,*) '      ===>>   FCT      scheme is used. Horizontal order: ', nn_fct_h,   &
             &                                                                      ' Vertical   order: ', nn_fct_v
-         CASE( np_FCT_zts )   ;   WRITE(numout,*) '      ===>>   use 2nd order FCT with ', nn_fct_zts,'vertical sub-timestepping'
          CASE( np_MUS     )   ;   WRITE(numout,*) '      ===>>   MUSCL    scheme is used'
          CASE( np_UBS     )   ;   WRITE(numout,*) '      ===>>   UBS      scheme is used'
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_cen.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_cen.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_cen.F90	(revision 9019)
@@ -11,5 +11,4 @@
    !!                   NB: on the vertical it is actually a 4th order COMPACT scheme which is used
    !!----------------------------------------------------------------------
-   USE oce      , ONLY: tsn ! now ocean temperature and salinity
    USE dom_oce        ! ocean space and time domain
    USE eosbn2         ! equation of state
@@ -24,5 +23,4 @@
    USE trc_oce        ! share passive tracers/Ocean variables
    USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
 
@@ -30,17 +28,17 @@
    PRIVATE
 
-   PUBLIC   tra_adv_cen       ! routine called by step.F90
+   PUBLIC   tra_adv_cen   ! called by traadv.F90
    
    REAL(wp) ::   r1_6 = 1._wp / 6._wp   ! =1/6
 
-   LOGICAL :: l_trd   ! flag to compute trends
-   LOGICAL :: l_ptr   ! flag to compute poleward transport
-   LOGICAL :: l_hst   ! flag to compute heat/salt transport
+   LOGICAL ::   l_trd   ! flag to compute trends
+   LOGICAL ::   l_ptr   ! flag to compute poleward transport
+   LOGICAL ::   l_hst   ! flag to compute heat/salt transport
 
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
-   !! $Id$
+   !! NEMO/OPA 4.0, NEMO Consortium (2017)
+   !! $Id:$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
@@ -48,5 +46,5 @@
 
    SUBROUTINE tra_adv_cen( kt, kit000, cdtype, pun, pvn, pwn,     &
-      &                                             ptn, pta, kjpt, kn_cen_h, kn_cen_v ) 
+      &                                        ptn, pta, kjpt, kn_cen_h, kn_cen_v ) 
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE tra_adv_cen  ***
@@ -80,10 +78,8 @@
       REAL(wp) ::   zC2t_u, zC4t_u   ! local scalars
       REAL(wp) ::   zC2t_v, zC4t_v   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zwx, zwy, zwz, ztu, ztv, ztw
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwx, zwy, zwz, ztu, ztv, ztw
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('tra_adv_cen')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   zwx, zwy, zwz, ztu, ztv, ztw )
+      IF( ln_timing )   CALL timing_start('tra_adv_cen')
       !
       IF( kt == kit000 )  THEN
@@ -92,5 +88,5 @@
          IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~ '
       ENDIF
-      !
+      !                          ! set local switches
       l_trd = .FALSE.
       l_hst = .FALSE.
@@ -130,5 +126,5 @@
                END DO
             END DO
-            CALL lbc_lnk( ztu, 'U', -1. )   ;    CALL lbc_lnk( ztv, 'V', -1. )   ! Lateral boundary cond. (unchanged sgn)
+            CALL lbc_lnk( ztu, 'U', -1. )   ;    CALL lbc_lnk( ztv, 'V', -1. )   ! Lateral boundary cond.
             !
             DO jk = 1, jpkm1                       ! Horizontal advective fluxes
@@ -203,13 +199,11 @@
          END IF
          !                                 ! "Poleward" heat and salt transports 
-         IF( l_ptr )  CALL dia_ptr_hst( jn, 'adv', zwy(:,:,:) )
+         IF( l_ptr )   CALL dia_ptr_hst( jn, 'adv', zwy(:,:,:) )
          !                                 !  heat and salt transport
-         IF( l_hst )  CALL dia_ar5_hst( jn, 'adv', zwx(:,:,:), zwy(:,:,:) )
+         IF( l_hst )   CALL dia_ar5_hst( jn, 'adv', zwx(:,:,:), zwy(:,:,:) )
          !
       END DO
       !
-      CALL wrk_dealloc( jpi,jpj,jpk,   zwx, zwy, zwz, ztu, ztv, ztw )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_adv_cen')
+      IF( ln_timing )   CALL timing_stop('tra_adv_cen')
       !
    END SUBROUTINE tra_adv_cen
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_fct.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_fct.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_fct.F90	(revision 9019)
@@ -9,5 +9,4 @@
    !!----------------------------------------------------------------------
    !!  tra_adv_fct    : update the tracer trend with a 3D advective trends using a 2nd or 4th order FCT scheme
-   !!  tra_adv_fct_zts: update the tracer trend with a 3D advective trends using a 2nd order FCT scheme 
    !!                   with sub-time-stepping in the vertical direction
    !!  nonosc         : compute monotonic tracer fluxes by a non-oscillatory algorithm 
@@ -21,12 +20,11 @@
    USE diaptr         ! poleward transport diagnostics
    USE diaar5         ! AR5 diagnostics
-   USE phycst, ONLY: rau0_rcp
+   USE phycst  , ONLY : rau0_rcp
    !
    USE in_out_manager ! I/O manager
-   USE iom
+   USE iom            ! 
    USE lib_mpp        ! MPP library
    USE lbclnk         ! ocean lateral boundary condition (or mpp link) 
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
 
@@ -34,7 +32,6 @@
    PRIVATE
 
-   PUBLIC   tra_adv_fct        ! routine called by traadv.F90
-   PUBLIC   tra_adv_fct_zts    ! routine called by traadv.F90
-   PUBLIC   interp_4th_cpt     ! routine called by traadv_cen.F90
+   PUBLIC   tra_adv_fct        ! called by traadv.F90
+   PUBLIC   interp_4th_cpt     ! called by traadv_cen.F90
 
    LOGICAL  ::   l_trd   ! flag to compute trends
@@ -50,5 +47,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -70,5 +67,5 @@
       !!
       !! ** Action : - update pta  with the now advective tracer trends
-      !!             - send trends to trdtra module for further diagnostcs (l_trdtra=T)
+      !!             - send trends to trdtra module for further diagnostics (l_trdtra=T)
       !!             - htr_adv, str_adv : poleward advective heat and salt transport (ln_diaptr=T)
       !!----------------------------------------------------------------------
@@ -88,12 +85,9 @@
       REAL(wp) ::   zfp_ui, zfp_vj, zfp_wk, zC2t_u, zC4t_u   !   -      -
       REAL(wp) ::   zfm_ui, zfm_vj, zfm_wk, zC2t_v, zC4t_v   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zwi, zwx, zwy, zwz, ztu, ztv, zltu, zltv, ztw
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrdx, ztrdy, ztrdz, zptry
-      REAL(wp), POINTER, DIMENSION(:,:)   :: z2d
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_adv_fct')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   zwi, zwx, zwy, zwz, ztu, ztv, zltu, zltv, ztw )
+      REAL(wp), DIMENSION(jpi,jpj,jpk)        ::   zwi, zwx, zwy, zwz, ztu, ztv, zltu, zltv, ztw
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ztrdx, ztrdy, ztrdz, zptry
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('tra_adv_fct')
       !
       IF( kt == kit000 )  THEN
@@ -103,19 +97,19 @@
       ENDIF
       !
-      l_trd = .FALSE.
+      l_trd = .FALSE.            ! set local switches
       l_hst = .FALSE.
       l_ptr = .FALSE.
-      IF( ( cdtype == 'TRA'   .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) )     l_trd = .TRUE.
-      IF(   cdtype == 'TRA'   .AND. ln_diaptr )                                              l_ptr = .TRUE. 
-      IF(   cdtype == 'TRA' .AND. ( iom_use("uadv_heattr") .OR. iom_use("vadv_heattr") .OR. &
-         &                          iom_use("uadv_salttr") .OR. iom_use("vadv_salttr")  ) )  l_hst = .TRUE.
+      IF( ( cdtype =='TRA' .AND. l_trdtra  ) .OR. ( cdtype =='TRC' .AND. l_trdtrc ) )       l_trd = .TRUE.
+      IF(   cdtype =='TRA' .AND. ln_diaptr )                                                l_ptr = .TRUE. 
+      IF(   cdtype =='TRA' .AND. ( iom_use("uadv_heattr") .OR. iom_use("vadv_heattr") .OR.  &
+         &                         iom_use("uadv_salttr") .OR. iom_use("vadv_salttr")  ) )  l_hst = .TRUE.
       !
       IF( l_trd .OR. l_hst )  THEN
-         CALL wrk_alloc( jpi, jpj, jpk, ztrdx, ztrdy, ztrdz )
+         ALLOCATE( ztrdx(jpi,jpj,jpk), ztrdy(jpi,jpj,jpk), ztrdz(jpi,jpj,jpk) )
          ztrdx(:,:,:) = 0._wp   ;    ztrdy(:,:,:) = 0._wp   ;   ztrdz(:,:,:) = 0._wp
       ENDIF
       !
       IF( l_ptr ) THEN  
-         CALL wrk_alloc( jpi, jpj, jpk, zptry )
+         ALLOCATE( zptry(jpi,jpj,jpk) )
          zptry(:,:,:) = 0._wp
       ENDIF
@@ -184,5 +178,5 @@
          END IF
          !                             ! "Poleward" heat and salt transports (contribution of upstream fluxes)
-         IF( l_ptr )  zptry(:,:,:) = zwy(:,:,:) 
+         IF( l_ptr )   zptry(:,:,:) = zwy(:,:,:) 
          !
          !        !==  anti-diffusive flux : high order minus low order  ==!
@@ -308,326 +302,30 @@
          END DO
          !
-         IF( l_trd .OR. l_hst ) THEN     ! trend diagnostics (contribution of upstream fluxes)
-            ztrdx(:,:,:) = ztrdx(:,:,:) + zwx(:,:,:)  ! <<< Add to previously computed
-            ztrdy(:,:,:) = ztrdy(:,:,:) + zwy(:,:,:)  ! <<< Add to previously computed
-            ztrdz(:,:,:) = ztrdz(:,:,:) + zwz(:,:,:)  ! <<< Add to previously computed
+         IF( l_trd .OR. l_hst ) THEN   ! trend diagnostics // heat/salt transport
+            ztrdx(:,:,:) = ztrdx(:,:,:) + zwx(:,:,:)  ! <<< add anti-diffusive fluxes 
+            ztrdy(:,:,:) = ztrdy(:,:,:) + zwy(:,:,:)  !     to upstream fluxes
+            ztrdz(:,:,:) = ztrdz(:,:,:) + zwz(:,:,:)  !
+            !
+            IF( l_trd ) THEN              ! trend diagnostics
+               CALL trd_tra( kt, cdtype, jn, jptra_xad, ztrdx, pun, ptn(:,:,:,jn) )
+               CALL trd_tra( kt, cdtype, jn, jptra_yad, ztrdy, pvn, ptn(:,:,:,jn) )
+               CALL trd_tra( kt, cdtype, jn, jptra_zad, ztrdz, pwn, ptn(:,:,:,jn) )
+            ENDIF
+            !                             ! heat/salt transport
+            IF( l_hst )   CALL dia_ar5_hst( jn, 'adv', ztrdx(:,:,:), ztrdy(:,:,:) )
+            !
+            DEALLOCATE( ztrdx, ztrdy, ztrdz )
          ENDIF
-            !
-         IF( l_trd ) THEN 
-            CALL trd_tra( kt, cdtype, jn, jptra_xad, ztrdx, pun, ptn(:,:,:,jn) )
-            CALL trd_tra( kt, cdtype, jn, jptra_yad, ztrdy, pvn, ptn(:,:,:,jn) )
-            CALL trd_tra( kt, cdtype, jn, jptra_zad, ztrdz, pwn, ptn(:,:,:,jn) )
-            !
-         END IF
-         !                                !  heat/salt transport
-         IF( l_hst )  CALL dia_ar5_hst( jn, 'adv', ztrdx(:,:,:), ztrdy(:,:,:) )
-
-         !                                ! "Poleward" heat and salt transports (contribution of upstream fluxes)
-         IF( l_ptr ) THEN  
-            zptry(:,:,:) = zptry(:,:,:) + zwy(:,:,:)  ! <<< Add to previously computed
+         IF( l_ptr ) THEN              ! "Poleward" transports
+            zptry(:,:,:) = zptry(:,:,:) + zwy(:,:,:)  ! <<< add anti-diffusive fluxes
             CALL dia_ptr_hst( jn, 'adv', zptry(:,:,:) )
+            DEALLOCATE( zptry )
          ENDIF
          !
       END DO                     ! end of tracer loop
       !
-                              CALL wrk_dealloc( jpi,jpj,jpk,    zwi, zwx, zwy, zwz, ztu, ztv, zltu, zltv, ztw )
-      IF( l_trd .OR. l_hst )  CALL wrk_dealloc( jpi, jpj, jpk, ztrdx, ztrdy, ztrdz )
-      IF( l_ptr )             CALL wrk_dealloc( jpi, jpj, jpk, zptry )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_adv_fct')
+      IF( ln_timing )   CALL timing_stop('tra_adv_fct')
       !
    END SUBROUTINE tra_adv_fct
-
-
-   SUBROUTINE tra_adv_fct_zts( kt, kit000, cdtype, p2dt, pun, pvn, pwn,      &
-      &                                                  ptb, ptn, pta, kjpt, kn_fct_zts )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE tra_adv_fct_zts  ***
-      !! 
-      !! **  Purpose :   Compute the now trend due to total advection of 
-      !!       tracers and add it to the general trend of tracer equations
-      !!
-      !! **  Method  :   TVD ZTS scheme, i.e. 2nd order centered scheme with
-      !!       corrected flux (monotonic correction). This version use sub-
-      !!       timestepping for the vertical advection which increases stability
-      !!       when vertical metrics are small.
-      !!       note: - this advection scheme needs a leap-frog time scheme
-      !!
-      !! ** Action : - update (pta) with the now advective tracer trends
-      !!             - save the trends 
-      !!----------------------------------------------------------------------
-      INTEGER                              , INTENT(in   ) ::   kt              ! ocean time-step index
-      INTEGER                              , INTENT(in   ) ::   kit000          ! first time step index
-      CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype          ! =TRA or TRC (tracer indicator)
-      INTEGER                              , INTENT(in   ) ::   kjpt            ! number of tracers
-      INTEGER                              , INTENT(in   ) ::   kn_fct_zts      ! number of number of vertical sub-timesteps
-      REAL(wp)                             , INTENT(in   ) ::   p2dt            ! tracer time-step
-      REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ) ::   pun, pvn, pwn   ! 3 ocean velocity components
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb, ptn        ! before and now tracer fields
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta             ! tracer trend 
-      !
-      REAL(wp), DIMENSION( jpk )                           ::   zts             ! length of sub-timestep for vertical advection
-      REAL(wp)                                             ::   zr_p2dt         ! reciprocal of tracer timestep
-      INTEGER  ::   ji, jj, jk, jl, jn       ! dummy loop indices  
-      INTEGER  ::   jtb, jtn, jta   ! sub timestep pointers for leap-frog/euler forward steps
-      INTEGER  ::   jtaken          ! toggle for collecting appropriate fluxes from sub timesteps
-      REAL(wp) ::   z_rzts          ! Fractional length of Euler forward sub-timestep for vertical advection
-      REAL(wp) ::   ztra            ! local scalar
-      REAL(wp) ::   zfp_ui, zfp_vj, zfp_wk   !   -      -
-      REAL(wp) ::   zfm_ui, zfm_vj, zfm_wk   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:  )   ::   zwx_sav , zwy_sav
-      REAL(wp), POINTER, DIMENSION(:,:,:)   ::   zwi, zwx, zwy, zwz, zhdiv, zwzts, zwz_sav
-      REAL(wp), POINTER, DIMENSION(:,:,:)   ::   ztrdx, ztrdy, ztrdz
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zptry
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   ztrs
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_adv_fct_zts')
-      !
-      CALL wrk_alloc( jpi,jpj,             zwx_sav, zwy_sav )
-      CALL wrk_alloc( jpi,jpj,jpk,         zwx, zwy, zwz, zwi, zhdiv, zwzts, zwz_sav )
-      CALL wrk_alloc( jpi,jpj,jpk,kjpt+1,  ztrs )
-      !
-      IF( kt == kit000 )  THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'tra_adv_fct_zts : 2nd order FCT scheme with ', kn_fct_zts, ' vertical sub-timestep on ', cdtype
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
-      ENDIF
-      !
-      l_trd = .FALSE.
-      l_hst = .FALSE.
-      l_ptr = .FALSE.
-      IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) )      l_trd = .TRUE.
-      IF(   cdtype == 'TRA' .AND. ln_diaptr )                                               l_ptr = .TRUE. 
-      IF(   cdtype == 'TRA' .AND. ( iom_use("uadv_heattr") .OR. iom_use("vadv_heattr") .OR. &
-         &                          iom_use("uadv_salttr") .OR. iom_use("vadv_salttr")  ) ) l_hst = .TRUE.
-      !
-      IF( l_trd .OR. l_hst )  THEN
-         CALL wrk_alloc( jpi,jpj,jpk,   ztrdx, ztrdy, ztrdz )
-         ztrdx(:,:,:) = 0._wp  ;    ztrdy(:,:,:) = 0._wp  ;   ztrdz(:,:,:) = 0._wp
-      ENDIF
-      !
-      IF( l_ptr ) THEN  
-         CALL wrk_alloc( jpi, jpj,jpk, zptry )
-         zptry(:,:,:) = 0._wp
-      ENDIF
-      zwi(:,:,:) = 0._wp
-      z_rzts = 1._wp / REAL( kn_fct_zts, wp )
-      zr_p2dt = 1._wp / p2dt
-      !
-      ! surface & Bottom value : flux set to zero for all tracers
-      zwz(:,:, 1 ) = 0._wp
-      zwx(:,:,jpk) = 0._wp   ;    zwz(:,:,jpk) = 0._wp
-      zwy(:,:,jpk) = 0._wp   ;    zwi(:,:,jpk) = 0._wp
-      !
-      !                                                          ! ===========
-      DO jn = 1, kjpt                                            ! tracer loop
-         !                                                       ! ===========
-         !
-         ! Upstream advection with initial mass fluxes & intermediate update
-         DO jk = 1, jpkm1        ! upstream tracer flux in the i and j direction
-            DO jj = 1, jpjm1
-               DO ji = 1, fs_jpim1   ! vector opt.
-                  ! upstream scheme
-                  zfp_ui = pun(ji,jj,jk) + ABS( pun(ji,jj,jk) )
-                  zfm_ui = pun(ji,jj,jk) - ABS( pun(ji,jj,jk) )
-                  zfp_vj = pvn(ji,jj,jk) + ABS( pvn(ji,jj,jk) )
-                  zfm_vj = pvn(ji,jj,jk) - ABS( pvn(ji,jj,jk) )
-                  zwx(ji,jj,jk) = 0.5_wp * ( zfp_ui * ptb(ji,jj,jk,jn) + zfm_ui * ptb(ji+1,jj  ,jk,jn) )
-                  zwy(ji,jj,jk) = 0.5_wp * ( zfp_vj * ptb(ji,jj,jk,jn) + zfm_vj * ptb(ji  ,jj+1,jk,jn) )
-               END DO
-            END DO
-         END DO
-         !                       ! upstream tracer flux in the k direction
-         DO jk = 2, jpkm1              ! Interior value
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zfp_wk = pwn(ji,jj,jk) + ABS( pwn(ji,jj,jk) )
-                  zfm_wk = pwn(ji,jj,jk) - ABS( pwn(ji,jj,jk) )
-                  zwz(ji,jj,jk) = 0.5_wp * ( zfp_wk * ptb(ji,jj,jk,jn) + zfm_wk * ptb(ji,jj,jk-1,jn) ) * wmask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-         IF( ln_linssh ) THEN          ! top value : linear free surface case only (as zwz is multiplied by wmask)
-            IF( ln_isfcav ) THEN             ! ice-shelf cavities: top value
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     zwz(ji,jj, mikt(ji,jj) ) = pwn(ji,jj,mikt(ji,jj)) * ptb(ji,jj,mikt(ji,jj),jn) 
-                  END DO
-               END DO   
-            ELSE                             ! no cavities, surface value
-               zwz(:,:,1) = pwn(:,:,1) * ptb(:,:,1,jn)
-            ENDIF
-         ENDIF
-         !
-         DO jk = 1, jpkm1         ! total advective trend
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  !                             ! total intermediate advective trends
-                  ztra = - (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )   &
-                     &      + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )   &
-                     &      + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1)   ) * r1_e1e2t(ji,jj)
-                  !                             ! update and guess with monotonic sheme
-                  pta(ji,jj,jk,jn) =                     pta(ji,jj,jk,jn) +        ztra   / e3t_n(ji,jj,jk) * tmask(ji,jj,jk)
-                  zwi(ji,jj,jk)    = ( e3t_b(ji,jj,jk) * ptb(ji,jj,jk,jn) + p2dt * ztra ) / e3t_a(ji,jj,jk) * tmask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-         !                           
-         CALL lbc_lnk( zwi, 'T', 1. )     ! Lateral boundary conditions on zwi  (unchanged sign)
-         !                
-         IF( l_trd .OR. l_hst )  THEN                ! trend diagnostics (contribution of upstream fluxes)
-            ztrdx(:,:,:) = zwx(:,:,:)   ;    ztrdy(:,:,:) = zwy(:,:,:)  ;   ztrdz(:,:,:) = zwz(:,:,:)
-         END IF
-         !                                ! "Poleward" heat and salt transports (contribution of upstream fluxes)
-         IF( l_ptr )  zptry(:,:,:) = zwy(:,:,:)
-
-         ! 3. anti-diffusive flux : high order minus low order
-         ! ---------------------------------------------------
-
-         DO jk = 1, jpkm1                    !* horizontal anti-diffusive fluxes
-            !
-            DO jj = 1, jpjm1
-               DO ji = 1, fs_jpim1   ! vector opt.
-                  zwx_sav(ji,jj) = zwx(ji,jj,jk)
-                  zwy_sav(ji,jj) = zwy(ji,jj,jk)
-                  !
-                  zwx(ji,jj,jk) = 0.5_wp * pun(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji+1,jj,jk,jn) )
-                  zwy(ji,jj,jk) = 0.5_wp * pvn(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji,jj+1,jk,jn) )
-               END DO
-            END DO
-            !
-            DO jj = 2, jpjm1                    ! partial horizontal divergence
-               DO ji = fs_2, fs_jpim1
-                  zhdiv(ji,jj,jk) = (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk)   &
-                     &               + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk)  )
-               END DO
-            END DO
-            !
-            DO jj = 1, jpjm1
-               DO ji = 1, fs_jpim1   ! vector opt.
-                  zwx(ji,jj,jk) = zwx(ji,jj,jk) - zwx_sav(ji,jj)
-                  zwy(ji,jj,jk) = zwy(ji,jj,jk) - zwy_sav(ji,jj)
-               END DO
-            END DO
-         END DO
-         !
-         !                                !* vertical anti-diffusive flux
-         zwz_sav(:,:,:)   = zwz(:,:,:)
-         ztrs   (:,:,:,1) = ptb(:,:,:,jn)
-         ztrs   (:,:,1,2) = ptb(:,:,1,jn)
-         ztrs   (:,:,1,3) = ptb(:,:,1,jn)
-         zwzts  (:,:,:)   = 0._wp
-         !
-         DO jl = 1, kn_fct_zts                  ! Start of sub timestepping loop
-            !
-            IF( jl == 1 ) THEN                        ! Euler forward to kick things off
-               jtb = 1   ;   jtn = 1   ;   jta = 2
-               zts(:) = p2dt * z_rzts
-               jtaken = MOD( kn_fct_zts + 1 , 2)            ! Toggle to collect every second flux
-               !                                            ! starting at jl =1 if kn_fct_zts is odd; 
-               !                                            ! starting at jl =2 otherwise
-            ELSEIF( jl == 2 ) THEN                    ! First leapfrog step
-               jtb = 1   ;   jtn = 2   ;   jta = 3
-               zts(:) = 2._wp * p2dt * z_rzts
-            ELSE                                      ! Shuffle pointers for subsequent leapfrog steps
-               jtb = MOD(jtb,3) + 1
-               jtn = MOD(jtn,3) + 1
-               jta = MOD(jta,3) + 1
-            ENDIF
-            DO jk = 2, jpkm1                          ! interior value
-               DO jj = 2, jpjm1
-                  DO ji = fs_2, fs_jpim1
-                     zwz(ji,jj,jk) = 0.5_wp * pwn(ji,jj,jk) * ( ztrs(ji,jj,jk,jtn) + ztrs(ji,jj,jk-1,jtn) ) * wmask(ji,jj,jk)
-                     IF( jtaken == 0 )   zwzts(ji,jj,jk) = zwzts(ji,jj,jk) + zwz(ji,jj,jk) * zts(jk)    ! Accumulate time-weighted vertcal flux
-                  END DO
-               END DO
-            END DO
-            IF( ln_linssh ) THEN                    ! top value (only in linear free surface case)
-               IF( ln_isfcav ) THEN                      ! ice-shelf cavities
-                  DO jj = 1, jpj
-                     DO ji = 1, jpi
-                        zwz(ji,jj, mikt(ji,jj) ) = pwn(ji,jj,mikt(ji,jj)) * ptb(ji,jj,mikt(ji,jj),jn)   ! linear free surface 
-                     END DO
-                  END DO   
-               ELSE                                      ! no ocean cavities
-                  zwz(:,:,1) = pwn(:,:,1) * ptb(:,:,1,jn)
-               ENDIF
-            ENDIF
-            !
-            jtaken = MOD( jtaken + 1 , 2 )
-            !
-            DO jk = 2, jpkm1                             ! total advective trends
-               DO jj = 2, jpjm1
-                  DO ji = fs_2, fs_jpim1
-                     ztrs(ji,jj,jk,jta) = ztrs(ji,jj,jk,jtb)                                                 &
-                        &               - zts(jk) * (  zhdiv(ji,jj,jk) + zwz(ji,jj,jk) - zwz(ji,jj,jk+1) )   &
-                        &                         * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
-                  END DO
-               END DO
-            END DO
-            !
-         END DO
-
-         DO jk = 2, jpkm1          ! Anti-diffusive vertical flux using average flux from the sub-timestepping
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1
-                  zwz(ji,jj,jk) = ( zwzts(ji,jj,jk) * zr_p2dt - zwz_sav(ji,jj,jk) ) * wmask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-         CALL lbc_lnk( zwx, 'U', -1. )   ;   CALL lbc_lnk( zwy, 'V', -1. )         ! Lateral bondary conditions
-         CALL lbc_lnk( zwz, 'W',  1. )
-
-         ! 4. monotonicity algorithm
-         ! -------------------------
-         CALL nonosc( ptb(:,:,:,jn), zwx, zwy, zwz, zwi, p2dt )
-
-
-         ! 5. final trend with corrected fluxes
-         ! ------------------------------------
-         DO jk = 1, jpkm1
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.  
-                  pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + (   zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )       &
-                     &                                    + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1)   )   &
-                     &                                * r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-
-        !
-         IF( l_trd .OR. l_hst ) THEN     ! trend diagnostics (contribution of upstream fluxes)
-            ztrdx(:,:,:) = ztrdx(:,:,:) + zwx(:,:,:)  ! <<< Add to previously computed
-            ztrdy(:,:,:) = ztrdy(:,:,:) + zwy(:,:,:)  ! <<< Add to previously computed
-            ztrdz(:,:,:) = ztrdz(:,:,:) + zwz(:,:,:)  ! <<< Add to previously computed
-         ENDIF
-            !
-         IF( l_trd ) THEN 
-            CALL trd_tra( kt, cdtype, jn, jptra_xad, ztrdx, pun, ptn(:,:,:,jn) )
-            CALL trd_tra( kt, cdtype, jn, jptra_yad, ztrdy, pvn, ptn(:,:,:,jn) )
-            CALL trd_tra( kt, cdtype, jn, jptra_zad, ztrdz, pwn, ptn(:,:,:,jn) )
-            !
-         END IF
-         !                                             ! heat/salt transport
-         IF( l_hst )  CALL dia_ar5_hst( jn, 'adv', ztrdx(:,:,:), ztrdy(:,:,:) )
-
-         !                                            ! "Poleward" heat and salt transports (contribution of upstream fluxes)
-         IF( l_ptr ) THEN  
-            zptry(:,:,:) = zptry(:,:,:) + zwy(:,:,:)  ! <<< Add to previously computed
-            CALL dia_ptr_hst( jn, 'adv', zptry(:,:,:) )
-         ENDIF
-         !
-      END DO
-      !
-                              CALL wrk_alloc( jpi,jpj,             zwx_sav, zwy_sav )
-                              CALL wrk_alloc( jpi,jpj, jpk,        zwx, zwy, zwz, zwi, zhdiv, zwzts, zwz_sav )
-                              CALL wrk_alloc( jpi,jpj,jpk,kjpt+1,  ztrs )
-      IF( l_trd .OR. l_hst )  CALL wrk_dealloc( jpi, jpj, jpk, ztrdx, ztrdy, ztrdz )
-      IF( l_ptr )             CALL wrk_dealloc( jpi, jpj, jpk, zptry )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_adv_fct_zts')
-      !
-   END SUBROUTINE tra_adv_fct_zts
 
 
@@ -653,10 +351,8 @@
       REAL(wp) ::   zpos, zneg, zbt, za, zb, zc, zbig, zrtrn    ! local scalars
       REAL(wp) ::   zau, zbu, zcu, zav, zbv, zcv, zup, zdo            !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zbetup, zbetdo, zbup, zbdo
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('nonosc')
-      !
-      CALL wrk_alloc( jpi, jpj, jpk, zbetup, zbetdo, zbup, zbdo )
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zbetup, zbetdo, zbup, zbdo
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('nonosc')
       !
       zbig  = 1.e+40_wp
@@ -734,7 +430,5 @@
       CALL lbc_lnk( paa, 'U', -1. )   ;   CALL lbc_lnk( pbb, 'V', -1. )   ! lateral boundary condition (changed sign)
       !
-      CALL wrk_dealloc( jpi, jpj, jpk, zbetup, zbetdo, zbup, zbdo )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('nonosc')
+      IF( ln_timing )   CALL timing_stop('nonosc')
       !
    END SUBROUTINE nonosc
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_mle.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_mle.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_mle.F90	(revision 9019)
@@ -15,9 +15,9 @@
    USE phycst         ! physical constant
    USE zdfmxl         ! mixed layer depth
+   !
    USE lbclnk         ! lateral boundary condition / mpp link
    USE in_out_manager ! I/O manager
    USE iom            ! IOM library
    USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
    USE timing         ! Timing
 
@@ -86,22 +86,14 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pw         !   increased by the MLE induced transport
       !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      INTEGER  ::   ikmax        ! temporary integer
-      REAL(wp) ::   zcuw, zmuw   ! local scalar
-      REAL(wp) ::   zcvw, zmvw   !   -      -
-      REAL(wp) ::   zc                                     !   -      -
-      !
-      INTEGER  ::   ii, ij, ik              ! local integers
-      INTEGER, DIMENSION(3) ::   ilocu      !
-      INTEGER, DIMENSION(2) ::   ilocs      !
-      REAL(wp), POINTER, DIMENSION(:,:  ) :: zpsim_u, zpsim_v, zmld, zbm, zhu, zhv, zn2, zLf_NH, zLf_MH
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zpsi_uw, zpsi_vw
-      INTEGER, POINTER, DIMENSION(:,:) :: inml_mle
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_adv_mle')
-      CALL wrk_alloc( jpi, jpj, zpsim_u, zpsim_v, zmld, zbm, zhu, zhv, zn2, zLf_NH, zLf_MH)
-      CALL wrk_alloc( jpi, jpj, jpk, zpsi_uw, zpsi_vw)
-      CALL wrk_alloc( jpi, jpj, inml_mle)
+      INTEGER  ::   ji, jj, jk          ! dummy loop indices
+      INTEGER  ::   ii, ij, ik, ikmax   ! local integers
+      REAL(wp) ::   zcuw, zmuw, zc      ! local scalar
+      REAL(wp) ::   zcvw, zmvw          !   -      -
+      INTEGER , DIMENSION(jpi,jpj)     :: inml_mle
+      REAL(wp), DIMENSION(jpi,jpj)     :: zpsim_u, zpsim_v, zmld, zbm, zhu, zhv, zn2, zLf_NH, zLf_MH
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zpsi_uw, zpsi_vw
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('tra_adv_mle')
       !
       !                                      !==  MLD used for MLE  ==!
@@ -256,9 +248,6 @@
          CALL iom_put( "psiv_mle", zpsi_vw )    ! j-mle streamfunction
       ENDIF
-      CALL wrk_dealloc( jpi, jpj, zpsim_u, zpsim_v, zmld, zbm, zhu, zhv, zn2, zLf_NH, zLf_MH)
-      CALL wrk_dealloc( jpi, jpj, jpk, zpsi_uw, zpsi_vw)
-      CALL wrk_dealloc( jpi, jpj, inml_mle)
-
-      IF( nn_timing == 1 )  CALL timing_stop('tra_adv_mle')
+      !
+      IF( ln_timing )   CALL timing_stop('tra_adv_mle')
       !
    END SUBROUTINE tra_adv_mle
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_mus.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_mus.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_mus.F90	(revision 9019)
@@ -26,6 +26,5 @@
 
    !
-   USE iom
-   USE wrk_nemo       ! Memory Allocation
+   USE iom            ! XIOS library
    USE timing         ! Timing
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
@@ -85,16 +84,13 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta             ! tracer trend 
       !
-      INTEGER  ::   ji, jj, jk, jn       ! dummy loop indices
-      INTEGER  ::   ierr                 ! local integer
-      REAL(wp) ::   zu, z0u, zzwx, zw    ! local scalars
-      REAL(wp) ::   zv, z0v, zzwy, z0w   !   -      -
-      REAL(wp) ::   zalpha               !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zslpx, zslpy   ! 3D workspace
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zwx  , zwy     ! -      - 
+      INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
+      INTEGER  ::   ierr             ! local integer
+      REAL(wp) ::   zu, z0u, zzwx, zw , zalpha   ! local scalars
+      REAL(wp) ::   zv, z0v, zzwy, z0w           !   -      -
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwx, zslpx   ! 3D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwy, zslpy   ! -      - 
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('tra_adv_mus')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   zslpx, zslpy, zwx, zwy )
+      IF( ln_timing )   CALL timing_start('tra_adv_mus')
       !
       IF( kt == kit000 )  THEN
@@ -279,7 +275,5 @@
       END DO                     ! end of tracer loop
       !
-      CALL wrk_dealloc( jpi,jpj,jpk,   zslpx, zslpy, zwx, zwy )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_adv_mus')
+      IF( ln_timing )   CALL timing_stop('tra_adv_mus')
       !
    END SUBROUTINE tra_adv_mus
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_qck.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_qck.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_qck.F90	(revision 9019)
@@ -25,5 +25,4 @@
    USE lbclnk          ! ocean lateral boundary condition (or mpp link)
    USE in_out_manager  ! I/O manager
-   USE wrk_nemo        ! Memory Allocation
    USE timing          ! Timing
    USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
@@ -43,5 +42,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -96,5 +95,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('tra_adv_qck')
+      IF( ln_timing )   CALL timing_start('tra_adv_qck')
       !
       IF( kt == kit000 )  THEN
@@ -118,5 +117,5 @@
       CALL tra_adv_cen2_k( kt, cdtype, pwn,         ptn, pta, kjpt )
       !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_adv_qck')
+      IF( ln_timing )   CALL timing_stop('tra_adv_qck')
       !
    END SUBROUTINE tra_adv_qck
@@ -138,8 +137,7 @@
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
       REAL(wp) ::   ztra, zbtr, zdir, zdx, zmsk   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zwx, zfu, zfc, zfd
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwx, zfu, zfc, zfd
       !----------------------------------------------------------------------
       !
-      CALL wrk_alloc( jpi, jpj, jpk, zwx, zfu, zfc, zfd )
       !                                                          ! ===========
       DO jn = 1, kjpt                                            ! tracer loop
@@ -230,9 +228,7 @@
          END DO
          !                                 ! trend diagnostics
-         IF( l_trd )                     CALL trd_tra( kt, cdtype, jn, jptra_xad, zwx, pun, ptn(:,:,:,jn) )
+         IF( l_trd )   CALL trd_tra( kt, cdtype, jn, jptra_xad, zwx, pun, ptn(:,:,:,jn) )
          !
       END DO
-      !
-      CALL wrk_dealloc( jpi, jpj, jpk, zwx, zfu, zfc, zfd )
       !
    END SUBROUTINE tra_adv_qck_i
@@ -252,10 +248,8 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta        ! tracer trend 
       !!
-      INTEGER  :: ji, jj, jk, jn   ! dummy loop indices
+      INTEGER  :: ji, jj, jk, jn                ! dummy loop indices
       REAL(wp) :: ztra, zbtr, zdir, zdx, zmsk   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zwy, zfu, zfc, zfd
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwy, zfu, zfc, zfd   ! 3D workspace
       !----------------------------------------------------------------------
-      !
-      CALL wrk_alloc( jpi, jpj, jpk, zwy, zfu, zfc, zfd )
       !
       !                                                          ! ===========
@@ -320,6 +314,5 @@
             END DO
          END DO
-         !--- Lateral boundary conditions 
-         CALL lbc_lnk( zfu(:,:,:), 'T', 1. ) 
+         CALL lbc_lnk( zfu(:,:,:), 'T', 1. )    !--- Lateral boundary conditions 
          !
          ! Tracer flux on the x-direction
@@ -353,11 +346,9 @@
          END DO
          !                                 ! trend diagnostics
-         IF( l_trd )                     CALL trd_tra( kt, cdtype, jn, jptra_yad, zwy, pvn, ptn(:,:,:,jn) )
+         IF( l_trd )   CALL trd_tra( kt, cdtype, jn, jptra_yad, zwy, pvn, ptn(:,:,:,jn) )
          !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
-         IF( l_ptr )                     CALL dia_ptr_hst( jn, 'adv', zwy(:,:,:) )
+         IF( l_ptr )   CALL dia_ptr_hst( jn, 'adv', zwy(:,:,:) )
          !
       END DO
-      !
-      CALL wrk_dealloc( jpi, jpj, jpk, zwy, zfu, zfc, zfd )
       !
    END SUBROUTINE tra_adv_qck_j
@@ -377,8 +368,6 @@
       !
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zwz
-      !!----------------------------------------------------------------------
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   zwz )
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwz   ! 3D workspace
+      !!----------------------------------------------------------------------
       !
       zwz(:,:, 1 ) = 0._wp       ! surface & bottom values set to zero for all tracers
@@ -421,6 +410,4 @@
       END DO
       !
-      CALL wrk_dealloc( jpi,jpj,jpk,   zwz )
-      !
    END SUBROUTINE tra_adv_cen2_k
 
@@ -443,5 +430,5 @@
       !----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('quickest')
+      IF( ln_timing )   CALL timing_start('quickest')
       !
       DO jk = 1, jpkm1
@@ -475,5 +462,5 @@
       END DO
       !
-      IF( nn_timing == 1 )  CALL timing_stop('quickest')
+      IF( ln_timing )   CALL timing_stop('quickest')
       !
    END SUBROUTINE quickest
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_ubs.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_ubs.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_ubs.F90	(revision 9019)
@@ -20,11 +20,9 @@
    USE diaptr         ! poleward transport diagnostics
    USE diaar5         ! AR5 diagnostics
-
    !
-   USE iom
-   USE lib_mpp        ! I/O library
+   USE iom            ! I/O library
+   USE lib_mpp        ! massively parallel library
    USE lbclnk         ! ocean lateral boundary condition (or mpp link)
    USE in_out_manager ! I/O manager
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
@@ -101,10 +99,8 @@
       REAL(wp) ::   zfp_ui, zfm_ui, zcenut, ztak, zfp_wk, zfm_wk   !   -      -
       REAL(wp) ::   zfp_vj, zfm_vj, zcenvt, zeeu, zeev, z_hdivn    !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: ztu, ztv, zltu, zltv, zti, ztw
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_adv_ubs')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   ztu, ztv, zltu, zltv, zti, ztw )
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztu, ztv, zltu, zltv, zti, ztw   ! 3D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('tra_adv_ubs')
       !
       IF( kt == kit000 )  THEN
@@ -285,7 +281,5 @@
       END DO
       !
-      CALL wrk_dealloc( jpi,jpj,jpk,   ztu, ztv, zltu, zltv, zti, ztw )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_adv_ubs')
+      IF( ln_timing )   CALL timing_stop('tra_adv_ubs')
       !
    END SUBROUTINE tra_adv_ubs
@@ -313,10 +307,8 @@
       INTEGER  ::   ikm1         ! local integer
       REAL(wp) ::   zpos, zneg, zbt, za, zb, zc, zbig, zrtrn   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zbetup, zbetdo
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('nonosc_z')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   zbetup, zbetdo )
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zbetup, zbetdo     ! 3D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('nonosc_z')
       !
       zbig  = 1.e+40_wp
@@ -387,7 +379,5 @@
       END DO
       !
-      CALL wrk_dealloc( jpi,jpj,jpk,   zbetup, zbetdo )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('nonosc_z')
+      IF( ln_timing )   CALL timing_stop('nonosc_z')
       !
    END SUBROUTINE nonosc_z
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/trabbc.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/trabbc.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/trabbc.F90	(revision 9019)
@@ -27,5 +27,4 @@
    USE lib_mpp        ! distributed memory computing library
    USE prtctl         ! Print control
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
 
@@ -77,11 +76,11 @@
       !
       INTEGER  ::   ji, jj    ! dummy loop indices
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrdt
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrdt   ! 3D workspace
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('tra_bbc')
+      IF( ln_timing )   CALL timing_start('tra_bbc')
       !
       IF( l_trdtra )   THEN         ! Save the input temperature trend
-         CALL wrk_alloc( jpi,jpj,jpk,   ztrdt )
+         ALLOCATE( ztrdt(jpi,jpj,jpk) )
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem)
       ENDIF
@@ -98,10 +97,10 @@
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
          CALL trd_tra( kt, 'TRA', jp_tem, jptra_bbc, ztrdt )
-         CALL wrk_dealloc( jpi,jpj,jpk,   ztrdt )
+         DEALLOCATE( ztrdt )
       ENDIF
       !
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' bbc  - Ta: ', mask1=tmask, clinfo3='tra-ta' )
       !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_bbc')
+      IF( ln_timing )   CALL timing_stop('tra_bbc')
       !
    END SUBROUTINE tra_bbc
@@ -130,5 +129,5 @@
       TYPE(FLD_N)        ::   sn_qgh    ! informations about the geotherm. field to be read
       CHARACTER(len=256) ::   cn_dir    ! Root directory for location of ssr files
-      !
+      !!
       NAMELIST/nambbc/ln_trabbc, nn_geoflx, rn_geoflx_cst, sn_qgh, cn_dir 
       !!----------------------------------------------------------------------
@@ -161,9 +160,9 @@
          !
          CASE ( 1 )                          !* constant flux
-            IF(lwp) WRITE(numout,*) '      *** constant heat flux  =   ', rn_geoflx_cst
+            IF(lwp) WRITE(numout,*) '      ===>>   constant heat flux  =   ', rn_geoflx_cst
             qgh_trd0(:,:) = r1_rau0_rcp * rn_geoflx_cst
             !
          CASE ( 2 )                          !* variable geothermal heat flux : read the geothermal fluxes in mW/m2
-            IF(lwp) WRITE(numout,*) '      *** variable geothermal heat flux'
+            IF(lwp) WRITE(numout,*) '      ===>>   variable geothermal heat flux'
             !
             ALLOCATE( sf_qgh(1), STAT=ierror )
@@ -173,5 +172,5 @@
             ENDIF
             ALLOCATE( sf_qgh(1)%fnow(jpi,jpj,1)   )
-            IF( sn_qgh%ln_tint )ALLOCATE( sf_qgh(1)%fdta(jpi,jpj,1,2) )
+            IF( sn_qgh%ln_tint )   ALLOCATE( sf_qgh(1)%fdta(jpi,jpj,1,2) )
             ! fill sf_chl with sn_chl and control print
             CALL fld_fill( sf_qgh, (/ sn_qgh /), cn_dir, 'tra_bbc_init',   &
@@ -187,5 +186,5 @@
          !
       ELSE
-         IF(lwp) WRITE(numout,*) '      *** no geothermal heat flux'
+         IF(lwp) WRITE(numout,*) '      ===>>   no geothermal heat flux'
       ENDIF
       !
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 9019)
@@ -13,8 +13,7 @@
    !!             -   ! 2010-11  (G. Madec) add mbk. arrays associated to the deepest ocean level
    !!             -   ! 2013-04  (F. Roquet, G. Madec)  use of eosbn2 instead of local hard coded alpha and beta
+   !!            4.0  ! 2017-04  (G. Madec)  ln_trabbl namelist variable instead of a CPP key
    !!----------------------------------------------------------------------
-#if   defined key_trabbl
-   !!----------------------------------------------------------------------
-   !!   'key_trabbl'   or                             bottom boundary layer
+
    !!----------------------------------------------------------------------
    !!   tra_bbl_alloc : allocate trabbl arrays
@@ -36,5 +35,4 @@
    USE lbclnk         ! ocean lateral boundary conditions
    USE prtctl         ! Print control
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
@@ -49,7 +47,6 @@
    PUBLIC   bbl           !  routine called by trcbbl.F90 and dtadyn.F90
 
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trabbl = .TRUE.    !: bottom boundary layer flag
-
    !                                !!* Namelist nambbl *
+   LOGICAL , PUBLIC ::   ln_trabbl   !: bottom boundary layer flag
    INTEGER , PUBLIC ::   nn_bbl_ldf  !: =1   : diffusive bbl or not (=0)
    INTEGER , PUBLIC ::   nn_bbl_adv  !: =1/2 : advective bbl or not (=0)
@@ -82,8 +79,8 @@
       !!                ***  FUNCTION tra_bbl_alloc  ***
       !!----------------------------------------------------------------------
-      ALLOCATE( utr_bbl  (jpi,jpj) , ahu_bbl  (jpi,jpj) , mbku_d  (jpi,jpj) , mgrhu(jpi,jpj) ,     &
-         &      vtr_bbl  (jpi,jpj) , ahv_bbl  (jpi,jpj) , mbkv_d  (jpi,jpj) , mgrhv(jpi,jpj) ,     &
-         &      ahu_bbl_0(jpi,jpj) , ahv_bbl_0(jpi,jpj) ,                                          &
-         &      e3u_bbl_0(jpi,jpj) , e3v_bbl_0(jpi,jpj) ,                                      STAT=tra_bbl_alloc )
+      ALLOCATE( utr_bbl  (jpi,jpj) , ahu_bbl  (jpi,jpj) , mbku_d(jpi,jpj) , mgrhu(jpi,jpj) ,     &
+         &      vtr_bbl  (jpi,jpj) , ahv_bbl  (jpi,jpj) , mbkv_d(jpi,jpj) , mgrhv(jpi,jpj) ,     &
+         &      ahu_bbl_0(jpi,jpj) , ahv_bbl_0(jpi,jpj) ,                                        &
+         &      e3u_bbl_0(jpi,jpj) , e3v_bbl_0(jpi,jpj) ,                                    STAT=tra_bbl_alloc )
          !
       IF( lk_mpp            )   CALL mpp_sum ( tra_bbl_alloc )
@@ -106,11 +103,11 @@
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step
       !
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrdt, ztrds
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start( 'tra_bbl')
-      !
-      IF( l_trdtra )   THEN                         !* Save the input trends
-         CALL wrk_alloc( jpi, jpj, jpk, ztrdt, ztrds )
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrdt, ztrds
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start( 'tra_bbl')
+      !
+      IF( l_trdtra )   THEN                         !* Save the T-S input trends
+         ALLOCATE( ztrdt(jpi,jpj,jpk) , ztrds(jpi,jpj,jpk) )
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem)
          ztrds(:,:,:) = tsa(:,:,:,jp_sal)
@@ -150,8 +147,8 @@
          CALL trd_tra( kt, 'TRA', jp_tem, jptra_bbl, ztrdt )
          CALL trd_tra( kt, 'TRA', jp_sal, jptra_bbl, ztrds )
-         CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds )
-      ENDIF
-      !
-      IF( nn_timing == 1 )  CALL timing_stop( 'tra_bbl')
+         DEALLOCATE( ztrdt, ztrds )
+      ENDIF
+      !
+      IF( ln_timing )  CALL timing_stop( 'tra_bbl')
       !
    END SUBROUTINE tra_bbl
@@ -186,10 +183,8 @@
       INTEGER  ::   ik           ! local integers
       REAL(wp) ::   zbtr         ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:) :: zptb
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_bbl_dif')
-      !
-      CALL wrk_alloc( jpi, jpj, zptb )
+      REAL(wp), DIMENSION(jpi,jpj) ::   zptb   ! workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('tra_bbl_dif')
       !
       DO jn = 1, kjpt                                     ! tracer loop
@@ -216,7 +211,6 @@
       END DO                                                ! end tracer
       !                                                     ! ===========
-      CALL wrk_dealloc( jpi, jpj, zptb )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_bbl_dif')
+      !
+      IF( ln_timing )   CALL timing_stop('tra_bbl_dif')
       !
    END SUBROUTINE tra_bbl_dif
@@ -249,5 +243,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start( 'tra_bbl_adv')
+      IF( ln_timing )   CALL timing_start( 'tra_bbl_adv')
       !                                                          ! ===========
       DO jn = 1, kjpt                                            ! tracer loop
@@ -301,8 +295,9 @@
             !
          END DO
-         !                                                       ! ===========
-      END DO                                                     ! end tracer
-      !                                                          ! ===========
-      IF( nn_timing == 1 )  CALL timing_stop( 'tra_bbl_adv')
+         !                                                  ! ===========
+      END DO                                                ! end tracer
+      !                                                     ! ===========
+      !
+      IF( ln_timing )   CALL timing_stop( 'tra_bbl_adv')
       !
    END SUBROUTINE tra_bbl_adv
@@ -349,5 +344,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start( 'bbl')
+      IF( ln_timing )   CALL timing_start( 'bbl')
       !
       IF( kt == kit000 )  THEN
@@ -480,5 +475,5 @@
       ENDIF
       !
-      IF( nn_timing == 1 )  CALL timing_stop( 'bbl')
+      IF( ln_timing )   CALL timing_stop( 'bbl')
       !
    END SUBROUTINE bbl
@@ -494,13 +489,12 @@
       !!              called by nemo_init at the first timestep (kit000)
       !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj               ! dummy loop indices
-      INTEGER ::   ii0, ii1, ij0, ij1   ! local integer
-      INTEGER ::   ios                  !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:) :: zmbk
-      !
-      NAMELIST/nambbl/ nn_bbl_ldf, nn_bbl_adv, rn_ahtbbl, rn_gambbl
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start( 'tra_bbl_init')
+      INTEGER ::   ji, jj                      ! dummy loop indices
+      INTEGER ::   ii0, ii1, ij0, ij1, ios     ! local integer
+      REAL(wp), DIMENSION(jpi,jpj) ::   zmbk   ! workspace
+      !!
+      NAMELIST/nambbl/ ln_trabbl, nn_bbl_ldf, nn_bbl_adv, rn_ahtbbl, rn_gambbl
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start( 'tra_bbl_init')
       !
       REWIND( numnam_ref )              ! Namelist nambbl in reference namelist : Bottom boundary layer scheme
@@ -519,17 +513,22 @@
          WRITE(numout,*) 'tra_bbl_init : bottom boundary layer initialisation'
          WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) '   Namelist nambbl : set bbl parameters'
-         WRITE(numout,*) '      diffusive bbl (=1)   or not (=0)    nn_bbl_ldf = ', nn_bbl_ldf
-         WRITE(numout,*) '      advective bbl (=1/2) or not (=0)    nn_bbl_adv = ', nn_bbl_adv
-         WRITE(numout,*) '      diffusive bbl coefficient           rn_ahtbbl  = ', rn_ahtbbl, ' m2/s'
-         WRITE(numout,*) '      advective bbl coefficient           rn_gambbl  = ', rn_gambbl, ' s'
-      ENDIF
-
+         WRITE(numout,*) '       Namelist nambbl : set bbl parameters'
+         WRITE(numout,*) '          bottom boundary layer flag          ln_trabbl  = ', ln_trabbl
+      ENDIF
+      IF( .NOT.ln_trabbl )   RETURN
+      !
+      IF(lwp) THEN
+         WRITE(numout,*) '          diffusive bbl (=1)   or not (=0)    nn_bbl_ldf = ', nn_bbl_ldf
+         WRITE(numout,*) '          advective bbl (=1/2) or not (=0)    nn_bbl_adv = ', nn_bbl_adv
+         WRITE(numout,*) '          diffusive bbl coefficient           rn_ahtbbl  = ', rn_ahtbbl, ' m2/s'
+         WRITE(numout,*) '          advective bbl coefficient           rn_gambbl  = ', rn_gambbl, ' s'
+      ENDIF
+      !
       !                              ! allocate trabbl arrays
       IF( tra_bbl_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'tra_bbl_init : unable to allocate arrays' )
-
+      !
       IF( nn_bbl_adv == 1 )    WRITE(numout,*) '       * Advective BBL using upper velocity'
       IF( nn_bbl_adv == 2 )    WRITE(numout,*) '       * Advective BBL using velocity = F( delta rho)'
-
+      !
       !                             !* vertical index of  "deep" bottom u- and v-points
       DO jj = 1, jpjm1                    ! (the "shelf" bottom k-indices are mbku and mbkv)
@@ -540,9 +539,7 @@
       END DO
       ! converte into REAL to use lbc_lnk ; impose a min value of 1 as a zero can be set in lbclnk
-      CALL wrk_alloc( jpi, jpj, zmbk )
       zmbk(:,:) = REAL( mbku_d(:,:), wp )   ;   CALL lbc_lnk(zmbk,'U',1.)   ;   mbku_d(:,:) = MAX( INT( zmbk(:,:) ), 1 )
       zmbk(:,:) = REAL( mbkv_d(:,:), wp )   ;   CALL lbc_lnk(zmbk,'V',1.)   ;   mbkv_d(:,:) = MAX( INT( zmbk(:,:) ), 1 )
-      CALL wrk_dealloc( jpi, jpj, zmbk )
-
+      !
                                         !* sign of grad(H) at u- and v-points; zero if grad(H) = 0
       mgrhu(:,:) = 0   ;   mgrhv(:,:) = 0
@@ -570,22 +567,8 @@
       ahu_bbl_0(:,:) = rn_ahtbbl * e2_e1u(:,:) * e3u_bbl_0(:,:) * umask(:,:,1)
       ahv_bbl_0(:,:) = rn_ahtbbl * e1_e2v(:,:) * e3v_bbl_0(:,:) * vmask(:,:,1)
-
-      !
-      IF( nn_timing == 1 )  CALL timing_stop( 'tra_bbl_init')
+      !
+      IF( ln_timing )   CALL timing_stop( 'tra_bbl_init')
       !
    END SUBROUTINE tra_bbl_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Dummy module :                      No bottom boundary layer scheme
-   !!----------------------------------------------------------------------
-   LOGICAL, PUBLIC, PARAMETER ::   lk_trabbl = .FALSE.   !: bbl flag
-CONTAINS
-   SUBROUTINE tra_bbl_init               ! Dummy routine
-   END SUBROUTINE tra_bbl_init
-   SUBROUTINE tra_bbl( kt )              ! Dummy routine
-      WRITE(*,*) 'tra_bbl: You should not have seen this print! error?', kt
-   END SUBROUTINE tra_bbl
-#endif
 
    !!======================================================================
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 9019)
@@ -33,9 +33,8 @@
    !
    USE in_out_manager ! I/O manager
+   USE iom            ! XIOS
    USE lib_mpp        ! MPP library
    USE prtctl         ! Print control
-   USE wrk_nemo       ! Memory allocation
    USE timing         ! Timing
-   USE iom
 
    IMPLICIT NONE
@@ -94,12 +93,12 @@
       !
       INTEGER ::   ji, jj, jk, jn   ! dummy loop indices
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::  zts_dta, ztrdts
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )   CALL timing_start('tra_dmp')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,jpts,   zts_dta )
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts)     ::  zts_dta
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  ztrdts
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('tra_dmp')
+      !
       IF( l_trdtra )   THEN                    !* Save ta and sa trends
-         CALL wrk_alloc( jpi,jpj,jpk,jpts,   ztrdts ) 
+         ALLOCATE( ztrdts(jpi,jpj,jpk,jpts) ) 
          ztrdts(:,:,:,:) = tsa(:,:,:,:) 
       ENDIF
@@ -154,5 +153,5 @@
          CALL trd_tra( kt, 'TRA', jp_tem, jptra_dmp, ztrdts(:,:,:,jp_tem) )
          CALL trd_tra( kt, 'TRA', jp_sal, jptra_dmp, ztrdts(:,:,:,jp_sal) )
-         CALL wrk_dealloc( jpi,jpj,jpk,jpts,   ztrdts ) 
+         DEALLOCATE( ztrdts ) 
       ENDIF
       !                           ! Control print
@@ -160,7 +159,5 @@
          &                       tab3d_2=tsa(:,:,:,jp_sal), clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
       !
-      CALL wrk_dealloc( jpi,jpj,jpk,jpts,   zts_dta )
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('tra_dmp')
+      IF( ln_timing )   CALL timing_stop('tra_dmp')
       !
    END SUBROUTINE tra_dmp
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traldf.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traldf.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traldf.F90	(revision 9019)
@@ -30,5 +30,4 @@
    USE lib_mpp        ! distribued memory computing library
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE wrk_nemo       ! Memory allocation
    USE timing         ! Timing
 
@@ -58,11 +57,11 @@
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
       !!
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrdt, ztrds
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )   CALL timing_start('tra_ldf')
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrdt, ztrds
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('tra_ldf')
       !
       IF( l_trdtra )   THEN                    !* Save ta and sa trends
-         CALL wrk_alloc( jpi,jpj,jpk,   ztrdt, ztrds ) 
+         ALLOCATE( ztrdt(jpi,jpj,jpk) , ztrds(jpi,jpj,jpk) ) 
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) 
          ztrds(:,:,:) = tsa(:,:,:,jp_sal)
@@ -85,5 +84,5 @@
          CALL trd_tra( kt, 'TRA', jp_tem, jptra_ldf, ztrdt )
          CALL trd_tra( kt, 'TRA', jp_sal, jptra_ldf, ztrds )
-         CALL wrk_dealloc( jpi,jpj,jpk,   ztrdt, ztrds ) 
+         DEALLOCATE( ztrdt, ztrds ) 
       ENDIF
       !                                        !* print mean trends (used for debugging)
@@ -91,5 +90,5 @@
          &                       tab3d_2=tsa(:,:,:,jp_sal), clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
       !
-      IF( nn_timing == 1 )   CALL timing_stop('tra_ldf')
+      IF( ln_timing )   CALL timing_stop('tra_ldf')
       !
    END SUBROUTINE tra_ldf
@@ -107,5 +106,5 @@
       !!----------------------------------------------------------------------
       !
-      IF(lwp) THEN                     ! Namelist print
+      IF(lwp) THEN                     !==  Namelist print  ==!
          WRITE(numout,*)
          WRITE(numout,*) 'tra_ldf_init : lateral tracer diffusive operator'
@@ -114,18 +113,18 @@
          WRITE(numout,*) '      see ldf_tra_init report for lateral mixing parameters'
       ENDIF
-      !                                   ! use of lateral operator or not
+      !                                !==  use of lateral operator or not  ==!
       nldf   = np_ERROR
       ioptio = 0
-      IF( ln_traldf_lap )   ioptio = ioptio + 1
-      IF( ln_traldf_blp )   ioptio = ioptio + 1
-      IF( ioptio >  1   )   CALL ctl_stop( 'tra_ldf_init: use ONE or NONE of the 2 lap/bilap operator type on tracer' )
-      IF( ioptio == 0   )   nldf = np_no_ldf     ! No lateral diffusion
-      !
-      IF( nldf /= np_no_ldf ) THEN        ! direction ==>> type of operator  
+      IF( ln_traldf_NONE ) THEN   ;   nldf = np_no_ldf   ;   ioptio = ioptio + 1   ;   ENDIF
+      IF( ln_traldf_lap  ) THEN   ;                          ioptio = ioptio + 1   ;   ENDIF
+      IF( ln_traldf_blp  ) THEN   ;                          ioptio = ioptio + 1   ;   ENDIF
+      IF( ioptio /=  1   )   CALL ctl_stop( 'tra_ldf_init: use ONE of the 3 operator options (NONE/lap/blp)' )
+      !
+      IF( .NOT.ln_traldf_NONE ) THEN   !==  direction ==>> type of operator  ==!
          ioptio = 0
          IF( ln_traldf_lev )   ioptio = ioptio + 1
          IF( ln_traldf_hor )   ioptio = ioptio + 1
          IF( ln_traldf_iso )   ioptio = ioptio + 1
-         IF( ioptio >  1 )   CALL ctl_stop( 'tra_ldf_init: use only ONE direction (level/hor/iso)' )
+         IF( ioptio /=  1  )   CALL ctl_stop( 'tra_ldf_init: use ONE direction (level/hor/iso)' )
          !
          !                                ! defined the type of lateral diffusion from ln_traldf_... logicals
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_iso.F90	(revision 9019)
@@ -30,5 +30,4 @@
    USE phycst         ! physical constants
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
 
@@ -111,12 +110,9 @@
       REAL(wp) ::  zmskv, zahv_w, zabe2, zcof2, zcoef4   !   -      -
       REAL(wp) ::  zcoef0, ze3w_2, zsign, z2dt, z1_2dt   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zdkt, zdk1t, z2d
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zdit, zdjt, zftu, zftv, ztfw 
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_ldf_iso')
-      !
-      CALL wrk_alloc( jpi,jpj,       zdkt, zdk1t, z2d ) 
-      CALL wrk_alloc( jpi,jpj,jpk,   zdit, zdjt , zftu, zftv, ztfw  ) 
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zdkt, zdk1t, z2d
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdit, zdjt, zftu, zftv, ztfw 
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('tra_ldf_iso')
       !
       IF( kt == kit000 )  THEN
@@ -386,10 +382,6 @@
          !                                                        ! ===============
       END DO                                                      ! end tracer loop
-      !                                                           ! ===============
-      !
-      CALL wrk_dealloc( jpi, jpj,      zdkt, zdk1t, z2d ) 
-      CALL wrk_dealloc( jpi, jpj, jpk, zdit, zdjt , zftu, zftv, ztfw  ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_ldf_iso')
+      !
+      IF( ln_timing )   CALL timing_stop('tra_ldf_iso')
       !
    END SUBROUTINE tra_ldf_iso
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_lap_blp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_lap_blp.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_lap_blp.F90	(revision 9019)
@@ -22,9 +22,8 @@
    !
    USE in_out_manager ! I/O manager
+   USE iom            ! I/O library
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp        ! distribued memory computing library
    USE timing         ! Timing
-   USE wrk_nemo       ! Memory allocation
-   USE iom
 
    IMPLICIT NONE
@@ -87,8 +86,8 @@
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
       REAL(wp) ::   zsign            ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztu, ztv, zaheeu, zaheev
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )   CALL timing_start('tra_ldf_lap')
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ztu, ztv, zaheeu, zaheev
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('tra_ldf_lap')
       !
       IF( kt == nit000 .AND. lwp )  THEN
@@ -97,6 +96,4 @@
          WRITE(numout,*) '~~~~~~~~~~~ '
       ENDIF
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   ztu, ztv, zaheeu, zaheev ) 
       !
       l_hst = .FALSE.
@@ -169,7 +166,5 @@
       !                             ! ==================
       !
-      CALL wrk_dealloc( jpi,jpj,jpk,   ztu, ztv, zaheeu, zaheev ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_ldf_lap')
+      IF( ln_timing )   CALL timing_stop('tra_ldf_lap')
       !
    END SUBROUTINE tra_ldf_lap
@@ -203,13 +198,10 @@
       !
       INTEGER ::   ji, jj, jk, jn   ! dummy loop indices
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) :: zlap         ! laplacian at t-point
-      REAL(wp), POINTER, DIMENSION(:,:,:)   :: zglu, zglv   ! bottom GRADh of the laplacian (u- and v-points)
-      REAL(wp), POINTER, DIMENSION(:,:,:)   :: zgui, zgvi   ! top    GRADh of the laplacian (u- and v-points)
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt) :: zlap         ! laplacian at t-point
+      REAL(wp), DIMENSION(jpi,jpj,    kjpt) :: zglu, zglv   ! bottom GRADh of the laplacian (u- and v-points)
+      REAL(wp), DIMENSION(jpi,jpj,    kjpt) :: zgui, zgvi   ! top    GRADh of the laplacian (u- and v-points)
       !!---------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('tra_ldf_blp')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,kjpt,   zlap ) 
-      CALL wrk_alloc( jpi,jpj,    kjpt,   zglu, zglv, zgui, zgvi ) 
+      IF( ln_timing )   CALL timing_start('tra_ldf_blp')
       !
       IF( kt == kit000 .AND. lwp )  THEN
@@ -253,8 +245,5 @@
       END SELECT
       !
-      CALL wrk_dealloc( jpi,jpj,jpk,kjpt,   zlap ) 
-      CALL wrk_dealloc( jpi,jpj    ,kjpt,   zglu, zglv, zgui, zgvi ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_ldf_blp')
+      IF( ln_timing )   CALL timing_stop('tra_ldf_blp')
       !
    END SUBROUTINE tra_ldf_blp
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_triad.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_triad.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traldf_triad.F90	(revision 9019)
@@ -27,5 +27,4 @@
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
 
@@ -94,12 +93,9 @@
       REAL(wp) ::   ze1ur, ze2vr, ze3wr, zdxt, zdyt, zdzt
       REAL(wp) ::   zah, zah_slp, zaei_slp
-      REAL(wp), POINTER, DIMENSION(:,:  ) :: z2d                                            ! 2D workspace
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zdit, zdjt, zftu, zftv, ztfw, zpsi_uw, zpsi_vw   ! 3D     -
+      REAL(wp), DIMENSION(jpi,jpj    ) ::   z2d                                              ! 2D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdit, zdjt, zftu, zftv, ztfw, zpsi_uw, zpsi_vw   ! 3D     -
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('tra_ldf_triad')
-      !
-      CALL wrk_alloc( jpi,jpj,       z2d ) 
-      CALL wrk_alloc( jpi,jpj,jpk,   zdit, zdjt, zftu, zftv, ztfw, zpsi_uw, zpsi_vw  ) 
+      IF( ln_timing )   CALL timing_start('tra_ldf_triad')
       !
       IF( .NOT.ALLOCATED(zdkt3d) )  THEN
@@ -434,9 +430,5 @@
       END DO                                                      ! end tracer loop
       !                                                           ! ===============
-      !
-      CALL wrk_dealloc( jpi,jpj,       z2d ) 
-      CALL wrk_dealloc( jpi,jpj,jpk,   zdit, zdjt, zftu, zftv, ztfw, zpsi_uw, zpsi_vw  ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_ldf_triad')
+      IF( ln_timing )   CALL timing_stop('tra_ldf_triad')
       !
    END SUBROUTINE tra_ldf_triad
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/tranpc.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/tranpc.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/tranpc.F90	(revision 9019)
@@ -26,5 +26,4 @@
    USE in_out_manager ! I/O manager
    USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
 
@@ -67,11 +66,10 @@
       REAL(wp) ::   zta, zalfa, zsum_temp, zsum_alfa, zaw, zdz, zsum_z
       REAL(wp) ::   zsa, zbeta, zsum_sali, zsum_beta, zbw, zrw, z1_r2dt
-      REAL(wp), PARAMETER :: zn2_zero = 1.e-14_wp       ! acceptance criteria for neutrality (N2==0)
-      REAL(wp), POINTER, DIMENSION(:)       ::   zvn2   ! vertical profile of N2 at 1 given point...
-      REAL(wp), POINTER, DIMENSION(:,:)     ::   zvts   ! vertical profile of T and S at 1 given point...
-      REAL(wp), POINTER, DIMENSION(:,:)     ::   zvab   ! vertical profile of alpha and beta
-      REAL(wp), POINTER, DIMENSION(:,:,:)   ::   zn2    ! N^2 
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   zab    ! alpha and beta
-      REAL(wp), POINTER, DIMENSION(:,:,:)   ::   ztrdt, ztrds   ! 3D workspace
+      REAL(wp), PARAMETER ::   zn2_zero = 1.e-14_wp      ! acceptance criteria for neutrality (N2==0)
+      REAL(wp), DIMENSION(        jpk     ) ::   zvn2         ! vertical profile of N2 at 1 given point...
+      REAL(wp), DIMENSION(        jpk,jpts) ::   zvts, zvab   ! vertical profile of T & S , and  alpha & betaat 1 given point
+      REAL(wp), DIMENSION(jpi,jpj,jpk     ) ::   zn2          ! N^2 
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts) ::   zab          ! alpha and beta
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrdt, ztrds   ! 3D workspace
       !
       LOGICAL, PARAMETER :: l_LB_debug = .FALSE. ! set to true if you want to follow what is
@@ -80,19 +78,14 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('tra_npc')
+      IF( ln_timing )   CALL timing_start('tra_npc')
       !
       IF( MOD( kt, nn_npc ) == 0 ) THEN
          !
-         CALL wrk_alloc( jpi, jpj, jpk, zn2 )    ! N2
-         CALL wrk_alloc( jpi, jpj, jpk, 2, zab ) ! Alpha and Beta
-         CALL wrk_alloc( jpk, 2, zvts, zvab )    ! 1D column vector at point ji,jj
-         CALL wrk_alloc( jpk, zvn2 )             ! 1D column vector at point ji,jj
-
          IF( l_trdtra )   THEN                    !* Save initial after fields
-            CALL wrk_alloc( jpi, jpj, jpk, ztrdt, ztrds )
+            ALLOCATE( ztrdt(jpi,jpj,jpk) , ztrds(jpi,jpj,jpk) )
             ztrdt(:,:,:) = tsa(:,:,:,jp_tem) 
             ztrds(:,:,:) = tsa(:,:,:,jp_sal)
          ENDIF
-
+         !
          IF( l_LB_debug ) THEN
             ! Location of 1 known convection site to follow what's happening in the water column
@@ -101,10 +94,10 @@
             klc1 =  mbkt(ilc1,jlc1) ! bottom of the ocean for debug point...          
          ENDIF
-         
+         !
          CALL eos_rab( tsa, zab )         ! after alpha and beta (given on T-points)
          CALL bn2    ( tsa, zab, zn2 )    ! after Brunt-Vaisala  (given on W-points)
-        
+         !
          inpcc = 0
-
+         !
          DO jj = 2, jpjm1                 ! interior column only
             DO ji = fs_2, fs_jpim1
@@ -313,5 +306,5 @@
             CALL trd_tra( kt, 'TRA', jp_tem, jptra_npc, ztrdt )
             CALL trd_tra( kt, 'TRA', jp_sal, jptra_npc, ztrds )
-            CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds )
+            DEALLOCATE( ztrdt, ztrds )
          ENDIF
          !
@@ -323,12 +316,7 @@
          ENDIF
          !
-         CALL wrk_dealloc(jpi, jpj, jpk, zn2 )
-         CALL wrk_dealloc(jpi, jpj, jpk, 2, zab )
-         CALL wrk_dealloc(jpk, zvn2 )
-         CALL wrk_dealloc(jpk, 2, zvts, zvab )
-         !
       ENDIF   ! IF( MOD( kt, nn_npc ) == 0 ) THEN
       !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_npc')
+      IF( ln_timing )   CALL timing_stop('tra_npc')
       !
    END SUBROUTINE tra_npc
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 9019)
@@ -35,7 +35,7 @@
    USE traqsr          ! penetrative solar radiation (needed for nksr)
    USE phycst          ! physical constant
-   USE ldftra          ! lateral physics on tracers
-   USE ldfslp
-   USE bdy_oce   , ONLY: ln_bdy
+   USE ldftra          ! lateral physics : tracers
+   USE ldfslp          ! lateral physics : slopes
+   USE bdy_oce  , ONLY : ln_bdy
    USE bdytra          ! open boundary condition (bdy_tra routine)
    !
@@ -43,5 +43,4 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE prtctl          ! Print control
-   USE wrk_nemo        ! Memory allocation
    USE timing          ! Timing
 #if defined key_agrif
@@ -91,8 +90,8 @@
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
       REAL(wp) ::   zfact            ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrdt, ztrds
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start( 'tra_nxt')
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrdt, ztrds
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start( 'tra_nxt')
       !
       IF( kt == nit000 ) THEN
@@ -114,5 +113,5 @@
  
       ! set time step size (Euler/Leapfrog)
-      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;   r2dt =     rdt      ! at nit000             (Euler)
+      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;   r2dt =        rdt   ! at nit000             (Euler)
       ELSEIF( kt <= nit000 + 1 )           THEN   ;   r2dt = 2._wp* rdt   ! at nit000 or nit000+1 (Leapfrog)
       ENDIF
@@ -120,5 +119,5 @@
       ! trends computation initialisation
       IF( l_trdtra )   THEN                    
-         CALL wrk_alloc( jpi, jpj, jpk, ztrdt, ztrds )
+         ALLOCATE( ztrdt(jpi,jpj,jpk) , ztrds(jpi,jpj,jpk) )
          ztrdt(:,:,jpk) = 0._wp
          ztrds(:,:,jpk) = 0._wp
@@ -136,5 +135,5 @@
          CALL trd_tra( kt, 'TRA', jp_tem, jptra_tot, ztrdt )
          CALL trd_tra( kt, 'TRA', jp_sal, jptra_tot, ztrds )
-         IF( ln_linssh ) THEN 
+         IF( ln_linssh ) THEN       ! linear sea surface height only
             ! Store now fields before applying the Asselin filter 
             ! in order to calculate Asselin filter trend later.
@@ -150,6 +149,6 @@
             END DO
          END DO
-         IF (l_trdtra .AND. .NOT. ln_linssh) THEN  ! Zero Asselin filter contribution must be explicitly written out since for vvl
-                                                   ! Asselin filter is output by tra_nxt_vvl that is not called on this time step
+         IF (l_trdtra .AND. .NOT. ln_linssh ) THEN   ! Zero Asselin filter contribution must be explicitly written out since for vvl
+            !                                        ! Asselin filter is output by tra_nxt_vvl that is not called on this time step
             ztrdt(:,:,:) = 0._wp
             ztrds(:,:,:) = 0._wp
@@ -181,5 +180,5 @@
          CALL trd_tra( kt, 'TRA', jp_sal, jptra_atf, ztrds )
       END IF
-      IF( l_trdtra ) CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds )
+      IF( l_trdtra )   DEALLOCATE( ztrdt , ztrds )
       !
       !                        ! control print
@@ -187,5 +186,5 @@
          &                       tab3d_2=tsn(:,:,:,jp_sal), clinfo2=       ' Sn: ', mask2=tmask )
       !
-      IF( nn_timing == 1 )   CALL timing_stop('tra_nxt')
+      IF( ln_timing )   CALL timing_stop('tra_nxt')
       !
    END SUBROUTINE tra_nxt
@@ -271,5 +270,5 @@
       REAL(wp) ::   zfact, zfact1, ztc_a , ztc_n , ztc_b , ztc_f , ztc_d    ! local scalar
       REAL(wp) ::   zfact2, ze3t_b, ze3t_n, ze3t_a, ze3t_f, ze3t_d   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) :: ztrd_atf
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) ::   ztrd_atf
       !!----------------------------------------------------------------------
       !
@@ -290,13 +289,13 @@
       ENDIF
       !
-      IF( ( l_trdtra .and. cdtype == 'TRA' ) .OR. ( l_trdtrc .and. cdtype == 'TRC' ) )   THEN
-         CALL wrk_alloc( jpi, jpj, jpk, kjpt, ztrd_atf )
+      IF( ( l_trdtra .AND. cdtype == 'TRA' ) .OR. ( l_trdtrc .AND. cdtype == 'TRC' ) )   THEN
+         ALLOCATE( ztrd_atf(jpi,jpj,jpk,kjpt) )
          ztrd_atf(:,:,:,:) = 0.0_wp
       ENDIF
       zfact = 1._wp / r2dt
+      zfact1 = atfp * p2dt
+      zfact2 = zfact1 * r1_rau0
       DO jn = 1, kjpt      
          DO jk = 1, jpkm1
-            zfact1 = atfp * p2dt
-            zfact2 = zfact1 * r1_rau0
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1
@@ -357,14 +356,15 @@
       END DO
       !
-      IF( l_trdtra .and. cdtype == 'TRA' ) THEN 
-         CALL trd_tra( kt, cdtype, jp_tem, jptra_atf, ztrd_atf(:,:,:,jp_tem) )
-         CALL trd_tra( kt, cdtype, jp_sal, jptra_atf, ztrd_atf(:,:,:,jp_sal) )
-         CALL wrk_dealloc( jpi, jpj, jpk, kjpt, ztrd_atf )
-      ENDIF
-      IF( l_trdtrc .and. cdtype == 'TRC' ) THEN
-         DO jn = 1, kjpt
-            CALL trd_tra( kt, cdtype, jn, jptra_atf, ztrd_atf(:,:,:,jn) )
-         END DO
-         CALL wrk_dealloc( jpi, jpj, jpk, kjpt, ztrd_atf )
+      IF( ( l_trdtra .AND. cdtype == 'TRA' ) .OR. ( l_trdtrc .AND. cdtype == 'TRC' ) )   THEN
+         IF( l_trdtra .AND. cdtype == 'TRA' ) THEN 
+            CALL trd_tra( kt, cdtype, jp_tem, jptra_atf, ztrd_atf(:,:,:,jp_tem) )
+            CALL trd_tra( kt, cdtype, jp_sal, jptra_atf, ztrd_atf(:,:,:,jp_sal) )
+         ENDIF
+         IF( l_trdtrc .AND. cdtype == 'TRC' ) THEN
+            DO jn = 1, kjpt
+               CALL trd_tra( kt, cdtype, jn, jptra_atf, ztrd_atf(:,:,:,jn) )
+            END DO
+         ENDIF
+         DEALLOCATE( ztrd_atf )
       ENDIF
       !
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/traqsr.F90	(revision 9019)
@@ -29,10 +29,9 @@
    USE in_out_manager ! I/O manager
    USE prtctl         ! Print control
-   USE iom            ! I/O manager
+   USE iom            ! I/O library
    USE fldread        ! read input fields
    USE restart        ! ocean restart
    USE lib_mpp        ! MPP library
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
 
@@ -48,5 +47,4 @@
    LOGICAL , PUBLIC ::   ln_qsr_2bd   !: 2 band         light absorption flag
    LOGICAL , PUBLIC ::   ln_qsr_bio   !: bio-model      light absorption flag
-   LOGICAL , PUBLIC ::   ln_qsr_ice   !: light penetration for ice-model LIM3 (clem)
    INTEGER , PUBLIC ::   nn_chldta    !: use Chlorophyll data (=1) or not (=0)
    REAL(wp), PUBLIC ::   rn_abs       !: fraction absorbed in the very near surface (RGB & 2 bands)
@@ -113,10 +111,10 @@
       REAL(wp) ::   zCb, zCmax, zze, zpsi, zpsimax, zdelpsi, zCtot, zCze
       REAL(wp) ::   zlogc, zlogc2, zlogc3 
-      REAL(wp), POINTER, DIMENSION(:,:)   :: zekb, zekg, zekr
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: ze0, ze1, ze2, ze3, zea, ztrdt
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zetot, zchl3d
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_qsr')
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:)   :: zekb, zekg, zekr
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: ze0, ze1, ze2, ze3, zea, ztrdt
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: zetot, zchl3d
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('tra_qsr')
       !
       IF( kt == nit000 ) THEN
@@ -127,5 +125,5 @@
       !
       IF( l_trdtra ) THEN      ! trends diagnostic: save the input temperature trend
-         CALL wrk_alloc( jpi,jpj,jpk,   ztrdt ) 
+         ALLOCATE( ztrdt(jpi,jpj,jpk) ) 
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem)
       ENDIF
@@ -161,6 +159,7 @@
       CASE( np_RGB , np_RGBc )         !==  R-G-B fluxes  ==!
          !
-         CALL wrk_alloc( jpi,jpj,       zekb, zekg, zekr        ) 
-         CALL wrk_alloc( jpi,jpj,jpk,   ze0, ze1, ze2, ze3, zea, zchl3d ) 
+         ALLOCATE( zekb(jpi,jpj)     , zekg(jpi,jpj)     , zekr  (jpi,jpj)     , &
+            &      ze0 (jpi,jpj,jpk) , ze1 (jpi,jpj,jpk) , ze2   (jpi,jpj,jpk) , &
+            &      ze3 (jpi,jpj,jpk) , zea (jpi,jpj,jpk) , zchl3d(jpi,jpj,jpk)   ) 
          !
          IF( nqsr == np_RGBc ) THEN          !*  Variable Chlorophyll
@@ -240,6 +239,5 @@
          END DO
          !
-         CALL wrk_dealloc( jpi,jpj,        zekb, zekg, zekr        ) 
-         CALL wrk_dealloc( jpi,jpj,jpk,   ze0, ze1, ze2, ze3, zea, zchl3d ) 
+         DEALLOCATE( zekb , zekg , zekr , ze0 , ze1 , ze2 , ze3 , zea , zchl3d ) 
          !
       CASE( np_2BD  )            !==  2-bands fluxes  ==!
@@ -269,26 +267,22 @@
       END DO
       !
-      IF( ln_qsr_ice ) THEN      ! sea-ice: store the 1st ocean level attenuation coefficient
-         DO jj = 2, jpjm1 
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               IF( qsr(ji,jj) /= 0._wp ) THEN   ;   fraqsr_1lev(ji,jj) = qsr_hc(ji,jj,1) / ( r1_rau0_rcp * qsr(ji,jj) )
-               ELSE                             ;   fraqsr_1lev(ji,jj) = 1._wp
-               ENDIF
-            END DO
-         END DO
-         ! Update haloes since lim_thd needs fraqsr_1lev to be defined everywhere
-         CALL lbc_lnk( fraqsr_1lev(:,:), 'T', 1._wp )
-      ENDIF
+      ! sea-ice: store the 1st ocean level attenuation coefficient
+      DO jj = 2, jpjm1 
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            IF( qsr(ji,jj) /= 0._wp ) THEN   ;   fraqsr_1lev(ji,jj) = qsr_hc(ji,jj,1) / ( r1_rau0_rcp * qsr(ji,jj) )
+            ELSE                             ;   fraqsr_1lev(ji,jj) = 1._wp
+            ENDIF
+         END DO
+      END DO
+      CALL lbc_lnk( fraqsr_1lev(:,:), 'T', 1._wp )
       !
       IF( iom_use('qsr3d') ) THEN      ! output the shortwave Radiation distribution
-         CALL wrk_alloc( jpi,jpj,jpk,   zetot )
-         !
+         ALLOCATE( zetot(jpi,jpj,jpk) )
          zetot(:,:,nksr+1:jpk) = 0._wp     ! below ~400m set to zero
          DO jk = nksr, 1, -1
-            zetot(:,:,jk) = zetot(:,:,jk+1) + qsr_hc(:,:,jk) / r1_rau0_rcp
+            zetot(:,:,jk) = zetot(:,:,jk+1) + qsr_hc(:,:,jk) * rau0_rcp
          END DO         
          CALL iom_put( 'qsr3d', zetot )   ! 3D distribution of shortwave Radiation
-         !
-         CALL wrk_dealloc( jpi,jpj,jpk,   zetot ) 
+         DEALLOCATE( zetot ) 
       ENDIF
       !
@@ -301,10 +295,10 @@
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
          CALL trd_tra( kt, 'TRA', jp_tem, jptra_qsr, ztrdt )
-         CALL wrk_dealloc( jpi,jpj,jpk,   ztrdt ) 
+         DEALLOCATE( ztrdt ) 
       ENDIF
       !                       ! print mean trends (used for debugging)
       IF(ln_ctl)   CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' qsr  - Ta: ', mask1=tmask, clinfo3='tra-ta' )
       !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_qsr')
+      IF( ln_timing )   CALL timing_stop('tra_qsr')
       !
    END SUBROUTINE tra_qsr
@@ -336,9 +330,9 @@
       TYPE(FLD_N)        ::   sn_chl   ! informations about the chlorofyl field to be read
       !!
-      NAMELIST/namtra_qsr/  sn_chl, cn_dir, ln_qsr_rgb, ln_qsr_2bd, ln_qsr_bio, ln_qsr_ice,  &
+      NAMELIST/namtra_qsr/  sn_chl, cn_dir, ln_qsr_rgb, ln_qsr_2bd, ln_qsr_bio,  &
          &                  nn_chldta, rn_abs, rn_si0, rn_si1
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start('tra_qsr_init')
+      IF( ln_timing )   CALL timing_start('tra_qsr_init')
       !
       REWIND( numnam_ref )              ! Namelist namtra_qsr in reference     namelist
@@ -359,5 +353,4 @@
          WRITE(numout,*) '      2 band               light penetration       ln_qsr_2bd = ', ln_qsr_2bd
          WRITE(numout,*) '      bio-model            light penetration       ln_qsr_bio = ', ln_qsr_bio
-         WRITE(numout,*) '      light penetration for ice-model (LIM3)       ln_qsr_ice = ', ln_qsr_ice
          WRITE(numout,*) '      RGB : Chl data (=1) or cst value (=0)        nn_chldta  = ', nn_chldta
          WRITE(numout,*) '      RGB & 2 bands: fraction of light (rn_si1)    rn_abs     = ', rn_abs
@@ -435,5 +428,5 @@
       ENDIF
       !
-      IF( nn_timing == 1 )   CALL timing_stop('tra_qsr_init')
+      IF( ln_timing )   CALL timing_stop('tra_qsr_init')
       !
    END SUBROUTINE tra_qsr_init
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/trasbc.F90	(revision 9019)
@@ -32,5 +32,4 @@
    USE iom            ! xIOS server
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
 
@@ -75,8 +74,8 @@
       INTEGER  ::   ikt, ikb              ! local integers
       REAL(wp) ::   zfact, z1_e3t, zdep   ! local scalar
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrdt, ztrds
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::  ztrdt, ztrds
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('tra_sbc')
+      IF( ln_timing )   CALL timing_start('tra_sbc')
       !
       IF( kt == nit000 ) THEN
@@ -87,5 +86,5 @@
       !
       IF( l_trdtra ) THEN                    !* Save ta and sa trends
-         CALL wrk_alloc( jpi, jpj, jpk, ztrdt, ztrds ) 
+         ALLOCATE( ztrdt(jpi,jpj,jpk) , ztrds(jpi,jpj,jpk) ) 
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem)
          ztrds(:,:,:) = tsa(:,:,:,jp_sal)
@@ -232,5 +231,5 @@
          CALL trd_tra( kt, 'TRA', jp_tem, jptra_nsr, ztrdt )
          CALL trd_tra( kt, 'TRA', jp_sal, jptra_nsr, ztrds )
-         CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds ) 
+         DEALLOCATE( ztrdt , ztrds ) 
       ENDIF
       !
@@ -238,5 +237,5 @@
          &                       tab3d_2=tsa(:,:,:,jp_sal), clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
       !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_sbc')
+      IF( ln_timing )   CALL timing_stop('tra_sbc')
       !
    END SUBROUTINE tra_sbc
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf.F90	(revision 9019)
@@ -4,11 +4,11 @@
    !! Ocean active tracers:  vertical component of the tracer mixing trend
    !!==============================================================================
-   !! History :  1.0  ! 2005-11  (G. Madec)  Original code
-   !!            3.0  ! 2008-01  (C. Ethe, G. Madec)  merge TRC-TRA
+   !! History :  1.0  !  2005-11  (G. Madec)  Original code
+   !!            3.0  !  2008-01  (C. Ethe, G. Madec)  merge TRC-TRA
+   !!            4.0  !  2017-06  (G. Madec)  remove explict time-stepping option
    !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
    !!   tra_zdf       : Update the tracer trend with the vertical diffusion
-   !!   tra_zdf_init  : initialisation of the computation
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and tracers variables
@@ -20,6 +20,4 @@
    USE ldftra         ! lateral diffusion: eddy diffusivity
    USE ldfslp         ! lateral diffusion: iso-neutral slope 
-   USE trazdf_exp     ! vertical diffusion: explicit (tra_zdf_exp routine)
-   USE trazdf_imp     ! vertical diffusion: implicit (tra_zdf_imp routine)
    USE trd_oce        ! trends: ocean variables
    USE trdtra         ! trends: tracer trend manager
@@ -29,5 +27,4 @@
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory allocation
    USE timing         ! Timing
 
@@ -35,14 +32,11 @@
    PRIVATE
 
-   PUBLIC   tra_zdf        ! routine called by step.F90
-   PUBLIC   tra_zdf_init   ! routine called by nemogcm.F90
-
-   INTEGER ::   nzdf = 0   ! type vertical diffusion algorithm used (defined from ln_zdf...  namlist logicals)
+   PUBLIC   tra_zdf       ! called by step.F90
+   PUBLIC   tra_zdf_imp   ! called by trczdf.F90
 
    !! * Substitutions
-#  include "zdfddm_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -56,28 +50,25 @@
       !! ** Purpose :   compute the vertical ocean tracer physics.
       !!---------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-      !
-      INTEGER  ::   jk                   ! Dummy loop indices
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrdt, ztrds   ! 3D workspace
-      !!---------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_zdf')
-      !
-      IF( neuler == 0 .AND. kt == nit000 ) THEN     ! at nit000
-         r2dt =  rdt                          ! = rdt (restarting with Euler time stepping)
-      ELSEIF( kt <= nit000 + 1) THEN                ! at nit000 or nit000+1
-         r2dt = 2. * rdt                      ! = 2 rdt (leapfrog)
-      ENDIF
-      !
-      IF( l_trdtra )   THEN                    !* Save ta and sa trends
-         CALL wrk_alloc( jpi, jpj, jpk, ztrdt, ztrds )
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      INTEGER  ::   jk   ! Dummy loop indices
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ztrdt, ztrds   ! 3D workspace
+      !!---------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('tra_zdf')
+      !
+      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;   r2dt =      rdt   ! at nit000, =   rdt (restarting with Euler time stepping)
+      ELSEIF( kt <= nit000 + 1           ) THEN   ;   r2dt = 2. * rdt   ! otherwise, = 2 rdt (leapfrog)
+      ENDIF
+      !
+      IF( l_trdtra )   THEN                  !* Save ta and sa trends
+         ALLOCATE( ztrdt(jpi,jpj,jpk) , ztrds(jpi,jpj,jpk) )
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem)
          ztrds(:,:,:) = tsa(:,:,:,jp_sal)
       ENDIF
       !
-      SELECT CASE ( nzdf )                       ! compute lateral mixing trend and add it to the general trend
-      CASE ( 0 )    ;    CALL tra_zdf_exp( kt, nit000, 'TRA', r2dt, nn_zdfexp, tsb, tsa, jpts )  !   explicit scheme 
-      CASE ( 1 )    ;    CALL tra_zdf_imp( kt, nit000, 'TRA', r2dt,            tsb, tsa, jpts )  !   implicit scheme 
-      END SELECT
+      !                                      !* compute lateral mixing trend and add it to the general trend
+      CALL tra_zdf_imp( kt, nit000, 'TRA', r2dt, tsb, tsa, jpts ) 
+
 !!gm WHY here !   and I don't like that !
       ! DRAKKAR SSS control {
@@ -90,7 +81,7 @@
          DO jk = 1, jpkm1
             ztrdt(:,:,jk) = ( ( tsa(:,:,jk,jp_tem)*e3t_a(:,:,jk) - tsb(:,:,jk,jp_tem)*e3t_b(:,:,jk) ) &
-                 & / (e3t_n(:,:,jk)*r2dt) ) - ztrdt(:,:,jk)
+               &          / (e3t_n(:,:,jk)*r2dt) ) - ztrdt(:,:,jk)
             ztrds(:,:,jk) = ( ( tsa(:,:,jk,jp_sal)*e3t_a(:,:,jk) - tsb(:,:,jk,jp_sal)*e3t_b(:,:,jk) ) &
-                 & / (e3t_n(:,:,jk)*r2dt) ) - ztrds(:,:,jk)
+              &           / (e3t_n(:,:,jk)*r2dt) ) - ztrds(:,:,jk)
          END DO
 !!gm this should be moved in trdtra.F90 and done on all trends
@@ -100,5 +91,5 @@
          CALL trd_tra( kt, 'TRA', jp_tem, jptra_zdf, ztrdt )
          CALL trd_tra( kt, 'TRA', jp_sal, jptra_zdf, ztrds )
-         CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds )
+         DEALLOCATE( ztrdt , ztrds )
       ENDIF
       !                                          ! print mean trends (used for debugging)
@@ -106,46 +97,165 @@
          &                       tab3d_2=tsa(:,:,:,jp_sal), clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
       !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_zdf')
+      IF( ln_timing )   CALL timing_stop('tra_zdf')
       !
    END SUBROUTINE tra_zdf
 
-
-   SUBROUTINE tra_zdf_init
+ 
+   SUBROUTINE tra_zdf_imp( kt, kit000, cdtype, p2dt, ptb, pta, kjpt ) 
       !!----------------------------------------------------------------------
-      !!                 ***  ROUTINE tra_zdf_init  ***
-      !!
-      !! ** Purpose :   Choose the vertical mixing scheme
-      !!
-      !! ** Method  :   Set nzdf from ln_zdfexp
-      !!      nzdf = 0   explicit (time-splitting) scheme (ln_zdfexp=T)
-      !!           = 1   implicit (euler backward) scheme (ln_zdfexp=F)
-      !!      NB: rotation of lateral mixing operator or TKE & GLS schemes,
-      !!          an implicit scheme is required.
-      !!----------------------------------------------------------------------
-      USE zdftke
-      USE zdfgls
-      !!----------------------------------------------------------------------
-      !
-      ! Choice from ln_zdfexp already read in namelist in zdfini module
-      IF( ln_zdfexp ) THEN   ;   nzdf = 0           ! use explicit scheme
-      ELSE                   ;   nzdf = 1           ! use implicit scheme
-      ENDIF
-      !
-      ! Force implicit schemes
-      IF( lk_zdftke .OR. lk_zdfgls   )   nzdf = 1   ! TKE, or GLS physics
-      IF( ln_traldf_iso              )   nzdf = 1   ! iso-neutral lateral physics
-      IF( ln_traldf_hor .AND. ln_sco )   nzdf = 1   ! horizontal lateral physics in s-coordinate
-      IF( ln_zdfexp .AND. nzdf == 1 )   CALL ctl_stop( 'tra_zdf : If using the rotation of lateral mixing operator',   &
-            &                         ' GLS or TKE scheme, the implicit scheme is required, set ln_zdfexp = .false.' )
-            !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'tra_zdf_init : vertical tracer physics scheme'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         IF( nzdf ==  0 )   WRITE(numout,*) '      ===>>   Explicit time-splitting scheme'
-         IF( nzdf ==  1 )   WRITE(numout,*) '      ===>>   Implicit (euler backward) scheme'
-      ENDIF
-      !
-   END SUBROUTINE tra_zdf_init
+      !!                  ***  ROUTINE tra_zdf_imp  ***
+      !!
+      !! ** Purpose :   Compute the after tracer through a implicit computation
+      !!     of the vertical tracer diffusion (including the vertical component 
+      !!     of lateral mixing (only for 2nd order operator, for fourth order 
+      !!     it is already computed and add to the general trend in traldf) 
+      !!
+      !! ** Method  :  The vertical diffusion of a tracer ,t , is given by:
+      !!          difft = dz( avt dz(t) ) = 1/e3t dk+1( avt/e3w dk(t) )
+      !!      It is computed using a backward time scheme (t=after field)
+      !!      which provide directly the after tracer field.
+      !!      If ln_zdfddm=T, use avs for salinity or for passive tracers
+      !!      Surface and bottom boundary conditions: no diffusive flux on
+      !!      both tracers (bottom, applied through the masked field avt).
+      !!      If iso-neutral mixing, add to avt the contribution due to lateral mixing.
+      !!
+      !! ** Action  : - pta  becomes the after tracer
+      !!---------------------------------------------------------------------
+      INTEGER                              , INTENT(in   ) ::   kt       ! ocean time-step index
+      INTEGER                              , INTENT(in   ) ::   kit000   ! first time step index
+      CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype   ! =TRA or TRC (tracer indicator)
+      INTEGER                              , INTENT(in   ) ::   kjpt     ! number of tracers
+      REAL(wp)                             , INTENT(in   ) ::   p2dt     ! tracer time-step
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb      ! before and now tracer fields
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta      ! in: tracer trend ; out: after tracer field
+      !
+      INTEGER  ::  ji, jj, jk, jn   ! dummy loop indices
+      REAL(wp) ::  zrhs             ! local scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  zwi, zwt, zwd, zws
+      !!---------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('tra_zdf_imp')
+      !
+      IF( kt == kit000 )  THEN
+         IF(lwp)WRITE(numout,*)
+         IF(lwp)WRITE(numout,*) 'tra_zdf_imp : implicit vertical mixing on ', cdtype
+         IF(lwp)WRITE(numout,*) '~~~~~~~~~~~ '
+      ENDIF
+      !                                               ! ============= !
+      DO jn = 1, kjpt                                 !  tracer loop  !
+         !                                            ! ============= !
+         !  Matrix construction
+         ! --------------------
+         ! Build matrix if temperature or salinity (only in double diffusion case) or first passive tracer
+         !
+         IF(  ( cdtype == 'TRA' .AND. ( jn == jp_tem .OR. ( jn == jp_sal .AND. ln_zdfddm ) ) ) .OR.   &
+            & ( cdtype == 'TRC' .AND. jn == 1 )  )  THEN
+            !
+            ! vertical mixing coef.: avt for temperature, avs for salinity and passive tracers
+            IF( cdtype == 'TRA' .AND. jn == jp_tem ) THEN   ;   zwt(:,:,2:jpk) = avt(:,:,2:jpk)
+            ELSE                                            ;   zwt(:,:,2:jpk) = avs(:,:,2:jpk)
+            ENDIF
+            zwt(:,:,1) = 0._wp
+            !
+            IF( l_ldfslp ) THEN            ! isoneutral diffusion: add the contribution 
+               IF( ln_traldf_msc  ) THEN     ! MSC iso-neutral operator 
+                  DO jk = 2, jpkm1
+                     DO jj = 2, jpjm1
+                        DO ji = fs_2, fs_jpim1   ! vector opt.
+                           zwt(ji,jj,jk) = zwt(ji,jj,jk) + akz(ji,jj,jk)  
+                        END DO
+                     END DO
+                  END DO
+               ELSE                          ! standard or triad iso-neutral operator
+                  DO jk = 2, jpkm1
+                     DO jj = 2, jpjm1
+                        DO ji = fs_2, fs_jpim1   ! vector opt.
+                           zwt(ji,jj,jk) = zwt(ji,jj,jk) + ah_wslp2(ji,jj,jk)
+                        END DO
+                     END DO
+                  END DO
+               ENDIF
+            ENDIF
+            !
+            ! Diagonal, lower (i), upper (s)  (including the bottom boundary condition since avt is masked)
+            DO jk = 1, jpkm1
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1   ! vector opt.
+!!gm BUG  I think, use e3w_a instead of e3w_n, not sure of that
+                     zwi(ji,jj,jk) = - p2dt * zwt(ji,jj,jk  ) / e3w_n(ji,jj,jk  )
+                     zws(ji,jj,jk) = - p2dt * zwt(ji,jj,jk+1) / e3w_n(ji,jj,jk+1)
+                     zwd(ji,jj,jk) = e3t_a(ji,jj,jk) - zwi(ji,jj,jk) - zws(ji,jj,jk)
+                 END DO
+               END DO
+            END DO
+            !
+            !! Matrix inversion from the first level
+            !!----------------------------------------------------------------------
+            !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
+            !
+            !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
+            !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
+            !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
+            !        (        ...               )( ...  ) ( ...  )
+            !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
+            !
+            !   m is decomposed in the product of an upper and lower triangular matrix.
+            !   The 3 diagonal terms are in 3d arrays: zwd, zws, zwi.
+            !   Suffices i,s and d indicate "inferior" (below diagonal), diagonal
+            !   and "superior" (above diagonal) components of the tridiagonal system.
+            !   The solution will be in the 4d array pta.
+            !   The 3d array zwt is used as a work space array.
+            !   En route to the solution pta is used a to evaluate the rhs and then 
+            !   used as a work space array: its value is modified.
+            !
+            DO jj = 2, jpjm1        !* 1st recurrence:   Tk = Dk - Ik Sk-1 / Tk-1   (increasing k)
+               DO ji = fs_2, fs_jpim1            ! done one for all passive tracers (so included in the IF instruction)
+                  zwt(ji,jj,1) = zwd(ji,jj,1)
+               END DO
+            END DO
+            DO jk = 2, jpkm1
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1
+                     zwt(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1) / zwt(ji,jj,jk-1)
+                  END DO
+               END DO
+            END DO
+            !
+         ENDIF 
+         !         
+         DO jj = 2, jpjm1           !* 2nd recurrence:    Zk = Yk - Ik / Tk-1  Zk-1
+            DO ji = fs_2, fs_jpim1
+               pta(ji,jj,1,jn) = e3t_b(ji,jj,1) * ptb(ji,jj,1,jn) + p2dt * e3t_n(ji,jj,1) * pta(ji,jj,1,jn)
+            END DO
+         END DO
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
+                  zrhs = e3t_b(ji,jj,jk) * ptb(ji,jj,jk,jn) + p2dt * e3t_n(ji,jj,jk) * pta(ji,jj,jk,jn)   ! zrhs=right hand side
+                  pta(ji,jj,jk,jn) = zrhs - zwi(ji,jj,jk) / zwt(ji,jj,jk-1) * pta(ji,jj,jk-1,jn)
+               END DO
+            END DO
+         END DO
+         !
+         DO jj = 2, jpjm1           !* 3d recurrence:    Xk = (Zk - Sk Xk+1 ) / Tk   (result is the after tracer)
+            DO ji = fs_2, fs_jpim1
+               pta(ji,jj,jpkm1,jn) = pta(ji,jj,jpkm1,jn) / zwt(ji,jj,jpkm1) * tmask(ji,jj,jpkm1)
+            END DO
+         END DO
+         DO jk = jpk-2, 1, -1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
+                  pta(ji,jj,jk,jn) = ( pta(ji,jj,jk,jn) - zws(ji,jj,jk) * pta(ji,jj,jk+1,jn) )   &
+                     &             / zwt(ji,jj,jk) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         !                                            ! ================= !
+      END DO                                          !  end tracer loop  !
+      !                                               ! ================= !
+      !
+      IF( ln_timing )   CALL timing_stop('tra_zdf_imp')
+      !
+   END SUBROUTINE tra_zdf_imp
 
    !!==============================================================================
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf_exp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf_exp.F90	(revision 9018)
+++ 	(revision )
@@ -1,153 +1,0 @@
-MODULE trazdf_exp
-   !!==============================================================================
-   !!                    ***  MODULE  trazdf_exp  ***
-   !! Ocean  tracers:  vertical component of the tracer mixing trend using
-   !!                  a split-explicit time-stepping 
-   !!==============================================================================
-   !! History :  OPA  !  1990-10  (B. Blanke)  Original code
-   !!            7.0  !  1991-11  (G. Madec)
-   !!                 !  1992-06  (M. Imbard)  correction on tracer trend loops
-   !!                 !  1996-01  (G. Madec)  statement function for e3
-   !!                 !  1997-05  (G. Madec)  vertical component of isopycnal
-   !!                 !  1997-07  (G. Madec)  geopotential diffusion in s-coord
-   !!                 !  2000-08  (G. Madec)  double diffusive mixing
-   !!   NEMO     1.0  !  2002-08  (G. Madec)  F90: Free form and module
-   !!             -   !  2004-08  (C. Talandier) New trends organisation
-   !!             -   !  2005-11  (G. Madec)  New organisation
-   !!            3.0  !  2008-04  (G. Madec)  leap-frog time stepping done in trazdf
-   !!            3.3  !  2010-06  (C. Ethe, G. Madec) Merge TRA-TRC
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   tra_zdf_exp   : compute the tracer the vertical diffusion trend using a
-   !!                   split-explicit time stepping and provide the after tracer
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and active tracers 
-   USE dom_oce        ! ocean space and time domain 
-   USE domvvl         ! variable volume levels
-   USE zdf_oce        ! ocean vertical physics
-   USE zdfddm         ! ocean vertical physics: double diffusion
-   USE trc_oce        ! share passive tracers/Ocean variables
-   !
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory Allocation
-   USE timing         ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   tra_zdf_exp   ! routine called by step.F90
-
-   !! * Substitutions
-#  include "zdfddm_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE tra_zdf_exp( kt, kit000, cdtype, p2dt, ksts,   &
-      &                                        ptb , pta , kjpt )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE tra_zdf_exp  ***
-      !!                   
-      !! ** Purpose :   Compute the after tracer fields due to the vertical
-      !!      tracer mixing alone, and then due to the whole tracer trend.
-      !!
-      !! ** Method  : - The after tracer fields due to the vertical diffusion
-      !!      of tracers alone is given by:
-      !!                ztb = ptb + p2dt difft
-      !!      where difft = dz( avt dz(ptb) ) = 1/e3t dk+1( avt/e3w dk(ptb) )
-      !!           (if lk_zdfddm=T use avs on salinity and passive tracers instead of avt)
-      !!      difft is evaluated with an Euler split-explit scheme using a
-      !!      no flux boundary condition at both surface and bottomi boundaries.
-      !!      (N.B. bottom condition is applied through the masked field avt).
-      !!              - the after tracer fields due to the whole trend is 
-      !!      obtained in leap-frog environment applied on thickness weighted tracer by :
-      !!          pta = [ ptb*e3tb + e3tn*( ztb - ptb + p2dt pta ) ] / e3tn
-      !!
-      !! ** Action : - after tracer fields pta
-      !!---------------------------------------------------------------------
-      INTEGER                              , INTENT(in   ) ::   kt       ! ocean time-step index
-      INTEGER                              , INTENT(in   ) ::   kit000   ! first time step index
-      CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype   ! =TRA or TRC (tracer indicator)
-      INTEGER                              , INTENT(in   ) ::   kjpt     ! number of tracers
-      INTEGER                              , INTENT(in   ) ::   ksts     ! number of sub-time step
-      REAL(wp)                             , INTENT(in   ) ::   p2dt     ! vertical profile of tracer time-step
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb      ! before and now tracer fields
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta      ! in: tracer trend ; out: after tracer field 
-      !
-      INTEGER  ::  ji, jj, jk, jn, jl   ! dummy loop indices
-      REAL(wp) ::  z1_ksts, ze3tr       ! local scalars
-      REAL(wp) ::  ztra, ze3tb    !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztb, zwf
-      !!---------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_zdf_exp')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   ztb, zwf ) 
-      !
-      IF( kt == kit000 )  THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'tra_zdf_exp : explicit vertical mixing on ', cdtype
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
-      ENDIF
-
-      ! Initializations
-      ! ---------------
-      z1_ksts = 1._wp / REAL( ksts, wp )
-      zwf(:,:, 1 ) = 0._wp    ! no flux at the surface and at bottom level
-      zwf(:,:,jpk) = 0._wp
-      !
-      !
-      DO jn = 1, kjpt         !==  loop over tracers  ==!
-         !
-         ztb(:,:,:) = ptb(:,:,:,jn)    ! initial before value for tracer
-         ! 
-         DO jl = 1, ksts         !==  Split-explicit loop  ==!
-            !              
-            DO jk = 2, jpk             ! 1st vertical derivative (w-flux)
-               DO jj = 2, jpjm1 
-                  DO ji = fs_2, fs_jpim1   ! vector opt.
-                     IF( cdtype == 'TRA' .AND. jn == jp_tem ) THEN  ! temperature : use of avt
-                        zwf(ji,jj,jk) =   avt(ji,jj,jk) * ( ztb(ji,jj,jk-1) - ztb(ji,jj,jk) ) / e3w_b(ji,jj,jk)
-                     ELSE                                           ! salinity or pass. tracer : use of avs
-                        zwf(ji,jj,jk) = fsavs(ji,jj,jk) * ( ztb(ji,jj,jk-1) - ztb(ji,jj,jk) ) / e3w_b(ji,jj,jk)
-                     END IF
-                  END DO
-               END DO
-            END DO
-            !
-            DO jk = 1, jpkm1           ! 2nd vertical derivative   ==> tracer at kt+l*2*rdt/nn_zdfexp
-               DO jj = 2, jpjm1 
-                  DO ji = fs_2, fs_jpim1   ! vector opt.
-                     ztb(ji,jj,jk) = ztb(ji,jj,jk) + p2dt * ( zwf(ji,jj,jk) - zwf(ji,jj,jk+1) ) / e3t_n(ji,jj,jk)
-                  END DO
-               END DO
-            END DO
-            !
-         END DO                  ! end sub-time stepping
-
-         DO jk = 1, jpkm1        !==  After tracer due to all trends
-            DO jj = 2, jpjm1 
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  ze3tb = e3t_b(ji,jj,jk) / e3t_n(ji,jj,jk)
-                  ztra  = ( ztb(ji,jj,jk) - ptb(ji,jj,jk,jn) ) + p2dt * pta(ji,jj,jk,jn)  ! total trend * 2dt 
-                  pta(ji,jj,jk,jn) = ( ze3tb * ptb(ji,jj,jk,jn) + ztra ) * tmask(ji,jj,jk)    ! after tracer
-               END DO
-            END DO
-         END DO
-         !
-      END DO                     ! end of tracer loop
-      !
-      CALL wrk_dealloc( jpi,jpj,jpk,   ztb, zwf ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_zdf_exp')
-      !
-   END SUBROUTINE tra_zdf_exp
-
-   !!==============================================================================
-END MODULE trazdf_exp
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf_imp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf_imp.F90	(revision 9018)
+++ 	(revision )
@@ -1,217 +1,0 @@
-MODULE trazdf_imp
-   !!======================================================================
-   !!                 ***  MODULE  trazdf_imp  ***
-   !! Ocean  tracers:  vertical component of the tracer mixing trend
-   !!======================================================================
-   !! History :  OPA  !  1990-10  (B. Blanke)  Original code
-   !!            7.0  !  1991-11  (G. Madec)
-   !!                 !  1992-06  (M. Imbard) correction on tracer trend loops
-   !!                 !  1996-01  (G. Madec) statement function for e3
-   !!                 !  1997-05  (G. Madec) vertical component of isopycnal
-   !!                 !  1997-07  (G. Madec) geopotential diffusion in s-coord
-   !!                 !  2000-08  (G. Madec) double diffusive mixing
-   !!   NEMO     1.0  !  2002-08  (G. Madec) F90: Free form and module
-   !!            2.0  !  2006-11  (G. Madec) New step reorganisation
-   !!            3.2  !  2009-03  (G. Madec)  heat and salt content trends
-   !!            3.3  !  2010-06  (C. Ethe, G. Madec) Merge TRA-TRC
-   !!             -   !  2011-02  (A. Coward, C. Ethe, G. Madec) improvment of surface boundary condition
-   !!            3.7  !  2015-11  (G. Madec, A. Coward)  non linear free surface by default 
-   !!----------------------------------------------------------------------
-  
-   !!----------------------------------------------------------------------
-   !!   tra_zdf_imp   : Update the tracer trend with vertical mixing, nad compute the after tracer field
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers variables
-   USE dom_oce        ! ocean space and time domain variables 
-   USE zdf_oce        ! ocean vertical physics variables
-   USE trc_oce        ! share passive tracers/ocean variables
-   USE domvvl         ! variable volume
-   USE ldftra         ! lateral mixing type
-   USE ldfslp         ! lateral physics: slope of diffusion
-   USE zdfddm         ! ocean vertical physics: double diffusion
-   USE traldf_triad   ! active tracers: Method of Stabilizing Correction
-   !
-   USE in_out_manager ! I/O manager
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory Allocation
-   USE timing         ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   tra_zdf_imp   !  routine called by step.F90
-
-   !! * Substitutions
-#  include "zdfddm_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
- 
-   SUBROUTINE tra_zdf_imp( kt, kit000, cdtype, p2dt, ptb, pta, kjpt ) 
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE tra_zdf_imp  ***
-      !!
-      !! ** Purpose :   Compute the after tracer through a implicit computation
-      !!     of the vertical tracer diffusion (including the vertical component 
-      !!     of lateral mixing (only for 2nd order operator, for fourth order 
-      !!     it is already computed and add to the general trend in traldf) 
-      !!
-      !! ** Method  :  The vertical diffusion of a tracer ,t , is given by:
-      !!          difft = dz( avt dz(t) ) = 1/e3t dk+1( avt/e3w dk(t) )
-      !!      It is computed using a backward time scheme (t=after field)
-      !!      which provide directly the after tracer field.
-      !!      If lk_zdfddm=T, use avs for salinity or for passive tracers
-      !!      Surface and bottom boundary conditions: no diffusive flux on
-      !!      both tracers (bottom, applied through the masked field avt).
-      !!      If iso-neutral mixing, add to avt the contribution due to lateral mixing.
-      !!
-      !! ** Action  : - pta  becomes the after tracer
-      !!---------------------------------------------------------------------
-      INTEGER                              , INTENT(in   ) ::   kt       ! ocean time-step index
-      INTEGER                              , INTENT(in   ) ::   kit000   ! first time step index
-      CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype   ! =TRA or TRC (tracer indicator)
-      INTEGER                              , INTENT(in   ) ::   kjpt     ! number of tracers
-      REAL(wp)                             , INTENT(in   ) ::   p2dt     ! tracer time-step
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb      ! before and now tracer fields
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta      ! in: tracer trend ; out: after tracer field
-      !
-      INTEGER  ::  ji, jj, jk, jn   ! dummy loop indices
-      REAL(wp) ::  zrhs             ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zwi, zwt, zwd, zws
-      !!---------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_zdf_imp')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   zwi, zwt, zwd, zws ) 
-      !
-      IF( kt == kit000 )  THEN
-         IF(lwp)WRITE(numout,*)
-         IF(lwp)WRITE(numout,*) 'tra_zdf_imp : implicit vertical mixing on ', cdtype
-         IF(lwp)WRITE(numout,*) '~~~~~~~~~~~ '
-      ENDIF
-      !                                               ! ============= !
-      DO jn = 1, kjpt                                 !  tracer loop  !
-         !                                            ! ============= !
-         !  Matrix construction
-         ! --------------------
-         ! Build matrix if temperature or salinity (only in double diffusion case) or first passive tracer
-         !
-         IF(  ( cdtype == 'TRA' .AND. ( jn == jp_tem .OR. ( jn == jp_sal .AND. lk_zdfddm ) ) ) .OR.   &
-            & ( cdtype == 'TRC' .AND. jn == 1 )  )  THEN
-            !
-            ! vertical mixing coef.: avt for temperature, avs for salinity and passive tracers
-            IF( cdtype == 'TRA' .AND. jn == jp_tem ) THEN   ;   zwt(:,:,2:jpk) = avt  (:,:,2:jpk)
-            ELSE                                            ;   zwt(:,:,2:jpk) = fsavs(:,:,2:jpk)
-            ENDIF
-            zwt(:,:,1) = 0._wp
-            !
-            IF( l_ldfslp ) THEN            ! isoneutral diffusion: add the contribution 
-               IF( ln_traldf_msc  ) THEN     ! MSC iso-neutral operator 
-                  DO jk = 2, jpkm1
-                     DO jj = 2, jpjm1
-                        DO ji = fs_2, fs_jpim1   ! vector opt.
-                           zwt(ji,jj,jk) = zwt(ji,jj,jk) + akz(ji,jj,jk)  
-                        END DO
-                     END DO
-                  END DO
-               ELSE                          ! standard or triad iso-neutral operator
-                  DO jk = 2, jpkm1
-                     DO jj = 2, jpjm1
-                        DO ji = fs_2, fs_jpim1   ! vector opt.
-                           zwt(ji,jj,jk) = zwt(ji,jj,jk) + ah_wslp2(ji,jj,jk)
-                        END DO
-                     END DO
-                  END DO
-               ENDIF
-            ENDIF
-            !
-            ! Diagonal, lower (i), upper (s)  (including the bottom boundary condition since avt is masked)
-            DO jk = 1, jpkm1
-               DO jj = 2, jpjm1
-                  DO ji = fs_2, fs_jpim1   ! vector opt.
-!!gm BUG  I think, use e3w_a instead of e3w_n
-                     zwi(ji,jj,jk) = - p2dt * zwt(ji,jj,jk  ) / e3w_n(ji,jj,jk  )
-                     zws(ji,jj,jk) = - p2dt * zwt(ji,jj,jk+1) / e3w_n(ji,jj,jk+1)
-                     zwd(ji,jj,jk) = e3t_a(ji,jj,jk) - zwi(ji,jj,jk) - zws(ji,jj,jk)
-                 END DO
-               END DO
-            END DO
-            !
-            !! Matrix inversion from the first level
-            !!----------------------------------------------------------------------
-            !   solve m.x = y  where m is a tri diagonal matrix ( jpk*jpk )
-            !
-            !        ( zwd1 zws1   0    0    0  )( zwx1 ) ( zwy1 )
-            !        ( zwi2 zwd2 zws2   0    0  )( zwx2 ) ( zwy2 )
-            !        (  0   zwi3 zwd3 zws3   0  )( zwx3 )=( zwy3 )
-            !        (        ...               )( ...  ) ( ...  )
-            !        (  0    0    0   zwik zwdk )( zwxk ) ( zwyk )
-            !
-            !   m is decomposed in the product of an upper and lower triangular matrix.
-            !   The 3 diagonal terms are in 3d arrays: zwd, zws, zwi.
-            !   Suffices i,s and d indicate "inferior" (below diagonal), diagonal
-            !   and "superior" (above diagonal) components of the tridiagonal system.
-            !   The solution will be in the 4d array pta.
-            !   The 3d array zwt is used as a work space array.
-            !   En route to the solution pta is used a to evaluate the rhs and then 
-            !   used as a work space array: its value is modified.
-            !
-            DO jj = 2, jpjm1        !* 1st recurrence:   Tk = Dk - Ik Sk-1 / Tk-1   (increasing k)
-               DO ji = fs_2, fs_jpim1            ! done one for all passive tracers (so included in the IF instruction)
-                  zwt(ji,jj,1) = zwd(ji,jj,1)
-               END DO
-            END DO
-            DO jk = 2, jpkm1
-               DO jj = 2, jpjm1
-                  DO ji = fs_2, fs_jpim1
-                     zwt(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1) / zwt(ji,jj,jk-1)
-                  END DO
-               END DO
-            END DO
-            !
-         ENDIF 
-         !         
-         DO jj = 2, jpjm1           !* 2nd recurrence:    Zk = Yk - Ik / Tk-1  Zk-1
-            DO ji = fs_2, fs_jpim1
-               pta(ji,jj,1,jn) = e3t_b(ji,jj,1) * ptb(ji,jj,1,jn) + p2dt * e3t_n(ji,jj,1) * pta(ji,jj,1,jn)
-            END DO
-         END DO
-         DO jk = 2, jpkm1
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1
-                  zrhs = e3t_b(ji,jj,jk) * ptb(ji,jj,jk,jn) + p2dt * e3t_n(ji,jj,jk) * pta(ji,jj,jk,jn)   ! zrhs=right hand side
-                  pta(ji,jj,jk,jn) = zrhs - zwi(ji,jj,jk) / zwt(ji,jj,jk-1) * pta(ji,jj,jk-1,jn)
-               END DO
-            END DO
-         END DO
-         !
-         DO jj = 2, jpjm1           !* 3d recurrence:    Xk = (Zk - Sk Xk+1 ) / Tk   (result is the after tracer)
-            DO ji = fs_2, fs_jpim1
-               pta(ji,jj,jpkm1,jn) = pta(ji,jj,jpkm1,jn) / zwt(ji,jj,jpkm1) * tmask(ji,jj,jpkm1)
-            END DO
-         END DO
-         DO jk = jpk-2, 1, -1
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1
-                  pta(ji,jj,jk,jn) = ( pta(ji,jj,jk,jn) - zws(ji,jj,jk) * pta(ji,jj,jk+1,jn) )   &
-                     &             / zwt(ji,jj,jk) * tmask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-         !                                            ! ================= !
-      END DO                                          !  end tracer loop  !
-      !                                               ! ================= !
-      !
-      CALL wrk_dealloc( jpi,jpj,jpk,   zwi, zwt, zwd, zws ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_zdf_imp')
-      !
-   END SUBROUTINE tra_zdf_imp
-
-   !!==============================================================================
-END MODULE trazdf_imp
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/zpshde.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/zpshde.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRA/zpshde.F90	(revision 9019)
@@ -22,5 +22,4 @@
    USE lbclnk          ! lateral boundary conditions (or mpp link)
    USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! Memory allocation
    USE timing          ! Timing
 
@@ -99,8 +98,8 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )   CALL timing_start( 'zps_hde')
-      !
-      pgtu(:,:,:)=0._wp   ;   zti (:,:,:)=0._wp   ;   zhi (:,:  )=0._wp
-      pgtv(:,:,:)=0._wp   ;   ztj (:,:,:)=0._wp   ;   zhj (:,:  )=0._wp
+      IF( ln_timing )   CALL timing_start( 'zps_hde')
+      !
+      pgtu(:,:,:) = 0._wp   ;   zti (:,:,:) = 0._wp   ;   zhi (:,:) = 0._wp
+      pgtv(:,:,:) = 0._wp   ;   ztj (:,:,:) = 0._wp   ;   zhj (:,:) = 0._wp
       !
       DO jn = 1, kjpt      !==   Interpolation of tracers at the last ocean level   ==!
@@ -188,8 +187,9 @@
       END IF
       !
-      IF( nn_timing == 1 )   CALL timing_stop( 'zps_hde')
+      IF( ln_timing )   CALL timing_stop( 'zps_hde')
       !
    END SUBROUTINE zps_hde
-   !
+
+
    SUBROUTINE zps_hde_isf( kt, kjpt, pta, pgtu, pgtv, pgtui, pgtvi,  &
       &                          prd, pgru, pgrv, pgrui, pgrvi )
@@ -256,5 +256,5 @@
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start( 'zps_hde_isf')
+      IF( ln_timing )   CALL timing_start( 'zps_hde_isf')
       !
       pgtu (:,:,:) = 0._wp   ;   pgtv (:,:,:) =0._wp
@@ -453,7 +453,8 @@
       END IF  
       !
-      IF( nn_timing == 1 )   CALL timing_stop( 'zps_hde_isf')
+      IF( ln_timing )   CALL timing_stop( 'zps_hde_isf')
       !
    END SUBROUTINE zps_hde_isf
+
    !!======================================================================
 END MODULE zpshde
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trd_oce.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trd_oce.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trd_oce.F90	(revision 9019)
@@ -72,5 +72,5 @@
    INTEGER, PUBLIC, PARAMETER ::   jpdyn_atf  = 10     !: Asselin time filter
    INTEGER, PUBLIC, PARAMETER ::   jpdyn_tau  = 11     !: surface stress
-   INTEGER, PUBLIC, PARAMETER ::   jpdyn_bfri = 12     !: implicit bottom friction (ln_bfrimp=.TRUE.)
+   INTEGER, PUBLIC, PARAMETER ::   jpdyn_bfri = 12     !: implicit bottom friction (ln_drgimp=.TRUE.)
    INTEGER, PUBLIC, PARAMETER ::   jpdyn_ken  = 13     !: use for calculation of KE
    !
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trddyn.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trddyn.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trddyn.F90	(revision 9019)
@@ -15,28 +15,28 @@
    USE oce            ! ocean dynamics and tracers variables
    USE dom_oce        ! ocean space and time domain variables
-   USE zdf_oce        ! ocean vertical physics variables
+   USE phycst         ! physical constants
+   USE sbc_oce        ! surface boundary condition: ocean
+   USE zdf_oce        ! ocean vertical physics: variables
+   USE zdfdrg         ! ocean vertical physics: bottom friction
    USE trd_oce        ! trends: ocean variables
-   USE zdfbfr         ! bottom friction
-   USE sbc_oce        ! surface boundary condition: ocean
-   USE phycst         ! physical constants
    USE trdken         ! trends: Kinetic ENergy 
    USE trdglo         ! trends: global domain averaged
    USE trdvor         ! trends: vertical averaged vorticity 
    USE trdmxl         ! trends: mixed layer averaged 
+   !
    USE in_out_manager ! I/O manager
    USE lbclnk         ! lateral boundary condition 
    USE iom            ! I/O manager library
    USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory allocation
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC trd_dyn        ! called by all dynXX modules
+   PUBLIC trd_dyn        ! called by all dynXXX modules
 
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -103,6 +103,6 @@
       INTEGER ::   ji, jj, jk   ! dummy loop indices
       INTEGER ::   ikbu, ikbv   ! local integers
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   z2dx, z2dy   ! 2D workspace 
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   z3dx, z3dy   ! 3D workspace 
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:)   ::   z2dx, z2dy   ! 2D workspace 
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   z3dx, z3dy   ! 3D workspace 
       !!----------------------------------------------------------------------
       !
@@ -118,5 +118,5 @@
       CASE( jpdyn_keg )   ;   CALL iom_put( "utrd_keg", putrd )    ! Kinetic Energy gradient (or had)
                               CALL iom_put( "vtrd_keg", pvtrd )
-                              CALL wrk_alloc( jpi, jpj, jpk, z3dx, z3dy )
+                              ALLOCATE( z3dx(jpi,jpj,jpk) , z3dy(jpi,jpj,jpk) )
                               z3dx(:,:,:) = 0._wp                  ! U.dxU & V.dyV (approximation)
                               z3dy(:,:,:) = 0._wp
@@ -133,25 +133,22 @@
                               CALL iom_put( "utrd_udx", z3dx  )
                               CALL iom_put( "vtrd_vdy", z3dy  )
-                              CALL wrk_dealloc( jpi, jpj, jpk, z3dx, z3dy )
-      CASE( jpdyn_zad )   ;   CALL iom_put( "utrd_zad", putrd )    ! vertical   advection
+                              DEALLOCATE( z3dx , z3dy )
+      CASE( jpdyn_zad )   ;   CALL iom_put( "utrd_zad", putrd )    ! vertical advection
                               CALL iom_put( "vtrd_zad", pvtrd )
-      CASE( jpdyn_ldf )   ;   CALL iom_put( "utrd_ldf", putrd )    ! lateral diffusion
+      CASE( jpdyn_ldf )   ;   CALL iom_put( "utrd_ldf", putrd )    ! lateral  diffusion
                               CALL iom_put( "vtrd_ldf", pvtrd )
       CASE( jpdyn_zdf )   ;   CALL iom_put( "utrd_zdf", putrd )    ! vertical diffusion 
                               CALL iom_put( "vtrd_zdf", pvtrd )
+                              !
                               !                                    ! wind stress trends
-                              CALL wrk_alloc( jpi, jpj, z2dx, z2dy )
+                              ALLOCATE( z2dx(jpi,jpj) , z2dy(jpi,jpj) )
                               z2dx(:,:) = ( utau_b(:,:) + utau(:,:) ) / ( e3u_n(:,:,1) * rau0 )
                               z2dy(:,:) = ( vtau_b(:,:) + vtau(:,:) ) / ( e3v_n(:,:,1) * rau0 )
                               CALL iom_put( "utrd_tau", z2dx )
                               CALL iom_put( "vtrd_tau", z2dy )
-                              CALL wrk_dealloc( jpi, jpj, z2dx, z2dy )
-      CASE( jpdyn_bfr )       ! called if ln_bfrimp=T
-                              CALL iom_put( "utrd_bfr", putrd )    ! bottom friction (explicit case)
-                              CALL iom_put( "vtrd_bfr", pvtrd )
-      CASE( jpdyn_atf )   ;   CALL iom_put( "utrd_atf", putrd )        ! asselin filter trends 
-                              CALL iom_put( "vtrd_atf", pvtrd )
-      CASE( jpdyn_bfri )  ;   IF( ln_bfrimp ) THEN                     ! bottom friction (implicit case)
-                              	CALL wrk_alloc( jpi, jpj, jpk, z3dx, z3dy )
+                              DEALLOCATE( z2dx , z2dy )
+                              !                                    ! bottom stress tends (implicit case)
+                              IF( ln_drgimp ) THEN
+                                 ALLOCATE( z3dx(jpi,jpj,jpk) , z3dy(jpi,jpj,jpk) )
                               	z3dx(:,:,:) = 0._wp   ;   z3dy(:,:,:) = 0._wp  ! after velocity known (now filed at this stage)
                               	DO jk = 1, jpkm1
@@ -160,14 +157,19 @@
                               	         ikbu = mbku(ji,jj)          ! deepest ocean u- & v-levels
                                           ikbv = mbkv(ji,jj)
-                                          z3dx(ji,jj,jk) = bfrua(ji,jj) * un(ji,jj,ikbu) / e3u_n(ji,jj,ikbu)
-                                          z3dy(ji,jj,jk) = bfrva(ji,jj) * vn(ji,jj,ikbv) / e3v_n(ji,jj,ikbv)
+                                          z3dx(ji,jj,jk) = 0.5*( rCdU_bot(ji+1,jj)+rCdU_bot(ji,jj) )*un(ji,jj,ikbu)/e3u_n(ji,jj,ikbu)
+                                          z3dy(ji,jj,jk) = 0.5*( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj) )*vn(ji,jj,ikbv)/e3v_n(ji,jj,ikbv)
                               	      END DO
                               	   END DO
                               	END DO
-                              	CALL lbc_lnk( z3dx, 'U', -1. ) ; CALL lbc_lnk( z3dy, 'V', -1. )
-                              	CALL iom_put( "utrd_bfri", z3dx )
-                              	CALL iom_put( "vtrd_bfri", z3dy )
-                              	CALL wrk_dealloc( jpi, jpj, jpk, z3dx, z3dy )
-         					      ENDIF
+                              	CALL lbc_lnk( z3dx, 'U', -1. )   ;   CALL lbc_lnk( z3dy, 'V', -1. )
+                              	CALL iom_put( "utrd_bfr", z3dx )
+                              	CALL iom_put( "vtrd_bfr", z3dy )
+                                 DEALLOCATE( z3dx , z3dy )
+                              ENDIF
+      CASE( jpdyn_bfr )       ! called if ln_drgimp=F
+                              CALL iom_put( "utrd_bfr", putrd )    ! bottom friction (explicit case)
+                              CALL iom_put( "vtrd_bfr", pvtrd )
+      CASE( jpdyn_atf )   ;   CALL iom_put( "utrd_atf", putrd )        ! asselin filter trends 
+                              CALL iom_put( "vtrd_atf", pvtrd )
       END SELECT
       !
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trdglo.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trdglo.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trdglo.F90	(revision 9019)
@@ -9,26 +9,25 @@
 
    !!----------------------------------------------------------------------
-   !!   trd_glo      : domain averaged budget of trends (including kinetic energy and T^2 trends)
-   !!   glo_dyn_wri  : print dynamic trends in ocean.output file
-   !!   glo_tra_wri  : print global T & T^2 trends in ocean.output file
-   !!   trd_glo_init : initialization step
+   !!   trd_glo       : domain averaged budget of trends (including kinetic energy and T^2 trends)
+   !!   glo_dyn_wri   : print dynamic trends in ocean.output file
+   !!   glo_tra_wri   : print global T & T^2 trends in ocean.output file
+   !!   trd_glo_init  : initialization step
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain variables
-   USE sbc_oce         ! surface boundary condition: ocean
-   USE trd_oce         ! trends: ocean variables
-   USE phycst          ! physical constants
-   USE ldftra          ! lateral diffusion: eddy diffusivity & EIV coeff.
-   USE ldfdyn          ! ocean dynamics: lateral physics
-   USE zdf_oce         ! ocean vertical physics
-   USE zdfbfr          ! bottom friction
-   USE zdfddm          ! ocean vertical physics: double diffusion
-   USE eosbn2          ! equation of state
-   USE phycst          ! physical constants
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain variables
+   USE sbc_oce        ! surface boundary condition: ocean
+   USE trd_oce        ! trends: ocean variables
+   USE phycst         ! physical constants
+   USE ldftra         ! lateral diffusion: eddy diffusivity & EIV coeff.
+   USE ldfdyn         ! ocean dynamics: lateral physics
+   USE zdf_oce        ! ocean vertical physics
+   USE zdfdrg         ! ocean vertical physics: bottom friction
+   USE zdfddm         ! ocean vertical physics: double diffusion
+   USE eosbn2         ! equation of state
+   USE phycst         ! physical constants
    !
-   USE lib_mpp         ! distibuted memory computing library
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O manager library
-   USE wrk_nemo        ! Memory allocation
+   USE lib_mpp        ! distibuted memory computing library
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
 
    IMPLICIT NONE
@@ -53,5 +52,4 @@
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
-#  include "zdfddm_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
@@ -78,9 +76,7 @@
       INTEGER ::   ikbu, ikbv      ! local integers
       REAL(wp)::   zvm, zvt, zvs, z1_2rau0   ! local scalars
-      REAL(wp), POINTER, DIMENSION(:,:)  :: ztswu, ztswv, z2dx, z2dy   ! 2D workspace 
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, ztswu, ztswv, z2dx, z2dy )
-
+      REAL(wp), DIMENSION(jpi,jpj)  :: ztswu, ztswv, z2dx, z2dy   ! 2D workspace 
+      !!----------------------------------------------------------------------
+      !
       IF( MOD(kt,nn_trd) == 0 .OR. kt == nit000 .OR. kt == nitend ) THEN
          !
@@ -124,8 +120,8 @@
                DO jj = 1, jpjm1
                   DO ji = 1, jpim1
-                     zvt = ptrdx(ji,jj,jk) * tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)   &
-                        &                  * e1u    (ji  ,jj  ) * e2u    (ji,jj) * e3u_n(ji,jj,jk)
-                     zvs = ptrdy(ji,jj,jk) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)   &
-                        &                  * e1v    (ji  ,jj  ) * e2v    (ji,jj) * e3u_n(ji,jj,jk)
+                     zvt = ptrdx(ji,jj,jk) * tmask_i(ji+1,jj) * tmask_i(ji,jj) * umask(ji,jj,jk)   &
+                        &                                     * e1e2u  (ji,jj) * e3u_n(ji,jj,jk)
+                     zvs = ptrdy(ji,jj,jk) * tmask_i(ji,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)   &
+                        &                                     * e1e2v  (ji,jj) * e3u_n(ji,jj,jk)
                      umo(ktrd) = umo(ktrd) + zvt
                      vmo(ktrd) = vmo(ktrd) + zvs
@@ -139,8 +135,8 @@
                DO jj = 1, jpjm1
                   DO ji = 1, jpim1
-                     zvt = ( utau_b(ji,jj) + utau(ji,jj) ) * tmask_i(ji+1,jj  ) * tmask_i(ji,jj) * umask(ji,jj,jk)   &
-                        &                       * z1_2rau0 * e1u    (ji  ,jj  ) * e2u    (ji,jj)
-                     zvs = ( vtau_b(ji,jj) + vtau(ji,jj) ) * tmask_i(ji  ,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)   &
-                        &                       * z1_2rau0 * e1v    (ji  ,jj  ) * e2v    (ji,jj) * e3u_n(ji,jj,jk)
+                     zvt = ( utau_b(ji,jj) + utau(ji,jj) ) * tmask_i(ji+1,jj) * tmask_i(ji,jj) * umask(ji,jj,jk)   &
+                        &                                                     * z1_2rau0       * e1e2u(ji,jj)
+                     zvs = ( vtau_b(ji,jj) + vtau(ji,jj) ) * tmask_i(ji,jj+1) * tmask_i(ji,jj) * vmask(ji,jj,jk)   &
+                        &                                                     * z1_2rau0       * e1e2v(ji,jj)
                      umo(jpdyn_tau) = umo(jpdyn_tau) + zvt
                      vmo(jpdyn_tau) = vmo(jpdyn_tau) + zvs
@@ -152,5 +148,5 @@
             IF( ktrd == jpdyn_atf ) THEN     ! last trend (asselin time filter)
                !
-               IF( ln_bfrimp ) THEN                   ! implicit bfr case: compute separately the bottom friction 
+               IF( ln_drgimp ) THEN                   ! implicit drag case: compute separately the bottom friction 
                   z1_2rau0 = 0.5_wp / rau0
                   DO jj = 1, jpjm1
@@ -158,6 +154,6 @@
                         ikbu = mbku(ji,jj)                  ! deepest ocean u- & v-levels
                         ikbv = mbkv(ji,jj)
-                        zvt = bfrua(ji,jj) * un(ji,jj,ikbu) * e1u(ji,jj) * e2v(ji,jj)
-                        zvs = bfrva(ji,jj) * vn(ji,jj,ikbv) * e1v(ji,jj) * e2v(ji,jj)
+                        zvt = 0.5*( rCdU_bot(ji+1,jj)+rCdU_bot(ji,jj) ) * un(ji,jj,ikbu) * e1e2u(ji,jj)
+                        zvs = 0.5*( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj) ) * vn(ji,jj,ikbv) * e1e2v(ji,jj)
                         umo(jpdyn_bfri) = umo(jpdyn_bfri) + zvt
                         vmo(jpdyn_bfri) = vmo(jpdyn_bfri) + zvs
@@ -166,4 +162,5 @@
                   END DO
                ENDIF
+!!gm top drag case is missing 
                ! 
                CALL glo_dyn_wri( kt )                 ! print the results in ocean.output
@@ -179,6 +176,4 @@
       ENDIF
       !
-      CALL wrk_dealloc( jpi, jpj, ztswu, ztswv, z2dx, z2dy )
-      !
    END SUBROUTINE trd_glo
 
@@ -194,8 +189,6 @@
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
       REAL(wp) ::   zcof         ! local scalar
-      REAL(wp), POINTER, DIMENSION(:,:,:)  ::  zkx, zky, zkz, zkepe  
-      !!----------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, jpk, zkx, zky, zkz, zkepe )
+      REAL(wp), DIMENSION(jpi,jpj,jpk)  ::  zkx, zky, zkz, zkepe  
+      !!----------------------------------------------------------------------
 
       ! I. Momentum trends
@@ -284,5 +277,5 @@
             &      + vmo(jpdyn_bfr) + vmo(jpdyn_atf) ) / tvolv
             WRITE (numout,9513) umo(jpdyn_tau) / tvolu, vmo(jpdyn_tau) / tvolv
-            IF( ln_bfrimp )   WRITE (numout,9514) umo(jpdyn_bfri) / tvolu, vmo(jpdyn_bfri) / tvolv
+            IF( ln_drgimp )   WRITE (numout,9514) umo(jpdyn_bfri) / tvolu, vmo(jpdyn_bfri) / tvolv
          ENDIF
 
@@ -323,5 +316,5 @@
             &      + hke(jpdyn_bfr) + hke(jpdyn_atf) ) / tvolt
             WRITE (numout,9533) hke(jpdyn_tau) / tvolt
-            IF( ln_bfrimp )   WRITE (numout,9534) hke(jpdyn_bfri) / tvolt
+            IF( ln_drgimp )   WRITE (numout,9534) hke(jpdyn_bfri) / tvolt
          ENDIF
 
@@ -373,6 +366,4 @@
       ENDIF
       !
-      CALL wrk_dealloc( jpi, jpj, jpk, zkx, zky, zkz, zkepe )
-      !
    END SUBROUTINE glo_dyn_wri
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trdken.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trdken.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trdken.F90	(revision 9019)
@@ -13,11 +13,10 @@
    USE oce            ! ocean dynamics and tracers variables
    USE dom_oce        ! ocean space and time domain variables
+   USE phycst         ! physical constants
    USE sbc_oce        ! surface boundary condition: ocean
    USE zdf_oce        ! ocean vertical physics variables
+   USE zdfdrg         ! ocean vertical physics: bottom friction
+   USE ldftra         ! ocean active tracers lateral physics
    USE trd_oce        ! trends: ocean variables
-!!gm   USE dynhpg          ! hydrostatic pressure gradient   
-   USE zdfbfr         ! bottom friction
-   USE ldftra         ! ocean active tracers lateral physics
-   USE phycst         ! physical constants
    USE trdvor         ! ocean vorticity trends 
    USE trdglo         ! trends:global domain averaged
@@ -27,5 +26,4 @@
    USE iom            ! I/O manager library
    USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory allocation
    USE ldfslp         ! Isopycnal slopes
 
@@ -74,5 +72,5 @@
       !!          diagnose separately the KE trend associated with wind stress
       !!              - bottom friction case (jpdyn_bfr):
-      !!          explicit case (ln_bfrimp=F): bottom trend put in the 1st level 
+      !!          explicit case (ln_drgimp=F): bottom trend put in the 1st level 
       !!                                       of putrd, pvtrd
       !
@@ -86,9 +84,7 @@
       INTEGER ::   ikbu  , ikbv     ! local integers
       INTEGER ::   ikbum1, ikbvm1   !   -       -
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   z2dx, z2dy, zke2d   ! 2D workspace 
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zke                 ! 3D workspace 
-      !!----------------------------------------------------------------------
-      !
-      CALL wrk_alloc( jpi, jpj, jpk, zke )
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   z2dx, z2dy, zke2d   ! 2D workspace 
+      REAL(wp), DIMENSION(jpi,jpj,jpk)      ::   zke                 ! 3D workspace 
+      !!----------------------------------------------------------------------
       !
       CALL lbc_lnk( putrd, 'U', -1. )   ;   CALL lbc_lnk( pvtrd, 'V', -1. )      ! lateral boundary conditions
@@ -125,5 +121,5 @@
          CASE( jpdyn_zdf )   ;   CALL iom_put( "ketrd_zdf"   , zke )    ! vertical diffusion 
          !                   !                                          ! wind stress trends
-                                 CALL wrk_alloc( jpi, jpj, z2dx, z2dy, zke2d )
+                                 ALLOCATE( z2dx(jpi,jpj) , z2dy(jpi,jpj) , zke2d(jpi,jpj) )
                            z2dx(:,:) = un(:,:,1) * ( utau_b(:,:) + utau(:,:) ) * e1e2u(:,:) * umask(:,:,1)
                            z2dy(:,:) = vn(:,:,1) * ( vtau_b(:,:) + vtau(:,:) ) * e1e2v(:,:) * vmask(:,:,1)
@@ -136,9 +132,9 @@
                            END DO
                                  CALL iom_put( "ketrd_tau"   , zke2d )  ! 
-                                 CALL wrk_dealloc( jpi, jpj     , z2dx, z2dy, zke2d )
+                                 DEALLOCATE( z2dx , z2dy , zke2d )
          CASE( jpdyn_bfr )   ;   CALL iom_put( "ketrd_bfr"   , zke )    ! bottom friction (explicit case) 
 !!gm TO BE DONE properly
-!!gm only valid if ln_bfrimp=F otherwise the bottom stress as to be recomputed at the end of the computation....
-!         IF(.NOT. ln_bfrimp) THEN
+!!gm only valid if ln_drgimp=F otherwise the bottom stress as to be recomputed at the end of the computation....
+!         IF(.NOT. ln_drgimp) THEN
 !            DO jj = 1, jpj    !   
 !               DO ji = 1, jpi
@@ -163,5 +159,5 @@
 !! reflechir a une possible sauvegarde du "vrai" un,vn pour le calcul de atf....
 !
-!         IF( ln_bfrimp ) THEN                                          ! bottom friction (implicit case)
+!         IF( ln_drgimp ) THEN                                          ! bottom friction (implicit case)
 !            DO jj = 1, jpj                                                  ! after velocity known (now filed at this stage)
 !               DO ji = 1, jpi
@@ -192,6 +188,4 @@
       END SELECT
       !
-      CALL wrk_dealloc( jpi, jpj, jpk, zke )
-      !
    END SUBROUTINE trd_ken
 
@@ -207,15 +201,12 @@
       !! ** Work only for full steps and partial steps (ln_hpg_zco or ln_hpg_zps)
       !!---------------------------------------------------------------------- 
-      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
-      !!
-      REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(  out) ::   pconv
-      !
-      INTEGER  ::   ji, jj, jk                       ! dummy loop indices
-      INTEGER  ::   iku, ikv                         ! temporary integers
-      REAL(wp) ::   zcoef                            ! temporary scalars
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::  zconv  ! temporary conv on W-grid
-      !!----------------------------------------------------------------------
-      !
-      CALL wrk_alloc( jpi,jpj,jpk, zconv )
+      INTEGER                   , INTENT(in   ) ::   kt      ! ocean time-step index
+      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   pconv   ! 
+      !
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      INTEGER  ::   iku, ikv     ! local integers
+      REAL(wp) ::   zcoef        ! local scalars
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::  zconv  ! 3D workspace
+      !!----------------------------------------------------------------------
       !
       ! Local constant initialization 
@@ -240,6 +231,4 @@
       END DO
       !
-      CALL wrk_dealloc( jpi,jpj,jpk, zconv )      
-      !
    END SUBROUTINE ken_p2k
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl.F90	(revision 9019)
@@ -69,6 +69,4 @@
    INTEGER ::   ionce, icount                   
 
-   !! * Substitutions
-#  include "zdfddm_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trdpen.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trdpen.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trdpen.F90	(revision 9019)
@@ -37,5 +37,4 @@
 
    !! * Substitutions
-#  include "zdfddm_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90	(revision 9019)
@@ -31,5 +31,4 @@
    USE iom            ! I/O manager library
    USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! Memory allocation
 
    IMPLICIT NONE
@@ -42,5 +41,4 @@
 
    !! * Substitutions
-#  include "zdfddm_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
@@ -83,9 +81,8 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::   ptra    ! now tracer variable
       !
-      INTEGER  ::   jk   ! loop indices
-      REAL(wp), POINTER, DIMENSION(:,:,:)  ::   zwt, zws, ztrdt, ztrds   ! 3D workspace
-      !!----------------------------------------------------------------------
-      !
-      CALL wrk_alloc( jpi, jpj, jpk, ztrds )
+      INTEGER ::   jk   ! loop indices
+      REAL(wp),        DIMENSION(jpi,jpj,jpk) ::   ztrds             ! 3D workspace
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   zwt, zws, ztrdt   ! 3D workspace
+      !!----------------------------------------------------------------------
       !      
       IF( .NOT. ALLOCATED( trdtx ) ) THEN      ! allocate trdtra arrays
@@ -104,4 +101,5 @@
                                  ztrds(:,:,:) = 0._wp
                                  CALL trd_tra_mng( trdt, ztrds, ktrd, kt )
+ !!gm Gurvan, verify the jptra_evd trend please !
          CASE( jptra_evd )   ;   avt_evd(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)
          CASE DEFAULT                 ! other trends: masked trends
@@ -124,5 +122,5 @@
          CASE( jptra_zdfp )           ! diagnose the "PURE" Kz trend (here: just before the swap)
             !                         ! iso-neutral diffusion case otherwise jptra_zdf is "PURE"
-            CALL wrk_alloc( jpi, jpj, jpk, zwt, zws, ztrdt )
+            ALLOCATE( zwt(jpi,jpj,jpk), zws(jpi,jpj,jpk), ztrdt(jpi,jpj,jpk) )
             !
             zwt(:,:, 1 ) = 0._wp   ;   zws(:,:, 1 ) = 0._wp            ! vertical diffusive fluxes
@@ -130,5 +128,5 @@
             DO jk = 2, jpk
                zwt(:,:,jk) = avt(:,:,jk) * ( tsa(:,:,jk-1,jp_tem) - tsa(:,:,jk,jp_tem) ) / e3w_n(:,:,jk) * tmask(:,:,jk)
-               zws(:,:,jk) = fsavs(:,:,jk) * ( tsa(:,:,jk-1,jp_sal) - tsa(:,:,jk,jp_sal) ) / e3w_n(:,:,jk) * tmask(:,:,jk)
+               zws(:,:,jk) = avs(:,:,jk) * ( tsa(:,:,jk-1,jp_sal) - tsa(:,:,jk,jp_sal) ) / e3w_n(:,:,jk) * tmask(:,:,jk)
             END DO
             !
@@ -154,5 +152,5 @@
             CALL trd_tra_mng( ztrdt, ztrds, jptra_evd, kt )  
             !
-            CALL wrk_dealloc( jpi, jpj, jpk, zwt, zws, ztrdt )
+            DEALLOCATE( zwt, zws, ztrdt )
             !
          CASE DEFAULT                 ! other trends: mask and send T & S trends to trd_tra_mng
@@ -176,6 +174,4 @@
          !
       ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj, jpk, ztrds )
       !
    END SUBROUTINE trd_tra
@@ -307,5 +303,5 @@
       INTEGER ::   ji, jj, jk   ! dummy loop indices
       INTEGER ::   ikbu, ikbv   ! local integers
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   z2dx, z2dy   ! 2D workspace 
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:)   ::   z2dx, z2dy   ! 2D workspace 
       !!----------------------------------------------------------------------
       !
@@ -316,44 +312,44 @@
       ! This total trend is done every time step
       CASE( jptra_tot  )   ;   CALL iom_put( "ttrd_tot" , ptrdx )           ! model total trend
-         CALL iom_put( "strd_tot" , ptrdy )
+                               CALL iom_put( "strd_tot" , ptrdy )
       END SELECT
-
+      !
       ! These trends are done every second time step. When 1ts output is selected must go different (2ts) file from standard T-file
       IF( MOD( kt, 2 ) == 0 ) THEN
          SELECT CASE( ktrd )
-         CASE( jptra_xad  )   ;   CALL iom_put( "ttrd_xad" , ptrdx )        ! x- horizontal advection
-            CALL iom_put( "strd_xad" , ptrdy )
-         CASE( jptra_yad  )   ;   CALL iom_put( "ttrd_yad" , ptrdx )        ! y- horizontal advection
-            CALL iom_put( "strd_yad" , ptrdy )
-         CASE( jptra_zad  )   ;   CALL iom_put( "ttrd_zad" , ptrdx )        ! z- vertical   advection
-            CALL iom_put( "strd_zad" , ptrdy )
-            IF( ln_linssh ) THEN                   ! cst volume : adv flux through z=0 surface
-               CALL wrk_alloc( jpi, jpj, z2dx, z2dy )
-               z2dx(:,:) = wn(:,:,1) * tsn(:,:,1,jp_tem) / e3t_n(:,:,1)
-               z2dy(:,:) = wn(:,:,1) * tsn(:,:,1,jp_sal) / e3t_n(:,:,1)
-               CALL iom_put( "ttrd_sad", z2dx )
-               CALL iom_put( "strd_sad", z2dy )
-               CALL wrk_dealloc( jpi, jpj, z2dx, z2dy )
-            ENDIF
-         CASE( jptra_totad  ) ;   CALL iom_put( "ttrd_totad" , ptrdx )      ! total   advection
-            CALL iom_put( "strd_totad" , ptrdy )
-         CASE( jptra_ldf  )   ;   CALL iom_put( "ttrd_ldf" , ptrdx )        ! lateral diffusion
-            CALL iom_put( "strd_ldf" , ptrdy )
-         CASE( jptra_zdf  )   ;   CALL iom_put( "ttrd_zdf" , ptrdx )        ! vertical diffusion (including Kz contribution)
-            CALL iom_put( "strd_zdf" , ptrdy )
-         CASE( jptra_zdfp )   ;   CALL iom_put( "ttrd_zdfp", ptrdx )        ! PURE vertical diffusion (no isoneutral contribution)
-            CALL iom_put( "strd_zdfp", ptrdy )
-         CASE( jptra_evd )    ;   CALL iom_put( "ttrd_evd", ptrdx )         ! EVD trend (convection)
-            CALL iom_put( "strd_evd", ptrdy )
-         CASE( jptra_dmp  )   ;   CALL iom_put( "ttrd_dmp" , ptrdx )        ! internal restoring (damping)
-            CALL iom_put( "strd_dmp" , ptrdy )
-         CASE( jptra_bbl  )   ;   CALL iom_put( "ttrd_bbl" , ptrdx )        ! bottom boundary layer
-            CALL iom_put( "strd_bbl" , ptrdy )
-         CASE( jptra_npc  )   ;   CALL iom_put( "ttrd_npc" , ptrdx )        ! static instability mixing
-            CALL iom_put( "strd_npc" , ptrdy )
-         CASE( jptra_bbc  )   ;   CALL iom_put( "ttrd_bbc" , ptrdx )        ! geothermal heating   (only on temperature)
-         CASE( jptra_nsr  )   ;   CALL iom_put( "ttrd_qns" , ptrdx(:,:,1) ) ! surface forcing + runoff (ln_rnf=T)
-            CALL iom_put( "strd_cdt" , ptrdy(:,:,1) )        ! output as 2D surface fields
-         CASE( jptra_qsr  )   ;   CALL iom_put( "ttrd_qsr" , ptrdx )        ! penetrative solar radiat. (only on temperature)
+         CASE( jptra_xad  )   ;   CALL iom_put( "ttrd_xad"  , ptrdx )        ! x- horizontal advection
+                                  CALL iom_put( "strd_xad"  , ptrdy )
+         CASE( jptra_yad  )   ;   CALL iom_put( "ttrd_yad"  , ptrdx )        ! y- horizontal advection
+                                  CALL iom_put( "strd_yad"  , ptrdy )
+         CASE( jptra_zad  )   ;   CALL iom_put( "ttrd_zad"  , ptrdx )        ! z- vertical   advection
+                                  CALL iom_put( "strd_zad"  , ptrdy )
+                                  IF( ln_linssh ) THEN                   ! cst volume : adv flux through z=0 surface
+                                     ALLOCATE( z2dx(jpi,jpj), z2dy(jpi,jpj) )
+                                     z2dx(:,:) = wn(:,:,1) * tsn(:,:,1,jp_tem) / e3t_n(:,:,1)
+                                     z2dy(:,:) = wn(:,:,1) * tsn(:,:,1,jp_sal) / e3t_n(:,:,1)
+                                     CALL iom_put( "ttrd_sad", z2dx )
+                                     CALL iom_put( "strd_sad", z2dy )
+                                     DEALLOCATE( z2dx, z2dy )
+                                  ENDIF
+         CASE( jptra_totad  ) ;   CALL iom_put( "ttrd_totad", ptrdx )        ! total   advection
+                                  CALL iom_put( "strd_totad", ptrdy )
+         CASE( jptra_ldf  )   ;   CALL iom_put( "ttrd_ldf"  , ptrdx )        ! lateral diffusion
+                                  CALL iom_put( "strd_ldf"  , ptrdy )
+         CASE( jptra_zdf  )   ;   CALL iom_put( "ttrd_zdf"  , ptrdx )        ! vertical diffusion (including Kz contribution)
+                                  CALL iom_put( "strd_zdf"  , ptrdy )
+         CASE( jptra_zdfp )   ;   CALL iom_put( "ttrd_zdfp" , ptrdx )        ! PURE vertical diffusion (no isoneutral contribution)
+                                  CALL iom_put( "strd_zdfp" , ptrdy )
+         CASE( jptra_evd )    ;   CALL iom_put( "ttrd_evd"  , ptrdx )        ! EVD trend (convection)
+                                  CALL iom_put( "strd_evd"  , ptrdy )
+         CASE( jptra_dmp  )   ;   CALL iom_put( "ttrd_dmp"  , ptrdx )        ! internal restoring (damping)
+                                  CALL iom_put( "strd_dmp"  , ptrdy )
+         CASE( jptra_bbl  )   ;   CALL iom_put( "ttrd_bbl"  , ptrdx )        ! bottom boundary layer
+                                  CALL iom_put( "strd_bbl"  , ptrdy )
+         CASE( jptra_npc  )   ;   CALL iom_put( "ttrd_npc"  , ptrdx )        ! static instability mixing
+                                  CALL iom_put( "strd_npc"  , ptrdy )
+         CASE( jptra_bbc  )   ;   CALL iom_put( "ttrd_bbc"  , ptrdx )        ! geothermal heating   (only on temperature)
+         CASE( jptra_nsr  )   ;   CALL iom_put( "ttrd_qns"  , ptrdx(:,:,1) ) ! surface forcing + runoff (ln_rnf=T)
+                                  CALL iom_put( "strd_cdt"  , ptrdy(:,:,1) )        ! output as 2D surface fields
+         CASE( jptra_qsr  )   ;   CALL iom_put( "ttrd_qsr"  , ptrdx )        ! penetrative solar radiat. (only on temperature)
          END SELECT
          ! the Asselin filter trend  is also every other time step but needs to be lagged one time step
@@ -366,4 +362,51 @@
       END IF
       !
+      ! These trends are done every second time step. When 1ts output is selected must go different (2ts) file from standard T-file
+      IF( MOD( kt, 2 ) == 0 ) THEN
+         SELECT CASE( ktrd )
+         CASE( jptra_xad  )   ;   CALL iom_put( "ttrd_xad"  , ptrdx )         ! x- horizontal advection
+                                  CALL iom_put( "strd_xad"  , ptrdy )
+         CASE( jptra_yad  )   ;   CALL iom_put( "ttrd_yad"  , ptrdx )         ! y- horizontal advection
+                                  CALL iom_put( "strd_yad"  , ptrdy )
+         CASE( jptra_zad  )   ;   CALL iom_put( "ttrd_zad"  , ptrdx )         ! z- vertical   advection
+                                  CALL iom_put( "strd_zad"  , ptrdy )
+                                  IF( ln_linssh ) THEN                   ! cst volume : adv flux through z=0 surface
+                                     ALLOCATE( z2dx(jpi,jpj) , z2dy(jpi,jpj) )
+                                     z2dx(:,:) = wn(:,:,1) * tsn(:,:,1,jp_tem) / e3t_n(:,:,1)
+                                     z2dy(:,:) = wn(:,:,1) * tsn(:,:,1,jp_sal) / e3t_n(:,:,1)
+                                     CALL iom_put( "ttrd_sad", z2dx )
+                                     CALL iom_put( "strd_sad", z2dy )
+                                     DEALLOCATE( z2dx, z2dy )
+                                  ENDIF
+         CASE( jptra_totad  ) ;   CALL iom_put( "ttrd_totad", ptrdx )         ! total   advection
+                                  CALL iom_put( "strd_totad", ptrdy )
+         CASE( jptra_ldf  )   ;   CALL iom_put( "ttrd_ldf"  , ptrdx )         ! lateral diffusion
+                                  CALL iom_put( "strd_ldf"  , ptrdy )
+         CASE( jptra_zdf  )   ;   CALL iom_put( "ttrd_zdf"  , ptrdx )         ! vertical diffusion (including Kz contribution)
+                                  CALL iom_put( "strd_zdf"  , ptrdy )
+         CASE( jptra_zdfp )   ;   CALL iom_put( "ttrd_zdfp" , ptrdx )         ! PURE vertical diffusion (no isoneutral contribution)
+                                  CALL iom_put( "strd_zdfp" , ptrdy )
+         CASE( jptra_evd )    ;   CALL iom_put( "ttrd_evd"  , ptrdx )         ! EVD trend (convection)
+                                  CALL iom_put( "strd_evd"  , ptrdy )
+         CASE( jptra_dmp  )   ;   CALL iom_put( "ttrd_dmp"  , ptrdx )         ! internal restoring (damping)
+                                  CALL iom_put( "strd_dmp"  , ptrdy )
+         CASE( jptra_bbl  )   ;   CALL iom_put( "ttrd_bbl"  , ptrdx )         ! bottom boundary layer
+                                  CALL iom_put( "strd_bbl"  , ptrdy )
+         CASE( jptra_npc  )   ;   CALL iom_put( "ttrd_npc"  , ptrdx )         ! static instability mixing
+                                  CALL iom_put( "strd_npc"  , ptrdy )
+         CASE( jptra_bbc  )   ;   CALL iom_put( "ttrd_bbc"  , ptrdx )         ! geothermal heating   (only on temperature)
+         CASE( jptra_nsr  )   ;   CALL iom_put( "ttrd_qns"  , ptrdx(:,:,1) )  ! surface forcing + runoff (ln_rnf=T)
+                                  CALL iom_put( "strd_cdt"  , ptrdy(:,:,1) )        ! output as 2D surface fields
+         CASE( jptra_qsr  )   ;   CALL iom_put( "ttrd_qsr"  , ptrdx )         ! penetrative solar radiat. (only on temperature)
+         END SELECT
+         ! the Asselin filter trend  is also every other time step but needs to be lagged one time step
+         ! Even when 1ts output is selected can go to the same (2ts) file as the trends plotted every even time step.
+      ELSEIF( MOD( kt, 2 ) == 1 ) THEN
+         SELECT CASE( ktrd )
+         CASE( jptra_atf  )   ;   CALL iom_put( "ttrd_atf" , ptrdx )        ! asselin time Filter
+                                  CALL iom_put( "strd_atf" , ptrdy )
+         END SELECT
+      ENDIF
+      !
    END SUBROUTINE trd_tra_iom
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/USR/usrdef_sbc.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/USR/usrdef_sbc.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/USR/usrdef_sbc.F90	(revision 9019)
@@ -27,6 +27,6 @@
 
    PUBLIC   usrdef_sbc_oce    ! routine called in sbcmod module
-   PUBLIC   usrdef_sbc_ice_tau  ! routine called by sbcice_lim.F90 for ice dynamics
-   PUBLIC   usrdef_sbc_ice_flx  ! routine called by sbcice_lim.F90 for ice thermo
+   PUBLIC   usrdef_sbc_ice_tau  ! routine called by icestp.F90 for ice dynamics
+   PUBLIC   usrdef_sbc_ice_flx  ! routine called by icestp.F90 for ice thermo
 
    !! * Substitutions
@@ -229,6 +229,8 @@
    END SUBROUTINE usrdef_sbc_ice_tau
 
-   SUBROUTINE usrdef_sbc_ice_flx( kt )
+   SUBROUTINE usrdef_sbc_ice_flx( kt, phs, phi )
       INTEGER, INTENT(in) ::   kt   ! ocean time step
+      REAL(wp), DIMENSION(:,:,:), INTENT(in)  ::   phs    ! snow thickness
+      REAL(wp), DIMENSION(:,:,:), INTENT(in)  ::   phi    ! ice thickness
    END SUBROUTINE usrdef_sbc_ice_flx
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdf_oce.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdf_oce.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdf_oce.F90	(revision 9019)
@@ -4,6 +4,7 @@
    !! Ocean physics : define vertical mixing variables
    !!=====================================================================
-   !! history :  1.0  !  2002-06  (G. Madec) Original code
-   !!            3.2  !  2009-07  (G.Madec) addition of avm
+   !! history :  1.0  !  2002-06  (G. Madec)  Original code
+   !!            3.2  !  2009-07  (G. Madec)  addition of avm
+   !!            4.0  !  2017-05  (G. Madec)  avm and drag coef. defined at t-point
    !!----------------------------------------------------------------------
    USE par_oce        ! ocean parameters
@@ -16,38 +17,40 @@
    PUBLIC  zdf_oce_alloc    ! Called in nemogcm.F90
 
-#if defined key_zdfcst
-   LOGICAL, PARAMETER, PUBLIC ::   lk_zdfcst        = .TRUE.         !: constant vertical mixing flag
-#else
-   LOGICAL, PARAMETER, PUBLIC ::   lk_zdfcst        = .FALSE.        !: constant vertical mixing flag
-#endif
-
-   !                                 !!* namelist namzdf: vertical diffusion *
+   !                            !!* namelist namzdf: vertical physics *
+   !                             ! vertical closure scheme flags
+   LOGICAL , PUBLIC ::   ln_zdfcst   !: constant coefficients
+   LOGICAL , PUBLIC ::   ln_zdfric   !: Richardson depend coefficients
+   LOGICAL , PUBLIC ::   ln_zdftke   !: Turbulent Kinetic Energy closure
+   LOGICAL , PUBLIC ::   ln_zdfgls   !: Generic Length Scale closure
+   LOGICAL , PUBLIC ::   ln_zdfosm   !: OSMOSIS BL closure
+   !                             ! convection
+   LOGICAL , PUBLIC ::   ln_zdfevd   !: convection: enhanced vertical diffusion flag
+   INTEGER , PUBLIC ::      nn_evdm     !: =0/1 flag to apply enhanced avm or not
+   REAL(wp), PUBLIC ::      rn_evd      !: vertical eddy coeff. for enhanced vert. diff. (m2/s)
+   LOGICAL , PUBLIC ::   ln_zdfnpc   !: convection: non-penetrative convection flag
+   INTEGER , PUBLIC ::      nn_npc      !: non penetrative convective scheme call  frequency
+   INTEGER , PUBLIC ::      nn_npcp     !: non penetrative convective scheme print frequency
+   !                             ! double diffusion
+   LOGICAL , PUBLIC ::   ln_zdfddm   !: double diffusive mixing flag
+   REAL(wp), PUBLIC ::      rn_avts     !: maximum value of avs for salt fingering
+   REAL(wp), PUBLIC ::      rn_hsbfr    !: heat/salt buoyancy flux ratio
+   !                             ! gravity wave-induced vertical mixing
+   LOGICAL , PUBLIC ::   ln_zdfswm   !: surface  wave-induced mixing flag
+   LOGICAL , PUBLIC ::   ln_zdfiwm   !: internal wave-induced mixing flag
+   !                             ! coefficients 
    REAL(wp), PUBLIC ::   rn_avm0     !: vertical eddy viscosity (m2/s)
    REAL(wp), PUBLIC ::   rn_avt0     !: vertical eddy diffusivity (m2/s)
    INTEGER , PUBLIC ::   nn_avb      !: constant or profile background on avt (=0/1)
-   INTEGER , PUBLIC ::   nn_havtb    !: horizontal shape or not for avtb (=0/1)
-   LOGICAL , PUBLIC ::   ln_zdfexp   !: explicit vertical diffusion scheme flag
-   INTEGER , PUBLIC ::   nn_zdfexp   !: number of sub-time step (explicit time stepping)
-   LOGICAL , PUBLIC ::   ln_zdfevd   !: convection: enhanced vertical diffusion flag
-   INTEGER , PUBLIC ::   nn_evdm     !: =0/1 flag to apply enhanced avm or not
-   REAL(wp), PUBLIC ::   rn_avevd    !: vertical eddy coeff. for enhanced vert. diff. (m2/s)
-   LOGICAL , PUBLIC ::   ln_zdfnpc   !: convection: non-penetrative convection flag
-   INTEGER , PUBLIC ::   nn_npc      !: non penetrative convective scheme call  frequency
-   INTEGER , PUBLIC ::   nn_npcp     !: non penetrative convective scheme print frequency
-   LOGICAL , PUBLIC ::   ln_zdfqiao  !: Enhanced wave vertical mixing Qiao(2010) formulation flag
+   INTEGER , PUBLIC ::   nn_havtb    !: horizontal shape or not for avtb (=0/1)   !                             ! convection
 
 
-   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:)     ::   avmb , avtb    !: background profile of avm and avt
-   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:)   ::   avtb_2d        !: horizontal shape of background Kz profile
-   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:)   ::   bfrua, bfrva   !: Bottom friction coefficients set in zdfbfr
-   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:)   ::   tfrua, tfrva   !: top friction coefficients set in zdfbfr
-   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   avmu , avmv    !: vertical viscosity coef at uw- & vw-pts       [m2/s]
-   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   avm  , avt     !: vertical viscosity & diffusivity coef at w-pt [m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   avt_k , avm_k  ! not enhanced Kz
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   avmu_k, avmv_k ! not enhanced Kz
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   en              !: now turbulent kinetic energy   [m2/s2]
+   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   avm, avt, avs  !: vertical mixing coefficients (w-point) [m2/s]
+   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   avm_k , avt_k  !: Kz computed by turbulent closure alone [m2/s]
+   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   en             !: now turbulent kinetic energy          [m2/s2]
+   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:)     ::   avmb , avtb    !: background profile of avm and avt      [m2/s]
+   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:)   ::   avtb_2d        !: horizontal shape of background Kz profile [-]
 
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -60,12 +63,7 @@
       !!----------------------------------------------------------------------
       !
-      ALLOCATE(avmb(jpk) , bfrua(jpi,jpj) ,                         &
-         &     avtb(jpk) , bfrva(jpi,jpj) , avtb_2d(jpi,jpj) ,      &
-         &     tfrua(jpi, jpj), tfrva(jpi, jpj)              ,      &
-         &     avmu  (jpi,jpj,jpk), avm   (jpi,jpj,jpk)      ,      &
-         &     avmv  (jpi,jpj,jpk), avt   (jpi,jpj,jpk)      ,      &
-         &     avt_k (jpi,jpj,jpk), avm_k (jpi,jpj,jpk)      ,      & 
-         &     avmu_k(jpi,jpj,jpk), avmv_k(jpi,jpj,jpk)      ,      &
-         &     en    (jpi,jpj,jpk), STAT = zdf_oce_alloc )
+      ALLOCATE( avm (jpi,jpj,jpk) , avm_k(jpi,jpj,jpk) , avs(jpi,jpj,jpk) ,   &
+         &      avt (jpi,jpj,jpk) , avt_k(jpi,jpj,jpk) , en (jpi,jpj,jpk) ,   & 
+         &      avmb(jpk)         , avtb(jpk)          , avtb_2d(jpi,jpj) , STAT = zdf_oce_alloc )
          !
       IF( zdf_oce_alloc /= 0 )   CALL ctl_warn('zdf_oce_alloc: failed to allocate arrays')
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfbfr.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfbfr.F90	(revision 9018)
+++ 	(revision )
@@ -1,490 +1,0 @@
-MODULE zdfbfr
-   !!======================================================================
-   !!                       ***  MODULE  zdfbfr  ***
-   !! Ocean physics: Bottom friction
-   !!======================================================================
-   !! History :  OPA  ! 1997-06  (G. Madec, A.-M. Treguier)  Original code
-   !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
-   !!            3.2  ! 2009-09  (A.C.Coward)  Correction to include barotropic contribution
-   !!            3.3  ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
-   !!            3.4  ! 2011-11  (H. Liu) implementation of semi-implicit bottom friction option
-   !!                 ! 2012-06  (H. Liu) implementation of Log Layer bottom friction option
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   zdf_bfr      : update bottom friction coefficient (non-linear bottom friction only)
-   !!   zdf_bfr_init : read in namelist and control the bottom friction parameters.
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain variables
-   USE zdf_oce         ! ocean vertical physics variables
-   USE in_out_manager  ! I/O manager
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp         ! distributed memory computing
-   USE prtctl          ! Print control
-   USE timing          ! Timing
-   USE wrk_nemo        ! Memory Allocation
-   USE phycst, ONLY: vkarmn
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   zdf_bfr         ! called by step.F90
-   PUBLIC   zdf_bfr_init    ! called by nemogcm.F90
-
-   !                                 !!* Namelist nambfr: bottom friction namelist *
-   INTEGER , PUBLIC ::   nn_bfr       ! = 0/1/2/3 type of bottom friction  (PUBLIC for TAM)
-   REAL(wp), PUBLIC ::   rn_bfri1     ! bottom drag coefficient (linear case)  (PUBLIC for TAM)
-   REAL(wp), PUBLIC ::   rn_bfri2     ! bottom drag coefficient (non linear case) (PUBLIC for TAM)
-   REAL(wp), PUBLIC ::   rn_bfri2_max ! Maximum bottom drag coefficient (non linear case and ln_loglayer=T) (PUBLIC for TAM)
-   REAL(wp), PUBLIC ::   rn_bfeb2     ! background bottom turbulent kinetic energy  [m2/s2] (PUBLIC for TAM)
-   REAL(wp), PUBLIC ::   rn_bfrien    ! local factor to enhance coefficient bfri (PUBLIC for TAM)
-   LOGICAL , PUBLIC ::   ln_bfr2d     ! logical switch for 2D enhancement (PUBLIC for TAM)
-   REAL(wp), PUBLIC ::   rn_tfri1     ! top drag coefficient (linear case)  (PUBLIC for TAM)
-   REAL(wp), PUBLIC ::   rn_tfri2     ! top drag coefficient (non linear case) (PUBLIC for TAM)
-   REAL(wp), PUBLIC ::   rn_tfri2_max ! Maximum top drag coefficient (non linear case and ln_loglayer=T) (PUBLIC for TAM)
-   REAL(wp), PUBLIC ::   rn_tfeb2     ! background top turbulent kinetic energy  [m2/s2] (PUBLIC for TAM)
-   REAL(wp), PUBLIC ::   rn_tfrien    ! local factor to enhance coefficient tfri (PUBLIC for TAM)
-   LOGICAL , PUBLIC ::   ln_tfr2d     ! logical switch for 2D enhancement (PUBLIC for TAM)
-
-   LOGICAL , PUBLIC ::   ln_loglayer  ! switch for log layer bfr coeff. (PUBLIC for TAM)
-   REAL(wp), PUBLIC ::   rn_bfrz0     ! bottom roughness for loglayer bfr coeff (PUBLIC for TAM)
-   REAL(wp), PUBLIC ::   rn_tfrz0     ! bottom roughness for loglayer bfr coeff (PUBLIC for TAM)
-   LOGICAL , PUBLIC ::   ln_bfrimp    ! logical switch for implicit bottom friction
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:), PUBLIC ::  bfrcoef2d, tfrcoef2d   ! 2D bottom/top drag coefficient (PUBLIC for TAM)
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION zdf_bfr_alloc()
-      !!----------------------------------------------------------------------
-      !!                ***  FUNCTION zdf_bfr_alloc  ***
-      !!----------------------------------------------------------------------
-      ALLOCATE( bfrcoef2d(jpi,jpj), tfrcoef2d(jpi,jpj), STAT=zdf_bfr_alloc )
-      !
-      IF( lk_mpp             )   CALL mpp_sum ( zdf_bfr_alloc )
-      IF( zdf_bfr_alloc /= 0 )   CALL ctl_warn('zdf_bfr_alloc: failed to allocate arrays.')
-   END FUNCTION zdf_bfr_alloc
-
-
-   SUBROUTINE zdf_bfr( kt )
-      !!----------------------------------------------------------------------
-      !!                   ***  ROUTINE zdf_bfr  ***
-      !!
-      !! ** Purpose :   compute the bottom friction coefficient.
-      !!
-      !! ** Method  :   Calculate and store part of the momentum trend due
-      !!              to bottom friction following the chosen friction type
-      !!              (free-slip, linear, or quadratic). The component
-      !!              calculated here is multiplied by the bottom velocity in
-      !!              dyn_bfr to provide the trend term.
-      !!                The coefficients are updated at each time step only
-      !!              in the quadratic case.
-      !!
-      !! ** Action  :   bfrua , bfrva   bottom friction coefficients
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
-      !!
-      INTEGER  ::   ji, jj                       ! dummy loop indices
-      INTEGER  ::   ikbt, ikbu, ikbv             ! local integers
-      REAL(wp) ::   zvu, zuv, zecu, zecv, ztmp   ! temporary scalars
-      REAL(wp), POINTER, DIMENSION(:,:) ::  zbfrt, ztfrt
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('zdf_bfr')
-      !
-      IF( nn_bfr == 2 ) THEN                 ! quadratic bottom friction only
-         !
-         CALL wrk_alloc( jpi, jpj, zbfrt, ztfrt )
-
-         IF ( ln_loglayer.AND. .NOT.ln_linssh ) THEN ! "log layer" bottom friction coefficient
-
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  ikbt = mbkt(ji,jj)
-!! JC: possible WAD implementation should modify line below if layers vanish
-                  ztmp = tmask(ji,jj,ikbt) * ( vkarmn / LOG( 0.5_wp * e3t_n(ji,jj,ikbt) / rn_bfrz0 ))**2._wp
-                  zbfrt(ji,jj) = MAX(bfrcoef2d(ji,jj), ztmp)
-                  zbfrt(ji,jj) = MIN(zbfrt(ji,jj), rn_bfri2_max)
-               END DO
-            END DO
-! (ISF)
-            IF ( ln_isfcav ) THEN
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     ikbt = mikt(ji,jj)
-! JC: possible WAD implementation should modify line below if layers vanish
-                     ztmp = (1.-tmask(ji,jj,1)) * ( vkarmn / LOG( 0.5_wp * e3t_n(ji,jj,ikbt) / rn_bfrz0 ))**2._wp
-                     ztfrt(ji,jj) = MAX(tfrcoef2d(ji,jj), ztmp)
-                     ztfrt(ji,jj) = MIN(ztfrt(ji,jj), rn_tfri2_max)
-                  END DO
-               END DO
-            END IF
-            !   
-         ELSE
-            zbfrt(:,:) = bfrcoef2d(:,:)
-            ztfrt(:,:) = tfrcoef2d(:,:)
-         ENDIF
-
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1
-               ikbu = mbku(ji,jj)         ! ocean bottom level at u- and v-points
-               ikbv = mbkv(ji,jj)         ! (deepest ocean u- and v-points)
-               !
-               zvu  = 0.25 * (  vn(ji,jj  ,ikbu) + vn(ji+1,jj  ,ikbu)     &
-                  &           + vn(ji,jj-1,ikbu) + vn(ji+1,jj-1,ikbu)  )
-               zuv  = 0.25 * (  un(ji,jj  ,ikbv) + un(ji-1,jj  ,ikbv)     &
-                  &           + un(ji,jj+1,ikbv) + un(ji-1,jj+1,ikbv)  )
-               !
-               zecu = SQRT(  un(ji,jj,ikbu) * un(ji,jj,ikbu) + zvu*zvu + rn_bfeb2  )
-               zecv = SQRT(  vn(ji,jj,ikbv) * vn(ji,jj,ikbv) + zuv*zuv + rn_bfeb2  )
-               !
-               bfrua(ji,jj) = - 0.5_wp * ( zbfrt(ji,jj) + zbfrt(ji+1,jj  ) ) * zecu
-               bfrva(ji,jj) = - 0.5_wp * ( zbfrt(ji,jj) + zbfrt(ji  ,jj+1) ) * zecv
-               !
-               ! in case of 2 cell water column, we assume each cell feels the top and bottom friction
-               IF ( ln_isfcav ) THEN
-                  IF ( miku(ji,jj) + 1  >=  mbku(ji,jj) ) THEN
-                     bfrua(ji,jj) = - 0.5_wp * ( ( zbfrt(ji,jj) + zbfrt(ji+1,jj  ) )   &
-                                  &            + ( ztfrt(ji,jj) + ztfrt(ji+1,jj  ) ) ) &
-                                  &          * zecu * (1._wp - umask(ji,jj,1))
-                  ENDIF
-                  IF( mikv(ji,jj) + 1  >=  mbkv(ji,jj) ) THEN
-                     bfrva(ji,jj) = - 0.5_wp * ( ( zbfrt(ji,jj) + zbfrt(ji  ,jj+1) )   &
-                                  &            + ( ztfrt(ji,jj) + ztfrt(ji  ,jj+1) ) ) &
-                                  &          * zecv * (1._wp - vmask(ji,jj,1))
-                  ENDIF
-               ENDIF
-            END DO
-         END DO
-         CALL lbc_lnk( bfrua, 'U', 1. )   ;   CALL lbc_lnk( bfrva, 'V', 1. )      ! Lateral boundary condition
-
-         IF( ln_isfcav ) THEN
-            DO jj = 2, jpjm1
-               DO ji = 2, jpim1
-                  ! (ISF) ========================================================================
-                  ikbu = miku(ji,jj)         ! ocean top level at u- and v-points 
-                  ikbv = mikv(ji,jj)         ! (1st wet ocean u- and v-points)
-                  !
-                  zvu  = 0.25 * (  vn(ji,jj  ,ikbu) + vn(ji+1,jj  ,ikbu)     &
-                     &           + vn(ji,jj-1,ikbu) + vn(ji+1,jj-1,ikbu)  )
-                  zuv  = 0.25 * (  un(ji,jj  ,ikbv) + un(ji-1,jj  ,ikbv)     &
-                     &           + un(ji,jj+1,ikbv) + un(ji-1,jj+1,ikbv)  )
-              !
-                  zecu = SQRT(  un(ji,jj,ikbu) * un(ji,jj,ikbu) + zvu*zvu + rn_tfeb2 )
-                  zecv = SQRT(  vn(ji,jj,ikbv) * vn(ji,jj,ikbv) + zuv*zuv + rn_tfeb2 )
-              !
-                  tfrua(ji,jj) = - 0.5_wp * ( ztfrt(ji,jj) + ztfrt(ji+1,jj  ) ) * zecu * (1._wp - umask(ji,jj,1))
-                  tfrva(ji,jj) = - 0.5_wp * ( ztfrt(ji,jj) + ztfrt(ji  ,jj+1) ) * zecv * (1._wp - vmask(ji,jj,1))
-              ! (ISF) END ====================================================================
-              ! in case of 2 cell water column, we assume each cell feels the top and bottom friction
-                  IF ( miku(ji,jj) + 1 .GE. mbku(ji,jj) ) THEN
-                     tfrua(ji,jj) = - 0.5_wp * ( ( ztfrt(ji,jj) + ztfrt(ji+1,jj  ) )   &
-                                  &            + ( zbfrt(ji,jj) + zbfrt(ji+1,jj  ) ) ) &
-                                  &          * zecu * (1._wp - umask(ji,jj,1))
-                  END IF
-                  IF ( mikv(ji,jj) + 1 .GE. mbkv(ji,jj) ) THEN
-                     tfrva(ji,jj) = - 0.5_wp * ( ( ztfrt(ji,jj) + ztfrt(ji  ,jj+1) )   &
-                                  &            + ( zbfrt(ji,jj) + zbfrt(ji  ,jj+1) ) ) &
-                                  &          * zecv * (1._wp - vmask(ji,jj,1))
-                  END IF
-               END DO
-            END DO
-            CALL lbc_lnk( tfrua, 'U', 1. )   ;   CALL lbc_lnk( tfrva, 'V', 1. )      ! Lateral boundary condition
-         END IF
-         !
-         !
-         IF(ln_ctl)   CALL prt_ctl( tab2d_1=bfrua, clinfo1=' bfr  - u: ', mask1=umask,        &
-            &                       tab2d_2=bfrva, clinfo2=       ' v: ', mask2=vmask,ovlap=1 )
-         CALL wrk_dealloc( jpi,jpj,zbfrt, ztfrt )
-      ENDIF
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('zdf_bfr')
-      !
-   END SUBROUTINE zdf_bfr
-
-
-   SUBROUTINE zdf_bfr_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE zdf_bfr_init  ***
-      !!
-      !! ** Purpose :   Initialization of the bottom friction
-      !!
-      !! ** Method  :   Read the nambfr namelist and check their consistency
-      !!                called at the first timestep (nit000)
-      !!----------------------------------------------------------------------
-      USE iom   ! I/O module for ehanced bottom friction file
-      !!
-      INTEGER   ::   inum         ! logical unit for enhanced bottom friction file
-      INTEGER   ::   ji, jj       ! dummy loop indexes
-      INTEGER   ::   ikbt, ikbu, ikbv   ! temporary integers
-      INTEGER   ::   ictu, ictv         !    -          -
-      INTEGER   ::   ios
-      REAL(wp)  ::   zminbfr, zmaxbfr   ! temporary scalars
-      REAL(wp)  ::   zmintfr, zmaxtfr   ! temporary scalars
-      REAL(wp)  ::   ztmp, zfru, zfrv   !    -         -
-      !!
-      NAMELIST/nambfr/ nn_bfr, rn_bfri1, rn_bfri2, rn_bfri2_max, rn_bfeb2, rn_bfrz0, ln_bfr2d, &
-                    &          rn_tfri1, rn_tfri2, rn_tfri2_max, rn_tfeb2, rn_tfrz0, ln_tfr2d, &
-                    &  rn_bfrien, rn_tfrien, ln_bfrimp, ln_loglayer
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('zdf_bfr_init')
-      !
-      !                              !* Allocate zdfbfr arrays
-      IF( zdf_bfr_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_bfr_init : unable to allocate arrays' )
-      !
-      !                              !* Parameter control and print
-      !
-      REWIND( numnam_ref )              ! Namelist nambfr in reference namelist : Bottom momentum boundary condition
-      READ  ( numnam_ref, nambfr, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambfr in reference namelist', lwp )
-
-      REWIND( numnam_cfg )              ! Namelist nambfr in configuration namelist : Bottom momentum boundary condition
-      READ  ( numnam_cfg, nambfr, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambfr in configuration namelist', lwp )
-      IF(lwm) WRITE ( numond, nambfr )
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'zdf_bfr_init : momentum bottom friction'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
-      IF(lwp) WRITE(numout,*) '   Namelist nam_bfr : set bottom friction parameters'
-      !
-      SELECT CASE (nn_bfr)
-      !
-      CASE( 0 )
-         IF(lwp) WRITE(numout,*) '      free-slip '
-         bfrua(:,:) = 0._wp
-         bfrva(:,:) = 0._wp
-         tfrua(:,:) = 0._wp
-         tfrva(:,:) = 0._wp
-         !
-      CASE( 1 )
-         IF(lwp) WRITE(numout,*) '      linear botton friction'
-         IF(lwp) WRITE(numout,*) '      bottom friction coef.   rn_bfri1  = ', rn_bfri1
-         IF( ln_bfr2d ) THEN
-            IF(lwp) WRITE(numout,*) '      read coef. enhancement distribution from file   ln_bfr2d  = ', ln_bfr2d
-            IF(lwp) WRITE(numout,*) '      coef rn_bfri2 enhancement factor                rn_bfrien  = ',rn_bfrien
-         ENDIF
-         IF ( ln_isfcav ) THEN
-            IF(lwp) WRITE(numout,*) '      top    friction coef.   rn_bfri1  = ', rn_tfri1
-            IF( ln_tfr2d ) THEN
-               IF(lwp) WRITE(numout,*) '      read coef. enhancement distribution from file   ln_tfr2d  = ', ln_tfr2d
-               IF(lwp) WRITE(numout,*) '      coef rn_tfri2 enhancement factor                rn_tfrien  = ',rn_tfrien
-            ENDIF
-         END IF
-         !
-         IF(ln_bfr2d) THEN
-            ! bfr_coef is a coefficient in [0,1] giving the mask where to apply the bfr enhancement
-            CALL iom_open('bfr_coef.nc',inum)
-            CALL iom_get (inum, jpdom_data, 'bfr_coef',bfrcoef2d,1) ! bfrcoef2d is used as tmp array
-            CALL iom_close(inum)
-            bfrcoef2d(:,:) = rn_bfri1 * ( 1 + rn_bfrien * bfrcoef2d(:,:) )
-         ELSE
-            bfrcoef2d(:,:) = rn_bfri1  ! initialize bfrcoef2d to the namelist variable
-         ENDIF
-         !
-         bfrua(:,:) = - bfrcoef2d(:,:)
-         bfrva(:,:) = - bfrcoef2d(:,:)
-         !
-         IF ( ln_isfcav ) THEN
-            IF(ln_tfr2d) THEN
-               ! tfr_coef is a coefficient in [0,1] giving the mask where to apply the bfr enhancement
-               CALL iom_open('tfr_coef.nc',inum)
-               CALL iom_get (inum, jpdom_data, 'tfr_coef',tfrcoef2d,1) ! tfrcoef2d is used as tmp array
-               CALL iom_close(inum)
-               tfrcoef2d(:,:) = rn_tfri1 * ( 1 + rn_tfrien * tfrcoef2d(:,:) )
-            ELSE
-               tfrcoef2d(:,:) = rn_tfri1  ! initialize tfrcoef2d to the namelist variable
-            ENDIF
-            !
-            tfrua(:,:) = - tfrcoef2d(:,:)
-            tfrva(:,:) = - tfrcoef2d(:,:)
-         END IF
-         !
-      CASE( 2 )
-         IF(lwp) WRITE(numout,*) '      quadratic bottom friction'
-         IF(lwp) WRITE(numout,*) '      friction coef.   rn_bfri2  = ', rn_bfri2
-         IF(lwp) WRITE(numout,*) '      Max. coef. (log case)   rn_bfri2_max  = ', rn_bfri2_max
-         IF(lwp) WRITE(numout,*) '      background tke   rn_bfeb2  = ', rn_bfeb2
-         IF(lwp) WRITE(numout,*) '      log formulation   ln_bfr2d = ', ln_loglayer
-         IF(lwp) WRITE(numout,*) '      bottom roughness  rn_bfrz0 [m] = ', rn_bfrz0
-         IF( rn_bfrz0 <= 0._wp ) THEN
-            WRITE(ctmp1,*) '      bottom roughness must be strictly positive'
-            CALL ctl_stop( ctmp1 )
-         ENDIF
-         IF( ln_bfr2d ) THEN
-            IF(lwp) WRITE(numout,*) '      read coef. enhancement distribution from file   ln_bfr2d  = ', ln_bfr2d
-            IF(lwp) WRITE(numout,*) '      coef rn_bfri2 enhancement factor                rn_bfrien  = ',rn_bfrien
-         ENDIF
-         IF ( ln_isfcav ) THEN
-            IF(lwp) WRITE(numout,*) '      quadratic top    friction'
-            IF(lwp) WRITE(numout,*) '      friction coef.    rn_tfri2     = ', rn_tfri2
-            IF(lwp) WRITE(numout,*) '      Max. coef. (log case)   rn_tfri2_max  = ', rn_tfri2_max
-            IF(lwp) WRITE(numout,*) '      background tke    rn_tfeb2     = ', rn_tfeb2
-            IF(lwp) WRITE(numout,*) '      log formulation   ln_tfr2d     = ', ln_loglayer
-            IF(lwp) WRITE(numout,*) '      top roughness     rn_tfrz0 [m] = ', rn_tfrz0
-            IF( rn_tfrz0 <= 0._wp ) THEN
-               WRITE(ctmp1,*) '      top roughness must be strictly positive'
-               CALL ctl_stop( ctmp1 )
-            ENDIF
-            IF( ln_tfr2d ) THEN
-               IF(lwp) WRITE(numout,*) '      read coef. enhancement distribution from file   ln_tfr2d  = ', ln_tfr2d
-               IF(lwp) WRITE(numout,*) '      coef rn_tfri2 enhancement factor                rn_tfrien  = ',rn_tfrien
-            ENDIF
-         END IF
-         !
-         IF(ln_bfr2d) THEN
-            ! bfr_coef is a coefficient in [0,1] giving the mask where to apply the bfr enhancement
-            CALL iom_open('bfr_coef.nc',inum)
-            CALL iom_get (inum, jpdom_data, 'bfr_coef',bfrcoef2d,1) ! bfrcoef2d is used as tmp array
-            CALL iom_close(inum)
-            !
-            bfrcoef2d(:,:) = rn_bfri2 * ( 1 + rn_bfrien * bfrcoef2d(:,:) )
-         ELSE
-            bfrcoef2d(:,:) = rn_bfri2  ! initialize bfrcoef2d to the namelist variable
-         ENDIF
-         
-         IF ( ln_isfcav ) THEN
-            IF(ln_tfr2d) THEN
-               ! tfr_coef is a coefficient in [0,1] giving the mask where to apply the bfr enhancement
-               CALL iom_open('tfr_coef.nc',inum)
-               CALL iom_get (inum, jpdom_data, 'tfr_coef',tfrcoef2d,1) ! tfrcoef2d is used as tmp array
-               CALL iom_close(inum)
-               !
-               tfrcoef2d(:,:) = rn_tfri2 * ( 1 + rn_tfrien * tfrcoef2d(:,:) )
-            ELSE
-               tfrcoef2d(:,:) = rn_tfri2  ! initialize tfrcoef2d to the namelist variable
-            ENDIF
-         END IF
-         !
-         IF( ln_loglayer.AND. ln_linssh ) THEN ! set "log layer" bottom friction once for all
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  ikbt = mbkt(ji,jj)
-                  ztmp = tmask(ji,jj,ikbt) * ( vkarmn / LOG( 0.5_wp * e3t_n(ji,jj,ikbt) / rn_bfrz0 ))**2._wp
-                  bfrcoef2d(ji,jj) = MAX(bfrcoef2d(ji,jj), ztmp)
-                  bfrcoef2d(ji,jj) = MIN(bfrcoef2d(ji,jj), rn_bfri2_max)
-               END DO
-            END DO
-            IF ( ln_isfcav ) THEN
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     ikbt = mikt(ji,jj)
-                     ztmp = tmask(ji,jj,ikbt) * ( vkarmn / LOG( 0.5_wp * e3t_n(ji,jj,ikbt) / rn_tfrz0 ))**2._wp
-                     tfrcoef2d(ji,jj) = MAX(tfrcoef2d(ji,jj), ztmp)
-                     tfrcoef2d(ji,jj) = MIN(tfrcoef2d(ji,jj), rn_tfri2_max)
-                  END DO
-               END DO
-            END IF
-         ENDIF
-         !
-         bfrua(:,:) = - bfrcoef2d(:,:)
-         bfrva(:,:) = - bfrcoef2d(:,:)
-         !
-         !
-      CASE DEFAULT
-         IF(lwp) WRITE(ctmp1,*) '         bad flag value for nn_bfr = ', nn_bfr
-         CALL ctl_stop( ctmp1 )
-         !
-      END SELECT
-      !
-      IF(lwp) WRITE(numout,*) '      implicit bottom friction switch                ln_bfrimp  = ', ln_bfrimp
-      !
-      !                              ! Make sure ln_zdfexp=.false. when use implicit bfr
-      IF( ln_bfrimp .AND. ln_zdfexp ) THEN
-         IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) 'Implicit bottom friction can only be used when ln_zdfexp=.false.'
-            WRITE(numout,*) '         but you set: ln_bfrimp=.true. and ln_zdfexp=.true.!!!!'
-            WRITE(ctmp1,*)  '         set either ln_zdfexp = .false or ln_bfrimp = .false.'
-            CALL ctl_stop( ctmp1 )
-         END IF
-      END IF
-      !
-      ! Basic stability check on bottom friction coefficient
-      !
-      ictu = 0               ! counter for stability criterion breaches at U-pts
-      ictv = 0               ! counter for stability criterion breaches at V-pts
-      zminbfr =  1.e10_wp    ! initialise tracker for minimum of bottom friction coefficient
-      zmaxbfr = -1.e10_wp    ! initialise tracker for maximum of bottom friction coefficient
-      zmintfr =  1.e10_wp    ! initialise tracker for minimum of bottom friction coefficient
-      zmaxtfr = -1.e10_wp    ! initialise tracker for maximum of bottom friction coefficient
-      !
-      DO jj = 2, jpjm1
-         DO ji = 2, jpim1
-             ikbu = mbku(ji,jj)       ! deepest ocean level at u- and v-points
-             ikbv = mbkv(ji,jj)
-             zfru = 0.5 * e3u_n(ji,jj,ikbu) / rdt
-             zfrv = 0.5 * e3v_n(ji,jj,ikbv) / rdt
-             IF( ABS( bfrcoef2d(ji,jj) ) > zfru ) THEN
-                IF( ln_ctl ) THEN
-                   WRITE(numout,*) 'BFR ', narea, nimpp+ji, njmpp+jj, ikbu
-                   WRITE(numout,*) 'BFR ', ABS( bfrcoef2d(ji,jj) ), zfru
-                ENDIF
-                ictu = ictu + 1
-             ENDIF
-             IF( ABS( bfrcoef2d(ji,jj) ) > zfrv ) THEN
-                 IF( ln_ctl ) THEN
-                     WRITE(numout,*) 'BFR ', narea, nimpp+ji, njmpp+jj, ikbv
-                     WRITE(numout,*) 'BFR ', bfrcoef2d(ji,jj), zfrv
-                 ENDIF
-                 ictv = ictv + 1
-             ENDIF
-             zminbfr = MIN(  zminbfr, MIN( zfru, ABS( bfrcoef2d(ji,jj) ) )  )
-             zmaxbfr = MAX(  zmaxbfr, MIN( zfrv, ABS( bfrcoef2d(ji,jj) ) )  )
-! (ISF)
-             IF ( ln_isfcav ) THEN
-                ikbu = miku(ji,jj)       ! 1st wet ocean level at u- and v-points
-                ikbv = mikv(ji,jj)
-                zfru = 0.5 * e3u_n(ji,jj,ikbu) / rdt
-                zfrv = 0.5 * e3v_n(ji,jj,ikbv) / rdt
-                IF( ABS( tfrcoef2d(ji,jj) ) > zfru ) THEN
-                   IF( ln_ctl ) THEN
-                      WRITE(numout,*) 'TFR ', narea, nimpp+ji, njmpp+jj, ikbu
-                      WRITE(numout,*) 'TFR ', ABS( tfrcoef2d(ji,jj) ), zfru
-                   ENDIF
-                   ictu = ictu + 1
-                ENDIF
-                IF( ABS( tfrcoef2d(ji,jj) ) > zfrv ) THEN
-                   IF( ln_ctl ) THEN
-                      WRITE(numout,*) 'TFR ', narea, nimpp+ji, njmpp+jj, ikbv
-                      WRITE(numout,*) 'TFR ', tfrcoef2d(ji,jj), zfrv
-                   ENDIF
-                   ictv = ictv + 1
-                ENDIF
-                zmintfr = MIN(  zmintfr, MIN( zfru, ABS( tfrcoef2d(ji,jj) ) )  )
-                zmaxtfr = MAX(  zmaxtfr, MIN( zfrv, ABS( tfrcoef2d(ji,jj) ) )  )
-             END IF
-! END ISF
-         END DO
-      END DO
-      IF( lk_mpp ) THEN
-         CALL mpp_sum( ictu )
-         CALL mpp_sum( ictv )
-         CALL mpp_min( zminbfr )
-         CALL mpp_max( zmaxbfr )
-         IF ( ln_isfcav) CALL mpp_min( zmintfr )
-         IF ( ln_isfcav) CALL mpp_max( zmaxtfr )
-      ENDIF
-      IF( .NOT.ln_bfrimp) THEN
-      IF( lwp .AND. ictu + ictv > 0 ) THEN
-         WRITE(numout,*) ' Bottom/Top friction stability check failed at ', ictu, ' U-points '
-         WRITE(numout,*) ' Bottom/Top friction stability check failed at ', ictv, ' V-points '
-         WRITE(numout,*) ' Bottom friction coefficient now ranges from: ', zminbfr, ' to ', zmaxbfr
-         IF ( ln_isfcav ) WRITE(numout,*) ' Top friction coefficient now ranges from: ', zmintfr, ' to ', zmaxtfr
-         WRITE(numout,*) ' Bottom/Top friction coefficient will be reduced where necessary'
-      ENDIF
-      ENDIF
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('zdf_bfr_init')
-      !
-   END SUBROUTINE zdf_bfr_init
-
-   !!======================================================================
-END MODULE zdfbfr
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfddm.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfddm.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfddm.F90	(revision 9019)
@@ -8,23 +8,20 @@
    !!            3.3  ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
    !!            3.6  ! 2013-04  (G. Madec, F. Roquet) zrau compute locally using interpolation of alpha & beta
+   !!            4.0  !  2017-04  (G. Madec)  remove CPP ddm key & avm at t-point only 
    !!----------------------------------------------------------------------
-#if defined key_zdfddm
+
    !!----------------------------------------------------------------------
-   !!   'key_zdfddm' :                                     double diffusion
+   !!   zdf_ddm       : compute the Kz for salinity
    !!----------------------------------------------------------------------
-   !!   zdf_ddm       : compute the Ks for salinity
-   !!   zdf_ddm_init  : read namelist and control the parameters
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain variables 
-   USE zdf_oce         ! ocean vertical physics variables
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain variables
+   USE zdf_oce        ! ocean vertical physics variables
    USE eosbn2         ! equation of state
    !
-   USE in_out_manager  ! I/O manager
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE prtctl          ! Print control
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! work arrays
-   USE timing          ! Timing
+   USE in_out_manager ! I/O manager
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl         ! Print control
+   USE lib_mpp        ! MPP library
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -32,14 +29,4 @@
 
    PUBLIC   zdf_ddm       ! called by step.F90
-   PUBLIC   zdf_ddm_init  ! called by opa.F90
-   PUBLIC   zdf_ddm_alloc ! called by nemogcm.F90
-
-   LOGICAL , PUBLIC, PARAMETER ::   lk_zdfddm = .TRUE.  !: double diffusive mixing flag
-
-   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   avs   !: salinity vertical diffusivity coeff. at w-point
-
-   !                       !!* Namelist namzdf_ddm : double diffusive mixing *
-   REAL(wp) ::   rn_avts    ! maximum value of avs for salt fingering
-   REAL(wp) ::   rn_hsbfr   ! heat/salt buoyancy flux ratio
 
    !! * Substitutions
@@ -52,15 +39,5 @@
 CONTAINS
 
-   INTEGER FUNCTION zdf_ddm_alloc()
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE zdf_ddm_alloc  ***
-      !!----------------------------------------------------------------------
-      ALLOCATE( avs(jpi,jpj,jpk) , STAT= zdf_ddm_alloc )
-      IF( lk_mpp             )   CALL mpp_sum ( zdf_ddm_alloc )
-      IF( zdf_ddm_alloc /= 0 )   CALL ctl_warn('zdf_ddm_alloc: failed to allocate arrays')
-   END FUNCTION zdf_ddm_alloc
-
-
-   SUBROUTINE zdf_ddm( kt )
+   SUBROUTINE zdf_ddm( kt, p_avm, p_avt, p_avs )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE zdf_ddm  ***
@@ -86,5 +63,5 @@
       !!      avt = avt + zavft + zavdt
       !!      avs = avs + zavfs + zavds
-      !!      avmu, avmv are required to remain at least above avt and avs.
+      !!      avm is required to remain at least above avt and avs.
       !!      
       !! ** Action  :   avt, avs : updated vertical eddy diffusivity coef. for T & S
@@ -92,5 +69,8 @@
       !! References :   Merryfield et al., JPO, 29, 1124-1142, 1999.
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step indexocean time step
+      INTEGER, INTENT(in   ) ::   kt       ! ocean time-step indexocean time step
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   p_avm   !  Kz on momentum    (w-points)
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   p_avt   !  Kz on temperature (w-points)
+      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   p_avs   !  Kz on salinity    (w-points)
       !
       INTEGER  ::   ji, jj , jk     ! dummy loop indices
@@ -100,10 +80,8 @@
       REAL(wp) ::   zavft, zavfs    !   -      -
       REAL(wp) ::   zavdt, zavds    !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zrau, zmsks, zmskf, zmskd1, zmskd2, zmskd3
+      REAL(wp), DIMENSION(jpi,jpj) ::   zrau, zmsks, zmskf, zmskd1, zmskd2, zmskd3
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('zdf_ddm')
-      !
-      CALL wrk_alloc( jpi,jpj, zrau, zmsks, zmskf, zmskd1, zmskd2, zmskd3 )
+      IF( ln_timing )   CALL timing_start('zdf_ddm')
       !
       !                                                ! ===============
@@ -112,7 +90,12 @@
          ! Define the mask 
          ! ---------------
-         DO jj = 1, jpj                                ! R=zrau = (alpha / beta) (dk[t] / dk[s])
+!!gm  WORK to be done:   change the code from vector optimisation to scalar one.
+!!gm                     ==>>>  test in the loop instead of use of mask arrays
+!!gm                            and many acces in memory
+         
+         DO jj = 1, jpj                !==  R=zrau = (alpha / beta) (dk[t] / dk[s])  ==!
             DO ji = 1, jpi
                zrw =   ( gdepw_n(ji,jj,jk  ) - gdept_n(ji,jj,jk) )   &
+!!gm please, use e3w_n below 
                   &  / ( gdept_n(ji,jj,jk-1) - gdept_n(ji,jj,jk) ) 
                !
@@ -129,5 +112,5 @@
          END DO
 
-         DO jj = 1, jpj                                     ! indicators:
+         DO jj = 1, jpj                !==  indicators  ==!
             DO ji = 1, jpi
                ! stability indicator: msks=1 if rn2>0; 0 elsewhere
@@ -174,27 +157,7 @@
                   &                             +  0.15 * zrau(ji,jj)          * zmskd2(ji,jj)  )
                ! add to the eddy viscosity coef. previously computed
-# if defined key_zdftmx_new
-               ! key_zdftmx_new: New internal wave-driven param: use avs value computed by zdftmx
-               avs (ji,jj,jk) = avs(ji,jj,jk) + zavfs + zavds
-# else
-               avs (ji,jj,jk) = avt(ji,jj,jk) + zavfs + zavds
-# endif
-               avt (ji,jj,jk) = avt(ji,jj,jk) + zavft + zavdt
-               avm (ji,jj,jk) = avm(ji,jj,jk) + MAX( zavft + zavdt, zavfs + zavds )
-            END DO
-         END DO
-
-
-         ! Increase avmu, avmv if necessary
-         ! --------------------------------
-!!gm to be changed following the definition of avm.
-         DO jj = 1, jpjm1
-            DO ji = 1, fs_jpim1   ! vector opt.
-               avmu(ji,jj,jk) = MAX( avmu(ji,jj,jk),    &
-                  &                  avt(ji,jj,jk), avt(ji+1,jj,jk),   &
-                  &                  avs(ji,jj,jk), avs(ji+1,jj,jk) )  * wumask(ji,jj,jk)
-               avmv(ji,jj,jk) = MAX( avmv(ji,jj,jk),    &
-                  &                  avt(ji,jj,jk), avt(ji,jj+1,jk),   &
-                  &                  avs(ji,jj,jk), avs(ji,jj+1,jk) )  * wvmask(ji,jj,jk)
+               p_avs(ji,jj,jk) = p_avt(ji,jj,jk) + zavfs + zavds
+               p_avt(ji,jj,jk) = p_avt(ji,jj,jk) + zavft + zavdt
+               p_avm(ji,jj,jk) = p_avm(ji,jj,jk) + MAX( zavft + zavdt, zavfs + zavds )
             END DO
          END DO
@@ -203,75 +166,12 @@
       !                                                   ! ===============
       !
-      CALL lbc_lnk( avt , 'W', 1._wp )     ! Lateral boundary conditions   (unchanged sign)
-      CALL lbc_lnk( avs , 'W', 1._wp )
-      CALL lbc_lnk( avm , 'W', 1._wp )
-      CALL lbc_lnk( avmu, 'U', 1._wp ) 
-      CALL lbc_lnk( avmv, 'V', 1._wp )
-
       IF(ln_ctl) THEN
          CALL prt_ctl(tab3d_1=avt , clinfo1=' ddm  - t: ', tab3d_2=avs , clinfo2=' s: ', ovlap=1, kdim=jpk)
-         CALL prt_ctl(tab3d_1=avmu, clinfo1=' ddm  - u: ', mask1=umask, &
-            &         tab3d_2=avmv, clinfo2=       ' v: ', mask2=vmask, ovlap=1, kdim=jpk)
       ENDIF
       !
-      CALL wrk_dealloc( jpi,jpj, zrau, zmsks, zmskf, zmskd1, zmskd2, zmskd3 )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('zdf_ddm')
+      IF( ln_timing )   CALL timing_stop('zdf_ddm')
       !
    END SUBROUTINE zdf_ddm
    
-   
-   SUBROUTINE zdf_ddm_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE zdf_ddm_init  ***
-      !!
-      !! ** Purpose :   Initialization of double diffusion mixing scheme
-      !!
-      !! ** Method  :   Read the namzdf_ddm namelist and check the parameter values
-      !!              called by zdf_ddm at the first timestep (nit000)
-      !!----------------------------------------------------------------------
-      INTEGER ::   ios   ! local integer
-      !!
-      NAMELIST/namzdf_ddm/ rn_avts, rn_hsbfr
-      !!----------------------------------------------------------------------
-      !
-      REWIND( numnam_ref )              ! Namelist namzdf_ddm in reference namelist : Double diffusion mixing scheme
-      READ  ( numnam_ref, namzdf_ddm, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_ddm in reference namelist', lwp )
-
-      REWIND( numnam_cfg )              ! Namelist namzdf_ddm in configuration namelist : Double diffusion mixing scheme
-      READ  ( numnam_cfg, namzdf_ddm, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_ddm in configuration namelist', lwp )
-      IF(lwm) WRITE ( numond, namzdf_ddm )
-      !
-      IF(lwp) THEN                    ! Parameter print
-         WRITE(numout,*)
-         WRITE(numout,*) 'zdf_ddm : double diffusive mixing'
-         WRITE(numout,*) '~~~~~~~'
-         WRITE(numout,*) '   Namelist namzdf_ddm : set dd mixing parameter'
-         WRITE(numout,*) '      maximum avs for dd mixing      rn_avts   = ', rn_avts
-         WRITE(numout,*) '      heat/salt buoyancy flux ratio  rn_hsbfr  = ', rn_hsbfr
-      ENDIF
-      !
-      !                               ! allocate zdfddm arrays
-      IF( zdf_ddm_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_ddm_init : unable to allocate arrays' )
-      !                               ! initialization to masked Kz
-      avs(:,:,:) = rn_avt0 * wmask(:,:,:) 
-      !
-   END SUBROUTINE zdf_ddm_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :          Dummy module          No double diffusion
-   !!----------------------------------------------------------------------
-   LOGICAL, PUBLIC, PARAMETER ::   lk_zdfddm = .FALSE.   !: double diffusion flag
-CONTAINS
-   SUBROUTINE zdf_ddm( kt )           ! Dummy routine
-      WRITE(*,*) 'zdf_ddm: You should not have seen this print! error?', kt
-   END SUBROUTINE zdf_ddm
-   SUBROUTINE zdf_ddm_init            ! Dummy routine
-   END SUBROUTINE zdf_ddm_init
-#endif
-
    !!======================================================================
 END MODULE zdfddm
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfddm_substitute.h90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfddm_substitute.h90	(revision 9018)
+++ 	(revision )
@@ -1,18 +1,0 @@
-   !!----------------------------------------------------------------------
-   !!                    *** zdfddm_substitute.h90  ***
-   !!----------------------------------------------------------------------
-   !! ** purpose :   substitute fsaht. the eddy diffusivity coeff.
-   !!      with a constant or 1D or 2D or 3D array, using CPP macro.
-   !!----------------------------------------------------------------------
-#if defined key_zdfddm  && ! defined key_offline
-!   'key_zdfddm' :                      avs: 3D array defined in zdfddm module
-#   define   fsavs(i,j,k)       avs(i,j,k)
-#else
-!   Defautl option :                     avs = avt
-#   define   fsavs(i,j,k)       avt(i,j,k)
-#endif
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
-   !! $Id$ 
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfdrg.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfdrg.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfdrg.F90	(revision 9019)
@@ -0,0 +1,379 @@
+MODULE zdfdrg
+   !!======================================================================
+   !!                       ***  MODULE  zdfdrg  ***
+   !! Ocean physics: top and/or Bottom friction 
+   !!======================================================================
+   !! History :  OPA  ! 1997-06  (G. Madec, A.-M. Treguier)  Original code
+   !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
+   !!            3.2  ! 2009-09  (A.C.Coward)  Correction to include barotropic contribution
+   !!            3.3  ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
+   !!            3.4  ! 2011-11  (H. Liu) implementation of semi-implicit bottom friction option
+   !!                 ! 2012-06  (H. Liu) implementation of Log Layer bottom friction option
+   !!            4.0  ! 2017-05  (G. Madec) zdfbfr becomes zdfdrg + variable names change
+   !!                                     + drag defined at t-point + new user interface + top drag (ocean cavities)
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   zdf_drg       : update bottom friction coefficient (non-linear bottom friction only)
+   !!   zdf_drg_init  : read in namdrg namelist and control the bottom friction parameters.
+   !!       drg_init  :
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers variables
+   USE phycst  , ONLY : vkarmn
+   USE dom_oce        ! ocean space and time domain variables
+   USE zdf_oce        ! ocean vertical physics variables
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O module
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp        ! distributed memory computing
+   USE prtctl         ! Print control
+   USE timing         ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   zdf_drg         ! called by zdf_phy
+   PUBLIC   zdf_drg_init    ! called by zdf_phy_init
+
+   !                                 !!* Namelist namdrg: nature of drag coefficient namelist *
+   LOGICAL          ::   ln_NONE      ! free-slip       : Cd = 0
+   LOGICAL          ::   ln_lin       !     linear  drag: Cd = Cd0_lin
+   LOGICAL          ::   ln_non_lin   ! non-linear  drag: Cd = Cd0_nl |U|
+   LOGICAL          ::   ln_loglayer  ! logarithmic drag: Cd = vkarmn/log(z/z0)
+   LOGICAL , PUBLIC ::   ln_drgimp    ! implicit top/bottom friction flag
+
+   !                                 !!* Namelist namdrg_top & _bot: TOP or BOTTOM coefficient namelist *
+   REAL(wp)         ::   rn_Cd0       !: drag coefficient                                           [ - ]
+   REAL(wp)         ::   rn_Uc0       !: characteristic velocity (linear case: tau=rho*Cd0*Uc0*u)   [m/s]
+   REAL(wp)         ::   rn_Cdmax     !: drag value maximum (ln_loglayer=T)                         [ - ]
+   REAL(wp)         ::   rn_z0        !: roughness          (ln_loglayer=T)                         [ m ]
+   REAL(wp)         ::   rn_ke0       !: background kinetic energy (non-linear case)                [m2/s2]
+   LOGICAL          ::   ln_boost     !: =T regional boost of Cd0 ; =F Cd0 horizontally uniform
+   REAL(wp)         ::     rn_boost      !: local boost factor                                       [ - ]
+
+   REAL(wp), PUBLIC ::   r_Cdmin_top, r_Cdmax_top, r_z0_top, r_ke0_top   ! set from namdrg_top namelist values
+   REAL(wp), PUBLIC ::   r_Cdmin_bot, r_Cdmax_bot, r_z0_bot, r_ke0_bot   !  -    -  namdrg_bot    -       -
+
+   INTEGER ::              ndrg       ! choice of the type of drag coefficient
+   !                                  ! associated indices:
+   INTEGER, PARAMETER ::   np_NONE     = 0   ! free-slip: drag set to zero
+   INTEGER, PARAMETER ::   np_lin      = 1   !     linear drag: Cd = Cd0_lin
+   INTEGER, PARAMETER ::   np_non_lin  = 2   ! non-linear drag: Cd = Cd0_nl |U|
+   INTEGER, PARAMETER ::   np_loglayer = 3   ! non linear drag (logarithmic formulation): Cd = vkarmn/log(z/z0)
+
+   LOGICAL , PUBLIC ::   l_zdfdrg           !: flag to update at each time step the top/bottom Cd
+   LOGICAL          ::   l_log_not_linssh   !: flag to update at each time step the position ot the velocity point 
+   !
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:), PUBLIC ::   rCd0_top, rCd0_bot   !: precomputed top/bottom drag coeff. at t-point (>0)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:), PUBLIC ::   rCdU_top, rCdU_bot   !: top/bottom drag coeff. at t-point (<0)  [m/s]
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
+   !! $Id: zdfdrg.F90 7753 2017-03-03 11:46:59Z gm $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE zdf_drg( kt, k_mk, pCdmin, pCdmax, pz0, pke0, pCd0, pCdU )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE zdf_drg  ***
+      !!
+      !! ** Purpose :   update the top/bottom drag coefficient (non-linear case only)
+      !!
+      !! ** Method  :   In non linear friction case, the drag coeficient is
+      !!              a function of the velocity:
+      !!                          Cd = cd0 * |U+Ut|   
+      !!              where U is the top or bottom velocity and
+      !!                    Ut a tidal velocity (Ut^2 = Tidal kinetic energy 
+      !!                       assumed here here to be constant) 
+      !!              Depending on the input variable, the top- or bottom drag is compted
+      !!
+      !! ** Action  :   p_Cd   drag coefficient at t-point
+      !!----------------------------------------------------------------------
+      INTEGER                 , INTENT(in   ) ::   kt       ! ocean time-step index
+      !                       !               !!         !==  top or bottom variables  ==!
+      INTEGER , DIMENSION(:,:), INTENT(in   ) ::   k_mk     ! wet level (1st or last)
+      REAL(wp)                , INTENT(in   ) ::   pCdmin   ! min drag value
+      REAL(wp)                , INTENT(in   ) ::   pCdmax   ! max drag value
+      REAL(wp)                , INTENT(in   ) ::   pz0      ! roughness
+      REAL(wp)                , INTENT(in   ) ::   pke0     ! background tidal KE
+      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::   pCd0     ! masked precomputed part of Cd0
+      REAL(wp), DIMENSION(:,:), INTENT(  out) ::   pCdU     ! = - Cd*|U|   (t-points) [m/s]
+      !!
+      INTEGER ::   ji, jj   ! dummy loop indices
+      INTEGER ::   imk      ! local integers
+      REAL(wp)::   zzz, zut, zvt, zcd   ! local scalars
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('zdf_drg')
+      !
+      !
+      IF( l_log_not_linssh ) THEN     !==  "log layer"  ==!   compute Cd and -Cd*|U|
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               imk = k_mk(ji,jj)          ! ocean bottom level at t-points
+               zut = un(ji,jj,imk) + un(ji-1,jj,imk)     ! 2 x velocity at t-point
+               zvt = vn(ji,jj,imk) + vn(ji,jj-1,imk)
+               zzz = 0.5_wp * e3t_n(ji,jj,imk)           ! altitude below/above (top/bottom) the boundary
+               !
+!!JC: possible WAD implementation should modify line below if layers vanish
+               zcd = (  vkarmn / LOG( zzz / pz0 )  )**2
+               zcd = pCd0(ji,jj) * MIN(  MAX( pCdmin , zcd ) , pCdmax  )   ! here pCd0 = mask*boost
+               pCdU(ji,jj) = - zcd * SQRT(  0.25 * ( zut*zvt + zvt*zvt ) + pke0  )
+            END DO
+         END DO
+      ELSE                                            !==  standard Cd  ==!
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               imk = k_mk(ji,jj)    ! ocean bottom level at t-points
+               zut = un(ji,jj,imk) + un(ji-1,jj,imk)     ! 2 x velocity at t-point
+               zvt = vn(ji,jj,imk) + vn(ji,jj-1,imk)
+               !                                                           ! here pCd0 = mask*boost * drag
+               pCdU(ji,jj) = - pCd0(ji,jj) * SQRT(  0.25 * ( zut*zvt + zvt*zvt ) + pke0  )
+            END DO
+         END DO
+      ENDIF
+      !
+      IF(ln_ctl)   CALL prt_ctl( tab2d_1=pCdU, clinfo1=' Cd*U ')
+      !
+      IF( ln_timing )   CALL timing_stop('zdf_drg')
+      !
+   END SUBROUTINE zdf_drg
+
+
+   SUBROUTINE zdf_drg_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_brg_init  ***
+      !!
+      !! ** Purpose :   Initialization of the bottom friction
+      !!
+      !! ** Method  :   Read the namdrg namelist and check their consistency
+      !!                called at the first timestep (nit000)
+      !!----------------------------------------------------------------------
+      INTEGER   ::   ji, jj      ! dummy loop indexes
+      INTEGER   ::   ios, ioptio   ! local integers
+      !!
+      NAMELIST/namdrg/ ln_NONE, ln_lin, ln_non_lin, ln_loglayer, ln_drgimp
+      !!----------------------------------------------------------------------
+      !
+      !                     !==  drag nature  ==!
+      !
+      REWIND( numnam_ref )                   ! Namelist namdrg in reference namelist
+      READ  ( numnam_ref, namdrg, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 )   CALL ctl_nam( ios , 'namdrg in reference namelist', lwp )
+      REWIND( numnam_cfg )                   ! Namelist namdrg in configuration namelist
+      READ  ( numnam_cfg, namdrg, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 )   CALL ctl_nam( ios , 'namdrg in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, namdrg )
+      !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'zdf_drg_init : top and/or bottom drag setting'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namdrg : top/bottom friction choices'
+         WRITE(numout,*) '      free-slip       : Cd = 0                  ln_NONE     = ', ln_NONE
+         WRITE(numout,*) '      linear  drag    : Cd = Cd0                ln_lin      = ', ln_lin
+         WRITE(numout,*) '      non-linear  drag: Cd = Cd0_nl |U|         ln_non_lin  = ', ln_non_lin
+         WRITE(numout,*) '      logarithmic drag: Cd = vkarmn/log(z/z0)   ln_loglayer = ', ln_loglayer
+         WRITE(numout,*) '      implicit friction                         ln_drgimp   = ', ln_drgimp
+      ENDIF
+      !
+      ioptio = 0                       ! set ndrg and control check
+      IF( ln_NONE     ) THEN   ;   ndrg = np_NONE       ;   ioptio = ioptio + 1   ;   ENDIF
+      IF( ln_lin      ) THEN   ;   ndrg = np_lin        ;   ioptio = ioptio + 1   ;   ENDIF
+      IF( ln_non_lin  ) THEN   ;   ndrg = np_non_lin    ;   ioptio = ioptio + 1   ;   ENDIF
+      IF( ln_loglayer ) THEN   ;   ndrg = np_loglayer   ;   ioptio = ioptio + 1   ;   ENDIF
+      !
+      IF( ioptio /= 1 )   CALL ctl_stop( 'zdf_drg_init: Choose ONE type of drag coef in namdrg' )
+      !
+      !
+      !                     !==  BOTTOM drag setting  ==!   (applied at seafloor)
+      !
+      ALLOCATE( rCd0_bot(jpi,jpj), rCdU_bot(jpi,jpj) )
+      CALL drg_init( 'BOTTOM'   , mbkt       ,                                         &   ! <== in
+         &           r_Cdmin_bot, r_Cdmax_bot, r_z0_bot, r_ke0_bot, rCd0_bot, rCdU_bot )   ! ==> out
+
+      !
+      !                     !==  TOP drag setting  ==!   (applied at the top of ocean cavities)
+      !
+      IF ( ln_isfcav ) THEN             ! Ocean cavities: top friction setting
+         ALLOCATE( rCd0_top(jpi,jpj), rCdU_top(jpi,jpj) )
+         CALL drg_init( 'TOP   '   , mikt       ,                                         &   ! <== in
+            &           r_Cdmin_top, r_Cdmax_top, r_z0_top, r_ke0_top, rCd0_bot, rCdU_bot )   ! ==> out
+      ENDIF
+      !
+   END SUBROUTINE zdf_drg_init
+
+
+   SUBROUTINE drg_init( cd_topbot, k_mk,  &
+      &                 pCdmin, pCdmax, pz0, pke0, pCd0, pCdU ) 
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE drg_init  ***
+      !!
+      !! ** Purpose :   Initialization of the top/bottom friction CdO and Cd
+      !!              from namelist parameters
+      !!----------------------------------------------------------------------
+      CHARACTER(len=6)        , INTENT(in   ) ::   cd_topbot       ! top/ bot indicator
+      INTEGER , DIMENSION(:,:), INTENT(in   ) ::   k_mk            ! 1st/last  wet level 
+      REAL(wp)                , INTENT(  out) ::   pCdmin, pCdmax  ! min and max drag coef. [-]
+      REAL(wp)                , INTENT(  out) ::   pz0             ! roughness              [m]
+      REAL(wp)                , INTENT(  out) ::   pke0            ! background KE          [m2/s2]
+      REAL(wp), DIMENSION(:,:), INTENT(  out) ::   pCd0            ! masked precomputed part of the non-linear drag coefficient
+      REAL(wp), DIMENSION(:,:), INTENT(  out) ::   pCdU            ! linear drag*|U| at t-points  [m/s]
+      !!
+      CHARACTER(len=40) ::   cl_namdrg, cl_file, cl_varname, cl_namref, cl_namcfg  ! local names 
+      INTEGER ::   ji, jj              ! dummy loop indexes
+      LOGICAL ::   ll_top, ll_bot      ! local logical
+      INTEGER ::   ios, inum, imk      ! local integers
+      REAL(wp)::   zmsk, zzz, zcd      ! local scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   zmsk_boost   ! 2D workspace
+      !!
+      NAMELIST/namdrg_top/ rn_Cd0, rn_Uc0, rn_Cdmax, rn_ke0, rn_z0, ln_boost, rn_boost
+      NAMELIST/namdrg_bot/ rn_Cd0, rn_Uc0, rn_Cdmax, rn_ke0, rn_z0, ln_boost, rn_boost
+      !!----------------------------------------------------------------------
+      !
+      !                          !==  set TOP / BOTTOM specificities  ==!
+      ll_top = .FALSE.
+      ll_bot = .FALSE.
+      !
+      SELECT CASE (cd_topbot)
+      CASE( 'TOP   ' )
+         ll_top = .TRUE.
+         cl_namdrg  = 'namdrg_top'
+         cl_namref  = 'namdrg_top in reference     namelist'
+         cl_namcfg  = 'namdrg_top in configuration namelist'
+         cl_file    = 'tfr_coef.nc'
+         cl_varname = 'tfr_coef'
+      CASE( 'BOTTOM' )
+         ll_bot = .TRUE.
+         cl_namdrg  = 'namdrg_bot'
+         cl_namref  = 'namdrg_bot  in reference     namelist'
+         cl_namcfg  = 'namdrg_bot  in configuration namelist'
+         cl_file    = 'bfr_coef.nc'
+         cl_varname = 'tfr_coef'
+      CASE DEFAULT
+         CALL ctl_stop( 'drg_init: bad value for cd_topbot ' )
+      END SELECT
+      !
+      !                          !==  read namlist  ==!
+      !
+      REWIND( numnam_ref )                   ! Namelist cl_namdrg in reference namelist
+      IF(ll_top)   READ  ( numnam_ref, namdrg_top, IOSTAT = ios, ERR = 901)
+      IF(ll_bot)   READ  ( numnam_ref, namdrg_bot, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 )   CALL ctl_nam( ios , TRIM(cl_namref), lwp )
+      REWIND( numnam_cfg )                   ! Namelist cd_namdrg in configuration namelist
+      IF(ll_top)   READ  ( numnam_cfg, namdrg_top, IOSTAT = ios, ERR = 902 )
+      IF(ll_bot)   READ  ( numnam_cfg, namdrg_bot, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 )   CALL ctl_nam( ios , TRIM(cl_namcfg), lwp )
+      IF(lwm .AND. ll_top)   WRITE ( numond, namdrg_top )
+      IF(lwm .AND. ll_bot)   WRITE ( numond, namdrg_bot )
+      !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '   Namelist ',TRIM(cl_namdrg),' : set ',TRIM(cd_topbot),' friction parameters'
+         WRITE(numout,*) '      drag coefficient                        rn_Cd0   = ', rn_Cd0
+         WRITE(numout,*) '      characteristic velocity (linear case)   rn_Uc0   = ', rn_Uc0, ' m/s'
+         WRITE(numout,*) '      non-linear drag maximum                 rn_Cdmax = ', rn_Cdmax
+         WRITE(numout,*) '      background kinetic energy  (n-l case)   rn_ke0   = ', rn_ke0
+         WRITE(numout,*) '      bottom roughness           (n-l case)   rn_z0    = ', rn_z0
+         WRITE(numout,*) '      set a regional boost of Cd0             ln_boost = ', ln_boost
+         WRITE(numout,*) '         associated boost factor              rn_boost = ', rn_boost
+      ENDIF
+      !
+      !                          !==  return some namelist parametres  ==!   (used in non_lin and loglayer cases)
+      pCdmin = rn_Cd0
+      pCdmax = rn_Cdmax
+      pz0    = rn_z0
+      pke0   = rn_ke0
+      !
+      !                          !==  mask * boost factor  ==!
+      !
+      IF( ln_boost ) THEN           !* regional boost:   boost factor = 1 + regional boost
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '   ==>>   use a regional boost read in ', TRIM(cl_file), ' file'
+         IF(lwp) WRITE(numout,*) '          using enhancement factor of ', rn_boost
+         ! cl_varname is a coefficient in [0,1] giving where to apply the regional boost
+         CALL iom_open ( TRIM(cl_file), inum )
+         CALL iom_get  ( inum, jpdom_data, TRIM(cl_varname), zmsk_boost, 1 )
+         CALL iom_close( inum)
+         zmsk_boost(:,:) = 1._wp + rn_boost * zmsk_boost(:,:)
+         !
+      ELSE                          !* no boost:   boost factor = 1
+         zmsk_boost(:,:) = 1._wp
+      ENDIF
+      !                             !* mask outside ocean cavities area (top) or land area (bot)
+      IF(ll_top)   zmsk_boost(:,:) = zmsk_boost(:,:) * ssmask(:,:) * (1. - tmask(:,:,1) )  ! none zero in ocean cavities only
+      IF(ll_bot)   zmsk_boost(:,:) = zmsk_boost(:,:) * ssmask(:,:)                         ! x seafloor mask
+      !
+      !
+      SELECT CASE( ndrg )
+      !
+      CASE( np_NONE )            !==  No top/bottom friction  ==!   (pCdU = 0)
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '   ==>>   ',TRIM(cd_topbot),' free-slip, friction set to zero'
+         !
+         l_zdfdrg = .FALSE.         ! no time variation of the drag: set it one for all
+         !
+         pCdU(:,:) = 0._wp          ! pCd0 never used
+         !
+      CASE( np_lin )             !==  linear friction  ==!   (pCdU = Cd0 * Uc0)
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '   ==>>   linear ',TRIM(cd_topbot),' friction (constant coef = Cd0*Uc0 = ', rn_Cd0*rn_Uc0, ')'
+         !
+         l_zdfdrg = .FALSE.         ! no time variation of the Cd*|U| : set it one for all
+         !                      
+         pCdU(:,:) = - rn_Cd0 * rn_Uc0 * zmsk_boost(:,:)   ! pCd0 never used: remain undefined
+         !
+      CASE( np_non_lin )         !== non-linear friction  ==!   (pCd0 = Cd0 )
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '   ==>>   quadratic ',TRIM(cd_topbot),' friction (propotional to module of the velocity)'
+         IF(lwp) WRITE(numout,*) '   with   Cd0 = ', rn_Cd0, ', and',   &
+            &                             ' a background velocity module of (rn_ke0)^1/2 = ', SQRT(rn_ke0), 'm/s)'
+         !
+         l_zdfdrg = .TRUE.          !* Cd*|U| updated at each time-step (it depends on ocean velocity)
+         !
+         pCd0(:,:) = rn_Cd0 * zmsk_boost(:,:)  !* constant in time proportionality coefficient (= mask (and boost) Cd0)
+         !
+      CASE( np_loglayer )       !== logarithmic layer formulation of friction  ==!   (CdU = (vkarman log(z/z0))^2 |U| )
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '   ==>>   quadratic ',TRIM(cd_topbot),' drag (propotional to module of the velocity)'
+         IF(lwp) WRITE(numout,*) '   with   a logarithmic Cd0 formulation Cd0 = ( vkarman log(z/z0) )^2 ,'
+         IF(lwp) WRITE(numout,*) '          a background velocity module of (rn_ke0)^1/2 = ', SQRT(pke0), 'm/s), '
+         IF(lwp) WRITE(numout,*) '          a logarithmic formulation: a roughness of ', pz0, ' meters,   and '
+         IF(lwp) WRITE(numout,*) '          a proportionality factor bounded by min/max values of ', pCdmin, pCdmax
+         !
+         l_zdfdrg = .TRUE.          !* Cd*|U| updated at each time-step (it depends on ocean velocity)
+         !
+         IF( ln_linssh ) THEN       !* pCd0 = (v log(z/z0))^2   as velocity points have a fixed z position
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '   N.B.   linear free surface case, Cd0 computed one for all'
+            !
+            l_log_not_linssh = .FALSE.    !- don't update Cd at each time step
+            !
+            DO jj = 1, jpj                   ! pCd0 = mask (and boosted) logarithmic drag coef. 
+               DO ji = 1, jpi
+                  zzz =  0.5_wp * e3t_0(ji,jj,k_mk(ji,jj))
+                  zcd = (  vkarmn / LOG( zzz / rn_z0 )  )**2
+                  pCd0(ji,jj) = zmsk_boost(ji,jj) * MIN(  MAX( rn_Cd0 , zcd ) , rn_Cdmax  )  ! rn_Cd0 < Cd0 < rn_Cdmax
+               END DO
+            END DO
+         ELSE                       !* Cd updated at each time-step ==> pCd0 = mask * boost
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '   N.B.   non-linear free surface case, Cd0 updated at each time-step '
+            !
+            l_log_not_linssh = .TRUE.     ! compute the drag coef. at each time-step 
+            !
+            pCd0(:,:) = zmsk_boost(:,:)
+         ENDIF
+         !
+      CASE DEFAULT
+         CALL ctl_stop( 'drg_init: bad flag value for ndrg ' )
+      END SELECT
+      !
+   END SUBROUTINE drg_init
+
+   !!======================================================================
+END MODULE zdfdrg
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfevd.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfevd.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfevd.F90	(revision 9019)
@@ -8,4 +8,5 @@
    !!   NEMO     1.0  !  2002-06  (G. Madec)  F90: Free form and module
    !!            3.2  !  2009-03  (M. Leclair, G. Madec, R. Benshila) test on both before & after
+   !!            4.0  !  2017-04  (G. Madec)  evd applied on avm (at t-point) 
    !!----------------------------------------------------------------------
 
@@ -23,5 +24,4 @@
    USE iom             ! for iom_put
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE wrk_nemo        ! work arrays
    USE timing          ! Timing
 
@@ -38,5 +38,5 @@
 CONTAINS
 
-   SUBROUTINE zdf_evd( kt )
+   SUBROUTINE zdf_evd( kt, p_avm, p_avt )
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE zdf_evd  ***
@@ -45,19 +45,22 @@
       !!      sivity coefficients when a static instability is encountered.
       !!
-      !! ** Method  :   avt, avm, and the 4 neighbouring avmu, avmv coefficients
-      !!      are set to avevd (namelist parameter) if the water column is 
-      !!      statically unstable (i.e. if rn2 < -1.e-12 )
+      !! ** Method  :   tracer (and momentum if nn_evdm=1) vertical mixing 
+      !!              coefficients are set to rn_evd (namelist parameter) 
+      !!              if the water column is statically unstable.
+      !!                The test of static instability is performed using
+      !!              Brunt-Vaisala frequency (rn2 < -1.e-12) of to successive
+      !!              time-step (Leap-Frog environnement): before and
+      !!              now time-step.
       !!
-      !! ** Action  :   avt, avm, avmu, avmv updted in static instability cases
-      !!
-      !! References :   Lazar, A., these de l'universite Paris VI, France, 1997
+      !! ** Action  :   avt, avm   enhanced where static instability occurs
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt   ! ocean time-step indexocean time step
+      INTEGER                    , INTENT(in   ) ::   kt             ! ocean time-step indexocean time step
+      REAL(wp), DIMENSION(:,:,:) , INTENT(inout) ::   p_avm, p_avt   !  momentum and tracer Kz (w-points)
       !
       INTEGER ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zavt_evd, zavm_evd
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zavt_evd, zavm_evd
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('zdf_evd')
+      IF( ln_timing )   CALL timing_start('zdf_evd')
       !
       IF( kt == nit000 ) THEN
@@ -68,41 +71,44 @@
       ENDIF
       !
-      CALL wrk_alloc( jpi,jpj,jpk,   zavt_evd, zavm_evd ) 
       !
-      zavt_evd(:,:,:) = avt(:,:,:)           ! set avt prior to evd application
+      zavt_evd(:,:,:) = p_avt(:,:,:)         ! set avt prior to evd application
       !
       SELECT CASE ( nn_evdm )
       !
-      CASE ( 1 )           ! enhance vertical eddy viscosity and diffusivity (if rn2<-1.e-12)
+      CASE ( 1 )           !==  enhance tracer & momentum Kz  ==!   (if rn2<-1.e-12)
          !
-         zavm_evd(:,:,:) = avm(:,:,:)           ! set avm prior to evd application
+         zavm_evd(:,:,:) = p_avm(:,:,:)      ! set avm prior to evd application
+         !
+!! change last digits results
+!         WHERE( MAX( rn2(2:jpi,2:jpj,2:jpkm1), rn2b(2:jpi,2:jpj,2:jpkm1) )  <= -1.e-12 ) THEN
+!            p_avt(2:jpi,2:jpj,2:jpkm1) = rn_evd * wmask(2:jpi,2:jpj,2:jpkm1)
+!            p_avm(2:jpi,2:jpj,2:jpkm1) = rn_evd * wmask(2:jpi,2:jpj,2:jpkm1)
+!         END WHERE
          !
          DO jk = 1, jpkm1 
-            DO jj = 2, jpj             ! no vector opt.
-               DO ji = 2, jpi
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
                   IF(  MIN( rn2(ji,jj,jk), rn2b(ji,jj,jk) ) <= -1.e-12 ) THEN
-                     avt (ji  ,jj  ,jk) = rn_avevd * tmask(ji  ,jj  ,jk)
-                     avm (ji  ,jj  ,jk) = rn_avevd * tmask(ji  ,jj  ,jk)
-                     avmu(ji  ,jj  ,jk) = rn_avevd * umask(ji  ,jj  ,jk)
-                     avmu(ji-1,jj  ,jk) = rn_avevd * umask(ji-1,jj  ,jk)
-                     avmv(ji  ,jj  ,jk) = rn_avevd * vmask(ji  ,jj  ,jk)
-                     avmv(ji  ,jj-1,jk) = rn_avevd * vmask(ji  ,jj-1,jk)
+                     p_avt(ji,jj,jk) = rn_evd * wmask(ji,jj,jk)
+                     p_avm(ji,jj,jk) = rn_evd * wmask(ji,jj,jk)
                   ENDIF
                END DO
             END DO
          END DO 
-         CALL lbc_lnk( avt , 'W', 1. )   ;   CALL lbc_lnk( avm , 'W', 1. )   ! Lateral boundary conditions
-         CALL lbc_lnk( avmu, 'U', 1. )   ;   CALL lbc_lnk( avmv, 'V', 1. )
          !
-         zavm_evd(:,:,:) = avm(:,:,:) - zavm_evd(:,:,:)   ! change in avm due to evd
-         CALL iom_put( "avm_evd", zavm_evd )              ! output this change
+         zavm_evd(:,:,:) = p_avm(:,:,:) - zavm_evd(:,:,:)   ! change in avm due to evd
+         CALL iom_put( "avm_evd", zavm_evd )                ! output this change
          !
-      CASE DEFAULT         ! enhance vertical eddy diffusivity only (if rn2<-1.e-12) 
+      CASE DEFAULT         !==  enhance tracer Kz  ==!   (if rn2<-1.e-12) 
+!! change last digits results
+!         WHERE( MAX( rn2(2:jpi,2:jpj,2:jpkm1), rn2b(2:jpi,2:jpj,2:jpkm1) )  <= -1.e-12 )
+!            p_avt(2:jpi,2:jpj,2:jpkm1) = rn_evd * wmask(2:jpi,2:jpj,2:jpkm1)
+!         END WHERE
+
          DO jk = 1, jpkm1
-!!!         WHERE( rn2(:,:,jk) <= -1.e-12 ) avt(:,:,jk) = tmask(:,:,jk) * avevd   ! agissant sur T SEUL! 
-            DO jj = 1, jpj             ! loop over the whole domain (no lbc_lnk call)
-               DO ji = 1, jpi
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
                   IF(  MIN( rn2(ji,jj,jk), rn2b(ji,jj,jk) ) <= -1.e-12 )   &
-                     avt(ji,jj,jk) = rn_avevd * tmask(ji,jj,jk)
+                     p_avt(ji,jj,jk) = rn_evd * wmask(ji,jj,jk)
                END DO
             END DO
@@ -110,12 +116,10 @@
          !
       END SELECT 
-
-      zavt_evd(:,:,:) = avt(:,:,:) - zavt_evd(:,:,:)   ! change in avt due to evd
+      !
+      zavt_evd(:,:,:) = p_avt(:,:,:) - zavt_evd(:,:,:)   ! change in avt due to evd
       CALL iom_put( "avt_evd", zavt_evd )              ! output this change
       IF( l_trdtra ) CALL trd_tra( kt, 'TRA', jp_tem, jptra_evd, zavt_evd )
       !
-      CALL wrk_dealloc( jpi,jpj,jpk,   zavt_evd, zavm_evd ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('zdf_evd')
+      IF( ln_timing )   CALL timing_stop('zdf_evd')
       !
    END SUBROUTINE zdf_evd
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90	(revision 9019)
@@ -5,10 +5,10 @@
    !!                 turbulent closure parameterization
    !!======================================================================
-   !! History :   3.0  !  2009-09  (G. Reffray)  Original code
-   !!             3.3  !  2010-10  (C. Bricaud)  Add in the reference
+   !! History :  3.0  !  2009-09  (G. Reffray)  Original code
+   !!            3.3  !  2010-10  (C. Bricaud)  Add in the reference
+   !!            4.0  !  2017-04  (G. Madec)  remove CPP keys & avm at t-point only 
+   !!             -   !  2017-05  (G. Madec)  add top friction as boundary condition
    !!----------------------------------------------------------------------
-#if defined key_zdfgls
-   !!----------------------------------------------------------------------
-   !!   'key_zdfgls'                 Generic Length Scale vertical physics
+
    !!----------------------------------------------------------------------
    !!   zdf_gls       : update momentum and tracer Kz from a gls scheme
@@ -19,14 +19,13 @@
    USE dom_oce        ! ocean space and time domain
    USE domvvl         ! ocean space and time domain : variable volume layer
-   USE zdf_oce        ! ocean vertical physics
-   USE zdfbfr         ! bottom friction (only for rn_bfrz0)
+   USE zdfdrg  , ONLY : r_z0_top , r_z0_bot   ! top/bottom roughness
+   USE zdfdrg  , ONLY : rCdU_top , rCdU_bot   ! top/bottom friction
    USE sbc_oce        ! surface boundary condition: ocean
    USE phycst         ! physical constants
    USE zdfmxl         ! mixed layer
-   USE sbcwave ,  ONLY: hsw   ! significant wave height
+   USE sbcwave , ONLY : hsw   ! significant wave height
    !
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp        ! MPP manager
-   USE wrk_nemo       ! work arrays
    USE prtctl         ! Print control
    USE in_out_manager ! I/O manager
@@ -38,14 +37,14 @@
    PRIVATE
 
-   PUBLIC   zdf_gls        ! routine called in step module
-   PUBLIC   zdf_gls_init   ! routine called in opa module
-   PUBLIC   gls_rst        ! routine called in step module
-
-   LOGICAL , PUBLIC, PARAMETER ::   lk_zdfgls = .TRUE.   !: TKE vertical mixing flag
+   PUBLIC   zdf_gls        ! called in zdfphy
+   PUBLIC   zdf_gls_init   ! called in zdfphy
+   PUBLIC   gls_rst        ! called in zdfphy
+
    !
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   mxln    !: now mixing length
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   hmxl_n    !: now mixing length
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   zwall   !: wall function
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ustars2 !: Squared surface velocity scale at T-points
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ustarb2 !: Squared bottom  velocity scale at T-points
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ustar2_surf !: Squared surface velocity scale at T-points
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ustar2_top  !: Squared top     velocity scale at T-points
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ustar2_bot  !: Squared bottom  velocity scale at T-points
 
    !                              !! ** Namelist  namzdf_gls  **
@@ -102,4 +101,6 @@
    REAL(wp) ::   rsc_tke, rsc_psi, rpsi1, rpsi2, rpsi3, rsc_psi0  !     -           -           -        -
    REAL(wp) ::   rpsi3m, rpsi3p, rpp, rmm, rnn                    !     -           -           -        -
+   !
+   REAL(wp) ::   r2_3 = 2._wp/3._wp   ! constant=2/3
 
    !! * Substitutions
@@ -116,6 +117,6 @@
       !!                ***  FUNCTION zdf_gls_alloc  ***
       !!----------------------------------------------------------------------
-      ALLOCATE( mxln(jpi,jpj,jpk), zwall(jpi,jpj,jpk) ,     &
-         &      ustars2(jpi,jpj) , ustarb2(jpi,jpj)   , STAT= zdf_gls_alloc )
+      ALLOCATE( hmxl_n(jpi,jpj,jpk) , ustar2_surf(jpi,jpj) ,                     &
+         &      zwall (jpi,jpj,jpk) , ustar2_top (jpi,jpj) , ustar2_bot(jpi,jpj) , STAT= zdf_gls_alloc )
          !
       IF( lk_mpp             )   CALL mpp_sum ( zdf_gls_alloc )
@@ -124,5 +125,5 @@
 
 
-   SUBROUTINE zdf_gls( kt )
+   SUBROUTINE zdf_gls( kt, p_sh2, p_avm, p_avt )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE zdf_gls  ***
@@ -131,94 +132,92 @@
       !!              coefficients using the GLS turbulent closure scheme.
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt ! ocean time step
-      INTEGER  ::   ji, jj, jk, ibot, ibotm1, dir  ! dummy loop arguments
-      REAL(wp) ::   zesh2, zsigpsi, zcoef, zex1, zex2   ! local scalars
-      REAL(wp) ::   ztx2, zty2, zup, zdown, zcof        !   -      - 
-      REAL(wp) ::   zratio, zrn2, zflxb, sh             !   -      -
+      USE zdf_oce , ONLY : en, avtb, avmb   ! ocean vertical physics
+      !!
+      INTEGER                   , INTENT(in   ) ::   kt             ! ocean time step
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   p_sh2          ! shear production term
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   p_avm, p_avt   !  momentum and tracer Kz (w-points)
+      !
+      INTEGER  ::   ji, jj, jk    ! dummy loop arguments
+      INTEGER  ::   ibot, ibotm1  ! local integers
+      INTEGER  ::   itop, itopp1  !   -       -
+      REAL(wp) ::   zesh2, zsigpsi, zcoef, zex1 , zex2  ! local scalars
+      REAL(wp) ::   ztx2, zty2, zup, zdown, zcof, zdir  !   -      - 
+      REAL(wp) ::   zratio, zrn2, zflxb, sh     , z_en  !   -      -
       REAL(wp) ::   prod, buoy, diss, zdiss, sm         !   -      -
-      REAL(wp) ::   gh, gm, shr, dif, zsqen, zav        !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::   zdep
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::   zkar
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::   zflxs       ! Turbulence fluxed induced by internal waves 
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::   zhsro       ! Surface roughness (surface waves)
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   eb          ! tke at time before
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   mxlb        ! mixing length at time before
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   shear       ! vertical shear
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   eps         ! dissipation rate
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zwall_psi   ! Wall function use in the wb case (ln_sigpsi)
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   psi         ! psi at time now
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   z_elem_a    ! element of the first  matrix diagonal
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   z_elem_b    ! element of the second matrix diagonal
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   z_elem_c    ! element of the third  matrix diagonal
+      REAL(wp) ::   gh, gm, shr, dif, zsqen, zavt, zavm !   -      -
+      REAL(wp) ::   zmsku, zmskv                        !   -      -
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zdep
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zkar
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zflxs       ! Turbulence fluxed induced by internal waves 
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zhsro       ! Surface roughness (surface waves)
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   eb          ! tke at time before
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   hmxl_b      ! mixing length at time before
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   eps         ! dissipation rate
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwall_psi   ! Wall function use in the wb case (ln_sigpsi)
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   psi         ! psi at time now
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zd_lw, zd_up, zdiag   ! lower, upper  and diagonal of the matrix
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zstt, zstm  ! stability function on tracer and momentum
       !!--------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('zdf_gls')
-      !
-      CALL wrk_alloc( jpi,jpj,       zdep, zkar, zflxs, zhsro )
-      CALL wrk_alloc( jpi,jpj,jpk,   eb, mxlb, shear, eps, zwall_psi, z_elem_a, z_elem_b, z_elem_c, psi  )
-      
+      IF( ln_timing )   CALL timing_start('zdf_gls')
+      !
       ! Preliminary computing
 
-      ustars2 = 0._wp   ;   ustarb2 = 0._wp   ;   psi  = 0._wp   ;   zwall_psi = 0._wp
-
-      IF( kt /= nit000 ) THEN   ! restore before value to compute tke
-         avt (:,:,:) = avt_k (:,:,:)
-         avm (:,:,:) = avm_k (:,:,:)
-         avmu(:,:,:) = avmu_k(:,:,:)
-         avmv(:,:,:) = avmv_k(:,:,:) 
-      ENDIF
-
-      ! Compute surface and bottom friction at T-points
+      ustar2_surf(:,:) = 0._wp   ;         psi(:,:,:) = 0._wp   
+      ustar2_top (:,:) = 0._wp   ;   zwall_psi(:,:,:) = 0._wp
+      ustar2_bot (:,:) = 0._wp
+
+      ! Compute surface, top and bottom friction at T-points
       DO jj = 2, jpjm1          
          DO ji = fs_2, fs_jpim1   ! vector opt.         
             !
             ! surface friction
-            ustars2(ji,jj) = r1_rau0 * taum(ji,jj) * tmask(ji,jj,1)
+            ustar2_surf(ji,jj) = r1_rau0 * taum(ji,jj) * tmask(ji,jj,1)
             !   
-            ! bottom friction (explicit before friction)        
-            ! Note that we chose here not to bound the friction as in dynbfr)   
-            ztx2 = (  bfrua(ji,jj)  * ub(ji,jj,mbku(ji,jj)) + bfrua(ji-1,jj) * ub(ji-1,jj,mbku(ji-1,jj))  )   &         
-               & * ( 1._wp - 0.5_wp * umask(ji,jj,1) * umask(ji-1,jj,1)  )      
-            zty2 = (  bfrva(ji,jj)  * vb(ji,jj,mbkv(ji,jj)) + bfrva(ji,jj-1) * vb(ji,jj-1,mbkv(ji,jj-1))  )   &         
-               & * ( 1._wp - 0.5_wp * vmask(ji,jj,1) * vmask(ji,jj-1,1)  )      
-            ustarb2(ji,jj) = SQRT( ztx2 * ztx2 + zty2 * zty2 ) * tmask(ji,jj,1)         
-         END DO         
-      END DO    
-
-      ! Set surface roughness length
-      SELECT CASE ( nn_z0_met )
-      !
-      CASE ( 0 )             ! Constant roughness          
+!!gm Rq we may add here r_ke0(_top/_bot) ?  ==>> think about that...
+          ! bottom friction (explicit before friction)
+          zmsku = ( 2._wp - umask(ji-1,jj,mbkt(ji,jj)) * umask(ji,jj,mbkt(ji,jj)) )
+          zmskv = ( 2._wp - vmask(ji,jj-1,mbkt(ji,jj)) * vmask(ji,jj,mbkt(ji,jj)) )     ! (CAUTION: CdU<0)
+          ustar2_bot(ji,jj) = - rCdU_bot(ji,jj) * SQRT(  ( zmsku*( ub(ji,jj,mbkt(ji,jj))+ub(ji-1,jj,mbkt(ji,jj)) ) )**2  &
+             &                                         + ( zmskv*( vb(ji,jj,mbkt(ji,jj))+vb(ji,jj-1,mbkt(ji,jj)) ) )**2  )
+         END DO
+      END DO
+      IF( ln_isfcav ) THEN       !top friction
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zmsku = ( 2. - umask(ji-1,jj,mikt(ji,jj)) * umask(ji,jj,mikt(ji,jj)) )
+               zmskv = ( 2. - vmask(ji,jj-1,mikt(ji,jj)) * vmask(ji,jj,mikt(ji,jj)) )     ! (CAUTION: CdU<0)
+               ustar2_top(ji,jj) = - rCdU_top(ji,jj) * SQRT(  ( zmsku*( ub(ji,jj,mikt(ji,jj))+ub(ji-1,jj,mikt(ji,jj)) ) )**2  &
+                  &                                         + ( zmskv*( vb(ji,jj,mikt(ji,jj))+vb(ji,jj-1,mikt(ji,jj)) ) )**2  )
+            END DO
+         END DO
+      ENDIF
+   
+      SELECT CASE ( nn_z0_met )      !==  Set surface roughness length  ==!
+      CASE ( 0 )                          ! Constant roughness          
          zhsro(:,:) = rn_hsro
       CASE ( 1 )             ! Standard Charnock formula
-         zhsro(:,:) = MAX(rsbc_zs1 * ustars2(:,:), rn_hsro)
+         zhsro(:,:) = MAX( rsbc_zs1 * ustar2_surf(:,:) , rn_hsro )
       CASE ( 2 )             ! Roughness formulae according to Rascle et al., Ocean Modelling (2008)
-         zdep(:,:)  = 30.*TANH(2.*0.3/(28.*SQRT(MAX(ustars2(:,:),rsmall))))             ! Wave age (eq. 10)
-         zhsro(:,:) = MAX(rsbc_zs2 * ustars2(:,:) * zdep(:,:)**1.5, rn_hsro) ! zhsro = rn_frac_hs * Hsw (eq. 11)
+!!gm faster coding : the 2 comment lines should be used
+!!gm         zcof = 2._wp * 0.6_wp / 28._wp
+!!gm         zdep(:,:)  = 30._wp * TANH(  zcof/ SQRT( MAX(ustar2_surf(:,:),rsmall) )  )       ! Wave age (eq. 10)
+         zdep (:,:) = 30.*TANH( 2.*0.3/(28.*SQRT(MAX(ustar2_surf(:,:),rsmall))) )         ! Wave age (eq. 10)
+         zhsro(:,:) = MAX(rsbc_zs2 * ustar2_surf(:,:) * zdep(:,:)**1.5, rn_hsro)          ! zhsro = rn_frac_hs * Hsw (eq. 11)
       CASE ( 3 )             ! Roughness given by the wave model (coupled or read in file)
-         zhsro(:,:) = hsw(:,:)
+         zhsro(:,:) = rn_frac_hs * hsw(:,:)   ! (rn_frac_hs=1.6 see Eq. (5) of Rascle et al. 2008 )
       END SELECT
-
-      ! Compute shear and dissipation rate
-      DO jk = 2, jpkm1
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               avmu(ji,jj,jk) = avmu(ji,jj,jk) * ( un(ji,jj,jk-1) - un(ji,jj,jk) )   &
-                  &                            * ( ub(ji,jj,jk-1) - ub(ji,jj,jk) )   &
-                  &                            / (  e3uw_n(ji,jj,jk) * e3uw_b(ji,jj,jk) )
-               avmv(ji,jj,jk) = avmv(ji,jj,jk) * ( vn(ji,jj,jk-1) - vn(ji,jj,jk) )   &
-                  &                            * ( vb(ji,jj,jk-1) - vb(ji,jj,jk) )   &
-                  &                            / (  e3vw_n(ji,jj,jk) * e3vw_b(ji,jj,jk) )
-               eps(ji,jj,jk)  = rc03 * en(ji,jj,jk) * SQRT(en(ji,jj,jk)) / mxln(ji,jj,jk)
+      !
+      DO jk = 2, jpkm1              !==  Compute dissipation rate  ==!
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               eps(ji,jj,jk)  = rc03 * en(ji,jj,jk) * SQRT( en(ji,jj,jk) ) / hmxl_n(ji,jj,jk)
             END DO
          END DO
       END DO
-      !
-      ! Lateral boundary conditions (avmu,avmv) (sign unchanged)
-      CALL lbc_lnk( avmu, 'U', 1. )   ;   CALL lbc_lnk( avmv, 'V', 1. )
 
       ! Save tke at before time step
-      eb  (:,:,:) = en  (:,:,:)
-      mxlb(:,:,:) = mxln(:,:,:)
+      eb    (:,:,:) = en    (:,:,:)
+      hmxl_b(:,:,:) = hmxl_n(:,:,:)
 
       IF( nn_clos == 0 ) THEN    ! Mellor-Yamada
@@ -226,5 +225,5 @@
             DO jj = 2, jpjm1 
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zup   = mxln(ji,jj,jk) * gdepw_n(ji,jj,mbkt(ji,jj)+1)
+                  zup   = hmxl_n(ji,jj,jk) * gdepw_n(ji,jj,mbkt(ji,jj)+1)
                   zdown = vkarmn * gdepw_n(ji,jj,jk) * ( -gdepw_n(ji,jj,jk) + gdepw_n(ji,jj,mbkt(ji,jj)+1) )
                   zcoef = ( zup / MAX( zdown, rsmall ) )
@@ -245,25 +244,23 @@
       ! The surface boundary condition are set after
       ! The bottom boundary condition are also set after. In standard e(bottom)=0.
-      ! z_elem_b : diagonal z_elem_c : upper diagonal z_elem_a : lower diagonal
+      ! zdiag : diagonal zd_up : upper diagonal zd_lw : lower diagonal
       ! Warning : after this step, en : right hand side of the matrix
 
       DO jk = 2, jpkm1
          DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               !
-               ! shear prod. at w-point weightened by mask
-               shear(ji,jj,jk) =  ( avmu(ji-1,jj,jk) + avmu(ji,jj,jk) ) / MAX( 1.e0 , umask(ji-1,jj,jk) + umask(ji,jj,jk) )   &
-                  &             + ( avmv(ji,jj-1,jk) + avmv(ji,jj,jk) ) / MAX( 1.e0 , vmask(ji,jj-1,jk) + vmask(ji,jj,jk) )
-               !
-               ! stratif. destruction
-               buoy = - avt(ji,jj,jk) * rn2(ji,jj,jk)
-               !
-               ! shear prod. - stratif. destruction
-               diss = eps(ji,jj,jk)
-               !
-               dir = 0.5_wp + SIGN( 0.5_wp, shear(ji,jj,jk) + buoy )   ! dir =1(=0) if shear(ji,jj,jk)+buoy >0(<0)
-               !
-               zesh2 = dir*(shear(ji,jj,jk)+buoy)+(1._wp-dir)*shear(ji,jj,jk)          ! production term
-               zdiss = dir*(diss/en(ji,jj,jk))   +(1._wp-dir)*(diss-buoy)/en(ji,jj,jk) ! dissipation term
+            DO ji = 2, jpim1
+               !
+               buoy = - p_avt(ji,jj,jk) * rn2(ji,jj,jk)     ! stratif. destruction
+               !
+               diss = eps(ji,jj,jk)                         ! dissipation
+               !
+               zdir = 0.5_wp + SIGN( 0.5_wp, p_sh2(ji,jj,jk) + buoy )   ! zdir =1(=0) if shear(ji,jj,jk)+buoy >0(<0)
+               !
+               zesh2 = zdir*(p_sh2(ji,jj,jk)+buoy)+(1._wp-zdir)*p_sh2(ji,jj,jk)          ! production term
+               zdiss = zdir*(diss/en(ji,jj,jk))   +(1._wp-zdir)*(diss-buoy)/en(ji,jj,jk) ! dissipation term
+!!gm better coding, identical results
+!               zesh2 =   p_sh2(ji,jj,jk) + zdir*buoy               ! production term
+!               zdiss = ( diss - (1._wp-zdir)*buoy ) / en(ji,jj,jk) ! dissipation term
+!!gm
                !
                ! Compute a wall function from 1. to rsc_psi*zwall/rsc_psi0
@@ -281,28 +278,21 @@
                ! building the matrix
                zcof = rfact_tke * tmask(ji,jj,jk)
-               !
-               ! lower diagonal
-               z_elem_a(ji,jj,jk) = zcof * ( avm  (ji,jj,jk  ) + avm  (ji,jj,jk-1) )   &
-                  &                      / ( e3t_n(ji,jj,jk-1) * e3w_n(ji,jj,jk  ) )
-               !
-               ! upper diagonal
-               z_elem_c(ji,jj,jk) = zcof * ( avm  (ji,jj,jk+1) + avm  (ji,jj,jk  ) )   &
-                  &                      / ( e3t_n(ji,jj,jk  ) * e3w_n(ji,jj,jk) )
-               !
-               ! diagonal
-               z_elem_b(ji,jj,jk) = 1._wp - z_elem_a(ji,jj,jk) - z_elem_c(ji,jj,jk)  &
-                  &                       + rdt * zdiss * tmask(ji,jj,jk) 
-               !
-               ! right hand side in en
-               en(ji,jj,jk) = en(ji,jj,jk) + rdt * zesh2 * tmask(ji,jj,jk)
+               !                                               ! lower diagonal
+               zd_lw(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk  ) + p_avm(ji,jj,jk-1) ) / ( e3t_n(ji,jj,jk-1) * e3w_n(ji,jj,jk) )
+               !                                               ! upper diagonal
+               zd_up(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk+1) + p_avm(ji,jj,jk  ) ) / ( e3t_n(ji,jj,jk  ) * e3w_n(ji,jj,jk) )
+               !                                               ! diagonal
+               zdiag(ji,jj,jk) = 1._wp - zd_lw(ji,jj,jk) - zd_up(ji,jj,jk)  + rdt * zdiss * wmask(ji,jj,jk) 
+               !                                               ! right hand side in en
+               en(ji,jj,jk) = en(ji,jj,jk) + rdt * zesh2 * wmask(ji,jj,jk)
             END DO
          END DO
       END DO
       !
-      z_elem_b(:,:,jpk) = 1._wp
+      zdiag(:,:,jpk) = 1._wp
       !
       ! Set surface condition on zwall_psi (1 at the bottom)
-      zwall_psi(:,:,1) = zwall_psi(:,:,2)
-      zwall_psi(:,:,jpk) = 1.
+      zwall_psi(:,:, 1 ) = zwall_psi(:,:,2)
+      zwall_psi(:,:,jpk) = 1._wp
       !
       ! Surface boundary condition on tke
@@ -311,39 +301,36 @@
       SELECT CASE ( nn_bc_surf )
       !
-      CASE ( 0 )             ! Dirichlet case
+      CASE ( 0 )             ! Dirichlet boundary condition (set e at k=1 & 2) 
       ! First level
-      en(:,:,1) = rc02r * ustars2(:,:) * (1._wp + rsbc_tke1)**(2._wp/3._wp)
-      en(:,:,1) = MAX(en(:,:,1), rn_emin) 
-      z_elem_a(:,:,1) = en(:,:,1)
-      z_elem_c(:,:,1) = 0._wp
-      z_elem_b(:,:,1) = 1._wp
+      en   (:,:,1) = MAX(  rn_emin , rc02r * ustar2_surf(:,:) * (1._wp + rsbc_tke1)**r2_3  )
+      zd_lw(:,:,1) = en(:,:,1)
+      zd_up(:,:,1) = 0._wp
+      zdiag(:,:,1) = 1._wp
       ! 
       ! One level below
-      en(:,:,2) = rc02r * ustars2(:,:) * (1._wp + rsbc_tke1 * ((zhsro(:,:)+gdepw_n(:,:,2)) &
-         &               / zhsro(:,:) )**(1.5_wp*ra_sf))**(2._wp/3._wp)
-      en(:,:,2) = MAX(en(:,:,2), rn_emin )
-      z_elem_a(:,:,2) = 0._wp 
-      z_elem_c(:,:,2) = 0._wp
-      z_elem_b(:,:,2) = 1._wp
-      !
-      !
-      CASE ( 1 )             ! Neumann boundary condition on d(e)/dz
+      en   (:,:,2) =  MAX(  rc02r * ustar2_surf(:,:) * (  1._wp + rsbc_tke1 * ((zhsro(:,:)+gdepw_n(:,:,2))   &
+         &                 / zhsro(:,:) )**(1.5_wp*ra_sf)  )**(2._wp/3._wp)                      , rn_emin   )
+      zd_lw(:,:,2) = 0._wp 
+      zd_up(:,:,2) = 0._wp
+      zdiag(:,:,2) = 1._wp
+      !
+      !
+      CASE ( 1 )             ! Neumann boundary condition (set d(e)/dz)
       !
       ! Dirichlet conditions at k=1
-      en(:,:,1)       = rc02r * ustars2(:,:) * (1._wp + rsbc_tke1)**(2._wp/3._wp)
-      en(:,:,1)       = MAX(en(:,:,1), rn_emin)      
-      z_elem_a(:,:,1) = en(:,:,1)
-      z_elem_c(:,:,1) = 0._wp
-      z_elem_b(:,:,1) = 1._wp
+      en   (:,:,1) = MAX(  rc02r * ustar2_surf(:,:) * (1._wp + rsbc_tke1)**r2_3 , rn_emin  )
+      zd_lw(:,:,1) = en(:,:,1)
+      zd_up(:,:,1) = 0._wp
+      zdiag(:,:,1) = 1._wp
       !
       ! at k=2, set de/dz=Fw
       !cbr
-      z_elem_b(:,:,2) = z_elem_b(:,:,2) +  z_elem_a(:,:,2) ! Remove z_elem_a from z_elem_b
-      z_elem_a(:,:,2) = 0._wp
-      zkar(:,:)       = (rl_sf + (vkarmn-rl_sf)*(1.-exp(-rtrans*gdept_n(:,:,1)/zhsro(:,:)) ))
-      zflxs(:,:)      = rsbc_tke2 * ustars2(:,:)**1.5_wp * zkar(:,:) &
-          &                       * ((zhsro(:,:)+gdept_n(:,:,1)) / zhsro(:,:) )**(1.5_wp*ra_sf)
-
-      en(:,:,2) = en(:,:,2) + zflxs(:,:)/e3w_n(:,:,2)
+      zdiag(:,:,2) = zdiag(:,:,2) +  zd_lw(:,:,2) ! Remove zd_lw from zdiag
+      zd_lw(:,:,2) = 0._wp
+      zkar (:,:)   = (rl_sf + (vkarmn-rl_sf)*(1.-EXP(-rtrans*gdept_n(:,:,1)/zhsro(:,:)) ))
+      zflxs(:,:)   = rsbc_tke2 * ustar2_surf(:,:)**1.5_wp * zkar(:,:) &
+          &                    * (  ( zhsro(:,:)+gdept_n(:,:,1) ) / zhsro(:,:)  )**(1.5_wp*ra_sf)
+!!gm why not   :                        * ( 1._wp + gdept_n(:,:,1) / zhsro(:,:) )**(1.5_wp*ra_sf)
+      en(:,:,2) = en(:,:,2) + zflxs(:,:) / e3w_n(:,:,2)
       !
       !
@@ -356,6 +343,46 @@
       !
       CASE ( 0 )             ! Dirichlet 
-         !                      ! en(ibot) = u*^2 / Co2 and mxln(ibot) = rn_lmin
+         !                      ! en(ibot) = u*^2 / Co2 and hmxl_n(ibot) = rn_lmin
          !                      ! Balance between the production and the dissipation terms
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+!!gm This means that bottom and ocean w-level above have a specified "en" value.   Sure ????
+!!   With thick deep ocean level thickness, this may be quite large, no ???
+!!   in particular in ocean cavities where top stratification can be large...
+               ibot   = mbkt(ji,jj) + 1      ! k   bottom level of w-point
+               ibotm1 = mbkt(ji,jj)          ! k-1 bottom level of w-point but >=1
+               !
+               z_en =  MAX( rc02r * ustar2_bot(ji,jj), rn_emin )
+               !
+               ! Dirichlet condition applied at: 
+               !     Bottom level (ibot)      &      Just above it (ibotm1)   
+               zd_lw(ji,jj,ibot) = 0._wp   ;   zd_lw(ji,jj,ibotm1) = 0._wp
+               zd_up(ji,jj,ibot) = 0._wp   ;   zd_up(ji,jj,ibotm1) = 0._wp
+               zdiag(ji,jj,ibot) = 1._wp   ;   zdiag(ji,jj,ibotm1) = 1._wp
+               en   (ji,jj,ibot) = z_en    ;   en   (ji,jj,ibotm1) = z_en
+            END DO
+         END DO
+         !
+         IF( ln_isfcav) THEN     ! top boundary   (ocean cavity)
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  itop   = mikt(ji,jj)       ! k   top w-point
+                  itopp1 = mikt(ji,jj) + 1   ! k+1 1st w-point below the top one
+                  !                                                ! mask at the ocean surface points
+                  z_en = MAX( rc02r * ustar2_top(ji,jj), rn_emin ) * ( 1._wp - tmask(ji,jj,1) )
+                  !
+ !!gm TO BE VERIFIED !!!
+                  ! Dirichlet condition applied at: 
+                  !     top level (itop)         &      Just below it (itopp1)   
+                  zd_lw(ji,jj,itop) = 0._wp   ;   zd_lw(ji,jj,itopp1) = 0._wp
+                  zd_up(ji,jj,itop) = 0._wp   ;   zd_up(ji,jj,itopp1) = 0._wp
+                  zdiag(ji,jj,itop) = 1._wp   ;   zdiag(ji,jj,itopp1) = 1._wp
+                  en   (ji,jj,itop) = z_en    ;   en   (ji,jj,itopp1) = z_en
+               END DO
+            END DO
+         ENDIF
+         !
+      CASE ( 1 )             ! Neumman boundary condition
+         !                      
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -363,36 +390,31 @@
                ibotm1 = mbkt(ji,jj)          ! k-1 bottom level of w-point but >=1
                !
+               z_en =  MAX( rc02r * ustar2_bot(ji,jj), rn_emin )
+               !
                ! Bottom level Dirichlet condition:
-               z_elem_a(ji,jj,ibot  ) = 0._wp
-               z_elem_c(ji,jj,ibot  ) = 0._wp
-               z_elem_b(ji,jj,ibot  ) = 1._wp
-               en(ji,jj,ibot  ) = MAX( rc02r * ustarb2(ji,jj), rn_emin )
-               !
-               ! Just above last level, Dirichlet condition again
-               z_elem_a(ji,jj,ibotm1) = 0._wp
-               z_elem_c(ji,jj,ibotm1) = 0._wp
-               z_elem_b(ji,jj,ibotm1) = 1._wp
-               en(ji,jj,ibotm1) = MAX( rc02r * ustarb2(ji,jj), rn_emin ) 
-            END DO
-         END DO
-         !
-      CASE ( 1 )             ! Neumman boundary condition
-         !                      
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               ibot   = mbkt(ji,jj) + 1      ! k   bottom level of w-point
-               ibotm1 = mbkt(ji,jj)          ! k-1 bottom level of w-point but >=1
-               !
-               ! Bottom level Dirichlet condition:
-               z_elem_a(ji,jj,ibot) = 0._wp
-               z_elem_c(ji,jj,ibot) = 0._wp
-               z_elem_b(ji,jj,ibot) = 1._wp
-               en(ji,jj,ibot) = MAX( rc02r * ustarb2(ji,jj), rn_emin )
-               !
-               ! Just above last level: Neumann condition
-               z_elem_b(ji,jj,ibotm1) = z_elem_b(ji,jj,ibotm1) + z_elem_c(ji,jj,ibotm1)   ! Remove z_elem_c from z_elem_b
-               z_elem_c(ji,jj,ibotm1) = 0._wp
-            END DO
-         END DO
+               !     Bottom level (ibot)      &      Just above it (ibotm1)   
+               !         Dirichlet            !         Neumann
+               zd_lw(ji,jj,ibot) = 0._wp   !   ! Remove zd_up from zdiag
+               zdiag(ji,jj,ibot) = 1._wp   ;   zdiag(ji,jj,ibotm1) = zdiag(ji,jj,ibotm1) + zd_up(ji,jj,ibotm1)
+               zd_up(ji,jj,ibot) = 0._wp   ;   zd_up(ji,jj,ibotm1) = 0._wp
+            END DO
+         END DO
+         IF( ln_isfcav) THEN     ! top boundary   (ocean cavity)
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  itop   = mikt(ji,jj)       ! k   top w-point
+                  itopp1 = mikt(ji,jj) + 1   ! k+1 1st w-point below the top one
+                  !                                                ! mask at the ocean surface points
+                  z_en = MAX( rc02r * ustar2_top(ji,jj), rn_emin ) * ( 1._wp - tmask(ji,jj,1) )
+                  !
+                  ! Bottom level Dirichlet condition:
+                  !     Bottom level (ibot)      &      Just above it (ibotm1)   
+                  !         Dirichlet            !         Neumann
+                  zd_lw(ji,jj,itop) = 0._wp   !   ! Remove zd_up from zdiag
+                  zdiag(ji,jj,itop) = 1._wp   ;   zdiag(ji,jj,itopp1) = zdiag(ji,jj,itopp1) + zd_up(ji,jj,itopp1)
+                  zd_up(ji,jj,itop) = 0._wp   ;   zd_up(ji,jj,itopp1) = 0._wp
+               END DO
+            END DO
+         ENDIF
          !
       END SELECT
@@ -404,5 +426,5 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1    ! vector opt.
-               z_elem_b(ji,jj,jk) = z_elem_b(ji,jj,jk) - z_elem_a(ji,jj,jk) * z_elem_c(ji,jj,jk-1) / z_elem_b(ji,jj,jk-1)
+               zdiag(ji,jj,jk) = zdiag(ji,jj,jk) - zd_lw(ji,jj,jk) * zd_up(ji,jj,jk-1) / zdiag(ji,jj,jk-1)
             END DO
          END DO
@@ -411,5 +433,5 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1    ! vector opt.
-               z_elem_a(ji,jj,jk) = en(ji,jj,jk) - z_elem_a(ji,jj,jk) / z_elem_b(ji,jj,jk-1) * z_elem_a(ji,jj,jk-1)
+               zd_lw(ji,jj,jk) = en(ji,jj,jk) - zd_lw(ji,jj,jk) / zdiag(ji,jj,jk-1) * zd_lw(ji,jj,jk-1)
             END DO
          END DO
@@ -418,5 +440,5 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1    ! vector opt.
-               en(ji,jj,jk) = ( z_elem_a(ji,jj,jk) - z_elem_c(ji,jj,jk) * en(ji,jj,jk+1) ) / z_elem_b(ji,jj,jk)
+               en(ji,jj,jk) = ( zd_lw(ji,jj,jk) - zd_up(ji,jj,jk) * en(ji,jj,jk+1) ) / zdiag(ji,jj,jk)
             END DO
          END DO
@@ -437,5 +459,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  psi(ji,jj,jk)  = eb(ji,jj,jk) * mxlb(ji,jj,jk)
+                  psi(ji,jj,jk)  = eb(ji,jj,jk) * hmxl_b(ji,jj,jk)
                END DO
             END DO
@@ -455,5 +477,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  psi(ji,jj,jk)  = SQRT( eb(ji,jj,jk) ) / ( rc0 * mxlb(ji,jj,jk) )
+                  psi(ji,jj,jk)  = SQRT( eb(ji,jj,jk) ) / ( rc0 * hmxl_b(ji,jj,jk) )
                END DO
             END DO
@@ -464,5 +486,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  psi(ji,jj,jk)  = rc02 * eb(ji,jj,jk) * mxlb(ji,jj,jk)**rnn 
+                  psi(ji,jj,jk)  = rc02 * eb(ji,jj,jk) * hmxl_b(ji,jj,jk)**rnn 
                END DO
             END DO
@@ -475,5 +497,5 @@
       ! Resolution of a tridiagonal linear system by a "methode de chasse"
       ! computation from level 2 to jpkm1  (e(1) already computed and e(jpk)=0 ).
-      ! z_elem_b : diagonal z_elem_c : upper diagonal z_elem_a : lower diagonal
+      ! zdiag : diagonal zd_up : upper diagonal zd_lw : lower diagonal
       ! Warning : after this step, en : right hand side of the matrix
 
@@ -485,42 +507,38 @@
                zratio = psi(ji,jj,jk) / eb(ji,jj,jk) 
                !
-               ! psi3+ : stable : B=-KhN²<0 => N²>0 if rn2>0 dir = 1 (stable) otherwise dir = 0 (unstable)
-               dir = 0.5_wp + SIGN( 0.5_wp, rn2(ji,jj,jk) )
-               !
-               rpsi3 = dir * rpsi3m + ( 1._wp - dir ) * rpsi3p
+               ! psi3+ : stable : B=-KhN²<0 => N²>0 if rn2>0 zdir = 1 (stable) otherwise zdir = 0 (unstable)
+               zdir = 0.5_wp + SIGN( 0.5_wp, rn2(ji,jj,jk) )
+               !
+               rpsi3 = zdir * rpsi3m + ( 1._wp - zdir ) * rpsi3p
                !
                ! shear prod. - stratif. destruction
-               prod = rpsi1 * zratio * shear(ji,jj,jk)
+               prod = rpsi1 * zratio * p_sh2(ji,jj,jk)
                !
                ! stratif. destruction
-               buoy = rpsi3 * zratio * (- avt(ji,jj,jk) * rn2(ji,jj,jk) )
+               buoy = rpsi3 * zratio * (- p_avt(ji,jj,jk) * rn2(ji,jj,jk) )
                !
                ! shear prod. - stratif. destruction
                diss = rpsi2 * zratio * zwall(ji,jj,jk) * eps(ji,jj,jk)
                !
-               dir = 0.5_wp + SIGN( 0.5_wp, prod + buoy )   ! dir =1(=0) if shear(ji,jj,jk)+buoy >0(<0)
-               !
-               zesh2 = dir * ( prod + buoy )          + (1._wp - dir ) * prod                        ! production term
-               zdiss = dir * ( diss / psi(ji,jj,jk) ) + (1._wp - dir ) * (diss-buoy) / psi(ji,jj,jk) ! dissipation term
+               zdir = 0.5_wp + SIGN( 0.5_wp, prod + buoy )     ! zdir =1(=0) if shear(ji,jj,jk)+buoy >0(<0)
+               !
+               zesh2 = zdir * ( prod + buoy )          + (1._wp - zdir ) * prod                        ! production term
+               zdiss = zdir * ( diss / psi(ji,jj,jk) ) + (1._wp - zdir ) * (diss-buoy) / psi(ji,jj,jk) ! dissipation term
                !                                                        
                ! building the matrix
                zcof = rfact_psi * zwall_psi(ji,jj,jk) * tmask(ji,jj,jk)
-               ! lower diagonal
-               z_elem_a(ji,jj,jk) = zcof * ( avm  (ji,jj,jk  ) + avm  (ji,jj,jk-1) )   &
-                  &                      / ( e3t_n(ji,jj,jk-1) * e3w_n(ji,jj,jk  ) )
-               ! upper diagonal
-               z_elem_c(ji,jj,jk) = zcof * ( avm  (ji,jj,jk+1) + avm  (ji,jj,jk  ) )   &
-                  &                      / ( e3t_n(ji,jj,jk  ) * e3w_n(ji,jj,jk) )
-               ! diagonal
-               z_elem_b(ji,jj,jk) = 1._wp - z_elem_a(ji,jj,jk) - z_elem_c(ji,jj,jk)  &
-                  &                       + rdt * zdiss * tmask(ji,jj,jk)
-               !
-               ! right hand side in psi
-               psi(ji,jj,jk) = psi(ji,jj,jk) + rdt * zesh2 * tmask(ji,jj,jk)
+               !                                               ! lower diagonal
+               zd_lw(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk  ) + p_avm(ji,jj,jk-1) ) / ( e3t_n(ji,jj,jk-1) * e3w_n(ji,jj,jk) )
+               !                                               ! upper diagonal
+               zd_up(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk+1) + p_avm(ji,jj,jk  ) ) / ( e3t_n(ji,jj,jk  ) * e3w_n(ji,jj,jk) )
+               !                                               ! diagonal
+               zdiag(ji,jj,jk) = 1._wp - zd_lw(ji,jj,jk) - zd_up(ji,jj,jk) + rdt * zdiss * wmask(ji,jj,jk)
+               !                                               ! right hand side in psi
+               psi(ji,jj,jk) = psi(ji,jj,jk) + rdt * zesh2 * wmask(ji,jj,jk)
             END DO
          END DO
       END DO
       !
-      z_elem_b(:,:,jpk) = 1._wp
+      zdiag(:,:,jpk) = 1._wp
 
       ! Surface boundary condition on psi
@@ -530,45 +548,42 @@
       !
       CASE ( 0 )             ! Dirichlet boundary conditions
-      !
-      ! Surface value
-      zdep(:,:)       = zhsro(:,:) * rl_sf ! Cosmetic
-      psi (:,:,1)     = rc0**rpp * en(:,:,1)**rmm * zdep(:,:)**rnn * tmask(:,:,1)
-      z_elem_a(:,:,1) = psi(:,:,1)
-      z_elem_c(:,:,1) = 0._wp
-      z_elem_b(:,:,1) = 1._wp
-      !
-      ! One level below
-      zkar(:,:)       = (rl_sf + (vkarmn-rl_sf)*(1._wp-exp(-rtrans*gdepw_n(:,:,2)/zhsro(:,:) )))
-      zdep(:,:)       = (zhsro(:,:) + gdepw_n(:,:,2)) * zkar(:,:)
-      psi (:,:,2)     = rc0**rpp * en(:,:,2)**rmm * zdep(:,:)**rnn * tmask(:,:,1)
-      z_elem_a(:,:,2) = 0._wp
-      z_elem_c(:,:,2) = 0._wp
-      z_elem_b(:,:,2) = 1._wp
-      ! 
-      !
+         !
+         ! Surface value
+         zdep    (:,:)   = zhsro(:,:) * rl_sf ! Cosmetic
+         psi     (:,:,1) = rc0**rpp * en(:,:,1)**rmm * zdep(:,:)**rnn * tmask(:,:,1)
+         zd_lw(:,:,1) = psi(:,:,1)
+         zd_up(:,:,1) = 0._wp
+         zdiag(:,:,1) = 1._wp
+         !
+         ! One level below
+         zkar    (:,:)   = (rl_sf + (vkarmn-rl_sf)*(1._wp-EXP(-rtrans*gdepw_n(:,:,2)/zhsro(:,:) )))
+         zdep    (:,:)   = (zhsro(:,:) + gdepw_n(:,:,2)) * zkar(:,:)
+         psi     (:,:,2) = rc0**rpp * en(:,:,2)**rmm * zdep(:,:)**rnn * tmask(:,:,1)
+         zd_lw(:,:,2) = 0._wp
+         zd_up(:,:,2) = 0._wp
+         zdiag(:,:,2) = 1._wp
+         ! 
       CASE ( 1 )             ! Neumann boundary condition on d(psi)/dz
-      !
-      ! Surface value: Dirichlet
-      zdep(:,:)       = zhsro(:,:) * rl_sf
-      psi (:,:,1)     = rc0**rpp * en(:,:,1)**rmm * zdep(:,:)**rnn * tmask(:,:,1)
-      z_elem_a(:,:,1) = psi(:,:,1)
-      z_elem_c(:,:,1) = 0._wp
-      z_elem_b(:,:,1) = 1._wp
-      !
-      ! Neumann condition at k=2
-      z_elem_b(:,:,2) = z_elem_b(:,:,2) +  z_elem_a(:,:,2) ! Remove z_elem_a from z_elem_b
-      z_elem_a(:,:,2) = 0._wp
-      !
-      ! Set psi vertical flux at the surface:
-      zkar(:,:) = rl_sf + (vkarmn-rl_sf)*(1._wp-exp(-rtrans*gdept_n(:,:,1)/zhsro(:,:) )) ! Lengh scale slope
-      zdep(:,:) = ((zhsro(:,:) + gdept_n(:,:,1)) / zhsro(:,:))**(rmm*ra_sf)
-      zflxs(:,:) = (rnn + rsbc_tke1 * (rnn + rmm*ra_sf) * zdep(:,:))*(1._wp + rsbc_tke1*zdep(:,:))**(2._wp*rmm/3._wp-1_wp)
-      zdep(:,:) =  rsbc_psi1 * (zwall_psi(:,:,1)*avm(:,:,1)+zwall_psi(:,:,2)*avm(:,:,2)) * &
-             & ustars2(:,:)**rmm * zkar(:,:)**rnn * (zhsro(:,:) + gdept_n(:,:,1))**(rnn-1.)
-      zflxs(:,:) = zdep(:,:) * zflxs(:,:)
-      psi(:,:,2) = psi(:,:,2) + zflxs(:,:) / e3w_n(:,:,2)
-
-      !   
-      !
+         !
+         ! Surface value: Dirichlet
+         zdep    (:,:)   = zhsro(:,:) * rl_sf
+         psi     (:,:,1) = rc0**rpp * en(:,:,1)**rmm * zdep(:,:)**rnn * tmask(:,:,1)
+         zd_lw(:,:,1) = psi(:,:,1)
+         zd_up(:,:,1) = 0._wp
+         zdiag(:,:,1) = 1._wp
+         !
+         ! Neumann condition at k=2
+         zdiag(:,:,2) = zdiag(:,:,2) +  zd_lw(:,:,2) ! Remove zd_lw from zdiag
+         zd_lw(:,:,2) = 0._wp
+         !
+         ! Set psi vertical flux at the surface:
+         zkar (:,:)   = rl_sf + (vkarmn-rl_sf)*(1._wp-EXP(-rtrans*gdept_n(:,:,1)/zhsro(:,:) )) ! Lengh scale slope
+         zdep (:,:)   = ((zhsro(:,:) + gdept_n(:,:,1)) / zhsro(:,:))**(rmm*ra_sf)
+         zflxs(:,:)   = (rnn + rsbc_tke1 * (rnn + rmm*ra_sf) * zdep(:,:))*(1._wp + rsbc_tke1*zdep(:,:))**(2._wp*rmm/3._wp-1_wp)
+         zdep (:,:)   = rsbc_psi1 * (zwall_psi(:,:,1)*p_avm(:,:,1)+zwall_psi(:,:,2)*p_avm(:,:,2)) * &
+            &           ustar2_surf(:,:)**rmm * zkar(:,:)**rnn * (zhsro(:,:) + gdept_n(:,:,1))**(rnn-1.)
+         zflxs(:,:)   = zdep(:,:) * zflxs(:,:)
+         psi  (:,:,2) = psi(:,:,2) + zflxs(:,:) / e3w_n(:,:,2)
+         !
       END SELECT
 
@@ -576,9 +591,11 @@
       ! --------------------------------
       !
-      SELECT CASE ( nn_bc_bot )
-      !
+!!gm should be done for ISF (top boundary cond.)
+!!gm so, totally new staff needed      ===>>> think about that !
+!
+      SELECT CASE ( nn_bc_bot )     ! bottom boundary
       !
       CASE ( 0 )             ! Dirichlet 
-         !                      ! en(ibot) = u*^2 / Co2 and mxln(ibot) = vkarmn * rn_bfrz0
+         !                      ! en(ibot) = u*^2 / Co2 and hmxl_n(ibot) = vkarmn * r_z0_bot
          !                      ! Balance between the production and the dissipation terms
          DO jj = 2, jpjm1
@@ -586,16 +603,16 @@
                ibot   = mbkt(ji,jj) + 1      ! k   bottom level of w-point
                ibotm1 = mbkt(ji,jj)          ! k-1 bottom level of w-point but >=1
-               zdep(ji,jj) = vkarmn * rn_bfrz0
+               zdep(ji,jj) = vkarmn * r_z0_bot
                psi (ji,jj,ibot) = rc0**rpp * en(ji,jj,ibot)**rmm * zdep(ji,jj)**rnn
-               z_elem_a(ji,jj,ibot) = 0._wp
-               z_elem_c(ji,jj,ibot) = 0._wp
-               z_elem_b(ji,jj,ibot) = 1._wp
+               zd_lw(ji,jj,ibot) = 0._wp
+               zd_up(ji,jj,ibot) = 0._wp
+               zdiag(ji,jj,ibot) = 1._wp
                !
                ! Just above last level, Dirichlet condition again (GOTM like)
-               zdep(ji,jj) = vkarmn * ( rn_bfrz0 + e3t_n(ji,jj,ibotm1) )
+               zdep(ji,jj) = vkarmn * ( r_z0_bot + e3t_n(ji,jj,ibotm1) )
                psi (ji,jj,ibotm1) = rc0**rpp * en(ji,jj,ibot  )**rmm * zdep(ji,jj)**rnn
-               z_elem_a(ji,jj,ibotm1) = 0._wp
-               z_elem_c(ji,jj,ibotm1) = 0._wp
-               z_elem_b(ji,jj,ibotm1) = 1._wp
+               zd_lw(ji,jj,ibotm1) = 0._wp
+               zd_up(ji,jj,ibotm1) = 0._wp
+               zdiag(ji,jj,ibotm1) = 1._wp
             END DO
          END DO
@@ -609,18 +626,18 @@
                !
                ! Bottom level Dirichlet condition:
-               zdep(ji,jj) = vkarmn * rn_bfrz0
+               zdep(ji,jj) = vkarmn * r_z0_bot
                psi (ji,jj,ibot) = rc0**rpp * en(ji,jj,ibot)**rmm * zdep(ji,jj)**rnn
                !
-               z_elem_a(ji,jj,ibot) = 0._wp
-               z_elem_c(ji,jj,ibot) = 0._wp
-               z_elem_b(ji,jj,ibot) = 1._wp
+               zd_lw(ji,jj,ibot) = 0._wp
+               zd_up(ji,jj,ibot) = 0._wp
+               zdiag(ji,jj,ibot) = 1._wp
                !
                ! Just above last level: Neumann condition with flux injection
-               z_elem_b(ji,jj,ibotm1) = z_elem_b(ji,jj,ibotm1) + z_elem_c(ji,jj,ibotm1) ! Remove z_elem_c from z_elem_b
-               z_elem_c(ji,jj,ibotm1) = 0.
+               zdiag(ji,jj,ibotm1) = zdiag(ji,jj,ibotm1) + zd_up(ji,jj,ibotm1) ! Remove zd_up from zdiag
+               zd_up(ji,jj,ibotm1) = 0.
                !
                ! Set psi vertical flux at the bottom:
-               zdep(ji,jj) = rn_bfrz0 + 0.5_wp*e3t_n(ji,jj,ibotm1)
-               zflxb = rsbc_psi2 * ( avm(ji,jj,ibot) + avm(ji,jj,ibotm1) )   &
+               zdep(ji,jj) = r_z0_bot + 0.5_wp*e3t_n(ji,jj,ibotm1)
+               zflxb = rsbc_psi2 * ( p_avm(ji,jj,ibot) + p_avm(ji,jj,ibotm1) )   &
                   &  * (0.5_wp*(en(ji,jj,ibot)+en(ji,jj,ibotm1)))**rmm * zdep(ji,jj)**(rnn-1._wp)
                psi(ji,jj,ibotm1) = psi(ji,jj,ibotm1) + zflxb / e3w_n(ji,jj,ibotm1)
@@ -636,5 +653,5 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1    ! vector opt.
-               z_elem_b(ji,jj,jk) = z_elem_b(ji,jj,jk) - z_elem_a(ji,jj,jk) * z_elem_c(ji,jj,jk-1) / z_elem_b(ji,jj,jk-1)
+               zdiag(ji,jj,jk) = zdiag(ji,jj,jk) - zd_lw(ji,jj,jk) * zd_up(ji,jj,jk-1) / zdiag(ji,jj,jk-1)
             END DO
          END DO
@@ -643,5 +660,5 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1    ! vector opt.
-               z_elem_a(ji,jj,jk) = psi(ji,jj,jk) - z_elem_a(ji,jj,jk) / z_elem_b(ji,jj,jk-1) * z_elem_a(ji,jj,jk-1)
+               zd_lw(ji,jj,jk) = psi(ji,jj,jk) - zd_lw(ji,jj,jk) / zdiag(ji,jj,jk-1) * zd_lw(ji,jj,jk-1)
             END DO
          END DO
@@ -650,5 +667,5 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1    ! vector opt.
-               psi(ji,jj,jk) = ( z_elem_a(ji,jj,jk) - z_elem_c(ji,jj,jk) * psi(ji,jj,jk+1) ) / z_elem_b(ji,jj,jk)
+               psi(ji,jj,jk) = ( zd_lw(ji,jj,jk) - zd_up(ji,jj,jk) * psi(ji,jj,jk+1) ) / zdiag(ji,jj,jk)
             END DO
          END DO
@@ -703,13 +720,13 @@
       ! Limit dissipation rate under stable stratification
       ! --------------------------------------------------
-      DO jk = 1, jpkm1 ! Note that this set boundary conditions on mxln at the same time
+      DO jk = 1, jpkm1 ! Note that this set boundary conditions on hmxl_n at the same time
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1    ! vector opt.
                ! limitation
-               eps(ji,jj,jk)  = MAX( eps(ji,jj,jk), rn_epsmin )
-               mxln(ji,jj,jk)  = rc03 * en(ji,jj,jk) * SQRT( en(ji,jj,jk) ) / eps(ji,jj,jk)
+               eps   (ji,jj,jk)  = MAX( eps(ji,jj,jk), rn_epsmin )
+               hmxl_n(ji,jj,jk)  = rc03 * en(ji,jj,jk) * SQRT( en(ji,jj,jk) ) / eps(ji,jj,jk)
                ! Galperin criterium (NOTE : Not required if the proper value of C3 in stable cases is calculated) 
                zrn2 = MAX( rn2(ji,jj,jk), rsmall )
-               IF (ln_length_lim) mxln(ji,jj,jk) = MIN(  rn_clim_galp * SQRT( 2._wp * en(ji,jj,jk) / zrn2 ), mxln(ji,jj,jk) )
+               IF( ln_length_lim )   hmxl_n(ji,jj,jk) = MIN(  rn_clim_galp * SQRT( 2._wp * en(ji,jj,jk) / zrn2 ), hmxl_n(ji,jj,jk) )
             END DO
          END DO
@@ -727,5 +744,5 @@
                DO ji = fs_2, fs_jpim1   ! vector opt.
                   ! zcof =  l²/q²
-                  zcof = mxlb(ji,jj,jk) * mxlb(ji,jj,jk) / ( 2._wp*eb(ji,jj,jk) )
+                  zcof = hmxl_b(ji,jj,jk) * hmxl_b(ji,jj,jk) / ( 2._wp*eb(ji,jj,jk) )
                   ! Gh = -N²l²/q²
                   gh = - rn2(ji,jj,jk) * zcof
@@ -736,7 +753,7 @@
                   sm = ( rb1**(-1._wp/3._wp) + ( 18._wp*ra1*ra1 + 9._wp*ra1*ra2*(1._wp-rc2) )*sh*gh ) / (1._wp-9._wp*ra1*ra2*gh)
                   !
-                  ! Store stability function in avmu and avmv
-                  avmu(ji,jj,jk) = rc_diff * sh * tmask(ji,jj,jk)
-                  avmv(ji,jj,jk) = rc_diff * sm * tmask(ji,jj,jk)
+                  ! Store stability function in zstt and zstm
+                  zstt(ji,jj,jk) = rc_diff * sh * tmask(ji,jj,jk)
+                  zstm(ji,jj,jk) = rc_diff * sm * tmask(ji,jj,jk)
                END DO
             END DO
@@ -748,5 +765,5 @@
                DO ji = fs_2, fs_jpim1   ! vector opt.
                   ! zcof =  l²/q²
-                  zcof = mxlb(ji,jj,jk)*mxlb(ji,jj,jk) / ( 2._wp * eb(ji,jj,jk) )
+                  zcof = hmxl_b(ji,jj,jk)*hmxl_b(ji,jj,jk) / ( 2._wp * eb(ji,jj,jk) )
                   ! Gh = -N²l²/q²
                   gh = - rn2(ji,jj,jk) * zcof
@@ -755,5 +772,5 @@
                   gh = gh * rf6
                   ! Gm =  M²l²/q² Shear number
-                  shr = shear(ji,jj,jk) / MAX( avm(ji,jj,jk), rsmall )
+                  shr = p_sh2(ji,jj,jk) / MAX( p_avm(ji,jj,jk), rsmall )
                   gm = MAX( shr * zcof , 1.e-10 )
                   gm = gm * rf6
@@ -764,7 +781,7 @@
                   sh = (rs4 - rs5*gh + rs6*gm) / rcff
                   !
-                  ! Store stability function in avmu and avmv
-                  avmu(ji,jj,jk) = rc_diff * sh * tmask(ji,jj,jk)
-                  avmv(ji,jj,jk) = rc_diff * sm * tmask(ji,jj,jk)
+                  ! Store stability function in zstt and zstm
+                  zstt(ji,jj,jk) = rc_diff * sh * tmask(ji,jj,jk)
+                  zstm(ji,jj,jk) = rc_diff * sm * tmask(ji,jj,jk)
                END DO
             END DO
@@ -776,11 +793,13 @@
       ! Lines below are useless if GOTM style Dirichlet conditions are used
 
-      avmv(:,:,1) = avmv(:,:,2)
+      zstm(:,:,1) = zstm(:,:,2)
 
       DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1   ! vector opt.
-            avmv(ji,jj,mbkt(ji,jj)+1) = avmv(ji,jj,mbkt(ji,jj))
+            zstm(ji,jj,mbkt(ji,jj)+1) = zstm(ji,jj,mbkt(ji,jj))
          END DO
       END DO
+!!gm should be done for ISF (top boundary cond.)
+!!gm so, totally new staff needed!!gm
 
       ! Compute diffusivities/viscosities
@@ -789,44 +808,20 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               zsqen         = SQRT( 2._wp * en(ji,jj,jk) ) * mxln(ji,jj,jk)
-               zav           = zsqen * avmu(ji,jj,jk)
-               avt(ji,jj,jk) = MAX( zav, avtb(jk) )*tmask(ji,jj,jk) ! apply mask for zdfmxl routine
-               zav           = zsqen * avmv(ji,jj,jk)
-               avm(ji,jj,jk) = MAX( zav, avmb(jk) ) ! Note that avm is not masked at the surface and the bottom
+               zsqen = SQRT( 2._wp * en(ji,jj,jk) ) * hmxl_n(ji,jj,jk)
+               zavt  = zsqen * zstt(ji,jj,jk)
+               zavm  = zsqen * zstm(ji,jj,jk)
+               p_avt(ji,jj,jk) = MAX( zavt, avtb(jk) ) * wmask(ji,jj,jk) ! apply mask for zdfmxl routine
+               p_avm(ji,jj,jk) = MAX( zavm, avmb(jk) )                   ! Note that avm is not masked at the surface and the bottom
             END DO
          END DO
       END DO
-      !
-      ! Lateral boundary conditions (sign unchanged)
-      avt(:,:,1)  = 0._wp
-      CALL lbc_lnk( avm, 'W', 1. )   ;   CALL lbc_lnk( avt, 'W', 1. )
-
-      DO jk = 2, jpkm1            !* vertical eddy viscosity at u- and v-points
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               avmu(ji,jj,jk) = 0.5 * ( avm(ji,jj,jk) + avm(ji+1,jj  ,jk) ) * umask(ji,jj,jk)
-               avmv(ji,jj,jk) = 0.5 * ( avm(ji,jj,jk) + avm(ji  ,jj+1,jk) ) * vmask(ji,jj,jk)
-            END DO
-         END DO
-      END DO
-      avmu(:,:,1) = 0._wp             ;   avmv(:,:,1) = 0._wp                 ! set surface to zero
-      CALL lbc_lnk( avmu, 'U', 1. )   ;   CALL lbc_lnk( avmv, 'V', 1. )       ! Lateral boundary conditions
-
+      p_avt(:,:,1) = 0._wp
+      !
       IF(ln_ctl) THEN
-         CALL prt_ctl( tab3d_1=en  , clinfo1=' gls  - e: ', tab3d_2=avt, clinfo2=' t: ', ovlap=1, kdim=jpk)
-         CALL prt_ctl( tab3d_1=avmu, clinfo1=' gls  - u: ', mask1=umask,                   &
-            &          tab3d_2=avmv, clinfo2=       ' v: ', mask2=vmask, ovlap=1, kdim=jpk )
+         CALL prt_ctl( tab3d_1=en   , clinfo1=' gls  - e: ', tab3d_2=p_avt, clinfo2=' t: ', ovlap=1, kdim=jpk)
+         CALL prt_ctl( tab3d_1=p_avm, clinfo1=' gls  - m: ', ovlap=1, kdim=jpk )
       ENDIF
       !
-      avt_k (:,:,:) = avt (:,:,:)
-      avm_k (:,:,:) = avm (:,:,:)
-      avmu_k(:,:,:) = avmu(:,:,:)
-      avmv_k(:,:,:) = avmv(:,:,:)
-      !
-      CALL wrk_dealloc( jpi,jpj,       zdep, zkar, zflxs, zhsro )
-      CALL wrk_dealloc( jpi,jpj,jpk,   eb, mxlb, shear, eps, zwall_psi, z_elem_a, z_elem_b, z_elem_c, psi )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('zdf_gls')
-      !
+      IF( ln_timing )   CALL timing_stop('zdf_gls')
       !
    END SUBROUTINE zdf_gls
@@ -838,8 +833,7 @@
       !!                     
       !! ** Purpose :   Initialization of the vertical eddy diffivity and 
-      !!      viscosity when using a gls turbulent closure scheme
+      !!              viscosity computed using a GLS turbulent closure scheme
       !!
       !! ** Method  :   Read the namzdf_gls namelist and check the parameters
-      !!      called at the first timestep (nit000)
       !!
       !! ** input   :   Namlist namzdf_gls
@@ -848,7 +842,4 @@
       !!
       !!----------------------------------------------------------------------
-      USE dynzdf_exp
-      USE trazdf_exp
-      !
       INTEGER ::   jk    ! dummy loop indices
       INTEGER ::   ios   ! Local integer output status for namelist read
@@ -862,5 +853,5 @@
       !!----------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('zdf_gls_init')
+      IF( ln_timing )   CALL timing_start('zdf_gls_init')
       !
       REWIND( numnam_ref )              ! Namelist namzdf_gls in reference namelist : Vertical eddy diffivity and viscosity using gls turbulent closure scheme
@@ -875,5 +866,5 @@
       IF(lwp) THEN                     !* Control print
          WRITE(numout,*)
-         WRITE(numout,*) 'zdf_gls_init : gls turbulent closure scheme'
+         WRITE(numout,*) 'zdf_gls_init : GLS turbulent closure scheme'
          WRITE(numout,*) '~~~~~~~~~~~~'
          WRITE(numout,*) '   Namelist namzdf_gls : set gls mixing parameters'
@@ -892,17 +883,21 @@
          WRITE(numout,*) '      Type of closure                               nn_clos        = ', nn_clos
          WRITE(numout,*) '      Surface roughness (m)                         rn_hsro        = ', rn_hsro
-         WRITE(numout,*) '      Bottom roughness (m) (nambfr namelist)        rn_bfrz0       = ', rn_bfrz0
+         WRITE(numout,*)
+         WRITE(numout,*) '   Namelist namdrg_top/_bot:   used values:'
+         WRITE(numout,*) '      top    ocean cavity roughness (m)             rn_z0(_top)   = ', r_z0_top
+         WRITE(numout,*) '      Bottom seafloor     roughness (m)             rn_z0(_bot)   = ', r_z0_bot
+         WRITE(numout,*)
       ENDIF
 
-      !                                !* allocate gls arrays
+      !                                !* allocate GLS arrays
       IF( zdf_gls_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_gls_init : unable to allocate arrays' )
 
       !                                !* Check of some namelist values
-      IF( nn_bc_surf < 0 .OR. nn_bc_surf > 1 ) CALL ctl_stop( 'zdf_gls_init: bad flag: nn_bc_surf is 0 or 1' )
-      IF( nn_bc_surf < 0 .OR. nn_bc_surf > 1 ) CALL ctl_stop( 'zdf_gls_init: bad flag: nn_bc_surf is 0 or 1' )
-      IF( nn_z0_met < 0 .OR. nn_z0_met > 3 ) CALL ctl_stop( 'zdf_gls_init: bad flag: nn_z0_met is 0, 1, 2 or 3' )
-      IF( nn_z0_met == 3 .AND. .NOT.ln_wave ) CALL ctl_stop( 'zdf_gls_init: nn_z0_met=3 requires ln_wave=T' )
-      IF( nn_stab_func  < 0 .OR. nn_stab_func  > 3 ) CALL ctl_stop( 'zdf_gls_init: bad flag: nn_stab_func is 0, 1, 2 and 3' )
-      IF( nn_clos       < 0 .OR. nn_clos       > 3 ) CALL ctl_stop( 'zdf_gls_init: bad flag: nn_clos is 0, 1, 2 or 3' )
+      IF( nn_bc_surf < 0   .OR. nn_bc_surf   > 1 )   CALL ctl_stop( 'zdf_gls_init: bad flag: nn_bc_surf is 0 or 1' )
+      IF( nn_bc_surf < 0   .OR. nn_bc_surf   > 1 )   CALL ctl_stop( 'zdf_gls_init: bad flag: nn_bc_surf is 0 or 1' )
+      IF( nn_z0_met  < 0   .OR. nn_z0_met    > 3 )   CALL ctl_stop( 'zdf_gls_init: bad flag: nn_z0_met is 0, 1, 2 or 3' )
+      IF( nn_z0_met == 3  .AND. .NOT.ln_wave     )   CALL ctl_stop( 'zdf_gls_init: nn_z0_met=3 requires ln_wave=T' )
+      IF( nn_stab_func < 0 .OR. nn_stab_func > 3 )   CALL ctl_stop( 'zdf_gls_init: bad flag: nn_stab_func is 0, 1, 2 and 3' )
+      IF( nn_clos      < 0 .OR. nn_clos      > 3 )   CALL ctl_stop( 'zdf_gls_init: bad flag: nn_clos is 0, 1, 2 or 3' )
 
       SELECT CASE ( nn_clos )          !* set the parameters for the chosen closure
@@ -910,5 +905,6 @@
       CASE( 0 )                              ! k-kl  (Mellor-Yamada)
          !
-         IF(lwp) WRITE(numout,*) 'The choosen closure is k-kl closed to the classical Mellor-Yamada'
+         IF(lwp) WRITE(numout,*) '   ==>>   k-kl closure chosen (i.e. closed to the classical Mellor-Yamada)'
+         IF(lwp) WRITE(numout,*)
          rpp     = 0._wp
          rmm     = 1._wp
@@ -928,5 +924,6 @@
       CASE( 1 )                              ! k-eps
          !
-         IF(lwp) WRITE(numout,*) 'The choosen closure is k-eps'
+         IF(lwp) WRITE(numout,*) '   ==>>   k-eps closure chosen'
+         IF(lwp) WRITE(numout,*)
          rpp     =  3._wp
          rmm     =  1.5_wp
@@ -946,5 +943,6 @@
       CASE( 2 )                              ! k-omega
          !
-         IF(lwp) WRITE(numout,*) 'The choosen closure is k-omega'
+         IF(lwp) WRITE(numout,*) '   ==>>   k-omega closure chosen'
+         IF(lwp) WRITE(numout,*)
          rpp     = -1._wp
          rmm     =  0.5_wp
@@ -964,5 +962,6 @@
       CASE( 3 )                              ! generic
          !
-         IF(lwp) WRITE(numout,*) 'The choosen closure is generic'
+         IF(lwp) WRITE(numout,*) '   ==>>   generic closure chosen'
+         IF(lwp) WRITE(numout,*)
          rpp     = 2._wp
          rmm     = 1._wp
@@ -987,5 +986,5 @@
       CASE ( 0 )                             ! Galperin stability functions
          !
-         IF(lwp) WRITE(numout,*) 'Stability functions from Galperin'
+         IF(lwp) WRITE(numout,*) '   ==>>   Stability functions from Galperin'
          rc2     =  0._wp
          rc3     =  0._wp
@@ -999,5 +998,5 @@
       CASE ( 1 )                             ! Kantha-Clayson stability functions
          !
-         IF(lwp) WRITE(numout,*) 'Stability functions from Kantha-Clayson'
+         IF(lwp) WRITE(numout,*) '   ==>>   Stability functions from Kantha-Clayson'
          rc2     =  0.7_wp
          rc3     =  0.2_wp
@@ -1011,5 +1010,5 @@
       CASE ( 2 )                             ! Canuto A stability functions
          !
-         IF(lwp) WRITE(numout,*) 'Stability functions from Canuto A'
+         IF(lwp) WRITE(numout,*) '   ==>>   Stability functions from Canuto A'
          rs0 = 1.5_wp * rl1 * rl5*rl5
          rs1 = -rl4*(rl6+rl7) + 2._wp*rl4*rl5*(rl1-(1._wp/3._wp)*rl2-rl3) + 1.5_wp*rl1*rl5*rl8
@@ -1035,5 +1034,5 @@
       CASE ( 3 )                             ! Canuto B stability functions
          !
-         IF(lwp) WRITE(numout,*) 'Stability functions from Canuto B'
+         IF(lwp) WRITE(numout,*) '   ==>>   Stability functions from Canuto B'
          rs0 = 1.5_wp * rm1 * rm5*rm5
          rs1 = -rm4 * (rm6+rm7) + 2._wp * rm4*rm5*(rm1-(1._wp/3._wp)*rm2-rm3) + 1.5_wp * rm1*rm5*rm8
@@ -1079,10 +1078,9 @@
          rl_sf = vkarmn
       ELSE
-         rl_sf = rc0 * SQRT(rc0/rcm_sf) * SQRT( ( (1._wp + 4._wp*rmm + 8._wp*rmm**2_wp)*rsc_tke          &
-                 &                                       + 12._wp * rsc_psi0*rpsi2 - (1._wp + 4._wp*rmm) &
-                 &                                                *SQRT(rsc_tke*(rsc_tke                 &
-                 &                                                   + 24._wp*rsc_psi0*rpsi2)) )         &
-                 &                                         /(12._wp*rnn**2.)                             &
-                 &                                       )
+         rl_sf = rc0 * SQRT(rc0/rcm_sf) * SQRT( ( (1._wp + 4._wp*rmm + 8._wp*rmm**2_wp) * rsc_tke        &
+            &                                            + 12._wp*rsc_psi0*rpsi2 - (1._wp + 4._wp*rmm)   &
+            &                                                     *SQRT(rsc_tke*(rsc_tke                 &
+            &                                                        + 24._wp*rsc_psi0*rpsi2)) )         &
+            &                                              /(12._wp*rnn**2.)                             )
       ENDIF
 
@@ -1090,23 +1088,21 @@
       IF(lwp) THEN                     !* Control print
          WRITE(numout,*)
-         WRITE(numout,*) 'Limit values'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) 'Parameter  m = ',rmm
-         WRITE(numout,*) 'Parameter  n = ',rnn
-         WRITE(numout,*) 'Parameter  p = ',rpp
-         WRITE(numout,*) 'rpsi1   = ',rpsi1
-         WRITE(numout,*) 'rpsi2   = ',rpsi2
-         WRITE(numout,*) 'rpsi3m  = ',rpsi3m
-         WRITE(numout,*) 'rpsi3p  = ',rpsi3p
-         WRITE(numout,*) 'rsc_tke = ',rsc_tke
-         WRITE(numout,*) 'rsc_psi = ',rsc_psi
-         WRITE(numout,*) 'rsc_psi0 = ',rsc_psi0
-         WRITE(numout,*) 'rc0     = ',rc0
+         WRITE(numout,*) '   Limit values :'
+         WRITE(numout,*) '      Parameter  m = ', rmm
+         WRITE(numout,*) '      Parameter  n = ', rnn
+         WRITE(numout,*) '      Parameter  p = ', rpp
+         WRITE(numout,*) '      rpsi1    = ', rpsi1
+         WRITE(numout,*) '      rpsi2    = ', rpsi2
+         WRITE(numout,*) '      rpsi3m   = ', rpsi3m
+         WRITE(numout,*) '      rpsi3p   = ', rpsi3p
+         WRITE(numout,*) '      rsc_tke  = ', rsc_tke
+         WRITE(numout,*) '      rsc_psi  = ', rsc_psi
+         WRITE(numout,*) '      rsc_psi0 = ', rsc_psi0
+         WRITE(numout,*) '      rc0      = ', rc0
          WRITE(numout,*)
-         WRITE(numout,*) 'Shear free turbulence parameters:'
-         WRITE(numout,*) 'rcm_sf  = ',rcm_sf
-         WRITE(numout,*) 'ra_sf   = ',ra_sf
-         WRITE(numout,*) 'rl_sf   = ',rl_sf
-         WRITE(numout,*)
+         WRITE(numout,*) '   Shear free turbulence parameters:'
+         WRITE(numout,*) '      rcm_sf   = ', rcm_sf
+         WRITE(numout,*) '      ra_sf    = ', ra_sf
+         WRITE(numout,*) '      rl_sf    = ', rl_sf
       ENDIF
 
@@ -1123,22 +1119,16 @@
       rsbc_psi1 = -0.5_wp * rdt * rc0**(rpp-2._wp*rmm) / rsc_psi
       rsbc_psi2 = -0.5_wp * rdt * rc0**rpp * rnn * vkarmn**rnn / rsc_psi ! Neumann + NO Wave breaking 
-
+      !
       rfact_tke = -0.5_wp / rsc_tke * rdt                                ! Cst used for the Diffusion term of tke
       rfact_psi = -0.5_wp / rsc_psi * rdt                                ! Cst used for the Diffusion term of tke
-
+      !
       !                                !* Wall proximity function
-      zwall (:,:,:) = 1._wp * tmask(:,:,:)
-
-      !                                !* set vertical eddy coef. to the background value
-      DO jk = 1, jpk
-         avt (:,:,jk) = avtb(jk) * tmask(:,:,jk)
-         avm (:,:,jk) = avmb(jk) * tmask(:,:,jk)
-         avmu(:,:,jk) = avmb(jk) * umask(:,:,jk)
-         avmv(:,:,jk) = avmb(jk) * vmask(:,:,jk)
-      END DO
-      !                              
-      CALL gls_rst( nit000, 'READ' )   !* read or initialize all required files
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('zdf_gls_init')
+!!gm tmask or wmask ????
+      zwall(:,:,:) = 1._wp * tmask(:,:,:)
+
+      !                                !* read or initialize all required files  
+      CALL gls_rst( nit000, 'READ' )      ! (en, avt_k, avm_k, hmxl_n)
+      !
+      IF( ln_timing )   CALL timing_stop('zdf_gls_init')
       !
    END SUBROUTINE zdf_gls_init
@@ -1155,9 +1145,11 @@
       !!                set to rn_emin or recomputed (nn_igls/=0)
       !!----------------------------------------------------------------------
-      INTEGER         , INTENT(in) ::   kt         ! ocean time-step
-      CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
+      USE zdf_oce , ONLY : en, avt_k, avm_k   ! ocean vertical physics
+      !!
+      INTEGER         , INTENT(in) ::   kt     ! ocean time-step
+      CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
       !
       INTEGER ::   jit, jk   ! dummy loop indices
-      INTEGER ::   id1, id2, id3, id4, id5, id6
+      INTEGER ::   id1, id2, id3, id4
       INTEGER ::   ji, jj, ikbu, ikbv
       REAL(wp)::   cbx, cby
@@ -1167,32 +1159,27 @@
          !                                   ! ---------------
          IF( ln_rstart ) THEN                   !* Read the restart file
-            id1 = iom_varid( numror, 'en'   , ldstop = .FALSE. )
-            id2 = iom_varid( numror, 'avt'  , ldstop = .FALSE. )
-            id3 = iom_varid( numror, 'avm'  , ldstop = .FALSE. )
-            id4 = iom_varid( numror, 'avmu' , ldstop = .FALSE. )
-            id5 = iom_varid( numror, 'avmv' , ldstop = .FALSE. )
-            id6 = iom_varid( numror, 'mxln' , ldstop = .FALSE. )
+            id1 = iom_varid( numror, 'en'    , ldstop = .FALSE. )
+            id2 = iom_varid( numror, 'avt_k' , ldstop = .FALSE. )
+            id3 = iom_varid( numror, 'avm_k' , ldstop = .FALSE. )
+            id4 = iom_varid( numror, 'hmxl_n', ldstop = .FALSE. )
             !
-            IF( MIN( id1, id2, id3, id4, id5, id6 ) > 0 ) THEN        ! all required arrays exist
+            IF( MIN( id1, id2, id3, id4 ) > 0 ) THEN        ! all required arrays exist
                CALL iom_get( numror, jpdom_autoglo, 'en'    , en     )
-               CALL iom_get( numror, jpdom_autoglo, 'avt'   , avt    )
-               CALL iom_get( numror, jpdom_autoglo, 'avm'   , avm    )
-               CALL iom_get( numror, jpdom_autoglo, 'avmu'  , avmu   )
-               CALL iom_get( numror, jpdom_autoglo, 'avmv'  , avmv   )
-               CALL iom_get( numror, jpdom_autoglo, 'mxln'  , mxln   )
+               CALL iom_get( numror, jpdom_autoglo, 'avt_k' , avt_k  )
+               CALL iom_get( numror, jpdom_autoglo, 'avm_k' , avm_k  )
+               CALL iom_get( numror, jpdom_autoglo, 'hmxl_n', hmxl_n )
             ELSE                        
-               IF(lwp) WRITE(numout,*) ' ===>>>> : previous run without gls scheme, en and mxln computed by iterative loop'
-               en  (:,:,:) = rn_emin
-               mxln(:,:,:) = 0.05        
-               avt_k (:,:,:) = avt (:,:,:)
-               avm_k (:,:,:) = avm (:,:,:)
-               avmu_k(:,:,:) = avmu(:,:,:)
-               avmv_k(:,:,:) = avmv(:,:,:)
-               DO jit = nit000 + 1, nit000 + 10   ;   CALL zdf_gls( jit )   ;   END DO
+               IF(lwp) WRITE(numout,*)
+               IF(lwp) WRITE(numout,*) '   ==>>   previous run without GLS scheme, set en and hmxl_n to background values'
+               en    (:,:,:) = rn_emin
+               hmxl_n(:,:,:) = 0.05_wp
+               ! avt_k, avm_k already set to the background value in zdf_phy_init
             ENDIF
          ELSE                                   !* Start from rest
-            IF(lwp) WRITE(numout,*) ' ===>>>> : Initialisation of en and mxln by background values'
-            en  (:,:,:) = rn_emin
-            mxln(:,:,:) = 0.05       
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '   ==>>   start from rest, set en and hmxl_n by background values'
+            en    (:,:,:) = rn_emin
+            hmxl_n(:,:,:) = 0.05_wp
+            ! avt_k, avm_k already set to the background value in zdf_phy_init
          ENDIF
          !
@@ -1200,33 +1187,12 @@
          !                                   ! -------------------
          IF(lwp) WRITE(numout,*) '---- gls-rst ----'
-         CALL iom_rstput( kt, nitrst, numrow, 'en'   , en     ) 
-         CALL iom_rstput( kt, nitrst, numrow, 'avt'  , avt_k  )
-         CALL iom_rstput( kt, nitrst, numrow, 'avm'  , avm_k  )
-         CALL iom_rstput( kt, nitrst, numrow, 'avmu' , avmu_k ) 
-         CALL iom_rstput( kt, nitrst, numrow, 'avmv' , avmv_k )
-         CALL iom_rstput( kt, nitrst, numrow, 'mxln' , mxln   )
+         CALL iom_rstput( kt, nitrst, numrow, 'en'    , en     ) 
+         CALL iom_rstput( kt, nitrst, numrow, 'avt_k' , avt_k  )
+         CALL iom_rstput( kt, nitrst, numrow, 'avm_k' , avm_k  )
+         CALL iom_rstput( kt, nitrst, numrow, 'hmxl_n', hmxl_n )
          !
       ENDIF
       !
    END SUBROUTINE gls_rst
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Dummy module :                                        NO TKE scheme
-   !!----------------------------------------------------------------------
-   LOGICAL, PUBLIC, PARAMETER ::   lk_zdfgls = .FALSE.   !: TKE flag
-CONTAINS
-   SUBROUTINE zdf_gls_init           ! Empty routine
-      WRITE(*,*) 'zdf_gls_init: You should not have seen this print! error?'
-   END SUBROUTINE zdf_gls_init
-   SUBROUTINE zdf_gls( kt )          ! Empty routine
-      WRITE(*,*) 'zdf_gls: You should not have seen this print! error?', kt
-   END SUBROUTINE zdf_gls
-   SUBROUTINE gls_rst( kt, cdrw )          ! Empty routine
-      INTEGER         , INTENT(in) ::   kt         ! ocean time-step
-      CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
-      WRITE(*,*) 'gls_rst: You should not have seen this print! error?', kt, cdrw
-   END SUBROUTINE gls_rst
-#endif
 
    !!======================================================================
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfini.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfini.F90	(revision 9018)
+++ 	(revision )
@@ -1,180 +1,0 @@
-MODULE zdfini
-   !!======================================================================
-   !!                      ***  MODULE  zdfini  ***
-   !! Ocean physics :   read vertical mixing namelist and check consistancy
-   !!======================================================================
-   !! History :  8.0  ! 1997-06  (G. Madec)  Original code from inimix
-   !!            1.0  ! 2002-08  (G. Madec)  F90 : free form
-   !!             -   ! 2005-06  (C. Ethe) KPP scheme
-   !!             -   ! 2009-07  (G. Madec) add avmb, avtb in restart for cen2 advection
-   !!            3.7  ! 2014-12  (G. Madec) remove KPP scheme
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   zdf_init    : initialization, namelist read, and parameters control
-   !!----------------------------------------------------------------------
-   USE par_oce         ! mesh and scale factors
-   USE zdf_oce         ! TKE vertical mixing          
-   USE sbc_oce         ! surface module (only for nn_isf in the option compatibility test)
-   USE zdftke          ! TKE vertical mixing
-   USE zdfgls          ! GLS vertical mixing
-   USE zdfric          ! Richardson vertical mixing   
-   USE zdfddm          ! double diffusion mixing      
-   USE zdfevd          ! enhanced vertical diffusion  
-   USE tranpc          ! convection: non penetrative adjustment
-   USE ldfslp          ! iso-neutral slopes
-   !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! IOM library
-   USE lib_mpp         ! distribued memory computing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   zdf_init   ! routine called by opa.F90
-   
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE zdf_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE zdf_init  ***
-      !! 
-      !! ** Purpose :   initializations of the vertical ocean physics
-      !!
-      !! ** Method  :   Read namelist namzdf, control logicals 
-      !!----------------------------------------------------------------------
-      INTEGER ::   ioptio, ios       ! local integers
-      !!
-      NAMELIST/namzdf/ rn_avm0, rn_avt0, nn_avb, nn_havtb, ln_zdfexp, nn_zdfexp,  &
-         &        ln_zdfevd, nn_evdm, rn_avevd, ln_zdfnpc, nn_npc, nn_npcp,       &
-         &        ln_zdfqiao
-      !!----------------------------------------------------------------------
-
-      REWIND( numnam_ref )              ! Namelist namzdf in reference namelist : Vertical mixing parameters
-      READ  ( numnam_ref, namzdf, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf in reference namelist', lwp )
-
-      REWIND( numnam_cfg )              ! Namelist namzdf in reference namelist : Vertical mixing parameters
-      READ  ( numnam_cfg, namzdf, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf in configuration namelist', lwp )
-      IF(lwm) WRITE ( numond, namzdf )
-
-      IF(lwp) THEN               !* Parameter print
-         WRITE(numout,*)
-         WRITE(numout,*) 'zdf_init : vertical physics'
-         WRITE(numout,*) '~~~~~~~~'
-         WRITE(numout,*) '   Namelist namzdf : set vertical mixing mixing parameters'
-         WRITE(numout,*) '      vertical eddy viscosity             rn_avm0   = ', rn_avm0
-         WRITE(numout,*) '      vertical eddy diffusivity           rn_avt0   = ', rn_avt0
-         WRITE(numout,*) '      constant background or profile      nn_avb    = ', nn_avb
-         WRITE(numout,*) '      horizontal variation for avtb       nn_havtb  = ', nn_havtb
-         WRITE(numout,*) '      time splitting / backward scheme    ln_zdfexp = ', ln_zdfexp
-         WRITE(numout,*) '      number of time step                 nn_zdfexp = ', nn_zdfexp
-         WRITE(numout,*) '      enhanced vertical diffusion         ln_zdfevd = ', ln_zdfevd
-         WRITE(numout,*) '         applied on momentum (=1/0)       nn_evdm   = ', nn_evdm
-         WRITE(numout,*) '      vertical coefficient for evd        rn_avevd  = ', rn_avevd
-         WRITE(numout,*) '      non-penetrative convection (npc)    ln_zdfnpc = ', ln_zdfnpc
-         WRITE(numout,*) '      npc call  frequency                 nn_npc    = ', nn_npc
-         WRITE(numout,*) '      npc print frequency                 nn_npcp   = ', nn_npcp
-         WRITE(numout,*) '      Qiao formulation flag               ln_zdfqiao=', ln_zdfqiao
-      ENDIF
-
-      !                          !* Parameter & logical controls
-      !                          !  ----------------------------
-      !
-      !                               ! ... check of vertical mixing scheme on tracers
-      !                                              ==> will be done in trazdf module
-      !
-      !                               ! ... check of mixing coefficient
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) '   vertical mixing option :'
-      ioptio = 0
-      IF( lk_zdfcst ) THEN
-         IF(lwp) WRITE(numout,*) '      constant eddy diffusion coefficients'
-         ioptio = ioptio+1
-      ENDIF
-      IF( lk_zdfric ) THEN
-         IF(lwp) WRITE(numout,*) '      Richardson dependent eddy coefficients'
-         ioptio = ioptio+1
-      ENDIF
-      IF( lk_zdftke ) THEN
-         IF(lwp) WRITE(numout,*) '      TKE dependent eddy coefficients'
-         ioptio = ioptio+1
-      ENDIF
-      IF( lk_zdfgls ) THEN
-         IF(lwp) WRITE(numout,*) '      GLS dependent eddy coefficients'
-         ioptio = ioptio+1
-      ENDIF
-      IF( ioptio == 0 .OR. ioptio > 1 )   &
-         &   CALL ctl_stop( ' one and only one vertical diffusion option has to be defined ' )
-      IF( ( lk_zdfric .OR. lk_zdfgls ) .AND. ln_isfcav )   &
-         &   CALL ctl_stop( ' only zdfcst and zdftke were tested with ice shelves cavities ' )
-      !
-      !                               ! ... Convection
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) '   convection :'
-      !
-#if defined key_top
-      IF( ln_zdfnpc )   CALL ctl_stop( ' zdf_init: npc scheme is not working with key_top' )
-#endif
-      !
-      ioptio = 0
-      IF( ln_zdfnpc ) THEN
-         IF(lwp) WRITE(numout,*) '      use non penetrative convective scheme'
-         ioptio = ioptio+1
-      ENDIF
-      IF( ln_zdfevd ) THEN
-         IF(lwp) WRITE(numout,*) '      use enhanced vertical dif. scheme'
-         ioptio = ioptio+1
-      ENDIF
-      IF( lk_zdftke ) THEN
-         IF(lwp) WRITE(numout,*) '      use the 1.5 turbulent closure'
-      ENDIF
-      IF( lk_zdfgls ) THEN
-         IF(lwp) WRITE(numout,*) '      use the GLS closure scheme'
-      ENDIF
-      IF ( ioptio > 1 )   CALL ctl_stop( ' chose between ln_zdfnpc and ln_zdfevd' )
-      IF( ioptio == 0 .AND. .NOT.( lk_zdftke .OR. lk_zdfgls ) )           &
-         CALL ctl_stop( ' except for TKE or GLS physics, a convection scheme is',   &
-         &              ' required: ln_zdfevd or ln_zdfnpc logicals' )
-
-      !                               !* Background eddy viscosity and diffusivity profil
-      IF( nn_avb == 0 ) THEN                ! Define avmb, avtb from namelist parameter
-         avmb(:) = rn_avm0
-         avtb(:) = rn_avt0                     
-      ELSE                                  ! Background profile of avt (fit a theoretical/observational profile (Krauss 1990)
-         avmb(:) = rn_avm0
-         avtb(:) = rn_avt0 + ( 3.e-4_wp - 2._wp * rn_avt0 ) * 1.e-4_wp * gdepw_1d(:)   ! m2/s
-         IF(ln_sco .AND. lwp)   CALL ctl_warn( 'avtb profile not valid in sco' )
-      ENDIF
-      !
-      IF( ln_rstart ) THEN                  !  Read avmb, avtb in restart (if exist)
-         ! if ln_traadv_cen, avmb, avtb have been modified in traadv_cen2 module. 
-         ! To ensure the restartability, avmb & avtb are written in the restart 
-         ! file in traadv_cen2 end read here. 
-         IF( iom_varid( numror, 'avmb', ldstop = .FALSE. ) > 0 ) THEN
-            CALL iom_get( numror, jpdom_unknown, 'avmb', avmb )
-            CALL iom_get( numror, jpdom_unknown, 'avtb', avtb )
-         ENDIF
-      ENDIF
-      !                                     ! 2D shape of the avtb
-      avtb_2d(:,:) = 1.e0                        ! uniform 
-      !
-      IF( nn_havtb == 1 ) THEN                   ! decrease avtb in the equatorial band
-           !  -15S -5S : linear decrease from avt0 to avt0/10.
-           !  -5S  +5N : cst value avt0/10.
-           !   5N  15N : linear increase from avt0/10, to avt0
-           WHERE(-15. <= gphit .AND. gphit < -5 )   avtb_2d = (1.  - 0.09 * (gphit + 15.))
-           WHERE( -5. <= gphit .AND. gphit <  5 )   avtb_2d =  0.1
-           WHERE(  5. <= gphit .AND. gphit < 15 )   avtb_2d = (0.1 + 0.09 * (gphit -  5.))
-      ENDIF
-      !
-   END SUBROUTINE zdf_init
-
-   !!======================================================================
-END MODULE zdfini
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfiwm.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfiwm.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfiwm.F90	(revision 9019)
@@ -0,0 +1,486 @@
+MODULE zdfiwm
+   !!========================================================================
+   !!                       ***  MODULE  zdfiwm  ***
+   !! Ocean physics: Internal gravity wave-driven vertical mixing
+   !!========================================================================
+   !! History :  1.0  !  2004-04  (L. Bessieres, G. Madec)  Original code
+   !!             -   !  2006-08  (A. Koch-Larrouy)  Indonesian strait
+   !!            3.3  !  2010-10  (C. Ethe, G. Madec)  reorganisation of initialisation phase
+   !!            3.6  !  2016-03  (C. de Lavergne)  New param: internal wave-driven mixing 
+   !!            4.0  !  2017-04  (G. Madec)  renamed module, remove the old param. and the CPP keys
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   zdf_iwm       : global     momentum & tracer Kz with wave induced Kz
+   !!   zdf_iwm_init  : global     momentum & tracer Kz with wave induced Kz
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain variables
+   USE zdf_oce        ! ocean vertical physics variables
+   USE zdfddm         ! ocean vertical physics: double diffusive mixing
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE eosbn2         ! ocean equation of state
+   USE phycst         ! physical constants
+   USE prtctl         ! Print control
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O Manager
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! work arrays
+   USE timing         ! Timing
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   zdf_iwm        ! called in step module 
+   PUBLIC   zdf_iwm_init   ! called in nemogcm module 
+
+   !                      !!* Namelist  namzdf_iwm : internal wave-driven mixing *
+   INTEGER ::  nn_zpyc     ! pycnocline-intensified mixing energy proportional to N (=1) or N^2 (=2)
+   LOGICAL ::  ln_mevar    ! variable (=T) or constant (=F) mixing efficiency
+   LOGICAL ::  ln_tsdiff   ! account for differential T/S wave-driven mixing (=T) or not (=F)
+
+   REAL(wp)::  r1_6 = 1._wp / 6._wp
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ebot_iwm   ! power available from high-mode wave breaking (W/m2)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   epyc_iwm   ! power available from low-mode, pycnocline-intensified wave breaking (W/m2)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ecri_iwm   ! power available from low-mode, critical slope wave breaking (W/m2)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hbot_iwm   ! WKB decay scale for high-mode energy dissipation (m)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hcri_iwm   ! decay scale for low-mode critical slope dissipation (m)
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2016)
+   !! $Id: zdfiwm.F90 8093 2017-05-30 08:13:14Z gm $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION zdf_iwm_alloc()
+      !!----------------------------------------------------------------------
+      !!                ***  FUNCTION zdf_iwm_alloc  ***
+      !!----------------------------------------------------------------------
+      ALLOCATE( ebot_iwm(jpi,jpj),  epyc_iwm(jpi,jpj),  ecri_iwm(jpi,jpj) ,     &
+      &         hbot_iwm(jpi,jpj),  hcri_iwm(jpi,jpj)                     , STAT=zdf_iwm_alloc )
+      !
+      IF( lk_mpp             )   CALL mpp_sum ( zdf_iwm_alloc )
+      IF( zdf_iwm_alloc /= 0 )   CALL ctl_warn('zdf_iwm_alloc: failed to allocate arrays')
+   END FUNCTION zdf_iwm_alloc
+
+
+   SUBROUTINE zdf_iwm( kt, p_avm, p_avt, p_avs )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_iwm  ***
+      !!                   
+      !! ** Purpose :   add to the vertical mixing coefficients the effect of
+      !!              breaking internal waves.
+      !!
+      !! ** Method  : - internal wave-driven vertical mixing is given by:
+      !!                  Kz_wave = min(  100 cm2/s, f(  Reb = zemx_iwm /( Nu * N^2 )  )
+      !!              where zemx_iwm is the 3D space distribution of the wave-breaking 
+      !!              energy and Nu the molecular kinematic viscosity.
+      !!              The function f(Reb) is linear (constant mixing efficiency)
+      !!              if the namelist parameter ln_mevar = F and nonlinear if ln_mevar = T.
+      !!
+      !!              - Compute zemx_iwm, the 3D power density that allows to compute
+      !!              Reb and therefrom the wave-induced vertical diffusivity.
+      !!              This is divided into three components:
+      !!                 1. Bottom-intensified low-mode dissipation at critical slopes
+      !!                     zemx_iwm(z) = ( ecri_iwm / rau0 ) * EXP( -(H-z)/hcri_iwm )
+      !!                                   / ( 1. - EXP( - H/hcri_iwm ) ) * hcri_iwm
+      !!              where hcri_iwm is the characteristic length scale of the bottom 
+      !!              intensification, ecri_iwm a map of available power, and H the ocean depth.
+      !!                 2. Pycnocline-intensified low-mode dissipation
+      !!                     zemx_iwm(z) = ( epyc_iwm / rau0 ) * ( sqrt(rn2(z))^nn_zpyc )
+      !!                                   / SUM( sqrt(rn2(z))^nn_zpyc * e3w(z) )
+      !!              where epyc_iwm is a map of available power, and nn_zpyc
+      !!              is the chosen stratification-dependence of the internal wave
+      !!              energy dissipation.
+      !!                 3. WKB-height dependent high mode dissipation
+      !!                     zemx_iwm(z) = ( ebot_iwm / rau0 ) * rn2(z) * EXP(-z_wkb(z)/hbot_iwm)
+      !!                                   / SUM( rn2(z) * EXP(-z_wkb(z)/hbot_iwm) * e3w(z) )
+      !!              where hbot_iwm is the characteristic length scale of the WKB bottom 
+      !!              intensification, ebot_iwm is a map of available power, and z_wkb is the
+      !!              WKB-stretched height above bottom defined as
+      !!                    z_wkb(z) = H * SUM( sqrt(rn2(z'>=z)) * e3w(z'>=z) )
+      !!                                 / SUM( sqrt(rn2(z'))    * e3w(z')    )
+      !!
+      !!              - update the model vertical eddy viscosity and diffusivity: 
+      !!                     avt  = avt  +    av_wave
+      !!                     avm  = avm  +    av_wave
+      !!
+      !!              - if namelist parameter ln_tsdiff = T, account for differential mixing:
+      !!                     avs  = avt  +    av_wave * diffusivity_ratio(Reb)
+      !!
+      !! ** Action  : - avt, avs, avm, increased by tide internal wave-driven mixing    
+      !!
+      !! References :  de Lavergne et al. 2015, JPO; 2016, in prep.
+      !!----------------------------------------------------------------------
+      INTEGER                    , INTENT(in   ) ::   kt             ! ocean time step
+      REAL(wp), DIMENSION(:,:,:) , INTENT(inout) ::   p_avm          ! momentum Kz (w-points)
+      REAL(wp), DIMENSION(:,:,:) , INTENT(inout) ::   p_avt, p_avs   ! tracer   Kz (w-points)
+      !
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zztmp        ! scalar workspace
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zfact       ! Used for vertical structure
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zhdep       ! Ocean depth
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwkb        ! WKB-stretched height above bottom
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zweight     ! Weight for high mode vertical distribution
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   znu_t       ! Molecular kinematic viscosity (T grid)
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   znu_w       ! Molecular kinematic viscosity (W grid)
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zReb        ! Turbulence intensity parameter
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zemx_iwm    ! local energy density available for mixing (W/kg)
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zav_ratio   ! S/T diffusivity ratio (only for ln_tsdiff=T)
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zav_wave    ! Internal wave-induced diffusivity
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   z3d  ! 3D workspace used for iom_put 
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:)   ::   z2d  ! 2D     -      -    -     -
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('zdf_iwm')
+      !
+      !                       !* Set to zero the 1st and last vertical levels of appropriate variables
+      zemx_iwm (:,:,1) = 0._wp   ;   zemx_iwm (:,:,jpk) = 0._wp
+      zav_ratio(:,:,1) = 0._wp   ;   zav_ratio(:,:,jpk) = 0._wp
+      zav_wave (:,:,1) = 0._wp   ;   zav_wave (:,:,jpk) = 0._wp
+      !
+      !                       ! ----------------------------- !
+      !                       !  Internal wave-driven mixing  !  (compute zav_wave)
+      !                       ! ----------------------------- !
+      !                             
+      !                       !* Critical slope mixing: distribute energy over the time-varying ocean depth,
+      !                                                 using an exponential decay from the seafloor.
+      DO jj = 1, jpj                ! part independent of the level
+         DO ji = 1, jpi
+            zhdep(ji,jj) = gdepw_0(ji,jj,mbkt(ji,jj)+1)       ! depth of the ocean
+            zfact(ji,jj) = rau0 * (  1._wp - EXP( -zhdep(ji,jj) / hcri_iwm(ji,jj) )  )
+            IF( zfact(ji,jj) /= 0._wp )   zfact(ji,jj) = ecri_iwm(ji,jj) / zfact(ji,jj)
+         END DO
+      END DO
+!!gm gde3w ==>>>  check for ssh taken into account.... seem OK gde3w_n=gdept_n - sshn
+      DO jk = 2, jpkm1              ! complete with the level-dependent part
+         zemx_iwm(:,:,jk) = zfact(:,:) * (  EXP( ( gde3w_n(:,:,jk  ) - zhdep(:,:) ) / hcri_iwm(:,:) )                      &
+            &                             - EXP( ( gde3w_n(:,:,jk-1) - zhdep(:,:) ) / hcri_iwm(:,:) )  ) * wmask(:,:,jk)   &
+            &                          / ( gde3w_n(:,:,jk) - gde3w_n(:,:,jk-1) )
+
+!!gm delta(gde3w_n) = e3t_n  !!  Please verify the grid-point position w versus t-point
+!!gm it seems to me that only 1/hcri_iwm  is used ==>  compute it one for all
+
+      END DO
+
+      !                        !* Pycnocline-intensified mixing: distribute energy over the time-varying 
+      !                        !* ocean depth as proportional to sqrt(rn2)^nn_zpyc
+      !                                          ! (NB: N2 is masked, so no use of wmask here)
+      SELECT CASE ( nn_zpyc )
+      !
+      CASE ( 1 )               ! Dissipation scales as N (recommended)
+         !
+         zfact(:,:) = 0._wp
+         DO jk = 2, jpkm1              ! part independent of the level
+            zfact(:,:) = zfact(:,:) + e3w_n(:,:,jk) * SQRT(  MAX( 0._wp, rn2(:,:,jk) )  ) * wmask(:,:,jk)
+         END DO
+         !
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( zfact(ji,jj) /= 0 )   zfact(ji,jj) = epyc_iwm(ji,jj) / ( rau0 * zfact(ji,jj) )
+            END DO
+         END DO
+         !
+         DO jk = 2, jpkm1              ! complete with the level-dependent part
+            zemx_iwm(:,:,jk) = zemx_iwm(:,:,jk) + zfact(:,:) * SQRT(  MAX( 0._wp, rn2(:,:,jk) )  ) * wmask(:,:,jk)
+         END DO
+         !
+      CASE ( 2 )               ! Dissipation scales as N^2
+         !
+         zfact(:,:) = 0._wp
+         DO jk = 2, jpkm1              ! part independent of the level
+            zfact(:,:) = zfact(:,:) + e3w_n(:,:,jk) * MAX( 0._wp, rn2(:,:,jk) ) * wmask(:,:,jk)
+         END DO
+         !
+         DO jj= 1, jpj
+            DO ji = 1, jpi
+               IF( zfact(ji,jj) /= 0 )   zfact(ji,jj) = epyc_iwm(ji,jj) / ( rau0 * zfact(ji,jj) )
+            END DO
+         END DO
+         !
+         DO jk = 2, jpkm1              ! complete with the level-dependent part
+            zemx_iwm(:,:,jk) = zemx_iwm(:,:,jk) + zfact(:,:) * MAX( 0._wp, rn2(:,:,jk) ) * wmask(:,:,jk)
+         END DO
+         !
+      END SELECT
+
+      !                        !* WKB-height dependent mixing: distribute energy over the time-varying 
+      !                        !* ocean depth as proportional to rn2 * exp(-z_wkb/rn_hbot)
+      !
+      zwkb (:,:,:) = 0._wp
+      zfact(:,:)   = 0._wp
+      DO jk = 2, jpkm1
+         zfact(:,:) = zfact(:,:) + e3w_n(:,:,jk) * SQRT(  MAX( 0._wp, rn2(:,:,jk) )  ) * wmask(:,:,jk)
+         zwkb(:,:,jk) = zfact(:,:)
+      END DO
+!!gm even better:
+!      DO jk = 2, jpkm1
+!         zwkb(:,:) = zwkb(:,:) + e3w_n(:,:,jk) * SQRT(  MAX( 0._wp, rn2(:,:,jk) )  )
+!      END DO
+!      zfact(:,:) = zwkb(:,:,jpkm1)
+!!gm or just use zwkb(k=jpk-1) instead of zfact...
+!!gm
+      !
+      DO jk = 2, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( zfact(ji,jj) /= 0 )   zwkb(ji,jj,jk) = zhdep(ji,jj) * ( zfact(ji,jj) - zwkb(ji,jj,jk) )   &
+                  &                                     * wmask(ji,jj,jk) / zfact(ji,jj)
+            END DO
+         END DO
+      END DO
+      zwkb(:,:,1) = zhdep(:,:) * wmask(:,:,1)
+      !
+      zweight(:,:,:) = 0._wp
+      DO jk = 2, jpkm1
+         zweight(:,:,jk) = MAX( 0._wp, rn2(:,:,jk) ) * hbot_iwm(:,:) * wmask(:,:,jk)                    &
+            &   * (  EXP( -zwkb(:,:,jk) / hbot_iwm(:,:) ) - EXP( -zwkb(:,:,jk-1) / hbot_iwm(:,:) )  )
+      END DO
+      !
+      zfact(:,:) = 0._wp
+      DO jk = 2, jpkm1              ! part independent of the level
+         zfact(:,:) = zfact(:,:) + zweight(:,:,jk)
+      END DO
+      !
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( zfact(ji,jj) /= 0 )   zfact(ji,jj) = ebot_iwm(ji,jj) / ( rau0 * zfact(ji,jj) )
+         END DO
+      END DO
+      !
+      DO jk = 2, jpkm1              ! complete with the level-dependent part
+         zemx_iwm(:,:,jk) = zemx_iwm(:,:,jk) + zweight(:,:,jk) * zfact(:,:) * wmask(:,:,jk)   &
+            &                                / ( gde3w_n(:,:,jk) - gde3w_n(:,:,jk-1) )
+!!gm  use of e3t_n just above?
+      END DO
+      !
+!!gm  this is to be replaced by just a constant value znu=1.e-6 m2/s
+      ! Calculate molecular kinematic viscosity
+      znu_t(:,:,:) = 1.e-4_wp * (  17.91_wp - 0.53810_wp * tsn(:,:,:,jp_tem) + 0.00694_wp * tsn(:,:,:,jp_tem) * tsn(:,:,:,jp_tem)  &
+         &                                  + 0.02305_wp * tsn(:,:,:,jp_sal)  ) * tmask(:,:,:) * r1_rau0
+      DO jk = 2, jpkm1
+         znu_w(:,:,jk) = 0.5_wp * ( znu_t(:,:,jk-1) + znu_t(:,:,jk) ) * wmask(:,:,jk)
+      END DO
+!!gm end
+      !
+      ! Calculate turbulence intensity parameter Reb
+      DO jk = 2, jpkm1
+         zReb(:,:,jk) = zemx_iwm(:,:,jk) / MAX( 1.e-20_wp, znu_w(:,:,jk) * rn2(:,:,jk) )
+      END DO
+      !
+      ! Define internal wave-induced diffusivity
+      DO jk = 2, jpkm1
+         zav_wave(:,:,jk) = znu_w(:,:,jk) * zReb(:,:,jk) * r1_6   ! This corresponds to a constant mixing efficiency of 1/6
+      END DO
+      !
+      IF( ln_mevar ) THEN              ! Variable mixing efficiency case : modify zav_wave in the
+         DO jk = 2, jpkm1              ! energetic (Reb > 480) and buoyancy-controlled (Reb <10.224 ) regimes
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  IF( zReb(ji,jj,jk) > 480.00_wp ) THEN
+                     zav_wave(ji,jj,jk) = 3.6515_wp * znu_w(ji,jj,jk) * SQRT( zReb(ji,jj,jk) )
+                  ELSEIF( zReb(ji,jj,jk) < 10.224_wp ) THEN
+                     zav_wave(ji,jj,jk) = 0.052125_wp * znu_w(ji,jj,jk) * zReb(ji,jj,jk) * SQRT( zReb(ji,jj,jk) )
+                  ENDIF
+               END DO
+            END DO
+         END DO
+      ENDIF
+      !
+      DO jk = 2, jpkm1                 ! Bound diffusivity by molecular value and 100 cm2/s
+         zav_wave(:,:,jk) = MIN(  MAX( 1.4e-7_wp, zav_wave(:,:,jk) ), 1.e-2_wp  ) * wmask(:,:,jk)
+      END DO
+      !
+      IF( kt == nit000 ) THEN        !* Control print at first time-step: diagnose the energy consumed by zav_wave
+         zztmp = 0._wp
+!!gm used of glosum 3D....
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zztmp = zztmp + e3w_n(ji,jj,jk) * e1e2t(ji,jj)   &
+                     &          * MAX( 0._wp, rn2(ji,jj,jk) ) * zav_wave(ji,jj,jk) * wmask(ji,jj,jk) * tmask_i(ji,jj)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( zztmp )
+         zztmp = rau0 * zztmp ! Global integral of rauo * Kz * N^2 = power contributing to mixing 
+         !
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'zdf_iwm : Internal wave-driven mixing (iwm)'
+            WRITE(numout,*) '~~~~~~~ '
+            WRITE(numout,*)
+            WRITE(numout,*) '      Total power consumption by av_wave =  ', zztmp * 1.e-12_wp, 'TW'
+         ENDIF
+      ENDIF
+
+      !                          ! ----------------------- !
+      !                          !   Update  mixing coefs  !                          
+      !                          ! ----------------------- !
+      !      
+      IF( ln_tsdiff ) THEN          !* Option for differential mixing of salinity and temperature
+         DO jk = 2, jpkm1              ! Calculate S/T diffusivity ratio as a function of Reb
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zav_ratio(ji,jj,jk) = ( 0.505_wp + 0.495_wp *                                                                  &
+                      &   TANH(    0.92_wp * (   LOG10(  MAX( 1.e-20_wp, zReb(ji,jj,jk) * 5._wp * r1_6 )  ) - 0.60_wp   )    )   &
+                      &                 ) * wmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL iom_put( "av_ratio", zav_ratio )
+         DO jk = 2, jpkm1           !* update momentum & tracer diffusivity with wave-driven mixing
+            p_avs(:,:,jk) = p_avs(:,:,jk) + zav_wave(:,:,jk) * zav_ratio(:,:,jk)
+            p_avt(:,:,jk) = p_avt(:,:,jk) + zav_wave(:,:,jk)
+            p_avm(:,:,jk) = p_avm(:,:,jk) + zav_wave(:,:,jk)
+         END DO
+         !
+      ELSE                          !* update momentum & tracer diffusivity with wave-driven mixing
+         DO jk = 2, jpkm1
+            p_avs(:,:,jk) = p_avs(:,:,jk) + zav_wave(:,:,jk)
+            p_avt(:,:,jk) = p_avt(:,:,jk) + zav_wave(:,:,jk)
+            p_avm(:,:,jk) = p_avm(:,:,jk) + zav_wave(:,:,jk)
+         END DO
+      ENDIF
+
+      !                             !* output internal wave-driven mixing coefficient
+      CALL iom_put( "av_wave", zav_wave )
+                                    !* output useful diagnostics: Kz*N^2 , 
+!!gm Kz*N2 should take into account the ratio avs/avt if it is used.... (see diaar5)
+                                    !  vertical integral of rau0 * Kz * N^2 , energy density (zemx_iwm)
+      IF( iom_use("bflx_iwm") .OR. iom_use("pcmap_iwm") ) THEN
+         ALLOCATE( z2d(jpi,jpj) , z3d(jpi,jpj,jpk) )
+         z3d(:,:,:) = MAX( 0._wp, rn2(:,:,:) ) * zav_wave(:,:,:)
+         z2d(:,:) = 0._wp
+         DO jk = 2, jpkm1
+            z2d(:,:) = z2d(:,:) + e3w_n(:,:,jk) * z3d(:,:,jk) * wmask(:,:,jk)
+         END DO
+         z2d(:,:) = rau0 * z2d(:,:)
+         CALL iom_put( "bflx_iwm", z3d )
+         CALL iom_put( "pcmap_iwm", z2d )
+         DEALLOCATE( z2d , z3d )
+      ENDIF
+      CALL iom_put( "emix_iwm", zemx_iwm )
+      
+      IF(ln_ctl)   CALL prt_ctl(tab3d_1=zav_wave , clinfo1=' iwm - av_wave: ', tab3d_2=avt, clinfo2=' avt: ', ovlap=1, kdim=jpk)
+      !
+      IF( ln_timing )   CALL timing_stop('zdf_iwm')
+      !
+   END SUBROUTINE zdf_iwm
+
+
+   SUBROUTINE zdf_iwm_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_iwm_init  ***
+      !!                     
+      !! ** Purpose :   Initialization of the wave-driven vertical mixing, reading
+      !!              of input power maps and decay length scales in netcdf files.
+      !!
+      !! ** Method  : - Read the namzdf_iwm namelist and check the parameters
+      !!
+      !!              - Read the input data in NetCDF files :
+      !!              power available from high-mode wave breaking (mixing_power_bot.nc)
+      !!              power available from pycnocline-intensified wave-breaking (mixing_power_pyc.nc)
+      !!              power available from critical slope wave-breaking (mixing_power_cri.nc)
+      !!              WKB decay scale for high-mode wave-breaking (decay_scale_bot.nc)
+      !!              decay scale for critical slope wave-breaking (decay_scale_cri.nc)
+      !!
+      !! ** input   : - Namlist namzdf_iwm
+      !!              - NetCDF files : mixing_power_bot.nc, mixing_power_pyc.nc, mixing_power_cri.nc,
+      !!              decay_scale_bot.nc decay_scale_cri.nc
+      !!
+      !! ** Action  : - Increase by 1 the nstop flag is setting problem encounter
+      !!              - Define ebot_iwm, epyc_iwm, ecri_iwm, hbot_iwm, hcri_iwm
+      !!
+      !! References : de Lavergne et al. JPO, 2015 ; de Lavergne PhD 2016
+      !!              de Lavergne et al. in prep., 2017
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      INTEGER  ::   inum         ! local integer
+      INTEGER  ::   ios
+      REAL(wp) ::   zbot, zpyc, zcri   ! local scalars
+      !!
+      NAMELIST/namzdf_iwm_new/ nn_zpyc, ln_mevar, ln_tsdiff
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('zdf_iwm_init')
+      !
+      REWIND( numnam_ref )              ! Namelist namzdf_iwm in reference namelist : Wave-driven mixing
+      READ  ( numnam_ref, namzdf_iwm_new, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_iwm in reference namelist', lwp )
+      !
+      REWIND( numnam_cfg )              ! Namelist namzdf_iwm in configuration namelist : Wave-driven mixing
+      READ  ( numnam_cfg, namzdf_iwm_new, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_iwm in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, namzdf_iwm_new )
+      !
+      IF(lwp) THEN                  ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'zdf_iwm_init : internal wave-driven mixing'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namzdf_iwm_new : set wave-driven mixing parameters'
+         WRITE(numout,*) '      Pycnocline-intensified diss. scales as N (=1) or N^2 (=2) = ', nn_zpyc
+         WRITE(numout,*) '      Variable (T) or constant (F) mixing efficiency            = ', ln_mevar
+         WRITE(numout,*) '      Differential internal wave-driven mixing (T) or not (F)   = ', ln_tsdiff
+      ENDIF
+      
+      ! The new wave-driven mixing parameterization elevates avt and avm in the interior, and
+      ! ensures that avt remains larger than its molecular value (=1.4e-7). Therefore, avtb should 
+      ! be set here to a very small value, and avmb to its (uniform) molecular value (=1.4e-6).
+      avmb(:) = 1.4e-6_wp        ! viscous molecular value
+      avtb(:) = 1.e-10_wp        ! very small diffusive minimum (background avt is specified in zdf_iwm)    
+      avtb_2d(:,:) = 1.e0_wp     ! uniform 
+      IF(lwp) THEN                  ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) '   Force the background value applied to avm & avt in TKE to be everywhere ',   &
+            &               'the viscous molecular value & a very small diffusive value, resp.'
+      ENDIF
+            
+      !                             ! allocate iwm arrays
+      IF( zdf_iwm_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_iwm_init : unable to allocate iwm arrays' )
+      !
+      !                             ! read necessary fields
+      CALL iom_open('mixing_power_bot',inum)       ! energy flux for high-mode wave breaking [W/m2]
+      CALL iom_get  (inum, jpdom_data, 'field', ebot_iwm, 1 ) 
+      CALL iom_close(inum)
+      !
+      CALL iom_open('mixing_power_pyc',inum)       ! energy flux for pynocline-intensified wave breaking [W/m2]
+      CALL iom_get  (inum, jpdom_data, 'field', epyc_iwm, 1 )
+      CALL iom_close(inum)
+      !
+      CALL iom_open('mixing_power_cri',inum)       ! energy flux for critical slope wave breaking [W/m2]
+      CALL iom_get  (inum, jpdom_data, 'field', ecri_iwm, 1 )
+      CALL iom_close(inum)
+      !
+      CALL iom_open('decay_scale_bot',inum)        ! spatially variable decay scale for high-mode wave breaking [m]
+      CALL iom_get  (inum, jpdom_data, 'field', hbot_iwm, 1 )
+      CALL iom_close(inum)
+      !
+      CALL iom_open('decay_scale_cri',inum)        ! spatially variable decay scale for critical slope wave breaking [m]
+      CALL iom_get  (inum, jpdom_data, 'field', hcri_iwm, 1 )
+      CALL iom_close(inum)
+
+      ebot_iwm(:,:) = ebot_iwm(:,:) * ssmask(:,:)
+      epyc_iwm(:,:) = epyc_iwm(:,:) * ssmask(:,:)
+      ecri_iwm(:,:) = ecri_iwm(:,:) * ssmask(:,:)
+
+      zbot = glob_sum( e1e2t(:,:) * ebot_iwm(:,:) )
+      zpyc = glob_sum( e1e2t(:,:) * epyc_iwm(:,:) )
+      zcri = glob_sum( e1e2t(:,:) * ecri_iwm(:,:) )
+      IF(lwp) THEN
+         WRITE(numout,*) '      High-mode wave-breaking energy:             ', zbot * 1.e-12_wp, 'TW'
+         WRITE(numout,*) '      Pycnocline-intensifed wave-breaking energy: ', zpyc * 1.e-12_wp, 'TW'
+         WRITE(numout,*) '      Critical slope wave-breaking energy:        ', zcri * 1.e-12_wp, 'TW'
+      ENDIF
+      !
+      IF( ln_timing )   CALL timing_stop('zdf_iwm_init')
+      !
+   END SUBROUTINE zdf_iwm_init
+
+   !!======================================================================
+END MODULE zdfiwm
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfmxl.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfmxl.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfmxl.F90	(revision 9019)
@@ -11,25 +11,24 @@
    !!   zdf_mxl      : Compute the turbocline and mixed layer depths.
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers variables
-   USE dom_oce         ! ocean space and time domain variables
-   USE trc_oce, ONLY: l_offline         ! ocean space and time domain variables
-   USE zdf_oce         ! ocean vertical physics
-   USE in_out_manager  ! I/O manager
-   USE prtctl          ! Print control
-   USE phycst          ! physical constants
-   USE iom             ! I/O library
-   USE lib_mpp         ! MPP library
-   USE wrk_nemo        ! work arrays
-   USE timing          ! Timing
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain variables
+   USE trc_oce  , ONLY: l_offline         ! ocean space and time domain variables
+   USE zdf_oce        ! ocean vertical physics
+   USE in_out_manager ! I/O manager
+   USE prtctl         ! Print control
+   USE phycst         ! physical constants
+   USE iom            ! I/O library
+   USE lib_mpp        ! MPP library
+   USE timing         ! Timing
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   zdf_mxl       ! called by step.F90
+   PUBLIC   zdf_mxl   ! called by zdfphy.F90
 
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   nmln    !: number of level in the mixed layer (used by TOP)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hmld    !: mixing layer depth (turbocline)      [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hmlp    !: mixed layer depth  (rho=rho0+zdcrit) [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hmlpt   !: depth of the last T-point inside the mixed layer [m]
+   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   nmln    !: number of level in the mixed layer (used by LDF, ZDF, TRD, TOP)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hmld    !: mixing layer depth (turbocline)      [m]   (used by TOP)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hmlp    !: mixed layer depth  (rho=rho0+zdcrit) [m]   (used by LDF)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hmlpt   !: depth of the last T-point inside the mixed layer [m] (used by LDF)
 
    REAL(wp), PUBLIC ::   rho_c = 0.01_wp    !: density criterion for mixed layer depth
@@ -37,5 +36,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$ 
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -80,11 +79,9 @@
       INTEGER  ::   iikn, iiki, ikt ! local integer
       REAL(wp) ::   zN2_c           ! local scalar
-      INTEGER, POINTER, DIMENSION(:,:) ::   imld   ! 2D workspace
+      INTEGER, DIMENSION(jpi,jpj) ::   imld   ! 2D workspace
       !!----------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('zdf_mxl')
+      IF( ln_timing )   CALL timing_start('zdf_mxl')
       !
-      CALL wrk_alloc( jpi,jpj, imld )
-
       IF( kt == nit000 ) THEN
          IF(lwp) WRITE(numout,*)
@@ -144,7 +141,5 @@
       IF(ln_ctl)   CALL prt_ctl( tab2d_1=REAL(nmln,wp), clinfo1=' nmln : ', tab2d_2=hmlp, clinfo2=' hmlp : ', ovlap=1 )
       !
-      CALL wrk_dealloc( jpi,jpj, imld )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('zdf_mxl')
+      IF( ln_timing )   CALL timing_stop('zdf_mxl')
       !
    END SUBROUTINE zdf_mxl
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfosm.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfosm.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfosm.F90	(revision 9019)
@@ -0,0 +1,1726 @@
+MODULE zdfosm
+   !!======================================================================
+   !!                       ***  MODULE  zdfosm  ***
+   !! Ocean physics:  vertical mixing coefficient compute from the OSMOSIS
+   !!                 turbulent closure parameterization
+   !!=====================================================================
+   !!  History : NEMO 4.0  ! A. Grant, G. Nurser
+   !! 15/03/2017  Changed calculation of pycnocline thickness in unstable conditions and stable conditions AG
+   !! 15/03/2017  Calculation of pycnocline gradients for stable conditions changed. Pycnocline gradients now depend on stability of the OSBL. A.G
+   !! 06/06/2017  (1) Checks on sign of buoyancy jump in calculation of  OSBL depth.  A.G.
+   !!             (2) Removed variable zbrad0, zbradh and zbradav since they are not used.
+   !!             (3) Approximate treatment for shear turbulence.
+   !!                        Minimum values for zustar and zustke.
+   !!                        Add velocity scale, zvstr, that tends to zustar for large Langmuir numbers.
+   !!                        Limit maximum value for Langmuir number.
+   !!                        Use zvstr in definition of stability parameter zhol.
+   !!             (4) Modified parametrization of entrainment flux, changing original coefficient 0.0485 for Langmuir contribution to 0.135 * zla
+   !!             (5) For stable boundary layer add factor that depends on length of timestep to 'slow' collapse and growth. Make sure buoyancy jump not negative.
+   !!             (6) For unstable conditions when growth is over multiple levels, limit change to maximum of one level per cycle through loop.
+   !!             (7) Change lower limits for loops that calculate OSBL averages from 1 to 2. Large gradients between levels 1 and 2 can cause problems.
+   !!             (8) Change upper limits from ibld-1 to ibld.
+   !!             (9) Calculation of pycnocline thickness in unstable conditions. Check added to ensure that buoyancy jump is positive before calculating Ri.
+   !!            (10) Thickness of interface layer at base of the stable OSBL set by Richardson number. Gives continuity in transition from unstable OSBL.
+   !!            (11) Checks that buoyancy jump is poitive when calculating pycnocline profiles.
+   !!            (12) Replace zwstrl with zvstr in calculation of eddy viscosity.
+   !! 27/09/2017 (13) Calculate Stokes drift and Stokes penetration depth from wave information
+   !!            (14) Bouyancy flux due to entrainment changed to include contribution from shear turbulence (for testing commented out).
+   !! 28/09/2017 (15) Calculation of Stokes drift moved into separate do-loops to allow for different options for the determining the Stokes drift to be added.
+   !!            (16) Calculation of Stokes drift from windspeed for PM spectrum (for testing, commented out)
+   !!            (17) Modification to Langmuir velocity scale to include effects due to the Stokes penetration depth (for testing, commented out)
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   'key_zdfosm'                                             OSMOSIS scheme
+   !!----------------------------------------------------------------------
+   !!   zdf_osm       : update momentum and tracer Kz from osm scheme
+   !!   zdf_osm_init  : initialization, namelist read, and parameters control
+   !!   osm_rst       : read (or initialize) and write osmosis restart fields
+   !!   tra_osm       : compute and add to the T & S trend the non-local flux
+   !!   trc_osm       : compute and add to the passive tracer trend the non-local flux (TBD)
+   !!   dyn_osm       : compute and add to u & v trensd the non-local flux
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and active tracers
+                      ! uses wn from previous time step (which is now wb) to calculate hbl
+   USE dom_oce        ! ocean space and time domain
+   USE zdf_oce        ! ocean vertical physics
+   USE sbc_oce        ! surface boundary condition: ocean
+   USE sbcwave        ! surface wave parameters
+   USE phycst         ! physical constants
+   USE eosbn2         ! equation of state
+   USE traqsr         ! details of solar radiation absorption
+   USE zdfddm         ! double diffusion mixing (avs array)
+   USE iom            ! I/O library
+   USE lib_mpp        ! MPP library
+   USE trd_oce        ! ocean trends definition
+   USE trdtra         ! tracers trends
+   !
+   USE in_out_manager ! I/O manager
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl         ! Print control
+   USE timing         ! Timing
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   zdf_osm       ! routine called by step.F90
+   PUBLIC   zdf_osm_init  ! routine called by nemogcm.F90
+   PUBLIC   osm_rst       ! routine called by step.F90
+   PUBLIC   tra_osm       ! routine called by step.F90
+   PUBLIC   trc_osm       ! routine called by trcstp.F90
+   PUBLIC   dyn_osm       ! routine called by 'step.F90'
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ghamu    !: non-local u-momentum flux
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ghamv    !: non-local v-momentum flux
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ghamt    !: non-local temperature flux (gamma/<ws>o)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ghams    !: non-local salinity flux (gamma/<ws>o)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   etmean   !: averaging operator for avt
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   hbl      !: boundary layer depth
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   hbli     !: intial boundary layer depth for stable blayer
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   dstokes  !: penetration depth of the Stokes drift.
+
+   !                      !!** Namelist  namzdf_osm  **
+   LOGICAL  ::   ln_use_osm_la      ! Use namelist  rn_osm_la
+   REAL(wp) ::   rn_osm_la          ! Turbulent Langmuir number
+   REAL(wp) ::   rn_osm_dstokes     ! Depth scale of Stokes drift
+   REAL(wp) ::   rn_osm_hbl0 = 10._wp       ! Initial value of hbl for 1D runs
+   INTEGER  ::   nn_ave             ! = 0/1 flag for horizontal average on avt
+   INTEGER  ::   nn_osm_wave = 0    ! = 0/1/2 flag for getting stokes drift from La# / PM wind-waves/Inputs into sbcwave
+   LOGICAL  ::   ln_dia_osm         ! Use namelist  rn_osm_la
+
+
+   LOGICAL  ::   ln_kpprimix  = .true.  ! Shear instability mixing
+   REAL(wp) ::   rn_riinfty   = 0.7     ! local Richardson Number limit for shear instability
+   REAL(wp) ::   rn_difri    =  0.005   ! maximum shear mixing at Rig = 0    (m2/s)
+   LOGICAL  ::   ln_convmix  = .true.   ! Convective instability mixing
+   REAL(wp) ::   rn_difconv = 1._wp     ! diffusivity when unstable below BL  (m2/s)
+
+   !                                    !!! ** General constants  **
+   REAL(wp) ::   epsln   = 1.0e-20_wp   ! a small positive number
+   REAL(wp) ::   pthird  = 1._wp/3._wp  ! 1/3
+   REAL(wp) ::   p2third = 2._wp/3._wp  ! 2/3
+
+   INTEGER :: idebug = 236
+   INTEGER :: jdebug = 228
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
+   !! $Id$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION zdf_osm_alloc()
+      !!----------------------------------------------------------------------
+      !!                 ***  FUNCTION zdf_osm_alloc  ***
+      !!----------------------------------------------------------------------
+     ALLOCATE( ghamu(jpi,jpj,jpk), ghamv(jpi,jpj,jpk), ghamt(jpi,jpj,jpk), ghams(jpi,jpj,jpk), &
+          &      hbl(jpi,jpj)    ,  hbli(jpi,jpj)    , dstokes(jpi, jpj) ,                     &
+          &   etmean(jpi,jpj,jpk),  STAT= zdf_osm_alloc )
+     IF( zdf_osm_alloc /= 0 )   CALL ctl_warn('zdf_osm_alloc: failed to allocate zdf_osm arrays')
+     IF( lk_mpp             )   CALL mpp_sum ( zdf_osm_alloc )
+   END FUNCTION zdf_osm_alloc
+
+
+   SUBROUTINE zdf_osm( kt, p_avm, p_avt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE zdf_osm  ***
+      !!
+      !! ** Purpose :   Compute the vertical eddy viscosity and diffusivity
+      !!      coefficients and non local mixing using the OSMOSIS scheme
+      !!
+      !! ** Method :   The boundary layer depth hosm is diagnosed at tracer points
+      !!      from profiles of buoyancy, and shear, and the surface forcing.
+      !!      Above hbl (sigma=-z/hbl <1) the mixing coefficients are computed from
+      !!
+      !!                      Kx =  hosm  Wx(sigma) G(sigma)
+      !!
+      !!             and the non local term ghamt = Cs / Ws(sigma) / hosm
+      !!      Below hosm  the coefficients are the sum of mixing due to internal waves
+      !!      shear instability and double diffusion.
+      !!
+      !!      -1- Compute the now interior vertical mixing coefficients at all depths.
+      !!      -2- Diagnose the boundary layer depth.
+      !!      -3- Compute the now boundary layer vertical mixing coefficients.
+      !!      -4- Compute the now vertical eddy vicosity and diffusivity.
+      !!      -5- Smoothing
+      !!
+      !!        N.B. The computation is done from jk=2 to jpkm1
+      !!             Surface value of avt are set once a time to zero
+      !!             in routine zdf_osm_init.
+      !!
+      !! ** Action  :   update the non-local terms ghamts
+      !!                update avt (before vertical eddy coef.)
+      !!
+      !! References : Large W.G., Mc Williams J.C. and Doney S.C.
+      !!         Reviews of Geophysics, 32, 4, November 1994
+      !!         Comments in the code refer to this paper, particularly
+      !!         the equation number. (LMD94, here after)
+      !!----------------------------------------------------------------------
+      INTEGER                   , INTENT(in   ) ::   kt            ! ocean time step
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::  p_avm, p_avt   ! momentum and tracer Kz (w-points)
+      !!
+      INTEGER ::   ji, jj, jk                   ! dummy loop indices
+      INTEGER ::   ikbot, jkmax, jkm1, jkp2     !
+
+      REAL(wp) ::   ztx, zty, zflageos, zstabl, zbuofdep,zucube      !
+      REAL(wp) ::   zalbet, zbeta, zthermal, zatt1                   !
+      REAL(wp) ::   zehat, zeta, zhrib, zsig, zscale, zwst, zws, zwm ! Velocity scales
+      REAL(wp) ::   zwsun, zwmun, zcons, zconm, zwcons, zwconm       !
+      REAL(wp) ::   zsr, zbw, ze, zb, zd, zc, zaw, za, zb1, za1, zkw, zk0, zcomp , zrhd,zrhdr,zbvzed   ! In situ density
+      INTEGER  ::   jm                          ! dummy loop indices
+      REAL(wp) ::   zr1, zr2, zr3, zr4, zrhop   ! Compression terms
+      REAL(wp) ::   zflag, zrn2, zdep21, zdep32, zdep43
+      REAL(wp) ::   zesh2, zri, zfri            ! Interior richardson mixing
+      REAL(wp) ::   zdelta, zdelta2, zdzup, zdzdn, zdzh, zvath, zgat1, zdat1, zkm1m, zkm1t
+      REAL(wp) :: zt,zs,zu,zv,zrh               ! variables used in constructing averages
+! Scales
+      REAL(wp), DIMENSION(jpi,jpj) :: zrad0     ! Surface solar temperature flux (deg m/s)
+      REAL(wp), DIMENSION(jpi,jpj) :: zradh     ! Radiative flux at bl base (Buoyancy units)
+      REAL(wp), DIMENSION(jpi,jpj) :: zradav    ! Radiative flux, bl average (Buoyancy Units)
+      REAL(wp), DIMENSION(jpi,jpj) :: zustar    ! friction velocity
+      REAL(wp), DIMENSION(jpi,jpj) :: zwstrl    ! Langmuir velocity scale
+      REAL(wp), DIMENSION(jpi,jpj) :: zvstr     ! Velocity scale that ends to zustar for large Langmuir number.
+      REAL(wp), DIMENSION(jpi,jpj) :: zwstrc    ! Convective velocity scale
+      REAL(wp), DIMENSION(jpi,jpj) :: zuw0      ! Surface u-momentum flux
+      REAL(wp), DIMENSION(jpi,jpj) :: zvw0      ! Surface v-momentum flux
+      REAL(wp), DIMENSION(jpi,jpj) :: zwth0     ! Surface heat flux (Kinematic)
+      REAL(wp), DIMENSION(jpi,jpj) :: zws0      ! Surface freshwater flux
+      REAL(wp), DIMENSION(jpi,jpj) :: zwb0      ! Surface buoyancy flux
+      REAL(wp), DIMENSION(jpi,jpj) :: zwthav    ! Heat flux - bl average
+      REAL(wp), DIMENSION(jpi,jpj) :: zwsav     ! freshwater flux - bl average
+      REAL(wp), DIMENSION(jpi,jpj) :: zwbav     ! Buoyancy flux - bl average
+      REAL(wp), DIMENSION(jpi,jpj) :: zwb_ent   ! Buoyancy entrainment flux
+      REAL(wp), DIMENSION(jpi,jpj) :: zustke    ! Surface Stokes drift
+      REAL(wp), DIMENSION(jpi,jpj) :: zla       ! Trubulent Langmuir number
+      REAL(wp), DIMENSION(jpi,jpj) :: zcos_wind ! Cos angle of surface stress
+      REAL(wp), DIMENSION(jpi,jpj) :: zsin_wind ! Sin angle of surface stress
+      REAL(wp), DIMENSION(jpi,jpj) :: zhol      ! Stability parameter for boundary layer
+      LOGICAL, DIMENSION(:,:), ALLOCATABLE :: lconv ! unstable/stable bl
+
+      ! mixed-layer variables
+
+      INTEGER, DIMENSION(jpi,jpj) :: ibld ! level of boundary layer base
+      INTEGER, DIMENSION(jpi,jpj) :: imld ! level of mixed-layer depth (pycnocline top)
+
+      REAL(wp) :: ztgrad,zsgrad,zbgrad ! Temporary variables used to calculate pycnocline gradients
+      REAL(wp) :: zugrad,zvgrad        ! temporary variables for calculating pycnocline shear
+
+      REAL(wp), DIMENSION(jpi,jpj) :: zhbl  ! bl depth - grid
+      REAL(wp), DIMENSION(jpi,jpj) :: zhml  ! ml depth - grid
+      REAL(wp), DIMENSION(jpi,jpj) :: zdh   ! pycnocline depth - grid
+      REAL(wp), DIMENSION(jpi,jpj) :: zdhdt ! BL depth tendency
+      REAL(wp), DIMENSION(jpi,jpj) :: zt_bl,zs_bl,zu_bl,zv_bl,zrh_bl  ! averages over the depth of the blayer
+      REAL(wp), DIMENSION(jpi,jpj) :: zt_ml,zs_ml,zu_ml,zv_ml,zrh_ml  ! averages over the depth of the mixed layer
+      REAL(wp), DIMENSION(jpi,jpj) :: zdt_bl,zds_bl,zdu_bl,zdv_bl,zdrh_bl,zdb_bl ! difference between blayer average and parameter at base of blayer
+      REAL(wp), DIMENSION(jpi,jpj) :: zdt_ml,zds_ml,zdu_ml,zdv_ml,zdrh_ml,zdb_ml ! difference between mixed layer average and parameter at base of blayer
+      REAL(wp), DIMENSION(jpi,jpj) :: zwth_ent,zws_ent ! heat and salinity fluxes at the top of the pycnocline
+      REAL(wp), DIMENSION(jpi,jpj) :: zuw_bse,zvw_bse  ! momentum fluxes at the top of the pycnocline
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zdtdz_pyc    ! parametrized gradient of temperature in pycnocline
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zdsdz_pyc    ! parametrised gradient of salinity in pycnocline
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zdbdz_pyc    ! parametrised gradient of buoyancy in the pycnocline
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zdudz_pyc    ! u-shear across the pycnocline
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zdvdz_pyc    ! v-shear across the pycnocline
+
+      ! Flux-gradient relationship variables
+
+      REAL(wp) :: zl_c,zl_l,zl_eps  ! Used to calculate turbulence length scale.
+
+      REAL(wp), DIMENSION(jpi,jpj) :: zdifml_sc,zvisml_sc,zdifpyc_sc,zvispyc_sc,zbeta_d_sc,zbeta_v_sc ! Scales for eddy diffusivity/viscosity
+      REAL(wp), DIMENSION(jpi,jpj) :: zsc_wth_1,zsc_ws_1 ! Temporary scales used to calculate scalar non-gradient terms.
+      REAL(wp), DIMENSION(jpi,jpj) :: zsc_uw_1,zsc_uw_2,zsc_vw_1,zsc_vw_2 ! Temporary scales for non-gradient momentum flux terms.
+      REAL(wp), DIMENSION(jpi,jpj) :: zhbl_t ! holds boundary layer depth updated by full timestep
+
+      ! For calculating Ri#-dependent mixing
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: z3du   ! u-shear^2
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: z3dv   ! v-shear^2
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zrimix ! spatial form of ri#-induced diffusion
+
+      ! Temporary variables
+      INTEGER :: inhml
+      INTEGER :: i_lconv_alloc
+      REAL(wp) :: znd,znd_d,zznd_ml,zznd_pyc,zznd_d ! temporary non-dimensional depths used in various routines
+      REAL(wp) :: ztemp, zari, zpert, zzdhdt, zdb   ! temporary variables
+      REAL(wp) :: zthick, zz0, zz1 ! temporary variables
+      REAL(wp) :: zvel_max, zhbl_s ! temporary variables
+      REAL(wp) :: zfac             ! temporary variable
+      REAL(wp) :: zus_x, zus_y     ! temporary Stokes drift
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zviscos ! viscosity
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zdiffut ! t-diffusivity
+
+      ! For debugging
+      INTEGER :: ikt
+      !!--------------------------------------------------------------------
+      !
+      IF( ln_timing )  CALL timing_start('zdf_osm')
+      !
+      ALLOCATE( lconv(jpi,jpj),  STAT= i_lconv_alloc )
+      IF( i_lconv_alloc /= 0 )   CALL ctl_warn('zdf_osm: failed to allocate lconv')
+
+      ibld(:,:)   = 0     ; imld(:,:)  = 0
+      zrad0(:,:)  = 0._wp ; zradh(:,:) = 0._wp ; zradav(:,:)    = 0._wp ; zustar(:,:)    = 0._wp
+      zwstrl(:,:) = 0._wp ; zvstr(:,:) = 0._wp ; zwstrc(:,:)    = 0._wp ; zuw0(:,:)      = 0._wp
+      zvw0(:,:)   = 0._wp ; zwth0(:,:) = 0._wp ; zws0(:,:)      = 0._wp ; zwb0(:,:)      = 0._wp
+      zwthav(:,:) = 0._wp ; zwsav(:,:) = 0._wp ; zwbav(:,:)     = 0._wp ; zwb_ent(:,:)   = 0._wp
+      zustke(:,:) = 0._wp ; zla(:,:)   = 0._wp ; zcos_wind(:,:) = 0._wp ; zsin_wind(:,:) = 0._wp
+      zhol(:,:)   = 0._wp
+      lconv(:,:)  = .FALSE.
+      ! mixed layer
+      ! no initialization of zhbl or zhml (or zdh?)
+      zhbl(:,:)    = 1._wp ; zhml(:,:)    = 1._wp ; zdh(:,:)      = 1._wp ; zdhdt(:,:)   = 0._wp
+      zt_bl(:,:)   = 0._wp ; zs_bl(:,:)   = 0._wp ; zu_bl(:,:)    = 0._wp ; zv_bl(:,:)   = 0._wp
+      zrh_bl(:,:)  = 0._wp ; zt_ml(:,:)   = 0._wp ; zs_ml(:,:)    = 0._wp ; zu_ml(:,:)   = 0._wp
+      zv_ml(:,:)   = 0._wp ; zrh_ml(:,:)  = 0._wp ; zdt_bl(:,:)   = 0._wp ; zds_bl(:,:)  = 0._wp
+      zdu_bl(:,:)  = 0._wp ; zdv_bl(:,:)  = 0._wp ; zdrh_bl(:,:)  = 0._wp ; zdb_bl(:,:)  = 0._wp
+      zdt_ml(:,:)  = 0._wp ; zds_ml(:,:)  = 0._wp ; zdu_ml(:,:)   = 0._wp ; zdv_ml(:,:)  = 0._wp
+      zdrh_ml(:,:) = 0._wp ; zdb_ml(:,:)  = 0._wp ; zwth_ent(:,:) = 0._wp ; zws_ent(:,:) = 0._wp
+      zuw_bse(:,:) = 0._wp ; zvw_bse(:,:) = 0._wp
+      !
+      zdtdz_pyc(:,:,:) = 0._wp ; zdsdz_pyc(:,:,:) = 0._wp ; zdbdz_pyc(:,:,:) = 0._wp
+      zdudz_pyc(:,:,:) = 0._wp ; zdvdz_pyc(:,:,:) = 0._wp
+      !
+      ! Flux-Gradient arrays.
+      zdifml_sc(:,:)  = 0._wp ; zvisml_sc(:,:)  = 0._wp ; zdifpyc_sc(:,:) = 0._wp
+      zvispyc_sc(:,:) = 0._wp ; zbeta_d_sc(:,:) = 0._wp ; zbeta_v_sc(:,:) = 0._wp
+      zsc_wth_1(:,:)  = 0._wp ; zsc_ws_1(:,:)   = 0._wp ; zsc_uw_1(:,:)   = 0._wp
+      zsc_uw_2(:,:)   = 0._wp ; zsc_vw_1(:,:)   = 0._wp ; zsc_vw_2(:,:)   = 0._wp
+      zhbl_t(:,:)     = 0._wp ; zdhdt(:,:)      = 0._wp
+
+      zdiffut(:,:,:) = 0._wp ; zviscos(:,:,:) = 0._wp ; ghamt(:,:,:) = 0._wp
+      ghams(:,:,:)   = 0._wp ; ghamu(:,:,:)   = 0._wp ; ghamv(:,:,:) = 0._wp
+
+      ! hbl = MAX(hbl,epsln)
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Calculate boundary layer scales
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      ! Assume two-band radiation model for depth of OSBL
+     zz0 =       rn_abs       ! surface equi-partition in 2-bands
+     zz1 =  1. - rn_abs
+     DO jj = 2, jpjm1
+        DO ji = 2, jpim1
+           ! Surface downward irradiance (so always +ve)
+           zrad0(ji,jj) = qsr(ji,jj) * r1_rau0_rcp
+           ! Downwards irradiance at base of boundary layer
+           zradh(ji,jj) = zrad0(ji,jj) * ( zz0 * EXP( -hbl(ji,jj)/rn_si0 ) + zz1 * EXP( -hbl(ji,jj)/rn_si1) )
+           ! Downwards irradiance averaged over depth of the OSBL
+           zradav(ji,jj) = zrad0(ji,jj) * ( zz0 * ( 1.0 - EXP( -hbl(ji,jj)/rn_si0 ) )*rn_si0 &
+                 &                         + zz1 * ( 1.0 - EXP( -hbl(ji,jj)/rn_si1 ) )*rn_si1 ) / hbl(ji,jj)
+        END DO
+     END DO
+     ! Turbulent surface fluxes and fluxes averaged over depth of the OSBL
+     DO jj = 2, jpjm1
+        DO ji = 2, jpim1
+           zthermal = rab_n(ji,jj,1,jp_tem)
+           zbeta    = rab_n(ji,jj,1,jp_sal)
+           ! Upwards surface Temperature flux for non-local term
+           zwth0(ji,jj) = - qns(ji,jj) * r1_rau0_rcp * tmask(ji,jj,1)
+           ! Upwards surface salinity flux for non-local term
+           zws0(ji,jj) = - ( ( emp(ji,jj)-rnf(ji,jj) ) * tsn(ji,jj,1,jp_sal)  + sfx(ji,jj) ) * r1_rau0 * tmask(ji,jj,1)
+           ! Non radiative upwards surface buoyancy flux
+           zwb0(ji,jj) = grav * zthermal * zwth0(ji,jj) -  grav * zbeta * zws0(ji,jj)
+           ! turbulent heat flux averaged over depth of OSBL
+           zwthav(ji,jj) = 0.5 * zwth0(ji,jj) - ( 0.5*( zrad0(ji,jj) + zradh(ji,jj) ) - zradav(ji,jj) )
+           ! turbulent salinity flux averaged over depth of the OBSL
+           zwsav(ji,jj) = 0.5 * zws0(ji,jj)
+           ! turbulent buoyancy flux averaged over the depth of the OBSBL
+           zwbav(ji,jj) = grav  * zthermal * zwthav(ji,jj) - grav  * zbeta * zwsav(ji,jj)
+           ! Surface upward velocity fluxes
+           zuw0(ji,jj) = -utau(ji,jj) * r1_rau0 * tmask(ji,jj,1)
+           zvw0(ji,jj) = -vtau(ji,jj) * r1_rau0 * tmask(ji,jj,1)
+           ! Friction velocity (zustar), at T-point : LMD94 eq. 2
+           zustar(ji,jj) = MAX( SQRT( SQRT( zuw0(ji,jj) * zuw0(ji,jj) + zvw0(ji,jj) * zvw0(ji,jj) ) ), 1.0e-8 )
+           zcos_wind(ji,jj) = -zuw0(ji,jj) / ( zustar(ji,jj) * zustar(ji,jj) )
+           zsin_wind(ji,jj) = -zvw0(ji,jj) / ( zustar(ji,jj) * zustar(ji,jj) )
+        END DO
+     END DO
+     ! Calculate Stokes drift in direction of wind (zustke) and Stokes penetration depth (dstokes)
+     SELECT CASE (nn_osm_wave)
+     ! Assume constant La#=0.3
+     CASE(0)
+        DO jj = 2, jpjm1
+           DO ji = 2, jpim1
+              zus_x = zcos_wind(ji,jj) * zustar(ji,jj) / 0.3**2
+              zus_y = zsin_wind(ji,jj) * zustar(ji,jj) / 0.3**2
+              zustke(ji,jj) = MAX ( SQRT( zus_x*zus_x + zus_y*zus_y), 1.0e-8 )
+              ! dstokes(ji,jj) set to constant value rn_osm_dstokes from namelist in zdf_osm_init
+           END DO
+        END DO
+     ! Assume Pierson-Moskovitz wind-wave spectrum
+     CASE(1)
+        DO jj = 2, jpjm1
+           DO ji = 2, jpim1
+              ! Use wind speed wndm included in sbc_oce module
+              zustke(ji,jj) = MAX ( 0.016 * wndm(ji,jj), 1.0e-8 )
+              dstokes(ji,jj) = 0.12 * wndm(ji,jj)**2 / grav
+           END DO
+        END DO
+     ! Use ECMWF wave fields as output from SBCWAVE
+     CASE(2)
+        zfac =  2.0_wp * rpi / 16.0_wp
+        DO jj = 2, jpjm1
+           DO ji = 2, jpim1
+              ! The Langmur number from the ECMWF model appears to give La<0.3 for wind-driven seas.
+              !    The coefficient 0.8 gives La=0.3  in this situation.
+              ! It could represent the effects of the spread of wave directions
+              ! around the mean wind. The effect of this adjustment needs to be tested.
+              zustke(ji,jj) = MAX (1.0 * ( zcos_wind(ji,jj) * ut0sd(ji,jj) + zsin_wind(ji,jj)  * vt0sd(ji,jj) ), zustar(ji,jj)/(0.45*0.45 ))
+              dstokes(ji,jj) = MAX(zfac * hsw(ji,jj)*hsw(ji,jj) / ( MAX(zustke(ji,jj)*wmp(ji,jj), 1.0e-7 ) ), 5.0e-1) !rn_osm_dstokes !
+           END DO
+        END DO
+     END SELECT
+
+     ! Langmuir velocity scale (zwstrl), La # (zla)
+     ! mixed scale (zvstr), convective velocity scale (zwstrc)
+     DO jj = 2, jpjm1
+        DO ji = 2, jpim1
+           ! Langmuir velocity scale (zwstrl), at T-point
+           zwstrl(ji,jj) = ( zustar(ji,jj) * zustar(ji,jj) * zustke(ji,jj) )**pthird
+           ! Modify zwstrl to allow for small and large values of dstokes/hbl.
+           ! Intended as a possible test. Doesn't affect LES results for entrainment,
+           !  but hasn't been shown to be correct as dstokes/h becomes large or small.
+           zwstrl(ji,jj) = zwstrl(ji,jj) *  &
+                & (1.12 * ( 1.0 - ( 1.0 - EXP( -hbl(ji,jj) / dstokes(ji,jj) ) ) * dstokes(ji,jj) / hbl(ji,jj) ))**pthird * &
+                & ( 1.0 - EXP( -15.0 * dstokes(ji,jj) / hbl(ji,jj) ))
+           ! define La this way so effects of Stokes penetration depth on velocity scale are included
+           zla(ji,jj) = SQRT ( zustar(ji,jj) / zwstrl(ji,jj) )**3
+           ! Velocity scale that tends to zustar for large Langmuir numbers
+           zvstr(ji,jj) = ( zwstrl(ji,jj)**3  + &
+                & ( 1.0 - EXP( -0.5 * zla(ji,jj)**2 ) ) * zustar(ji,jj) * zustar(ji,jj) * zustar(ji,jj) )**pthird
+
+           ! limit maximum value of Langmuir number as approximate treatment for shear turbulence.
+           ! Note zustke and zwstrl are not amended.
+           IF ( zla(ji,jj) >= 0.45 ) zla(ji,jj) = 0.45
+           !
+           ! get convective velocity (zwstrc), stabilty scale (zhol) and logical conection flag lconv
+           IF ( zwbav(ji,jj) > 0.0) THEN
+              zwstrc(ji,jj) = ( 2.0 * zwbav(ji,jj) * 0.9 * hbl(ji,jj) )**pthird
+              zhol(ji,jj) = -0.9 * hbl(ji,jj) * 2.0 * zwbav(ji,jj) / (zvstr(ji,jj)**3 + epsln )
+              lconv(ji,jj) = .TRUE.
+           ELSE
+              zhol(ji,jj) = -hbl(ji,jj) *  2.0 * zwbav(ji,jj)/ (zvstr(ji,jj)**3  + epsln )
+              lconv(ji,jj) = .FALSE.
+           ENDIF
+        END DO
+     END DO
+
+     !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+     ! Mixed-layer model - calculate averages over the boundary layer, and the change in the boundary layer depth
+     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+     ! BL must be always 2 levels deep.
+      hbl(:,:) = MAX(hbl(:,:), gdepw_n(:,:,3) )
+      ibld(:,:) = 3
+      DO jk = 4, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               IF ( hbl(ji,jj) >= gdepw_n(ji,jj,jk) ) THEN
+                  ibld(ji,jj) = MIN(mbkt(ji,jj), jk)
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         DO ji = 2, jpim1
+               zthermal = rab_n(ji,jj,1,jp_tem) !ideally use ibld not 1??
+               zbeta    = rab_n(ji,jj,1,jp_sal)
+               zt   = 0._wp
+               zs   = 0._wp
+               zu   = 0._wp
+               zv   = 0._wp
+               ! average over depth of boundary layer
+               zthick=0._wp
+               DO jm = 2, ibld(ji,jj)
+                  zthick=zthick+e3t_n(ji,jj,jm)
+                  zt   = zt  + e3t_n(ji,jj,jm) * tsn(ji,jj,jm,jp_tem)
+                  zs   = zs  + e3t_n(ji,jj,jm) * tsn(ji,jj,jm,jp_sal)
+                  zu   = zu  + e3t_n(ji,jj,jm) &
+                     &            * ( ub(ji,jj,jm) + ub(ji - 1,jj,jm) ) &
+                     &            / MAX( 1. , umask(ji,jj,jm) + umask(ji - 1,jj,jm) )
+                  zv   = zv  + e3t_n(ji,jj,jm) &
+                     &            * ( vb(ji,jj,jm) + vb(ji,jj - 1,jm) ) &
+                     &            / MAX( 1. , vmask(ji,jj,jm) + vmask(ji,jj - 1,jm) )
+               END DO
+               zt_bl(ji,jj) = zt / zthick
+               zs_bl(ji,jj) = zs / zthick
+               zu_bl(ji,jj) = zu / zthick
+               zv_bl(ji,jj) = zv / zthick
+               zdt_bl(ji,jj) = zt_bl(ji,jj) - tsn(ji,jj,ibld(ji,jj),jp_tem)
+               zds_bl(ji,jj) = zs_bl(ji,jj) - tsn(ji,jj,ibld(ji,jj),jp_sal)
+               zdu_bl(ji,jj) = zu_bl(ji,jj) - ( ub(ji,jj,ibld(ji,jj)) + ub(ji-1,jj,ibld(ji,jj) ) ) &
+                     &    / MAX(1. , umask(ji,jj,ibld(ji,jj) ) + umask(ji-1,jj,ibld(ji,jj) ) )
+               zdv_bl(ji,jj) = zv_bl(ji,jj) - ( vb(ji,jj,ibld(ji,jj)) + vb(ji,jj-1,ibld(ji,jj) ) ) &
+                     &   / MAX(1. , vmask(ji,jj,ibld(ji,jj) ) + vmask(ji,jj-1,ibld(ji,jj) ) )
+               zdb_bl(ji,jj) = grav * zthermal * zdt_bl(ji,jj) - grav * zbeta * zds_bl(ji,jj)
+               IF ( lconv(ji,jj) ) THEN    ! Convective
+                      zwb_ent(ji,jj) = -( 2.0 * 0.2 * zwbav(ji,jj) &
+                           &            + 0.135 * zla(ji,jj) * zwstrl(ji,jj)**3/hbl(ji,jj) )
+
+                      zvel_max = - ( 1.0 + 1.0 * ( zwstrl(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird * rn_rdt / hbl(ji,jj) ) * zwb_ent(ji,jj) / &
+                           &       ( zwstrl(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird
+! Entrainment including component due to shear turbulence. Modified Langmuir component, but gives same result for La=0.3 For testing uncomment.
+!                      zwb_ent(ji,jj) = -( 2.0 * 0.2 * zwbav(ji,jj) &
+!                           &            + ( 0.15 * ( 1.0 - EXP( -0.5 * zla(ji,jj) ) ) + 0.03 / zla(ji,jj)**2 ) * zustar(ji,jj)**3/hbl(ji,jj) )
+
+!                      zvel_max = - ( 1.0 + 1.0 * ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird * rn_rdt / zhbl(ji,jj) ) * zwb_ent(ji,jj) / &
+!                           &       ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird
+                      zzdhdt = - zwb_ent(ji,jj) / ( zvel_max + MAX(zdb_bl(ji,jj),0.0) )
+               ELSE                        ! Stable
+                      zzdhdt = 0.32 * ( hbli(ji,jj) / hbl(ji,jj) -1.0 ) * zwstrl(ji,jj)**3 / hbli(ji,jj) &
+                           &   + ( ( 0.32 / 3.0 ) * exp ( -2.5 * ( hbli(ji,jj) / hbl(ji,jj) - 1.0 ) ) &
+                           & - ( 0.32 / 3.0 - 0.135 * zla(ji,jj) ) * exp ( -12.5 * ( hbli(ji,jj) / hbl(ji,jj) ) ) ) &
+                           &  * zwstrl(ji,jj)**3 / hbli(ji,jj)
+                      zzdhdt = zzdhdt + zwbav(ji,jj)
+                      IF ( zzdhdt < 0._wp ) THEN
+                      ! For long timsteps factor in brackets slows the rapid collapse of the OSBL
+                          zpert = 2.0 * ( 1.0 + 2.0 * zwstrl(ji,jj) * rn_rdt / hbl(ji,jj) ) * zwstrl(ji,jj)**2 / hbl(ji,jj)
+                      ELSE
+                          zpert = 2.0 * ( 1.0 + 2.0 * zwstrl(ji,jj) * rn_rdt / hbl(ji,jj) ) * zwstrl(ji,jj)**2 / hbl(ji,jj) + MAX( zdb_bl(ji,jj),0.0 )
+                      ENDIF
+                      zzdhdt = 2.0 * zzdhdt / zpert
+               ENDIF
+               zdhdt(ji,jj) = zzdhdt
+           END DO
+      END DO
+
+      ! Calculate averages over depth of boundary layer
+      imld = ibld           ! use imld to hold previous blayer index
+      ibld(:,:) = 3
+
+      zhbl_t(:,:) = hbl(:,:) + (zdhdt(:,:) - wn(ji,jj,ibld(ji,jj)))* rn_rdt ! certainly need wb here, so subtract it
+      zhbl_t(:,:) = MIN(zhbl_t(:,:), ht_n(:,:))
+      zdhdt(:,:) = MIN(zdhdt(:,:), (zhbl_t(:,:) - hbl(:,:))/rn_rdt + wn(ji,jj,ibld(ji,jj))) ! adjustment to represent limiting by ocean bottom
+
+      DO jk = 4, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               IF ( zhbl_t(ji,jj) >= gdepw_n(ji,jj,jk) ) THEN
+                  ibld(ji,jj) =  MIN(mbkt(ji,jj), jk)
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+!
+! Step through model levels taking account of buoyancy change to determine the effect on dhdt
+!
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+           IF ( ibld(ji,jj) - imld(ji,jj) > 1 ) THEN
+!
+! If boundary layer changes by more than one level, need to check for stable layers between initial and final depths.
+!
+              zhbl_s = hbl(ji,jj)
+              jm = imld(ji,jj)
+              zthermal = rab_n(ji,jj,1,jp_tem)
+              zbeta = rab_n(ji,jj,1,jp_sal)
+              IF ( lconv(ji,jj) ) THEN
+!unstable
+                 zvel_max = -( 1.0 + 1.0 * ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird * rn_rdt / hbl(ji,jj) ) * zwb_ent(ji,jj) / &
+                      &      ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird
+
+                 DO jk = imld(ji,jj), ibld(ji,jj)
+                    zdb = MAX( grav * ( zthermal * ( zt_bl(ji,jj) - tsn(ji,jj,jm,jp_tem) ) &
+                         & - zbeta * ( zs_bl(ji,jj) - tsn(ji,jj,jm,jp_sal) ) ), 0.0 ) + zvel_max
+
+                    zhbl_s = zhbl_s + MIN( - zwb_ent(ji,jj) / zdb * rn_rdt / FLOAT(ibld(ji,jj)-imld(ji,jj) ), e3w_n(ji,jj,jk) )
+                    zhbl_s = MIN(zhbl_s, ht_n(ji,jj))
+
+                    IF ( zhbl_s >= gdepw_n(ji,jj,jm+1) ) jm = jm + 1
+                 END DO
+                 hbl(ji,jj) = zhbl_s
+                 ibld(ji,jj) = jm
+                 hbli(ji,jj) = hbl(ji,jj)
+             ELSE
+! stable
+                 DO jk = imld(ji,jj), ibld(ji,jj)
+                    zdb = MAX( grav * ( zthermal * ( zt_bl(ji,jj) - tsn(ji,jj,jm,jp_tem) ) - zbeta * ( zs_bl(ji,jj) - tsn(ji,jj,jm,jp_sal) ) ), 0.0 ) + &
+             &       2.0 * zwstrl(ji,jj)**2 / zhbl_s
+
+                    zhbl_s = zhbl_s +  (&
+                         & 0.32 * ( hbli(ji,jj) / zhbl_s -1.0 ) * zwstrl(ji,jj)**3 / hbli(ji,jj) + &
+            &       ( ( 0.32 / 3.0 ) * EXP( -2.5 * ( hbli(ji,jj) / zhbl_s -1.0 )  ) - &
+            &       ( 0.32 / 3.0  - 0.0485 ) * EXP( -12.5 * ( hbli(ji,jj) / zhbl_s ) ) ) * zwstrl(ji,jj)**3 / hbli(ji,jj) ) / zdb * &
+            &       e3w_n(ji,jj,jk) / zdhdt(ji,jj)  ! ALMG to investigate whether need to include wn here
+
+                    zhbl_s = MIN(zhbl_s, ht_n(ji,jj))
+                    IF ( zhbl_s >= gdepw_n(ji,jj,jm) ) jm = jm + 1
+                 END DO
+                 hbl(ji,jj) = MAX(zhbl_s, gdepw_n(ji,jj,3) )
+                 ibld(ji,jj) = MAX(jm, 3 )
+                 IF ( hbl(ji,jj) > hbli(ji,jj) ) hbli(ji,jj) = hbl(ji,jj)
+             ENDIF   ! IF ( lconv )
+           ELSE
+! change zero or one model level.
+             hbl(ji,jj) = zhbl_t(ji,jj)
+             IF ( lconv(ji,jj) ) THEN
+                 hbli(ji,jj) = hbl(ji,jj)
+             ELSE
+                 hbl(ji,jj) = MAX(hbl(ji,jj), gdepw_n(ji,jj,3) )
+                 IF ( hbl(ji,jj) > hbli(ji,jj) ) hbli(ji,jj) = hbl(ji,jj)
+             ENDIF
+           ENDIF
+           zhbl(ji,jj) = gdepw_n(ji,jj,ibld(ji,jj))
+         END DO
+      END DO
+      dstokes(:,:) = MIN ( dstokes(:,:), hbl(:,:)/3. )  !  Limit delta for shallow boundary layers for calculating flux-gradient terms.
+
+! Recalculate averages over boundary layer after depth updated
+     ! Consider later  combining this into the loop above and looking for columns
+     ! where the index for base of the boundary layer have changed
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         DO ji = 2, jpim1
+               zthermal = rab_n(ji,jj,1,jp_tem) !ideally use ibld not 1??
+               zbeta    = rab_n(ji,jj,1,jp_sal)
+               zt   = 0._wp
+               zs   = 0._wp
+               zu   = 0._wp
+               zv   = 0._wp
+               ! average over depth of boundary layer
+               zthick=0._wp
+               DO jm = 2, ibld(ji,jj)
+                  zthick=zthick+e3t_n(ji,jj,jm)
+                  zt   = zt  + e3t_n(ji,jj,jm) * tsn(ji,jj,jm,jp_tem)
+                  zs   = zs  + e3t_n(ji,jj,jm) * tsn(ji,jj,jm,jp_sal)
+                  zu   = zu  + e3t_n(ji,jj,jm) &
+                     &            * ( ub(ji,jj,jm) + ub(ji - 1,jj,jm) ) &
+                     &            / MAX( 1. , umask(ji,jj,jm) + umask(ji - 1,jj,jm) )
+                  zv   = zv  + e3t_n(ji,jj,jm) &
+                     &            * ( vb(ji,jj,jm) + vb(ji,jj - 1,jm) ) &
+                     &            / MAX( 1. , vmask(ji,jj,jm) + vmask(ji,jj - 1,jm) )
+               END DO
+               zt_bl(ji,jj) = zt / zthick
+               zs_bl(ji,jj) = zs / zthick
+               zu_bl(ji,jj) = zu / zthick
+               zv_bl(ji,jj) = zv / zthick
+               zdt_bl(ji,jj) = zt_bl(ji,jj) - tsn(ji,jj,ibld(ji,jj),jp_tem)
+               zds_bl(ji,jj) = zs_bl(ji,jj) - tsn(ji,jj,ibld(ji,jj),jp_sal)
+               zdu_bl(ji,jj) = zu_bl(ji,jj) - ( ub(ji,jj,ibld(ji,jj)) + ub(ji-1,jj,ibld(ji,jj) ) ) &
+                      &   / MAX(1. , umask(ji,jj,ibld(ji,jj) ) + umask(ji-1,jj,ibld(ji,jj) ) )
+               zdv_bl(ji,jj) = zv_bl(ji,jj) - ( vb(ji,jj,ibld(ji,jj)) + vb(ji,jj-1,ibld(ji,jj) ) ) &
+                      &  / MAX(1. , vmask(ji,jj,ibld(ji,jj) ) + vmask(ji,jj-1,ibld(ji,jj) ) )
+               zdb_bl(ji,jj) = grav * zthermal * zdt_bl(ji,jj) - grav * zbeta * zds_bl(ji,jj)
+               zhbl(ji,jj) = gdepw_n(ji,jj,ibld(ji,jj))
+               IF ( lconv(ji,jj) ) THEN
+                  IF ( zdb_bl(ji,jj) > 0._wp )THEN
+                     IF ( ( zwstrc(ji,jj) / zvstr(ji,jj) )**3 <= 0.5 ) THEN  ! near neutral stability
+                           zari = 4.5 * ( zvstr(ji,jj)**2 ) &
+                             & / ( zdb_bl(ji,jj) * zhbl(ji,jj) ) + 0.01
+                     ELSE                                                     ! unstable
+                           zari = 4.5 * ( zwstrc(ji,jj)**2 ) &
+                             & / ( zdb_bl(ji,jj) * zhbl(ji,jj) ) + 0.01
+                     ENDIF
+                     IF ( zari > 0.2 ) THEN                                                ! This test checks for weakly stratified pycnocline
+                        zari = 0.2
+                        zwb_ent(ji,jj) = 0._wp
+                     ENDIF
+                     inhml = MAX( INT( zari * zhbl(ji,jj) / e3t_n(ji,jj,ibld(ji,jj)) ) , 1 )
+                     imld(ji,jj) = MAX( ibld(ji,jj) - inhml, 1)
+                     zhml(ji,jj) = gdepw_n(ji,jj,imld(ji,jj))
+                     zdh(ji,jj) = zhbl(ji,jj) - zhml(ji,jj)
+                  ELSE  ! IF (zdb_bl)
+                     imld(ji,jj) = ibld(ji,jj) - 1
+                     zhml(ji,jj) = gdepw_n(ji,jj,imld(ji,jj))
+                     zdh(ji,jj) = zhbl(ji,jj) - zhml(ji,jj)
+                  ENDIF
+               ELSE   ! IF (lconv)
+                  IF ( zdhdt(ji,jj) >= 0.0 ) THEN    ! probably shouldn't include wm here
+                  ! boundary layer deepening
+                     IF ( zdb_bl(ji,jj) > 0._wp ) THEN
+                  ! pycnocline thickness set by stratification - use same relationship as for neutral conditions.
+                        zari = MIN( 4.5 * ( zvstr(ji,jj)**2 ) &
+                          & / ( zdb_bl(ji,jj) * zhbl(ji,jj) ) + 0.01  , 0.2 )
+                        inhml = MAX( INT( zari * zhbl(ji,jj) / e3t_n(ji,jj,ibld(ji,jj)) ) , 1 )
+                        imld(ji,jj) = MAX( ibld(ji,jj) - inhml, 1)
+                        zhml(ji,jj) = gdepw_n(ji,jj,imld(ji,jj))
+                        zdh(ji,jj) = zhbl(ji,jj) - zhml(ji,jj)
+                     ELSE
+                        imld(ji,jj) = ibld(ji,jj) - 1
+                        zhml(ji,jj) = gdepw_n(ji,jj,imld(ji,jj))
+                        zdh(ji,jj) = zhbl(ji,jj) - zhml(ji,jj)
+                     ENDIF ! IF (zdb_bl > 0.0)
+                  ELSE     ! IF(dhdt >= 0)
+                  ! boundary layer collapsing.
+                     imld(ji,jj) = ibld(ji,jj)
+                     zhml(ji,jj) = zhbl(ji,jj)
+                     zdh(ji,jj) = 0._wp
+                  ENDIF    ! IF (dhdt >= 0)
+               ENDIF       ! IF (lconv)
+         END DO
+      END DO
+
+      ! Average over the depth of the mixed layer in the convective boundary layer
+      ! Also calculate entrainment fluxes for temperature and salinity
+      DO jj = 2, jpjm1                                 !  Vertical slab
+         DO ji = 2, jpim1
+            zthermal = rab_n(ji,jj,1,jp_tem) !ideally use ibld not 1??
+            zbeta    = rab_n(ji,jj,1,jp_sal)
+            IF ( lconv(ji,jj) ) THEN
+               zt   = 0._wp
+               zs   = 0._wp
+               zu   = 0._wp
+               zv   = 0._wp
+               ! average over depth of boundary layer
+               zthick=0._wp
+               DO jm = 2, imld(ji,jj)
+                  zthick=zthick+e3t_n(ji,jj,jm)
+                  zt   = zt  + e3t_n(ji,jj,jm) * tsn(ji,jj,jm,jp_tem)
+                  zs   = zs  + e3t_n(ji,jj,jm) * tsn(ji,jj,jm,jp_sal)
+                  zu   = zu  + e3t_n(ji,jj,jm) &
+                     &            * ( ub(ji,jj,jm) + ub(ji - 1,jj,jm) ) &
+                     &            / MAX( 1. , umask(ji,jj,jm) + umask(ji - 1,jj,jm) )
+                  zv   = zv  + e3t_n(ji,jj,jm) &
+                     &            * ( vb(ji,jj,jm) + vb(ji,jj - 1,jm) ) &
+                     &            / MAX( 1. , vmask(ji,jj,jm) + vmask(ji,jj - 1,jm) )
+               END DO
+               zt_ml(ji,jj) = zt / zthick
+               zs_ml(ji,jj) = zs / zthick
+               zu_ml(ji,jj) = zu / zthick
+               zv_ml(ji,jj) = zv / zthick
+               zdt_ml(ji,jj) = zt_ml(ji,jj) - tsn(ji,jj,ibld(ji,jj),jp_tem)
+               zds_ml(ji,jj) = zs_ml(ji,jj) - tsn(ji,jj,ibld(ji,jj),jp_sal)
+               zdu_ml(ji,jj) = zu_ml(ji,jj) - ( ub(ji,jj,ibld(ji,jj)) + ub(ji-1,jj,ibld(ji,jj) ) ) &
+                     &    / MAX(1. , umask(ji,jj,ibld(ji,jj) ) + umask(ji-1,jj,ibld(ji,jj) ) )
+               zdv_ml(ji,jj) = zv_ml(ji,jj) - ( vb(ji,jj,ibld(ji,jj)) + vb(ji,jj-1,ibld(ji,jj) ) ) &
+                     &    / MAX(1. , vmask(ji,jj,ibld(ji,jj) ) + vmask(ji,jj-1,ibld(ji,jj) ) )
+               zdb_ml(ji,jj) = grav * zthermal * zdt_ml(ji,jj) - grav * zbeta * zds_ml(ji,jj)
+            ELSE
+            ! stable, if entraining calulate average below interface layer.
+               IF ( zdhdt(ji,jj) >= 0._wp ) THEN
+                  zt   = 0._wp
+                  zs   = 0._wp
+                  zu   = 0._wp
+                  zv   = 0._wp
+                  ! average over depth of boundary layer
+                  zthick=0._wp
+                  DO jm = 2, imld(ji,jj)
+                     zthick=zthick+e3t_n(ji,jj,jm)
+                     zt   = zt  + e3t_n(ji,jj,jm) * tsn(ji,jj,jm,jp_tem)
+                     zs   = zs  + e3t_n(ji,jj,jm) * tsn(ji,jj,jm,jp_sal)
+                     zu   = zu  + e3t_n(ji,jj,jm) &
+                        &            * ( ub(ji,jj,jm) + ub(ji - 1,jj,jm) ) &
+                        &            / MAX( 1. , umask(ji,jj,jm) + umask(ji - 1,jj,jm) )
+                     zv   = zv  + e3t_n(ji,jj,jm) &
+                        &            * ( vb(ji,jj,jm) + vb(ji,jj - 1,jm) ) &
+                        &            / MAX( 1. , vmask(ji,jj,jm) + vmask(ji,jj - 1,jm) )
+                  END DO
+                  zt_ml(ji,jj) = zt / zthick
+                  zs_ml(ji,jj) = zs / zthick
+                  zu_ml(ji,jj) = zu / zthick
+                  zv_ml(ji,jj) = zv / zthick
+                  zdt_ml(ji,jj) = zt_ml(ji,jj) - tsn(ji,jj,ibld(ji,jj),jp_tem)
+                  zds_ml(ji,jj) = zs_ml(ji,jj) - tsn(ji,jj,ibld(ji,jj),jp_sal)
+                  zdu_ml(ji,jj) = zu_ml(ji,jj) - ( ub(ji,jj,ibld(ji,jj)) + ub(ji-1,jj,ibld(ji,jj) ) ) &
+                        &    / MAX(1. , umask(ji,jj,ibld(ji,jj) ) + umask(ji-1,jj,ibld(ji,jj) ) )
+                  zdv_ml(ji,jj) = zv_ml(ji,jj) - ( vb(ji,jj,ibld(ji,jj)) + vb(ji,jj-1,ibld(ji,jj) ) ) &
+                        &    / MAX(1. , vmask(ji,jj,ibld(ji,jj) ) + vmask(ji,jj-1,ibld(ji,jj) ) )
+                  zdb_ml(ji,jj) = grav * zthermal * zdt_ml(ji,jj) - grav * zbeta * zds_ml(ji,jj)
+               ENDIF
+            ENDIF
+         END DO
+      END DO
+    !
+    ! rotate mean currents and changes onto wind align co-ordinates
+    !
+
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            ztemp = zu_ml(ji,jj)
+            zu_ml(ji,jj) = zu_ml(ji,jj) * zcos_wind(ji,jj) + zv_ml(ji,jj) * zsin_wind(ji,jj)
+            zv_ml(ji,jj) = zv_ml(ji,jj) * zcos_wind(ji,jj) - ztemp * zsin_wind(ji,jj)
+            ztemp = zdu_ml(ji,jj)
+            zdu_ml(ji,jj) = zdu_ml(ji,jj) * zcos_wind(ji,jj) + zdv_ml(ji,jj) * zsin_wind(ji,jj)
+            zdv_ml(ji,jj) = zdv_ml(ji,jj) * zsin_wind(ji,jj) - ztemp * zsin_wind(ji,jj)
+    !
+            ztemp = zu_bl(ji,jj)
+            zu_bl = zu_bl(ji,jj) * zcos_wind(ji,jj) + zv_bl(ji,jj) * zsin_wind(ji,jj)
+            zv_bl(ji,jj) = zv_bl(ji,jj) * zcos_wind(ji,jj) - ztemp * zsin_wind(ji,jj)
+            ztemp = zdu_bl(ji,jj)
+            zdu_bl(ji,jj) = zdu_bl(ji,jj) * zcos_wind(ji,jj) + zdv_bl(ji,jj) * zsin_wind(ji,jj)
+            zdv_bl(ji,jj) = zdv_bl(ji,jj) * zsin_wind(ji,jj) - ztemp * zsin_wind(ji,jj)
+         END DO
+      END DO
+
+     zuw_bse = 0._wp
+     zvw_bse = 0._wp
+     DO jj = 2, jpjm1
+        DO ji = 2, jpim1
+
+           IF ( lconv(ji,jj) ) THEN
+              IF ( zdb_bl(ji,jj) > 0._wp ) THEN
+                 zwth_ent(ji,jj) = zwb_ent(ji,jj) * zdt_ml(ji,jj) / (zdb_ml(ji,jj) + epsln)
+                 zws_ent(ji,jj) = zwb_ent(ji,jj) * zds_ml(ji,jj) / (zdb_ml(ji,jj) + epsln)
+              ENDIF
+           ELSE
+              zwth_ent(ji,jj) = -2.0 * zwthav(ji,jj) * ( (1.0 - 0.8) - ( 1.0 - 0.8)**(3.0/2.0) )
+              zws_ent(ji,jj) = -2.0 * zwsav(ji,jj) * ( (1.0 - 0.8 ) - ( 1.0 - 0.8 )**(3.0/2.0) )
+           ENDIF
+        END DO
+     END DO
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      !  Pycnocline gradients for scalars and velocity
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+       DO jj = 2, jpjm1
+          DO ji = 2, jpim1
+          !
+             IF ( lconv (ji,jj) ) THEN
+             ! Unstable conditions
+                IF( zdb_bl(ji,jj) > 0._wp ) THEN
+                ! calculate pycnocline profiles, no need if zdb_bl <= 0. since profile is zero and arrays have been initialized to zero
+                   ztgrad = ( zdt_ml(ji,jj) / zdh(ji,jj) )
+                   zsgrad = ( zds_ml(ji,jj) / zdh(ji,jj) )
+                   zbgrad = ( zdb_ml(ji,jj) / zdh(ji,jj) )
+                   DO jk = 2 , ibld(ji,jj)
+                      znd = -( gdepw_n(ji,jj,jk) - zhml(ji,jj) ) / zdh(ji,jj)
+                      zdtdz_pyc(ji,jj,jk) =  ztgrad * EXP( -1.75 * ( znd + 0.75 )**2 )
+                      zdbdz_pyc(ji,jj,jk) =  zbgrad * EXP( -1.75 * ( znd + 0.75 )**2 )
+                      zdsdz_pyc(ji,jj,jk) =  zsgrad * EXP( -1.75 * ( znd + 0.75 )**2 )
+                   END DO
+                ENDIF
+             ELSE
+             ! stable conditions
+             ! if pycnocline profile only defined when depth steady of increasing.
+                IF ( zdhdt(ji,jj) >= 0.0 ) THEN        ! Depth increasing, or steady.
+                   IF ( zdb_bl(ji,jj) > 0._wp ) THEN
+                     IF ( zhol(ji,jj) >= 0.5 ) THEN      ! Very stable - 'thick' pycnocline
+                         ztgrad = zdt_bl(ji,jj) / zhbl(ji,jj)
+                         zsgrad = zds_bl(ji,jj) / zhbl(ji,jj)
+                         zbgrad = zdb_bl(ji,jj) / zhbl(ji,jj)
+                         DO jk = 2, ibld(ji,jj)
+                            znd = gdepw_n(ji,jj,jk) / zhbl(ji,jj)
+                            zdtdz_pyc(ji,jj,jk) =  ztgrad * EXP( -15.0 * ( znd - 0.9 )**2 )
+                            zdbdz_pyc(ji,jj,jk) =  zbgrad * EXP( -15.0 * ( znd - 0.9 )**2 )
+                            zdsdz_pyc(ji,jj,jk) =  zsgrad * EXP( -15.0 * ( znd - 0.9 )**2 )
+                         END DO
+                     ELSE                                   ! Slightly stable - 'thin' pycnoline - needed when stable layer begins to form.
+                         ztgrad = zdt_bl(ji,jj) / zdh(ji,jj)
+                         zsgrad = zds_bl(ji,jj) / zdh(ji,jj)
+                         zbgrad = zdb_bl(ji,jj) / zdh(ji,jj)
+                         DO jk = 2, ibld(ji,jj)
+                            znd = -( gdepw_n(ji,jj,jk) - zhml(ji,jj) ) / zdh(ji,jj)
+                            zdtdz_pyc(ji,jj,jk) =  ztgrad * EXP( -1.75 * ( znd + 0.75 )**2 )
+                            zdbdz_pyc(ji,jj,jk) =  zbgrad * EXP( -1.75 * ( znd + 0.75 )**2 )
+                            zdsdz_pyc(ji,jj,jk) =  zsgrad * EXP( -1.75 * ( znd + 0.75 )**2 )
+                         END DO
+                      ENDIF ! IF (zhol >=0.5)
+                   ENDIF    ! IF (zdb_bl> 0.)
+                ENDIF       ! IF (zdhdt >= 0) zdhdt < 0 not considered since pycnocline profile is zero, profile arrays are intialized to zero
+             ENDIF          ! IF (lconv)
+            !
+          END DO
+       END DO
+!
+       DO jj = 2, jpjm1
+          DO ji = 2, jpim1
+          !
+             IF ( lconv (ji,jj) ) THEN
+             ! Unstable conditions
+                 zugrad = ( zdu_ml(ji,jj) / zdh(ji,jj) ) + 0.275 * zustar(ji,jj)*zustar(ji,jj) / &
+               & (( zwstrl(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird * zhml(ji,jj) ) / zla(ji,jj)**(8.0/3.0)
+                zvgrad = ( zdv_ml(ji,jj) / zdh(ji,jj) ) + 3.5 * ff_t(ji,jj) * zustke(ji,jj) / &
+              & ( zwstrl(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird
+                DO jk = 2 , ibld(ji,jj)-1
+                   znd = -( gdepw_n(ji,jj,jk) - zhml(ji,jj) ) / zdh(ji,jj)
+                   zdudz_pyc(ji,jj,jk) =  zugrad * EXP( -1.75 * ( znd + 0.75 )**2 )
+                   zdvdz_pyc(ji,jj,jk) = zvgrad * EXP( -1.75 * ( znd + 0.75 )**2 )
+                END DO
+             ELSE
+             ! stable conditions
+                zugrad = 3.25 * zdu_bl(ji,jj) / zhbl(ji,jj)
+                zvgrad = 2.75 * zdv_bl(ji,jj) / zhbl(ji,jj)
+                DO jk = 2, ibld(ji,jj)
+                   znd = gdepw_n(ji,jj,jk) / zhbl(ji,jj)
+                   IF ( znd < 1.0 ) THEN
+                      zdudz_pyc(ji,jj,jk) = zugrad * EXP( -40.0 * ( znd - 1.0 )**2 )
+                   ELSE
+                      zdudz_pyc(ji,jj,jk) = zugrad * EXP( -20.0 * ( znd - 1.0 )**2 )
+                   ENDIF
+                   zdvdz_pyc(ji,jj,jk) = zvgrad * EXP( -20.0 * ( znd - 0.85 )**2 )
+                END DO
+             ENDIF
+            !
+          END DO
+       END DO
+       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+       ! Eddy viscosity/diffusivity and non-gradient terms in the flux-gradient relationship
+       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      ! WHERE ( lconv )
+      !     zdifml_sc = zhml * ( zwstrl**3 + 0.5 * zwstrc**3 )**pthird
+      !     zvisml_sc = zdifml_sc
+      !     zdifpyc_sc = 0.165 * ( zwstrl**3 + zwstrc**3 )**pthird * ( zhbl - zhml )
+      !     zvispyc_sc = 0.142 * ( zwstrl**3 + 0.5 * zwstrc**3 )**pthird * ( zhbl - zhml )
+      !     zbeta_d_sc = 1.0 - (0.165 / 0.8 * ( zhbl - zhml ) / zhbl )**p2third
+      !     zbeta_v_sc = 1.0 -  2.0 * (0.142 /0.375) * (zhbl - zhml ) / zhml
+      !  ELSEWHERE
+      !     zdifml_sc = zwstrl * zhbl * EXP ( -( zhol / 0.183_wp )**2 )
+      !     zvisml_sc = zwstrl * zhbl * EXP ( -( zhol / 0.183_wp )**2 )
+      !  ENDWHERE
+       DO jj = 2, jpjm1
+          DO ji = 2, jpim1
+             IF ( lconv(ji,jj) ) THEN
+               zdifml_sc(ji,jj) = zhml(ji,jj) * ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird
+               zvisml_sc(ji,jj) = zdifml_sc(ji,jj)
+               zdifpyc_sc(ji,jj) = 0.165 * ( zvstr(ji,jj)**3 + 0.5 *zwstrc(ji,jj)**3 )**pthird * zdh(ji,jj)
+               zvispyc_sc(ji,jj) = 0.142 * ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird * zdh(ji,jj)
+               zbeta_d_sc(ji,jj) = 1.0 - (0.165 / 0.8 * zdh(ji,jj) / zhbl(ji,jj) )**p2third
+               zbeta_v_sc(ji,jj) = 1.0 -  2.0 * (0.142 /0.375) * zdh(ji,jj) / zhml(ji,jj)
+             ELSE
+               zdifml_sc(ji,jj) = zvstr(ji,jj) * zhbl(ji,jj) * EXP ( -( zhol(ji,jj) / 0.6_wp )**2 )
+               zvisml_sc(ji,jj) = zvstr(ji,jj) * zhbl(ji,jj) * EXP ( -( zhol(ji,jj) / 0.6_wp )**2 )
+            END IF
+        END DO
+    END DO
+!
+       DO jj = 2, jpjm1
+          DO ji = 2, jpim1
+             IF ( lconv(ji,jj) ) THEN
+                DO jk = 2, imld(ji,jj)   ! mixed layer diffusivity
+                    zznd_ml = gdepw_n(ji,jj,jk) / zhml(ji,jj)
+                    !
+                    zdiffut(ji,jj,jk) = 0.8 * zdifml_sc(ji,jj) * zznd_ml * ( 1.0 - zbeta_d_sc(ji,jj) * zznd_ml )**1.5
+                    !
+                    zviscos(ji,jj,jk) = 0.375 * zvisml_sc(ji,jj) * zznd_ml * ( 1.0 - zbeta_v_sc(ji,jj) * zznd_ml ) * ( 1.0 - 0.5 * zznd_ml**2 )
+                END DO
+                ! pycnocline - if present linear profile
+                IF ( zdh(ji,jj) > 0._wp ) THEN
+                   DO jk = imld(ji,jj)+1 , ibld(ji,jj)
+                       zznd_pyc = -( gdepw_n(ji,jj,jk) - zhml(ji,jj) ) / zdh(ji,jj)
+                       !
+                       zdiffut(ji,jj,jk) = zdifpyc_sc(ji,jj)*( 1.0 + zznd_pyc )
+                       !
+                       zviscos(ji,jj,jk) = zvispyc_sc(ji,jj) * ( 1.0 + zznd_pyc )
+                   END DO
+                ENDIF
+                ! Temporay fix to ensure zdiffut is +ve; won't be necessary with wn taken out
+                zdiffut(ji,jj,ibld(ji,jj)) = zdhdt(ji,jj)* e3t_n(ji,jj,ibld(ji,jj))
+                ! could be taken out, take account of entrainment represents as a diffusivity
+                ! should remove w from here, represents entrainment
+             ELSE
+             ! stable conditions
+                DO jk = 2, ibld(ji,jj)
+                   zznd_ml = gdepw_n(ji,jj,jk) / zhbl(ji,jj)
+                   zdiffut(ji,jj,jk) = 0.75 * zdifml_sc(ji,jj) * zznd_ml * ( 1.0 - zznd_ml )**1.5
+                   zviscos(ji,jj,jk) = 0.375 * zvisml_sc(ji,jj) * zznd_ml * (1.0 - zznd_ml) * ( 1.0 - zznd_ml**2 )
+                END DO
+             ENDIF   ! end if ( lconv )
+!
+          END DO  ! end of ji loop
+       END DO     ! end of jj loop
+
+       !
+       ! calculate non-gradient components of the flux-gradient relationships
+       !
+! Stokes term in scalar flux, flux-gradient relationship
+       WHERE ( lconv )
+          zsc_wth_1 = zwstrl**3 * zwth0 / ( zvstr**3 + 0.5 * zwstrc**3 + epsln)
+          !
+          zsc_ws_1 = zwstrl**3 * zws0 / ( zvstr**3 + 0.5 * zwstrc**3 + epsln )
+       ELSEWHERE
+          zsc_wth_1 = 2.0 * zwthav
+          !
+          zsc_ws_1 = 2.0 * zwsav
+       ENDWHERE
+
+
+       DO jj = 2, jpjm1
+          DO ji = 2, jpim1
+            IF ( lconv(ji,jj) ) THEN
+              DO jk = 2, imld(ji,jj)
+                 zznd_d = gdepw_n(ji,jj,jk) / dstokes(ji,jj)
+                 ghamt(ji,jj,jk) = ghamt(ji,jj,jk) +  1.35 * EXP ( -zznd_d ) * ( 1.0 - EXP ( -2.0 * zznd_d ) ) * zsc_wth_1(ji,jj)
+                 !
+                 ghams(ji,jj,jk) = ghams(ji,jj,jk) + 1.35 * EXP ( -zznd_d ) * ( 1.0 - EXP ( -2.0 * zznd_d ) ) * zsc_ws_1(ji,jj)
+              END DO ! end jk loop
+            ELSE     ! else for if (lconv)
+ ! Stable conditions
+               DO jk = 2, ibld(ji,jj)
+                  zznd_d=gdepw_n(ji,jj,jk) / dstokes(ji,jj)
+                  ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + 1.5 * EXP ( -0.9 * zznd_d ) * ( 1.0 - EXP ( -4.0 * zznd_d ) ) * zsc_wth_1(ji,jj)
+                  !
+                  ghams(ji,jj,jk) = ghams(ji,jj,jk) + 1.5 * EXP ( -0.9 * zznd_d ) * ( 1.0 - EXP ( -4.0 * zznd_d ) ) * zsc_ws_1(ji,jj)
+               END DO
+            ENDIF               ! endif for check on lconv
+
+          END DO  ! end of ji loop
+       END DO     ! end of jj loop
+
+
+! Stokes term in flux-gradient relationship (note in zsc_uw_n don't use zvstr since term needs to go to zero as zwstrl goes to zero)
+       WHERE ( lconv )
+          zsc_uw_1 = ( zwstrl**3 + 0.5 * zwstrc**3 )**pthird * zustke /( 1.0 - 1.0 * 6.5 * zla**(8.0/3.0) )
+          zsc_uw_2 = ( zwstrl**3 + 0.5 * zwstrc**3 )**pthird * zustke / ( zla**(8.0/3.0) + epsln )
+          zsc_vw_1 = ff_t * zhml * zustke**3 * zla**(8.0/3.0) / ( ( zvstr**3 + 0.5 * zwstrc**3 )**(2.0/3.0) + epsln )
+       ELSEWHERE
+          zsc_uw_1 = zustar**2
+          zsc_vw_1 = ff_t * zhbl * zustke**3 * zla**(8.0/3.0) / (zvstr**2 + epsln)
+       ENDWHERE
+
+       DO jj = 2, jpjm1
+          DO ji = 2, jpim1
+             IF ( lconv(ji,jj) ) THEN
+                DO jk = 2, imld(ji,jj)
+                   zznd_d = gdepw_n(ji,jj,jk) / dstokes(ji,jj)
+                   ghamu(ji,jj,jk) = ghamu(ji,jj,jk) + ( -0.05 * EXP ( -0.4 * zznd_d ) * zsc_uw_1(ji,jj) + 0.00125 * EXP ( -zznd_d ) * zsc_uw_2(ji,jj) ) * ( 1.0 - EXP ( -2.0 * zznd_d ) )
+!
+                   ghamv(ji,jj,jk) = ghamv(ji,jj,jk) - 0.65 * 0.15 * EXP ( -zznd_d ) * ( 1.0 - EXP ( -2.0 * zznd_d ) ) * zsc_vw_1(ji,jj)
+                END DO   ! end jk loop
+             ELSE
+! Stable conditions
+                DO jk = 2, ibld(ji,jj) ! corrected to ibld
+                   zznd_d = gdepw_n(ji,jj,jk) / dstokes(ji,jj)
+                   ghamu(ji,jj,jk) = ghamu(ji,jj,jk) - 0.75 * 1.3 * EXP ( -0.5 * zznd_d ) * ( 1.0 - EXP ( -4.0 * zznd_d ) ) * zsc_uw_1(ji,jj)
+                   ghamv(ji,jj,jk) = ghamv(ji,jj,jk) + 0._wp
+                END DO   ! end jk loop
+             ENDIF
+          END DO  ! ji loop
+       END DO     ! jj loo
+
+! Buoyancy term in flux-gradient relationship [note : includes ROI ratio (X0.3) and pressure (X0.5)]
+
+       WHERE ( lconv )
+          zsc_wth_1 = zwbav * zwth0 * ( 1.0 + EXP ( 0.2 * zhol ) ) / ( zvstr**3 + 0.5 * zwstrc**3 + epsln )
+          zsc_ws_1 = zwbav * zws0 * ( 1.0 + EXP ( 0.2 * zhol ) ) / ( zvstr**3 + 0.5 * zwstrc**3 + epsln )
+       ELSEWHERE
+          zsc_wth_1 = 0._wp
+          zsc_ws_1 = 0._wp
+       ENDWHERE
+
+       DO jj = 2, jpjm1
+          DO ji = 2, jpim1
+             IF (lconv(ji,jj) ) THEN
+                DO jk = 2, imld(ji,jj)
+                   zznd_ml = gdepw_n(ji,jj,jk) / zhml(ji,jj)
+            ! calculate turbulent length scale
+                   zl_c = 0.9 * ( 1.0 - EXP ( -7.0 * ( zznd_ml - zznd_ml**3 / 3.0 ) ) ) * ( 1.0 - EXP ( -15.0 * ( 1.1 - zznd_ml ) ) )
+                   zl_l = 2.0 * ( 1.0 - EXP ( -2.0 * ( zznd_ml - zznd_ml**3 / 3.0 ) ) ) * (1.0 -  EXP ( -5.0 * ( 1.0 -zznd_ml ) ) ) * ( 1.0 + dstokes(ji,jj) / zhml (ji,jj) )
+                   zl_eps = zl_l + ( zl_c - zl_l ) / ( 1.0 + EXP ( 3.0 * LOG10 ( - zhol(ji,jj) ) ) ) ** (3.0/2.0)
+            ! non-gradient buoyancy terms
+                   ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + 0.3 * 0.5 * zsc_wth_1(ji,jj) * zl_eps * zhml(ji,jj) / ( 0.15 + zznd_ml )
+                   ghams(ji,jj,jk) = ghams(ji,jj,jk) + 0.3 * 0.5 * zsc_ws_1(ji,jj) * zl_eps * zhml(ji,jj) / ( 0.15 + zznd_ml )
+                END DO
+             ELSE
+                DO jk = 2, ibld(ji,jj)
+                   ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + zsc_wth_1(ji,jj)
+                   ghams(ji,jj,jk) = ghams(ji,jj,jk) + zsc_ws_1(ji,jj)
+                END DO
+             ENDIF
+          END DO   ! ji loop
+       END DO      ! jj loop
+
+
+       WHERE ( lconv )
+          zsc_uw_1 = -zwb0 * zustar**2 * zhml / ( zvstr**3 + 0.5 * zwstrc**3 + epsln )
+          zsc_uw_2 = zwb0 *  zustke * zhml / ( zvstr**3 + 0.5 * zwstrc**3 + epsln )**(2.0/3.0)
+          zsc_vw_1 = 0._wp
+       ELSEWHERE
+         zsc_uw_1 = 0._wp
+         zsc_vw_1 = 0._wp
+       ENDWHERE
+
+       DO jj = 2, jpjm1
+          DO ji = 2, jpim1
+             IF ( lconv(ji,jj) ) THEN
+                DO jk = 2 , imld(ji,jj)
+                   zznd_d = gdepw_n(ji,jj,jk) / dstokes(ji,jj)
+                   ghamu(ji,jj,jk) = ghamu(ji,jj,jk) + 0.3 * 0.5 * ( zsc_uw_1(ji,jj) + 0.125 * EXP( -0.5 * zznd_d ) * ( 1.0 - EXP ( -0.5 * zznd_d) ) * zsc_uw_2(ji,jj) )
+                   ghamv(ji,jj,jk) = ghamv(ji,jj,jk) + zsc_vw_1(ji,jj)
+                END DO  ! jk loop
+             ELSE
+             ! stable conditions
+                DO jk = 2, ibld(ji,jj)
+                   ghamu(ji,jj,jk) = ghamu(ji,jj,jk) + zsc_uw_1(ji,jj)
+                   ghamv(ji,jj,jk) = ghamv(ji,jj,jk) + zsc_vw_1(ji,jj)
+                END DO
+             ENDIF
+          END DO        ! ji loop
+       END DO           ! jj loop
+
+! Transport term in flux-gradient relationship [note : includes ROI ratio (X0.3) ]
+
+       WHERE ( lconv )
+          zsc_wth_1 = zwth0
+          zsc_ws_1 = zws0
+       ELSEWHERE
+          zsc_wth_1 = 2.0 * zwthav
+          zsc_ws_1 = zws0
+       ENDWHERE
+
+       DO jj = 2, jpjm1
+          DO ji = 2, jpim1
+            IF ( lconv(ji,jj) ) THEN
+               DO jk = 2, imld(ji,jj)
+                  zznd_ml=gdepw_n(ji,jj,jk) / zhml(ji,jj)
+                  ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + 0.3 * zsc_wth_1(ji,jj) * ( -2.0 + 2.75 * ( ( 1.0 + 0.6 * zznd_ml**4 ) - EXP ( -6.0 *zznd_ml ) ) )  &
+      &           * ( 1.0 -EXP ( -15.0 * ( 1.0 - zznd_ml ) ) )
+                  !
+                  ghams(ji,jj,jk) = ghams(ji,jj,jk) + 0.3 * zsc_ws_1(ji,jj) * ( -2.0 + 2.75 * ( ( 1.0 + 0.6 * zznd_ml**4 ) - EXP ( -6.0 *zznd_ml ) ) )  &
+      &           * ( 1.0 -EXP ( -15.0 * ( 1.0 - zznd_ml ) ) )
+               END DO
+            ELSE
+               DO jk = 2, ibld(ji,jj)
+                  zznd_d = gdepw_n(ji,jj,jk) / dstokes(ji,jj)
+                  znd = gdepw_n(ji,jj,jk) / zhbl(ji,jj)
+                  ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + 0.3 * ( -4.06 * EXP( -2.0 * zznd_d ) * (1.0 - EXP( -4.0 * zznd_d ) ) + &
+               &  7.5 * EXP ( -10.0 * ( 0.95 - znd )**2 ) * ( 1.0 - znd ) ) * zsc_wth_1(ji,jj)
+                  ghams(ji,jj,jk) = ghams(ji,jj,jk) + 0.3 * ( -4.06 * EXP( -2.0 * zznd_d ) * (1.0 - EXP( -4.0 * zznd_d ) ) + &
+               &  7.5 * EXP ( -10.0 * ( 0.95 - znd )**2 ) * ( 1.0 - znd ) ) * zsc_ws_1(ji,jj)
+               END DO
+            ENDIF
+          ENDDO    ! ji loop
+       END DO      ! jj loop
+
+
+       WHERE ( lconv )
+          zsc_uw_1 = zustar**2
+          zsc_vw_1 = ff_t * zustke * zhml
+       ELSEWHERE
+          zsc_uw_1 = zustar**2
+          zsc_uw_2 = (2.25 - 3.0 * ( 1.0 - EXP( -1.25 * 2.0 ) ) ) * ( 1.0 - EXP( -4.0 * 2.0 ) ) * zsc_uw_1
+          zsc_vw_1 = ff_t * zustke * zhbl
+          zsc_vw_2 = -0.11 * SIN( 3.14159 * ( 2.0 + 0.4 ) ) * EXP(-( 1.5 + 2.0 )**2 ) * zsc_vw_1
+       ENDWHERE
+
+       DO jj = 2, jpjm1
+          DO ji = 2, jpim1
+             IF ( lconv(ji,jj) ) THEN
+               DO jk = 2, imld(ji,jj)
+                  zznd_ml = gdepw_n(ji,jj,jk) / zhml(ji,jj)
+                  zznd_d = gdepw_n(ji,jj,jk) / dstokes(ji,jj)
+                  ghamu(ji,jj,jk) = ghamu(ji,jj,jk)&
+                       & + 0.3 * ( -2.0 + 2.5 * ( 1.0 + 0.1 * zznd_ml**4 ) - EXP ( -8.0 * zznd_ml ) ) * zsc_uw_1(ji,jj)
+                  !
+                  ghamv(ji,jj,jk) = ghamv(ji,jj,jk)&
+                       & + 0.3 * 0.1 * ( EXP( -zznd_d ) + EXP( -5.0 * ( 1.0 - zznd_ml ) ) ) * zsc_vw_1(ji,jj)
+               END DO
+             ELSE
+               DO jk = 2, ibld(ji,jj)
+                  znd = gdepw_n(ji,jj,jk) / zhbl(ji,jj)
+                  zznd_d = gdepw_n(ji,jj,jk) / dstokes(ji,jj)
+                  IF ( zznd_d <= 2.0 ) THEN
+                     ghamu(ji,jj,jk) = ghamu(ji,jj,jk) + 0.5 * 0.3 &
+                          &*  ( 2.25 - 3.0  * ( 1.0 - EXP( - 1.25 * zznd_d ) ) * ( 1.0 - EXP( -2.0 * zznd_d ) ) ) * zsc_uw_1(ji,jj)
+                     !
+                  ELSE
+                     ghamu(ji,jj,jk) = ghamu(ji,jj,jk)&
+                          & + 0.5 * 0.3 * ( 1.0 - EXP( -5.0 * ( 1.0 - znd ) ) ) * zsc_uw_2(ji,jj)
+                     !
+                  ENDIF
+
+                  ghamv(ji,jj,jk) = ghamv(ji,jj,jk)&
+                       & + 0.3 * 0.15 * SIN( 3.14159 * ( 0.65 * zznd_d ) ) * EXP( -0.25 * zznd_d**2 ) * zsc_vw_1(ji,jj)
+                  ghamv(ji,jj,jk) = ghamv(ji,jj,jk)&
+                       & + 0.3 * 0.15 * EXP( -5.0 * ( 1.0 - znd ) ) * ( 1.0 - EXP( -20.0 * ( 1.0 - znd ) ) ) * zsc_vw_2(ji,jj)
+               END DO
+             ENDIF
+          END DO
+       END DO
+!
+! Make surface forced velocity non-gradient terms go to zero at the base of the mixed layer.
+
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            IF ( lconv(ji,jj) ) THEN
+               DO jk = 2, ibld(ji,jj)
+                  znd = ( gdepw_n(ji,jj,jk) - zhml(ji,jj) ) / zhml(ji,jj) !ALMG to think about
+                  IF ( znd >= 0.0 ) THEN
+                     ghamu(ji,jj,jk) = ghamu(ji,jj,jk) * ( 1.0 - EXP( -30.0 * znd**2 ) )
+                     ghamv(ji,jj,jk) = ghamv(ji,jj,jk) * ( 1.0 - EXP( -30.0 * znd**2 ) )
+                  ELSE
+                     ghamu(ji,jj,jk) = 0._wp
+                     ghamv(ji,jj,jk) = 0._wp
+                  ENDIF
+               END DO
+            ELSE
+               DO jk = 2, ibld(ji,jj)
+                  znd = ( gdepw_n(ji,jj,jk) - zhml(ji,jj) ) / zhml(ji,jj) !ALMG to think about
+                  IF ( znd >= 0.0 ) THEN
+                     ghamu(ji,jj,jk) = ghamu(ji,jj,jk) * ( 1.0 - EXP( -10.0 * znd**2 ) )
+                     ghamv(ji,jj,jk) = ghamv(ji,jj,jk) * ( 1.0 - EXP( -10.0 * znd**2 ) )
+                  ELSE
+                     ghamu(ji,jj,jk) = 0._wp
+                     ghamv(ji,jj,jk) = 0._wp
+                  ENDIF
+               END DO
+            ENDIF
+         END DO
+      END DO
+
+      ! pynocline contributions
+       ! Temporary fix to avoid instabilities when zdb_bl becomes very very small
+       zsc_uw_1 = 0._wp ! 50.0 * zla**(8.0/3.0) * zustar**2 * zhbl / ( zdb_bl + epsln )
+       DO jj = 2, jpjm1
+          DO ji = 2, jpim1
+             DO jk= 2, ibld(ji,jj)
+                znd = gdepw_n(ji,jj,jk) / zhbl(ji,jj)
+                ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + zdiffut(ji,jj,jk) * zdtdz_pyc(ji,jj,jk)
+                ghams(ji,jj,jk) = ghams(ji,jj,jk) + zdiffut(ji,jj,jk) * zdsdz_pyc(ji,jj,jk)
+                ghamu(ji,jj,jk) = ghamu(ji,jj,jk) + zviscos(ji,jj,jk) * zdudz_pyc(ji,jj,jk)
+                ghamu(ji,jj,jk) = ghamu(ji,jj,jk) + zsc_uw_1(ji,jj) * ( 1.0 - znd )**(7.0/4.0) * zdbdz_pyc(ji,jj,jk)
+                ghamv(ji,jj,jk) = ghamv(ji,jj,jk) + zviscos(ji,jj,jk) * zdvdz_pyc(ji,jj,jk)
+             END DO
+           END DO
+       END DO
+
+! Entrainment contribution.
+
+       DO jj=2, jpjm1
+          DO ji = 2, jpim1
+             IF ( lconv(ji,jj) ) THEN
+               DO jk = 1, imld(ji,jj) - 1
+                  znd=gdepw_n(ji,jj,jk) / zhml(ji,jj)
+                  ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + zwth_ent(ji,jj) * znd
+                  ghams(ji,jj,jk) = ghams(ji,jj,jk) + zws_ent(ji,jj) * znd
+                  ghamu(ji,jj,jk) = ghamu(ji,jj,jk) + zuw_bse(ji,jj) * znd
+                  ghamv(ji,jj,jk) = ghamv(ji,jj,jk) + zvw_bse(ji,jj) * znd
+               END DO
+               DO jk = imld(ji,jj), ibld(ji,jj)
+                  znd = -( gdepw_n(ji,jj,jk) - zhml(ji,jj) ) / zdh(ji,jj)
+                  ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + zwth_ent(ji,jj) * ( 1.0 + znd )
+                  ghams(ji,jj,jk) = ghams(ji,jj,jk) + zws_ent(ji,jj) * ( 1.0 + znd )
+                  ghamu(ji,jj,jk) = ghamu(ji,jj,jk) + zuw_bse(ji,jj) * ( 1.0 + znd )
+                  ghamv(ji,jj,jk) = ghamv(ji,jj,jk) + zvw_bse(ji,jj) * ( 1.0 + znd )
+                END DO
+             ENDIF
+             ghamt(ji,jj,ibld(ji,jj)) = 0._wp
+             ghams(ji,jj,ibld(ji,jj)) = 0._wp
+             ghamu(ji,jj,ibld(ji,jj)) = 0._wp
+             ghamv(ji,jj,ibld(ji,jj)) = 0._wp
+          END DO       ! ji loop
+       END DO          ! jj loop
+
+
+       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+       ! Need to put in code for contributions that are applied explicitly to
+       ! the prognostic variables
+       !  1. Entrainment flux
+       !
+       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+
+
+       ! rotate non-gradient velocity terms back to model reference frame
+
+       DO jj = 2, jpjm1
+          DO ji = 2, jpim1
+             DO jk = 2, ibld(ji,jj)
+                ztemp = ghamu(ji,jj,jk)
+                ghamu(ji,jj,jk) = ghamu(ji,jj,jk) * zcos_wind(ji,jj) - ghamv(ji,jj,jk) * zsin_wind(ji,jj)
+                ghamv(ji,jj,jk) = ghamv(ji,jj,jk) * zcos_wind(ji,jj) + ztemp * zsin_wind(ji,jj)
+             END DO
+          END DO
+       END DO
+
+       IF(ln_dia_osm) THEN
+          IF ( iom_use("zdtdz_pyc") ) CALL iom_put( "zdtdz_pyc", wmask*zdtdz_pyc )
+       END IF
+
+! KPP-style Ri# mixing
+       IF( ln_kpprimix) THEN
+          DO jk = 2, jpkm1           !* Shear production at uw- and vw-points (energy conserving form)
+             DO jj = 1, jpjm1
+                DO ji = 1, jpim1   ! vector opt.
+                   z3du(ji,jj,jk) = 0.5 * (  un(ji,jj,jk-1) -  un(ji  ,jj,jk) )   &
+                        &                 * (  ub(ji,jj,jk-1) -  ub(ji  ,jj,jk) ) * wumask(ji,jj,jk) &
+                        &                 / (  e3uw_n(ji,jj,jk) * e3uw_b(ji,jj,jk) )
+                   z3dv(ji,jj,jk) = 0.5 * (  vn(ji,jj,jk-1) -  vn(ji,jj  ,jk) )   &
+                        &                 * (  vb(ji,jj,jk-1) -  vb(ji,jj  ,jk) ) * wvmask(ji,jj,jk) &
+                        &                 / (  e3vw_n(ji,jj,jk) * e3vw_b(ji,jj,jk) )
+                END DO
+             END DO
+          END DO
+      !
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1   ! vector opt.
+                  !                                          ! shear prod. at w-point weightened by mask
+                  zesh2  =  ( z3du(ji-1,jj,jk) + z3du(ji,jj,jk) ) / MAX( 1._wp , umask(ji-1,jj,jk) + umask(ji,jj,jk) )   &
+                     &    + ( z3dv(ji,jj-1,jk) + z3dv(ji,jj,jk) ) / MAX( 1._wp , vmask(ji,jj-1,jk) + vmask(ji,jj,jk) )
+                  !                                          ! local Richardson number
+                  zri   = MAX( rn2b(ji,jj,jk), 0._wp ) / MAX(zesh2, epsln)
+                  zfri =  MIN( zri / rn_riinfty , 1.0_wp )
+                  zfri  = ( 1.0_wp - zfri * zfri )
+                  zrimix(ji,jj,jk)  =  zfri * zfri  * zfri * wmask(ji, jj, jk)
+                END DO
+             END DO
+          END DO
+
+          DO jj = 2, jpjm1
+             DO ji = 2, jpim1
+                DO jk = ibld(ji,jj) + 1, jpkm1
+                   zdiffut(ji,jj,jk) = zrimix(ji,jj,jk)*rn_difri
+                   zviscos(ji,jj,jk) = zrimix(ji,jj,jk)*rn_difri
+                END DO
+             END DO
+          END DO
+
+       END IF ! ln_kpprimix = .true.
+
+! KPP-style set diffusivity large if unstable below BL
+       IF( ln_convmix) THEN
+          DO jj = 2, jpjm1
+             DO ji = 2, jpim1
+                DO jk = ibld(ji,jj) + 1, jpkm1
+                  IF(  MIN( rn2(ji,jj,jk), rn2b(ji,jj,jk) ) <= -1.e-12 ) zdiffut(ji,jj,jk) = rn_difconv
+                END DO
+             END DO
+          END DO
+       END IF ! ln_convmix = .true.
+
+       ! Lateral boundary conditions on zvicos (sign unchanged), needed to caclulate viscosities on u and v grids
+       CALL lbc_lnk( zviscos(:,:,:), 'W', 1. )
+
+       ! GN 25/8: need to change tmask --> wmask
+
+     DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+             DO ji = 2, jpim1
+                p_avt(ji,jj,jk) = MAX( zdiffut(ji,jj,jk), avtb(jk) ) * tmask(ji,jj,jk)
+                p_avm(ji,jj,jk) = MAX( zviscos(ji,jj,jk), avmb(jk) ) * tmask(ji,jj,jk)
+             END DO
+         END DO
+     END DO
+
+
+     CALL lbc_lnk( p_avt, 'W', 1. )                      ! Lateral boundary conditions on p_avt  (sign unchanged)
+     CALL lbc_lnk( p_avm, 'W', 1. )                      ! Lateral boundary conditions on p_avm  (sign unchanged)
+
+      ! Lateral boundary conditions on ghamu and ghamv, currently on W-grid  (sign unchanged), needed to caclulate gham[uv] on u and v grids
+      CALL lbc_lnk( ghamu(:,:,:), 'W', 1. )
+      CALL lbc_lnk( ghamv(:,:,:), 'W', 1. )
+       DO jk = 2, jpkm1
+           DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  ghamu(ji,jj,jk) = ( ghamu(ji,jj,jk) + ghamu(ji+1,jj,jk) ) &
+                     &  / MAX( 1., tmask(ji,jj,jk) + tmask (ji + 1,jj,jk) ) * umask(ji,jj,jk)
+
+                  ghamv(ji,jj,jk) = ( ghamv(ji,jj,jk) + ghamv(ji,jj+1,jk) ) &
+                      &  / MAX( 1., tmask(ji,jj,jk) + tmask (ji,jj+1,jk) ) * vmask(ji,jj,jk)
+
+                  ghamt(ji,jj,jk) =  ghamt(ji,jj,jk) * tmask(ji,jj,jk)
+                  ghams(ji,jj,jk) =  ghams(ji,jj,jk) * tmask(ji,jj,jk)
+               END DO
+           END DO
+        END DO
+        ! Lateral boundary conditions on final outputs for gham[ts],  on W-grid  (sign unchanged)
+       CALL lbc_lnk( ghamt(:,:,:), 'W', 1. )
+       CALL lbc_lnk( ghams(:,:,:), 'W', 1. )
+      ! Lateral boundary conditions on final outputs for gham[uv],  on [UV]-grid  (sign unchanged)
+       CALL lbc_lnk( ghamu(:,:,:), 'U', 1. )
+       CALL lbc_lnk( ghamv(:,:,:), 'V', 1. )
+
+       IF(ln_dia_osm) THEN
+         SELECT CASE (nn_osm_wave)
+         ! Stokes drift set by assumimg onstant La#=0.3(=0)  or Pierson-Moskovitz spectrum (=1).
+         CASE(0:1)
+            IF ( iom_use("us_x") ) CALL iom_put( "us_x", tmask(:,:,1)*zustke*zcos_wind )   ! x surface Stokes drift
+            IF ( iom_use("us_y") ) CALL iom_put( "us_y", tmask(:,:,1)*zustke*zsin_wind )  ! y surface Stokes drift
+            IF ( iom_use("wind_wave_abs_power") ) CALL iom_put( "wind_wave_abs_power", 1000.*rau0*tmask(:,:,1)*zustar**2*zustke )
+         ! Stokes drift read in from sbcwave  (=2).
+         CASE(2)
+            IF ( iom_use("us_x") ) CALL iom_put( "us_x", ut0sd )               ! x surface Stokes drift
+            IF ( iom_use("us_y") ) CALL iom_put( "us_y", vt0sd )               ! y surface Stokes drift
+            IF ( iom_use("wind_wave_abs_power") ) CALL iom_put( "wind_wave_abs_power", 1000.*rau0*tmask(:,:,1)*zustar**2* &
+                 & SQRT(ut0sd**2 + vt0sd**2 ) )
+         END SELECT
+         IF ( iom_use("ghamt") ) CALL iom_put( "ghamt", tmask*ghamt )            ! <Tw_NL>
+         IF ( iom_use("ghams") ) CALL iom_put( "ghams", tmask*ghams )            ! <Sw_NL>
+         IF ( iom_use("ghamu") ) CALL iom_put( "ghamu", umask*ghamu )            ! <uw_NL>
+         IF ( iom_use("ghamv") ) CALL iom_put( "ghamv", vmask*ghamv )            ! <vw_NL>
+         IF ( iom_use("zwth0") ) CALL iom_put( "zwth0", tmask(:,:,1)*zwth0 )            ! <Tw_0>
+         IF ( iom_use("zws0") ) CALL iom_put( "zws0", tmask(:,:,1)*zws0 )                ! <Sw_0>
+         IF ( iom_use("hbl") ) CALL iom_put( "hbl", tmask(:,:,1)*hbl )                  ! boundary-layer depth
+         IF ( iom_use("hbli") ) CALL iom_put( "hbli", tmask(:,:,1)*hbli )               ! Initial boundary-layer depth
+         IF ( iom_use("dstokes") ) CALL iom_put( "dstokes", tmask(:,:,1)*dstokes )      ! Stokes drift penetration depth
+         IF ( iom_use("zustke") ) CALL iom_put( "zustke", tmask(:,:,1)*zustke )            ! Stokes drift magnitude at T-points
+         IF ( iom_use("zwstrc") ) CALL iom_put( "zwstrc", tmask(:,:,1)*zwstrc )         ! convective velocity scale
+         IF ( iom_use("zwstrl") ) CALL iom_put( "zwstrl", tmask(:,:,1)*zwstrl )         ! Langmuir velocity scale
+         IF ( iom_use("zustar") ) CALL iom_put( "zustar", tmask(:,:,1)*zustar )         ! friction velocity scale
+         IF ( iom_use("wind_power") ) CALL iom_put( "wind_power", 1000.*rau0*tmask(:,:,1)*zustar**3 ) ! BL depth internal to zdf_osm routine
+         IF ( iom_use("wind_wave_power") ) CALL iom_put( "wind_wave_power", 1000.*rau0*tmask(:,:,1)*zustar**2*zustke )
+         IF ( iom_use("zhbl") ) CALL iom_put( "zhbl", tmask(:,:,1)*zhbl )               ! BL depth internal to zdf_osm routine
+         IF ( iom_use("zhml") ) CALL iom_put( "zhml", tmask(:,:,1)*zhml )               ! ML depth internal to zdf_osm routine
+         IF ( iom_use("zdh") ) CALL iom_put( "zdh", tmask(:,:,1)*zdh )               ! ML depth internal to zdf_osm routine
+         IF ( iom_use("zhol") ) CALL iom_put( "zhol", tmask(:,:,1)*zhol )               ! ML depth internal to zdf_osm routine
+         IF ( iom_use("zwthav") ) CALL iom_put( "zwthav", tmask(:,:,1)*zwthav )               ! ML depth internal to zdf_osm routine
+         IF ( iom_use("zwth_ent") ) CALL iom_put( "zwth_ent", tmask(:,:,1)*zwth_ent )               ! ML depth internal to zdf_osm routine
+         IF ( iom_use("zt_ml") ) CALL iom_put( "zt_ml", tmask(:,:,1)*zt_ml )               ! average T in ML
+      END IF
+      ! Lateral boundary conditions on p_avt  (sign unchanged)
+      CALL lbc_lnk( p_avt(:,:,:), 'W', 1. )
+      !
+      IF( ln_timing )  CALL timing_stop('zdf_osm')
+      !
+   END SUBROUTINE zdf_osm
+
+
+   SUBROUTINE zdf_osm_init
+     !!----------------------------------------------------------------------
+     !!                  ***  ROUTINE zdf_osm_init  ***
+     !!
+     !! ** Purpose :   Initialization of the vertical eddy diffivity and
+     !!      viscosity when using a osm turbulent closure scheme
+     !!
+     !! ** Method  :   Read the namosm namelist and check the parameters
+     !!      called at the first timestep (nit000)
+     !!
+     !! ** input   :   Namlist namosm
+     !!----------------------------------------------------------------------
+     INTEGER  ::   ios            ! local integer
+     INTEGER  ::   ji, jj, jk     ! dummy loop indices
+     !!
+     NAMELIST/namzdf_osm/ ln_use_osm_la, rn_osm_la, rn_osm_dstokes, nn_ave &
+          & ,nn_osm_wave, ln_dia_osm, rn_osm_hbl0 &
+          & ,ln_kpprimix, rn_riinfty, rn_difri, ln_convmix, rn_difconv
+     !!----------------------------------------------------------------------
+     !
+     IF( ln_timing )  CALL timing_start('zdf_osm_init')
+     !
+     REWIND( numnam_ref )              ! Namelist namzdf_osm in reference namelist : Osmosis ML model
+     READ  ( numnam_ref, namzdf_osm, IOSTAT = ios, ERR = 901)
+901    IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_osm in reference namelist', lwp )
+
+     REWIND( numnam_cfg )              ! Namelist namzdf_tke in configuration namelist : Turbulent Kinetic Energy
+     READ  ( numnam_cfg, namzdf_osm, IOSTAT = ios, ERR = 902 )
+902    IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_osm in configuration namelist', lwp )
+     IF(lwm) WRITE ( numond, namzdf_osm )
+
+     IF(lwp) THEN                    ! Control print
+        WRITE(numout,*)
+        WRITE(numout,*) 'zdf_osm_init : OSMOSIS Parameterisation'
+        WRITE(numout,*) '~~~~~~~~~~~~'
+        WRITE(numout,*) '   Namelist namzdf_osm : set tke mixing parameters'
+        WRITE(numout,*) '     Use namelist  rn_osm_la                     ln_use_osm_la = ', ln_use_osm_la
+        WRITE(numout,*) '     Turbulent Langmuir number                     rn_osm_la   = ', rn_osm_la
+        WRITE(numout,*) '     Initial hbl for 1D runs                       rn_osm_hbl0   = ', rn_osm_hbl0
+        WRITE(numout,*) '     Depth scale of Stokes drift                rn_osm_dstokes = ', rn_osm_dstokes
+        WRITE(numout,*) '     horizontal average flag                       nn_ave      = ', nn_ave
+        WRITE(numout,*) '     Stokes drift                                  nn_osm_wave = ', nn_osm_wave
+        SELECT CASE (nn_osm_wave)
+        CASE(0)
+           WRITE(numout,*) '     calculated assuming constant La#=0.3'
+        CASE(1)
+           WRITE(numout,*) '     calculated from Pierson Moskowitz wind-waves'
+        CASE(2)
+           WRITE(numout,*) '     calculated from ECMWF wave fields'
+        END SELECT
+        WRITE(numout,*) '     Output osm diagnostics                       ln_dia_osm  = ',  ln_dia_osm
+        WRITE(numout,*) '     Use KPP-style shear instability mixing       ln_kpprimix = ', ln_kpprimix
+        WRITE(numout,*) '     local Richardson Number limit for shear instability rn_riinfty = ', rn_riinfty
+        WRITE(numout,*) '     maximum shear diffusivity at Rig = 0    (m2/s) rn_difri = ', rn_difri
+        WRITE(numout,*) '     Use large mixing below BL when unstable       ln_convmix = ', ln_convmix
+        WRITE(numout,*) '     diffusivity when unstable below BL     (m2/s) rn_difconv = ', rn_difconv
+     ENDIF
+
+     !                              ! allocate zdfosm arrays
+     IF( zdf_osm_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_osm_init : unable to allocate arrays' )
+
+     call osm_rst( nit000, 'READ' ) !* read or initialize hbl
+
+     IF( ln_zdfddm) THEN
+        IF(lwp) THEN
+           WRITE(numout,*)
+           WRITE(numout,*) '    Double diffusion mixing on temperature and salinity '
+           WRITE(numout,*) '    CAUTION : done in routine zdfosm, not in routine zdfddm '
+        ENDIF
+     ENDIF
+
+
+     !set constants not in namelist
+     !-----------------------------
+
+     IF(lwp) THEN
+        WRITE(numout,*)
+     ENDIF
+
+     IF (nn_osm_wave == 0) THEN
+        dstokes(:,:) = rn_osm_dstokes
+     END IF
+
+     ! Horizontal average : initialization of weighting arrays
+     ! -------------------
+
+     SELECT CASE ( nn_ave )
+
+     CASE ( 0 )                ! no horizontal average
+        IF(lwp) WRITE(numout,*) '          no horizontal average on avt'
+        IF(lwp) WRITE(numout,*) '          only in very high horizontal resolution !'
+        ! weighting mean arrays etmean
+        !           ( 1  1 )
+        ! avt = 1/4 ( 1  1 )
+        !
+        etmean(:,:,:) = 0.e0
+
+        DO jk = 1, jpkm1
+           DO jj = 2, jpjm1
+              DO ji = 2, jpim1   ! vector opt.
+                 etmean(ji,jj,jk) = tmask(ji,jj,jk)                     &
+                      &  / MAX( 1.,  umask(ji-1,jj  ,jk) + umask(ji,jj,jk)   &
+                      &            + vmask(ji  ,jj-1,jk) + vmask(ji,jj,jk)  )
+              END DO
+           END DO
+        END DO
+
+     CASE ( 1 )                ! horizontal average
+        IF(lwp) WRITE(numout,*) '          horizontal average on avt'
+        ! weighting mean arrays etmean
+        !           ( 1/2  1  1/2 )
+        ! avt = 1/8 ( 1    2  1   )
+        !           ( 1/2  1  1/2 )
+        etmean(:,:,:) = 0.e0
+
+        DO jk = 1, jpkm1
+           DO jj = 2, jpjm1
+              DO ji = 2, jpim1   ! vector opt.
+                 etmean(ji,jj,jk) = tmask(ji, jj,jk)                           &
+                      & / MAX( 1., 2.* tmask(ji,jj,jk)                           &
+                      &      +.5 * ( tmask(ji-1,jj+1,jk) + tmask(ji-1,jj-1,jk)   &
+                      &             +tmask(ji+1,jj+1,jk) + tmask(ji+1,jj-1,jk) ) &
+                      &      +1. * ( tmask(ji-1,jj  ,jk) + tmask(ji  ,jj+1,jk)   &
+                      &             +tmask(ji  ,jj-1,jk) + tmask(ji+1,jj  ,jk) ) )
+              END DO
+           END DO
+        END DO
+
+     CASE DEFAULT
+        WRITE(ctmp1,*) '          bad flag value for nn_ave = ', nn_ave
+        CALL ctl_stop( ctmp1 )
+
+     END SELECT
+
+     ! Initialization of vertical eddy coef. to the background value
+     ! -------------------------------------------------------------
+     DO jk = 1, jpk
+        avt (:,:,jk) = avtb(jk) * tmask(:,:,jk)
+     END DO
+
+     ! zero the surface flux for non local term and osm mixed layer depth
+     ! ------------------------------------------------------------------
+     ghamt(:,:,:) = 0.
+     ghams(:,:,:) = 0.
+     ghamu(:,:,:) = 0.
+     ghamv(:,:,:) = 0.
+
+     !
+     IF( ln_timing )  CALL timing_stop('zdf_osm_init')
+     !
+   END SUBROUTINE zdf_osm_init
+
+
+   SUBROUTINE osm_rst( kt, cdrw )
+     !!---------------------------------------------------------------------
+     !!                   ***  ROUTINE osm_rst  ***
+     !!
+     !! ** Purpose :   Read or write BL fields in restart file
+     !!
+     !! ** Method  :   use of IOM library. If the restart does not contain
+     !!                required fields, they are recomputed from stratification
+     !!----------------------------------------------------------------------
+
+     INTEGER, INTENT(in) :: kt
+     CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
+
+     INTEGER ::   id1, id2   ! iom enquiry index
+     INTEGER  ::   ji, jj, jk     ! dummy loop indices
+     INTEGER  ::   iiki, ikt ! local integer
+     REAL(wp) ::   zhbf           ! tempory scalars
+     REAL(wp) ::   zN2_c           ! local scalar
+     REAL(wp) ::   rho_c = 0.01_wp    !: density criterion for mixed layer depth
+     INTEGER, DIMENSION(:,:), ALLOCATABLE :: imld_rst ! level of mixed-layer depth (pycnocline top)
+     !!----------------------------------------------------------------------
+     !
+     !!-----------------------------------------------------------------------------
+     ! If READ/WRITE Flag is 'READ', try to get hbl from restart file. If successful then return
+     !!-----------------------------------------------------------------------------
+     IF( TRIM(cdrw) == 'READ'.AND. ln_rstart) THEN
+        id1 = iom_varid( numror, 'wn'   , ldstop = .FALSE. )
+        IF( id1 > 0 ) THEN                       ! 'wn' exists; read
+           CALL iom_get( numror, jpdom_autoglo, 'wn', wn )
+           WRITE(numout,*) ' ===>>>> :  wn read from restart file'
+        ELSE
+           wn(:,:,:) = 0._wp
+           WRITE(numout,*) ' ===>>>> :  wn not in restart file, set to zero initially'
+        END IF
+        id1 = iom_varid( numror, 'hbl'   , ldstop = .FALSE. )
+        id2 = iom_varid( numror, 'hbli'   , ldstop = .FALSE. )
+        IF( id1 > 0 .AND. id2 > 0) THEN                       ! 'hbl' exists; read and return
+           CALL iom_get( numror, jpdom_autoglo, 'hbl', hbl )
+           CALL iom_get( numror, jpdom_autoglo, 'hbli', hbli )
+           WRITE(numout,*) ' ===>>>> :  hbl & hbli read from restart file'
+           RETURN
+        ELSE                      ! 'hbl' & 'hbli' not in restart file, recalculate
+           WRITE(numout,*) ' ===>>>> : previous run without osmosis scheme, hbl computed from stratification'
+        END IF
+     END IF
+
+     !!-----------------------------------------------------------------------------
+     ! If READ/WRITE Flag is 'WRITE', write hbl into the restart file, then return
+     !!-----------------------------------------------------------------------------
+     IF( TRIM(cdrw) == 'WRITE') THEN     !* Write hbli into the restart file, then return
+        IF(lwp) WRITE(numout,*) '---- osm-rst ----'
+         CALL iom_rstput( kt, nitrst, numrow, 'wn'   , wn     )
+         CALL iom_rstput( kt, nitrst, numrow, 'hbl'   , hbl     )
+         CALL iom_rstput( kt, nitrst, numrow, 'hbli'   , hbli     )
+        RETURN
+     END IF
+
+     !!-----------------------------------------------------------------------------
+     ! Getting hbl, no restart file with hbl, so calculate from surface stratification
+     !!-----------------------------------------------------------------------------
+     IF( lwp ) WRITE(numout,*) ' ===>>>> : calculating hbl computed from stratification'
+     ALLOCATE( imld_rst(jpi,jpj) )
+     ! w-level of the mixing and mixed layers
+     CALL eos_rab( tsn, rab_n )
+     CALL bn2(tsn, rab_n, rn2)
+     imld_rst(:,:)  = nlb10         ! Initialization to the number of w ocean point
+     hbl(:,:)  = 0._wp              ! here hbl used as a dummy variable, integrating vertically N^2
+     zN2_c = grav * rho_c * r1_rau0 ! convert density criteria into N^2 criteria
+     !
+     hbl(:,:)  = 0._wp              ! here hbl used as a dummy variable, integrating vertically N^2
+     DO jk = 1, jpkm1
+        DO jj = 1, jpj              ! Mixed layer level: w-level
+           DO ji = 1, jpi
+              ikt = mbkt(ji,jj)
+              hbl(ji,jj) = hbl(ji,jj) + MAX( rn2(ji,jj,jk) , 0._wp ) * e3w_n(ji,jj,jk)
+              IF( hbl(ji,jj) < zN2_c )   imld_rst(ji,jj) = MIN( jk , ikt ) + 1   ! Mixed layer level
+           END DO
+        END DO
+     END DO
+     !
+     DO jj = 1, jpj
+        DO ji = 1, jpi
+           iiki = imld_rst(ji,jj)
+           hbl (ji,jj) = gdepw_n(ji,jj,iiki  ) * ssmask(ji,jj)    ! Turbocline depth
+        END DO
+     END DO
+     hbl = MAX(hbl,epsln)
+     hbli(:,:) = hbl(:,:)
+     DEALLOCATE( imld_rst )
+     WRITE(numout,*) ' ===>>>> : hbl computed from stratification'
+   END SUBROUTINE osm_rst
+
+
+   SUBROUTINE tra_osm( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_osm  ***
+      !!
+      !! ** Purpose :   compute and add to the tracer trend the non-local tracer flux
+      !!
+      !! ** Method  :   ???
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ztrdt, ztrds   ! 3D workspace
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) :: kt
+      INTEGER :: ji, jj, jk
+      !
+      IF( ln_timing )  CALL timing_start('tra_osm')
+      !
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_osm : OSM non-local tracer fluxes'
+         IF(lwp) WRITE(numout,*) '~~~~~~~   '
+      ENDIF
+
+      IF( l_trdtra )   THEN                    !* Save ta and sa trends
+         ALLOCATE( ztrdt(jpi,jpj,jpk) )   ;    ztrdt(:,:,:) = tsa(:,:,:,jp_tem)
+         ALLOCATE( ztrds(jpi,jpj,jpk) )   ;    ztrds(:,:,:) = tsa(:,:,:,jp_sal)
+      ENDIF
+
+      ! add non-local temperature and salinity flux
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               tsa(ji,jj,jk,jp_tem) =  tsa(ji,jj,jk,jp_tem)                      &
+                  &                 - (  ghamt(ji,jj,jk  )  &
+                  &                    - ghamt(ji,jj,jk+1) ) /e3t_n(ji,jj,jk)
+               tsa(ji,jj,jk,jp_sal) =  tsa(ji,jj,jk,jp_sal)                      &
+                  &                 - (  ghams(ji,jj,jk  )  &
+                  &                    - ghams(ji,jj,jk+1) ) / e3t_n(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+
+      ! save the non-local tracer flux trends for diagnostic
+      IF( l_trdtra )   THEN
+         ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
+         ztrds(:,:,:) = tsa(:,:,:,jp_sal) - ztrds(:,:,:)
+!!bug gm jpttdzdf ==> jpttosm
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_zdf, ztrdt )
+         CALL trd_tra( kt, 'TRA', jp_sal, jptra_zdf, ztrds )
+         DEALLOCATE( ztrdt )      ;     DEALLOCATE( ztrds )
+      ENDIF
+
+      IF(ln_ctl) THEN
+         CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' osm  - Ta: ', mask1=tmask,   &
+         &             tab3d_2=tsa(:,:,:,jp_sal), clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+      ENDIF
+      !
+      IF( ln_timing )  CALL timing_stop('tra_osm')
+      !
+   END SUBROUTINE tra_osm
+
+
+   SUBROUTINE trc_osm( kt )          ! Dummy routine
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_osm  ***
+      !!
+      !! ** Purpose :   compute and add to the passive tracer trend the non-local
+      !!                 passive tracer flux
+      !!
+      !!
+      !! ** Method  :   ???
+      !!----------------------------------------------------------------------
+      !
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) :: kt
+      WRITE(*,*) 'trc_osm: Not written yet', kt
+   END SUBROUTINE trc_osm
+
+
+   SUBROUTINE dyn_osm( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dyn_osm  ***
+      !!
+      !! ** Purpose :   compute and add to the velocity trend the non-local flux
+      !! copied/modified from tra_osm
+      !!
+      !! ** Method  :   ???
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   !
+      !
+      INTEGER :: ji, jj, jk   ! dummy loop indices
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )  CALL timing_start('dyn_osm')
+      !
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'dyn_osm : OSM non-local velocity'
+         IF(lwp) WRITE(numout,*) '~~~~~~~   '
+      ENDIF
+      !code saving tracer trends removed, replace with trdmxl_oce
+
+      DO jk = 1, jpkm1           ! add non-local u and v fluxes
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               ua(ji,jj,jk) =  ua(ji,jj,jk)                      &
+                  &                 - (  ghamu(ji,jj,jk  )  &
+                  &                    - ghamu(ji,jj,jk+1) ) / e3u_n(ji,jj,jk)
+               va(ji,jj,jk) =  va(ji,jj,jk)                      &
+                  &                 - (  ghamv(ji,jj,jk  )  &
+                  &                    - ghamv(ji,jj,jk+1) ) / e3v_n(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+
+      ! code for saving tracer trends removed
+      !
+      IF( ln_timing )  CALL timing_stop('dyn_osm')
+      !
+   END SUBROUTINE dyn_osm
+
+   !!======================================================================
+END MODULE zdfosm
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfphy.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfphy.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfphy.F90	(revision 9019)
@@ -0,0 +1,321 @@
+MODULE zdfphy
+   !!======================================================================
+   !!                      ***  MODULE  zdfphy  ***
+   !! Vertical ocean physics :   manager of all vertical physics packages
+   !!======================================================================
+   !! History :  4.0  !  2017-04  (G. Madec)  original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   zdf_phy_init  : initialization of all vertical physics packages
+   !!   zdf_phy       : upadate at each time-step the vertical mixing coeff. 
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers variables
+   USE zdf_oce        ! vertical physics: shared variables         
+   USE zdfdrg         ! vertical physics: top/bottom drag coef.
+   USE zdfsh2         ! vertical physics: shear production term of TKE
+   USE zdfric         ! vertical physics: RIChardson dependent vertical mixing   
+   USE zdftke         ! vertical physics: TKE vertical mixing
+   USE zdfgls         ! vertical physics: GLS vertical mixing
+   USE zdfosm         ! vertical physics: OSMOSIS vertical mixing
+   USE zdfddm         ! vertical physics: double diffusion mixing      
+   USE zdfevd         ! vertical physics: convection via enhanced vertical diffusion  
+   USE zdfiwm         ! vertical physics: internal wave-induced mixing  
+   USE zdfswm         ! vertical physics: surface  wave-induced mixing
+   USE zdfmxl         ! vertical physics: mixed layer
+   USE tranpc         ! convection: non penetrative adjustment
+   USE trc_oce        ! variables shared between passive tracer & ocean           
+   USE sbc_oce        ! surface module (only for nn_isf in the option compatibility test)
+   USE sbcrnf         ! surface boundary condition: runoff variables
+#if defined key_agrif
+   USE agrif_opa_interp   ! interpavm
+#endif
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! IOM library
+   USE lbclnk         ! lateral boundary conditions
+   USE lib_mpp        ! distribued memory computing
+   USE timing         ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   zdf_phy_init  ! called by nemogcm.F90
+   PUBLIC   zdf_phy       ! called by step.F90
+
+   INTEGER ::   nzdf_phy   ! type of vertical closure used 
+   !                       ! associated indicators
+   INTEGER, PARAMETER ::   np_CST = 1   ! Constant Kz
+   INTEGER, PARAMETER ::   np_RIC = 2   ! Richardson number dependent Kz
+   INTEGER, PARAMETER ::   np_TKE = 3   ! Turbulente Kinetic Eenergy closure scheme for Kz
+   INTEGER, PARAMETER ::   np_GLS = 4   ! Generic Length Scale closure scheme for Kz
+   INTEGER, PARAMETER ::   np_OSM = 5   ! OSMOSIS-OBL closure scheme for Kz
+
+   LOGICAL ::   l_zdfsh2   ! shear production term flag (=F for CST, =T otherwise (i.e. TKE, GLS, RIC))
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
+   !! $Id: zdfphy.F90 8160 2017-06-10 07:31:34Z gm $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE zdf_phy_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_phy_init  ***
+      !! 
+      !! ** Purpose :   initializations of the vertical ocean physics
+      !!
+      !! ** Method  :   Read namelist namzdf, control logicals 
+      !!                set horizontal shape and vertical profile of background mixing coef.
+      !!----------------------------------------------------------------------
+      INTEGER ::   jk            ! dummy loop indices
+      INTEGER ::   ioptio, ios   ! local integers
+      !!
+      NAMELIST/namzdf/ ln_zdfcst, ln_zdfric, ln_zdftke, ln_zdfgls,   &     ! type of closure scheme
+         &             ln_zdfosm,                                    &     ! type of closure scheme
+         &             ln_zdfevd, nn_evdm, rn_evd ,                  &     ! convection : evd
+         &             ln_zdfnpc, nn_npc , nn_npcp,                  &     ! convection : npc
+         &             ln_zdfddm, rn_avts, rn_hsbfr,                 &     ! double diffusion
+         &             ln_zdfswm,                                    &     ! surface  wave-induced mixing
+         &             ln_zdfiwm,                                    &     ! internal  -      -      -
+         &             rn_avm0, rn_avt0, nn_avb, nn_havtb                  ! coefficients
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('zdf_phy_init')
+      !
+      !                           !==  Namelist  ==!
+      REWIND( numnam_ref )              ! Namelist namzdf in reference namelist : Vertical mixing parameters
+      READ  ( numnam_ref, namzdf, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namzdf in reference namelist', lwp )
+      !
+      REWIND( numnam_cfg )              ! Namelist namzdf in reference namelist : Vertical mixing parameters
+      READ  ( numnam_cfg, namzdf, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namzdf in configuration namelist', lwp )
+      IF(lwm)   WRITE ( numond, namzdf )
+      !
+      IF(lwp) THEN                      ! Parameter print
+         WRITE(numout,*)
+         WRITE(numout,*) 'zdf_phy_init: vertical physics'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namzdf : set vertical mixing mixing parameters'
+         WRITE(numout,*) '      vertical closure scheme'
+         WRITE(numout,*) '         constant vertical mixing coefficient    ln_zdfcst = ', ln_zdfcst
+         WRITE(numout,*) '         Richardson number dependent closure     ln_zdfric = ', ln_zdfric
+         WRITE(numout,*) '         Turbulent Kinetic Energy closure (TKE)  ln_zdftke = ', ln_zdftke
+         WRITE(numout,*) '         Generic Length Scale closure (GLS)      ln_zdfgls = ', ln_zdfgls
+         WRITE(numout,*) '         OSMOSIS-OBL closure (OSM)               ln_zdfosm = ', ln_zdfosm
+         WRITE(numout,*) '      convection: '
+         WRITE(numout,*) '         enhanced vertical diffusion             ln_zdfevd = ', ln_zdfevd
+         WRITE(numout,*) '            applied on momentum (=1/0)             nn_evdm = ', nn_evdm
+         WRITE(numout,*) '            vertical coefficient for evd           rn_evd  = ', rn_evd
+         WRITE(numout,*) '         non-penetrative convection (npc)        ln_zdfnpc = ', ln_zdfnpc
+         WRITE(numout,*) '            npc call  frequency                    nn_npc  = ', nn_npc
+         WRITE(numout,*) '            npc print frequency                    nn_npcp = ', nn_npcp
+         WRITE(numout,*) '      double diffusive mixing                    ln_zdfddm = ', ln_zdfddm
+         WRITE(numout,*) '         maximum avs for dd mixing                 rn_avts = ', rn_avts
+         WRITE(numout,*) '         heat/salt buoyancy flux ratio             rn_hsbfr= ', rn_hsbfr
+         WRITE(numout,*) '      gravity wave-induced mixing'
+         WRITE(numout,*) '         surface  wave (Qiao et al 2010)         ln_zdfswm = ', ln_zdfswm                                          ! surface wave induced mixing
+         WRITE(numout,*) '         internal wave (de Lavergne et al 2017)  ln_zdfiwm = ', ln_zdfiwm
+         WRITE(numout,*) '      coefficients : '
+         WRITE(numout,*) '         vertical eddy viscosity                 rn_avm0   = ', rn_avm0
+         WRITE(numout,*) '         vertical eddy diffusivity               rn_avt0   = ', rn_avt0
+         WRITE(numout,*) '         constant background or profile          nn_avb    = ', nn_avb
+         WRITE(numout,*) '         horizontal variation for avtb           nn_havtb  = ', nn_havtb
+      ENDIF
+
+      !                          !==  Background eddy viscosity and diffusivity  ==!
+      IF( nn_avb == 0 ) THEN             ! Define avmb, avtb from namelist parameter
+         avmb(:) = rn_avm0
+         avtb(:) = rn_avt0                     
+      ELSE                               ! Background profile of avt (fit a theoretical/observational profile (Krauss 1990)
+         avmb(:) = rn_avm0
+         avtb(:) = rn_avt0 + ( 3.e-4_wp - 2._wp * rn_avt0 ) * 1.e-4_wp * gdepw_1d(:)   ! m2/s
+         IF(ln_sco .AND. lwp)   CALL ctl_warn( 'avtb profile not valid in sco' )
+      ENDIF
+      !                                  ! 2D shape of the avtb
+      avtb_2d(:,:) = 1._wp                   ! uniform 
+      !
+      IF( nn_havtb == 1 ) THEN               ! decrease avtb by a factor of ten in the equatorial band
+           !                                 !   -15S -5S : linear decrease from avt0 to avt0/10.
+           !                                 !   -5S  +5N : cst value avt0/10.
+           !                                 !    5N  15N : linear increase from avt0/10, to avt0
+           WHERE(-15. <= gphit .AND. gphit < -5 )   avtb_2d = (1.  - 0.09 * (gphit + 15.))
+           WHERE( -5. <= gphit .AND. gphit <  5 )   avtb_2d =  0.1
+           WHERE(  5. <= gphit .AND. gphit < 15 )   avtb_2d = (0.1 + 0.09 * (gphit -  5.))
+      ENDIF
+      !
+      DO jk = 1, jpk                      ! set turbulent closure Kz to the background value (avt_k, avm_k)
+         avt_k(:,:,jk) = avtb_2d(:,:) * avtb(jk) * wmask (:,:,jk)
+         avm_k(:,:,jk) =                avmb(jk) * wmask (:,:,jk)
+      END DO
+!!gm  to be tested only the 1st & last levels
+!      avt  (:,:, 1 ) = 0._wp   ;   avs(:,:, 1 ) = 0._wp   ;   avm  (:,:, 1 ) = 0._wp
+!      avt  (:,:,jpk) = 0._wp   ;   avs(:,:,jpk) = 0._wp   ;   avm  (:,:,jpk) = 0._wp
+!!gm
+      avt  (:,:,:) = 0._wp   ;   avs(:,:,:) = 0._wp   ;   avm  (:,:,:) = 0._wp
+
+      !                          !==  Convection  ==!
+      !
+      IF( ln_zdfnpc .AND. ln_zdfevd )   CALL ctl_stop( 'zdf_phy_init: chose between ln_zdfnpc and ln_zdfevd' )
+      IF( ln_zdfosm .AND. ln_zdfevd )   CALL ctl_stop( 'zdf_phy_init: chose between ln_zdfosm and ln_zdfevd' )
+      IF( lk_top    .AND. ln_zdfnpc )   CALL ctl_stop( 'zdf_phy_init: npc scheme is not working with key_top' )
+      IF( lk_top    .AND. ln_zdfosm )   CALL ctl_stop( 'zdf_phy_init: osmosis scheme is not working with key_top' )
+      IF(lwp) THEN
+         WRITE(numout,*)
+         IF    ( ln_zdfnpc ) THEN  ;   WRITE(numout,*) '      convection: use non penetrative convective scheme'
+         ELSEIF( ln_zdfevd ) THEN  ;   WRITE(numout,*) '      convection: use enhanced vertical diffusion scheme'
+         ELSE                      ;   WRITE(numout,*) '      convection: no specific scheme used'
+         ENDIF
+      ENDIF
+
+      IF(lwp) THEN               !==  Double Diffusion Mixing parameterization  ==!   (ddm)
+         WRITE(numout,*)
+         IF( ln_zdfddm ) THEN   ;   WRITE(numout,*) '      use double diffusive mixing: avs /= avt'
+         ELSE                   ;   WRITE(numout,*) '      No  double diffusive mixing: avs = avt'
+         ENDIF
+      ENDIF
+
+      !                          !==  type of vertical turbulent closure  ==!    (set nzdf_phy)
+      ioptio = 0 
+      IF( ln_zdfcst ) THEN   ;   ioptio = ioptio + 1   ;    nzdf_phy = np_CST   ;   ENDIF
+      IF( ln_zdfric ) THEN   ;   ioptio = ioptio + 1   ;    nzdf_phy = np_RIC   ;   CALL zdf_ric_init   ;   ENDIF
+      IF( ln_zdftke ) THEN   ;   ioptio = ioptio + 1   ;    nzdf_phy = np_TKE   ;   CALL zdf_tke_init   ;   ENDIF
+      IF( ln_zdfgls ) THEN   ;   ioptio = ioptio + 1   ;    nzdf_phy = np_GLS   ;   CALL zdf_gls_init   ;   ENDIF
+      IF( ln_zdfosm ) THEN   ;   ioptio = ioptio + 1   ;    nzdf_phy = np_OSM   ;   CALL zdf_osm_init   ;   ENDIF
+      !
+      IF( ioptio /= 1 )    CALL ctl_stop( 'zdf_phy_init: one and only one vertical diffusion option has to be defined ' )
+      IF( ln_isfcav ) THEN
+      IF( ln_zdfric .OR. ln_zdfgls )    CALL ctl_stop( 'zdf_phy_init: zdfric and zdfgls never tested with ice shelves cavities ' )
+      ENDIF
+      !                                ! shear production term flag
+      IF( ln_zdfcst ) THEN   ;   l_zdfsh2 = .FALSE.
+      ELSE                   ;   l_zdfsh2 = .TRUE.
+      ENDIF
+
+      !                          !== gravity wave-driven mixing  ==!
+      IF( ln_zdfiwm )   CALL zdf_iwm_init       ! internal wave-driven mixing
+      IF( ln_zdfswm )   CALL zdf_swm_init       ! surface  wave-driven mixing
+
+      !                          !== top/bottom friction  ==!
+      CALL zdf_drg_init
+      !
+      !                          !== time-stepping  ==!
+      ! Check/update of time stepping done in dynzdf_init/trazdf_init
+      !!gm move it here ?
+      !
+      IF( ln_timing )   CALL timing_stop('zdf_phy_init')
+      !
+   END SUBROUTINE zdf_phy_init
+
+
+   SUBROUTINE zdf_phy( kt )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE zdf_phy  ***
+      !!
+      !! ** Purpose :  Update ocean physics at each time-step
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  :   avm, avt vertical eddy viscosity and diffusivity at w-points
+      !!                nmld ??? mixed layer depth in level and meters   <<<<====verifier !
+      !!                bottom stress.....                               <<<<====verifier !
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      INTEGER ::   ji, jj, jk   ! dummy loop indice
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zsh2   ! shear production
+      !! ---------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('zdf_phy')
+      !
+      IF( l_zdfdrg ) THEN     !==  update top/bottom drag  ==!   (non-linear cases)
+         !
+         !                       !* bottom drag
+         CALL zdf_drg( kt, mbkt    , r_Cdmin_bot, r_Cdmax_bot,   &   ! <<== in 
+            &              r_z0_bot,   r_ke0_bot,    rCd0_bot,   &
+            &                                        rCdU_bot  )     ! ==>> out : bottom drag [m/s]
+         IF( ln_isfcav ) THEN    !* top drag   (ocean cavities)
+            CALL zdf_drg( kt, mikt    , r_Cdmin_top, r_Cdmax_top,   &   ! <<== in 
+               &              r_z0_top,   r_ke0_top,    rCd0_top,   &
+               &                                        rCdU_top  )     ! ==>> out : bottom drag [m/s]
+         ENDIF
+      ENDIF
+      !
+      !                       !==  Kz from chosen turbulent closure  ==!   (avm_k, avt_k)
+      !
+      IF( l_zdfsh2 )   &         !* shear production at w-points (energy conserving form)
+         CALL zdf_sh2( ub, vb, un, vn, avm_k,   &     ! <<== in
+            &                           zsh2    )     ! ==>> out : shear production
+      !
+      SELECT CASE ( nzdf_phy )                  !* Vertical eddy viscosity and diffusivity coefficients at w-points
+      CASE( np_RIC )   ;   CALL zdf_ric( kt, gdept_n, zsh2, avm_k, avt_k )    ! Richardson number dependent Kz
+      CASE( np_TKE )   ;   CALL zdf_tke( kt         , zsh2, avm_k, avt_k )    ! TKE closure scheme for Kz
+      CASE( np_GLS )   ;   CALL zdf_gls( kt         , zsh2, avm_k, avt_k )    ! GLS closure scheme for Kz
+      CASE( np_OSM )   ;   CALL zdf_osm( kt               , avm_k, avt_k )    ! OSMOSIS closure scheme for Kz
+!     CASE( np_CST )                                  ! Constant Kz (reset avt, avm to the background value)
+!         ! avt_k and avm_k set one for all at initialisation phase
+!!gm         avt(2:jpim1,2:jpjm1,1:jpkm1) = rn_avt0 * wmask(2:jpim1,2:jpjm1,1:jpkm1)
+!!gm         avm(2:jpim1,2:jpjm1,1:jpkm1) = rn_avm0 * wmask(2:jpim1,2:jpjm1,1:jpkm1)
+      END SELECT
+      !  
+      !                          !==  ocean Kz  ==!   (avt, avs, avm)
+      !
+      !                                         !* start from turbulent closure values
+      avt(:,:,2:jpkm1) = avt_k(:,:,2:jpkm1)
+      avm(:,:,2:jpkm1) = avm_k(:,:,2:jpkm1)
+      !
+      IF( ln_rnf_mouth ) THEN                   !* increase diffusivity at rivers mouths
+         DO jk = 2, nkrnf
+            avt(:,:,jk) = avt(:,:,jk) + 2._wp * rn_avt_rnf * rnfmsk(:,:) * wmask(:,:,jk)
+         END DO
+      ENDIF
+      !
+      IF( ln_zdfevd )   CALL zdf_evd( kt, avm, avt )  !* convection: enhanced vertical eddy diffusivity
+      !
+      !                                         !* double diffusive mixing
+      IF( ln_zdfddm ) THEN                            ! update avt and compute avs
+                        CALL zdf_ddm( kt, avm, avt, avs )
+      ELSE                                            ! same mixing on all tracers
+         avs(2:jpim1,2:jpjm1,1:jpkm1) = avt(2:jpim1,2:jpjm1,1:jpkm1)
+      ENDIF
+      !
+      !                                         !* wave-induced mixing 
+      IF( ln_zdfswm )   CALL zdf_swm( kt, avm, avt, avs )   ! surface  wave (Qiao et al. 2004) 
+      IF( ln_zdfiwm )   CALL zdf_iwm( kt, avm, avt, avs )   ! internal wave (de Lavergne et al 2017)
+
+#if defined key_agrif 
+      ! interpolation parent grid => child grid for avm_k ( ex : at west border: update column 1 and 2)
+      IF( l_zdfsh2 )   CALL Agrif_avm
+#endif
+
+      !                                         !* Lateral boundary conditions (sign unchanged)
+      IF( l_zdfsh2 ) THEN
+         CALL lbc_lnk( avm_k, 'W', 1. )               ! needed to compute the shear production term
+         CALL lbc_lnk( avt_k, 'W', 1. )               !!gm a priori useless ==>> to be tested
+      ENDIF
+      CALL lbc_lnk( avm  , 'W', 1. )                  ! needed to compute avm at u- and v-points
+      CALL lbc_lnk( avt  , 'W', 1. )                  !!gm  a priori only avm_k and avm are required
+      CALL lbc_lnk( avs  , 'W', 1. )                  !!gm  for calculation, kept here for output only
+      !
+      IF( l_zdfdrg ) THEN     ! drag  have been updated (non-linear cases)
+         IF( ln_isfcav )   CALL lbc_lnk( rCdU_top, 'T', 1. )   ! top    drag
+                           CALL lbc_lnk( rCdU_bot, 'T', 1. )   ! bottom drag
+      ENDIF
+      !
+      CALL zdf_mxl( kt )                        !* mixed layer depth, and level
+      !
+      IF( lrst_oce ) THEN                       !* write TKE, GLS or RIC fields in the restart file
+         IF( ln_zdftke )   CALL tke_rst( kt, 'WRITE' )
+         IF( ln_zdfgls )   CALL gls_rst( kt, 'WRITE' )
+         IF( ln_zdfric )   CALL ric_rst( kt, 'WRITE' ) 
+         ! NB. OSMOSIS restart (osm_rst) will be called in step.F90 after wn has been updated
+      ENDIF
+      !
+      IF( ln_timing )   CALL timing_stop('zdf_phy')
+      !
+   END SUBROUTINE zdf_phy
+
+   !!======================================================================
+END MODULE zdfphy
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfqiao.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfqiao.F90	(revision 9018)
+++ 	(revision )
@@ -1,128 +1,0 @@
-MODULE zdfqiao
-   !!======================================================================
-   !!                       ***  MODULE  zdfqiao  ***
-   !! Qiao module      : vertical mixing enhancement due to surface waves 
-   !!======================================================================
-   !! History :  3.6  !  2014-10  (E. Clementi)  Original code
-   !!----------------------------------------------------------------------
-   !!   zdf_qiao        : compute Qiao parameters
-   !!----------------------------------------------------------------------
-
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! distribued memory computing library
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE zdf_oce
-   USE sbcwave         ! wave module
-   USE dom_oce
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)  
-   
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC zdf_qiao    ! routine called in step
-
-   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:) :: qbv, qbvu, qbvv
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011) 
-   !! $Id: $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-
-CONTAINS
-
-   SUBROUTINE zdf_qiao( kt )
-      !!---------------------------------------------------------------------
-      !!                     ***  ROUTINE zdf_qiao ***
-      !!
-      !! ** Purpose :Compute the Qiao term (qbv) to be added to
-      !!             vertical viscosity and diffusivity coeffs.  
-      !!
-      !! ** Method  :qbv = alpha * A * Us(0) * exp (3 * k * z)
-      !!             
-      !! ** action  :Compute the Qiao wave dependent term 
-      !!             only if ln_wave=.true.
-      !!               
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT( in  ) ::  kt   ! ocean time step
-      !
-      INTEGER :: jj, ji, jk   ! dummy loop indices
-      !!---------------------------------------------------------------------
-      !
-      IF( kt == nit000 ) THEN                   ! First call kt=nit000 !
-         IF( .NOT. ( ln_wave .AND. ln_sdw ) )   &
-            &   CALL ctl_stop ( 'Ask for wave Qiao enhanced turbulence but ln_wave   &
-            &                    and ln_sdw have to be activated')
-         IF( zdf_qiao_alloc() /= 0 )   &
-            &   CALL ctl_stop( 'STOP', 'zdf_qiao : unable to allocate arrays' )
-      ENDIF
-
-      !
-      ! Compute the Qiao term Bv (qbv) to be added to
-      ! vertical viscosity and diffusivity
-      ! qbv = alpha * A * Us(0) * exp (3 * k * z)
-      ! alpha here is set to 1
-      !---------------------------------------------------------------------------------
-      !
-      DO jk = 1, jpk
-         DO jj = 1, jpjm1
-            DO ji = 1, fs_jpim1
-               qbv(ji,jj,jk) = 1.0 * 0.353553 * hsw(ji,jj) * tsd2d(ji,jj) *             &
-            &                  EXP(3.0 * wnum(ji,jj) *                                  &                     
-            &                  (-MIN( gdepw_n(ji  ,jj  ,jk), gdepw_n(ji+1,jj  ,jk),     &
-            &                         gdepw_n(ji  ,jj+1,jk), gdepw_n(ji+1,jj+1,jk))))   &
-            &                          * wmask(ji,jj,jk)
-            END DO
-         END DO
-      END DO
-      !
-      CALL lbc_lnk( qbv, 'W', 1. )   ! Lateral boundary conditions
-         
-      !
-      ! Interpolate Qiao parameter qbv into the grid_U and grid_V
-      !----------------------------------------------------------
-      !
-      DO jk = 1, jpk
-         DO jj = 1, jpjm1
-            DO ji = 1, fs_jpim1
-               qbvu(ji,jj,jk) = 0.5 * wumask(ji,jj,jk)  *              &  
-            &                  ( qbv(ji,jj,jk) + qbv(ji+1,jj  ,jk) )
-               qbvv(ji,jj,jk) = 0.5 * wvmask(ji,jj,jk)  *              &
-            &                  ( qbv(ji,jj,jk) + qbv(ji  ,jj+1,jk) )
-            END DO
-         END DO
-      END DO
-      ! 
-      CALL lbc_lnk( qbvu, 'U', 1. ) ; CALL lbc_lnk( qbvv, 'V', 1. )   ! Lateral boundary conditions
-
-      ! Enhance vertical mixing coeff.         
-      !-------------------------------
-      !
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               avmu(ji,jj,jk) = ( avmu(ji,jj,jk) + qbvu(ji,jj,jk) ) * umask(ji,jj,jk)
-               avmv(ji,jj,jk) = ( avmv(ji,jj,jk) + qbvv(ji,jj,jk) ) * vmask(ji,jj,jk)
-               avt (ji,jj,jk) = ( avt (ji,jj,jk) + qbv (ji,jj,jk) ) * tmask(ji,jj,jk)
-            END DO
-         END DO
-      END DO
-      !
-   END SUBROUTINE zdf_qiao
-
-   INTEGER FUNCTION zdf_qiao_alloc()
-      !!----------------------------------------------------------------------
-      !!                ***  FUNCTION zdf_qiao_alloc  ***
-      !!----------------------------------------------------------------------
-      ALLOCATE( qbv(jpi,jpj,jpk), qbvu(jpi,jpj,jpk), qbvv(jpi,jpj,jpk),   &
-         &      STAT = zdf_qiao_alloc )
-      !
-      IF( lk_mpp             )  CALL mpp_sum ( zdf_qiao_alloc )
-      IF( zdf_qiao_alloc > 0 )  CALL ctl_warn('zdf_qiao_alloc: allocation of arrays failed.')
-      !
-   END FUNCTION zdf_qiao_alloc
-      
-   !!======================================================================
-END MODULE zdfqiao
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90	(revision 9019)
@@ -5,57 +5,53 @@
    !!                 Richardson number dependent formulation
    !!======================================================================
-   !! History :  OPA  ! 1987-09  (P. Andrich)  Original code
-   !!            4.0  ! 1991-11  (G. Madec)
-   !!            7.0  ! 1996-01  (G. Madec)  complete rewriting of multitasking suppression of common work arrays
-   !!            8.0  ! 1997-06  (G. Madec)  complete rewriting of zdfmix
-   !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
-   !!            3.3  ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
-   !!            3.3.1! 2011-09  (P. Oddo) Mixed layer depth parameterization
-   !!----------------------------------------------------------------------
-#if defined key_zdfric
-   !!----------------------------------------------------------------------
-   !!   'key_zdfric'                                             Kz = f(Ri)
-   !!----------------------------------------------------------------------
-   !!   zdf_ric       : update momentum and tracer Kz from the Richardson
-   !!                  number computation
+   !! History :  OPA  !  1987-09  (P. Andrich)  Original code
+   !!            4.0  !  1991-11  (G. Madec)
+   !!            7.0  !  1996-01  (G. Madec)  complete rewriting of multitasking suppression of common work arrays
+   !!            8.0  !  1997-06  (G. Madec)  complete rewriting of zdfmix
+   !!   NEMO     1.0  !  2002-06  (G. Madec)  F90: Free form and module
+   !!            3.3  !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
+   !!            3.3.1!  2011-09  (P. Oddo) Mixed layer depth parameterization
+   !!            4.0  !  2017-04  (G. Madec)  remove CPP ddm key & avm at t-point only 
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
    !!   zdf_ric_init  : initialization, namelist read, & parameters control
+   !!   zdf_ric       : update momentum and tracer Kz from the Richardson number
+   !!   ric_rst       : read/write RIC restart in ocean restart file
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and tracers variables
    USE dom_oce        ! ocean space and time domain variables
-   USE zdf_oce        ! ocean vertical physics
+   USE zdf_oce        ! vertical physics: variables
+   USE phycst         ! physical constants
+   USE sbc_oce,  ONLY :   taum
+   !
    USE in_out_manager ! I/O manager
-   USE lbclnk         ! ocean lateral boundary condition (or mpp link)
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
+   USE iom            ! I/O manager library
    USE timing         ! Timing
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
 
-   USE eosbn2, ONLY : neos
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   zdf_ric         ! called by step.F90
-   PUBLIC   zdf_ric_init    ! called by opa.F90
-
-   LOGICAL, PUBLIC, PARAMETER ::   lk_zdfric = .TRUE.   !: Richardson vertical mixing flag
-
-   !                           !!* Namelist namzdf_ric : Richardson number dependent Kz *
-   INTEGER  ::   nn_ric         ! coefficient of the parameterization
-   REAL(wp) ::   rn_avmri       ! maximum value of the vertical eddy viscosity
-   REAL(wp) ::   rn_alp         ! coefficient of the parameterization
-   REAL(wp) ::   rn_ekmfc       ! Ekman Factor Coeff
-   REAL(wp) ::   rn_mldmin      ! minimum mixed layer (ML) depth    
-   REAL(wp) ::   rn_mldmax      ! maximum mixed layer depth
-   REAL(wp) ::   rn_wtmix       ! Vertical eddy Diff. in the ML
-   REAL(wp) ::   rn_wvmix       ! Vertical eddy Visc. in the ML
-   LOGICAL  ::   ln_mldw        ! Use or not the MLD parameters
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   tmric   !: coef. for the horizontal mean at t-point
+   PUBLIC   zdf_ric         ! called by zdfphy.F90
+   PUBLIC   ric_rst         ! called by zdfphy.F90
+   PUBLIC   zdf_ric_init    ! called by nemogcm.F90
+
+   !                        !!* Namelist namzdf_ric : Richardson number dependent Kz *
+   INTEGER  ::   nn_ric      ! coefficient of the parameterization
+   REAL(wp) ::   rn_avmri    ! maximum value of the vertical eddy viscosity
+   REAL(wp) ::   rn_alp      ! coefficient of the parameterization
+   REAL(wp) ::   rn_ekmfc    ! Ekman Factor Coeff
+   REAL(wp) ::   rn_mldmin   ! minimum mixed layer (ML) depth    
+   REAL(wp) ::   rn_mldmax   ! maximum mixed layer depth
+   REAL(wp) ::   rn_wtmix    ! Vertical eddy Diff. in the ML
+   REAL(wp) ::   rn_wvmix    ! Vertical eddy Visc. in the ML
+   LOGICAL  ::   ln_mldw     ! Use or not the MLD parameters
 
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -63,16 +59,55 @@
 CONTAINS
 
-   INTEGER FUNCTION zdf_ric_alloc()
-      !!----------------------------------------------------------------------
-      !!                 ***  FUNCTION zdf_ric_alloc  ***
-      !!----------------------------------------------------------------------
-      ALLOCATE( tmric(jpi,jpj,jpk)   , STAT= zdf_ric_alloc )
-      !
-      IF( lk_mpp             )   CALL mpp_sum ( zdf_ric_alloc )
-      IF( zdf_ric_alloc /= 0 )   CALL ctl_warn('zdf_ric_alloc: failed to allocate arrays')
-   END FUNCTION zdf_ric_alloc
-
-
-   SUBROUTINE zdf_ric( kt )
+   SUBROUTINE zdf_ric_init
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE zdf_ric_init  ***
+      !!                    
+      !! ** Purpose :   Initialization of the vertical eddy diffusivity and
+      !!      viscosity coef. for the Richardson number dependent formulation.
+      !!
+      !! ** Method  :   Read the namzdf_ric namelist and check the parameter values
+      !!
+      !! ** input   :   Namelist namzdf_ric
+      !!
+      !! ** Action  :   increase by 1 the nstop flag is setting problem encounter
+      !!----------------------------------------------------------------------
+      INTEGER :: ji, jj, jk   ! dummy loop indices
+      INTEGER ::   ios        ! Local integer output status for namelist read
+      !!
+      NAMELIST/namzdf_ric/ rn_avmri, rn_alp   , nn_ric  , rn_ekmfc,  &
+         &                rn_mldmin, rn_mldmax, rn_wtmix, rn_wvmix, ln_mldw
+      !!----------------------------------------------------------------------
+      !
+      REWIND( numnam_ref )              ! Namelist namzdf_ric in reference namelist : Vertical diffusion Kz depends on Richardson number
+      READ  ( numnam_ref, namzdf_ric, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_ric in reference namelist', lwp )
+
+      REWIND( numnam_cfg )              ! Namelist namzdf_ric in configuration namelist : Vertical diffusion Kz depends on Richardson number
+      READ  ( numnam_cfg, namzdf_ric, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_ric in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, namzdf_ric )
+      !
+      IF(lwp) THEN                   ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'zdf_ric_init : Ri depend vertical mixing scheme'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namzdf_ric : set Kz=F(Ri) parameters'
+         WRITE(numout,*) '      maximum vertical viscosity        rn_avmri  = ', rn_avmri
+         WRITE(numout,*) '      coefficient                       rn_alp    = ', rn_alp
+         WRITE(numout,*) '      exponent                          nn_ric    = ', nn_ric
+         WRITE(numout,*) '      Ekman layer enhanced mixing       ln_mldw   = ', ln_mldw
+         WRITE(numout,*) '         Ekman Factor Coeff             rn_ekmfc  = ', rn_ekmfc
+         WRITE(numout,*) '         minimum mixed layer depth      rn_mldmin = ', rn_mldmin
+         WRITE(numout,*) '         maximum mixed layer depth      rn_mldmax = ', rn_mldmax
+         WRITE(numout,*) '         Vertical eddy Diff. in the ML  rn_wtmix  = ', rn_wtmix
+         WRITE(numout,*) '         Vertical eddy Visc. in the ML  rn_wvmix  = ', rn_wvmix
+      ENDIF
+      !
+      CALL ric_rst( nit000, 'READ' )  !* read or initialize all required files
+      !
+   END SUBROUTINE zdf_ric_init
+
+
+   SUBROUTINE zdf_ric( kt, pdept, p_sh2, p_avm, p_avt )
       !!----------------------------------------------------------------------
       !!                 ***  ROUTINE zdfric  ***
@@ -88,12 +123,10 @@
       !!                with ri  = N^2 / dz(u)**2
       !!                         = e3w**2 * rn2/[ mi( dk(ub) )+mj( dk(vb) ) ]
-      !!                    avm0= rn_avmri / (1 + rn_alp*ri)**nn_ric
-      !!      Where ri is the before local Richardson number,
-      !!            rn_avmri is the maximum value reaches by avm and avt 
-      !!            avmb and avtb are the background (or minimum) values
-      !!            and rn_alp, nn_ric are adjustable parameters.
-      !!      Typical values used are : avm0=1.e-2 m2/s, avmb=1.e-6 m2/s
-      !!      avtb=1.e-7 m2/s, rn_alp=5. and nn_ric=2.
-      !!      a numerical threshold is impose on the vertical shear (1.e-20)
+      !!                    avm0= rn_avmri / (1 + rn_alp*Ri)**nn_ric
+      !!                where ri is the before local Richardson number,
+      !!                rn_avmri is the maximum value reaches by avm and avt 
+      !!                and rn_alp, nn_ric are adjustable parameters.
+      !!                Typical values : rn_alp=5. and nn_ric=2.
+      !!
       !!      As second step compute Ekman depth from wind stress forcing
       !!      and apply namelist provided vertical coeff within this depth.
@@ -101,5 +134,5 @@
       !!              Ustar = SQRT(Taum/rho0)
       !!              ekd= rn_ekmfc * Ustar / f0
-      !!      Large et al. (1994, eq.29) suggest rn_ekmfc=0.7; however, the derivation
+      !!      Large et al. (1994, eq.24) suggest rn_ekmfc=0.7; however, the derivation
       !!      of the above equation indicates the value is somewhat arbitrary; therefore
       !!      we allow the freedom to increase or decrease this value, if the
@@ -108,211 +141,105 @@
       !!      namelist
       !!        N.B. the mask are required for implicit scheme, and surface
-      !!      and bottom value already set in zdfini.F90
+      !!      and bottom value already set in zdfphy.F90
+      !!
+      !! ** Action  :   avm, avt  mixing coeff (inner domain values only)
       !!
       !! References : Pacanowski & Philander 1981, JPO, 1441-1451.
       !!              PFJ Lermusiaux 2001.
       !!----------------------------------------------------------------------
-      USE phycst,   ONLY:   rsmall,rau0
-      USE sbc_oce,  ONLY:   taum
-      !!
-      INTEGER, INTENT( in ) ::   kt                           ! ocean time-step
-      !!
-      INTEGER  ::   ji, jj, jk                                ! dummy loop indices
-      REAL(wp) ::   zcoef, zdku, zdkv, zri, z05alp, zflageos  ! temporary scalars
-      REAL(wp) ::   zrhos, zustar
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zwx, ekm_dep  
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('zdf_ric')
-      !
-      CALL wrk_alloc( jpi,jpj, zwx, ekm_dep )
-      !                                                ! ===============
-      DO jk = 2, jpkm1                                 ! Horizontal slab
-         !                                             ! ===============
-         ! Richardson number (put in zwx(ji,jj))
-         ! -----------------
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1
-               zcoef = 0.5 / e3w_n(ji,jj,jk)
-               !                                            ! shear of horizontal velocity
-               zdku = zcoef * (  ub(ji-1,jj,jk-1) + ub(ji,jj,jk-1)   &
-                  &             -ub(ji-1,jj,jk  ) - ub(ji,jj,jk  )  )
-               zdkv = zcoef * (  vb(ji,jj-1,jk-1) + vb(ji,jj,jk-1)   &
-                  &             -vb(ji,jj-1,jk  ) - vb(ji,jj,jk  )  )
-               !                                            ! richardson number (minimum value set to zero)
-               zri = rn2(ji,jj,jk) / ( zdku*zdku + zdkv*zdkv + 1.e-20 )
-               zwx(ji,jj) = MAX( zri, 0.e0 )
-            END DO
-         END DO
-         CALL lbc_lnk( zwx, 'W', 1. )                       ! Boundary condition   (sign unchanged)
-
-         ! Vertical eddy viscosity and diffusivity coefficients
-         ! -------------------------------------------------------
-         z05alp = 0.5_wp * rn_alp
-         DO jj = 1, jpjm1                                   ! Eddy viscosity coefficients (avm)
-            DO ji = 1, fs_jpim1
-               avmu(ji,jj,jk) = umask(ji,jj,jk) * rn_avmri / ( 1. + z05alp*( zwx(ji+1,jj)+zwx(ji,jj) ) )**nn_ric
-               avmv(ji,jj,jk) = vmask(ji,jj,jk) * rn_avmri / ( 1. + z05alp*( zwx(ji,jj+1)+zwx(ji,jj) ) )**nn_ric
-            END DO
-         END DO
-         DO jj = 2, jpjm1                                   ! Eddy diffusivity coefficients (avt)
-            DO ji = fs_2, fs_jpim1
-               avt(ji,jj,jk) = tmric(ji,jj,jk) / ( 1._wp + rn_alp * zwx(ji,jj) )           &
-                  &                            * (  avmu(ji,jj,jk) + avmu(ji-1,jj,jk)      &
-                  &                               + avmv(ji,jj,jk) + avmv(ji,jj-1,jk)  )   &
-                  &          + avtb(jk) * tmask(ji,jj,jk)
-            END DO
-         END DO
-         DO jj = 2, jpjm1                                   ! Add the background coefficient on eddy viscosity
-            DO ji = fs_2, fs_jpim1
-               avmu(ji,jj,jk) = avmu(ji,jj,jk) + avmb(jk) * umask(ji,jj,jk)
-               avmv(ji,jj,jk) = avmv(ji,jj,jk) + avmb(jk) * vmask(ji,jj,jk)
-            END DO
-         END DO
-         !                                             ! ===============
-      END DO                                           !   End of slab
-      !                                                ! ===============
-      !
-      IF( ln_mldw ) THEN
-
-      !  Compute Ekman depth from wind stress forcing.
-      ! -------------------------------------------------------
-      zflageos = ( 0.5 + SIGN( 0.5, neos - 1. ) ) * rau0
-      DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1
-            zrhos          = rhop(ji,jj,1) + zflageos * ( 1. - tmask(ji,jj,1) )
-            zustar         = SQRT( taum(ji,jj) / ( zrhos +  rsmall ) )
-            ekm_dep(ji,jj) = rn_ekmfc * zustar / ( ABS( ff_t(ji,jj) ) + rsmall )
-            ekm_dep(ji,jj) = MAX(ekm_dep(ji,jj),rn_mldmin) ! Minimun allowed
-            ekm_dep(ji,jj) = MIN(ekm_dep(ji,jj),rn_mldmax) ! Maximum allowed
-         END DO
-      END DO
-
-      ! In the first model level vertical diff/visc coeff.s 
-      ! are always equal to the namelist values rn_wtmix/rn_wvmix
-      ! -------------------------------------------------------
-      DO jj = 2, jpjm1
-         DO ji = fs_2, fs_jpim1
-            avmv(ji,jj,1) = MAX( avmv(ji,jj,1), rn_wvmix )
-            avmu(ji,jj,1) = MAX( avmu(ji,jj,1), rn_wvmix )
-            avt( ji,jj,1) = MAX(  avt(ji,jj,1), rn_wtmix )
-         END DO
-      END DO
-
-      !  Force the vertical mixing coef within the Ekman depth
-      ! -------------------------------------------------------
+      INTEGER                   , INTENT(in   ) ::   kt             ! ocean time-step
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pdept          ! depth of t-point  [m]
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   p_sh2          ! shear production term
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   p_avm, p_avt   ! momentum and tracer Kz (w-points)
+      !!
+      INTEGER  ::   ji, jj, jk                  ! dummy loop indices
+      REAL(wp) ::   zcfRi, zav, zustar, zhek    ! local scalars
+      REAL(wp), DIMENSION(jpi,jpj) ::   zh_ekm  ! 2D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('zdf_ric')
+      !
+      !                       !==  avm and avt = F(Richardson number)  ==!
       DO jk = 2, jpkm1
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1
-               IF( gdept_n(ji,jj,jk) < ekm_dep(ji,jj) ) THEN
-                  avmv(ji,jj,jk) = MAX( avmv(ji,jj,jk), rn_wvmix )
-                  avmu(ji,jj,jk) = MAX( avmu(ji,jj,jk), rn_wvmix )
-                  avt( ji,jj,jk) = MAX(  avt(ji,jj,jk), rn_wtmix )
-               ENDIF
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1              ! coefficient = F(richardson number) (avm-weighted Ri)
+               zcfRi = 1._wp / (  1._wp + rn_alp * MAX(  0._wp , avm(ji,jj,jk) * rn2(ji,jj,jk) / ( p_sh2(ji,jj,jk) + 1.e-20 ) )  )
+               zav   = rn_avmri * zcfRi**nn_ric
+               !                          ! avm and avt coefficients
+               p_avm(ji,jj,jk) = MAX(  zav         , avmb(jk)  ) * wmask(ji,jj,jk)
+               p_avt(ji,jj,jk) = MAX(  zav * zcfRi , avtb(jk)  ) * wmask(ji,jj,jk)
             END DO
          END DO
       END DO
-
-      DO jk = 1, jpkm1                
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1
-               avmv(ji,jj,jk) = avmv(ji,jj,jk) * vmask(ji,jj,jk)
-               avmu(ji,jj,jk) = avmu(ji,jj,jk) * umask(ji,jj,jk)
-               avt( ji,jj,jk) = avt( ji,jj,jk) * tmask(ji,jj,jk)
+      !
+!!gm BUG <<<<====  This param can't work at low latitude 
+!!gm               it provides there much to thick mixed layer ( summer 150m in GYRE configuration !!! )
+      !
+      IF( ln_mldw ) THEN      !==  set a minimum value in the Ekman layer  ==!
+         !
+         DO jj = 2, jpjm1        !* Ekman depth
+            DO ji = 2, jpim1
+               zustar = SQRT( taum(ji,jj) * r1_rau0 )
+               zhek   = rn_ekmfc * zustar / ( ABS( ff_t(ji,jj) ) + rsmall )   ! Ekman depth
+               zh_ekm(ji,jj) = MAX(  rn_mldmin , MIN( zhek , rn_mldmax )  )   ! set allowed range
             END DO
          END DO
-      END DO
-
-     ENDIF
-
-      CALL lbc_lnk( avt , 'W', 1. )                         ! Boundary conditions   (unchanged sign)
-      CALL lbc_lnk( avmu, 'U', 1. )   ;   CALL lbc_lnk( avmv, 'V', 1. )
-      !
-      CALL wrk_dealloc( jpi,jpj, zwx, ekm_dep )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('zdf_ric')
-      !
-   END SUBROUTINE zdf_ric
-
-
-   SUBROUTINE zdf_ric_init
-      !!----------------------------------------------------------------------
-      !!                 ***  ROUTINE zdfbfr_init  ***
-      !!                    
-      !! ** Purpose :   Initialization of the vertical eddy diffusivity and
-      !!      viscosity coef. for the Richardson number dependent formulation.
-      !!
-      !! ** Method  :   Read the namzdf_ric namelist and check the parameter values
-      !!
-      !! ** input   :   Namelist namzdf_ric
-      !!
-      !! ** Action  :   increase by 1 the nstop flag is setting problem encounter
-      !!----------------------------------------------------------------------
-      INTEGER :: ji, jj, jk   ! dummy loop indices
-      INTEGER ::   ios        ! Local integer output status for namelist read
-      !!
-      NAMELIST/namzdf_ric/ rn_avmri, rn_alp   , nn_ric  , rn_ekmfc,  &
-         &                rn_mldmin, rn_mldmax, rn_wtmix, rn_wvmix, ln_mldw
-      !!----------------------------------------------------------------------
-      !
-      REWIND( numnam_ref )              ! Namelist namzdf_ric in reference namelist : Vertical diffusion Kz depends on Richardson number
-      READ  ( numnam_ref, namzdf_ric, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_ric in reference namelist', lwp )
-
-      REWIND( numnam_cfg )              ! Namelist namzdf_ric in configuration namelist : Vertical diffusion Kz depends on Richardson number
-      READ  ( numnam_cfg, namzdf_ric, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_ric in configuration namelist', lwp )
-      IF(lwm) WRITE ( numond, namzdf_ric )
-      !
-      IF(lwp) THEN                   ! Control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'zdf_ric : Ri depend vertical mixing scheme'
-         WRITE(numout,*) '~~~~~~~'
-         WRITE(numout,*) '   Namelist namzdf_ric : set Kz(Ri) parameters'
-         WRITE(numout,*) '      maximum vertical viscosity     rn_avmri  = ', rn_avmri
-         WRITE(numout,*) '      coefficient                    rn_alp    = ', rn_alp
-         WRITE(numout,*) '      coefficient                    nn_ric    = ', nn_ric
-         WRITE(numout,*) '      Ekman Factor Coeff             rn_ekmfc  = ', rn_ekmfc
-         WRITE(numout,*) '      minimum mixed layer depth      rn_mldmin = ', rn_mldmin
-         WRITE(numout,*) '      maximum mixed layer depth      rn_mldmax = ', rn_mldmax
-         WRITE(numout,*) '      Vertical eddy Diff. in the ML  rn_wtmix  = ', rn_wtmix
-         WRITE(numout,*) '      Vertical eddy Visc. in the ML  rn_wvmix  = ', rn_wvmix
-         WRITE(numout,*) '      Use the MLD parameterization   ln_mldw   = ', ln_mldw
-      ENDIF
-      !
-      !                              ! allocate zdfric arrays
-      IF( zdf_ric_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_ric_init : unable to allocate arrays' )
-      !
-      DO jk = 1, jpk                 ! weighting mean array tmric for 4 T-points
-         DO jj = 2, jpj              ! which accounts for coastal boundary conditions            
-            DO ji = 2, jpi
-               tmric(ji,jj,jk) =  tmask(ji,jj,jk)                                  &
-                  &            / MAX( 1.,  umask(ji-1,jj  ,jk) + umask(ji,jj,jk)   &
-                  &                      + vmask(ji  ,jj-1,jk) + vmask(ji,jj,jk)  )
+         DO jk = 2, jpkm1        !* minimum mixing coeff. within the Ekman layer
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  IF( pdept(ji,jj,jk) < zh_ekm(ji,jj) ) THEN
+                     p_avm(ji,jj,jk) = MAX(  p_avm(ji,jj,jk), rn_wvmix  ) * wmask(ji,jj,jk)
+                     p_avt(ji,jj,jk) = MAX(  p_avt(ji,jj,jk), rn_wtmix  ) * wmask(ji,jj,jk)
+                  ENDIF
+               END DO
             END DO
          END DO
-      END DO
-      tmric(:,1,:) = 0._wp
-      !
-      DO jk = 1, jpk                 ! Initialization of vertical eddy coef. to the background value
-         avt (:,:,jk) = avtb(jk) * tmask(:,:,jk)
-         avmu(:,:,jk) = avmb(jk) * umask(:,:,jk)
-         avmv(:,:,jk) = avmb(jk) * vmask(:,:,jk)
-      END DO
-      !
-   END SUBROUTINE zdf_ric_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Dummy module :              NO Richardson dependent vertical mixing
-   !!----------------------------------------------------------------------
-   LOGICAL, PUBLIC, PARAMETER ::   lk_zdfric = .FALSE.   !: Richardson mixing flag
-CONTAINS
-   SUBROUTINE zdf_ric_init         ! Dummy routine
-   END SUBROUTINE zdf_ric_init
-   SUBROUTINE zdf_ric( kt )        ! Dummy routine
-      WRITE(*,*) 'zdf_ric: You should not have seen this print! error?', kt
+      ENDIF
+      !
+      IF( ln_timing )   CALL timing_stop('zdf_ric')
+      !
    END SUBROUTINE zdf_ric
-#endif
+
+
+   SUBROUTINE ric_rst( kt, cdrw )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE ric_rst  ***
+      !!                     
+      !! ** Purpose :   Read or write TKE file (en) in restart file
+      !!
+      !! ** Method  :   use of IOM library
+      !!                if the restart does not contain TKE, en is either 
+      !!                set to rn_emin or recomputed 
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in) ::   kt     ! ocean time-step
+      CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
+      !
+      INTEGER ::   jit, jk    ! dummy loop indices
+      INTEGER ::   id1, id2   ! local integers
+      !!----------------------------------------------------------------------
+      !
+      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
+         !                                   ! ---------------
+         !           !* Read the restart file
+         IF( ln_rstart ) THEN
+            id1 = iom_varid( numror, 'avt_k', ldstop = .FALSE. )
+            id2 = iom_varid( numror, 'avm_k', ldstop = .FALSE. )
+            !
+            IF( MIN( id1, id2 ) > 0 ) THEN         ! restart exists => read it
+               CALL iom_get( numror, jpdom_autoglo, 'avt_k', avt_k )
+               CALL iom_get( numror, jpdom_autoglo, 'avm_k', avm_k )
+            ENDIF
+         ENDIF
+         !           !* otherwise Kz already set to the background value in zdf_phy_init
+         !
+      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
+         !                                   ! -------------------
+         IF(lwp) WRITE(numout,*) '---- ric-rst ----'
+         CALL iom_rstput( kt, nitrst, numrow, 'avt_k', avt_k )
+         CALL iom_rstput( kt, nitrst, numrow, 'avm_k', avm_k )
+         !
+      ENDIF
+      !
+   END SUBROUTINE ric_rst
 
    !!======================================================================
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfsh2.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfsh2.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfsh2.F90	(revision 9019)
@@ -0,0 +1,84 @@
+MODULE zdfsh2
+   !!======================================================================
+   !!                       ***  MODULE  zdfsh2  ***
+   !! Ocean physics:  shear production term of TKE 
+   !!=====================================================================
+   !! History :   -   !  2014-10  (A. Barthelemy, G. Madec)  original code
+   !!   NEMO     4.0  !  2017-04  (G. Madec)  remove u-,v-pts avm
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   zdf_sh2       : compute mixing the shear production term of TKE
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! domain: ocean
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE timing         ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   zdf_sh2        ! called by zdftke, zdfglf, and zdfric
+   
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
+   !! $Id: $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE zdf_sh2( pub, pvb, pun, pvn, p_avm, p_sh2  ) 
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE zdf_sh2  ***
+      !!
+      !! ** Purpose :   Compute the shear production term of a TKE equation
+      !!
+      !! ** Method  : - a stable discretization of this term is linked to the
+      !!                time-space discretization of the vertical diffusion
+      !!                of the OGCM. NEMO uses C-grid, a leap-frog environment 
+      !!                and an implicit computation of vertical mixing term,
+      !!                so the shear production at w-point is given by:
+      !!                   sh2 = mi[   mi(avm) * dk[ub]/e3ub * dk[un]/e3un   ] 
+      !!                       + mj[   mj(avm) * dk[vb]/e3vb * dk[vn]/e3vn   ] 
+      !!                NB: wet-point only horizontal averaging of shear
+      !!
+      !! ** Action  : - p_sh2 shear prod. term at w-point (inner domain only)
+      !!                                                   *****
+      !! References :   Bruchard, OM 2002
+      !! ---------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:,:) , INTENT(in   ) ::   pub, pvb, pun, pvn   ! before, now horizontal velocities
+      REAL(wp), DIMENSION(:,:,:) , INTENT(in   ) ::   p_avm                ! vertical eddy viscosity (w-points)
+      REAL(wp), DIMENSION(:,:,:) , INTENT(  out) ::   p_sh2                ! shear production of TKE (w-points)
+      !
+      INTEGER  ::   ji, jj, jk   ! dummy loop arguments
+      REAL(wp), DIMENSION(jpi,jpj) ::   zsh2u, zsh2v   ! 2D workspace
+      !!--------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('zdf_sh2')
+      !
+      DO jk = 2, jpkm1
+         DO jj = 1, jpjm1        !* 2 x shear production at uw- and vw-points (energy conserving form)
+            DO ji = 1, jpim1
+               zsh2u(ji,jj) = ( p_avm(ji+1,jj,jk) + p_avm(ji,jj,jk) ) &
+                  &         * (   pun(ji,jj,jk-1) -   pun(ji,jj,jk) ) &
+                  &         * (   pub(ji,jj,jk-1) -   pub(ji,jj,jk) ) / ( e3uw_n(ji,jj,jk) * e3uw_b(ji,jj,jk) ) * wumask(ji,jj,jk)
+               zsh2v(ji,jj) = ( p_avm(ji,jj+1,jk) + p_avm(ji,jj,jk) ) &
+                  &         * (   pvn(ji,jj,jk-1) -   pvn(ji,jj,jk) ) &
+                  &         * (   pvb(ji,jj,jk-1) -   pvb(ji,jj,jk) ) / ( e3vw_n(ji,jj,jk) * e3vw_b(ji,jj,jk) ) * wvmask(ji,jj,jk)
+            END DO
+         END DO
+         DO jj = 2, jpjm1        !* shear production at w-point
+            DO ji = 2, jpim1           ! coast mask: =2 at the coast ; =1 otherwise (NB: wmask useless as zsh2 are masked)
+               p_sh2(ji,jj,jk) = 0.25 * (   ( zsh2u(ji-1,jj) + zsh2u(ji,jj) ) * ( 2. - umask(ji-1,jj,jk) * umask(ji,jj,jk) )   &
+                  &                       + ( zsh2v(ji,jj-1) + zsh2v(ji,jj) ) * ( 2. - vmask(ji,jj-1,jk) * vmask(ji,jj,jk) )   )
+            END DO
+         END DO
+      END DO 
+      !
+      IF( ln_timing )   CALL timing_stop('zdf_sh2')     
+      !
+   END SUBROUTINE zdf_sh2
+
+   !!======================================================================
+END MODULE zdfsh2
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfswm.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfswm.F90	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfswm.F90	(revision 9019)
@@ -0,0 +1,97 @@
+MODULE zdfswm
+   !!======================================================================
+   !!                       ***  MODULE  zdfswm  ***
+   !! vertical physics :   surface wave-induced mixing 
+   !!======================================================================
+   !! History :  3.6  !  2014-10  (E. Clementi)  Original code
+   !!            4.0  !  2017-04  (G. Madec)  debug + simplifications
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   zdf_swm      : update Kz due to surface wave-induced mixing 
+   !!   zdf_swm_init : initilisation
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean domain variable
+   USE zdf_oce        ! vertical physics: mixing coefficients
+   USE sbc_oce        ! Surface boundary condition: ocean fields
+   USE sbcwave        ! wave module
+   !
+   USE in_out_manager ! I/O manager
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)  
+   USE lib_mpp        ! distribued memory computing library
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC zdf_swm         ! routine called in zdp_phy
+   PUBLIC zdf_swm_init    ! routine called in zdf_phy_init
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017) 
+   !! $Id:$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE zdf_swm( kt, p_avm, p_avt, p_avs )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE zdf_swm ***
+      !!
+      !! ** Purpose :Compute the swm term (qbv) to be added to
+      !!             vertical viscosity and diffusivity coeffs.  
+      !!
+      !! ** Method  :   Compute the swm term Bv (zqb) and added it to
+      !!               vertical viscosity and diffusivity coefficients
+      !!                   zqb = alpha * A * Us(0) * exp (3 * k * z)
+      !!               where alpha is set here to 1
+      !!             
+      !! ** action  :    avt, avs, avm updated by the surface wave-induced mixing
+      !!                               (inner domain only)
+      !!               
+      !! reference : Qiao et al. GRL, 2004
+      !!---------------------------------------------------------------------
+      INTEGER                    , INTENT(in   ) ::   kt             ! ocean time step
+      REAL(wp), DIMENSION(:,:,:) , INTENT(inout) ::   p_avm          ! momentum Kz (w-points)
+      REAL(wp), DIMENSION(:,:,:) , INTENT(inout) ::   p_avt, p_avs   ! tracer   Kz (w-points)
+      !
+      INTEGER ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp)::   zcoef, zqb   ! local scalar
+      !!---------------------------------------------------------------------
+      !
+      zcoef = 1._wp * 0.353553_wp
+      DO jk = 2, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               zqb = zcoef * hsw(ji,jj) * tsd2d(ji,jj) * EXP( -3. * wnum(ji,jj) * gdepw_n(ji,jj,jk) ) * wmask(ji,jj,jk)
+               !
+               p_avt(ji,jj,jk) = p_avt(ji,jj,jk) + zqb
+               p_avs(ji,jj,jk) = p_avs(ji,jj,jk) + zqb
+               p_avm(ji,jj,jk) = p_avm(ji,jj,jk) + zqb
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE zdf_swm
+   
+   
+   SUBROUTINE zdf_swm_init
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE zdf_swm_init ***
+      !!
+      !! ** Purpose :   surface wave-induced mixing initialisation  
+      !!
+      !! ** Method  :   check the availability of surface wave fields
+      !!---------------------------------------------------------------------
+      !
+      IF(lwp) THEN                  ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'zdf_swm_init : surface wave-driven mixing'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+      ENDIF
+      IF(  .NOT.ln_wave .OR.   &
+         & .NOT.ln_sdw    )   CALL ctl_stop ( 'zdf_swm_init: ln_zdfswm=T but ln_wave and ln_sdw /= T')
+      !
+   END SUBROUTINE zdf_swm_init
+
+   !!======================================================================
+END MODULE zdfswm
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 9019)
@@ -27,8 +27,8 @@
    !!            3.3  !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
    !!            3.6  !  2014-11  (P. Mathiot) add ice shelf capability
+   !!            4.0  !  2017-04  (G. Madec)  remove CPP ddm key & avm at t-point only 
+   !!             -   !  2017-05  (G. Madec)  add top/bottom friction as boundary condition (ln_drg)
    !!----------------------------------------------------------------------
-#if defined key_zdftke
-   !!----------------------------------------------------------------------
-   !!   'key_zdftke'                                   TKE vertical physics
+
    !!----------------------------------------------------------------------
    !!   zdf_tke       : update momentum and tracer Kz from a tke scheme
@@ -43,18 +43,14 @@
    USE domvvl         ! domain: variable volume layer
    USE sbc_oce        ! surface boundary condition: ocean
-   USE zdf_oce        ! vertical physics: ocean variables
+   USE zdfdrg         ! vertical physics: top/bottom drag coef.
    USE zdfmxl         ! vertical physics: mixed layer
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE prtctl         ! Print control
+   !
    USE in_out_manager ! I/O manager
    USE iom            ! I/O manager library
    USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl         ! Print control
    USE timing         ! Timing
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-#if defined key_agrif
-   USE agrif_opa_interp
-   USE agrif_opa_update
-#endif
 
    IMPLICIT NONE
@@ -64,6 +60,4 @@
    PUBLIC   zdf_tke_init   ! routine called in opa module
    PUBLIC   tke_rst        ! routine called in step module
-
-   LOGICAL , PUBLIC, PARAMETER ::   lk_zdftke = .TRUE.  !: TKE vertical mixing flag
 
    !                      !!** Namelist  namzdf_tke  **
@@ -78,9 +72,10 @@
    REAL(wp) ::   rn_emin0  ! surface minimum value of tke   [m2/s2]
    REAL(wp) ::   rn_bshear ! background shear (>0) currently a numerical threshold (do not change it)
+   LOGICAL  ::   ln_drg    ! top/bottom friction forcing flag 
    INTEGER  ::   nn_etau   ! type of depth penetration of surface tke (=0/1/2/3)
-   INTEGER  ::   nn_htau   ! type of tke profile of penetration (=0/1)
-   REAL(wp) ::   rn_efr    ! fraction of TKE surface value which penetrates in the ocean
+   INTEGER  ::      nn_htau   ! type of tke profile of penetration (=0/1)
+   REAL(wp) ::      rn_efr    ! fraction of TKE surface value which penetrates in the ocean
    LOGICAL  ::   ln_lc     ! Langmuir cells (LC) as a source term of TKE or not
-   REAL(wp) ::   rn_lc     ! coef to compute vertical velocity of Langmuir cells
+   REAL(wp) ::      rn_lc     ! coef to compute vertical velocity of Langmuir cells
 
    REAL(wp) ::   ri_cri    ! critic Richardson number (deduced from rn_ediff and rn_ediss values)
@@ -89,12 +84,7 @@
    REAL(wp) ::   rhftau_scl = 1.0_wp       ! scale factor applied to HF part of taum  (nn_etau=3)
 
-   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   htau           ! depth of tke penetration (nn_htau)
-   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dissl          ! now mixing lenght of dissipation
-   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   apdlr          ! now mixing lenght of dissipation
-#if defined key_c1d
-   !                                                                        !!** 1D cfg only  **   ('key_c1d')
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e_dis, e_mix   !: dissipation and mixing turbulent lengh scales
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e_pdl, e_ric   !: prandl and local Richardson numbers
-#endif
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   htau    ! depth of tke penetration (nn_htau)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dissl   ! now mixing lenght of dissipation
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   apdlr   ! now mixing lenght of dissipation
 
    !! * Substitutions
@@ -111,12 +101,6 @@
       !!                ***  FUNCTION zdf_tke_alloc  ***
       !!----------------------------------------------------------------------
-      ALLOCATE(                                                                    &
-#if defined key_c1d
-         &      e_dis(jpi,jpj,jpk) , e_mix(jpi,jpj,jpk) ,                          &
-         &      e_pdl(jpi,jpj,jpk) , e_ric(jpi,jpj,jpk) ,                          &
-#endif
-         &      htau  (jpi,jpj)    , dissl(jpi,jpj,jpk) ,     & 
-         &      apdlr(jpi,jpj,jpk) ,                                           STAT= zdf_tke_alloc      )
-         !
+      ALLOCATE( htau(jpi,jpj) , dissl(jpi,jpj,jpk) , apdlr(jpi,jpj,jpk) ,   STAT= zdf_tke_alloc )
+      !
       IF( lk_mpp             )   CALL mpp_sum ( zdf_tke_alloc )
       IF( zdf_tke_alloc /= 0 )   CALL ctl_warn('zdf_tke_alloc: failed to allocate arrays')
@@ -125,5 +109,5 @@
 
 
-   SUBROUTINE zdf_tke( kt )
+   SUBROUTINE zdf_tke( kt, p_sh2, p_avm, p_avt )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE zdf_tke  ***
@@ -162,5 +146,5 @@
       !!
       !! ** Action  :   compute en (now turbulent kinetic energy)
-      !!                update avt, avmu, avmv (before vertical eddy coef.)
+      !!                update avt, avm (before vertical eddy coef.)
       !!
       !! References : Gaspar et al., JGR, 1990,
@@ -170,37 +154,17 @@
       !!              Bruchard OM 2002
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time step
-      !!----------------------------------------------------------------------
-      !
-#if defined key_agrif 
-      ! interpolation parent grid => child grid for avm_k ( ex : at west border: update column 1 and 2)
-      IF( .NOT.Agrif_Root() )   CALL Agrif_Tke
-#endif
-      !
-      IF( kt /= nit000 ) THEN   ! restore before value to compute tke
-         avt (:,:,:) = avt_k (:,:,:) 
-         avm (:,:,:) = avm_k (:,:,:) 
-         avmu(:,:,:) = avmu_k(:,:,:) 
-         avmv(:,:,:) = avmv_k(:,:,:) 
-      ENDIF 
-      !
-      CALL tke_tke      ! now tke (en)
-      !
-      CALL tke_avn      ! now avt, avm, avmu, avmv
-      !
-      avt_k (:,:,:) = avt (:,:,:) 
-      avm_k (:,:,:) = avm (:,:,:) 
-      avmu_k(:,:,:) = avmu(:,:,:) 
-      avmv_k(:,:,:) = avmv(:,:,:) 
-      !
-#if defined key_agrif
-      ! Update child grid f => parent grid 
-      IF( .NOT.Agrif_Root() )   CALL Agrif_Update_Tke( kt )      ! children only
-#endif      
-     ! 
+      INTEGER                   , INTENT(in   ) ::   kt             ! ocean time step
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   p_sh2          ! shear production term
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   p_avm, p_avt   !  momentum and tracer Kz (w-points)
+      !!----------------------------------------------------------------------
+      !
+      CALL tke_tke( gdepw_n, e3t_n, e3w_n, p_sh2, p_avm, p_avt )   ! now tke (en)
+      !
+      CALL tke_avn( gdepw_n, e3t_n, e3w_n,        p_avm, p_avt )   ! now avt, avm, dissl
+      !
   END SUBROUTINE zdf_tke
 
 
-   SUBROUTINE tke_tke
+   SUBROUTINE tke_tke( pdepw, p_e3t, p_e3w, p_sh2, p_avm, p_avt )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE tke_tke  ***
@@ -210,36 +174,37 @@
       !! ** Method  : - TKE surface boundary condition
       !!              - source term due to Langmuir cells (Axell JGR 2002) (ln_lc=T)
-      !!              - source term due to shear (saved in avmu, avmv arrays)
+      !!              - source term due to shear (= Kz dz[Ub] * dz[Un] )
       !!              - Now TKE : resolution of the TKE equation by inverting
       !!                a tridiagonal linear system by a "methode de chasse"
       !!              - increase TKE due to surface and internal wave breaking
+      !!             NB: when sea-ice is present, both LC parameterization 
+      !!                 and TKE penetration are turned off when the ice fraction 
+      !!                 is smaller than 0.25 
       !!
       !! ** Action  : - en : now turbulent kinetic energy)
-      !!              - avmu, avmv : production of TKE by shear at u and v-points
-      !!                (= Kz dz[Ub] * dz[Un] )
       !! ---------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk                      ! dummy loop arguments
-!!bfr      INTEGER  ::   ikbu, ikbv, ikbum1, ikbvm1      ! temporary scalar
-!!bfr      INTEGER  ::   ikbt, ikbumm1, ikbvmm1          ! temporary scalar
-      REAL(wp) ::   zrhoa  = 1.22                   ! Air density kg/m3
-      REAL(wp) ::   zcdrag = 1.5e-3                 ! drag coefficient
-      REAL(wp) ::   zbbrau, zesh2                   ! temporary scalars
-      REAL(wp) ::   zfact1, zfact2, zfact3          !    -         -
-      REAL(wp) ::   ztx2  , zty2  , zcof            !    -         -
-      REAL(wp) ::   ztau  , zdif                    !    -         -
-      REAL(wp) ::   zus   , zwlc  , zind            !    -         -
-      REAL(wp) ::   zzd_up, zzd_lw                  !    -         -
-!!bfr      REAL(wp) ::   zebot                           !    -         -
-      INTEGER , POINTER, DIMENSION(:,:  ) ::   imlc
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::   zhlc
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zpelc, zdiag, zd_up, zd_lw, z3du, z3dv
-      REAL(wp)                            ::   zri  !   local Richardson number
+      USE zdf_oce , ONLY : en   ! ocean vertical physics
+      !!
+      REAL(wp), DIMENSION(:,:,:) , INTENT(in   ) ::   pdepw          ! depth of w-points
+      REAL(wp), DIMENSION(:,:,:) , INTENT(in   ) ::   p_e3t, p_e3w   ! level thickness (t- & w-points)
+      REAL(wp), DIMENSION(:,:,:) , INTENT(in   ) ::   p_sh2          ! shear production term
+      REAL(wp), DIMENSION(:,:,:) , INTENT(in   ) ::   p_avm, p_avt   ! vertical eddy viscosity & diffusivity (w-points)
+      !
+      INTEGER ::   ji, jj, jk              ! dummy loop arguments
+      REAL(wp) ::   zetop, zebot, zmsku, zmskv ! local scalars
+      REAL(wp) ::   zrhoa  = 1.22              ! Air density kg/m3
+      REAL(wp) ::   zcdrag = 1.5e-3            ! drag coefficient
+      REAL(wp) ::   zbbrau, zri                ! local scalars
+      REAL(wp) ::   zfact1, zfact2, zfact3     !   -         -
+      REAL(wp) ::   ztx2  , zty2  , zcof       !   -         -
+      REAL(wp) ::   ztau  , zdif               !   -         -
+      REAL(wp) ::   zus   , zwlc  , zind       !   -         -
+      REAL(wp) ::   zzd_up, zzd_lw             !   -         -
+      INTEGER , DIMENSION(jpi,jpj)     ::   imlc
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zhlc
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zpelc, zdiag, zd_up, zd_lw
       !!--------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('tke_tke')
-      !
-      CALL wrk_alloc( jpi,jpj,       imlc )    ! integer
-      CALL wrk_alloc( jpi,jpj,       zhlc ) 
-      CALL wrk_alloc( jpi,jpj,jpk,   zpelc, zdiag, zd_up, zd_lw, z3du, z3dv ) 
+      IF( ln_timing )   CALL timing_start('tke_tke')
       !
       zbbrau = rn_ebb / rau0       ! Local constant initialisation
@@ -248,8 +213,13 @@
       zfact3 = 0.5_wp       * rn_ediss
       !
-      !
-      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      !                     !  Surface boundary condition on tke
-      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !                     !  Surface/top/bottom boundary condition on tke
+      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      
+      DO jj = 2, jpjm1            ! en(1)   = rn_ebb taum / rau0  (min value rn_emin0)
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            en(ji,jj,1) = MAX( rn_emin0, zbbrau * taum(ji,jj) ) * tmask(ji,jj,1)
+         END DO
+      END DO
       IF ( ln_isfcav ) THEN
          DO jj = 2, jpjm1            ! en(mikt(ji,jj))   = rn_emin
@@ -258,42 +228,49 @@
             END DO
          END DO
-      END IF
-      DO jj = 2, jpjm1            ! en(1)   = rn_ebb taum / rau0  (min value rn_emin0)
-         DO ji = fs_2, fs_jpim1   ! vector opt.
-            en(ji,jj,1) = MAX( rn_emin0, zbbrau * taum(ji,jj) ) * tmask(ji,jj,1)
-         END DO
-      END DO
-      
-!!bfr   - start commented area
+      ENDIF
+      !
       !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       !                     !  Bottom boundary condition on tke
       !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       !
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      ! Tests to date have found the bottom boundary condition on tke to have very little effect.
-      ! The condition is coded here for completion but commented out until there is proof that the
-      ! computational cost is justified
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      !                     en(bot)   = (rn_ebb0/rau0)*0.5*sqrt(u_botfr^2+v_botfr^2) (min value rn_emin)
-!!    DO jj = 2, jpjm1
-!!       DO ji = fs_2, fs_jpim1   ! vector opt.
-!!          ztx2 = bfrua(ji-1,jj) * ub(ji-1,jj,mbku(ji-1,jj)) + &
-!!                 bfrua(ji  ,jj) * ub(ji  ,jj,mbku(ji  ,jj) )
-!!          zty2 = bfrva(ji,jj  ) * vb(ji,jj  ,mbkv(ji,jj  )) + &
-!!                 bfrva(ji,jj-1) * vb(ji,jj-1,mbkv(ji,jj-1) )
-!!          zebot = 0.001875_wp * SQRT( ztx2 * ztx2 + zty2 * zty2 )   !  where 0.001875 = (rn_ebb0/rau0) * 0.5 = 3.75*0.5/1000.
-!!          en (ji,jj,mbkt(ji,jj)+1) = MAX( zebot, rn_emin ) * tmask(ji,jj,1)
-!!       END DO
-!!    END DO
-!!bfr   - end commented area
-      !
-      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( ln_lc ) THEN      !  Langmuir circulation source term added to tke       (Axell JGR 2002)
+      !   en(bot)   = (ebb0/rau0)*0.5*sqrt(u_botfr^2+v_botfr^2) (min value rn_emin)
+      ! where ebb0 does not includes surface wave enhancement (i.e. ebb0=3.75)
+      ! Note that stress averaged is done using an wet-only calculation of u and v at t-point like in zdfsh2
+      !
+      IF( ln_drg ) THEN       !== friction used as top/bottom boundary condition on TKE
+         !
+         DO jj = 2, jpjm1           ! bottom friction
+            DO ji = fs_2, fs_jpim1     ! vector opt.
+               zmsku = ( 2. - umask(ji-1,jj,mbkt(ji,jj)) * umask(ji,jj,mbkt(ji,jj)) )
+               zmskv = ( 2. - vmask(ji,jj-1,mbkt(ji,jj)) * vmask(ji,jj,mbkt(ji,jj)) )
+               !                       ! where 0.001875 = (rn_ebb0/rau0) * 0.5 = 3.75*0.5/1000. (CAUTION CdU<0)
+               zebot = - 0.001875_wp * rCdU_bot(ji,jj) * SQRT(  ( zmsku*( ub(ji,jj,mbkt(ji,jj))+ub(ji-1,jj,mbkt(ji,jj)) ) )**2  &
+                  &                                           + ( zmskv*( vb(ji,jj,mbkt(ji,jj))+vb(ji,jj-1,mbkt(ji,jj)) ) )**2  )
+               en(ji,jj,mbkt(ji,jj)+1) = MAX( zebot, rn_emin ) * ssmask(ji,jj)
+            END DO
+         END DO
+         IF( ln_isfcav ) THEN       ! top friction
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zmsku = ( 2. - umask(ji-1,jj,mikt(ji,jj)) * umask(ji,jj,mikt(ji,jj)) )
+                  zmskv = ( 2. - vmask(ji,jj-1,mikt(ji,jj)) * vmask(ji,jj,mikt(ji,jj)) )
+                  !                             ! where 0.001875 = (rn_ebb0/rau0) * 0.5 = 3.75*0.5/1000.  (CAUTION CdU<0)
+                  zetop = - 0.001875_wp * rCdU_top(ji,jj) * SQRT(  ( zmsku*( ub(ji,jj,mikt(ji,jj))+ub(ji-1,jj,mikt(ji,jj)) ) )**2  &
+                     &                                           + ( zmskv*( vb(ji,jj,mikt(ji,jj))+vb(ji,jj-1,mikt(ji,jj)) ) )**2  )
+                  en(ji,jj,mikt(ji,jj)) = MAX( zetop, rn_emin ) * (1._wp - tmask(ji,jj,1))   ! masked at ocean surface
+               END DO
+            END DO
+         ENDIF
+         !
+      ENDIF
+      !
+      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      IF( ln_lc ) THEN      !  Langmuir circulation source term added to tke   !   (Axell JGR 2002)
          !                  !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
          !
          !                        !* total energy produce by LC : cumulative sum over jk
-         zpelc(:,:,1) =  MAX( rn2b(:,:,1), 0._wp ) * gdepw_n(:,:,1) * e3w_n(:,:,1)
+         zpelc(:,:,1) =  MAX( rn2b(:,:,1), 0._wp ) * pdepw(:,:,1) * p_e3w(:,:,1)
          DO jk = 2, jpk
-            zpelc(:,:,jk)  = zpelc(:,:,jk-1) + MAX( rn2b(:,:,jk), 0._wp ) * gdepw_n(:,:,jk) * e3w_n(:,:,jk)
+            zpelc(:,:,jk)  = zpelc(:,:,jk-1) + MAX( rn2b(:,:,jk), 0._wp ) * pdepw(:,:,jk) * p_e3w(:,:,jk)
          END DO
          !                        !* finite Langmuir Circulation depth
@@ -311,5 +288,5 @@
          DO jj = 1, jpj 
             DO ji = 1, jpi
-               zhlc(ji,jj) = gdepw_n(ji,jj,imlc(ji,jj))
+               zhlc(ji,jj) = pdepw(ji,jj,imlc(ji,jj))
             END DO
          END DO
@@ -320,8 +297,8 @@
                   zus  = zcof * SQRT( taum(ji,jj) )           ! Stokes drift
                   !                                           ! vertical velocity due to LC
-                  zind = 0.5 - SIGN( 0.5, gdepw_n(ji,jj,jk) - zhlc(ji,jj) )
-                  zwlc = zind * rn_lc * zus * SIN( rpi * gdepw_n(ji,jj,jk) / zhlc(ji,jj) )
+                  zind = 0.5 - SIGN( 0.5, pdepw(ji,jj,jk) - zhlc(ji,jj) )
+                  zwlc = zind * rn_lc * zus * SIN( rpi * pdepw(ji,jj,jk) / zhlc(ji,jj) )
                   !                                           ! TKE Langmuir circulation source term
-                  en(ji,jj,jk) = en(ji,jj,jk) + rdt * MAX(0.,1._wp - 2.*fr_i(ji,jj) ) * ( zwlc * zwlc * zwlc )   &
+                  en(ji,jj,jk) = en(ji,jj,jk) + rdt * MAX(0.,1._wp - 4.*fr_i(ji,jj) ) * ( zwlc * zwlc * zwlc )   &
                      &                              / zhlc(ji,jj) * wmask(ji,jj,jk) * tmask(ji,jj,1)
                END DO
@@ -338,36 +315,15 @@
       !                     ! zdiag : diagonal zd_up : upper diagonal zd_lw : lower diagonal
       !
-      DO jk = 2, jpkm1           !* Shear production at uw- and vw-points (energy conserving form)
-         DO jj = 1, jpjm1
-            DO ji = 1, fs_jpim1   ! vector opt.
-               z3du(ji,jj,jk) = 0.5 * ( avm(ji,jj,jk  ) + avm(ji+1,jj,jk) )   &
-                  &                 * (  un(ji,jj,jk-1) -  un(ji  ,jj,jk) )   &
-                  &                 * (  ub(ji,jj,jk-1) -  ub(ji  ,jj,jk) ) * wumask(ji,jj,jk) &
-                  &                 / (  e3uw_n(ji,jj,jk) * e3uw_b(ji,jj,jk) )
-               z3dv(ji,jj,jk) = 0.5 * ( avm(ji,jj,jk  ) + avm(ji,jj+1,jk) )   &
-                  &                 * (  vn(ji,jj,jk-1) -  vn(ji,jj  ,jk) )   &
-                  &                 * (  vb(ji,jj,jk-1) -  vb(ji,jj  ,jk) ) * wvmask(ji,jj,jk) &
-                  &                 / (  e3vw_n(ji,jj,jk) * e3vw_b(ji,jj,jk) )
-            END DO
-         END DO
-      END DO
-      !
-      IF( nn_pdl == 1 ) THEN      !* Prandtl number case: compute apdlr
-         ! Note that zesh2 is also computed in the next loop.
-         ! We decided to compute it twice to keep code readability and avoid an IF case in the DO loops
+      IF( nn_pdl == 1 ) THEN      !* Prandtl number = F( Ri )
          DO jk = 2, jpkm1
             DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  !                                          ! shear prod. at w-point weightened by mask
-                  zesh2  =  ( z3du(ji-1,jj,jk) + z3du(ji,jj,jk) ) / MAX( 1._wp , umask(ji-1,jj,jk) + umask(ji,jj,jk) )   &
-                     &    + ( z3dv(ji,jj-1,jk) + z3dv(ji,jj,jk) ) / MAX( 1._wp , vmask(ji,jj-1,jk) + vmask(ji,jj,jk) )    
-                  !                                          ! local Richardson number
-                  zri   = MAX( rn2b(ji,jj,jk), 0._wp ) * avm(ji,jj,jk) / ( zesh2 + rn_bshear )
+               DO ji = 2, jpim1
+                  !                             ! local Richardson number
+                  zri = MAX( rn2b(ji,jj,jk), 0._wp ) * p_avm(ji,jj,jk) / ( p_sh2(ji,jj,jk) + rn_bshear )
+                  !                             ! inverse of Prandtl number
                   apdlr(ji,jj,jk) = MAX(  0.1_wp,  ri_cri / MAX( ri_cri , zri )  )
-                  
-               END DO
-            END DO
-         END DO
-         !
+               END DO
+            END DO
+         END DO
       ENDIF
       !         
@@ -376,28 +332,20 @@
             DO ji = fs_2, fs_jpim1   ! vector opt.
                zcof   = zfact1 * tmask(ji,jj,jk)
-# if defined key_zdftmx_new
-               ! key_zdftmx_new: New internal wave-driven param: set a minimum value for Kz on TKE (ensure numerical stability)
-               zzd_up = zcof * MAX( avm(ji,jj,jk+1) + avm(ji,jj,jk), 2.e-5_wp )   &  ! upper diagonal
-                  &          / (  e3t_n(ji,jj,jk  ) * e3w_n(ji,jj,jk  )  )
-               zzd_lw = zcof * MAX( avm(ji,jj,jk) + avm(ji,jj,jk-1), 2.e-5_wp )   &  ! lower diagonal
-                  &          / (  e3t_n(ji,jj,jk-1) * e3w_n(ji,jj,jk  )  )
-# else
-               zzd_up = zcof * ( avm  (ji,jj,jk+1) + avm  (ji,jj,jk  ) )   &  ! upper diagonal
-                  &          / ( e3t_n(ji,jj,jk  ) * e3w_n(ji,jj,jk  ) )
-               zzd_lw = zcof * ( avm  (ji,jj,jk  ) + avm  (ji,jj,jk-1) )   &  ! lower diagonal
-                  &          / ( e3t_n(ji,jj,jk-1) * e3w_n(ji,jj,jk  ) )
-# endif
-               !                                   ! shear prod. at w-point weightened by mask
-               zesh2  =  ( z3du(ji-1,jj,jk) + z3du(ji,jj,jk) ) / MAX( 1._wp , umask(ji-1,jj,jk) + umask(ji,jj,jk) )   &
-                  &    + ( z3dv(ji,jj-1,jk) + z3dv(ji,jj,jk) ) / MAX( 1._wp , vmask(ji,jj-1,jk) + vmask(ji,jj,jk) )    
+               !                                   ! A minimum of 2.e-5 m2/s is imposed on TKE vertical
+               !                                   ! eddy coefficient (ensure numerical stability)
+               zzd_up = zcof * MAX(  p_avm(ji,jj,jk+1) + p_avm(ji,jj,jk  ) , 2.e-5_wp  )   &  ! upper diagonal
+                  &          /    (  p_e3t(ji,jj,jk  ) * p_e3w(ji,jj,jk  )  )
+               zzd_lw = zcof * MAX(  p_avm(ji,jj,jk  ) + p_avm(ji,jj,jk-1) , 2.e-5_wp  )   &  ! lower diagonal
+                  &          /    (  p_e3t(ji,jj,jk-1) * p_e3w(ji,jj,jk  )  )
                !
                zd_up(ji,jj,jk) = zzd_up            ! Matrix (zdiag, zd_up, zd_lw)
                zd_lw(ji,jj,jk) = zzd_lw
-               zdiag(ji,jj,jk) = 1._wp - zzd_lw - zzd_up + zfact2 * dissl(ji,jj,jk) * tmask(ji,jj,jk)
+               zdiag(ji,jj,jk) = 1._wp - zzd_lw - zzd_up + zfact2 * dissl(ji,jj,jk) * wmask(ji,jj,jk)
                !
                !                                   ! right hand side in en
-               en(ji,jj,jk) = en(ji,jj,jk) + rdt * (  zesh2  -   avt(ji,jj,jk) * rn2(ji,jj,jk)    &
-                  &                                 + zfact3 * dissl(ji,jj,jk) * en (ji,jj,jk)  ) &
-                  &                                 * wmask(ji,jj,jk)
+               en(ji,jj,jk) = en(ji,jj,jk) + rdt * (  p_sh2(ji,jj,jk)                          &   ! shear
+                  &                                 - p_avt(ji,jj,jk) * rn2(ji,jj,jk)          &   ! stratification
+                  &                                 + zfact3 * dissl(ji,jj,jk) * en(ji,jj,jk)  &   ! dissipation
+                  &                                ) * wmask(ji,jj,jk)
             END DO
          END DO
@@ -442,9 +390,10 @@
          END DO
       END DO
-
+      !
       !                            !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       !                            !  TKE due to surface and internal wave breaking
       !                            !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 !!gm BUG : in the exp  remove the depth of ssh !!!
+!!gm       i.e. use gde3w in argument (pdepw)
       
       
@@ -453,6 +402,6 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  en(ji,jj,jk) = en(ji,jj,jk) + rn_efr * en(ji,jj,1) * EXP( -gdepw_n(ji,jj,jk) / htau(ji,jj) )   &
-                     &                                 * MAX(0.,1._wp - 2.*fr_i(ji,jj) )  * wmask(ji,jj,jk) * tmask(ji,jj,1)
+                  en(ji,jj,jk) = en(ji,jj,jk) + rn_efr * en(ji,jj,1) * EXP( -pdepw(ji,jj,jk) / htau(ji,jj) )   &
+                     &                                 * MAX(0.,1._wp - 4.*fr_i(ji,jj) )  * wmask(ji,jj,jk) * tmask(ji,jj,1)
                END DO
             END DO
@@ -462,6 +411,6 @@
             DO ji = fs_2, fs_jpim1   ! vector opt.
                jk = nmln(ji,jj)
-               en(ji,jj,jk) = en(ji,jj,jk) + rn_efr * en(ji,jj,1) * EXP( -gdepw_n(ji,jj,jk) / htau(ji,jj) )   &
-                  &                                 * MAX(0.,1._wp - 2.*fr_i(ji,jj) )  * wmask(ji,jj,jk) * tmask(ji,jj,1)
+               en(ji,jj,jk) = en(ji,jj,jk) + rn_efr * en(ji,jj,1) * EXP( -pdepw(ji,jj,jk) / htau(ji,jj) )   &
+                  &                                 * MAX(0.,1._wp - 4.*fr_i(ji,jj) )  * wmask(ji,jj,jk) * tmask(ji,jj,1)
             END DO
          END DO
@@ -475,22 +424,17 @@
                   zdif = taum(ji,jj) - ztau                            ! mean of modulus - modulus of the mean 
                   zdif = rhftau_scl * MAX( 0._wp, zdif + rhftau_add )  ! apply some modifications...
-                  en(ji,jj,jk) = en(ji,jj,jk) + zbbrau * zdif * EXP( -gdepw_n(ji,jj,jk) / htau(ji,jj) )   &
-                     &                        * MAX(0.,1._wp - 2.*fr_i(ji,jj) ) * wmask(ji,jj,jk) * tmask(ji,jj,1)
-               END DO
-            END DO
-         END DO
-      ENDIF
-      CALL lbc_lnk( en, 'W', 1. )      ! Lateral boundary conditions (sign unchanged)
-      !
-      CALL wrk_dealloc( jpi,jpj,       imlc )    ! integer
-      CALL wrk_dealloc( jpi,jpj,       zhlc ) 
-      CALL wrk_dealloc( jpi,jpj,jpk,   zpelc, zdiag, zd_up, zd_lw, z3du, z3dv ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tke_tke')
+                  en(ji,jj,jk) = en(ji,jj,jk) + zbbrau * zdif * EXP( -pdepw(ji,jj,jk) / htau(ji,jj) )   &
+                     &                        * MAX(0.,1._wp - 4.*fr_i(ji,jj) ) * wmask(ji,jj,jk) * tmask(ji,jj,1)
+               END DO
+            END DO
+         END DO
+      ENDIF
+      !
+      IF( ln_timing )   CALL timing_stop('tke_tke')
       !
    END SUBROUTINE tke_tke
 
 
-   SUBROUTINE tke_avn
+   SUBROUTINE tke_avn( pdepw, p_e3t, p_e3w, p_avm, p_avt )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE tke_avn  ***
@@ -524,18 +468,21 @@
       !!      with pdlr=1 if nn_pdl=0, pdlr=1/pdl=F(Ri) otherwise.
       !!
-      !! ** Action  : - avt : now vertical eddy diffusivity (w-point)
-      !!              - avmu, avmv : now vertical eddy viscosity at uw- and vw-points
-      !!----------------------------------------------------------------------
+      !! ** Action  : - avt, avm : now vertical eddy diffusivity and viscosity (w-point)
+      !!----------------------------------------------------------------------
+      USE zdf_oce , ONLY : en, avtb, avmb, avtb_2d   ! ocean vertical physics
+      !!
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pdepw          ! depth (w-points)
+      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   p_e3t, p_e3w   ! level thickness (t- & w-points)
+      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   p_avm, p_avt   ! vertical eddy viscosity & diffusivity (w-points)
+      !
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zrn2, zraug, zcoef, zav     ! local scalars
-      REAL(wp) ::   zdku, zri, zsqen            !   -      -
-      REAL(wp) ::   zdkv, zemxl, zemlm, zemlp   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zmpdl, zmxlm, zmxld
+      REAL(wp) ::   zrn2, zraug, zcoef, zav   ! local scalars
+      REAL(wp) ::   zdku,   zdkv, zsqen       !   -      -
+      REAL(wp) ::   zemxl, zemlm, zemlp       !   -      -
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zmxlm, zmxld   ! 3D workspace
       !!--------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('tke_avn')
-
-      CALL wrk_alloc( jpi,jpj,jpk, zmpdl, zmxlm, zmxld ) 
-
+      IF( ln_timing )   CALL timing_start('tke_avn')
+      !
       !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       !                     !  Mixing length
@@ -549,7 +496,7 @@
       !
       IF( ln_mxl0 ) THEN            ! surface mixing length = F(stress) : l=vkarmn*2.e5*taum/(rau0*g)
+         zraug = vkarmn * 2.e5_wp / ( rau0 * grav )
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1
-               zraug = vkarmn * 2.e5_wp / ( rau0 * grav )
                zmxlm(ji,jj,1) = MAX( rn_mxl0, zraug * taum(ji,jj) * tmask(ji,jj,1) )
             END DO
@@ -576,14 +523,14 @@
       !
  !!gm Not sure of that coding for ISF....
-      ! where wmask = 0 set zmxlm == e3w_n
+      ! where wmask = 0 set zmxlm == p_e3w
       CASE ( 0 )           ! bounded by the distance to surface and bottom
          DO jk = 2, jpkm1
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zemxl = MIN( gdepw_n(ji,jj,jk) - gdepw_n(ji,jj,mikt(ji,jj)), zmxlm(ji,jj,jk),   &
-                  &            gdepw_n(ji,jj,mbkt(ji,jj)+1) - gdepw_n(ji,jj,jk) )
+                  zemxl = MIN( pdepw(ji,jj,jk) - pdepw(ji,jj,mikt(ji,jj)), zmxlm(ji,jj,jk),   &
+                  &            pdepw(ji,jj,mbkt(ji,jj)+1) - pdepw(ji,jj,jk) )
                   ! wmask prevent zmxlm = 0 if jk = mikt(ji,jj)
-                  zmxlm(ji,jj,jk) = zemxl * wmask(ji,jj,jk) + MIN(zmxlm(ji,jj,jk),e3w_n(ji,jj,jk)) * (1 - wmask(ji,jj,jk))
-                  zmxld(ji,jj,jk) = zemxl * wmask(ji,jj,jk) + MIN(zmxlm(ji,jj,jk),e3w_n(ji,jj,jk)) * (1 - wmask(ji,jj,jk))
+                  zmxlm(ji,jj,jk) = zemxl * wmask(ji,jj,jk) + MIN( zmxlm(ji,jj,jk) , p_e3w(ji,jj,jk) ) * (1 - wmask(ji,jj,jk))
+                  zmxld(ji,jj,jk) = zemxl * wmask(ji,jj,jk) + MIN( zmxlm(ji,jj,jk) , p_e3w(ji,jj,jk) ) * (1 - wmask(ji,jj,jk))
                END DO
             END DO
@@ -594,5 +541,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zemxl = MIN( e3w_n(ji,jj,jk), zmxlm(ji,jj,jk) )
+                  zemxl = MIN( p_e3w(ji,jj,jk), zmxlm(ji,jj,jk) )
                   zmxlm(ji,jj,jk) = zemxl
                   zmxld(ji,jj,jk) = zemxl
@@ -605,5 +552,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zmxlm(ji,jj,jk) = MIN( zmxlm(ji,jj,jk-1) + e3t_n(ji,jj,jk-1), zmxlm(ji,jj,jk) )
+                  zmxlm(ji,jj,jk) = MIN( zmxlm(ji,jj,jk-1) + p_e3t(ji,jj,jk-1), zmxlm(ji,jj,jk) )
                END DO
             END DO
@@ -612,5 +559,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zemxl = MIN( zmxlm(ji,jj,jk+1) + e3t_n(ji,jj,jk+1), zmxlm(ji,jj,jk) )
+                  zemxl = MIN( zmxlm(ji,jj,jk+1) + p_e3t(ji,jj,jk+1), zmxlm(ji,jj,jk) )
                   zmxlm(ji,jj,jk) = zemxl
                   zmxld(ji,jj,jk) = zemxl
@@ -623,5 +570,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zmxld(ji,jj,jk) = MIN( zmxld(ji,jj,jk-1) + e3t_n(ji,jj,jk-1), zmxlm(ji,jj,jk) )
+                  zmxld(ji,jj,jk) = MIN( zmxld(ji,jj,jk-1) + p_e3t(ji,jj,jk-1), zmxlm(ji,jj,jk) )
                END DO
             END DO
@@ -630,5 +577,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zmxlm(ji,jj,jk) = MIN( zmxlm(ji,jj,jk+1) + e3t_n(ji,jj,jk+1), zmxlm(ji,jj,jk) )
+                  zmxlm(ji,jj,jk) = MIN( zmxlm(ji,jj,jk+1) + p_e3t(ji,jj,jk+1), zmxlm(ji,jj,jk) )
                END DO
             END DO
@@ -647,11 +594,6 @@
       END SELECT
       !
-# if defined key_c1d
-      e_dis(:,:,:) = zmxld(:,:,:)      ! c1d configuration : save mixing and dissipation turbulent length scales
-      e_mix(:,:,:) = zmxlm(:,:,:)
-# endif
-
-      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      !                     !  Vertical eddy viscosity and diffusivity  (avmu, avmv, avt)
+      !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !                     !  Vertical eddy viscosity and diffusivity  (avm and avt)
       !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       DO jk = 1, jpkm1            !* vertical eddy viscosity & diffivity at w-points
@@ -660,21 +602,11 @@
                zsqen = SQRT( en(ji,jj,jk) )
                zav   = rn_ediff * zmxlm(ji,jj,jk) * zsqen
-               avm  (ji,jj,jk) = MAX( zav,                  avmb(jk) ) * wmask(ji,jj,jk)
-               avt  (ji,jj,jk) = MAX( zav, avtb_2d(ji,jj) * avtb(jk) ) * wmask(ji,jj,jk)
+               p_avm(ji,jj,jk) = MAX( zav,                  avmb(jk) ) * wmask(ji,jj,jk)
+               p_avt(ji,jj,jk) = MAX( zav, avtb_2d(ji,jj) * avtb(jk) ) * wmask(ji,jj,jk)
                dissl(ji,jj,jk) = zsqen / zmxld(ji,jj,jk)
             END DO
          END DO
       END DO
-      CALL lbc_lnk( avm, 'W', 1. )      ! Lateral boundary conditions (sign unchanged)
-      !
-      DO jk = 2, jpkm1            !* vertical eddy viscosity at wu- and wv-points
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               avmu(ji,jj,jk) = 0.5 * ( avm(ji,jj,jk) + avm(ji+1,jj  ,jk) ) * wumask(ji,jj,jk)
-               avmv(ji,jj,jk) = 0.5 * ( avm(ji,jj,jk) + avm(ji  ,jj+1,jk) ) * wvmask(ji,jj,jk)
-            END DO
-         END DO
-      END DO
-      CALL lbc_lnk( avmu, 'U', 1. )   ;   CALL lbc_lnk( avmv, 'V', 1. )      ! Lateral boundary conditions
+      !
       !
       IF( nn_pdl == 1 ) THEN      !* Prandtl number case: update avt
@@ -682,26 +614,16 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  avt(ji,jj,jk)   = MAX( apdlr(ji,jj,jk) * avt(ji,jj,jk), avtb_2d(ji,jj) * avtb(jk) ) * tmask(ji,jj,jk)
-# if defined key_c1d
-                  e_pdl(ji,jj,jk) = apdlr(ji,jj,jk) * wmask(ji,jj,jk)    ! c1d configuration : save masked Prandlt number
-!!gm bug NO zri here....
-!!gm remove the specific diag for c1d !
-                  e_ric(ji,jj,jk) = zri * wmask(ji,jj,jk)                            ! c1d config. : save Ri
-# endif
+                  p_avt(ji,jj,jk)   = MAX( apdlr(ji,jj,jk) * p_avt(ji,jj,jk), avtb_2d(ji,jj) * avtb(jk) ) * tmask(ji,jj,jk)
               END DO
             END DO
          END DO
       ENDIF
-      CALL lbc_lnk( avt, 'W', 1. )                      ! Lateral boundary conditions on avt  (sign unchanged)
-
+      !
       IF(ln_ctl) THEN
-         CALL prt_ctl( tab3d_1=en  , clinfo1=' tke  - e: ', tab3d_2=avt, clinfo2=' t: ', ovlap=1, kdim=jpk)
-         CALL prt_ctl( tab3d_1=avmu, clinfo1=' tke  - u: ', mask1=umask,                   &
-            &          tab3d_2=avmv, clinfo2=       ' v: ', mask2=vmask, ovlap=1, kdim=jpk )
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi,jpj,jpk, zmpdl, zmxlm, zmxld ) 
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tke_avn')
+         CALL prt_ctl( tab3d_1=en   , clinfo1=' tke  - e: ', tab3d_2=p_avt, clinfo2=' t: ', ovlap=1, kdim=jpk)
+         CALL prt_ctl( tab3d_1=p_avm, clinfo1=' tke  - m: ', ovlap=1, kdim=jpk )
+      ENDIF
+      !
+      IF( ln_timing )   CALL timing_stop('tke_avn')
       !
    END SUBROUTINE tke_avn
@@ -722,10 +644,12 @@
       !! ** Action  :   Increase by 1 the nstop flag is setting problem encounter
       !!----------------------------------------------------------------------
+      USE zdf_oce , ONLY : ln_zdfiwm   ! Internal Wave Mixing flag
+      !!
       INTEGER ::   ji, jj, jk   ! dummy loop indices
       INTEGER ::   ios
       !!
-      NAMELIST/namzdf_tke/ rn_ediff, rn_ediss , rn_ebb , rn_emin  ,   &
-         &                 rn_emin0, rn_bshear, nn_mxl , ln_mxl0  ,   &
-         &                 rn_mxl0 , nn_pdl   , ln_lc  , rn_lc    ,   &
+      NAMELIST/namzdf_tke/ rn_ediff, rn_ediss , rn_ebb , rn_emin  ,          &
+         &                 rn_emin0, rn_bshear, nn_mxl , ln_mxl0  ,          &
+         &                 rn_mxl0 , nn_pdl   , ln_drg , ln_lc    , rn_lc,   &
          &                 nn_etau , nn_htau  , rn_efr   
       !!----------------------------------------------------------------------
@@ -741,16 +665,4 @@
       !
       ri_cri   = 2._wp    / ( 2._wp + rn_ediss / rn_ediff )   ! resulting critical Richardson number
-# if defined key_zdftmx_new
-      ! key_zdftmx_new: New internal wave-driven param: specified value of rn_emin & rmxl_min are used
-      rn_emin  = 1.e-10_wp
-      rmxl_min = 1.e-03_wp
-      IF(lwp) THEN                  ! Control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'zdf_tke_init :  New tidal mixing case: force rn_emin = 1.e-10 and rmxl_min = 1.e-3 '
-         WRITE(numout,*) '~~~~~~~~~~~~'
-      ENDIF
-# else
-      rmxl_min = 1.e-6_wp / ( rn_ediff * SQRT( rn_emin ) )    ! resulting minimum length to recover molecular viscosity
-# endif
       !
       IF(lwp) THEN                    !* Control print
@@ -764,16 +676,34 @@
          WRITE(numout,*) '      minimum value of tke                        rn_emin   = ', rn_emin
          WRITE(numout,*) '      surface minimum value of tke                rn_emin0  = ', rn_emin0
+         WRITE(numout,*) '      prandl number flag                          nn_pdl    = ', nn_pdl
          WRITE(numout,*) '      background shear (>0)                       rn_bshear = ', rn_bshear
          WRITE(numout,*) '      mixing length type                          nn_mxl    = ', nn_mxl
-         WRITE(numout,*) '      prandl number flag                          nn_pdl    = ', nn_pdl
-         WRITE(numout,*) '      surface mixing length = F(stress) or not    ln_mxl0   = ', ln_mxl0
-         WRITE(numout,*) '      surface  mixing length minimum value        rn_mxl0   = ', rn_mxl0
-         WRITE(numout,*) '      flag to take into acc.  Langmuir circ.      ln_lc     = ', ln_lc
-         WRITE(numout,*) '      coef to compute verticla velocity of LC     rn_lc     = ', rn_lc
+         WRITE(numout,*) '         surface mixing length = F(stress) or not    ln_mxl0   = ', ln_mxl0
+         WRITE(numout,*) '         surface  mixing length minimum value        rn_mxl0   = ', rn_mxl0
+         WRITE(numout,*) '      top/bottom friction forcing flag            ln_drg    = ', ln_drg
+         WRITE(numout,*) '      Langmuir cells parametrization              ln_lc     = ', ln_lc
+         WRITE(numout,*) '         coef to compute vertical velocity of LC     rn_lc  = ', rn_lc
          WRITE(numout,*) '      test param. to add tke induced by wind      nn_etau   = ', nn_etau
-         WRITE(numout,*) '      flag for computation of exp. tke profile    nn_htau   = ', nn_htau
-         WRITE(numout,*) '      fraction of en which pene. the thermocline  rn_efr    = ', rn_efr
+         WRITE(numout,*) '          type of tke penetration profile            nn_htau   = ', nn_htau
+         WRITE(numout,*) '          fraction of TKE that penetrates            rn_efr    = ', rn_efr
          WRITE(numout,*)
-         WRITE(numout,*) '      critical Richardson nb with your parameters  ri_cri = ', ri_cri
+         IF( ln_drg ) THEN
+            WRITE(numout,*) '   Namelist namdrg_top/_bot:   used values:'
+            WRITE(numout,*) '      top    ocean cavity roughness (m)          rn_z0(_top)= ', r_z0_top
+            WRITE(numout,*) '      Bottom seafloor     roughness (m)          rn_z0(_bot)= ', r_z0_bot
+         ENDIF
+         WRITE(numout,*)
+         WRITE(numout,*)
+         WRITE(numout,*) '   ==>> critical Richardson nb with your parameters  ri_cri = ', ri_cri
+         WRITE(numout,*)
+      ENDIF
+      !
+      IF( ln_zdfiwm ) THEN          ! Internal wave-driven mixing
+         rn_emin  = 1.e-10_wp             ! specific values of rn_emin & rmxl_min are used
+         rmxl_min = 1.e-03_wp             ! associated avt minimum = molecular salt diffusivity (10^-9 m2/s)
+         IF(lwp) WRITE(numout,*) '      Internal wave-driven mixing case:   force   rn_emin = 1.e-10 and rmxl_min = 1.e-3 '
+      ELSE                          ! standard case : associated avt minimum = molecular viscosity (10^-6 m2/s)
+         rmxl_min = 1.e-6_wp / ( rn_ediff * SQRT( rn_emin ) )    ! resulting minimum length to recover molecular viscosity
+         IF(lwp) WRITE(numout,*) '      minimum mixing length with your parameters rmxl_min = ', rmxl_min
       ENDIF
       !
@@ -786,5 +716,5 @@
       IF( nn_htau < 0   .OR.  nn_htau > 1 )   CALL ctl_stop( 'bad flag: nn_htau is 0, 1 or 2 ' )
       IF( nn_etau == 3 .AND. .NOT. ln_cpl )   CALL ctl_stop( 'nn_etau == 3 : HF taum only known in coupled mode' )
-
+      !
       IF( ln_mxl0 ) THEN
          IF(lwp) WRITE(numout,*) '   use a surface mixing length = F(stress) :   set rn_mxl0 = rmxl_min'
@@ -803,14 +733,6 @@
          END SELECT
       ENDIF
-      !                               !* set vertical eddy coef. to the background value
-      DO jk = 1, jpk
-         avt (:,:,jk) = avtb(jk) * wmask (:,:,jk)
-         avm (:,:,jk) = avmb(jk) * wmask (:,:,jk)
-         avmu(:,:,jk) = avmb(jk) * wumask(:,:,jk)
-         avmv(:,:,jk) = avmb(jk) * wvmask(:,:,jk)
-      END DO
-      dissl(:,:,:) = 1.e-12_wp
-      !                              
-      CALL tke_rst( nit000, 'READ' )  !* read or initialize all required files
+      !                                !* read or initialize all required files
+      CALL tke_rst( nit000, 'READ' )      ! (en, avt_k, avm_k, dissl) 
       !
    END SUBROUTINE zdf_tke_init
@@ -818,93 +740,59 @@
 
    SUBROUTINE tke_rst( kt, cdrw )
-     !!---------------------------------------------------------------------
-     !!                   ***  ROUTINE tke_rst  ***
-     !!                     
-     !! ** Purpose :   Read or write TKE file (en) in restart file
-     !!
-     !! ** Method  :   use of IOM library
-     !!                if the restart does not contain TKE, en is either 
-     !!                set to rn_emin or recomputed 
-     !!----------------------------------------------------------------------
-     INTEGER         , INTENT(in) ::   kt     ! ocean time-step
-     CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
-     !
-     INTEGER ::   jit, jk   ! dummy loop indices
-     INTEGER ::   id1, id2, id3, id4, id5, id6   ! local integers
-     !!----------------------------------------------------------------------
-     !
-     IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
-        !                                   ! ---------------
-        IF( ln_rstart ) THEN                   !* Read the restart file
-           id1 = iom_varid( numror, 'en'   , ldstop = .FALSE. )
-           id2 = iom_varid( numror, 'avt'  , ldstop = .FALSE. )
-           id3 = iom_varid( numror, 'avm'  , ldstop = .FALSE. )
-           id4 = iom_varid( numror, 'avmu' , ldstop = .FALSE. )
-           id5 = iom_varid( numror, 'avmv' , ldstop = .FALSE. )
-           id6 = iom_varid( numror, 'dissl', ldstop = .FALSE. )
-           !
-           IF( id1 > 0 ) THEN                       ! 'en' exists
-              CALL iom_get( numror, jpdom_autoglo, 'en', en )
-              IF( MIN( id2, id3, id4, id5, id6 ) > 0 ) THEN        ! all required arrays exist
-                 CALL iom_get( numror, jpdom_autoglo, 'avt'  , avt   )
-                 CALL iom_get( numror, jpdom_autoglo, 'avm'  , avm   )
-                 CALL iom_get( numror, jpdom_autoglo, 'avmu' , avmu  )
-                 CALL iom_get( numror, jpdom_autoglo, 'avmv' , avmv  )
-                 CALL iom_get( numror, jpdom_autoglo, 'dissl', dissl )
-              ELSE                                                 ! one at least array is missing
-                 CALL tke_avn                                          ! compute avt, avm, avmu, avmv and dissl (approximation)
-              ENDIF
-           ELSE                                     ! No TKE array found: initialisation
-              IF(lwp) WRITE(numout,*) ' ===>>>> : previous run without tke scheme, en computed by iterative loop'
-              en (:,:,:) = rn_emin * tmask(:,:,:)
-              CALL tke_avn                               ! recompute avt, avm, avmu, avmv and dissl (approximation)
-              !
-              avt_k (:,:,:) = avt (:,:,:)
-              avm_k (:,:,:) = avm (:,:,:)
-              avmu_k(:,:,:) = avmu(:,:,:)
-              avmv_k(:,:,:) = avmv(:,:,:)
-              !
-              DO jit = nit000 + 1, nit000 + 10   ;   CALL zdf_tke( jit )   ;   END DO
-           ENDIF
-        ELSE                                   !* Start from rest
-           en(:,:,:) = rn_emin * tmask(:,:,:)
-           DO jk = 1, jpk                           ! set the Kz to the background value
-              avt (:,:,jk) = avtb(jk) * wmask (:,:,jk)
-              avm (:,:,jk) = avmb(jk) * wmask (:,:,jk)
-              avmu(:,:,jk) = avmb(jk) * wumask(:,:,jk)
-              avmv(:,:,jk) = avmb(jk) * wvmask(:,:,jk)
-           END DO
-        ENDIF
-        !
-     ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
-        !                                   ! -------------------
-        IF(lwp) WRITE(numout,*) '---- tke-rst ----'
-        CALL iom_rstput( kt, nitrst, numrow, 'en'   , en     )
-        CALL iom_rstput( kt, nitrst, numrow, 'avt'  , avt_k  )
-        CALL iom_rstput( kt, nitrst, numrow, 'avm'  , avm_k  )
-        CALL iom_rstput( kt, nitrst, numrow, 'avmu' , avmu_k )
-        CALL iom_rstput( kt, nitrst, numrow, 'avmv' , avmv_k )
-        CALL iom_rstput( kt, nitrst, numrow, 'dissl', dissl  )
-        !
-     ENDIF
-     !
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE tke_rst  ***
+      !!                     
+      !! ** Purpose :   Read or write TKE file (en) in restart file
+      !!
+      !! ** Method  :   use of IOM library
+      !!                if the restart does not contain TKE, en is either 
+      !!                set to rn_emin or recomputed 
+      !!----------------------------------------------------------------------
+      USE zdf_oce , ONLY : en, avt_k, avm_k   ! ocean vertical physics
+      !!
+      INTEGER         , INTENT(in) ::   kt     ! ocean time-step
+      CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
+      !
+      INTEGER ::   jit, jk              ! dummy loop indices
+      INTEGER ::   id1, id2, id3, id4   ! local integers
+      !!----------------------------------------------------------------------
+      !
+      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
+         !                                   ! ---------------
+         IF( ln_rstart ) THEN                   !* Read the restart file
+            id1 = iom_varid( numror, 'en'   , ldstop = .FALSE. )
+            id2 = iom_varid( numror, 'avt_k', ldstop = .FALSE. )
+            id3 = iom_varid( numror, 'avm_k', ldstop = .FALSE. )
+            id4 = iom_varid( numror, 'dissl', ldstop = .FALSE. )
+            !
+            IF( MIN( id1, id2, id3, id4 ) > 0 ) THEN      ! fields exist
+               CALL iom_get( numror, jpdom_autoglo, 'en', en )
+               CALL iom_get( numror, jpdom_autoglo, 'avt_k', avt_k )
+               CALL iom_get( numror, jpdom_autoglo, 'avm_k', avm_k )
+               CALL iom_get( numror, jpdom_autoglo, 'dissl', dissl )
+            ELSE                                          ! start TKE from rest
+               IF(lwp) WRITE(numout,*) '   ==>>   previous run without TKE scheme, set en to background values'
+               en   (:,:,:) = rn_emin * wmask(:,:,:)
+               dissl(:,:,:) = 1.e-12_wp
+               ! avt_k, avm_k already set to the background value in zdf_phy_init
+            ENDIF
+         ELSE                                   !* Start from rest
+            IF(lwp) WRITE(numout,*) '   ==>>   start from rest: set en to the background value'
+            en   (:,:,:) = rn_emin * wmask(:,:,:)
+            dissl(:,:,:) = 1.e-12_wp
+            ! avt_k, avm_k already set to the background value in zdf_phy_init
+         ENDIF
+         !
+      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
+         !                                   ! -------------------
+         IF(lwp) WRITE(numout,*) '---- tke-rst ----'
+         CALL iom_rstput( kt, nitrst, numrow, 'en'   , en    )
+         CALL iom_rstput( kt, nitrst, numrow, 'avt_k', avt_k )
+         CALL iom_rstput( kt, nitrst, numrow, 'avm_k', avm_k )
+         CALL iom_rstput( kt, nitrst, numrow, 'dissl', dissl )
+         !
+      ENDIF
+      !
    END SUBROUTINE tke_rst
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Dummy module :                                        NO TKE scheme
-   !!----------------------------------------------------------------------
-   LOGICAL, PUBLIC, PARAMETER ::   lk_zdftke = .FALSE.   !: TKE flag
-CONTAINS
-   SUBROUTINE zdf_tke_init           ! Dummy routine
-   END SUBROUTINE zdf_tke_init
-   SUBROUTINE zdf_tke( kt )          ! Dummy routine
-      WRITE(*,*) 'zdf_tke: You should not have seen this print! error?', kt
-   END SUBROUTINE zdf_tke
-   SUBROUTINE tke_rst( kt, cdrw )
-     CHARACTER(len=*) ::   cdrw
-     WRITE(*,*) 'tke_rst: You should not have seen this print! error?', kt, cdwr
-   END SUBROUTINE tke_rst
-#endif
 
    !!======================================================================
Index: anches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftmx.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftmx.F90	(revision 9018)
+++ 	(revision )
@@ -1,1046 +1,0 @@
-MODULE zdftmx
-   !!========================================================================
-   !!                       ***  MODULE  zdftmx  ***
-   !! Ocean physics: vertical tidal mixing coefficient
-   !!========================================================================
-   !! History :  1.0  !  2004-04  (L. Bessieres, G. Madec)  Original code
-   !!             -   !  2006-08  (A. Koch-Larrouy) Indonesian strait
-   !!            3.3  !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
-   !!----------------------------------------------------------------------
-#if defined key_zdftmx
-   !!----------------------------------------------------------------------
-   !!   'key_zdftmx'                                  Tidal vertical mixing
-   !!----------------------------------------------------------------------
-   !!   zdf_tmx       : global     momentum & tracer Kz with tidal induced Kz
-   !!   tmx_itf       : Indonesian momentum & tracer Kz with tidal induced Kz 
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers variables
-   USE dom_oce        ! ocean space and time domain variables
-   USE zdf_oce        ! ocean vertical physics variables
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE eosbn2         ! ocean equation of state
-   USE phycst         ! physical constants
-   USE prtctl         ! Print control
-   USE in_out_manager ! I/O manager
-   USE iom            ! I/O Manager
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
-   USE timing         ! Timing
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   zdf_tmx         ! called in step module 
-   PUBLIC   zdf_tmx_init    ! called in opa module 
-   PUBLIC   zdf_tmx_alloc   ! called in nemogcm module
-
-   LOGICAL, PUBLIC, PARAMETER ::   lk_zdftmx = .TRUE.    !: tidal mixing flag
-
-   !                       !!* Namelist  namzdf_tmx : tidal mixing *
-   REAL(wp) ::  rn_htmx     ! vertical decay scale for turbulence (meters)
-   REAL(wp) ::  rn_n2min    ! threshold of the Brunt-Vaisala frequency (s-1)
-   REAL(wp) ::  rn_tfe      ! tidal dissipation efficiency (St Laurent et al. 2002)
-   REAL(wp) ::  rn_me       ! mixing efficiency (Osborn 1980)
-   LOGICAL  ::  ln_tmx_itf  ! Indonesian Through Flow (ITF): Koch-Larrouy et al. (2007) parameterization
-   REAL(wp) ::  rn_tfe_itf  ! ITF tidal dissipation efficiency (St Laurent et al. 2002)
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   en_tmx     ! energy available for tidal mixing (W/m2)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   mask_itf   ! mask to use over Indonesian area
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   az_tmx     ! coefficient used to evaluate the tidal induced Kz
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION zdf_tmx_alloc()
-      !!----------------------------------------------------------------------
-      !!                ***  FUNCTION zdf_tmx_alloc  ***
-      !!----------------------------------------------------------------------
-      ALLOCATE(en_tmx(jpi,jpj), mask_itf(jpi,jpj), az_tmx(jpi,jpj,jpk), STAT=zdf_tmx_alloc )
-      !
-      IF( lk_mpp             )   CALL mpp_sum ( zdf_tmx_alloc )
-      IF( zdf_tmx_alloc /= 0 )   CALL ctl_warn('zdf_tmx_alloc: failed to allocate arrays')
-   END FUNCTION zdf_tmx_alloc
-
-
-   SUBROUTINE zdf_tmx( kt )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE zdf_tmx  ***
-      !!                   
-      !! ** Purpose :   add to the vertical mixing coefficients the effect of
-      !!              tidal mixing (Simmons et al 2004).
-      !!
-      !! ** Method  : - tidal-induced vertical mixing is given by:
-      !!                  Kz_tides = az_tmx / max( rn_n2min, N^2 )
-      !!              where az_tmx is a coefficient that specified the 3D space 
-      !!              distribution of the faction of tidal energy taht is used
-      !!              for mixing. Its expression is set in zdf_tmx_init routine,
-      !!              following Simmons et al. 2004.
-      !!                NB: a specific bounding procedure is performed on av_tide
-      !!              so that the input tidal energy is actually almost used. The
-      !!              basic maximum value is 60 cm2/s, but values of 300 cm2/s 
-      !!              can be reached in area where bottom stratification is too 
-      !!              weak.
-      !!
-      !!              - update av_tide in the Indonesian Through Flow area
-      !!              following Koch-Larrouy et al. (2007) parameterisation
-      !!              (see tmx_itf routine).
-      !!
-      !!              - update the model vertical eddy viscosity and diffusivity: 
-      !!                     avt  = avt  +    av_tides
-      !!                     avm  = avm  +    av_tides
-      !!                     avmu = avmu + mi(av_tides)
-      !!                     avmv = avmv + mj(av_tides)
-      !!
-      !! ** Action  :   avt, avm, avmu, avmv   increased by tidal mixing
-      !!
-      !! References : Simmons et al. 2004, Ocean Modelling, 6, 3-4, 245-263.
-      !!              Koch-Larrouy et al. 2007, GRL.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step 
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   ztpc         ! scalar workspace
-      REAL(wp), POINTER, DIMENSION(:,:)   ::   zkz
-      REAL(wp), POINTER, DIMENSION(:,:,:) ::   zav_tide
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('zdf_tmx')
-      !
-      CALL wrk_alloc( jpi,jpj,       zkz )
-      CALL wrk_alloc( jpi,jpj,jpk,   zav_tide )
-      !
-      !                          ! ----------------------- !
-      !                          !  Standard tidal mixing  !  (compute zav_tide)
-      !                          ! ----------------------- !
-      !                             !* First estimation (with n2 bound by rn_n2min) bounded by 60 cm2/s
-      zav_tide(:,:,:) = MIN(  60.e-4, az_tmx(:,:,:) / MAX( rn_n2min, rn2(:,:,:) )  )
-
-      zkz(:,:) = 0.e0               !* Associated potential energy consummed over the whole water column
-      DO jk = 2, jpkm1
-         zkz(:,:) = zkz(:,:) + e3w_n(:,:,jk) * MAX( 0.e0, rn2(:,:,jk) ) * rau0 * zav_tide(:,:,jk) * wmask(:,:,jk)
-      END DO
-
-      DO jj = 1, jpj                !* Here zkz should be equal to en_tmx ==> multiply by en_tmx/zkz to recover en_tmx
-         DO ji = 1, jpi
-            IF( zkz(ji,jj) /= 0.e0 )   zkz(ji,jj) = en_tmx(ji,jj) / zkz(ji,jj)
-         END DO
-      END DO
-
-      DO jk = 2, jpkm1     !* Mutiply by zkz to recover en_tmx, BUT bound by 30/6 ==> zav_tide bound by 300 cm2/s
-         zav_tide(:,:,jk) = zav_tide(:,:,jk) * MIN( zkz(:,:), 30./6. ) * wmask(:,:,jk)  !kz max = 300 cm2/s
-      END DO
-
-      IF( kt == nit000 ) THEN       !* check at first time-step: diagnose the energy consumed by zav_tide
-         ztpc = 0._wp
-         DO jk= 1, jpk
-            DO jj= 1, jpj
-               DO ji= 1, jpi
-                  ztpc = ztpc + e3w_n(ji,jj,jk) * e1e2t(ji,jj)                  &
-                     &        * MAX( 0.e0, rn2(ji,jj,jk) ) * zav_tide(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
-               END DO
-            END DO
-         END DO
-         ztpc= rau0 / ( rn_tfe * rn_me ) * ztpc
-         IF( lk_mpp )   CALL mpp_sum( ztpc )
-         IF(lwp) WRITE(numout,*) 
-         IF(lwp) WRITE(numout,*) '          N Total power consumption by av_tide    : ztpc = ', ztpc * 1.e-12 ,'TW'
-      ENDIF
-       
-      !                          ! ----------------------- !
-      !                          !    ITF  tidal mixing    !  (update zav_tide)
-      !                          ! ----------------------- !
-      IF( ln_tmx_itf )   CALL tmx_itf( kt, zav_tide )
-
-      !                          ! ----------------------- !
-      !                          !   Update  mixing coefs  !                          
-      !                          ! ----------------------- !
-      DO jk = 2, jpkm1              !* update momentum & tracer diffusivity with tidal mixing
-         avt(:,:,jk) = avt(:,:,jk) + zav_tide(:,:,jk) * wmask(:,:,jk)
-         avm(:,:,jk) = avm(:,:,jk) + zav_tide(:,:,jk) * wmask(:,:,jk)
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1  ! vector opt.
-               avmu(ji,jj,jk) = avmu(ji,jj,jk) + 0.5 * ( zav_tide(ji,jj,jk) + zav_tide(ji+1,jj  ,jk) ) * wumask(ji,jj,jk)
-               avmv(ji,jj,jk) = avmv(ji,jj,jk) + 0.5 * ( zav_tide(ji,jj,jk) + zav_tide(ji  ,jj+1,jk) ) * wvmask(ji,jj,jk)
-            END DO
-         END DO
-      END DO
-      CALL lbc_lnk( avmu, 'U', 1. )   ;   CALL lbc_lnk( avmv, 'V', 1. )      ! lateral boundary condition
-
-      !                             !* output tidal mixing coefficient
-      CALL iom_put( "av_tide", zav_tide )
-
-      IF(ln_ctl)   CALL prt_ctl(tab3d_1=zav_tide , clinfo1=' tmx - av_tide: ', tab3d_2=avt, clinfo2=' avt: ', ovlap=1, kdim=jpk)
-      !
-      CALL wrk_dealloc( jpi,jpj,       zkz )
-      CALL wrk_dealloc( jpi,jpj,jpk,   zav_tide )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('zdf_tmx')
-      !
-   END SUBROUTINE zdf_tmx
-
-
-   SUBROUTINE tmx_itf( kt, pav )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE tmx_itf  ***
-      !!                   
-      !! ** Purpose :   modify the vertical eddy diffusivity coefficients 
-      !!              (pav) in the Indonesian Through Flow area (ITF).
-      !!
-      !! ** Method  : - Following Koch-Larrouy et al. (2007), in the ITF defined
-      !!                by msk_itf (read in a file, see tmx_init), the tidal
-      !!                mixing coefficient is computed with :
-      !!                  * q=1 (i.e. all the tidal energy remains trapped in
-      !!                         the area and thus is used for mixing)
-      !!                  * the vertical distribution of the tifal energy is a
-      !!                    proportional to N above the thermocline (d(N^2)/dz > 0)
-      !!                    and to N^2 below the thermocline (d(N^2)/dz < 0)
-      !!
-      !! ** Action  :   av_tide   updated in the ITF area (msk_itf)
-      !!
-      !! References :  Koch-Larrouy et al. 2007, GRL 
-      !!----------------------------------------------------------------------
-      INTEGER , INTENT(in   )                         ::   kt   ! ocean time-step
-      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pav  ! Tidal mixing coef.
-      !! 
-      INTEGER  ::   ji, jj, jk    ! dummy loop indices
-      REAL(wp) ::   zcoef, ztpc   ! temporary scalar
-      REAL(wp), DIMENSION(:,:)  , POINTER ::   zkz                        ! 2D workspace
-      REAL(wp), DIMENSION(:,:)  , POINTER ::   zsum1 , zsum2 , zsum       !  -      -
-      REAL(wp), DIMENSION(:,:,:), POINTER ::   zempba_3d_1, zempba_3d_2   ! 3D workspace
-      REAL(wp), DIMENSION(:,:,:), POINTER ::   zempba_3d  , zdn2dz        !  -      -
-      REAL(wp), DIMENSION(:,:,:), POINTER ::   zavt_itf                   !  -      -
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tmx_itf')
-      !
-      CALL wrk_alloc( jpi,jpj, zkz, zsum1 , zsum2 , zsum )
-      CALL wrk_alloc( jpi,jpj,jpk, zempba_3d_1, zempba_3d_2, zempba_3d, zdn2dz, zavt_itf )
-
-      !                             ! compute the form function using N2 at each time step
-      zdn2dz     (:,:,jpk) = 0.e0
-      zempba_3d_1(:,:,jpk) = 0.e0
-      zempba_3d_2(:,:,jpk) = 0.e0
-      DO jk = 1, jpkm1             
-         zdn2dz     (:,:,jk) = rn2(:,:,jk) - rn2(:,:,jk+1)           ! Vertical profile of dN2/dz
-         zempba_3d_1(:,:,jk) = SQRT(  MAX( 0.e0, rn2(:,:,jk) )  )    !    -        -    of N
-         zempba_3d_2(:,:,jk) =        MAX( 0.e0, rn2(:,:,jk) )       !    -        -    of N^2
-      END DO
-      !
-      zsum (:,:) = 0.e0
-      zsum1(:,:) = 0.e0
-      zsum2(:,:) = 0.e0
-      DO jk= 2, jpk
-         zsum1(:,:) = zsum1(:,:) + zempba_3d_1(:,:,jk) * e3w_n(:,:,jk) * wmask(:,:,jk)
-         zsum2(:,:) = zsum2(:,:) + zempba_3d_2(:,:,jk) * e3w_n(:,:,jk) * wmask(:,:,jk)               
-      END DO
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( zsum1(ji,jj) /= 0.e0 )   zsum1(ji,jj) = 1.e0 / zsum1(ji,jj)
-            IF( zsum2(ji,jj) /= 0.e0 )   zsum2(ji,jj) = 1.e0 / zsum2(ji,jj)                
-         END DO
-      END DO
-
-      DO jk= 1, jpk
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zcoef = 0.5 - SIGN( 0.5, zdn2dz(ji,jj,jk) )       ! =0 if dN2/dz > 0, =1 otherwise 
-               ztpc  = zempba_3d_1(ji,jj,jk) * zsum1(ji,jj) *        zcoef     &
-                  &  + zempba_3d_2(ji,jj,jk) * zsum2(ji,jj) * ( 1. - zcoef )
-               !
-               zempba_3d(ji,jj,jk) =               ztpc 
-               zsum     (ji,jj)    = zsum(ji,jj) + ztpc * e3w_n(ji,jj,jk)
-            END DO
-         END DO
-       END DO
-       DO jj = 1, jpj
-          DO ji = 1, jpi
-             IF( zsum(ji,jj) > 0.e0 )   zsum(ji,jj) = 1.e0 / zsum(ji,jj)                
-          END DO
-       END DO
-
-      !                             ! first estimation bounded by 10 cm2/s (with n2 bounded by rn_n2min) 
-      zcoef = rn_tfe_itf / ( rn_tfe * rau0 )
-      DO jk = 1, jpk
-         zavt_itf(:,:,jk) = MIN(  10.e-4, zcoef * en_tmx(:,:) * zsum(:,:) * zempba_3d(:,:,jk)   &
-            &                                      / MAX( rn_n2min, rn2(:,:,jk) ) * tmask(:,:,jk)  )
-      END DO           
-
-      zkz(:,:) = 0.e0               ! Associated potential energy consummed over the whole water column
-      DO jk = 2, jpkm1
-         zkz(:,:) = zkz(:,:) + e3w_n(:,:,jk) * MAX( 0.e0, rn2(:,:,jk) ) * rau0 * zavt_itf(:,:,jk) * wmask(:,:,jk)
-      END DO
-
-      DO jj = 1, jpj                ! Here zkz should be equal to en_tmx ==> multiply by en_tmx/zkz to recover en_tmx
-         DO ji = 1, jpi
-            IF( zkz(ji,jj) /= 0.e0 )   zkz(ji,jj) = en_tmx(ji,jj) * rn_tfe_itf / rn_tfe / zkz(ji,jj)
-         END DO
-      END DO
-
-      DO jk = 2, jpkm1              ! Mutiply by zkz to recover en_tmx, BUT bound by 30/6 ==> zavt_itf bound by 300 cm2/s
-         zavt_itf(:,:,jk) = zavt_itf(:,:,jk) * MIN( zkz(:,:), 120./10. ) * wmask(:,:,jk)   ! kz max = 120 cm2/s
-      END DO
-
-      IF( kt == nit000 ) THEN       ! diagnose the nergy consumed by zavt_itf
-         ztpc = 0.e0
-         DO jk= 1, jpk
-            DO jj= 1, jpj
-               DO ji= 1, jpi
-                  ztpc = ztpc + e1e2t(ji,jj) * e3w_n(ji,jj,jk) * MAX( 0.e0, rn2(ji,jj,jk) )   &
-                     &                       * zavt_itf(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mpp_sum( ztpc )
-         ztpc= rau0 * ztpc / ( rn_me * rn_tfe_itf )
-         IF(lwp) WRITE(numout,*) '          N Total power consumption by zavt_itf: ztpc = ', ztpc * 1.e-12 ,'TW'
-      ENDIF
-
-      !                             ! Update pav with the ITF mixing coefficient
-      DO jk = 2, jpkm1
-         pav(:,:,jk) = pav     (:,:,jk) * ( 1.e0 - mask_itf(:,:) )   &
-            &        + zavt_itf(:,:,jk) *          mask_itf(:,:) 
-      END DO
-      !
-      CALL wrk_dealloc( jpi,jpj, zkz, zsum1 , zsum2 , zsum )
-      CALL wrk_dealloc( jpi,jpj,jpk, zempba_3d_1, zempba_3d_2, zempba_3d, zdn2dz, zavt_itf )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tmx_itf')
-      !
-   END SUBROUTINE tmx_itf
-
-
-   SUBROUTINE zdf_tmx_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE zdf_tmx_init  ***
-      !!                     
-      !! ** Purpose :   Initialization of the vertical tidal mixing, Reading
-      !!              of M2 and K1 tidal energy in nc files
-      !!
-      !! ** Method  : - Read the namtmx namelist and check the parameters
-      !!
-      !!              - Read the input data in NetCDF files :
-      !!              M2 and K1 tidal energy. The total tidal energy, en_tmx, 
-      !!              is the sum of M2, K1 and S2 energy where S2 is assumed 
-      !!              to be: S2=(1/2)^2 * M2
-      !!              mask_itf, a mask array that determine where substituing 
-      !!              the standard Simmons et al. (2005) formulation with the
-      !!              one of Koch_Larrouy et al. (2007).
-      !!
-      !!              - Compute az_tmx, a 3D coefficient that allows to compute
-      !!             the standard tidal-induced vertical mixing as follows:
-      !!                  Kz_tides = az_tmx / max( rn_n2min, N^2 )
-      !!             with az_tmx a bottom intensified coefficient is given by:
-      !!                 az_tmx(z) = en_tmx / ( rau0 * rn_htmx ) * EXP( -(H-z)/rn_htmx )
-      !!                                                  / ( 1. - EXP( - H   /rn_htmx ) ) 
-      !!             where rn_htmx the characteristic length scale of the bottom 
-      !!             intensification, en_tmx the tidal energy, and H the ocean depth
-      !!
-      !! ** input   :   - Namlist namtmx
-      !!                - NetCDF file : M2_ORCA2.nc, K1_ORCA2.nc, and mask_itf.nc
-      !!
-      !! ** Action  : - Increase by 1 the nstop flag is setting problem encounter
-      !!              - defined az_tmx used to compute tidal-induced mixing
-      !!
-      !! References : Simmons et al. 2004, Ocean Modelling, 6, 3-4, 245-263.
-      !!              Koch-Larrouy et al. 2007, GRL.
-      !!----------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      INTEGER  ::   inum         ! local integer
-      INTEGER  ::   ios
-      REAL(wp) ::   ztpc, ze_z   ! local scalars
-      REAL(wp), DIMENSION(:,:)  , POINTER ::  zem2, zek1     ! read M2 and K1 tidal energy
-      REAL(wp), DIMENSION(:,:)  , POINTER ::  zkz            ! total M2, K1 and S2 tidal energy
-      REAL(wp), DIMENSION(:,:)  , POINTER ::  zfact          ! used for vertical structure function
-      REAL(wp), DIMENSION(:,:)  , POINTER ::  zhdep          ! Ocean depth 
-      REAL(wp), DIMENSION(:,:,:), POINTER ::  zpc, zav_tide  ! power consumption
-      !!
-      NAMELIST/namzdf_tmx/ rn_htmx, rn_n2min, rn_tfe, rn_me, ln_tmx_itf, rn_tfe_itf
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('zdf_tmx_init')
-      !
-      CALL wrk_alloc( jpi,jpj,       zem2, zek1, zkz, zfact, zhdep )
-      CALL wrk_alloc( jpi,jpj,jpk,   zpc, zav_tide )
-      !
-      REWIND( numnam_ref )             ! Namelist namzdf_tmx in reference namelist : Tidal Mixing
-      READ  ( numnam_ref, namzdf_tmx, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_tmx in reference namelist', lwp )
-      !
-      REWIND( numnam_cfg )             ! Namelist namzdf_tmx in configuration namelist : Tidal Mixing
-      READ  ( numnam_cfg, namzdf_tmx, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_tmx in configuration namelist', lwp )
-      IF(lwm) WRITE ( numond, namzdf_tmx )
-      !
-      IF(lwp) THEN                     ! Control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'zdf_tmx_init : tidal mixing'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) '   Namelist namzdf_tmx : set tidal mixing parameters'
-         WRITE(numout,*) '      Vertical decay scale for turbulence   = ', rn_htmx 
-         WRITE(numout,*) '      Brunt-Vaisala frequency threshold     = ', rn_n2min
-         WRITE(numout,*) '      Tidal dissipation efficiency          = ', rn_tfe
-         WRITE(numout,*) '      Mixing efficiency                     = ', rn_me
-         WRITE(numout,*) '      ITF specific parameterisation         = ', ln_tmx_itf
-         WRITE(numout,*) '      ITF tidal dissipation efficiency      = ', rn_tfe_itf
-      ENDIF
-      !                                ! allocate tmx arrays
-      IF( zdf_tmx_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_tmx_init : unable to allocate tmx arrays' )
-
-      IF( ln_tmx_itf ) THEN            ! read the Indonesian Through Flow mask
-         CALL iom_open('mask_itf',inum)
-         CALL iom_get (inum, jpdom_data, 'tmaskitf',mask_itf,1) ! 
-         CALL iom_close(inum)
-      ENDIF
-      !                                ! read M2 tidal energy flux : W/m2  ( zem2 < 0 )
-      CALL iom_open('M2rowdrg',inum)
-      CALL iom_get (inum, jpdom_data, 'field',zem2,1) ! 
-      CALL iom_close(inum)
-      !                                ! read K1 tidal energy flux : W/m2  ( zek1 < 0 )
-      CALL iom_open('K1rowdrg',inum)
-      CALL iom_get (inum, jpdom_data, 'field',zek1,1) ! 
-      CALL iom_close(inum)
-      !                                ! Total tidal energy ( M2, S2 and K1  with S2=(1/2)^2 * M2 )
-      !                                ! only the energy available for mixing is taken into account,
-      !                                ! (mixing efficiency tidal dissipation efficiency)
-      en_tmx(:,:) = - rn_tfe * rn_me * ( zem2(:,:) * 1.25 + zek1(:,:) ) * ssmask(:,:)
-
-!============
-!TG: Bug for VVL? Should this section be moved out of _init and be updated at every timestep?
-!!gm : you are right, but tidal mixing acts in deep ocean (H>500m) where e3 is O(100m)
-!!     the error is thus ~1% which I feel comfortable with, compared to uncertainties in tidal energy dissipation.
-      !                                ! Vertical structure (az_tmx)
-      DO jj = 1, jpj                         ! part independent of the level
-         DO ji = 1, jpi
-            zhdep(ji,jj) = gdepw_0(ji,jj,mbkt(ji,jj)+1)       ! depth of the ocean
-            zfact(ji,jj) = rau0 * rn_htmx * ( 1. - EXP( -zhdep(ji,jj) / rn_htmx ) )
-            IF( zfact(ji,jj) /= 0 )   zfact(ji,jj) = en_tmx(ji,jj) / zfact(ji,jj)
-         END DO
-      END DO
-      DO jk= 1, jpk                          ! complete with the level-dependent part
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               az_tmx(ji,jj,jk) = zfact(ji,jj) * EXP( -( zhdep(ji,jj)-gdepw_0(ji,jj,jk) ) / rn_htmx ) * tmask(ji,jj,jk)
-            END DO
-         END DO
-      END DO
-!===========
-      !
-      IF( nprint == 1 .AND. lwp ) THEN
-         ! Control print
-         ! Total power consumption due to vertical mixing
-         ! zpc = rau0 * 1/rn_me * rn2 * zav_tide
-         zav_tide(:,:,:) = 0.e0
-         DO jk = 2, jpkm1
-            zav_tide(:,:,jk) = az_tmx(:,:,jk) / MAX( rn_n2min, rn2(:,:,jk) )
-         END DO
-         !
-         ztpc = 0._wp
-         zpc(:,:,:) = MAX(rn_n2min,rn2(:,:,:)) * zav_tide(:,:,:)
-         DO jk= 2, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  ztpc = ztpc + e3w_n(ji,jj,jk) * e1e2t(ji,jj) * zpc(ji,jj,jk) * wmask(ji,jj,jk) * tmask_i(ji,jj)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mpp_sum( ztpc )
-         ztpc= rau0 * 1/(rn_tfe * rn_me) * ztpc
-         !
-         WRITE(numout,*) 
-         WRITE(numout,*) '          Total power consumption of the tidally driven part of Kz : ztpc = ', ztpc * 1.e-12 ,'TW'
-         !
-         ! control print 2
-         zav_tide(:,:,:) = MIN( zav_tide(:,:,:), 60.e-4 )   
-         zkz(:,:) = 0._wp
-         DO jk = 2, jpkm1
-               zkz(:,:) = zkz(:,:) + e3w_n(:,:,jk) * MAX(0.e0, rn2(:,:,jk)) * rau0 * zav_tide(:,:,jk) * wmask(:,:,jk)
-         END DO
-         ! Here zkz should be equal to en_tmx ==> multiply by en_tmx/zkz
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( zkz(ji,jj) /= 0.e0 )   THEN
-                   zkz(ji,jj) = en_tmx(ji,jj) / zkz(ji,jj)
-               ENDIF
-            END DO
-         END DO
-         ztpc = 1.e50
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( zkz(ji,jj) /= 0.e0 )   THEN
-                   ztpc = Min( zkz(ji,jj), ztpc)
-               ENDIF
-            END DO
-         END DO
-         WRITE(numout,*) '          Min de zkz ', ztpc, ' Max = ', maxval(zkz(:,:) )
-         !
-         DO jk = 2, jpkm1
-            zav_tide(:,:,jk) = zav_tide(:,:,jk) * MIN( zkz(:,:), 30./6. ) * wmask(:,:,jk)  !kz max = 300 cm2/s
-         END DO
-         ztpc = 0._wp
-         zpc(:,:,:) = Max(0.e0,rn2(:,:,:)) * zav_tide(:,:,:)
-         DO jk= 1, jpk
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  ztpc = ztpc + e3w_n(ji,jj,jk) * e1e2t(ji,jj) * zpc(ji,jj,jk) * wmask(ji,jj,jk) * tmask_i(ji,jj)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mpp_sum( ztpc )
-         ztpc= rau0 * 1/(rn_tfe * rn_me) * ztpc
-         WRITE(numout,*) '          2 Total power consumption of the tidally driven part of Kz : ztpc = ', ztpc * 1.e-12 ,'TW'
-!!gm bug mpp  in these diagnostics
-         DO jk = 1, jpk
-            ze_z =                  SUM( e1e2t(:,:) * zav_tide(:,:,jk) * tmask_i(:,:) )   &
-               &     / MAX( 1.e-20, SUM( e1e2t(:,:) * wmask   (:,:,jk) * tmask_i(:,:) ) )
-            ztpc = 1.e50
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  IF( zav_tide(ji,jj,jk) /= 0.e0 )   ztpc = MIN( ztpc, zav_tide(ji,jj,jk) )
-               END DO
-            END DO
-            WRITE(numout,*) '            N2 min - jk= ', jk,'   ', ze_z * 1.e4,' cm2/s min= ',ztpc*1.e4,   &
-               &       'max= ', MAXVAL(zav_tide(:,:,jk) )*1.e4, ' cm2/s'
-         END DO
-
-         WRITE(numout,*) '          e_tide : ', SUM( e1e2t*en_tmx ) / ( rn_tfe * rn_me ) * 1.e-12, 'TW'
-         WRITE(numout,*) 
-         WRITE(numout,*) '          Initial profile of tidal vertical mixing'
-         DO jk = 1, jpk
-            DO jj = 1,jpj
-               DO ji = 1,jpi
-                  zkz(ji,jj) = az_tmx(ji,jj,jk) /MAX( rn_n2min, rn2(ji,jj,jk) )
-               END DO
-            END DO
-            ze_z =                  SUM( e1e2t(:,:) * zkz  (:,:)    * tmask_i(:,:) )   &
-               &     / MAX( 1.e-20, SUM( e1e2t(:,:) * wmask(:,:,jk) * tmask_i(:,:) ) )
-            WRITE(numout,*) '                jk= ', jk,'   ', ze_z * 1.e4,' cm2/s'
-         END DO
-         DO jk = 1, jpk
-            zkz(:,:) = az_tmx(:,:,jk) /rn_n2min
-            ze_z =                  SUM( e1e2t(:,:) * zkz  (:,:)    * tmask_i(:,:) )   &
-               &     / MAX( 1.e-20, SUM( e1e2t(:,:) * wmask(:,:,jk) * tmask_i(:,:) ) )
-            WRITE(numout,*) 
-            WRITE(numout,*) '          N2 min - jk= ', jk,'   ', ze_z * 1.e4,' cm2/s min= ',MINVAL(zkz)*1.e4,   &
-               &       'max= ', MAXVAL(zkz)*1.e4, ' cm2/s'
-         END DO
-!!gm  end bug mpp
-         !
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi,jpj, zem2, zek1, zkz, zfact, zhdep )
-      CALL wrk_dealloc( jpi,jpj,jpk, zpc, zav_tide )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('zdf_tmx_init')
-      !
-   END SUBROUTINE zdf_tmx_init
-
-#elif defined key_zdftmx_new
-   !!----------------------------------------------------------------------
-   !!   'key_zdftmx_new'               Internal wave-driven vertical mixing
-   !!----------------------------------------------------------------------
-   !!   zdf_tmx       : global     momentum & tracer Kz with wave induced Kz
-   !!   zdf_tmx_init  : global     momentum & tracer Kz with wave induced Kz
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers variables
-   USE dom_oce        ! ocean space and time domain variables
-   USE zdf_oce        ! ocean vertical physics variables
-   USE zdfddm         ! ocean vertical physics: double diffusive mixing
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE eosbn2         ! ocean equation of state
-   USE phycst         ! physical constants
-   USE prtctl         ! Print control
-   USE in_out_manager ! I/O manager
-   USE iom            ! I/O Manager
-   USE lib_mpp        ! MPP library
-   USE wrk_nemo       ! work arrays
-   USE timing         ! Timing
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   zdf_tmx         ! called in step module 
-   PUBLIC   zdf_tmx_init    ! called in nemogcm module 
-   PUBLIC   zdf_tmx_alloc   ! called in nemogcm module
-
-   LOGICAL, PUBLIC, PARAMETER ::   lk_zdftmx = .TRUE.    !: wave-driven mixing flag
-
-   !                       !!* Namelist  namzdf_tmx : internal wave-driven mixing *
-   INTEGER  ::  nn_zpyc     ! pycnocline-intensified mixing energy proportional to N (=1) or N^2 (=2)
-   LOGICAL  ::  ln_mevar    ! variable (=T) or constant (=F) mixing efficiency
-   LOGICAL  ::  ln_tsdiff   ! account for differential T/S wave-driven mixing (=T) or not (=F)
-
-   REAL(wp) ::  r1_6 = 1._wp / 6._wp
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ebot_tmx     ! power available from high-mode wave breaking (W/m2)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   epyc_tmx     ! power available from low-mode, pycnocline-intensified wave breaking (W/m2)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ecri_tmx     ! power available from low-mode, critical slope wave breaking (W/m2)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   hbot_tmx     ! WKB decay scale for high-mode energy dissipation (m)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   hcri_tmx     ! decay scale for low-mode critical slope dissipation (m)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   emix_tmx     ! local energy density available for mixing (W/kg)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   bflx_tmx     ! buoyancy flux Kz * N^2 (W/kg)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   pcmap_tmx    ! vertically integrated buoyancy flux (W/m2)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   zav_ratio    ! S/T diffusivity ratio (only for ln_tsdiff=T)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   zav_wave     ! Internal wave-induced diffusivity
-
-   !! * Substitutions
-#  include "zdfddm_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2016)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION zdf_tmx_alloc()
-      !!----------------------------------------------------------------------
-      !!                ***  FUNCTION zdf_tmx_alloc  ***
-      !!----------------------------------------------------------------------
-      ALLOCATE(     ebot_tmx(jpi,jpj),  epyc_tmx(jpi,jpj),  ecri_tmx(jpi,jpj)    ,   &
-      &             hbot_tmx(jpi,jpj),  hcri_tmx(jpi,jpj),  emix_tmx(jpi,jpj,jpk),   &
-      &         bflx_tmx(jpi,jpj,jpk), pcmap_tmx(jpi,jpj), zav_ratio(jpi,jpj,jpk),   & 
-      &         zav_wave(jpi,jpj,jpk), STAT=zdf_tmx_alloc     )
-      !
-      IF( lk_mpp             )   CALL mpp_sum ( zdf_tmx_alloc )
-      IF( zdf_tmx_alloc /= 0 )   CALL ctl_warn('zdf_tmx_alloc: failed to allocate arrays')
-   END FUNCTION zdf_tmx_alloc
-
-
-   SUBROUTINE zdf_tmx( kt )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE zdf_tmx  ***
-      !!                   
-      !! ** Purpose :   add to the vertical mixing coefficients the effect of
-      !!              breaking internal waves.
-      !!
-      !! ** Method  : - internal wave-driven vertical mixing is given by:
-      !!                  Kz_wave = min(  100 cm2/s, f(  Reb = emix_tmx /( Nu * N^2 )  )
-      !!              where emix_tmx is the 3D space distribution of the wave-breaking 
-      !!              energy and Nu the molecular kinematic viscosity.
-      !!              The function f(Reb) is linear (constant mixing efficiency)
-      !!              if the namelist parameter ln_mevar = F and nonlinear if ln_mevar = T.
-      !!
-      !!              - Compute emix_tmx, the 3D power density that allows to compute
-      !!              Reb and therefrom the wave-induced vertical diffusivity.
-      !!              This is divided into three components:
-      !!                 1. Bottom-intensified low-mode dissipation at critical slopes
-      !!                     emix_tmx(z) = ( ecri_tmx / rau0 ) * EXP( -(H-z)/hcri_tmx )
-      !!                                   / ( 1. - EXP( - H/hcri_tmx ) ) * hcri_tmx
-      !!              where hcri_tmx is the characteristic length scale of the bottom 
-      !!              intensification, ecri_tmx a map of available power, and H the ocean depth.
-      !!                 2. Pycnocline-intensified low-mode dissipation
-      !!                     emix_tmx(z) = ( epyc_tmx / rau0 ) * ( sqrt(rn2(z))^nn_zpyc )
-      !!                                   / SUM( sqrt(rn2(z))^nn_zpyc * e3w(z) )
-      !!              where epyc_tmx is a map of available power, and nn_zpyc
-      !!              is the chosen stratification-dependence of the internal wave
-      !!              energy dissipation.
-      !!                 3. WKB-height dependent high mode dissipation
-      !!                     emix_tmx(z) = ( ebot_tmx / rau0 ) * rn2(z) * EXP(-z_wkb(z)/hbot_tmx)
-      !!                                   / SUM( rn2(z) * EXP(-z_wkb(z)/hbot_tmx) * e3w(z) )
-      !!              where hbot_tmx is the characteristic length scale of the WKB bottom 
-      !!              intensification, ebot_tmx is a map of available power, and z_wkb is the
-      !!              WKB-stretched height above bottom defined as
-      !!                    z_wkb(z) = H * SUM( sqrt(rn2(z'>=z)) * e3w(z'>=z) )
-      !!                                 / SUM( sqrt(rn2(z'))    * e3w(z')    )
-      !!
-      !!              - update the model vertical eddy viscosity and diffusivity: 
-      !!                     avt  = avt  +    av_wave
-      !!                     avm  = avm  +    av_wave
-      !!                     avmu = avmu + mi(av_wave)
-      !!                     avmv = avmv + mj(av_wave)
-      !!
-      !!              - if namelist parameter ln_tsdiff = T, account for differential mixing:
-      !!                     avs  = avt  +    av_wave * diffusivity_ratio(Reb)
-      !!
-      !! ** Action  : - Define emix_tmx used to compute internal wave-induced mixing
-      !!              - avt, avs, avm, avmu, avmv increased by internal wave-driven mixing    
-      !!
-      !! References :  de Lavergne et al. 2015, JPO; 2016, in prep.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean time-step 
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   ztpc         ! scalar workspace
-      REAL(wp), DIMENSION(:,:)  , POINTER ::  zfact     ! Used for vertical structure
-      REAL(wp), DIMENSION(:,:)  , POINTER ::  zhdep     ! Ocean depth
-      REAL(wp), DIMENSION(:,:,:), POINTER ::  zwkb      ! WKB-stretched height above bottom
-      REAL(wp), DIMENSION(:,:,:), POINTER ::  zweight   ! Weight for high mode vertical distribution
-      REAL(wp), DIMENSION(:,:,:), POINTER ::  znu_t     ! Molecular kinematic viscosity (T grid)
-      REAL(wp), DIMENSION(:,:,:), POINTER ::  znu_w     ! Molecular kinematic viscosity (W grid)
-      REAL(wp), DIMENSION(:,:,:), POINTER ::  zReb      ! Turbulence intensity parameter
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )   CALL timing_start('zdf_tmx')
-      !
-      CALL wrk_alloc( jpi,jpj,       zfact, zhdep )
-      CALL wrk_alloc( jpi,jpj,jpk,   zwkb, zweight, znu_t, znu_w, zReb )
-
-      !                          ! ----------------------------- !
-      !                          !  Internal wave-driven mixing  !  (compute zav_wave)
-      !                          ! ----------------------------- !
-      !                             
-      !                        !* Critical slope mixing: distribute energy over the time-varying ocean depth,
-      !                                                 using an exponential decay from the seafloor.
-      DO jj = 1, jpj                ! part independent of the level
-         DO ji = 1, jpi
-            zhdep(ji,jj) = gdepw_0(ji,jj,mbkt(ji,jj)+1)       ! depth of the ocean
-            zfact(ji,jj) = rau0 * (  1._wp - EXP( -zhdep(ji,jj) / hcri_tmx(ji,jj) )  )
-            IF( zfact(ji,jj) /= 0 )   zfact(ji,jj) = ecri_tmx(ji,jj) / zfact(ji,jj)
-         END DO
-      END DO
-
-      DO jk = 2, jpkm1              ! complete with the level-dependent part
-         emix_tmx(:,:,jk) = zfact(:,:) * (  EXP( ( gde3w_n(:,:,jk  ) - zhdep(:,:) ) / hcri_tmx(:,:) )                      &
-            &                             - EXP( ( gde3w_n(:,:,jk-1) - zhdep(:,:) ) / hcri_tmx(:,:) )  ) * wmask(:,:,jk)   &
-            &                          / ( gde3w_n(:,:,jk) - gde3w_n(:,:,jk-1) )
-      END DO
-
-      !                        !* Pycnocline-intensified mixing: distribute energy over the time-varying 
-      !                        !* ocean depth as proportional to sqrt(rn2)^nn_zpyc
-
-      SELECT CASE ( nn_zpyc )
-
-      CASE ( 1 )               ! Dissipation scales as N (recommended)
-
-         zfact(:,:) = 0._wp
-         DO jk = 2, jpkm1              ! part independent of the level
-            zfact(:,:) = zfact(:,:) + e3w_n(:,:,jk) * SQRT(  MAX( 0._wp, rn2(:,:,jk) )  ) * wmask(:,:,jk)
-         END DO
-
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( zfact(ji,jj) /= 0 )   zfact(ji,jj) = epyc_tmx(ji,jj) / ( rau0 * zfact(ji,jj) )
-            END DO
-         END DO
-
-         DO jk = 2, jpkm1              ! complete with the level-dependent part
-            emix_tmx(:,:,jk) = emix_tmx(:,:,jk) + zfact(:,:) * SQRT(  MAX( 0._wp, rn2(:,:,jk) )  ) * wmask(:,:,jk)
-         END DO
-
-      CASE ( 2 )               ! Dissipation scales as N^2
-
-         zfact(:,:) = 0._wp
-         DO jk = 2, jpkm1              ! part independent of the level
-            zfact(:,:) = zfact(:,:) + e3w_n(:,:,jk) * MAX( 0._wp, rn2(:,:,jk) ) * wmask(:,:,jk)
-         END DO
-
-         DO jj= 1, jpj
-            DO ji = 1, jpi
-               IF( zfact(ji,jj) /= 0 )   zfact(ji,jj) = epyc_tmx(ji,jj) / ( rau0 * zfact(ji,jj) )
-            END DO
-         END DO
-
-         DO jk = 2, jpkm1              ! complete with the level-dependent part
-            emix_tmx(:,:,jk) = emix_tmx(:,:,jk) + zfact(:,:) * MAX( 0._wp, rn2(:,:,jk) ) * wmask(:,:,jk)
-         END DO
-
-      END SELECT
-
-      !                        !* WKB-height dependent mixing: distribute energy over the time-varying 
-      !                        !* ocean depth as proportional to rn2 * exp(-z_wkb/rn_hbot)
-      
-      zwkb(:,:,:) = 0._wp
-      zfact(:,:) = 0._wp
-      DO jk = 2, jpkm1
-         zfact(:,:) = zfact(:,:) + e3w_n(:,:,jk) * SQRT(  MAX( 0._wp, rn2(:,:,jk) )  ) * wmask(:,:,jk)
-         zwkb(:,:,jk) = zfact(:,:)
-      END DO
-
-      DO jk = 2, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( zfact(ji,jj) /= 0 )   zwkb(ji,jj,jk) = zhdep(ji,jj) * ( zfact(ji,jj) - zwkb(ji,jj,jk) )   &
-                                            &           * tmask(ji,jj,jk) / zfact(ji,jj)
-            END DO
-         END DO
-      END DO
-      zwkb(:,:,1) = zhdep(:,:) * tmask(:,:,1)
-
-      zweight(:,:,:) = 0._wp
-      DO jk = 2, jpkm1
-         zweight(:,:,jk) = MAX( 0._wp, rn2(:,:,jk) ) * hbot_tmx(:,:) * wmask(:,:,jk)                    &
-            &   * (  EXP( -zwkb(:,:,jk) / hbot_tmx(:,:) ) - EXP( -zwkb(:,:,jk-1) / hbot_tmx(:,:) )  )
-      END DO
-
-      zfact(:,:) = 0._wp
-      DO jk = 2, jpkm1              ! part independent of the level
-         zfact(:,:) = zfact(:,:) + zweight(:,:,jk)
-      END DO
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( zfact(ji,jj) /= 0 )   zfact(ji,jj) = ebot_tmx(ji,jj) / ( rau0 * zfact(ji,jj) )
-         END DO
-      END DO
-
-      DO jk = 2, jpkm1              ! complete with the level-dependent part
-         emix_tmx(:,:,jk) = emix_tmx(:,:,jk) + zweight(:,:,jk) * zfact(:,:) * wmask(:,:,jk)   &
-            &                                / ( gde3w_n(:,:,jk) - gde3w_n(:,:,jk-1) )
-      END DO
-
-
-      ! Calculate molecular kinematic viscosity
-      znu_t(:,:,:) = 1.e-4_wp * (  17.91_wp - 0.53810_wp * tsn(:,:,:,jp_tem) + 0.00694_wp * tsn(:,:,:,jp_tem) * tsn(:,:,:,jp_tem)  &
-         &                                  + 0.02305_wp * tsn(:,:,:,jp_sal)  ) * tmask(:,:,:) * r1_rau0
-      DO jk = 2, jpkm1
-         znu_w(:,:,jk) = 0.5_wp * ( znu_t(:,:,jk-1) + znu_t(:,:,jk) ) * wmask(:,:,jk)
-      END DO
-
-      ! Calculate turbulence intensity parameter Reb
-      DO jk = 2, jpkm1
-         zReb(:,:,jk) = emix_tmx(:,:,jk) / MAX( 1.e-20_wp, znu_w(:,:,jk) * rn2(:,:,jk) )
-      END DO
-
-      ! Define internal wave-induced diffusivity
-      DO jk = 2, jpkm1
-         zav_wave(:,:,jk) = znu_w(:,:,jk) * zReb(:,:,jk) * r1_6   ! This corresponds to a constant mixing efficiency of 1/6
-      END DO
-
-      IF( ln_mevar ) THEN              ! Variable mixing efficiency case : modify zav_wave in the
-         DO jk = 2, jpkm1              ! energetic (Reb > 480) and buoyancy-controlled (Reb <10.224 ) regimes
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  IF( zReb(ji,jj,jk) > 480.00_wp ) THEN
-                     zav_wave(ji,jj,jk) = 3.6515_wp * znu_w(ji,jj,jk) * SQRT( zReb(ji,jj,jk) )
-                  ELSEIF( zReb(ji,jj,jk) < 10.224_wp ) THEN
-                     zav_wave(ji,jj,jk) = 0.052125_wp * znu_w(ji,jj,jk) * zReb(ji,jj,jk) * SQRT( zReb(ji,jj,jk) )
-                  ENDIF
-               END DO
-            END DO
-         END DO
-      ENDIF
-
-      DO jk = 2, jpkm1                 ! Bound diffusivity by molecular value and 100 cm2/s
-         zav_wave(:,:,jk) = MIN(  MAX( 1.4e-7_wp, zav_wave(:,:,jk) ), 1.e-2_wp  ) * wmask(:,:,jk)
-      END DO
-
-      IF( kt == nit000 ) THEN        !* Control print at first time-step: diagnose the energy consumed by zav_wave
-         ztpc = 0._wp
-         DO jk = 2, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  ztpc = ztpc + e3w_n(ji,jj,jk) * e1e2t(ji,jj)   &
-                     &         * MAX( 0._wp, rn2(ji,jj,jk) ) * zav_wave(ji,jj,jk) * wmask(ji,jj,jk) * tmask_i(ji,jj)
-               END DO
-            END DO
-         END DO
-         IF( lk_mpp )   CALL mpp_sum( ztpc )
-         ztpc = rau0 * ztpc ! Global integral of rauo * Kz * N^2 = power contributing to mixing 
- 
-         IF(lwp) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) 'zdf_tmx : Internal wave-driven mixing (tmx)'
-            WRITE(numout,*) '~~~~~~~ '
-            WRITE(numout,*)
-            WRITE(numout,*) '      Total power consumption by av_wave: ztpc =  ', ztpc * 1.e-12_wp, 'TW'
-         ENDIF
-      ENDIF
-
-      !                          ! ----------------------- !
-      !                          !   Update  mixing coefs  !                          
-      !                          ! ----------------------- !
-      !      
-      IF( ln_tsdiff ) THEN          !* Option for differential mixing of salinity and temperature
-         DO jk = 2, jpkm1              ! Calculate S/T diffusivity ratio as a function of Reb
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zav_ratio(ji,jj,jk) = ( 0.505_wp + 0.495_wp *                                                                  &
-                      &   TANH(    0.92_wp * (   LOG10(  MAX( 1.e-20_wp, zReb(ji,jj,jk) * 5._wp * r1_6 )  ) - 0.60_wp   )    )   &
-                      &                 ) * wmask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-         CALL iom_put( "av_ratio", zav_ratio )
-         DO jk = 2, jpkm1           !* update momentum & tracer diffusivity with wave-driven mixing
-            fsavs(:,:,jk) = avt(:,:,jk) + zav_wave(:,:,jk) * zav_ratio(:,:,jk)
-            avt  (:,:,jk) = avt(:,:,jk) + zav_wave(:,:,jk)
-            avm  (:,:,jk) = avm(:,:,jk) + zav_wave(:,:,jk)
-         END DO
-         !
-      ELSE                          !* update momentum & tracer diffusivity with wave-driven mixing
-         DO jk = 2, jpkm1
-            fsavs(:,:,jk) = avt(:,:,jk) + zav_wave(:,:,jk)
-            avt  (:,:,jk) = avt(:,:,jk) + zav_wave(:,:,jk)
-            avm  (:,:,jk) = avm(:,:,jk) + zav_wave(:,:,jk)
-         END DO
-      ENDIF
-
-      DO jk = 2, jpkm1              !* update momentum diffusivity at wu and wv points
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1  ! vector opt.
-               avmu(ji,jj,jk) = avmu(ji,jj,jk) + 0.5_wp * ( zav_wave(ji,jj,jk) + zav_wave(ji+1,jj  ,jk) ) * wumask(ji,jj,jk)
-               avmv(ji,jj,jk) = avmv(ji,jj,jk) + 0.5_wp * ( zav_wave(ji,jj,jk) + zav_wave(ji  ,jj+1,jk) ) * wvmask(ji,jj,jk)
-            END DO
-         END DO
-      END DO
-      CALL lbc_lnk( avmu, 'U', 1. )   ;   CALL lbc_lnk( avmv, 'V', 1. )      ! lateral boundary condition
-
-      !                             !* output internal wave-driven mixing coefficient
-      CALL iom_put( "av_wave", zav_wave )
-                                    !* output useful diagnostics: N^2, Kz * N^2 (bflx_tmx), 
-                                    !  vertical integral of rau0 * Kz * N^2 (pcmap_tmx), energy density (emix_tmx)
-      IF( iom_use("bflx_tmx") .OR. iom_use("pcmap_tmx") ) THEN
-         bflx_tmx(:,:,:) = MAX( 0._wp, rn2(:,:,:) ) * zav_wave(:,:,:)
-         pcmap_tmx(:,:) = 0._wp
-         DO jk = 2, jpkm1
-            pcmap_tmx(:,:) = pcmap_tmx(:,:) + e3w_n(:,:,jk) * bflx_tmx(:,:,jk) * wmask(:,:,jk)
-         END DO
-         pcmap_tmx(:,:) = rau0 * pcmap_tmx(:,:)
-         CALL iom_put( "bflx_tmx", bflx_tmx )
-         CALL iom_put( "pcmap_tmx", pcmap_tmx )
-      ENDIF
-      CALL iom_put( "bn2", rn2 )
-      CALL iom_put( "emix_tmx", emix_tmx )
-      
-      CALL wrk_dealloc( jpi,jpj,       zfact, zhdep )
-      CALL wrk_dealloc( jpi,jpj,jpk,   zwkb, zweight, znu_t, znu_w, zReb )
-
-      IF(ln_ctl)   CALL prt_ctl(tab3d_1=zav_wave , clinfo1=' tmx - av_wave: ', tab3d_2=avt, clinfo2=' avt: ', ovlap=1, kdim=jpk)
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('zdf_tmx')
-      !
-   END SUBROUTINE zdf_tmx
-
-
-   SUBROUTINE zdf_tmx_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE zdf_tmx_init  ***
-      !!                     
-      !! ** Purpose :   Initialization of the wave-driven vertical mixing, reading
-      !!              of input power maps and decay length scales in netcdf files.
-      !!
-      !! ** Method  : - Read the namzdf_tmx namelist and check the parameters
-      !!
-      !!              - Read the input data in NetCDF files :
-      !!              power available from high-mode wave breaking (mixing_power_bot.nc)
-      !!              power available from pycnocline-intensified wave-breaking (mixing_power_pyc.nc)
-      !!              power available from critical slope wave-breaking (mixing_power_cri.nc)
-      !!              WKB decay scale for high-mode wave-breaking (decay_scale_bot.nc)
-      !!              decay scale for critical slope wave-breaking (decay_scale_cri.nc)
-      !!
-      !! ** input   : - Namlist namzdf_tmx
-      !!              - NetCDF files : mixing_power_bot.nc, mixing_power_pyc.nc, mixing_power_cri.nc,
-      !!              decay_scale_bot.nc decay_scale_cri.nc
-      !!
-      !! ** Action  : - Increase by 1 the nstop flag is setting problem encounter
-      !!              - Define ebot_tmx, epyc_tmx, ecri_tmx, hbot_tmx, hcri_tmx
-      !!
-      !! References : de Lavergne et al. 2015, JPO; 2016, in prep.
-      !!			  
-      !!----------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      INTEGER  ::   inum         ! local integer
-      INTEGER  ::   ios
-      REAL(wp) ::   zbot, zpyc, zcri   ! local scalars
-      !!
-      NAMELIST/namzdf_tmx_new/ nn_zpyc, ln_mevar, ln_tsdiff
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('zdf_tmx_init')
-      !
-      REWIND( numnam_ref )              ! Namelist namzdf_tmx in reference namelist : Wave-driven mixing
-      READ  ( numnam_ref, namzdf_tmx_new, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_tmx in reference namelist', lwp )
-      !
-      REWIND( numnam_cfg )              ! Namelist namzdf_tmx in configuration namelist : Wave-driven mixing
-      READ  ( numnam_cfg, namzdf_tmx_new, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_tmx in configuration namelist', lwp )
-      IF(lwm) WRITE ( numond, namzdf_tmx_new )
-      !
-      IF(lwp) THEN                  ! Control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'zdf_tmx_init : internal wave-driven mixing'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) '   Namelist namzdf_tmx_new : set wave-driven mixing parameters'
-         WRITE(numout,*) '      Pycnocline-intensified diss. scales as N (=1) or N^2 (=2) = ', nn_zpyc
-         WRITE(numout,*) '      Variable (T) or constant (F) mixing efficiency            = ', ln_mevar
-         WRITE(numout,*) '      Differential internal wave-driven mixing (T) or not (F)   = ', ln_tsdiff
-      ENDIF
-      
-      ! The new wave-driven mixing parameterization elevates avt and avm in the interior, and
-      ! ensures that avt remains larger than its molecular value (=1.4e-7). Therefore, avtb should 
-      ! be set here to a very small value, and avmb to its (uniform) molecular value (=1.4e-6).
-      avmb(:) = 1.4e-6_wp        ! viscous molecular value
-      avtb(:) = 1.e-10_wp        ! very small diffusive minimum (background avt is specified in zdf_tmx)    
-      avtb_2d(:,:) = 1.e0_wp     ! uniform 
-      IF(lwp) THEN                  ! Control print
-         WRITE(numout,*)
-         WRITE(numout,*) '   Force the background value applied to avm & avt in TKE to be everywhere ',   &
-            &               'the viscous molecular value & a very small diffusive value, resp.'
-      ENDIF
-      
-      IF( .NOT.lk_zdfddm )   CALL ctl_stop( 'STOP', 'zdf_tmx_init_new : key_zdftmx_new requires key_zdfddm' )
-      
-      !                             ! allocate tmx arrays
-      IF( zdf_tmx_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_tmx_init : unable to allocate tmx arrays' )
-      !
-      !                             ! read necessary fields
-      CALL iom_open('mixing_power_bot',inum)       ! energy flux for high-mode wave breaking [W/m2]
-      CALL iom_get  (inum, jpdom_data, 'field', ebot_tmx, 1 ) 
-      CALL iom_close(inum)
-      !
-      CALL iom_open('mixing_power_pyc',inum)       ! energy flux for pynocline-intensified wave breaking [W/m2]
-      CALL iom_get  (inum, jpdom_data, 'field', epyc_tmx, 1 )
-      CALL iom_close(inum)
-      !
-      CALL iom_open('mixing_power_cri',inum)       ! energy flux for critical slope wave breaking [W/m2]
-      CALL iom_get  (inum, jpdom_data, 'field', ecri_tmx, 1 )
-      CALL iom_close(inum)
-      !
-      CALL iom_open('decay_scale_bot',inum)        ! spatially variable decay scale for high-mode wave breaking [m]
-      CALL iom_get  (inum, jpdom_data, 'field', hbot_tmx, 1 )
-      CALL iom_close(inum)
-      !
-      CALL iom_open('decay_scale_cri',inum)        ! spatially variable decay scale for critical slope wave breaking [m]
-      CALL iom_get  (inum, jpdom_data, 'field', hcri_tmx, 1 )
-      CALL iom_close(inum)
-
-      ebot_tmx(:,:) = ebot_tmx(:,:) * ssmask(:,:)
-      epyc_tmx(:,:) = epyc_tmx(:,:) * ssmask(:,:)
-      ecri_tmx(:,:) = ecri_tmx(:,:) * ssmask(:,:)
-
-      ! Set once for all to zero the first and last vertical levels of appropriate variables
-      emix_tmx (:,:, 1 ) = 0._wp
-      emix_tmx (:,:,jpk) = 0._wp
-      zav_ratio(:,:, 1 ) = 0._wp
-      zav_ratio(:,:,jpk) = 0._wp
-      zav_wave (:,:, 1 ) = 0._wp
-      zav_wave (:,:,jpk) = 0._wp
-
-      zbot = glob_sum( e1e2t(:,:) * ebot_tmx(:,:) )
-      zpyc = glob_sum( e1e2t(:,:) * epyc_tmx(:,:) )
-      zcri = glob_sum( e1e2t(:,:) * ecri_tmx(:,:) )
-      IF(lwp) THEN
-         WRITE(numout,*) '      High-mode wave-breaking energy:             ', zbot * 1.e-12_wp, 'TW'
-         WRITE(numout,*) '      Pycnocline-intensifed wave-breaking energy: ', zpyc * 1.e-12_wp, 'TW'
-         WRITE(numout,*) '      Critical slope wave-breaking energy:        ', zcri * 1.e-12_wp, 'TW'
-      ENDIF
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('zdf_tmx_init')
-      !
-   END SUBROUTINE zdf_tmx_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option          Dummy module                NO Tidal MiXing
-   !!----------------------------------------------------------------------
-   LOGICAL, PUBLIC, PARAMETER ::   lk_zdftmx = .FALSE.   !: tidal mixing flag
-CONTAINS
-   SUBROUTINE zdf_tmx_init           ! Dummy routine
-      WRITE(*,*) 'zdf_tmx: You should not have seen this print! error?'
-   END SUBROUTINE zdf_tmx_init
-   SUBROUTINE zdf_tmx( kt )          ! Dummy routine
-      WRITE(*,*) 'zdf_tmx: You should not have seen this print! error?', kt
-   END SUBROUTINE zdf_tmx
-#endif
-
-   !!======================================================================
-END MODULE zdftmx
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/module_example
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/module_example	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/module_example	(revision 9019)
@@ -86,9 +86,4 @@
       !!                Give references if exist otherwise suppress these lines
       !!----------------------------------------------------------------------
-      USE toto_module      ! description of the module
-      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released
-      USE wrk_nemo, ONLY:   zztab => wrk_2d_5                     ! 2D workspace
-      USE wrk_nemo, ONLY:   zwx => wrk_3d_12 , zwy => wrk_3d_13   ! 3D workspace
-      !!
       INTEGER , INTENT(in   )                     ::   kt      ! short description 
       INTEGER , INTENT(inout)                     ::   pvar1   !   -         -
@@ -100,10 +95,7 @@
       REAL(wp) ::   zmlmin, zbbrau   ! temporary scalars     (DOCTOR : start with z)
       REAL(wp) ::   zfact1, zfact2   ! do not use continuation lines in declaration
+      REAL(wp), DIMENSION(jpi,jpj) ::   zwrk_2d   ! 2D workspace
       !!--------------------------------------------------------------------
-
-      IF( wrk_in_use(3, 12,13) .OR. wrk_in_use(2, 5 ) THEN
-         CALL ctl_stop('exa_mpl: requested workspace arrays unavailable')   ;   RETURN
-      ENDIF
-
+      !
       IF( kt == nit000  )   CALL exa_mpl_init    ! Initialization (first time-step only)
 
@@ -119,5 +111,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  avmv(ji,jj,jk) = ....
+                  avm(ji,jj,jk) = ....
                END DO
             END DO
@@ -128,5 +120,5 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  avmv(ji,jj,jk) = ...
+                  avm(ji,jj,jk) = ...
                END DO
             END DO
@@ -135,9 +127,5 @@
       END SELECT
       !
-      CALL mpplnk2( avmu, 'U', 1. )              ! Lateral boundary conditions (unchanged sign)
-      !
-      IF( wrk_not_released(3, 12,13) .OR. wrk_not_released(2, 5 ) THEN
-         CALL ctl_stop('exa_mpl: failed to release workspace arrays')   ;   RETURN
-      ENDIF
+      CALL lbc_lnk( avm, 'T', 1. )              ! Lateral boundary conditions (unchanged sign)
       !
    END SUBROUTINE exa_mpl
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 9019)
@@ -50,10 +50,9 @@
    USE usrdef_nam     ! user defined configuration
    USE tideini        ! tidal components initialization   (tide_ini routine)
-   USE bdy_oce,   ONLY: ln_bdy
+   USE bdy_oce,  ONLY : ln_bdy
    USE bdyini         ! open boundary cond. setting       (bdy_init routine)
    USE istate         ! initial state setting          (istate_init routine)
    USE ldfdyn         ! lateral viscosity setting      (ldfdyn_init routine)
    USE ldftra         ! lateral diffusivity setting    (ldftra_init routine)
-   USE zdfini         ! vertical physics setting          (zdf_init routine)
    USE trdini         ! dyn/tra trends initialization     (trd_init routine)
    USE asminc         ! assimilation increments     
@@ -140,7 +139,4 @@
       CALL Agrif_Declare_Var_top   !  "      "   "   "      "  TOP
 # endif
-# if defined key_lim2
-      CALL Agrif_Declare_Var_lim2  !  "      "   "   "      "  LIM2
-# endif
 # if defined key_lim3
       CALL Agrif_Declare_Var_lim3  !  "      "   "   "      "  LIM3
@@ -206,10 +202,12 @@
       !
 #if defined key_agrif
-      CALL Agrif_ParentGrid_To_ChildGrid()
-      IF( ln_diaobs ) CALL dia_obs_wri
-      IF( nn_timing == 1 )   CALL timing_finalize
-      CALL Agrif_ChildGrid_To_ParentGrid()
-#endif
-      IF( nn_timing == 1 )   CALL timing_finalize
+      IF( .NOT. Agrif_Root() ) THEN
+         CALL Agrif_ParentGrid_To_ChildGrid()
+         IF( ln_diaobs )        CALL dia_obs_wri
+         IF( nn_timing == 1 )   CALL timing_finalize
+         CALL Agrif_ChildGrid_To_ParentGrid()
+      ENDIF
+#endif
+      IF( ln_timing    )   CALL timing_finalize
       !
       CALL nemo_closefile
@@ -237,9 +235,11 @@
       INTEGER  ::   ji                 ! dummy loop indices
       INTEGER  ::   ios, ilocal_comm   ! local integer
+      INTEGER  ::   iiarea, ijarea     ! local integers
+      INTEGER  ::   iirest, ijrest     ! local integers
       CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
       !
       NAMELIST/namctl/ ln_ctl   , nn_print, nn_ictls, nn_ictle,   &
          &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,   &
-         &             nn_timing, nn_diacfl
+         &             ln_timing, ln_diacfl
       NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_write_cfg, cn_domcfg_out, ln_use_jattr
       !!----------------------------------------------------------------------
@@ -280,17 +280,4 @@
       ENDIF
       !
-      jpk = jpkglo
-      !
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90)
-         jpiglo  = nbcellsx + 2 + 2*nbghostcells
-         jpjglo  = nbcellsy + 2 + 2*nbghostcells
-         jpi     = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci
-         jpj     = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj
-         nperio  = 0
-         jperio  = 0
-         ln_use_jattr = .false.
-      ENDIF
-#endif
       !
       !                             !--------------------------------------------!
@@ -351,18 +338,42 @@
 #endif
       ENDIF
+      !
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90)
+         jpiglo  = nbcellsx + 2 + 2*nbghostcells
+         jpjglo  = nbcellsy + 2 + 2*nbghostcells
+         jpi     = ( jpiglo-2*nn_hls + (jpni-1+0) ) / jpni + 2*nn_hls
+         jpj     = ( jpjglo-2*nn_hls + (jpnj-1+0) ) / jpnj + 2*nn_hls
+         jpimax  = jpi
+         jpjmax  = jpj
+         nperio  = 0
+         jperio  = 0
+         ln_use_jattr = .false.
+      ENDIF
+#endif
 
       IF( Agrif_Root() ) THEN       ! AGRIF mother: specific setting from jpni and jpnj
+         iiarea = 1 + MOD( narea - 1 , jpni )
+         ijarea = 1 + ( narea - 1 ) / jpni
+         iirest = 1 + MOD( jpiglo - 2*nn_hls - 1 , jpni )
+         ijrest = 1 + MOD( jpjglo - 2*nn_hls - 1 , jpnj )
 #if defined key_nemocice_decomp
-         jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
-         jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim. 
+         jpi = ( nx_global+2-2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
+         jpj = ( ny_global+2-2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim. 
+         jpimax  = jpi
+         jpjmax  = jpj
+         IF( iiarea == jpni ) jpi = jpiglo - (jpni - 1) * (jpi - 2*nn_hls)
+         IF( ijarea == jpnj ) jpj = jpjglo - (jpnj - 1) * (jpj - 2*nn_hls)
 #else
-         jpi = ( jpiglo     -2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
-         jpj = ( jpjglo     -2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim.
-#endif
-      ENDIF
-
-!!gm ???    why here  it has already been done in line 301 !
+         jpi = ( jpiglo     -2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
+         jpj = ( jpjglo     -2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.
+         jpimax  = jpi
+         jpjmax  = jpj
+         IF( iiarea > iirest ) jpi = jpi - 1
+         IF( ijarea > ijrest ) jpj = jpj - 1
+#endif
+      ENDIF
+
       jpk = jpkglo                                             ! third dim
-!!gm end
 
 #if defined key_agrif
@@ -411,34 +422,32 @@
 
       !                                      ! Domain decomposition
-      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
-      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
-      ENDIF
-      !
-      IF( nn_timing == 1 )  CALL timing_init
+      CALL mpp_init
+      IF( ln_nnogather )   CALL nemo_northcomms! northfold neighbour lists
+      !
+      IF( ln_timing    )   CALL timing_init
       !
       !                                      ! General initialization
-                            CALL     phy_cst    ! Physical constants
-                            CALL     eos_init   ! Equation of state
-      IF( lk_c1d        )   CALL     c1d_init   ! 1D column configuration
-                            CALL     wad_init   ! Wetting and drying options
-                            CALL     dom_init   ! Domain
-      IF( ln_crs        )   CALL     crs_init   ! coarsened grid: domain initialization 
-      IF( ln_nnogather )    CALL nemo_northcomms! northfold neighbour lists (must be done after the masks are defined)
-      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
+                           CALL     phy_cst    ! Physical constants
+                           CALL     eos_init   ! Equation of state
+      IF( lk_c1d       )   CALL     c1d_init   ! 1D column configuration
+                           CALL     wad_init   ! Wetting and drying options
+                           CALL     dom_init   ! Domain
+      IF( ln_crs       )   CALL     crs_init   ! coarsened grid: domain initialization 
+      IF( ln_ctl       )   CALL prt_ctl_init   ! Print control
       
-      CALL diurnal_sst_bulk_init            ! diurnal sst
+      CALL diurnal_sst_bulk_init             ! diurnal sst
       IF ( ln_diurnal ) CALL diurnal_sst_coolskin_init   ! cool skin   
       
       ! IF ln_diurnal_only, then we only want a subset of the initialisation routines
-      IF ( ln_diurnal_only ) THEN
+      IF( ln_diurnal_only ) THEN
          CALL  istate_init   ! ocean initial state (Dynamics and tracers)
          CALL     sbc_init   ! Forcings : surface module
          CALL tra_qsr_init   ! penetrative solar radiation qsr
-         IF( ln_diaobs     ) THEN                  ! Observation & model comparison
-            CALL dia_obs_init            ! Initialize observational data
-            CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
+         IF( ln_diaobs ) THEN                   ! Observation & model comparison
+            CALL dia_obs_init                      ! Initialize observational data
+            CALL dia_obs( nit000 - 1 )             ! Observation operator for restart
          ENDIF     
          !                                     ! Assimilation increments
-         IF( lk_asminc     )   CALL asm_inc_init   ! Initialize assimilation increments
+         IF( lk_asminc )   CALL asm_inc_init   ! Initialize assimilation increments
                  
          IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
@@ -446,73 +455,63 @@
       ENDIF
       
-                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
+                           CALL  istate_init   ! ocean initial state (Dynamics and tracers)
 
       !                                      ! external forcing 
-!!gm to be added : creation and call of sbc_apr_init
-!==> cbr: sbc_apr_init in sbcmod as sbc_rnf_init
-                            CALL    tide_init   ! tidal harmonics
-                            CALL     sbc_init   ! surface boundary conditions (including sea-ice)
-                            CALL     bdy_init   ! Open boundaries initialisation
+                           CALL    tide_init   ! tidal harmonics
+                           CALL     sbc_init   ! surface boundary conditions (including sea-ice)
+                           CALL     bdy_init   ! Open boundaries initialisation
+
       !                                      ! Ocean physics
-      !                                         ! Vertical physics
-                            CALL     zdf_init      ! namelist read
-                            CALL zdf_bfr_init      ! bottom friction
-      IF( lk_zdfric     )   CALL zdf_ric_init      ! Richardson number dependent Kz
-      IF( lk_zdftke     )   CALL zdf_tke_init      ! TKE closure scheme
-      IF( lk_zdfgls     )   CALL zdf_gls_init      ! GLS closure scheme
-      IF( lk_zdftmx     )   CALL zdf_tmx_init      ! tidal vertical mixing
-      IF( lk_zdfddm     )   CALL zdf_ddm_init      ! double diffusive mixing
-         
+                           CALL zdf_phy_init    ! Vertical physics
+                                     
       !                                         ! Lateral physics
-                            CALL ldf_tra_init      ! Lateral ocean tracer physics
-                            CALL ldf_eiv_init      ! eddy induced velocity param.
-                            CALL ldf_dyn_init      ! Lateral ocean momentum physics
-
-      !                                         ! Active tracers
-                            CALL tra_qsr_init      ! penetrative solar radiation qsr
-                            CALL tra_bbc_init      ! bottom heat flux
-      IF( lk_trabbl     )   CALL tra_bbl_init      ! advective (and/or diffusive) bottom boundary layer scheme
-                            CALL tra_dmp_init      ! internal tracer damping
-                            CALL tra_adv_init      ! horizontal & vertical advection
-                            CALL tra_ldf_init      ! lateral mixing
-                            CALL tra_zdf_init      ! vertical mixing and after tracer fields
-
-      !                                         ! Dynamics
-      IF( lk_c1d        )   CALL dyn_dmp_init      ! internal momentum damping
-                            CALL dyn_adv_init      ! advection (vector or flux form)
-                            CALL dyn_vor_init      ! vorticity term including Coriolis
-                            CALL dyn_ldf_init      ! lateral mixing
-                            CALL dyn_hpg_init      ! horizontal gradient of Hydrostatic pressure
-                            CALL dyn_zdf_init      ! vertical diffusion
-                            CALL dyn_spg_init      ! surface pressure gradient
+                           CALL ldf_tra_init      ! Lateral ocean tracer physics
+                           CALL ldf_eiv_init      ! eddy induced velocity param.
+                           CALL ldf_dyn_init      ! Lateral ocean momentum physics
+
+      !                                      ! Active tracers
+      IF( ln_traqsr    )   CALL tra_qsr_init      ! penetrative solar radiation qsr
+                           CALL tra_bbc_init      ! bottom heat flux
+      IF( ln_trabbl    )   CALL tra_bbl_init      ! advective (and/or diffusive) bottom boundary layer scheme
+                           CALL tra_dmp_init      ! internal tracer damping
+                           CALL tra_adv_init      ! horizontal & vertical advection
+                           CALL tra_ldf_init      ! lateral mixing
+
+      !                                      ! Dynamics
+      IF( lk_c1d       )   CALL dyn_dmp_init      ! internal momentum damping
+                           CALL dyn_adv_init      ! advection (vector or flux form)
+                           CALL dyn_vor_init      ! vorticity term including Coriolis
+                           CALL dyn_ldf_init      ! lateral mixing
+                           CALL dyn_hpg_init      ! horizontal gradient of Hydrostatic pressure
+                           CALL dyn_spg_init      ! surface pressure gradient
 
 #if defined key_top
       !                                      ! Passive tracers
-                            CALL     trc_init
-#endif
-      IF( l_ldfslp      )   CALL ldf_slp_init   ! slope of lateral mixing
+                           CALL     trc_init
+#endif
+      IF( l_ldfslp     )   CALL ldf_slp_init    ! slope of lateral mixing
 
       !                                      ! Icebergs
-                            CALL icb_init( rdt, nit000)   ! initialise icebergs instance
+                           CALL icb_init( rdt, nit000)   ! initialise icebergs instance
 
       !                                      ! Misc. options
-                            CALL sto_par_init   ! Stochastic parametrization
-      IF( ln_sto_eos     )  CALL sto_pts_init   ! RRandom T/S fluctuations
+                           CALL sto_par_init    ! Stochastic parametrization
+      IF( ln_sto_eos   )   CALL sto_pts_init    ! RRandom T/S fluctuations
      
       !                                      ! Diagnostics
-      IF( lk_floats     )   CALL     flo_init   ! drifting Floats
-                            CALL dia_cfl_init   ! Initialise CFL diagnostics
-                            CALL dia_ptr_init   ! Poleward TRansports initialization
-      IF( lk_diadct     )   CALL dia_dct_init   ! Sections tranports
-                            CALL dia_hsb_init   ! heat content, salt content and volume budgets
-                            CALL     trd_init   ! Mixed-layer/Vorticity/Integral constraints trends
-                            CALL dia_obs_init            ! Initialize observational data
-      IF( ln_diaobs     )   CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
-
-      !                                         ! Assimilation increments
-      IF( lk_asminc     )   CALL asm_inc_init   ! Initialize assimilation increments
+      IF( lk_floats    )   CALL     flo_init    ! drifting Floats
+      IF( ln_diacfl    )   CALL dia_cfl_init    ! Initialise CFL diagnostics
+                           CALL dia_ptr_init    ! Poleward TRansports initialization
+      IF( lk_diadct    )   CALL dia_dct_init    ! Sections tranports
+                           CALL dia_hsb_init    ! heat content, salt content and volume budgets
+                           CALL     trd_init    ! Mixed-layer/Vorticity/Integral constraints trends
+                           CALL dia_obs_init    ! Initialize observational data
+      IF( ln_diaobs    )   CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
+
+      !                                      ! Assimilation increments
+      IF( lk_asminc    )   CALL asm_inc_init    ! Initialize assimilation increments
       IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
-                            CALL dia_tmb_init  ! TMB outputs
-                            CALL dia_25h_init  ! 25h mean  outputs
+                           CALL dia_tmb_init    ! TMB outputs
+                           CALL dia_25h_init    ! 25h mean  outputs
       !
    END SUBROUTINE nemo_init
@@ -541,5 +540,6 @@
          WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
          WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
-         WRITE(numout,*) '      timing activated    (0/1)       nn_timing  = ', nn_timing
+         WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
+         WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
       ENDIF
       !
@@ -551,4 +551,10 @@
       isplt     = nn_isplt
       jsplt     = nn_jsplt
+!!gm to be remove at the end of the 2017 merge party
+      if( ln_timing ) then  ;  nn_timing = 1
+      else                  ;  nn_timing = 0
+      endif
+!!gm end
+      
 
       IF(lwp) THEN                  ! control print
@@ -621,5 +627,5 @@
       !
       IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
-      IF( numsol          /= -1 )   CLOSE( numsol          )   ! solver file
+      IF( numrun          /= -1 )   CLOSE( numrun          )   ! run statistics file
       IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
       IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/oce.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/oce.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/oce.F90	(revision 9019)
@@ -63,14 +63,4 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   riceload
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   rke          !: kinetic energy
-
-   !! arrays relating to embedding ice in the ocean. These arrays need to be declared 
-   !! even if no ice model is required. In the no ice model or traditional levitating 
-   !! ice cases they contain only zeros
-   !! ---------------------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   snwice_mass        !: mass of snow and ice at current  ice time step   [Kg/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   snwice_mass_b      !: mass of snow and ice at previous ice time step   [Kg/m2]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   snwice_fmass       !: time evolution of mass of snow+ice               [Kg/m2/s]
-
    !! Energy budget of the leads (open water embedded in sea ice)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   fraqsr_1lev        !: fraction of solar net radiation absorbed in the first ocean level [-]
@@ -87,5 +77,5 @@
       !!                   ***  FUNCTION oce_alloc  ***
       !!----------------------------------------------------------------------
-      INTEGER :: ierr(7)
+      INTEGER :: ierr(6)
       !!----------------------------------------------------------------------
       !
@@ -99,27 +89,24 @@
          &      rhd  (jpi,jpj,jpk)      , rhop (jpi,jpj,jpk)                              , STAT=ierr(1) )
          !
-      ALLOCATE(rke(jpi,jpj,jpk)  ,                                         &
-         &     sshb(jpi,jpj)     , sshn(jpi,jpj)   , ssha(jpi,jpj)   ,     &
-         &     ub_b(jpi,jpj)     , un_b(jpi,jpj)   , ua_b(jpi,jpj)   ,     &
-         &     vb_b(jpi,jpj)     , vn_b(jpi,jpj)   , va_b(jpi,jpj)   ,     &
-         &     spgu  (jpi,jpj)   , spgv(jpi,jpj)   ,                       &
-         &     gtsu(jpi,jpj,jpts), gtsv(jpi,jpj,jpts),                     &
-         &     gru(jpi,jpj)      , grv(jpi,jpj)      ,                     &
-         &     gtui(jpi,jpj,jpts), gtvi(jpi,jpj,jpts),                     &
-         &     grui(jpi,jpj)     , grvi(jpi,jpj)     ,                     &
-         &     riceload(jpi,jpj),                             STAT=ierr(2) )
+      ALLOCATE( sshb(jpi,jpj)     , sshn(jpi,jpj)   , ssha(jpi,jpj)   ,     &
+         &      ub_b(jpi,jpj)     , un_b(jpi,jpj)   , ua_b(jpi,jpj)   ,     &
+         &      vb_b(jpi,jpj)     , vn_b(jpi,jpj)   , va_b(jpi,jpj)   ,     &
+         &      spgu  (jpi,jpj)   , spgv(jpi,jpj)                     ,     &
+         &      gtsu(jpi,jpj,jpts), gtsv(jpi,jpj,jpts)                ,     &
+         &      gru(jpi,jpj)      , grv(jpi,jpj)                      ,     &
+         &      gtui(jpi,jpj,jpts), gtvi(jpi,jpj,jpts)                ,     &
+         &      grui(jpi,jpj)     , grvi(jpi,jpj)                     ,     &
+         &      riceload(jpi,jpj)                                     , STAT=ierr(2) )
          !
-      ALLOCATE( snwice_mass(jpi,jpj) , snwice_mass_b(jpi,jpj), snwice_fmass(jpi,jpj) , STAT=ierr(3) )
-         !
-      ALLOCATE( fraqsr_1lev(jpi,jpj) , STAT=ierr(4) )
+      ALLOCATE( fraqsr_1lev(jpi,jpj) , STAT=ierr(3) )
          !
       ALLOCATE( ssha_e(jpi,jpj),  sshn_e(jpi,jpj), sshb_e(jpi,jpj), sshbb_e(jpi,jpj), &
          &        ua_e(jpi,jpj),    un_e(jpi,jpj),   ub_e(jpi,jpj),   ubb_e(jpi,jpj), &
          &        va_e(jpi,jpj),    vn_e(jpi,jpj),   vb_e(jpi,jpj),   vbb_e(jpi,jpj), &
-         &        hu_e(jpi,jpj),   hur_e(jpi,jpj),   hv_e(jpi,jpj),   hvr_e(jpi,jpj), STAT=ierr(5) )
+         &        hu_e(jpi,jpj),   hur_e(jpi,jpj),   hv_e(jpi,jpj),   hvr_e(jpi,jpj), STAT=ierr(4) )
          !
-      ALLOCATE( ub2_b(jpi,jpj), vb2_b(jpi,jpj)                                      , STAT=ierr(6) )
+      ALLOCATE( ub2_b(jpi,jpj), vb2_b(jpi,jpj)                                      , STAT=ierr(5) )
 #if defined key_agrif
-      ALLOCATE( ub2_i_b(jpi,jpj), vb2_i_b(jpi,jpj)                                  , STAT=ierr(7) )
+      ALLOCATE( ub2_i_b(jpi,jpj), vb2_i_b(jpi,jpj)                                  , STAT=ierr(6) )
 #endif
          !
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/par_oce.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/par_oce.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/par_oce.F90	(revision 9019)
@@ -54,6 +54,6 @@
 
    ! local domain size                !!! * local computational domain *
-   INTEGER, PUBLIC ::   jpi   ! = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   !: first  dimension
-   INTEGER, PUBLIC ::   jpj   ! = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   !: second dimension
+   INTEGER, PUBLIC ::   jpi   ! = ( jpiglo-2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls   !: first  dimension
+   INTEGER, PUBLIC ::   jpj   ! = ( jpjglo-2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls   !: second dimension
    INTEGER, PUBLIC ::   jpk   ! = jpkglo
    INTEGER, PUBLIC ::   jpim1 ! = jpi-1                                            !: inner domain indices
@@ -61,4 +61,6 @@
    INTEGER, PUBLIC ::   jpkm1 ! = jpk-1                                            !:   -     -      -
    INTEGER, PUBLIC ::   jpij  ! = jpi*jpj                                          !:  jpi x jpj
+   INTEGER, PUBLIC ::   jpimax! = maximum jpi across all areas 
+   INTEGER, PUBLIC ::   jpjmax! = maximum jpj across all areas
 
    !!---------------------------------------------------------------------
@@ -78,6 +80,5 @@
    INTEGER, PUBLIC, PARAMETER ::   jpr2di = 0   !: number of columns for extra outer halo 
    INTEGER, PUBLIC, PARAMETER ::   jpr2dj = 0   !: number of rows    for extra outer halo 
-   INTEGER, PUBLIC, PARAMETER ::   jpreci = 1   !: number of columns for overlap 
-   INTEGER, PUBLIC, PARAMETER ::   jprecj = 1   !: number of rows    for overlap 
+   INTEGER, PUBLIC, PARAMETER ::   nn_hls = 1   !: halo width (applies to both rows and columns)
 
    !!----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/step.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/step.F90	(revision 9019)
@@ -29,5 +29,6 @@
    !!            3.7  !  2014-10  (G. Madec)  LDF simplication 
    !!             -   !  2014-12  (G. Madec) remove KPP scheme
-   !!             -   !  2015-11  (J. Chanut) free surface simplification
+   !!             -   !  2015-11  (J. Chanut) free surface simplification (remove filtered free surface)
+   !!            4.0  !  2017-05  (G. Madec)  introduction of the vertical physics manager (zdfphy)
    !!----------------------------------------------------------------------
 
@@ -45,5 +46,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -61,7 +62,7 @@
       !!                     ***  ROUTINE stp  ***
       !!
-      !! ** Purpose : - Time stepping of OPA (momentum and active tracer eqs.)
-      !!              - Time stepping of LIM (dynamic and thermodynamic eqs.)
-      !!              - Tme stepping  of TRC (passive tracer eqs.)
+      !! ** Purpose : - Time stepping of OPA  (momentum and active tracer eqs.)
+      !!              - Time stepping of ESIM (dynamic and thermodynamic eqs.)
+      !!              - Time stepping of TRC  (passive tracer eqs.)
       !!
       !! ** Method  : -1- Update forcings and data
@@ -74,7 +75,8 @@
       !!              -8- Outputs and diagnostics
       !!----------------------------------------------------------------------
-      INTEGER ::   ji,jj,jk ! dummy loop indice
-      INTEGER ::   indic    ! error indicator if < 0
-      INTEGER ::   kcall    ! optional integer argument (dom_vvl_sf_nxt)
+      INTEGER ::   ji, jj, jk   ! dummy loop indice
+      INTEGER ::   indic        ! error indicator if < 0
+!!gm kcall can be removed, I guess
+      INTEGER ::   kcall        ! optional integer argument (dom_vvl_sf_nxt)
       !! ---------------------------------------------------------------------
 #if defined key_agrif
@@ -125,34 +127,7 @@
                          CALL bn2    ( tsn, rab_n, rn2  ) ! now    Brunt-Vaisala frequency
 
-      !
       !  VERTICAL PHYSICS
-                         CALL zdf_bfr( kstp )         ! bottom friction (if quadratic)
-      !                                               ! Vertical eddy viscosity and diffusivity coefficients
-      IF( lk_zdfric  )   CALL zdf_ric ( kstp )             ! Richardson number dependent Kz
-      IF( lk_zdftke  )   CALL zdf_tke ( kstp )             ! TKE closure scheme for Kz
-      IF( lk_zdfgls  )   CALL zdf_gls ( kstp )             ! GLS closure scheme for Kz
-      IF( ln_zdfqiao )   CALL zdf_qiao( kstp )             ! Qiao vertical mixing 
-      !
-      IF( lk_zdfcst  ) THEN                                ! Constant Kz (reset avt, avm[uv] to the background value)
-         avt (:,:,:) = rn_avt0 * wmask (:,:,:)
-         avmu(:,:,:) = rn_avm0 * wumask(:,:,:)
-         avmv(:,:,:) = rn_avm0 * wvmask(:,:,:)
-      ENDIF
-
-      IF( ln_rnf_mouth ) THEN                         ! increase diffusivity at rivers mouths
-         DO jk = 2, nkrnf   ;   avt(:,:,jk) = avt(:,:,jk) + 2._wp * rn_avt_rnf * rnfmsk(:,:) * tmask(:,:,jk)   ;   END DO
-      ENDIF
-      IF( ln_zdfevd  )   CALL zdf_evd( kstp )         ! enhanced vertical eddy diffusivity
-
-      IF( lk_zdftmx  )   CALL zdf_tmx( kstp )         ! tidal vertical mixing
-
-      IF( lk_zdfddm  )   CALL zdf_ddm( kstp )         ! double diffusive mixing
-
-                         CALL zdf_mxl( kstp )         ! mixed layer depth
-
-                                                      ! write TKE or GLS information in the restart file
-      IF( lrst_oce .AND. lk_zdftke )   CALL tke_rst( kstp, 'WRITE' )
-      IF( lrst_oce .AND. lk_zdfgls )   CALL gls_rst( kstp, 'WRITE' )
-      !
+                         CALL zdf_phy( kstp )         ! vertical physics update (top/bot drag, avt, avs, avm + MLD)
+
       !  LATERAL  PHYSICS
       !
@@ -211,4 +186,5 @@
                          CALL dyn_vor       ( kstp )  ! vorticity term including Coriolis
                          CALL dyn_ldf       ( kstp )  ! lateral mixing
+      IF( ln_zdfosm  )   CALL dyn_osm       ( kstp )  ! OSMOSIS non-local velocity fluxes
                          CALL dyn_hpg       ( kstp )  ! horizontal gradient of Hydrostatic pressure
                          CALL dyn_spg       ( kstp )  ! surface pressure gradient
@@ -221,5 +197,6 @@
       ENDIF
 
-                         CALL dyn_bfr       ( kstp )  ! bottom friction
+      IF( .NOT.ln_drgimp)   CALL dyn_bfr    ( kstp )  ! bottom friction
+      
                          CALL dyn_zdf       ( kstp )  ! vertical diffusion
 
@@ -233,5 +210,5 @@
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       IF( lk_floats  )   CALL flo_stp( kstp )         ! drifting Floats
-      IF( nn_diacfl == 1 )   CALL dia_cfl( kstp )         ! Courant number diagnostics
+      IF( ln_diacfl  )   CALL dia_cfl( kstp )         ! Courant number diagnostics
       IF( lk_diahth  )   CALL dia_hth( kstp )         ! Thermocline depth (20 degres isotherm depth)
       IF( lk_diadct  )   CALL dia_dct( kstp )         ! Transports
@@ -259,5 +236,5 @@
       IF( ln_traqsr  )   CALL tra_qsr       ( kstp )  ! penetrative solar radiation qsr
       IF( ln_trabbc  )   CALL tra_bbc       ( kstp )  ! bottom heat flux
-      IF( lk_trabbl  )   CALL tra_bbl       ( kstp )  ! advective (and/or diffusive) bottom boundary layer scheme
+      IF( ln_trabbl  )   CALL tra_bbl       ( kstp )  ! advective (and/or diffusive) bottom boundary layer scheme
       IF( ln_tradmp  )   CALL tra_dmp       ( kstp )  ! internal damping trends
       IF( ln_bdy     )   CALL bdy_tra_dmp   ( kstp )  ! bdy damping trends
@@ -267,4 +244,7 @@
 #endif
                          CALL tra_adv       ( kstp )  ! horizontal & vertical advection
+      IF( ln_zdfosm  )   CALL tra_osm       ( kstp )  ! OSMOSIS non-local tracer fluxes
+      IF( lrst_oce .AND. ln_zdfosm ) &
+           &             CALL osm_rst( kstp, 'WRITE' )! write OSMOSIS outputs + wn (so must do here) to restarts
                          CALL tra_ldf       ( kstp )  ! lateral mixing
 
@@ -349,7 +329,8 @@
 #endif
       !
-      IF( nn_timing == 1 .AND.  kstp == nit000  )   CALL timing_reset
+      IF( ln_timing .AND.  kstp == nit000  )   CALL timing_reset
       !
    END SUBROUTINE stp
    
+   !!======================================================================
 END MODULE step
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/step_oce.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/step_oce.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/step_oce.F90	(revision 9019)
@@ -7,69 +7,63 @@
    !!             3.7  !  2014-01  (G. Madec) LDF simplication 
    !!----------------------------------------------------------------------
-   USE oce              ! ocean dynamics and tracers variables
-   USE dom_oce          ! ocean space and time domain variables
-   USE zdf_oce          ! ocean vertical physics variables
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+   USE zdf_oce         ! ocean vertical physics variables
+   USE zdfdrg  ,  ONLY : ln_drgimp   ! implicit top/bottom friction
 
-   USE daymod           ! calendar                         (day     routine)
+   USE daymod          ! calendar                         (day     routine)
 
-   USE sbc_oce          ! surface boundary condition: ocean
-   USE sbcmod           ! surface boundary condition       (sbc     routine)
-   USE sbcrnf           ! surface boundary condition: runoff variables
-   USE sbccpl           ! surface boundary condition: coupled formulation (call send at end of step)
-   USE sbcapr           ! surface boundary condition: atmospheric pressure
-   USE sbctide          ! Tide initialisation
-   USE sbcwave          ! Wave intialisation
+   USE sbc_oce         ! surface boundary condition: ocean
+   USE sbcmod          ! surface boundary condition       (sbc     routine)
+   USE sbcrnf          ! surface boundary condition: runoff variables
+   USE sbccpl          ! surface boundary condition: coupled formulation (call send at end of step)
+   USE sbcapr          ! surface boundary condition: atmospheric pressure
+   USE sbctide         ! Tide initialisation
+   USE sbcwave         ! Wave intialisation
 
-   USE traqsr           ! solar radiation penetration      (tra_qsr routine)
-   USE trasbc           ! surface boundary condition       (tra_sbc routine)
-   USE trabbc           ! bottom boundary condition        (tra_bbc routine)
-   USE trabbl           ! bottom boundary layer            (tra_bbl routine)
-   USE tradmp           ! internal damping                 (tra_dmp routine)
-   USE traadv           ! advection scheme control     (tra_adv_ctl routine)
-   USE traldf           ! lateral mixing                   (tra_ldf routine)
-   USE trazdf           ! vertical mixing                  (tra_zdf routine)
-   USE tranxt           ! time-stepping                    (tra_nxt routine)
-   USE tranpc           ! non-penetrative convection       (tra_npc routine)
+   USE traqsr          ! solar radiation penetration      (tra_qsr routine)
+   USE trasbc          ! surface boundary condition       (tra_sbc routine)
+   USE trabbc          ! bottom boundary condition        (tra_bbc routine)
+   USE trabbl          ! bottom boundary layer            (tra_bbl routine)
+   USE tradmp          ! internal damping                 (tra_dmp routine)
+   USE traadv          ! advection scheme control     (tra_adv_ctl routine)
+   USE traldf          ! lateral mixing                   (tra_ldf routine)
+   USE trazdf          ! vertical mixing                  (tra_zdf routine)
+   USE tranxt          ! time-stepping                    (tra_nxt routine)
+   USE tranpc          ! non-penetrative convection       (tra_npc routine)
 
-   USE eosbn2           ! equation of state                (eos_bn2 routine)
+   USE eosbn2          ! equation of state                (eos_bn2 routine)
 
-   USE divhor           ! horizontal divergence            (div_hor routine)
-   USE dynadv           ! advection                        (dyn_adv routine)
-   USE dynbfr           ! Bottom friction terms            (dyn_bfr routine)
-   USE dynvor           ! vorticity term                   (dyn_vor routine)
-   USE dynhpg           ! hydrostatic pressure grad.       (dyn_hpg routine)
-   USE dynldf           ! lateral momentum diffusion       (dyn_ldf routine)
-   USE dynzdf           ! vertical diffusion               (dyn_zdf routine)
-   USE dynspg           ! surface pressure gradient        (dyn_spg routine)
+   USE divhor          ! horizontal divergence            (div_hor routine)
+   USE dynadv          ! advection                        (dyn_adv routine)
+   USE dynbfr          ! Bottom friction terms            (dyn_bfr routine)
+   USE dynvor          ! vorticity term                   (dyn_vor routine)
+   USE dynhpg          ! hydrostatic pressure grad.       (dyn_hpg routine)
+   USE dynldf          ! lateral momentum diffusion       (dyn_ldf routine)
+   USE dynzdf          ! vertical diffusion               (dyn_zdf routine)
+   USE dynspg          ! surface pressure gradient        (dyn_spg routine)
 
-   USE dynnxt           ! time-stepping                    (dyn_nxt routine)
+   USE dynnxt          ! time-stepping                    (dyn_nxt routine)
 
-   USE stopar           ! Stochastic parametrization       (sto_par routine)
+   USE stopar          ! Stochastic parametrization       (sto_par routine)
    USE stopts 
 
-   USE bdy_oce    , ONLY: ln_bdy
-   USE bdydta           ! open boundary condition data     (bdy_dta routine)
-   USE bdytra           ! bdy cond. for tracers            (bdy_tra routine)
-   USE bdydyn3d         ! bdy cond. for baroclinic vel.  (bdy_dyn3d routine)
+   USE bdy_oce  , ONLY : ln_bdy
+   USE bdydta          ! open boundary condition data     (bdy_dta routine)
+   USE bdytra          ! bdy cond. for tracers            (bdy_tra routine)
+   USE bdydyn3d        ! bdy cond. for baroclinic vel.  (bdy_dyn3d routine)
 
-   USE sshwzv           ! vertical velocity and ssh        (ssh_nxt routine)
+   USE sshwzv          ! vertical velocity and ssh        (ssh_nxt routine)
    !                                                       (ssh_swp routine)
    !                                                       (wzv     routine)
-   USE domvvl           ! variable vertical scale factors  (dom_vvl_sf_nxt routine)
+   USE domvvl          ! variable vertical scale factors  (dom_vvl_sf_nxt routine)
    !                                                       (dom_vvl_sf_swp routine)
 
-   USE ldfslp           ! iso-neutral slopes               (ldf_slp routine)
-   USE ldfdyn           ! lateral eddy viscosity coef.     (ldf_dyn routine)
-   USE ldftra           ! lateral eddy diffusive coef.     (ldf_tra routine)
+   USE ldfslp          ! iso-neutral slopes               (ldf_slp routine)
+   USE ldfdyn          ! lateral eddy viscosity coef.     (ldf_dyn routine)
+   USE ldftra          ! lateral eddy diffusive coef.     (ldf_tra routine)
 
-   USE zdftmx           ! tide-induced vertical mixing     (zdf_tmx routine)
-   USE zdfbfr           ! bottom friction                  (zdf_bfr routine)
-   USE zdftke           ! TKE vertical mixing              (zdf_tke routine)
-   USE zdfgls           ! GLS vertical mixing              (zdf_gls routine)
-   USE zdfddm           ! double diffusion mixing          (zdf_ddm routine)
-   USE zdfevd           ! enhanced vertical diffusion      (zdf_evd routine)
-   USE zdfric           ! Richardson vertical mixing       (zdf_ric routine)
-   USE zdfmxl           ! Mixed-layer depth                (zdf_mxl routine)
-   USE zdfqiao          !Qiao module wave induced mixing   (zdf_qiao routine)
+   USE zdfphy          ! vertical physics manager      (zdf_phy_init routine)
+   USE zdfosm  , ONLY : osm_rst, dyn_osm, tra_osm      ! OSMOSIS routines used in step.F90
 
    USE step_diu        ! Time stepping for diurnal sst
@@ -78,35 +72,35 @@
    USE sbc_oce         ! surface fluxes  
    
-   USE zpshde           ! partial step: hor. derivative     (zps_hde routine)
+   USE zpshde          ! partial step: hor. derivative     (zps_hde routine)
 
-   USE diawri           ! Standard run outputs             (dia_wri routine)
-   USE diaptr           ! poleward transports              (dia_ptr routine)
-   USE diadct           ! sections transports              (dia_dct routine)
-   USE diaar5           ! AR5 diagnosics                   (dia_ar5 routine)
-   USE diahth           ! thermocline depth                (dia_hth routine)
-   USE diahsb           ! heat, salt and volume budgets    (dia_hsb routine)
+   USE diawri          ! Standard run outputs             (dia_wri routine)
+   USE diaptr          ! poleward transports              (dia_ptr routine)
+   USE diadct          ! sections transports              (dia_dct routine)
+   USE diaar5          ! AR5 diagnosics                   (dia_ar5 routine)
+   USE diahth          ! thermocline depth                (dia_hth routine)
+   USE diahsb          ! heat, salt and volume budgets    (dia_hsb routine)
    USE diaharm
    USE diacfl
-   USE flo_oce          ! floats variables
-   USE floats           ! floats computation               (flo_stp routine)
+   USE flo_oce         ! floats variables
+   USE floats          ! floats computation               (flo_stp routine)
 
-   USE crsfld           ! Standard output on coarse grid   (crs_fld routine)
+   USE crsfld          ! Standard output on coarse grid   (crs_fld routine)
 
-   USE asminc           ! assimilation increments      (tra_asm_inc routine)
+   USE asminc          ! assimilation increments      (tra_asm_inc routine)
    !                                                   (dyn_asm_inc routine)
    USE asmbkg
-   USE stpctl           ! time stepping control            (stp_ctl routine)
-   USE restart          ! ocean restart                    (rst_wri routine)
-   USE prtctl           ! Print control                    (prt_ctl routine)
+   USE stpctl          ! time stepping control            (stp_ctl routine)
+   USE restart         ! ocean restart                    (rst_wri routine)
+   USE prtctl          ! Print control                    (prt_ctl routine)
 
-   USE diaobs           ! Observation operator
+   USE diaobs          ! Observation operator
 
-   USE in_out_manager   ! I/O manager
-   USE iom              !
+   USE in_out_manager  ! I/O manager
+   USE iom             !
    USE lbclnk
-   USE timing           ! Timing
+   USE timing          ! Timing
 
 #if defined key_iomput
-   USE xios
+   USE xios            ! I/O server
 #endif
 #if defined key_agrif
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/stpctl.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/stpctl.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/stpctl.F90	(revision 9019)
@@ -9,4 +9,6 @@
    !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
    !!            2.0  ! 2009-07  (G. Madec)  Add statistic for time-spliting
+   !!            3.7  ! 2016-09  (G. Madec)  Remove solver
+   !!            4.0  ! 2017-04  (G. Madec)  regroup global communications
    !!----------------------------------------------------------------------
 
@@ -21,5 +23,4 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp         ! distributed memory computing
-   USE lib_fortran     ! Fortran routines library 
 
    IMPLICIT NONE
@@ -28,5 +29,5 @@
    PUBLIC stp_ctl           ! routine called by step.F90
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -42,8 +43,11 @@
       !! ** Method  : - Save the time step in numstp
       !!              - Print it each 50 time steps
-      !!              - Stop the run IF problem ( indic < 0 )
+      !!              - Stop the run IF problem encountered by setting indic=-3
+      !!                Problems checked: |ssh| maximum larger than 10 m
+      !!                                  |U|   maximum larger than 10 m/s 
+      !!                                  negative sea surface salinity
       !!
-      !! ** Actions :   'time.step' file containing the last ocean time-step
-      !!                
+      !! ** Actions :   "time.step" file = last ocean time-step
+      !!                "run.stat"  file = run statistics
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in   ) ::   kt       ! ocean time-step index
@@ -51,8 +55,11 @@
       !!
       INTEGER  ::   ji, jj, jk             ! dummy loop indices
-      INTEGER  ::   ii, ij, ik             ! local integers
-      REAL(wp) ::   zumax, zsmin, zssh2, zsshmax    ! local scalars
-      INTEGER, DIMENSION(3) ::   ilocu     ! 
-      INTEGER, DIMENSION(2) ::   ilocs     ! 
+      INTEGER  ::   iih, ijh               ! local integers
+      INTEGER  ::   iiu, iju, iku          !   -       -
+      INTEGER  ::   iis, ijs, iks          !   -       -
+      REAL(wp) ::   zzz                    ! local real 
+      INTEGER , DIMENSION(3) ::   ilocu, ilocs
+      INTEGER , DIMENSION(2) ::   iloch
+      REAL(wp), DIMENSION(3) ::   zmax
       !!----------------------------------------------------------------------
       !
@@ -61,126 +68,63 @@
          WRITE(numout,*) 'stp_ctl : time-stepping control'
          WRITE(numout,*) '~~~~~~~'
-         ! open time.step file
+         !                                ! open time.step file
          CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
+         !                                ! open run.stat file
+         CALL ctl_opn( numrun, 'run.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
       ENDIF
       !
-      IF(lwp) WRITE ( numstp, '(1x, i8)' )   kt      !* save the current time step in numstp
-      IF(lwp) REWIND( numstp )                       !  --------------------------
+      IF(lwp) THEN                        !==  current time step  ==!   ("time.step" file)
+         WRITE ( numstp, '(1x, i8)' )   kt
+         REWIND( numstp )
+      ENDIF
       !
-      !                                              !* Test maximum of velocity (zonal only)
-      !                                              !  ------------------------
-      !! zumax = MAXVAL( ABS( un(:,:,:) ) )                ! slower than the following loop on NEC SX5
-      zumax = 0.e0
-      DO jk = 1, jpk
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zumax = MAX(zumax,ABS(un(ji,jj,jk)))
-          END DO 
-        END DO 
-      END DO        
-      IF( lk_mpp )   CALL mpp_max( zumax )                 ! max over the global domain
+      !                                   !==  test of extrema  ==!
+      zmax(1) = MAXVAL(  ABS( sshn(:,:) )  )                                  ! ssh max
+      zmax(2) = MAXVAL(  ABS( un(:,:,:) )  )                                  ! velocity max (zonal only)
+      zmax(3) = MAXVAL( -tsn(:,:,:,jp_sal) , mask = tmask(:,:,:) == 1._wp )   ! minus salinity max
       !
-      IF( MOD( kt, nwrite ) == 1 .AND. lwp )   WRITE(numout,*) ' ==>> time-step= ',kt,' abs(U) max: ', zumax
+      IF( lk_mpp )   CALL mpp_max_multiple( zmax(:), 3 ) ! max over the global domain
       !
-      IF( zumax > 20.e0 ) THEN
+      IF( MOD( kt, nwrite ) == 1 .AND. lwp ) THEN
+         WRITE(numout,*) ' ==>> time-step= ', kt, ' |ssh| max: ',   zmax(1), ' |U| max: ', zmax(2),   &
+            &                                     ' S min: '    , - zmax(3)
+      ENDIF
+      !
+      IF (  zmax(1) >  10._wp .OR.   &                     ! too large sea surface height ( > 10 m)
+         &  zmax(2) >  10._wp .OR.   &                     ! too large velocity ( > 10 m/s)
+         &  zmax(3) >=  0._wp .OR.   &                     ! negative or zero sea surface salinity
+         &  ISNAN( zmax(1) + zmax(2) + zmax(3) )  ) THEN   ! NaN encounter in the tests
          IF( lk_mpp ) THEN
-            CALL mpp_maxloc(ABS(un),umask,zumax,ii,ij,ik)
+            CALL mpp_maxloc( ABS(sshn)        , ssmask(:,:)  , zzz, iih, ijh )
+            CALL mpp_maxloc( ABS(un)          , umask (:,:,:), zzz, iiu, iju, iku )
+            CALL mpp_minloc( tsn(:,:,:,jp_sal), tmask (:,:,:), zzz, iis, ijs, iks )
          ELSE
-            ilocu = MAXLOC( ABS( un(:,:,:) ) )
-            ii = ilocu(1) + nimpp - 1
-            ij = ilocu(2) + njmpp - 1
-            ik = ilocu(3)
+            iloch = MINLOC( ABS( sshn(:,:)   )                               )
+            ilocu = MAXLOC( ABS( un  (:,:,:) )                               )
+            ilocs = MINLOC( tsn(:,:,:,jp_sal) , mask = tmask(:,:,:) == 1._wp )
+            iih = iloch(1) + nimpp - 1   ;   ijh = iloch(2) + njmpp - 1
+            iiu = ilocu(1) + nimpp - 1   ;   iju = ilocu(2) + njmpp - 1   ;   iku = ilocu(3)
+            iis = ilocs(1) + nimpp - 1   ;   ijs = ilocs(2) + njmpp - 1   ;   iks = ilocu(3)
          ENDIF
          IF(lwp) THEN
             WRITE(numout,cform_err)
-            WRITE(numout,*) ' stpctl: the zonal velocity is larger than 20 m/s'
+            WRITE(numout,*) ' stpctl: |ssh| > 10 m   or   |U| > 10 m/s   or   S < 0   or   NaN encounter in the tests'
             WRITE(numout,*) ' ====== '
-            WRITE(numout,9400) kt, zumax, ii, ij, ik
+            WRITE(numout,9100) kt,   zmax(1), iih, ijh
+            WRITE(numout,9200) kt,   zmax(2), iiu, iju, iku
+            WRITE(numout,9300) kt, - zmax(3), iis, ijs, iks
             WRITE(numout,*)
-            WRITE(numout,*) '          output of last fields in numwso'
+            WRITE(numout,*) '          output of last computed fields in output.abort.nc file'
          ENDIF
          kindic = -3
       ENDIF
-9400  FORMAT (' kt=',i6,' max abs(U): ',1pg11.4,', i j k: ',3i5)
+9100  FORMAT (' kt=',i8,'   |ssh| max: ',1pg11.4,', at  i j  : ',2i5)
+9200  FORMAT (' kt=',i8,'   |U|   max: ',1pg11.4,', at  i j k: ',3i5)
+9300  FORMAT (' kt=',i8,'   S     min: ',1pg11.4,', at  i j  : ',2i5)
       !
-      !                                              !* Test minimum of salinity
-      !                                              !  ------------------------
-      !! zsmin = MINVAL( tsn(:,:,1,jp_sal), mask = tmask(:,:,1) == 1.e0 )  slower than the following loop on NEC SX5
-      zsmin = 100._wp
-      DO jj = 2, jpjm1
-         DO ji = 1, jpi
-            IF( tmask(ji,jj,1) == 1) zsmin = MIN(zsmin,tsn(ji,jj,1,jp_sal))
-         END DO
-      END DO
-      IF( lk_mpp )   CALL mpp_min( zsmin )                ! min over the global domain
+      !                                            !==  run statistics  ==!   ("run.stat" file)
+      IF(lwp) WRITE(numrun,9400) kt, zmax(1), zmax(2), - zmax(3)
       !
-      IF( MOD( kt, nwrite ) == 1 .AND. lwp )   WRITE(numout,*) ' ==>> time-step= ',kt,' SSS min:', zsmin
-      !
-      IF( zsmin < 0.) THEN 
-         IF (lk_mpp) THEN
-            CALL mpp_minloc ( tsn(:,:,1,jp_sal),tmask(:,:,1), zsmin, ii,ij )
-         ELSE
-            ilocs = MINLOC( tsn(:,:,1,jp_sal), mask = tmask(:,:,1) == 1.e0 )
-            ii = ilocs(1) + nimpp - 1
-            ij = ilocs(2) + njmpp - 1
-         ENDIF
-         !
-         IF(lwp) THEN
-            WRITE(numout,cform_err)
-            WRITE(numout,*) 'stp_ctl : NEGATIVE sea surface salinity'
-            WRITE(numout,*) '======= '
-            WRITE(numout,9500) kt, zsmin, ii, ij
-            WRITE(numout,*)
-            WRITE(numout,*) '          output of last fields in numwso'
-         ENDIF
-         kindic = -3
-      ENDIF
-9500  FORMAT (' kt=',i6,' min SSS: ',1pg11.4,', i j: ',2i5)
-      !
-      !
-      IF( lk_c1d )  RETURN          ! No log file in case of 1D vertical configuration
-
-      ! log file (ssh statistics)
-      ! --------                                   !* ssh statistics (and others...)
-      IF( kt == nit000 .AND. lwp ) THEN   ! open ssh statistics file (put in solver.stat file)
-         CALL ctl_opn( numsol, 'solver.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
-      ENDIF
-      !
-      zsshmax = 0.e0
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( tmask(ji,jj,1) == 1) zsshmax = MAX( zsshmax, ABS(sshn(ji,jj)) )
-         END DO
-      END DO
-      IF( lk_mpp )   CALL mpp_max( zsshmax )                ! min over the global domain
-      !
-      IF( MOD( kt, nwrite ) == 1 .AND. lwp )   WRITE(numout,*) ' ==>> time-step= ',kt,' ssh max:', zsshmax
-      !
-      IF( zsshmax > 10.e0 ) THEN 
-         IF (lk_mpp) THEN
-            CALL mpp_maxloc( ABS(sshn(:,:)),tmask(:,:,1),zsshmax,ii,ij)
-         ELSE
-            ilocs = MAXLOC( ABS(sshn(:,:)) )
-            ii = ilocs(1) + nimpp - 1
-            ij = ilocs(2) + njmpp - 1
-         ENDIF
-         !
-         IF(lwp) THEN
-            WRITE(numout,cform_err)
-            WRITE(numout,*) 'stp_ctl : the ssh is larger than 10m'
-            WRITE(numout,*) '======= '
-            WRITE(numout,9600) kt, zsshmax, ii, ij
-            WRITE(numout,*)
-            WRITE(numout,*) '          output of last fields in numwso'
-         ENDIF
-         kindic = -3
-      ENDIF
-9600  FORMAT (' kt=',i6,' max ssh: ',1pg11.4,', i j: ',2i5)
-      !
-      zssh2 = glob_sum( sshn(:,:) * sshn(:,:) )
-      !
-      IF(lwp) WRITE(numsol,9700) kt, zssh2, zumax, zsmin      ! ssh statistics
-      !
-9700  FORMAT(' it :', i8, ' ssh2: ', d23.16, ' Umax: ',d23.16,' Smin: ',d23.16)
+9400  FORMAT(' it :', i8, '    |ssh|_max: ', e16.10, ' |U|_max: ',e16.10,' S_min: ',e16.10)
       !
    END SUBROUTINE stp_ctl
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/trc_oce.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/trc_oce.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/trc_oce.F90	(revision 9019)
@@ -24,9 +24,10 @@
    PUBLIC   trc_oce_alloc      ! function called by nemogcm.F90
 
-   LOGICAL , PUBLIC                                      ::   l_co2cpl  = .false.   !: atmospheric pco2 recieved from oasis
-   LOGICAL , PUBLIC                                      ::   l_offline = .false.   !: offline passive tracers flag
-   INTEGER , PUBLIC                                      ::   nn_dttrc = 1     !: frequency of step on passive tracers
-   REAL(wp), PUBLIC                                      ::   r_si2         !: largest depth of extinction (blue & 0.01 mg.m-3)  (RGB)
-   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   etot3         !: light absortion coefficient
+   LOGICAL , PUBLIC ::   l_co2cpl  = .false.   !: atmospheric pco2 recieved from oasis
+   LOGICAL , PUBLIC ::   l_offline = .false.   !: offline passive tracers flag
+   INTEGER , PUBLIC ::   nn_dttrc              !: frequency of step on passive tracers
+   REAL(wp), PUBLIC ::   r_si2                 !: largest depth of extinction (blue & 0.01 mg.m-3)  (RGB)
+   !
+   REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   etot3     !: light absortion coefficient
    REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:)   ::   oce_co2   !: ocean carbon flux
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90	(revision 9019)
@@ -93,9 +93,11 @@
       INTEGER ::   ji                 ! dummy loop indices
       INTEGER ::   ios, ilocal_comm   ! local integer
+      INTEGER  ::   iiarea, ijarea     ! local integers
+      INTEGER  ::   iirest, ijrest     ! local integers
       CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
       !
       NAMELIST/namctl/ ln_ctl   , nn_print, nn_ictls, nn_ictle,   &
          &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,   &
-         &             nn_timing, nn_diacfl
+         &             ln_timing, ln_diacfl
       NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_write_cfg, cn_domcfg_out, ln_use_jattr
       !!----------------------------------------------------------------------
@@ -209,21 +211,52 @@
 #endif
       ENDIF
+      !
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90)
+         jpiglo  = nbcellsx + 2 + 2*nbghostcells
+         jpjglo  = nbcellsy + 2 + 2*nbghostcells
+         jpi     = ( jpiglo-2*nn_hls + (jpni-1+0) ) / jpni + 2*nn_hls
+         jpj     = ( jpjglo-2*nn_hls + (jpnj-1+0) ) / jpnj + 2*nn_hls
+         jpimax  = jpi
+         jpjmax  = jpj
+         nperio  = 0
+         jperio  = 0
+         ln_use_jattr = .false.
+      ENDIF
+#endif
 
       IF( Agrif_Root() ) THEN       ! AGRIF mother: specific setting from jpni and jpnj
+         iiarea = 1 + MOD( narea - 1 , jpni )
+         ijarea = 1 + ( narea - 1 ) / jpni
+         iirest = 1 + MOD( jpiglo - 2*nn_hls - 1 , jpni )
+         ijrest = 1 + MOD( jpjglo - 2*nn_hls - 1 , jpnj )
 #if defined key_nemocice_decomp
-         jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
-         jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim. 
+         jpi = ( nx_global+2-2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
+         jpj = ( ny_global+2-2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim. 
+         jpimax  = jpi
+         jpjmax  = jpj
+         IF( iiarea == jpni ) jpi = jpiglo - (jpni - 1) * (jpi - 2*nn_hls)
+         IF( ijarea == jpnj ) jpj = jpjglo - (jpnj - 1) * (jpj - 2*nn_hls)
 #else
-         jpi = ( jpiglo     -2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
-         jpj = ( jpjglo     -2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim.
-#endif
-      ENDIF
-
-!!gm ???    why here  it has already been done in line 301 !
+         jpi = ( jpiglo     -2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
+         jpj = ( jpjglo     -2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.
+         jpimax  = jpi
+         jpjmax  = jpj
+         IF( iiarea > iirest ) jpi = jpi - 1
+         IF( ijarea > ijrest ) jpj = jpj - 1
+#endif
+      ENDIF
+
       jpk = jpkglo                                             ! third dim
-!!gm end
+
+#if defined key_agrif
+      ! simple trick to use same vertical grid as parent but different number of levels: 
+      ! Save maximum number of levels in jpkglo, then define all vertical grids with this number.
+      ! Suppress once vertical online interpolation is ok
+      IF(.NOT.Agrif_Root())   jpkglo = Agrif_Parent( jpkglo )
+#endif
       jpim1 = jpi-1                                            ! inner domain indices
       jpjm1 = jpj-1                                            !   "           "
-      jpkm1 = jpk-1                                            !   "           "
+      jpkm1 = MAX( 1, jpk-1 )                                  !   "           "
       jpij  = jpi*jpj                                          !  jpi x j
 
@@ -259,23 +292,21 @@
       !                             !-------------------------------!
 
-      CALL nemo_ctl                          ! Control prints & Benchmark
+      CALL nemo_ctl                             ! Control prints & Benchmark
 
       !                                      ! Domain decomposition
-      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
-      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
-      ENDIF
-      !
-      IF( nn_timing == 1 )  CALL timing_init
-      !
-      !                                      ! General initialization
-                            CALL     phy_cst    ! Physical constants
-                            CALL     eos_init   ! Equation of state
-                            CALL     dom_init   ! Domain
-
-      IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
-
-      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
-
-                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
+      CALL mpp_init
+      !
+      IF( ln_timing    )   CALL timing_init     ! timing by routine
+      !
+      !                                         ! General initialization
+                           CALL phy_cst            ! Physical constants
+                           CALL eos_init           ! Equation of state
+                           CALL dom_init           ! Domain
+
+      IF( ln_nnogather )   CALL nemo_northcomms ! Initialise the northfold neighbour lists (must be done after the masks are defined)
+
+      IF( ln_ctl       )   CALL prt_ctl_init    ! Print control
+
+                           CALL istate_init     ! ocean initial state (Dynamics and tracers)
    END SUBROUTINE nemo_init
 
@@ -303,5 +334,6 @@
          WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
          WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
-         WRITE(numout,*) '      timing activated    (0/1)       nn_timing  = ', nn_timing
+         WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
+         WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
       ENDIF
       !
@@ -383,5 +415,5 @@
       !
       IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
-      IF( numsol          /= -1 )   CLOSE( numsol          )   ! solver file
+      IF( numrun          /= -1 )   CLOSE( numrun          )   ! run statistics file
       IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
       IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAS_SRC/diawri.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAS_SRC/diawri.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAS_SRC/diawri.F90	(revision 9019)
@@ -38,8 +38,6 @@
    USE iom
    USE ioipsl
-#if defined key_lim2
-   USE limwri_2 
-#elif defined key_lim3
-   USE limwri
+#if defined key_lim3
+   USE icewri
 #endif
    USE lib_mpp         ! MPP library
@@ -397,8 +395,8 @@
          &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
 
-#if defined key_lim2
-      CALL lim_wri_state_2( kt, id_i, nh_i )
-#elif defined key_lim3
-      CALL lim_wri_state( kt, id_i, nh_i )
+#if defined key_lim3
+      IF( nn_ice == 2 ) THEN   ! condition needed in case agrif + lim but no-ice in child grid
+         CALL ice_wri_state( kt, id_i, nh_i )
+      ENDIF
 #else
       CALL histend( id_i, snc4chunks=snc4set )
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90	(revision 9019)
@@ -31,6 +31,6 @@
    USE icbini         ! handle bergs, initialisation
    USE icbstp         ! handle bergs, calving, themodynamics and transport
-   USE bdyini         ! open boundary cond. setting       (bdy_init routine). clem: mandatory for LIM3
-   USE bdydta         ! open boundary cond. setting   (bdy_dta_init routine). clem: mandatory for LIM3
+   USE bdyini         ! open boundary cond. setting       (bdy_init routine). mandatory for sea-ice
+   USE bdydta         ! open boundary cond. setting   (bdy_dta_init routine). mandatory for sea-ice
    !
    USE lib_mpp        ! distributed memory computing
@@ -87,7 +87,4 @@
       CALL Agrif_Declare_Var_top   !  "      "   "   "      "  TOP
 # endif
-# if defined key_lim2
-      CALL Agrif_Declare_Var_lim2  !  "      "   "   "      "  LIM
-# endif
 # if defined key_lim3
       CALL Agrif_Declare_Var_lim3  !  "      "   "   "      "  LIM3
@@ -135,11 +132,9 @@
       !
 #if defined key_agrif
-      IF( .NOT. Agrif_Root() ) THEN
          CALL Agrif_ParentGrid_To_ChildGrid()
-         IF( nn_timing == 1 )   CALL timing_finalize
+         IF( ln_timing )   CALL timing_finalize
          CALL Agrif_ChildGrid_To_ParentGrid()
-      ENDIF
-#endif
-      IF( nn_timing == 1 )   CALL timing_finalize
+#endif
+      IF( ln_timing )   CALL timing_finalize
       !
       CALL nemo_closefile
@@ -168,4 +163,6 @@
       INTEGER  ::   ilocal_comm   ! local integer
       INTEGER  ::   ios, inum     !   -      -
+      INTEGER  ::   iiarea, ijarea     ! local integers
+      INTEGER  ::   iirest, ijrest     ! local integers
       CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
       CHARACTER(len=80)                 ::   clname
@@ -173,5 +170,5 @@
       NAMELIST/namctl/ ln_ctl   , nn_print, nn_ictls, nn_ictle,   &
          &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,   &
-         &             nn_timing, nn_diacfl
+         &             ln_timing, ln_diacfl
       NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_write_cfg, cn_domcfg_out, ln_use_jattr
       !!----------------------------------------------------------------------
@@ -221,17 +218,4 @@
       ENDIF
       !
-      jpk = jpkglo
-      !
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90)
-         jpiglo  = nbcellsx + 2 + 2*nbghostcells
-         jpjglo  = nbcellsy + 2 + 2*nbghostcells
-         jpi     = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci
-         jpj     = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj
-         nperio  = 0
-         jperio  = 0
-         ln_use_jattr = .false.
-      ENDIF
-#endif
       !
       !                             !--------------------------------------------!
@@ -290,14 +274,42 @@
 #endif
       ENDIF
+      !
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90)
+         jpiglo  = nbcellsx + 2 + 2*nbghostcells
+         jpjglo  = nbcellsy + 2 + 2*nbghostcells
+         jpi     = ( jpiglo-2*nn_hls + (jpni-1+0) ) / jpni + 2*nn_hls
+         jpj     = ( jpjglo-2*nn_hls + (jpnj-1+0) ) / jpnj + 2*nn_hls
+         jpimax  = jpi
+         jpjmax  = jpj
+         nperio  = 0
+         jperio  = 0
+         ln_use_jattr = .false.
+      ENDIF
+#endif
 
       IF( Agrif_Root() ) THEN       ! AGRIF mother: specific setting from jpni and jpnj
+         iiarea = 1 + MOD( narea - 1 , jpni )
+         ijarea = 1 + ( narea - 1 ) / jpni
+         iirest = 1 + MOD( jpiglo - 2*nn_hls - 1 , jpni )
+         ijrest = 1 + MOD( jpjglo - 2*nn_hls - 1 , jpnj )
 #if defined key_nemocice_decomp
-         jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
-         jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim. 
+         jpi = ( nx_global+2-2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
+         jpj = ( ny_global+2-2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim. 
+         jpimax  = jpi
+         jpjmax  = jpj
+         IF( iiarea == jpni ) jpi = jpiglo - (jpni - 1) * (jpi - 2*nn_hls)
+         IF( ijarea == jpnj ) jpj = jpjglo - (jpnj - 1) * (jpj - 2*nn_hls)
 #else
-         jpi = ( jpiglo     -2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
-         jpj = ( jpjglo     -2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim.
-#endif
-      ENDIF
+         jpi = ( jpiglo     -2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
+         jpj = ( jpjglo     -2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.
+         jpimax  = jpi
+         jpjmax  = jpj
+         IF( iiarea > iirest ) jpi = jpi - 1
+         IF( ijarea > ijrest ) jpj = jpj - 1
+#endif
+      ENDIF
+
+      jpk = jpkglo                                             ! third dim
 
 #if defined key_agrif
@@ -350,29 +362,27 @@
 
       !                                      ! Domain decomposition
-      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
-      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
-      ENDIF
-      !
-      IF( nn_timing == 1 )  CALL timing_init
+      CALL mpp_init
+      !
+      IF( ln_timing    )   CALL timing_init
       !
       !                                     ! General initialization
-                            CALL phy_cst    ! Physical constants
-                            CALL eos_init   ! Equation of state
-                            CALL dom_init   ! Domain
-
-     IF( ln_nnogather )     CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
-
-      IF( ln_ctl      )     CALL prt_ctl_init   ! Print control
-                            CALL day_init   ! model calendar (using both namelist and restart infos)
+                           CALL phy_cst    ! Physical constants
+                           CALL eos_init   ! Equation of state
+                           CALL dom_init   ! Domain
+
+     IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
+
+      IF( ln_ctl      )    CALL prt_ctl_init   ! Print control
+                           CALL day_init   ! model calendar (using both namelist and restart infos)
       IF( ln_rstart )       CALL rst_read_open
 
-                            CALL sbc_init   ! Forcings : surface module 
-
-      ! ==> clem: open boundaries init. is mandatory for LIM3 because ice BDY is not decoupled from  
+                           CALL sbc_init   ! Forcings : surface module 
+
+      ! ==> clem: open boundaries init. is mandatory for sea-ice because ice BDY is not decoupled from  
       !           the environment of ocean BDY. Therefore bdy is called in both OPA and SAS modules. 
       !           This is not clean and should be changed in the future. 
-                            CALL bdy_init
+                           CALL bdy_init
       ! ==>
-                            CALL icb_init( rdt, nit000)   ! initialise icebergs instance
+                           CALL icb_init( rdt, nit000)   ! initialise icebergs instance
       
       IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
@@ -403,5 +413,6 @@
          WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
          WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
-         WRITE(numout,*) '      timing activated    (0/1)       nn_timing  = ', nn_timing
+         WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
+         WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
       ENDIF
       !
@@ -413,4 +424,9 @@
       isplt     = nn_isplt
       jsplt     = nn_jsplt
+!!gm to be remove at the end of the 2017 merge party
+      if( ln_timing ) then  ;  nn_timing = 1
+      else                  ;  nn_timing = 0
+      endif
+!!gm end
 
       IF(lwp) THEN                  ! control print
@@ -508,5 +524,5 @@
       USE dom_oce   , ONLY: dom_oce_alloc
       USE bdy_oce   , ONLY: ln_bdy, bdy_oce_alloc
-      USE oce         ! clem: mandatory for LIM3 because needed for bdy arrays
+      USE oce       ! mandatory for sea-ice because needed for bdy arrays
       !
       INTEGER :: ierr
@@ -515,5 +531,5 @@
       ierr =        dia_wri_alloc   ()
       ierr = ierr + dom_oce_alloc   ()          ! ocean domain
-      ierr = ierr + oce_alloc       ()          ! (tsn...) needed for agrif and/or lim3 and bdy
+      ierr = ierr + oce_alloc       ()          ! (tsn...) needed for agrif and/or ESIM and bdy
       ierr = ierr + bdy_oce_alloc   ()          ! bdy masks (incl. initialization)
       !
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAS_SRC/sbcssm.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAS_SRC/sbcssm.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAS_SRC/sbcssm.F90	(revision 9019)
@@ -114,6 +114,6 @@
          ENDIF
       ELSE
-         sst_m(:,:) = 0._wp
-         sss_m(:,:) = 0._wp
+         sss_m(:,:) = 35._wp                             ! =35. to obtain a physical value for the freezing point
+         CALL eos_fzp( sss_m(:,:), sst_m(:,:) )          ! sst_m is set at the freezing point
          ssu_m(:,:) = 0._wp
          ssv_m(:,:) = 0._wp
@@ -313,5 +313,5 @@
    ENDIF
  
-      CALL sbc_ssm( nit000 )   ! need to define ss?_m arrays used in limistate
+      CALL sbc_ssm( nit000 )   ! need to define ss?_m arrays used in iceistate
       l_initdone = .TRUE.
       !
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAS_SRC/step.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAS_SRC/step.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAS_SRC/step.F90	(revision 9019)
@@ -24,5 +24,5 @@
    USE diawri           ! Standard run outputs             (dia_wri routine)
    USE bdy_oce   , ONLY: ln_bdy
-   USE bdydta           ! clem: mandatory for LIM3
+   USE bdydta           ! mandatory for sea-ice
    USE stpctl           ! time stepping control            (stp_ctl routine)
    !
@@ -37,5 +37,5 @@
 
 #if defined key_agrif
-   USE agrif_oce, ONLY: lk_agrif_debug  !clem
+   USE agrif_oce, ONLY: lk_agrif_debug
 #endif
    
@@ -89,5 +89,5 @@
                              CALL iom_setkt( kstp - nit000 + 1, cxios_context )   ! tell iom we are at time step kstp
 
-      ! ==> clem: open boundaries is mandatory for LIM3 because ice BDY is not decoupled from  
+      ! ==> clem: open boundaries is mandatory for sea-ice because ice BDY is not decoupled from  
       !           the environment of ocean BDY. Therefore bdy is called in both OPA and SAS modules.
       !           From SAS: ocean bdy data are wrong  (but we do not care) and ice bdy data are OK.  
@@ -114,5 +114,5 @@
                              CALL dia_wri_state( 'output.abort', kstp )
       ENDIF
-      IF( kstp == nit000   ) CALL iom_close( numror )     ! close input  ocean restart file (clem: not sure...)
+      IF( kstp == nit000   ) CALL iom_close( numror )     ! close input  ocean restart file
       
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -127,5 +127,5 @@
 #endif
       !
-      IF( nn_timing == 1 .AND.  kstp == nit000  )   CALL timing_reset
+      IF( ln_timing .AND.  kstp == nit000  )   CALL timing_reset
       !
    END SUBROUTINE stp
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zopt.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zopt.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zopt.F90	(revision 9019)
@@ -119,5 +119,5 @@
       !                                          ! --------------
       neln(:,:) = 1                                   ! euphotic layer level
-      DO jk = 1, jpkm1                                  ! (i.e. 1rst T-level strictly below EL bottom)
+      DO jk = 1, jpkm1                                ! (i.e. 1rst T-level strictly below EL bottom)
          DO jj = 1, jpj
            DO ji = 1, jpi
@@ -147,4 +147,5 @@
    END SUBROUTINE p2z_opt
 
+
    SUBROUTINE p2z_opt_init
       !!----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcadv.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcadv.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcadv.F90	(revision 9019)
@@ -7,4 +7,5 @@
    !!            3.0  !  2010-06  (C. Ethe)   Adapted to passive tracers
    !!            3.7  !  2014-05  (G. Madec, C. Ethe)  Add 2nd/4th order cases for CEN and FCT schemes 
+   !!            4.0  !  2017-09  (G. Madec)  remove vertical time-splitting option
    !!----------------------------------------------------------------------
 #if defined key_top
@@ -17,4 +18,6 @@
    USE oce_trc        ! ocean dynamics and active tracers
    USE trc            ! ocean passive tracers variables
+   USE sbcwave        ! wave module
+   USE sbc_oce        ! surface boundary condition: ocean
    USE traadv_cen     ! centered scheme           (tra_adv_cen  routine)
    USE traadv_fct     ! FCT      scheme           (tra_adv_fct  routine)
@@ -23,21 +26,22 @@
    USE traadv_qck     ! QUICKEST scheme           (tra_adv_qck  routine)
    USE traadv_mle     ! ML eddy induced velocity  (tra_adv_mle  routine)
-   USE ldftra         ! lateral diffusion coefficient on tracers
+   USE ldftra         ! lateral diffusion: eddy diffusivity & EIV coeff.
    USE ldfslp         ! Lateral diffusion: slopes of neutral surfaces
    !
-   USE prtctl_trc     ! Print control
+   USE prtctl_trc     ! control print
+   USE timing         ! Timing
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   trc_adv       
-   PUBLIC   trc_adv_ini  
+   PUBLIC   trc_adv       ! called by trctrp.F90
+   PUBLIC   trc_adv_ini   ! called by trcini.F90
 
    !                            !!* Namelist namtrc_adv *
+   LOGICAL ::   ln_trcadv_NONE   ! no advection on passive tracers
    LOGICAL ::   ln_trcadv_cen    ! centered scheme flag
    INTEGER ::      nn_cen_h, nn_cen_v   ! =2/4 : horizontal and vertical choices of the order of CEN scheme
    LOGICAL ::   ln_trcadv_fct    ! FCT scheme flag
    INTEGER ::      nn_fct_h, nn_fct_v   ! =2/4 : horizontal and vertical choices of the order of FCT scheme
-   INTEGER ::      nn_fct_zts           ! >=1 : 2nd order FCT with vertical sub-timestepping
    LOGICAL ::   ln_trcadv_mus    ! MUSCL scheme flag
    LOGICAL ::      ln_mus_ups           ! use upstream scheme in vivcinity of river mouths
@@ -46,21 +50,19 @@
    LOGICAL ::   ln_trcadv_qck    ! QUICKEST scheme flag
 
-   !                                        ! choices of advection scheme:
+   INTEGER ::   nadv             ! choice of the type of advection scheme
+   !                             ! associated indices:
    INTEGER, PARAMETER ::   np_NO_adv  = 0   ! no T-S advection
    INTEGER, PARAMETER ::   np_CEN     = 1   ! 2nd/4th order centered scheme
    INTEGER, PARAMETER ::   np_FCT     = 2   ! 2nd/4th order Flux Corrected Transport scheme
-   INTEGER, PARAMETER ::   np_FCT_zts = 3   ! 2nd order FCT scheme with vertical sub-timestepping
-   INTEGER, PARAMETER ::   np_MUS     = 4   ! MUSCL scheme
-   INTEGER, PARAMETER ::   np_UBS     = 5   ! 3rd order Upstream Biased Scheme
-   INTEGER, PARAMETER ::   np_QCK     = 6   ! QUICK scheme
-
-   INTEGER ::              nadv             ! chosen advection scheme
-   !
+   INTEGER, PARAMETER ::   np_MUS     = 3   ! MUSCL scheme
+   INTEGER, PARAMETER ::   np_UBS     = 4   ! 3rd order Upstream Biased Scheme
+   INTEGER, PARAMETER ::   np_QCK     = 5   ! QUICK scheme
+   
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/TOP 3.7 , NEMO Consortium (2015)
+   !! NEMO/TOP 4.0 , NEMO Consortium (2017)
    !! $Id$ 
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 CONTAINS
@@ -72,5 +74,5 @@
       !! ** Purpose :   compute the ocean tracer advection trend.
       !!
-      !! ** Method  : - Update the tracer with the advection term following nadv
+      !! ** Method  : - Update after tracers (tra) with the advection term following nadv
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
@@ -78,22 +80,31 @@
       INTEGER ::   jk   ! dummy loop index
       CHARACTER (len=22) ::   charout
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zun, zvn, zwn  ! effective velocity
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )   CALL timing_start('trc_adv')
-      !
-      CALL wrk_alloc( jpi,jpj,jpk,   zun, zvn, zwn )
-      !                                               !==  effective transport  ==!
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zun, zvn, zwn  ! effective velocity
+      !!----------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('trc_adv')
+      !
+      !                                         !==  effective transport  ==!
       IF( l_offline ) THEN
-         zun(:,:,:) = un(:,:,:)     ! effective transport already in un/vn/wn
+         zun(:,:,:) = un(:,:,:)                    ! already in (un,vn,wn)
          zvn(:,:,:) = vn(:,:,:)
          zwn(:,:,:) = wn(:,:,:)
-      ELSE
-         !       
-         DO jk = 1, jpkm1
-            zun(:,:,jk) = e2u  (:,:) * e3u_n(:,:,jk) * un(:,:,jk)                   ! eulerian transport
-            zvn(:,:,jk) = e1v  (:,:) * e3v_n(:,:,jk) * vn(:,:,jk)
-            zwn(:,:,jk) = e1e2t(:,:)                 * wn(:,:,jk)
-         END DO
+      ELSE                                         ! build the effective transport
+         zun(:,:,jpk) = 0._wp
+         zvn(:,:,jpk) = 0._wp
+         zwn(:,:,jpk) = 0._wp
+         IF( ln_wave .AND. ln_sdw )  THEN
+            DO jk = 1, jpkm1                                                       ! eulerian transport + Stokes Drift
+               zun(:,:,jk) = e2u  (:,:) * e3u_n(:,:,jk) * ( un(:,:,jk) + usd(:,:,jk) )
+               zvn(:,:,jk) = e1v  (:,:) * e3v_n(:,:,jk) * ( vn(:,:,jk) + vsd(:,:,jk) )
+               zwn(:,:,jk) = e1e2t(:,:)                 * ( wn(:,:,jk) + wsd(:,:,jk) )
+            END DO
+         ELSE
+            DO jk = 1, jpkm1
+               zun(:,:,jk) = e2u  (:,:) * e3u_n(:,:,jk) * un(:,:,jk)                   ! eulerian transport
+               zvn(:,:,jk) = e1v  (:,:) * e3v_n(:,:,jk) * vn(:,:,jk)
+               zwn(:,:,jk) = e1e2t(:,:)                 * wn(:,:,jk)
+            END DO
+         ENDIF
          !
          IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN                                 ! add z-tilde and/or vvl corrections
@@ -107,35 +118,28 @@
          IF( ln_mle    )   CALL tra_adv_mle( kt, nittrc000, zun, zvn, zwn, 'TRC' )  ! add the mle transport
          !
-         zun(:,:,jpk) = 0._wp                                                       ! no transport trough the bottom
-         zvn(:,:,jpk) = 0._wp
-         zwn(:,:,jpk) = 0._wp
-         !
       ENDIF
       !
       SELECT CASE ( nadv )                      !==  compute advection trend and add it to general trend  ==!
       !
-      CASE ( np_CEN )                                    ! Centered : 2nd / 4th order
-         CALL tra_adv_cen    ( kt, nittrc000,'TRC',       zun, zvn, zwn     , trn, tra, jptra, nn_cen_h, nn_cen_v )
-      CASE ( np_FCT )                                    ! FCT      : 2nd / 4th order
-         CALL tra_adv_fct    ( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb, trn, tra, jptra, nn_fct_h, nn_fct_v )
-      CASE ( np_FCT_zts )                                ! 2nd order FCT with vertical time-splitting
-         CALL tra_adv_fct_zts( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb, trn, tra, jptra        , nn_fct_zts )
-      CASE ( np_MUS )                                    ! MUSCL
-         CALL tra_adv_mus    ( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb,      tra, jptra        , ln_mus_ups ) 
-      CASE ( np_UBS )                                    ! UBS
-         CALL tra_adv_ubs    ( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb, trn, tra, jptra        , nn_ubs_v   )
-      CASE ( np_QCK )                                    ! QUICKEST
-         CALL tra_adv_qck    ( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb, trn, tra, jptra                     )
+      CASE ( np_CEN )                                 ! Centered : 2nd / 4th order
+         CALL tra_adv_cen( kt, nittrc000,'TRC',          zun, zvn, zwn     , trn, tra, jptra, nn_cen_h, nn_cen_v )
+      CASE ( np_FCT )                                 ! FCT      : 2nd / 4th order
+         CALL tra_adv_fct( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb, trn, tra, jptra, nn_fct_h, nn_fct_v )
+      CASE ( np_MUS )                                 ! MUSCL
+         CALL tra_adv_mus( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb,      tra, jptra        , ln_mus_ups ) 
+      CASE ( np_UBS )                                 ! UBS
+         CALL tra_adv_ubs( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb, trn, tra, jptra          , nn_ubs_v )
+      CASE ( np_QCK )                                 ! QUICKEST
+         CALL tra_adv_qck( kt, nittrc000,'TRC', r2dttrc, zun, zvn, zwn, trb, trn, tra, jptra                     )
       !
       END SELECT
       !                  
-      IF( ln_ctl )   THEN                             !== print mean trends (used for debugging)
-         WRITE(charout, FMT="('adv ')")  ;  CALL prt_ctl_trc_info(charout)
-                                            CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
+      IF( ln_ctl ) THEN                         !== print mean trends (used for debugging)
+         WRITE(charout, FMT="('adv ')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
       END IF
       !
-      CALL wrk_dealloc( jpi,jpj,jpk,   zun, zvn, zwn )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('trc_adv')
+      IF( ln_timing )   CALL timing_stop('trc_adv')
       !
    END SUBROUTINE trc_adv
@@ -146,5 +150,5 @@
       !!                  ***  ROUTINE trc_adv_ini  ***
       !!                
-      !! ** Purpose : Control the consistency between namelist options for 
+      !! ** Purpose :   Control the consistency between namelist options for 
       !!              passive tracer advection schemes and set nadv
       !!----------------------------------------------------------------------
@@ -152,25 +156,28 @@
       INTEGER ::  ios                 ! Local integer output status for namelist read
       !!
-      NAMELIST/namtrc_adv/ ln_trcadv_cen, nn_cen_h, nn_cen_v,               &   ! CEN
-         &                 ln_trcadv_fct, nn_fct_h, nn_fct_v, nn_fct_zts,   &   ! FCT
-         &                 ln_trcadv_mus,                     ln_mus_ups,   &   ! MUSCL
-         &                 ln_trcadv_ubs,           nn_ubs_v,               &   ! UBS
-         &                 ln_trcadv_qck                                        ! QCK
-      !!----------------------------------------------------------------------
-      !
-      REWIND( numnat_ref )              !  namtrc_adv in reference namelist 
+      NAMELIST/namtrc_adv/ ln_trcadv_NONE,                       &   ! No advection
+         &                 ln_trcadv_cen, nn_cen_h, nn_cen_v,    &   ! CEN
+         &                 ln_trcadv_fct, nn_fct_h, nn_fct_v,    &   ! FCT
+         &                 ln_trcadv_mus, ln_mus_ups,            &   ! MUSCL
+         &                 ln_trcadv_ubs,           nn_ubs_v,    &   ! UBS
+         &                 ln_trcadv_qck                             ! QCK
+      !!----------------------------------------------------------------------
+      !
+      !                                !==  Namelist  ==!
+      REWIND( numnat_ref )                   !  namtrc_adv in reference namelist 
       READ  ( numnat_ref, namtrc_adv, IOSTAT = ios, ERR = 901)
 901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_adv in reference namelist', lwp )
-
-      REWIND( numnat_cfg )              ! namtrc_adv in configuration namelist
+      !
+      REWIND( numnat_cfg )                   ! namtrc_adv in configuration namelist
       READ  ( numnat_cfg, namtrc_adv, IOSTAT = ios, ERR = 902 )
 902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_adv in configuration namelist', lwp )
       IF(lwm) WRITE ( numont, namtrc_adv )
-
-      IF(lwp) THEN                    ! Namelist print
+      !
+      IF(lwp) THEN                           ! Namelist print
          WRITE(numout,*)
          WRITE(numout,*) 'trc_adv_ini : choice/control of the tracer advection scheme'
          WRITE(numout,*) '~~~~~~~~~~~'
          WRITE(numout,*) '   Namelist namtrc_adv : chose a advection scheme for tracers'
+         WRITE(numout,*) '      No advection on passive tracers           ln_trcadv_NONE= ', ln_trcadv_NONE
          WRITE(numout,*) '      centered scheme                           ln_trcadv_cen = ', ln_trcadv_cen
          WRITE(numout,*) '            horizontal 2nd/4th order               nn_cen_h   = ', nn_fct_h
@@ -179,5 +186,4 @@
          WRITE(numout,*) '            horizontal 2nd/4th order               nn_fct_h   = ', nn_fct_h
          WRITE(numout,*) '            vertical   2nd/4th order               nn_fct_v   = ', nn_fct_v
-         WRITE(numout,*) '            2nd order + vertical sub-timestepping  nn_fct_zts = ', nn_fct_zts
          WRITE(numout,*) '      MUSCL scheme                              ln_trcadv_mus = ', ln_trcadv_mus
          WRITE(numout,*) '            + upstream scheme near river mouths    ln_mus_ups = ', ln_mus_ups
@@ -187,81 +193,51 @@
       ENDIF
       !
-
-      ioptio = 0                       !==  Parameter control  ==!
-      IF( ln_trcadv_cen )   ioptio = ioptio + 1
-      IF( ln_trcadv_fct )   ioptio = ioptio + 1
-      IF( ln_trcadv_mus )   ioptio = ioptio + 1
-      IF( ln_trcadv_ubs )   ioptio = ioptio + 1
-      IF( ln_trcadv_qck )   ioptio = ioptio + 1
-
-      !
-      IF( ioptio == 0 ) THEN
-         nadv = np_NO_adv
-         CALL ctl_warn( 'trc_adv_init: You are running without tracer advection.' )
-      ENDIF
-      IF( ioptio /= 1 )   CALL ctl_stop( 'Choose ONE advection scheme in namelist namtrc_adv' )
+      !                                !==  Parameter control & set nadv ==!
+      ioptio = 0
+      IF( ln_trcadv_NONE ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_NO_adv   ;   ENDIF
+      IF( ln_trcadv_cen  ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_CEN      ;   ENDIF
+      IF( ln_trcadv_fct  ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_FCT      ;   ENDIF
+      IF( ln_trcadv_mus  ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_MUS      ;   ENDIF
+      IF( ln_trcadv_ubs  ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_UBS      ;   ENDIF
+      IF( ln_trcadv_qck  ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_QCK      ;   ENDIF
+      !
+      IF( ioptio /= 1 )   CALL ctl_stop( 'trc_adv_ini: Choose ONE advection option in namelist namtrc_adv' )
       !
       IF( ln_trcadv_cen .AND. ( nn_cen_h /= 2 .AND. nn_cen_h /= 4 )   &
                         .AND. ( nn_cen_v /= 2 .AND. nn_cen_v /= 4 )   ) THEN
-        CALL ctl_stop( 'trc_adv_init: CEN scheme, choose 2nd or 4th order' )
+        CALL ctl_stop( 'trc_adv_ini: CEN scheme, choose 2nd or 4th order' )
       ENDIF
       IF( ln_trcadv_fct .AND. ( nn_fct_h /= 2 .AND. nn_fct_h /= 4 )   &
                         .AND. ( nn_fct_v /= 2 .AND. nn_fct_v /= 4 )   ) THEN
-        CALL ctl_stop( 'trc_adv_init: FCT scheme, choose 2nd or 4th order' )
-      ENDIF
-      IF( ln_trcadv_fct .AND. nn_fct_zts > 0 ) THEN
-         IF( nn_fct_h == 4 ) THEN
-            nn_fct_h = 2
-            CALL ctl_stop( 'trc_adv_init: force 2nd order FCT scheme, 4th order does not exist with sub-timestepping' )
-         ENDIF
-         IF( .NOT.ln_linssh ) THEN
-            CALL ctl_stop( 'trc_adv_init: vertical sub-timestepping not allow in non-linear free surface' )
-         ENDIF
-         IF( nn_fct_zts == 1 )   CALL ctl_warn( 'trc_adv_init: FCT with ONE sub-timestep = FCT without sub-timestep' )
+        CALL ctl_stop( 'trc_adv_ini: FCT scheme, choose 2nd or 4th order' )
       ENDIF
       IF( ln_trcadv_ubs .AND. ( nn_ubs_v /= 2 .AND. nn_ubs_v /= 4 )   ) THEN
-        CALL ctl_stop( 'trc_adv_init: UBS scheme, choose 2nd or 4th order' )
+        CALL ctl_stop( 'trc_adv_ini: UBS scheme, choose 2nd or 4th order' )
       ENDIF
       IF( ln_trcadv_ubs .AND. nn_ubs_v == 4 ) THEN
-         CALL ctl_warn( 'trc_adv_init: UBS scheme, only 2nd FCT scheme available on the vertical. It will be used' )
+         CALL ctl_warn( 'trc_adv_ini: UBS scheme, only 2nd FCT scheme available on the vertical. It will be used' )
       ENDIF
       IF( ln_isfcav ) THEN                                                       ! ice-shelf cavities
-         IF(  ln_trcadv_cen .AND. nn_cen_v /= 4    .OR.   &                            ! NO 4th order with ISF
-            & ln_trcadv_fct .AND. nn_fct_v /= 4   )   CALL ctl_stop( 'tra_adv_init: 4th order COMPACT scheme not allowed with ISF' )
-      ENDIF
-      !
-      !                                !==  used advection scheme  ==!
-      !                                      ! set nadv
-      IF( ln_trcadv_cen                      )   nadv = np_CEN
-      IF( ln_trcadv_fct                      )   nadv = np_FCT
-      IF( ln_trcadv_fct .AND. nn_fct_zts > 0 )   nadv = np_FCT_zts
-      IF( ln_trcadv_mus                      )   nadv = np_MUS
-      IF( ln_trcadv_ubs                      )   nadv = np_UBS
-      IF( ln_trcadv_qck                      )   nadv = np_QCK
-      !
-      IF(lwp) THEN                   ! Print the choice
+         IF(  ln_trcadv_cen .AND. nn_cen_v == 4    .OR.   &                            ! NO 4th order with ISF
+            & ln_trcadv_fct .AND. nn_fct_v == 4   )   CALL ctl_stop( 'tra_adv_ini: 4th order COMPACT scheme not allowed with ISF' )
+      ENDIF
+      !
+      !                                !==  Print the choice  ==!  
+      IF(lwp) THEN
          WRITE(numout,*)
-         IF( nadv == np_NO_adv  )   WRITE(numout,*) '         NO passive tracer advection'
-         IF( nadv == np_CEN     )   WRITE(numout,*) '         CEN      scheme is used. Horizontal order: ', nn_cen_h,   &
-            &                                                                        ' Vertical   order: ', nn_cen_v
-         IF( nadv == np_FCT     )   WRITE(numout,*) '         FCT      scheme is used. Horizontal order: ', nn_fct_h,   &
-            &                                                                       ' Vertical   order: ', nn_fct_v
-         IF( nadv == np_FCT_zts )   WRITE(numout,*) '         use 2nd order FCT with ', nn_fct_zts,'vertical sub-timestepping'
-         IF( nadv == np_MUS     )   WRITE(numout,*) '         MUSCL    scheme is used'
-         IF( nadv == np_UBS     )   WRITE(numout,*) '         UBS      scheme is used'
-         IF( nadv == np_QCK     )   WRITE(numout,*) '         QUICKEST scheme is used'
+         SELECT CASE ( nadv )
+         CASE( np_NO_adv  )   ;   WRITE(numout,*) '      ===>>   NO passive tracer advection'
+         CASE( np_CEN     )   ;   WRITE(numout,*) '      ===>>   CEN      scheme is used. Horizontal order: ', nn_cen_h,   &
+            &                                                                     ' Vertical   order: ', nn_cen_v
+         CASE( np_FCT     )   ;   WRITE(numout,*) '      ===>>   FCT      scheme is used. Horizontal order: ', nn_fct_h,   &
+            &                                                                      ' Vertical   order: ', nn_fct_v
+         CASE( np_MUS     )   ;   WRITE(numout,*) '      ===>>   MUSCL    scheme is used'
+         CASE( np_UBS     )   ;   WRITE(numout,*) '      ===>>   UBS      scheme is used'
+         CASE( np_QCK     )   ;   WRITE(numout,*) '      ===>>   QUICKEST scheme is used'
+         END SELECT
       ENDIF
       !
    END SUBROUTINE trc_adv_ini
    
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                                         Empty module
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE trc_adv( kt )
-      INTEGER, INTENT(in) :: kt
-      WRITE(*,*) 'trc_adv: You should not have seen this print! error?', kt
-   END SUBROUTINE trc_adv
 #endif
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcbbl.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcbbl.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcbbl.F90	(revision 9019)
@@ -5,5 +5,4 @@
    !!                                  layer scheme
    !!======================================================================
-   !!==============================================================================
    !! History :  OPA  !  1996-06  (L. Mortier)  Original code
    !!            8.0  !  1997-11  (G. Madec)    Optimization
@@ -13,28 +12,27 @@
    !!             -   !  2010-04  (G. Madec)  Campin & Goosse advective bbl 
    !!             -   !  2010-06  (C. Ethe, G. Madec)  merge TRA-TRC
+   !!            4.0  !  2017-04  (G. Madec)  ln_trabbl namelist variable instead of a CPP key
    !!----------------------------------------------------------------------
-#if  defined key_top &&  defined key_trabbl 
+#if  defined key_top
    !!----------------------------------------------------------------------
-   !!   'key_trabbl                      diffusive or/and adevective bottom boundary layer
+   !!   'key_top'                                                TOP models
    !!----------------------------------------------------------------------
-   !!    trc_bbl       : update the tracer trends due to the bottom boundary layer (advective and/or diffusive)
+   !!    trc_bbl      : update the tracer trends due to the bottom boundary layer (advective and/or diffusive)
    !!----------------------------------------------------------------------
-   USE oce_trc             ! ocean dynamics and active tracers variables
-   USE trc                 ! ocean passive tracers variables
-   USE trabbl              ! 
-   USE prtctl_trc          ! Print control for debbuging
-   USE trd_oce
-   USE trdtra
+   USE oce_trc        ! ocean dynamics and active tracers variables
+   USE trc            ! ocean passive tracers variables
+   USE trd_oce        ! trends: ocean variables
+   USE trdtra         ! tracer trends
+   USE trabbl         ! bottom boundary layer 
+   USE prtctl_trc     ! Print control for debbuging
 
-   PUBLIC   trc_bbl       !  routine called by step.F90
+   PUBLIC   trc_bbl   !  routine called by trctrp.F90
 
    !!----------------------------------------------------------------------
-   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! NEMO/TOP 4.0 , NEMO Consortium (2017)
    !! $Id$ 
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
-
 
    SUBROUTINE trc_bbl( kt )
@@ -73,5 +71,5 @@
          ENDIF
          !
-      END IF
+      ENDIF
 
       !* Advective bbl : bbl upstream advective trends added to the tracer trends
@@ -84,5 +82,5 @@
          ENDIF
          !
-      END IF
+      ENDIF
 
       IF( l_trdtrc )   THEN                      ! save the horizontal diffusive trends for further diagnostics
@@ -98,12 +96,4 @@
    END SUBROUTINE trc_bbl
 
-#else
-   !!----------------------------------------------------------------------
-   !!   Dummy module :                      No bottom boundary layer scheme
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE trc_bbl( kt )              ! Empty routine
-      WRITE(*,*) 'tra_bbl: You should not have seen this print! error?', kt
-   END SUBROUTINE trc_bbl
 #endif
 
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcdmp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcdmp.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcdmp.F90	(revision 9019)
@@ -121,5 +121,5 @@
                      DO jj = 2, jpjm1
                         DO ji = fs_2, fs_jpim1   ! vector opt.
-                           IF( avt(ji,jj,jk) <= 5.e-4_wp )  THEN 
+                           IF( avs(ji,jj,jk) <= 5.e-4_wp )  THEN 
                               tra(ji,jj,jk,jn) = tra(ji,jj,jk,jn) + restotr(ji,jj,jk) * ( ztrcdta(ji,jj,jk) - trb(ji,jj,jk,jn) )
                            ENDIF
@@ -222,5 +222,5 @@
          !
       ENDIF
-      IF( nn_timing == 1 )  CALL timing_stop('trc_dmp_init')
+      IF( nn_timing == 1 )  CALL timing_stop('trc_dmp_ini')
       !
    END SUBROUTINE trc_dmp_ini
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcldf.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcldf.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcldf.F90	(revision 9019)
@@ -17,5 +17,6 @@
    USE trc            ! ocean passive tracers variables
    USE oce_trc        ! ocean dynamics and active tracers
-   USE ldfslp         ! lateral diffusion: iso-neutral slope
+   USE ldftra         ! lateral diffusion: eddy diffusivity & EIV coeff.
+   USE ldfslp         ! Lateral diffusion: slopes of neutral surfaces
    USE traldf_lap_blp ! lateral diffusion: lap/bilaplacian iso-level      operator  (tra_ldf_lap/_blp   routine)
    USE traldf_iso     ! lateral diffusion: laplacian iso-neutral standard operator  (tra_ldf_iso        routine)
@@ -32,4 +33,5 @@
    PUBLIC   trc_ldf_ini   
    !
+   LOGICAL , PUBLIC ::   ln_trcldf_NONE      !: No operator (no explicit lateral diffusion)
    LOGICAL , PUBLIC ::   ln_trcldf_lap       !:   laplacian operator
    LOGICAL , PUBLIC ::   ln_trcldf_blp       !: bilaplacian operator
@@ -45,5 +47,5 @@
    REAL(wp) ::  rldf       ! ratio between active and passive tracers diffusive coefficient
    
-   INTEGER  ::  nldf = 0   ! type of lateral diffusion used defined from ln_trcldf_... namlist logicals)
+   INTEGER  ::  nldf       ! type of lateral diffusion used defined from ln_trcldf_... namlist logicals)
    
    !! * Substitutions
@@ -98,14 +100,10 @@
       CASE ( np_lap   )                               ! iso-level laplacian
          CALL tra_ldf_lap  ( kt, nittrc000,'TRC', zahu, zahv, gtru, gtrv, gtrui, gtrvi, trb,      tra, jptra,  1   )
-         !
       CASE ( np_lap_i )                               ! laplacian : standard iso-neutral operator (Madec)
          CALL tra_ldf_iso  ( kt, nittrc000,'TRC', zahu, zahv, gtru, gtrv, gtrui, gtrvi, trb, trb, tra, jptra,  1   )
-         !
       CASE ( np_lap_it )                              ! laplacian : triad iso-neutral operator (griffies)
          CALL tra_ldf_triad( kt, nittrc000,'TRC', zahu, zahv, gtru, gtrv, gtrui, gtrvi, trb, trb, tra, jptra,  1   )
-         !
       CASE ( np_blp , np_blp_i , np_blp_it )          ! bilaplacian: all operator (iso-level, -neutral)
          CALL tra_ldf_blp  ( kt, nittrc000,'TRC', zahu, zahv, gtru, gtrv, gtrui, gtrvi, trb     , tra, jptra, nldf )
-         !
       END SELECT
       !
@@ -148,5 +146,5 @@
       NAMELIST/namtrc_ldf/ ln_trcldf_lap, ln_trcldf_blp,                                  &
          &                 ln_trcldf_lev, ln_trcldf_hor, ln_trcldf_iso, ln_trcldf_triad,  &
-         &                 rn_ahtrc_0   , rn_bhtrc_0, rn_fact_lap  
+         &                 rn_ahtrc_0   , rn_bhtrc_0   , rn_fact_lap  
       !!----------------------------------------------------------------------
       !
@@ -166,4 +164,5 @@
          WRITE(numout,*) '   Namelist namtrc_ldf : set lateral mixing parameters (type, direction, coefficients)'
          WRITE(numout,*) '      operator'
+         WRITE(numout,*) '         no explicit diffusion       ln_trcldf_NONE  = ', ln_trcldf_NONE
          WRITE(numout,*) '           laplacian                 ln_trcldf_lap   = ', ln_trcldf_lap
          WRITE(numout,*) '         bilaplacian                 ln_trcldf_blp   = ', ln_trcldf_blp
@@ -182,85 +181,88 @@
       !                                ! control the namelist parameters
       ioptio = 0
-      IF( ln_trcldf_lap )   ioptio = ioptio + 1
-      IF( ln_trcldf_blp )   ioptio = ioptio + 1
-      IF( ioptio >  1   )   CALL ctl_stop( 'trc_ldf_ctl: use ONE or NONE of the 2 lap/bilap operator type on tracer' )
-      IF( ioptio == 0   )   nldf = np_no_ldf   ! No lateral diffusion
+      IF( ln_trcldf_NONE ) THEN   ;   nldf = np_no_ldf   ;   ioptio = ioptio + 1   ;   ENDIF
+      IF( ln_trcldf_lap  ) THEN   ;                          ioptio = ioptio + 1   ;   ENDIF
+      IF( ln_trcldf_blp  ) THEN   ;                          ioptio = ioptio + 1   ;   ENDIF
+      IF( ioptio /=  1   )   CALL ctl_stop( 'trc_ldf_ini: use ONE of the 3 operator options (NONE/lap/blp)' )
       
-      IF( ln_trcldf_lap .AND. ln_trcldf_blp )   CALL ctl_stop( 'trc_ldf_ctl: bilaplacian should be used on both TRC and TRA' )
-      IF( ln_trcldf_blp .AND. ln_trcldf_lap )   CALL ctl_stop( 'trc_ldf_ctl:   laplacian should be used on both TRC and TRA' )
-      !
-      ioptio = 0
-      IF( ln_trcldf_lev )   ioptio = ioptio + 1
-      IF( ln_trcldf_hor )   ioptio = ioptio + 1
-      IF( ln_trcldf_iso )   ioptio = ioptio + 1
-      IF( ioptio /= 1   )   CALL ctl_stop( 'trc_ldf_ctl: use only ONE direction (level/hor/iso)' )
-      !
-      ! defined the type of lateral diffusion from ln_trcldf_... logicals
-      ! CAUTION : nldf = 1 is used in trazdf_imp, change it carefully
-      ierr = 0
-      IF( ln_trcldf_lap ) THEN      !==  laplacian operator  ==!
-         IF ( ln_zco ) THEN                ! z-coordinate
-            IF ( ln_trcldf_lev   )   nldf = np_lap     ! iso-level = horizontal (no rotation)
-            IF ( ln_trcldf_hor   )   nldf = np_lap     ! iso-level = horizontal (no rotation)
-            IF ( ln_trcldf_iso   )   nldf = np_lap_i   ! iso-neutral: standard  (   rotation)
-            IF ( ln_trcldf_triad )   nldf = np_lap_it  ! iso-neutral: triad     (   rotation)
+      IF( ln_trcldf_lap .AND. .NOT.ln_traldf_lap )   CALL ctl_stop( 'trc_ldf_ini:   laplacian should be used on both TRC and TRA' )
+      IF( ln_trcldf_blp .AND. .NOT.ln_traldf_blp )   CALL ctl_stop( 'trc_ldf_ini: bilaplacian should be used on both TRC and TRA' )
+      !
+      IF( .NOT.ln_trcldf_NONE ) THEN   ! direction ==>> type of operator 
+         ioptio = 0
+         IF( ln_trcldf_lev )   ioptio = ioptio + 1
+         IF( ln_trcldf_hor )   ioptio = ioptio + 1
+         IF( ln_trcldf_iso )   ioptio = ioptio + 1
+         IF( ioptio /= 1   )   CALL ctl_stop( 'trc_ldf_ini: use ONE direction (level/hor/iso)' )
+         !
+         ! defined the type of lateral diffusion from ln_trcldf_... logicals
+         ! CAUTION : nldf = 1 is used in trazdf_imp, change it carefully
+         ierr = 0
+         IF( ln_trcldf_lap ) THEN      !==  laplacian operator  ==!
+            IF( ln_zco ) THEN                ! z-coordinate
+               IF( ln_trcldf_lev   )   nldf = np_lap     ! iso-level = horizontal (no rotation)
+               IF( ln_trcldf_hor   )   nldf = np_lap     ! iso-level = horizontal (no rotation)
+               IF( ln_trcldf_iso   )   nldf = np_lap_i   ! iso-neutral: standard  (   rotation)
+               IF( ln_trcldf_triad )   nldf = np_lap_it  ! iso-neutral: triad     (   rotation)
+            ENDIF
+            IF( ln_zps ) THEN             ! z-coordinate with partial step
+               IF( ln_trcldf_lev   )   ierr = 1          ! iso-level not allowed 
+               IF( ln_trcldf_hor   )   nldf = np_lap     ! horizontal (no rotation)
+               IF( ln_trcldf_iso   )   nldf = np_lap_i   ! iso-neutral: standard (rotation)
+               IF( ln_trcldf_triad )   nldf = np_lap_it  ! iso-neutral: triad    (rotation)
+            ENDIF
+            IF( ln_sco ) THEN             ! s-coordinate
+               IF( ln_trcldf_lev   )   nldf = np_lap     ! iso-level  (no rotation)
+               IF( ln_trcldf_hor   )   nldf = np_lap_it  ! horizontal (   rotation)       !!gm   a checker....
+               IF( ln_trcldf_iso   )   nldf = np_lap_i   ! iso-neutral: standard (rotation)
+               IF( ln_trcldf_triad )   nldf = np_lap_it  ! iso-neutral: triad    (rotation)
+            ENDIF
+            !                                ! diffusivity ratio: passive / active tracers 
+            IF( ABS(rn_aht_0) < 2._wp*TINY(1._wp) ) THEN
+               IF( ABS(rn_ahtrc_0) < 2._wp*TINY(1._wp) ) THEN
+                  rldf = 1.0_wp
+               ELSE
+                  CALL ctl_stop( 'trc_ldf_ctl : cannot define rldf, rn_aht_0==0, rn_ahtrc_0 /=0' )
+               ENDIF
+            ELSE
+               rldf = rn_ahtrc_0 / rn_aht_0
+            ENDIF
          ENDIF
-         IF ( ln_zps ) THEN             ! z-coordinate with partial step
-            IF ( ln_trcldf_lev   )   ierr = 1         ! iso-level not allowed 
-            IF ( ln_trcldf_hor   )   nldf = np_lap     ! horizontal (no rotation)
-            IF ( ln_trcldf_iso   )   nldf = np_lap_i   ! iso-neutral: standard (rotation)
-            IF ( ln_trcldf_triad )   nldf = np_lap_it  ! iso-neutral: triad    (rotation)
+         !
+         IF( ln_trcldf_blp ) THEN      !==  bilaplacian operator  ==!
+            IF ( ln_zco ) THEN                ! z-coordinate
+               IF ( ln_trcldf_lev   )   nldf = np_blp     ! iso-level = horizontal (no rotation)
+               IF ( ln_trcldf_hor   )   nldf = np_blp     ! iso-level = horizontal (no rotation)
+               IF ( ln_trcldf_iso   )   nldf = np_blp_i   ! iso-neutral: standard (rotation)
+               IF ( ln_trcldf_triad )   nldf = np_blp_it  ! iso-neutral: triad    (rotation)
+            ENDIF
+            IF ( ln_zps ) THEN             ! z-coordinate with partial step
+               IF ( ln_trcldf_lev   )   ierr = 1         ! iso-level not allowed 
+               IF ( ln_trcldf_hor   )   nldf = np_blp     ! horizontal (no rotation)
+               IF ( ln_trcldf_iso   )   nldf = np_blp_i   ! iso-neutral: standard (rotation)
+               IF ( ln_trcldf_triad )   nldf = np_blp_it  ! iso-neutral: triad    (rotation)
+            ENDIF
+            IF ( ln_sco ) THEN             ! s-coordinate
+               IF ( ln_trcldf_lev   )   nldf = np_blp     ! iso-level  (no rotation)
+               IF ( ln_trcldf_hor   )   nldf = np_blp_it  ! horizontal (   rotation)       !!gm   a checker....
+               IF ( ln_trcldf_iso   )   nldf = np_blp_i   ! iso-neutral: standard (rotation)
+               IF ( ln_trcldf_triad )   nldf = np_blp_it  ! iso-neutral: triad    (rotation)
+            ENDIF
+            !                                ! diffusivity ratio: passive / active tracers 
+            IF( ABS(rn_bht_0) < 2._wp*TINY(1._wp) ) THEN
+               IF( ABS(rn_bhtrc_0) < 2._wp*TINY(1._wp) ) THEN
+                  rldf = 1.0_wp
+               ELSE
+                  CALL ctl_stop( 'trc_ldf_ctl : cannot define rldf, rn_aht_0==0, rn_ahtrc_0 /=0' )
+               ENDIF
+            ELSE
+               rldf = SQRT(  ABS( rn_bhtrc_0 / rn_bht_0 )  )
+            ENDIF
          ENDIF
-         IF ( ln_sco ) THEN             ! s-coordinate
-            IF ( ln_trcldf_lev   )   nldf = np_lap     ! iso-level  (no rotation)
-            IF ( ln_trcldf_hor   )   nldf = np_lap_it  ! horizontal (   rotation)       !!gm   a checker....
-            IF ( ln_trcldf_iso   )   nldf = np_lap_i   ! iso-neutral: standard (rotation)
-            IF ( ln_trcldf_triad )   nldf = np_lap_it  ! iso-neutral: triad    (rotation)
-         ENDIF
-         !                                ! diffusivity ratio: passive / active tracers 
-         IF( ABS(rn_aht_0) < 2._wp*TINY(1._wp) ) THEN
-            IF( ABS(rn_ahtrc_0) < 2._wp*TINY(1._wp) ) THEN
-               rldf = 1.0_wp
-            ELSE
-               CALL ctl_stop( 'trc_ldf_ctl : cannot define rldf, rn_aht_0==0, rn_ahtrc_0 /=0' )
-            ENDIF
-         ELSE
-            rldf = rn_ahtrc_0 / rn_aht_0
-         ENDIF
-      ENDIF
-      !
-      IF( ln_trcldf_blp ) THEN      !==  bilaplacian operator  ==!
-         IF ( ln_zco ) THEN                ! z-coordinate
-            IF ( ln_trcldf_lev   )   nldf = np_blp     ! iso-level = horizontal (no rotation)
-            IF ( ln_trcldf_hor   )   nldf = np_blp     ! iso-level = horizontal (no rotation)
-            IF ( ln_trcldf_iso   )   nldf = np_blp_i   ! iso-neutral: standard (rotation)
-            IF ( ln_trcldf_triad )   nldf = np_blp_it  ! iso-neutral: triad    (rotation)
-         ENDIF
-         IF ( ln_zps ) THEN             ! z-coordinate with partial step
-            IF ( ln_trcldf_lev   )   ierr = 1         ! iso-level not allowed 
-            IF ( ln_trcldf_hor   )   nldf = np_blp     ! horizontal (no rotation)
-            IF ( ln_trcldf_iso   )   nldf = np_blp_i   ! iso-neutral: standard (rotation)
-            IF ( ln_trcldf_triad )   nldf = np_blp_it  ! iso-neutral: triad    (rotation)
-         ENDIF
-         IF ( ln_sco ) THEN             ! s-coordinate
-            IF ( ln_trcldf_lev   )   nldf = np_blp     ! iso-level  (no rotation)
-            IF ( ln_trcldf_hor   )   nldf = np_blp_it  ! horizontal (   rotation)       !!gm   a checker....
-            IF ( ln_trcldf_iso   )   nldf = np_blp_i   ! iso-neutral: standard (rotation)
-            IF ( ln_trcldf_triad )   nldf = np_blp_it  ! iso-neutral: triad    (rotation)
-         ENDIF
-         !                                ! diffusivity ratio: passive / active tracers 
-         IF( ABS(rn_bht_0) < 2._wp*TINY(1._wp) ) THEN
-            IF( ABS(rn_bhtrc_0) < 2._wp*TINY(1._wp) ) THEN
-               rldf = 1.0_wp
-            ELSE
-               CALL ctl_stop( 'trc_ldf_ctl : cannot define rldf, rn_aht_0==0, rn_ahtrc_0 /=0' )
-            ENDIF
-         ELSE
-            rldf = SQRT(  ABS( rn_bhtrc_0 / rn_bht_0 )  )
-         ENDIF
-      ENDIF
-      !
-      IF( ierr == 1 )   CALL ctl_stop( 'trc_ldf_ctl: iso-level in z-partial step, not allowed' )
-      IF( ln_ldfeiv .AND. .NOT.ln_trcldf_iso )   CALL ctl_stop( 'trc_ldf_ctl: eiv requires isopycnal laplacian diffusion' )
+         !
+         IF( ierr == 1 )   CALL ctl_stop( 'trc_ldf_ini: iso-level in z-partial step, not allowed' )
+      ENDIF
+      !
+      IF( ln_ldfeiv .AND. .NOT.ln_trcldf_iso )   CALL ctl_stop( 'trc_ldf_ini: eiv requires isopycnal laplacian diffusion' )
       IF( nldf == 1 .OR. nldf == 3 )   l_ldfslp = .TRUE.    ! slope of neutral surfaces required 
       !
@@ -268,24 +270,16 @@
          WRITE(numout,*)
          SELECT CASE( nldf )
-         CASE( np_no_ldf )   ;   WRITE(numout,*) '          NO lateral diffusion'
-         CASE( np_lap    )   ;   WRITE(numout,*) '          laplacian iso-level operator'
-         CASE( np_lap_i  )   ;   WRITE(numout,*) '          Rotated laplacian operator (standard)'
-         CASE( np_lap_it )   ;   WRITE(numout,*) '          Rotated laplacian operator (triad)'
-         CASE( np_blp    )   ;   WRITE(numout,*) '          bilaplacian iso-level operator'
-         CASE( np_blp_i  )   ;   WRITE(numout,*) '          Rotated bilaplacian operator (standard)'
-         CASE( np_blp_it )   ;   WRITE(numout,*) '          Rotated bilaplacian operator (triad)'
+         CASE( np_no_ldf )   ;   WRITE(numout,*) '      ===>>   NO lateral diffusion'
+         CASE( np_lap    )   ;   WRITE(numout,*) '      ===>>   laplacian iso-level operator'
+         CASE( np_lap_i  )   ;   WRITE(numout,*) '      ===>>   Rotated laplacian operator (standard)'
+         CASE( np_lap_it )   ;   WRITE(numout,*) '      ===>>   Rotated laplacian operator (triad)'
+         CASE( np_blp    )   ;   WRITE(numout,*) '      ===>>   bilaplacian iso-level operator'
+         CASE( np_blp_i  )   ;   WRITE(numout,*) '      ===>>   Rotated bilaplacian operator (standard)'
+         CASE( np_blp_it )   ;   WRITE(numout,*) '      ===>>   Rotated bilaplacian operator (triad)'
          END SELECT
       ENDIF
       !
    END SUBROUTINE trc_ldf_ini
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                                         Empty module
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE trc_ldf( kt )
-      INTEGER, INTENT(in) :: kt
-      WRITE(*,*) 'trc_ldf: You should not have seen this print! error?', kt
-   END SUBROUTINE trc_ldf
+
 #endif
    !!======================================================================
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 9019)
@@ -28,6 +28,4 @@
    USE oce_trc         ! ocean dynamics and tracers variables
    USE trc             ! ocean passive tracers variables
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE prtctl_trc      ! Print control for debbuging
    USE trd_oce
    USE trdtra
@@ -38,9 +36,12 @@
    USE agrif_top_interp
 # endif
+   !
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl_trc      ! Print control for debbuging
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   trc_nxt          ! routine called by step.F90
+   PUBLIC   trc_nxt   ! routine called by step.F90
 
    REAL(wp) ::   rfact1, rfact2
@@ -82,5 +83,5 @@
       REAL(wp) ::   zfact            ! temporary scalar
       CHARACTER (len=22) :: charout
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::  ztrdt 
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) ::   ztrdt    ! 4D workspace
       !!----------------------------------------------------------------------
       !
@@ -102,5 +103,5 @@
 
       IF( l_trdtrc )  THEN             ! trends: store now fields before the Asselin filter application
-         CALL wrk_alloc( jpi, jpj, jpk, jptra, ztrdt )
+         ALLOCATE( ztrdt(jpi,jpj,jpk,jptra) )
          ztrdt(:,:,:,:)  = trn(:,:,:,:)
       ENDIF
@@ -138,5 +139,5 @@
             END DO
          END DO
-         CALL wrk_dealloc( jpi, jpj, jpk, jptra, ztrdt ) 
+         DEALLOCATE( ztrdt ) 
       END IF
       !
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90	(revision 9019)
@@ -58,14 +58,12 @@
       !!
       !!----------------------------------------------------------------------
-      !
-      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
-      !
-      INTEGER  ::   ji, jj, jn                                     ! dummy loop indices
-      REAL(wp) ::   zse3t, zrtrn, zratio, zfact                    ! temporary scalars
-      REAL(wp) ::   zswitch, zftra, zcd, zdtra, ztfx, ztra         ! temporary scalars
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      INTEGER  ::   ji, jj, jn                      ! dummy loop indices
+      REAL(wp) ::   zse3t, zrtrn, zratio, zfact     ! local scalars
+      REAL(wp) ::   zftra, zcd, zdtra, ztfx, ztra   !   -      -
       CHARACTER (len=22) :: charout
-      REAL(wp), POINTER, DIMENSION(:,:  ) :: zsfx
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: ztrtrd
-
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   zsfx
+      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrtrd
       !!---------------------------------------------------------------------
       !
@@ -77,10 +75,4 @@
       !
       zrtrn = 1.e-15_wp
-
-      SELECT CASE( nn_ice_embd )         ! levitating or embedded sea-ice option
-         CASE( 0    )   ;   zswitch = 1  ! (0) standard levitating sea-ice : salt exchange only
-         CASE( 1, 2 )   ;   zswitch = 0  ! (1) levitating sea-ice: salt and volume exchange but no pressure effect                                
-      !                                  ! (2) embedded sea-ice : salt and volume fluxes and pressure
-      END SELECT
 
       IF( kt == nittrc000 ) THEN
@@ -88,5 +80,5 @@
          IF(lwp) WRITE(numout,*) 'trc_sbc : Passive tracers surface boundary condition'
          IF(lwp) WRITE(numout,*) '~~~~~~~ '
-
+         !
          IF( ln_rsttr .AND. .NOT.ln_top_euler .AND.   &                     ! Restart: read in restart  file
             iom_varid( numrtr, 'sbc_'//TRIM(ctrcnm(1))//'_b', ldstop = .FALSE. ) > 0 ) THEN
@@ -125,7 +117,6 @@
          !
          IF( l_trdtrc )   ztrtrd(:,:,:) = tra(:,:,:,jn)  ! save trends
-
-         IF ( nn_ice_tr == -1 ) THEN  ! No tracers in sea ice (null concentration in sea ice)
-
+         !
+         IF( nn_ice_tr == -1 ) THEN    ! No tracers in sea ice (null concentration in sea ice)
             DO jj = 2, jpj
                DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -133,7 +124,5 @@
                END DO
             END DO
-
          ELSE
-
             DO jj = 2, jpj
                DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -142,9 +131,9 @@
                   zftra = - trc_i(ji,jj,jn) * fmmflx(ji,jj) ! uptake of tracer in the sea ice
                   zcd   =   trc_o(ji,jj,jn) * fmmflx(ji,jj) ! concentration dilution due to freezing-melting,
-                                                               ! only used in the levitating sea ice case
+                  !                                         ! only used in the levitating sea ice case
                   ! tracer flux only       : add concentration dilution term in net tracer flux, no F-M in volume flux
                   ! tracer and mass fluxes : no concentration dilution term in net tracer flux, F-M term in volume flux
-                  ztfx  = zftra + zswitch * zcd                ! net tracer flux (+C/D if no ice/ocean mass exchange)
-   
+                  ztfx  = zftra                             ! net tracer flux
+                  !
                   zdtra = r1_rau0 * ( ztfx + zsfx(ji,jj) * trn(ji,jj,1,jn) ) 
                   IF ( zdtra < 0. ) THEN
@@ -173,5 +162,5 @@
       END DO                                                     ! tracer loop
       !                                                          ! ===========
-
+      !
       !                                           Write in the tracer restar  file
       !                                          *******************************
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 9019)
@@ -15,5 +15,4 @@
    USE oce_trc         ! ocean dynamics and active tracers variables
    USE trc             ! ocean passive tracers variables 
-   USE trabbl          ! bottom boundary layer               (trc_bbl routine)
    USE trcbbl          ! bottom boundary layer               (trc_bbl routine)
    USE trcdmp          ! internal damping                    (trc_dmp routine)
@@ -63,5 +62,5 @@
          !
                                 CALL trc_sbc    ( kt )      ! surface boundary condition
-         IF( lk_trabbl )        CALL trc_bbl    ( kt )      ! advective (and/or diffusive) bottom boundary layer scheme
+         IF( ln_trabbl )        CALL trc_bbl    ( kt )      ! advective (and/or diffusive) bottom boundary layer scheme
          IF( ln_trcdmp )        CALL trc_dmp    ( kt )      ! internal damping trends
          IF( ln_bdy )           CALL trc_bdy_dmp( kt )      ! BDY damping trends
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trczdf.F90	(revision 9019)
@@ -4,6 +4,7 @@
    !! Ocean Passive tracers : vertical diffusive trends 
    !!=====================================================================
-   !! History :  9.0  ! 2005-11 (G. Madec)  Original code
+   !! History :  9.0  ! 2005-11  (G. Madec)  Original code
    !!       NEMO 3.0  ! 2008-01  (C. Ethe, G. Madec)  merge TRC-TRA 
+   !!            4.0  ! 2017-04  (G. Madec)  remove the explicit case
    !!----------------------------------------------------------------------
 #if defined key_top
@@ -11,13 +12,13 @@
    !!   'key_top'                                                TOP models
    !!----------------------------------------------------------------------
-   !!   trc_zdf      : update the tracer trend with the lateral diffusion
-   !!   trc_zdf_ini  : initialization, namelist read, and parameters control
+   !!   trc_zdf      : update the tracer trend with the vertical diffusion
    !!----------------------------------------------------------------------
    USE trc           ! ocean passive tracers variables
    USE oce_trc       ! ocean dynamics and active tracers
    USE trd_oce       ! trends: ocean variables
-   USE trazdf_exp    ! vertical diffusion: explicit (tra_zdf_exp     routine)
-   USE trazdf_imp    ! vertical diffusion: implicit (tra_zdf_imp     routine)
+   USE trazdf        ! tracer: vertical diffusion
+!!gm do we really need this ?
    USE trcldf        ! passive tracers: lateral diffusion
+!!gm
    USE trdtra        ! trends manager: tracers 
    USE prtctl_trc    ! Print control
@@ -27,15 +28,5 @@
 
    PUBLIC   trc_zdf         ! called by step.F90 
-   PUBLIC   trc_zdf_ini     ! called by nemogcm.F90 
    
-   !                                        !!** Vertical diffusion (nam_trczdf) **
-   LOGICAL , PUBLIC ::   ln_trczdf_exp       !: explicit vertical diffusion scheme flag
-   INTEGER , PUBLIC ::   nn_trczdf_exp       !: number of sub-time step (explicit time stepping)
-
-   INTEGER ::   nzdf = 0               ! type vertical diffusion algorithm used
-      !                                ! defined from ln_zdf...  namlist logicals)
-   !! * Substitutions
-#  include "zdfddm_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.7 , NEMO Consortium (2015)
@@ -49,5 +40,6 @@
       !!                  ***  ROUTINE trc_zdf  ***
       !!
-      !! ** Purpose :   compute the vertical ocean tracer physics.
+      !! ** Purpose :   compute the vertical ocean tracer physics using
+      !!              an implicit time-stepping scheme.
       !!---------------------------------------------------------------------
       INTEGER, INTENT( in ) ::  kt      ! ocean time-step index
@@ -55,19 +47,13 @@
       INTEGER               ::  jk, jn
       CHARACTER (len=22)    :: charout
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   ztrtrd   ! 4D workspace
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jptra) ::   ztrtrd   ! 4D workspace
       !!---------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('trc_zdf')
       !
-      IF( l_trdtrc )  THEN
-         CALL wrk_alloc( jpi, jpj, jpk, jptra, ztrtrd )
-         ztrtrd(:,:,:,:)  = tra(:,:,:,:)
-      ENDIF
-
-      SELECT CASE ( nzdf )                       ! compute lateral mixing trend and add it to the general trend
-      CASE ( 0 ) ;  CALL tra_zdf_exp( kt, nittrc000, 'TRC', r2dttrc, nn_trczdf_exp, trb, tra, jptra )    !   explicit scheme 
-      CASE ( 1 ) ;  CALL tra_zdf_imp( kt, nittrc000, 'TRC', r2dttrc,                trb, tra, jptra )    !   implicit scheme          
-      END SELECT
-
+      IF( l_trdtrc )   ztrtrd(:,:,:,:)  = tra(:,:,:,:)
+      !
+      CALL tra_zdf_imp( kt, nittrc000, 'TRC', r2dttrc, trb, tra, jptra )    !   implicit scheme          
+      !
       IF( l_trdtrc )   THEN                      ! save the vertical diffusive trends for further diagnostics
          DO jn = 1, jptra
@@ -77,10 +63,10 @@
             CALL trd_tra( kt, 'TRC', jn, jptra_zdf, ztrtrd(:,:,:,jn) )
          END DO
-         CALL wrk_dealloc( jpi, jpj, jpk, jptra, ztrtrd )
       ENDIF
       !                                          ! print mean trends (used for debugging)
       IF( ln_ctl )   THEN
-         WRITE(charout, FMT="('zdf ')") ;  CALL prt_ctl_trc_info(charout)
-                                           CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
+         WRITE(charout, FMT="('zdf ')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' )
       END IF
       !
@@ -88,64 +74,4 @@
       !
    END SUBROUTINE trc_zdf
-
-
-   SUBROUTINE trc_zdf_ini
-      !!----------------------------------------------------------------------
-      !!                 ***  ROUTINE trc_zdf_ini  ***
-      !!
-      !! ** Purpose :   Choose the vertical mixing scheme
-      !!
-      !! ** Method  :   Set nzdf from ln_zdfexp
-      !!      nzdf = 0   explicit (time-splitting) scheme (ln_trczdf_exp=T)
-      !!           = 1   implicit (euler backward) scheme (ln_trczdf_exp=F)
-      !!      NB: The implicit scheme is required when using : 
-      !!             - rotated lateral mixing operator
-      !!             - TKE, GLS vertical mixing scheme
-      !!----------------------------------------------------------------------
-      INTEGER ::  ios                 ! Local integer output status for namelist read
-      !!
-      NAMELIST/namtrc_zdf/ ln_trczdf_exp  , nn_trczdf_exp
-      !!----------------------------------------------------------------------
-      !
-      REWIND( numnat_ref )             ! namtrc_zdf in reference namelist 
-      READ  ( numnat_ref, namtrc_zdf, IOSTAT = ios, ERR = 905)
-905   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_zdf in reference namelist', lwp )
-      !
-      REWIND( numnat_cfg )             ! namtrc_zdf in configuration namelist 
-      READ  ( numnat_cfg, namtrc_zdf, IOSTAT = ios, ERR = 906 )
-906   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrc_zdf in configuration namelist', lwp )
-      IF(lwm) WRITE ( numont, namtrc_zdf )
-      !
-      IF(lwp) THEN                     ! Control print
-         WRITE(numout,*)
-         WRITE(numout,*) '   Namelist namtrc_zdf : set vertical diffusion  parameters'
-         WRITE(numout,*) '      time splitting / backward scheme ln_trczdf_exp = ', ln_trczdf_exp
-         WRITE(numout,*) '      number of time step              nn_trczdf_exp = ', nn_trczdf_exp
-      ENDIF
-
-      !                                ! Define the vertical tracer physics scheme
-      IF( ln_trczdf_exp ) THEN   ;   nzdf = 0     ! explicit scheme
-      ELSE                       ;   nzdf = 1     ! implicit scheme
-      ENDIF
-
-      !                                ! Force implicit schemes
-      IF( ln_trcldf_iso              )   nzdf = 1      ! iso-neutral lateral physics
-      IF( ln_trcldf_hor .AND. ln_sco )   nzdf = 1      ! horizontal lateral physics in s-coordinate
-#if defined key_zdftke || defined key_zdfgls 
-                                         nzdf = 1      ! TKE or GLS physics       
-#endif
-      IF( ln_trczdf_exp .AND. nzdf == 1 )  & 
-         CALL ctl_stop( 'trc_zdf : If using the rotated lateral mixing operator or TKE, GLS vertical scheme ', &
-            &           '          the implicit scheme is required, set ln_trczdf_exp = .false.' )
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'trc:zdf_ctl : vertical passive tracer physics scheme'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         IF( nzdf ==  0 )   WRITE(numout,*) '              Explicit time-splitting scheme'
-         IF( nzdf ==  1 )   WRITE(numout,*) '              Implicit (euler backward) scheme'
-      ENDIF
-      !
-   END SUBROUTINE trc_zdf_ini
    
 #else
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trdmxl_trc.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trdmxl_trc.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/TRP/trdmxl_trc.F90	(revision 9019)
@@ -20,8 +20,5 @@
    USE dom_oce           ! domain definition
    USE zdfmxl  , ONLY : nmln ! number of level in the mixed layer
-   USE zdf_oce , ONLY : avt  ! vert. diffusivity coef. at w-point for temp  
-# if defined key_zdfddm   
-   USE zdfddm  , ONLY : avs  ! salinity vertical diffusivity coeff. at w-point
-# endif
+   USE zdf_oce , ONLY : avs  ! vert. diffusivity coef. at w-point for temp  
    USE trdtrc_oce    ! definition of main arrays used for trends computations
    USE in_out_manager    ! I/O manager
@@ -54,6 +51,4 @@
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  ztmltrd2   !
 
-   !! * Substitutions
-#  include "zdfddm_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -275,11 +270,10 @@
       IF( ln_trcldf_iso ) THEN
          !
-         DO jj = 1,jpj
-            DO ji = 1,jpi
-               ik = nmld_trc(ji,jj)
-               zavt = fsavs(ji,jj,ik)
-               DO jn = 1, jptra
+         DO jn = 1, jptra
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ik = nmld_trc(ji,jj)
                   IF( ln_trdtrc(jn) )    &
-                  tmltrd_trc(ji,jj,jpmxl_trc_zdf,jn) = - zavt / e3w_n(ji,jj,ik) * tmask(ji,jj,ik)  &
+                  tmltrd_trc(ji,jj,jpmxl_trc_zdf,jn) = - avs(ji,jj,ik) / e3w_n(ji,jj,ik) * tmask(ji,jj,ik)  &
                        &                    * ( trn(ji,jj,ik-1,jn) - trn(ji,jj,ik,jn) )            &
                        &                    / MAX( 1., rmld_trc(ji,jj) ) * tmask(ji,jj,1)
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/oce_trc.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/oce_trc.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/oce_trc.F90	(revision 9019)
@@ -63,5 +63,4 @@
    USE sbc_oce , ONLY :   ln_rnf     =>    ln_rnf     !: runoffs / runoff mouths
    USE sbc_oce , ONLY :   fr_i       =>    fr_i       !: ice fraction (between 0 to 1)
-   USE sbc_oce , ONLY :   nn_ice_embd => nn_ice_embd  !: flag for  levitating/embedding sea-ice in the ocean
    USE sbc_oce , ONLY :   atm_co2    =>    atm_co2    !  atmospheric pCO2
    USE traqsr  , ONLY :   rn_abs     =>    rn_abs     !: fraction absorbed in the very near surface
@@ -101,8 +100,5 @@
 
    !* vertical diffusion *
-   USE zdf_oce , ONLY :   avt        =>   avt         !: vert. diffusivity coef. at w-point for temp  
-# if defined key_zdfddm
-   USE zdfddm  , ONLY :   avs        =>   avs         !: salinity vertical diffusivity coeff. at w-point
-# endif
+   USE zdf_oce , ONLY :   avs        =>   avs         !: vert. diffusivity coef. for salinity (w-point)
 
    !* mixing & mixed layer depth *
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/trc.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/trc.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/trc.F90	(revision 9019)
@@ -17,155 +17,105 @@
    PUBLIC   trc_alloc   ! called by nemogcm.F90
 
-   !! parameters for the control of passive tracers
-   !! ---------------------------------------------   
-   INTEGER, PUBLIC                                                 ::   numnat_ref = -1   !: logical unit for the reference passive tracer namelist_top_ref
-   INTEGER, PUBLIC                                                 ::   numnat_cfg = -1   !: logical unit for the reference passive tracer namelist_top_cfg
-   INTEGER, PUBLIC                                                 ::   numont     = -1   !: logical unit for the reference passive tracer namelist output output.namelist.top
-   INTEGER, PUBLIC                                                 ::   numtrc_ref = -1   !: logical unit for the reference passive tracer namelist_top_ref
-   INTEGER, PUBLIC                                                 ::   numtrc_cfg = -1   !: logical unit for the reference passive tracer namelist_top_cfg
-   INTEGER, PUBLIC                                                 ::   numonr     = -1   !: logical unit for the reference passive tracer namelist output output.namelist.top
-   INTEGER, PUBLIC                                                 ::   numstr        !: logical unit for tracer statistics
-   INTEGER, PUBLIC                                                 ::   numrtr        !: logical unit for trc restart (read )
-   INTEGER, PUBLIC                                                 ::   numrtw        !: logical unit for trc restart ( write )
+   !                                     !!- logical units of passive tracers
+   INTEGER, PUBLIC ::   numnat_ref = -1   !: reference passive tracer namelist_top_ref
+   INTEGER, PUBLIC ::   numnat_cfg = -1   !: reference passive tracer namelist_top_cfg
+   INTEGER, PUBLIC ::   numont     = -1   !: reference passive tracer namelist output output.namelist.top
+   INTEGER, PUBLIC ::   numtrc_ref = -1   !: reference passive tracer namelist_top_ref
+   INTEGER, PUBLIC ::   numtrc_cfg = -1   !: reference passive tracer namelist_top_cfg
+   INTEGER, PUBLIC ::   numonr     = -1   !: reference passive tracer namelist output output.namelist.top
+   INTEGER, PUBLIC ::   numstr            !: tracer statistics
+   INTEGER, PUBLIC ::   numrtr            !: trc restart (read )
+   INTEGER, PUBLIC ::   numrtw            !: trc restart ( write )
 
    !! passive tracers fields (before,now,after)
    !! --------------------------------------------------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)               ::  trai           !: initial total tracer
-   REAL(wp), PUBLIC                                                ::  areatot        !: total volume 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:  )         ::  cvol           !: volume correction -degrad option- 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:)         ::  trn            !: tracer concentration for now time step
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:)         ::  tra            !: tracer concentration for next time step
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:)         ::  trb            !: tracer concentration for before time step
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:  )         ::  sbc_trc_b      !: Before sbc fluxes for tracers
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:  )         ::  sbc_trc        !: Now sbc fluxes for tracers
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)       ::  trai           !: initial total tracer
+   REAL(wp), PUBLIC                                        ::  areatot        !: total volume 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:  ) ::  cvol           !: volume correction -degrad option- 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  trn            !: tracer concentration for now time step
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  tra            !: tracer concentration for next time step
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  trb            !: tracer concentration for before time step
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:  ) ::  sbc_trc_b      !: Before sbc fluxes for tracers
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:  ) ::  sbc_trc        !: Now sbc fluxes for tracers
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:  )         ::  trc_i          !: prescribed tracer concentration in sea ice for SBC
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:  )         ::  trc_o          !: prescribed tracer concentration in ocean for SBC
-   INTEGER             , PUBLIC                                    ::  nn_ice_tr      !: handling of sea ice tracers
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:  ) ::  trc_i          !: prescribed tracer concentration in sea ice for SBC
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:  ) ::  trc_o          !: prescribed tracer concentration in ocean for SBC
+   INTEGER             , PUBLIC                            ::  nn_ice_tr      !: handling of sea ice tracers
 
    !! interpolated gradient
    !!--------------------------------------------------  
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)           ::  gtru           !: hor. gradient at u-points at bottom ocean level
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)           ::  gtrv           !: hor. gradient at v-points at bottom ocean level
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)           ::  gtrui          !: hor. gradient at u-points at top    ocean level
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)           ::  gtrvi          !: hor. gradient at v-points at top    ocean level
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)             ::  qsr_mean        !: daily mean qsr
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  gtru           !: hor. gradient at u-points at bottom ocean level
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  gtrv           !: hor. gradient at v-points at bottom ocean level
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  gtrui          !: hor. gradient at u-points at top    ocean level
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  gtrvi          !: hor. gradient at v-points at top    ocean level
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  qsr_mean        !: daily mean qsr
    
    !! passive tracers  (input and output)
    !! ------------------------------------------  
-   LOGICAL             , PUBLIC                                    ::  ln_rsttr       !: boolean term for restart i/o for passive tracers (namelist)
-   LOGICAL             , PUBLIC                                    ::  lrst_trc       !: logical to control the trc restart write
-   INTEGER             , PUBLIC                                    ::  nn_writetrc    !: time step frequency for concentration outputs (namelist)
-   INTEGER             , PUBLIC                                    ::  nutwrs         !: output FILE for passive tracers restart
-   INTEGER             , PUBLIC                                    ::  nutrst         !: logical unit for restart FILE for passive tracers
-   INTEGER             , PUBLIC                                    ::  nn_rsttr       !: control of the time step ( 0 or 1 ) for pass. tr.
-   CHARACTER(len = 80) , PUBLIC                                    ::  cn_trcrst_in   !: suffix of pass. tracer restart name (input)
-   CHARACTER(len = 256), PUBLIC                                    ::  cn_trcrst_indir  !: restart input directory
-   CHARACTER(len = 80) , PUBLIC                                    ::  cn_trcrst_out  !: suffix of pass. tracer restart name (output)
-   CHARACTER(len = 256), PUBLIC                                    ::  cn_trcrst_outdir  !: restart output directory
-   REAL(wp)            , PUBLIC                                    ::  rdttrc         !: passive tracer time step
-   REAL(wp)            , PUBLIC                                    ::  r2dttrc        !: = 2*rdttrc except at nit000 (=rdttrc) if neuler=0
-   LOGICAL             , PUBLIC                                    ::  ln_top_euler   !: boolean term for euler integration 
-   LOGICAL             , PUBLIC                                    ::  ln_trcdta      !: Read inputs data from files
-   LOGICAL             , PUBLIC                                    ::  ln_trcdmp      !: internal damping flag
-   LOGICAL             , PUBLIC                                    ::  ln_trcdmp_clo  !: internal damping flag on closed seas
-   INTEGER             , PUBLIC                                    ::  nittrc000      !: first time step of passive tracers model
-   LOGICAL             , PUBLIC                                    ::  l_trcdm2dc     !: Diurnal cycle for TOP
+   LOGICAL             , PUBLIC ::   ln_rsttr           !: boolean term for restart i/o for passive tracers (namelist)
+   LOGICAL             , PUBLIC ::   lrst_trc           !: logical to control the trc restart write
+   INTEGER             , PUBLIC ::   nn_writetrc        !: time step frequency for concentration outputs (namelist)
+   INTEGER             , PUBLIC ::   nutwrs             !: output FILE for passive tracers restart
+   INTEGER             , PUBLIC ::   nutrst             !: logical unit for restart FILE for passive tracers
+   INTEGER             , PUBLIC ::   nn_rsttr           !: control of the time step ( 0 or 1 ) for pass. tr.
+   CHARACTER(len = 80) , PUBLIC ::   cn_trcrst_in       !: suffix of pass. tracer restart name (input)
+   CHARACTER(len = 256), PUBLIC ::   cn_trcrst_indir    !: restart input directory
+   CHARACTER(len = 80) , PUBLIC ::   cn_trcrst_out      !: suffix of pass. tracer restart name (output)
+   CHARACTER(len = 256), PUBLIC ::   cn_trcrst_outdir   !: restart output directory
+   REAL(wp)            , PUBLIC ::   rdttrc             !: passive tracer time step
+   REAL(wp)            , PUBLIC ::   r2dttrc            !: = 2*rdttrc except at nit000 (=rdttrc) if neuler=0
+   LOGICAL             , PUBLIC ::   ln_top_euler       !: boolean term for euler integration 
+   LOGICAL             , PUBLIC ::   ln_trcdta          !: Read inputs data from files
+   LOGICAL             , PUBLIC ::   ln_trcdmp          !: internal damping flag
+   LOGICAL             , PUBLIC ::   ln_trcdmp_clo      !: internal damping flag on closed seas
+   INTEGER             , PUBLIC ::   nittrc000          !: first time step of passive tracers model
+   LOGICAL             , PUBLIC ::   l_trcdm2dc         !: Diurnal cycle for TOP
 
    !! Information for the ice module for tracers
    !! ------------------------------------------
-   TYPE TRC_I_NML                    !--- Ice tracer namelist structure
-         REAL(wp)         :: trc_ratio  ! ice-ocean trc ratio
-         REAL(wp)         :: trc_prescr ! prescribed ice trc cc
-         CHARACTER(len=2) :: ctrc_o     ! choice of ocean trc cc
+   TYPE, PUBLIC ::   TRC_I_NML         !: Ice tracer namelist structure
+         REAL(wp)         :: trc_ratio    ! ice-ocean trc ratio
+         REAL(wp)         :: trc_prescr   ! prescribed ice trc cc
+         CHARACTER(len=2) :: ctrc_o       ! choice of ocean trc cc
    END TYPE
-
-   REAL(wp)        , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)  :: trc_ice_ratio      ! ice-ocean tracer ratio
-   REAL(wp)        , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)  :: trc_ice_prescr     ! prescribed ice trc cc
-   CHARACTER(len=2), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)  :: cn_trc_o ! choice of ocean tracer cc
+   !
+   REAL(wp)        , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   trc_ice_ratio    !: ice-ocean tracer ratio
+   REAL(wp)        , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   trc_ice_prescr   !: prescribed ice trc cc
+   CHARACTER(len=2), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   cn_trc_o         !: choice of ocean tracer cc
 
 
    !! information for outputs
    !! --------------------------------------------------
-   TYPE, PUBLIC :: PTRACER                                                            !: Passive tracer type
-       CHARACTER(len = 20)  :: clsname  !: short name
-       CHARACTER(len = 80)  :: cllname  !: long name
-       CHARACTER(len = 20)  :: clunit   !: unit
-       LOGICAL              :: llinit   !: read in a file or not
-       LOGICAL              :: llsbc   !: read in a file or not
-       LOGICAL              :: llcbc   !: read in a file or not
-       LOGICAL              :: llobc   !: read in a file or not
+   TYPE, PUBLIC ::   PTRACER        !: Passive tracer type
+      CHARACTER(len=20) ::   clsname   ! short name
+      CHARACTER(len=80) ::   cllname   ! long name
+      CHARACTER(len=20) ::   clunit    ! unit
+      LOGICAL           ::   llinit    ! read in a file or not
+      LOGICAL           ::   llsbc     ! read in a file or not
+      LOGICAL           ::   llcbc     ! read in a file or not
+      LOGICAL           ::   llobc     ! read in a file or not
    END TYPE PTRACER
-
-   CHARACTER(len = 20), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)    ::  ctrcnm         !: tracer name 
-   CHARACTER(len = 80), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)    ::  ctrcln         !: trccer field long name
-   CHARACTER(len = 20), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)    ::  ctrcun         !: tracer unit
-
-   TYPE, PUBLIC :: DIAG                                                               !: passive trcacer ddditional diagnostic type
-      CHARACTER(len = 20)  :: sname    !: short name
-      CHARACTER(len = 80)  :: lname    !: long name
-      CHARACTER(len = 20)  :: units    !: unit
+   !
+   CHARACTER(len=20), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ctrcnm   !: tracer name 
+   CHARACTER(len=80), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ctrcln   !: trccer field long name
+   CHARACTER(len=20), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ctrcun   !: tracer unit
+   !
+   TYPE, PUBLIC ::   DIAG         !: Passive trcacer ddditional diagnostic type
+      CHARACTER(len=20) ::   sname   ! short name
+      CHARACTER(len=80) ::   lname   ! long name
+      CHARACTER(len=20) ::   units   ! unit
    END TYPE DIAG
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:)         ::  trc3d          !: 3D diagnostics for tracers
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:)         ::  trc2d          !: 2D diagnostics for tracers
+   !
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   trc3d   !: 3D diagnostics for tracers
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   trc2d   !: 2D diagnostics for tracers
 
    !! information for inputs
    !! --------------------------------------------------
-   LOGICAL , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)    ::  ln_trc_ini     !: Initialisation from data input file
-   LOGICAL , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)    ::  ln_trc_obc     !: Use open boundary condition data
-   LOGICAL , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)    ::  ln_trc_sbc     !: Use surface boundary condition data
-   LOGICAL , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)    ::  ln_trc_cbc     !: Use coastal boundary condition data
-   LOGICAL , PUBLIC                                     ::  ln_rnf_ctl     !: remove runoff dilution on tracers
-   REAL(wp), PUBLIC                                     ::  rn_bc_time     !: Time scaling factor for SBC and CBC data (seconds in a day)
-
-
-   !! variables to average over physics over passive tracer sub-steps.
-   !! ----------------------------------------------------------------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  un_tm       !: i-horizontal velocity average     [m/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  vn_tm       !: j-horizontal velocity average     [m/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  tsn_tm      !: t/s average     [m/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  avt_tm      !: vertical diffusivity coeff. at  w-point   [m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  rhop_tm     !: 
-# if defined key_zdfddm
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  avs_tm      !: vertical double diffusivity coeff. at w-point   [m/s]
-# endif
-#if defined key_trabbl
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  ahu_bbl_tm  !: u-, w-points
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  ahv_bbl_tm  !: j-direction slope at u-, w-points
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  utr_bbl_tm  !: j-direction slope at u-, w-points
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  vtr_bbl_tm  !: j-direction slope at u-, w-points
-#endif
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  sshn_tm     !: average ssh for the now step [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  sshb_hold   !:hold sshb from the beginning of each sub-stepping[m]  
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  rnf_tm     !: river runoff
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  h_rnf_tm   !: depth in metres to the bottom of the relevant grid box
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  hmld_tm    !: mixed layer depth average [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  fr_i_tm    !: average ice fraction     [m/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  emp_tm     !: freshwater budget: volume flux [Kg/m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  fmmflx_tm  !: freshwater budget: freezing/melting [Kg/m2/s]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  emp_b_hold !: hold emp from the beginning of each sub-stepping[m]  
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  qsr_tm     !: solar radiation average [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  wndm_tm    !: 10m wind average [m]
-   !
-
-   ! Temporary physical arrays for sub_stepping
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  tsn_temp
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  un_temp,vn_temp,wn_temp     !: hold current values of avt, un, vn, wn
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  avt_temp, rhop_temp     !: hold current values of avt, un, vn, wn
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  sshn_temp, sshb_temp, ssha_temp, rnf_temp,h_rnf_temp
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  hdivn_temp, rotn_temp
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  hdivb_temp, rotb_temp
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  hmld_temp, qsr_temp, fr_i_temp,wndm_temp
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  emp_temp, fmmflx_temp, emp_b_temp
-   !
-#if defined key_trabbl
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  ahu_bbl_temp, ahv_bbl_temp, utr_bbl_temp, vtr_bbl_temp !: hold current values 
-#endif
-   !
-# if defined key_zdfddm
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  avs_temp      !: salinity vertical diffusivity coeff. at w-point   [m/s]
-# endif
+   LOGICAL , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ln_trc_ini    !: Initialisation from data input file
+   LOGICAL , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ln_trc_obc    !: Use open boundary condition data
+   LOGICAL , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ln_trc_sbc    !: Use surface boundary condition data
+   LOGICAL , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ln_trc_cbc    !: Use coastal boundary condition data
+   LOGICAL , PUBLIC                                  ::   ln_rnf_ctl    !: remove runoff dilution on tracers
+   REAL(wp), PUBLIC                                  ::   rn_bc_time    !: Time scaling factor for SBC and CBC data (seconds in a day)
    !
    CHARACTER(len=20), PUBLIC, DIMENSION(jp_bdy) :: cn_trc_dflt   ! Default OBC condition for all tracers
@@ -174,8 +124,9 @@
 !$AGRIF_DO_NOT_TREAT
    ! External data structure of BDY for TOP. Available elements: cn_obc, ll_trc, trcnow, dmp
-   TYPE(OBC_DATA),    PUBLIC, ALLOCATABLE, DIMENSION(:,:), TARGET ::  trcdta_bdy           !: bdy external data (local process)
+   TYPE(OBC_DATA), PUBLIC, ALLOCATABLE, DIMENSION(:,:), TARGET ::   trcdta_bdy   !: bdy external data (local process)
 !$AGRIF_END_DO_NOT_TREAT
+   !
    !!----------------------------------------------------------------------
-   !! NEMO/TOP 3.3.1 , NEMO Consortium (2010)
+   !! NEMO/TOP 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -205,11 +156,9 @@
          &      STAT = ierr(1)  )
       !
-      IF ( ln_bdy ) THEN
-         ALLOCATE( trcdta_bdy(jptra, jp_bdy), STAT = ierr(2) )
-      ENDIF
+      IF( ln_bdy       )   ALLOCATE( trcdta_bdy(jptra, jp_bdy)  , STAT = ierr(2) )
       !
-      IF (jp_dia3d > 0 ) ALLOCATE( trc3d(jpi,jpj,jpk,jp_dia3d), STAT = ierr(3) )
+      IF (jp_dia3d > 0 )   ALLOCATE( trc3d(jpi,jpj,jpk,jp_dia3d), STAT = ierr(3) )
       !
-      IF (jp_dia2d > 0 ) ALLOCATE( trc2d(jpi,jpj,jpk,jp_dia2d), STAT = ierr(4) )
+      IF (jp_dia2d > 0 )   ALLOCATE( trc2d(jpi,jpj,jpk,jp_dia2d), STAT = ierr(4) )
       ! 
       trc_alloc = MAXVAL( ierr )
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/trcini.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 9019)
@@ -197,5 +197,4 @@
       USE trcadv , ONLY:  trc_adv_ini
       USE trcldf , ONLY:  trc_ldf_ini
-      USE trczdf , ONLY:  trc_zdf_ini
       USE trcrad , ONLY:  trc_rad_ini
       !
@@ -206,5 +205,5 @@
                        CALL  trc_adv_ini          ! advection
                        CALL  trc_ldf_ini          ! lateral diffusion
-                       CALL  trc_zdf_ini          ! vertical diffusion
+                       !                          ! vertical diffusion: always implicit time stepping scheme
                        CALL  trc_rad_ini          ! positivity of passive tracers 
       !
@@ -224,16 +223,16 @@
       !!----------------------------------------------------------------------
       !
-      ! Initialisation of tracers Initial Conditions
-      IF( ln_trcdta )      CALL trc_dta_ini(jptra)
-
-      ! Initialisation of tracers Boundary Conditions
-      IF( ln_my_trc )     CALL trc_bc_ini(jptra)
-
-      IF( ln_rsttr ) THEN
+
+      IF( ln_trcdta )   CALL trc_dta_ini( jptra )      ! set initial tracers values
+
+      IF( ln_my_trc )   CALL trc_bc_ini ( jptra )      ! set tracers Boundary Conditions
+
+
+      IF( ln_rsttr ) THEN              ! restart from a file
         !
-        CALL trc_rst_read              ! restart from a file
+        CALL trc_rst_read
         !
-      ELSE
-        ! Initialisation of tracer from a file that may also be used for damping
+      ELSE                             ! Initialisation of tracer from a file that may also be used for damping
+!!gm BUG ?   if damping and restart, what's happening ?
         IF( ln_trcdta .AND. nb_trcdta > 0 ) THEN
             ! update passive tracers arrays with input data read from file
@@ -251,5 +250,5 @@
                   ENDIF
                ENDIF
-            ENDDO
+            END DO
             !
         ENDIF
@@ -263,4 +262,5 @@
    END SUBROUTINE trc_ini_state
 
+
    SUBROUTINE top_alloc
       !!----------------------------------------------------------------------
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/trcstp.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/trcstp.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/trcstp.F90	(revision 9019)
@@ -8,19 +8,20 @@
 #if defined key_top
    !!----------------------------------------------------------------------
-   !!   trc_stp      : passive tracer system time-stepping
-   !!----------------------------------------------------------------------
-   USE oce_trc          ! ocean dynamics and active tracers variables
+   !!   trc_stp       : passive tracer system time-stepping
+   !!----------------------------------------------------------------------
+   USE oce_trc        ! ocean dynamics and active tracers variables
    USE sbc_oce
    USE trc
-   USE trctrp           ! passive tracers transport
-   USE trcsms           ! passive tracers sources and sinks
+   USE trctrp         ! passive tracers transport
+   USE trcsms         ! passive tracers sources and sinks
    USE trcwri
    USE trcrst
+   USE trcsub         !
    USE trdtrc_oce
    USE trdmxl_trc
-   USE prtctl_trc       ! Print control for debbuging
-   USE iom
-   USE in_out_manager
-   USE trcsub
+   !
+   USE prtctl_trc     ! Print control for debbuging
+   USE iom            !
+   USE in_out_manager !
 
    IMPLICIT NONE
@@ -29,9 +30,9 @@
    PUBLIC   trc_stp    ! called by step
 
-   REAL(wp), DIMENSION(:,:,:), SAVE, ALLOCATABLE ::   qsr_arr ! save qsr during TOP time-step
-   REAL(wp) :: rdt_sampl
-   INTEGER  :: nb_rec_per_day, ktdcy
-   REAL(wp) :: rsecfst, rseclast
-   LOGICAL  :: llnew
+   LOGICAL  ::   llnew                   ! ???
+   REAL(wp) ::   rdt_sampl               ! ???
+   INTEGER  ::   nb_rec_per_day, ktdcy   ! ???
+   REAL(wp) ::   rsecfst, rseclast       ! ???
+   REAL(wp), DIMENSION(:,:,:), SAVE, ALLOCATABLE ::   qsr_arr   ! save qsr during TOP time-step
 
    !!----------------------------------------------------------------------
@@ -46,15 +47,14 @@
       !!                     ***  ROUTINE trc_stp  ***
       !!                      
-      !! ** Purpose : Time loop of opa for passive tracer
+      !! ** Purpose :   Time loop of opa for passive tracer
       !! 
-      !! ** Method  : 
-      !!              Compute the passive tracers trends 
-      !!              Update the passive tracers
+      !! ** Method  :   Compute the passive tracers trends 
+      !!                Update the passive tracers
       !!-------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::  kt      ! ocean time-step index
-      INTEGER               ::  jk, jn  ! dummy loop indices
-      REAL(wp)              ::  ztrai
-      CHARACTER (len=25)    ::  charout 
-
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !
+      INTEGER ::   jk, jn   ! dummy loop indices
+      REAL(wp)::   ztrai    ! local scalar
+      CHARACTER (len=25) ::   charout   !
       !!-------------------------------------------------------------------
       !
@@ -115,4 +115,5 @@
       !
    END SUBROUTINE trc_stp
+
 
    SUBROUTINE trc_mean_qsr( kt )
@@ -128,10 +129,12 @@
       !!              In coupled mode, the sampling is done at every coupling frequency 
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt
-      INTEGER  :: jn
-      REAL(wp) :: zkt, zrec
-      CHARACTER(len=1)               ::   cl1                      ! 1 character
-      CHARACTER(len=2)               ::   cl2                      ! 2 characters
-
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !
+      INTEGER  ::   jn   ! dummy loop indices
+      REAL(wp) ::   zkt, zrec     ! local scalars
+      CHARACTER(len=1) ::   cl1   ! 1 character
+      CHARACTER(len=2) ::   cl2   ! 2 characters
+      !!----------------------------------------------------------------------
+      !
       IF( kt == nittrc000 ) THEN
          IF( ln_cpl )  THEN  
@@ -143,5 +146,5 @@
          ENDIF
          !
-         IF( lwp ) THEN
+         IF(lwp) THEN
             WRITE(numout,*) 
             WRITE(numout,*) ' Sampling frequency dt = ', rdt_sampl, 's','   Number of sampling per day  nrec = ', nb_rec_per_day
@@ -171,5 +174,5 @@
                     CALL iom_get( numrtr, jpdom_autoglo, 'qsr_arr_'//cl2, qsr_arr(:,:,jn) )   !  A mean of qsr
                   ENDIF
-              ENDDO
+              END DO
             ELSE
                DO jn = 1, nb_rec_per_day
@@ -184,5 +187,5 @@
             DO jn = 1, nb_rec_per_day
                qsr_arr(:,:,jn) = qsr_mean(:,:)
-            ENDDO
+            END DO
          ENDIF
          !
@@ -220,5 +223,5 @@
                CALL iom_rstput( kt, nitrst, numrtw, 'qsr_arr_'//cl2, qsr_arr(:,:,jn) )
              ENDIF
-         ENDDO
+         END DO
          CALL iom_rstput( kt, nitrst, numrtw, 'qsr_mean', qsr_mean(:,:) )
       ENDIF
Index: /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/trcsub.F90
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/trcsub.F90	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/NEMO/TOP_SRC/trcsub.F90	(revision 9019)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                       ***  MODULE trcsubstp  ***
-   !!TOP :   Averages physics variables for TOP substepping. 
+   !!   TOP :   Averages physics variables for TOP substepping. 
    !!======================================================================
    !! History :  1.0  !  2011-10  (K. Edwards)  Original
@@ -8,18 +8,19 @@
 #if defined key_top
    !!----------------------------------------------------------------------
-   !!   trc_sub    : passive tracer system sub-stepping 
+   !!   trc_sub       : passive tracer system sub-stepping 
    !!----------------------------------------------------------------------
-   USE oce_trc          ! ocean dynamics and active tracers variables
+   USE oce_trc        ! ocean dynamics and active tracers variables
    USE trc
-   USE prtctl_trc       ! Print control for debbuging
-   USE iom
-   USE in_out_manager
-   USE lbclnk
-   USE trabbl
+   USE trabbl         ! bottom boundary layer
    USE zdf_oce
    USE domvvl
-   USE divhor          ! horizontal divergence            (div_hor routine)
-   USE sbcrnf    , ONLY: h_rnf, nk_rnf    ! River runoff
-   USE bdy_oce   , ONLY: ln_bdy, bdytmask ! BDY
+   USE divhor         ! horizontal divergence
+   USE sbcrnf   , ONLY: h_rnf, nk_rnf    ! River runoff
+   USE bdy_oce  , ONLY: ln_bdy, bdytmask ! BDY
+   !
+   USE prtctl_trc     ! Print control for debbuging
+   USE in_out_manager ! 
+   USE iom
+   USE lbclnk
 #if defined key_agrif
    USE agrif_opa_update
@@ -29,18 +30,51 @@
    IMPLICIT NONE
 
-   PUBLIC   trc_sub_stp      ! called by trc_stp
-   PUBLIC   trc_sub_ini      ! called by trc_ini to initialize substepping arrays.
-   PUBLIC   trc_sub_reset    ! called by trc_stp to reset physics variables
-   PUBLIC   trc_sub_ssh      ! called by trc_stp to reset physics variables
-
-   REAL(wp)  :: r1_ndttrc     !    1 /  nn_dttrc 
-   REAL(wp)  :: r1_ndttrcp1   !    1 / (nn_dttrc+1) 
-
-   !                                                       !* iso-neutral slopes (if l_ldfslp=T)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  uslp_temp, vslp_temp, wslpi_temp, wslpj_temp   !: hold current values 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  uslp_tm  , vslp_tm  , wslpi_tm  , wslpj_tm     !: time mean 
+   PUBLIC   trc_sub_stp     ! called by trc_stp
+   PUBLIC   trc_sub_ini     ! called by trc_ini to initialize substepping arrays.
+   PUBLIC   trc_sub_reset   ! called by trc_stp to reset physics variables
+   PUBLIC   trc_sub_ssh     ! called by trc_stp to reset physics variables
+
+   REAL(wp) :: r1_ndttrc     ! = 1 /  nn_dttrc 
+   REAL(wp) :: r1_ndttrcp1   ! = 1 / (nn_dttrc+1) 
+
+
+   !! averaged and temporary saved variables  (needed when a larger passive tracer time-step is used)
+   !! ----------------------------------------------------------------
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::    un_tm ,   un_temp   !: i-horizontal velocity average     [m/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::    vn_tm ,   vn_temp   !: j-horizontal velocity average     [m/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::              wn_temp   !: hold current values of avt, un, vn, wn
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   tsn_tm ,  tsn_temp   !: t/s average     [m/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   avs_tm ,  avs_temp   !: vertical diffusivity coeff. at  w-point   [m2/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  rhop_tm , rhop_temp   !: 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  sshn_tm , sshn_temp   !: average ssh for the now step [m]
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::    rnf_tm ,    rnf_temp   !: river runoff
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  h_rnf_tm ,  h_rnf_temp   !: depth in metres to the bottom of the relevant grid box
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   hmld_tm ,   hmld_temp   !: mixed layer depth average [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   fr_i_tm ,   fr_i_temp   !: average ice fraction     [m/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::    emp_tm ,    emp_temp   !: freshwater budget: volume flux [Kg/m2/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     :: fmmflx_tm , fmmflx_temp   !: freshwater budget: freezing/melting [Kg/m2/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     :: emp_b_hold,  emp_b_temp   !: hold emp from the beginning of each sub-stepping[m]  
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::    qsr_tm ,    qsr_temp   !: solar radiation average [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   wndm_tm ,   wndm_temp   !: 10m wind average [m]
+   !
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  sshb_hold   !:hold sshb from the beginning of each sub-stepping[m]  
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   sshb_temp, ssha_temp
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  hdivn_temp, rotn_temp
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::  hdivb_temp, rotb_temp
+   !
+   !                                                    !!- bottom boundary layer param (ln_trabbl=T)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  ahu_bbl_tm, ahu_bbl_temp  ! BBL diffusive i-coef.
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  ahv_bbl_tm, ahv_bbl_temp  ! BBL diffusive j-coef.
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  utr_bbl_tm, utr_bbl_temp  ! BBL u-advection
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)     ::  vtr_bbl_tm, vtr_bbl_temp  ! BBL v-advection
+
+   !                                                      !!- iso-neutral slopes (if l_ldfslp=T)
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   uslp_temp, vslp_temp, wslpi_temp, wslpj_temp   !: hold current values 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   uslp_tm  , vslp_tm  , wslpi_tm  , wslpj_tm     !: time mean 
+
 
    !!----------------------------------------------------------------------
-   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! NEMO/TOP 4.0 , NEMO Consortium (2017)
    !! $Id$ 
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -57,7 +91,8 @@
       !!              on TOP steps, calculate averages.
       !!-------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::  kt        ! ocean time-step index
-      INTEGER               ::  ji,jj,jk  ! dummy loop indices
-      REAL(wp)              ::  z1_ne3t, z1_ne3u, z1_ne3v, z1_ne3w
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !
+      INTEGER ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp)::   z1_ne3t, z1_ne3u, z1_ne3v, z1_ne3w   ! local scalars
       !!-------------------------------------------------------------------
       !
@@ -74,18 +109,14 @@
            r1_ndttrc        = 1._wp / REAL( nn_dttrc    , wp ) 
            r1_ndttrcp1      = 1._wp / REAL( nn_dttrc + 1, wp )
-           !
       ENDIF  
 
-       IF( MOD( kt , nn_dttrc ) /= 0 ) THEN
-          !
-          un_tm   (:,:,:)        = un_tm   (:,:,:)        + un   (:,:,:)        * e3u_n(:,:,:) 
-          vn_tm   (:,:,:)        = vn_tm   (:,:,:)        + vn   (:,:,:)        * e3v_n(:,:,:) 
-          tsn_tm  (:,:,:,jp_tem) = tsn_tm  (:,:,:,jp_tem) + tsn  (:,:,:,jp_tem) * e3t_n(:,:,:)  
-          tsn_tm  (:,:,:,jp_sal) = tsn_tm  (:,:,:,jp_sal) + tsn  (:,:,:,jp_sal) * e3t_n(:,:,:)  
-          rhop_tm (:,:,:)        = rhop_tm (:,:,:)        + rhop (:,:,:)        * e3t_n(:,:,:)  
-          avt_tm  (:,:,:)        = avt_tm  (:,:,:)        + avt  (:,:,:)        * e3w_n(:,:,:)  
-# if defined key_zdfddm
-          avs_tm  (:,:,:)        = avs_tm  (:,:,:)        + avs  (:,:,:)        * e3w_n(:,:,:)  
-# endif
+      IF( MOD( kt , nn_dttrc ) /= 0 ) THEN
+         !
+         un_tm   (:,:,:)        = un_tm   (:,:,:)        + un   (:,:,:)        * e3u_n(:,:,:) 
+         vn_tm   (:,:,:)        = vn_tm   (:,:,:)        + vn   (:,:,:)        * e3v_n(:,:,:) 
+         tsn_tm  (:,:,:,jp_tem) = tsn_tm  (:,:,:,jp_tem) + tsn  (:,:,:,jp_tem) * e3t_n(:,:,:)  
+         tsn_tm  (:,:,:,jp_sal) = tsn_tm  (:,:,:,jp_sal) + tsn  (:,:,:,jp_sal) * e3t_n(:,:,:)  
+         rhop_tm (:,:,:)        = rhop_tm (:,:,:)        + rhop (:,:,:)        * e3t_n(:,:,:)  
+         avs_tm  (:,:,:)        = avs_tm  (:,:,:)        + avs  (:,:,:)        * e3w_n(:,:,:)  
          IF( l_ldfslp ) THEN
             uslp_tm (:,:,:)      = uslp_tm (:,:,:)        + uslp (:,:,:)
@@ -94,27 +125,27 @@
             wslpj_tm(:,:,:)      = wslpj_tm(:,:,:)        + wslpj(:,:,:)
          ENDIF
-# if defined key_trabbl
-          IF( nn_bbl_ldf == 1 ) THEN
-             ahu_bbl_tm(:,:)     = ahu_bbl_tm(:,:)        + ahu_bbl(:,:) 
-             ahv_bbl_tm(:,:)     = ahv_bbl_tm(:,:)        + ahv_bbl(:,:) 
-          ENDIF
-          IF( nn_bbl_adv == 1 ) THEN
-             utr_bbl_tm(:,:)     = utr_bbl_tm(:,:)        + utr_bbl(:,:) 
-             vtr_bbl_tm(:,:)     = vtr_bbl_tm(:,:)        + vtr_bbl(:,:) 
-          ENDIF
-# endif
-          !
-          sshn_tm  (:,:)         = sshn_tm  (:,:)         + sshn  (:,:) 
-          rnf_tm   (:,:)         = rnf_tm   (:,:)         + rnf   (:,:) 
-          h_rnf_tm (:,:)         = h_rnf_tm (:,:)         + h_rnf (:,:) 
-          hmld_tm  (:,:)         = hmld_tm  (:,:)         + hmld  (:,:)
-          fr_i_tm  (:,:)         = fr_i_tm  (:,:)         + fr_i  (:,:)
-          emp_tm   (:,:)         = emp_tm   (:,:)         + emp   (:,:) 
-          fmmflx_tm(:,:)         = fmmflx_tm(:,:)         + fmmflx(:,:)
-          qsr_tm   (:,:)         = qsr_tm   (:,:)         + qsr   (:,:)
-          wndm_tm  (:,:)         = wndm_tm  (:,:)         + wndm  (:,:)
-
+         IF( ln_trabbl ) THEN
+            IF( nn_bbl_ldf == 1 ) THEN
+               ahu_bbl_tm(:,:)     = ahu_bbl_tm(:,:)        + ahu_bbl(:,:) 
+               ahv_bbl_tm(:,:)     = ahv_bbl_tm(:,:)        + ahv_bbl(:,:) 
+            ENDIF
+            IF( nn_bbl_adv == 1 ) THEN
+               utr_bbl_tm(:,:)     = utr_bbl_tm(:,:)        + utr_bbl(:,:) 
+               vtr_bbl_tm(:,:)     = vtr_bbl_tm(:,:)        + vtr_bbl(:,:) 
+            ENDIF
+         ENDIF 
+         !
+         sshn_tm  (:,:)         = sshn_tm  (:,:)         + sshn  (:,:) 
+         rnf_tm   (:,:)         = rnf_tm   (:,:)         + rnf   (:,:) 
+         h_rnf_tm (:,:)         = h_rnf_tm (:,:)         + h_rnf (:,:) 
+         hmld_tm  (:,:)         = hmld_tm  (:,:)         + hmld  (:,:)
+         fr_i_tm  (:,:)         = fr_i_tm  (:,:)         + fr_i  (:,:)
+         emp_tm   (:,:)         = emp_tm   (:,:)         + emp   (:,:) 
+         fmmflx_tm(:,:)         = fmmflx_tm(:,:)         + fmmflx(:,:)
+         qsr_tm   (:,:)         = qsr_tm   (:,:)         + qsr   (:,:)
+         wndm_tm  (:,:)         = wndm_tm  (:,:)         + wndm  (:,:)
+         !
       ELSE                           !  It is time to substep 
-         !   1. set temporary arrays to hold physics variables
+         !   1. set temporary arrays to hold physics/dynamical variables
          un_temp    (:,:,:)      = un    (:,:,:)
          vn_temp    (:,:,:)      = vn    (:,:,:)
@@ -122,22 +153,19 @@
          tsn_temp   (:,:,:,:)    = tsn   (:,:,:,:)
          rhop_temp  (:,:,:)      = rhop  (:,:,:)    
-         avt_temp   (:,:,:)      = avt   (:,:,:)
-# if defined key_zdfddm
          avs_temp   (:,:,:)      = avs   (:,:,:)
-# endif
          IF( l_ldfslp ) THEN
             uslp_temp  (:,:,:)   = uslp  (:,:,:)   ;   wslpi_temp (:,:,:)   = wslpi (:,:,:)
             vslp_temp  (:,:,:)   = vslp  (:,:,:)   ;   wslpj_temp (:,:,:)   = wslpj (:,:,:)
          ENDIF
-# if defined key_trabbl
-          IF( nn_bbl_ldf == 1 ) THEN
-             ahu_bbl_temp(:,:)   = ahu_bbl(:,:)  
-             ahv_bbl_temp(:,:)   = ahv_bbl(:,:) 
-          ENDIF
-          IF( nn_bbl_adv == 1 ) THEN
-             utr_bbl_temp(:,:)   = utr_bbl(:,:) 
-             vtr_bbl_temp(:,:)   = vtr_bbl(:,:) 
-          ENDIF
-# endif
+         IF( ln_trabbl ) THEN
+            IF( nn_bbl_ldf == 1 ) THEN
+               ahu_bbl_temp(:,:)   = ahu_bbl(:,:)  
+               ahv_bbl_temp(:,:)   = ahv_bbl(:,:) 
+            ENDIF
+            IF( nn_bbl_adv == 1 ) THEN
+               utr_bbl_temp(:,:)   = utr_bbl(:,:) 
+               vtr_bbl_temp(:,:)   = vtr_bbl(:,:) 
+            ENDIF
+         ENDIF 
          sshn_temp  (:,:)        = sshn  (:,:)
          sshb_temp  (:,:)        = sshb  (:,:)
@@ -161,8 +189,5 @@
          tsn_tm   (:,:,:,jp_sal) = tsn_tm  (:,:,:,jp_sal) + tsn  (:,:,:,jp_sal) * e3t_n(:,:,:)  
          rhop_tm (:,:,:)         = rhop_tm (:,:,:)        + rhop (:,:,:)        * e3t_n(:,:,:)  
-         avt_tm   (:,:,:)        = avt_tm  (:,:,:)        + avt  (:,:,:)        * e3w_n(:,:,:)  
-# if defined key_zdfddm
          avs_tm   (:,:,:)        = avs_tm  (:,:,:)        + avs  (:,:,:)        * e3w_n(:,:,:)  
-# endif
          IF( l_ldfslp ) THEN
             uslp_tm  (:,:,:)     = uslp_tm (:,:,:)        + uslp (:,:,:) 
@@ -171,14 +196,14 @@
             wslpj_tm (:,:,:)     = wslpj_tm(:,:,:)        + wslpj(:,:,:) 
          ENDIF
-# if defined key_trabbl
-          IF( nn_bbl_ldf == 1 ) THEN
-             ahu_bbl_tm(:,:)     = ahu_bbl_tm(:,:)        + ahu_bbl(:,:) 
-             ahv_bbl_tm(:,:)     = ahv_bbl_tm(:,:)        + ahv_bbl(:,:) 
-          ENDIF
-          IF( nn_bbl_adv == 1 ) THEN
-             utr_bbl_tm(:,:)     = utr_bbl_tm(:,:)        + utr_bbl(:,:) 
-             vtr_bbl_tm(:,:)     = vtr_bbl_tm(:,:)        + vtr_bbl(:,:) 
-          ENDIF
-# endif
+         IF( ln_trabbl ) THEN
+            IF( nn_bbl_ldf == 1 ) THEN
+               ahu_bbl_tm(:,:)     = ahu_bbl_tm(:,:)        + ahu_bbl(:,:) 
+               ahv_bbl_tm(:,:)     = ahv_bbl_tm(:,:)        + ahv_bbl(:,:) 
+            ENDIF
+            IF( nn_bbl_adv == 1 ) THEN
+               utr_bbl_tm(:,:)     = utr_bbl_tm(:,:)        + utr_bbl(:,:) 
+               vtr_bbl_tm(:,:)     = vtr_bbl_tm(:,:)        + vtr_bbl(:,:) 
+            ENDIF
+         ENDIF 
          sshn_tm  (:,:)          = sshn_tm    (:,:)       + sshn  (:,:) 
          rnf_tm   (:,:)          = rnf_tm     (:,:)       + rnf   (:,:) 
@@ -204,14 +229,14 @@
             fmmflx(:,:)          = fmmflx_tm  (:,:) * r1_ndttrc 
             fr_i  (:,:)          = fr_i_tm    (:,:) * r1_ndttrc
-# if defined key_trabbl
-            IF( nn_bbl_ldf == 1 ) THEN
-               ahu_bbl(:,:)      = ahu_bbl_tm (:,:) * r1_ndttrc  
-               ahv_bbl(:,:)      = ahv_bbl_tm (:,:) * r1_ndttrc 
-            ENDIF
-            IF( nn_bbl_adv == 1 ) THEN
-               utr_bbl(:,:)      = utr_bbl_tm (:,:) * r1_ndttrc  
-               vtr_bbl(:,:)      = vtr_bbl_tm (:,:) * r1_ndttrc 
-            ENDIF
-# endif
+            IF( ln_trabbl ) THEN
+               IF( nn_bbl_ldf == 1 ) THEN
+                  ahu_bbl(:,:)      = ahu_bbl_tm (:,:) * r1_ndttrc  
+                  ahv_bbl(:,:)      = ahv_bbl_tm (:,:) * r1_ndttrc 
+               ENDIF
+               IF( nn_bbl_adv == 1 ) THEN
+                  utr_bbl(:,:)      = utr_bbl_tm (:,:) * r1_ndttrc  
+                  vtr_bbl(:,:)      = vtr_bbl_tm (:,:) * r1_ndttrc 
+               ENDIF
+            ENDIF
          ELSE
             wndm  (:,:)          = wndm_tm    (:,:) * r1_ndttrcp1 
@@ -220,14 +245,14 @@
             fmmflx(:,:)          = fmmflx_tm  (:,:) * r1_ndttrcp1 
             fr_i  (:,:)          = fr_i_tm    (:,:) * r1_ndttrcp1 
-# if defined key_trabbl
-            IF( nn_bbl_ldf == 1 ) THEN
-               ahu_bbl(:,:)      = ahu_bbl_tm (:,:) * r1_ndttrcp1  
-               ahv_bbl(:,:)      = ahv_bbl_tm (:,:) * r1_ndttrcp1 
-            ENDIF
-            IF( nn_bbl_adv == 1 ) THEN
-               utr_bbl(:,:)      = utr_bbl_tm (:,:) * r1_ndttrcp1  
-               vtr_bbl(:,:)      = vtr_bbl_tm (:,:) * r1_ndttrcp1 
-            ENDIF
-# endif
+            IF( ln_trabbl ) THEN
+               IF( nn_bbl_ldf == 1 ) THEN
+                  ahu_bbl(:,:)      = ahu_bbl_tm (:,:) * r1_ndttrcp1  
+                  ahv_bbl(:,:)      = ahv_bbl_tm (:,:) * r1_ndttrcp1 
+               ENDIF
+               IF( nn_bbl_adv == 1 ) THEN
+                  utr_bbl(:,:)      = utr_bbl_tm (:,:) * r1_ndttrcp1  
+                  vtr_bbl(:,:)      = vtr_bbl_tm (:,:) * r1_ndttrcp1 
+               ENDIF
+            ENDIF
          ENDIF
          !
@@ -245,9 +270,6 @@
                   tsn  (ji,jj,jk,jp_sal) = tsn_tm  (ji,jj,jk,jp_sal) * z1_ne3t
                   rhop (ji,jj,jk)        = rhop_tm (ji,jj,jk)        * z1_ne3t
-!!gm : BUG? ==>> for avt & avs I don't understand the division by e3w
-                  avt  (ji,jj,jk)        = avt_tm  (ji,jj,jk)        * z1_ne3w
-# if defined key_zdfddm
+!!gm : BUG ==>> for avs I don't understand the division by e3w
                   avs  (ji,jj,jk)        = avs_tm  (ji,jj,jk)        * z1_ne3w
-# endif
                END DO
             END DO
@@ -264,5 +286,5 @@
       ENDIF
       !
-      IF( nn_timing == 1 )  CALL timing_start('trc_sub_stp')
+      IF( nn_timing == 1 )  CALL timing_stop('trc_sub_stp')
       !
    END SUBROUTINE trc_sub_stp
@@ -297,8 +319,5 @@
       rhop_tm (:,:,:)        = rhop (:,:,:)        * e3t_n(:,:,:)  
 !!gm : BUG? ==>> for avt & avs I don't understand the division by e3w
-      avt_tm  (:,:,:)        = avt  (:,:,:)        * e3w_n(:,:,:)  
-# if defined key_zdfddm
       avs_tm  (:,:,:)        = avs  (:,:,:)        * e3w_n(:,:,:)  
-# endif
       IF( l_ldfslp ) THEN
          wslpi_tm(:,:,:)     = wslpi(:,:,:)
@@ -313,19 +332,19 @@
 
       ! Physics variables that are set after initialization:
-      fr_i_tm(:,:) = 0._wp
-      emp_tm (:,:) = 0._wp
+      fr_i_tm  (:,:) = 0._wp
+      emp_tm   (:,:) = 0._wp
       fmmflx_tm(:,:)  = 0._wp
-      qsr_tm (:,:) = 0._wp
-      wndm_tm(:,:) = 0._wp
-# if defined key_trabbl
-      IF( nn_bbl_ldf == 1 ) THEN
-         ahu_bbl_tm(:,:) = 0._wp
-         ahv_bbl_tm(:,:) = 0._wp
-      ENDIF
-      IF( nn_bbl_adv == 1 ) THEN
-         utr_bbl_tm(:,:) = 0._wp
-         vtr_bbl_tm(:,:) = 0._wp
-      ENDIF
-# endif
+      qsr_tm   (:,:) = 0._wp
+      wndm_tm  (:,:) = 0._wp
+      IF( ln_trabbl ) THEN
+         IF( nn_bbl_ldf == 1 ) THEN
+            ahu_bbl_tm(:,:) = 0._wp
+            ahv_bbl_tm(:,:) = 0._wp
+         ENDIF
+         IF( nn_bbl_adv == 1 ) THEN
+            utr_bbl_tm(:,:) = 0._wp
+            vtr_bbl_tm(:,:) = 0._wp
+         ENDIF
+      ENDIF
       !
       IF( nn_timing == 1 )  CALL timing_stop('trc_sub_ini')
@@ -354,8 +373,5 @@
       tsn   (:,:,:,:) =  tsn_temp   (:,:,:,:)
       rhop  (:,:,:)   =  rhop_temp  (:,:,:)
-      avt   (:,:,:)   =  avt_temp   (:,:,:)
-# if defined key_zdfddm
       avs   (:,:,:)   =  avs_temp   (:,:,:)
-# endif
       IF( l_ldfslp ) THEN
          wslpi (:,:,:)=  wslpi_temp (:,:,:)
@@ -377,14 +393,14 @@
       qsr   (:,:)     =  qsr_temp   (:,:)
       wndm  (:,:)     =  wndm_temp  (:,:)
-# if defined key_trabbl
-      IF( nn_bbl_ldf == 1 ) THEN
-         ahu_bbl(:,:) = ahu_bbl_temp(:,:) 
-         ahv_bbl(:,:) = ahv_bbl_temp(:,:) 
-      ENDIF
-      IF( nn_bbl_adv == 1 ) THEN
-         utr_bbl(:,:) = utr_bbl_temp(:,:) 
-         vtr_bbl(:,:) = vtr_bbl_temp(:,:) 
-      ENDIF
-# endif
+      IF( ln_trabbl ) THEN
+         IF( nn_bbl_ldf == 1 ) THEN
+            ahu_bbl(:,:) = ahu_bbl_temp(:,:) 
+            ahv_bbl(:,:) = ahv_bbl_temp(:,:) 
+         ENDIF
+         IF( nn_bbl_adv == 1 ) THEN
+            utr_bbl(:,:) = utr_bbl_temp(:,:) 
+            vtr_bbl(:,:) = vtr_bbl_temp(:,:) 
+         ENDIF
+      ENDIF
       !
       hdivn (:,:,:)   =  hdivn_temp (:,:,:)
@@ -396,8 +412,5 @@
          tsn_tm  (:,:,:,jp_sal) = tsn  (:,:,:,jp_sal) * e3t_n(:,:,:)  
          rhop_tm (:,:,:)        = rhop (:,:,:)        * e3t_n(:,:,:)  
-         avt_tm  (:,:,:)        = avt  (:,:,:)        * e3w_n(:,:,:)  
-# if defined key_zdfddm
          avs_tm  (:,:,:)        = avs  (:,:,:)        * e3w_n(:,:,:)  
-# endif
       IF( l_ldfslp ) THEN
          uslp_tm (:,:,:)        = uslp (:,:,:)
@@ -418,14 +431,14 @@
       qsr_tm     (:,:) = qsr   (:,:)
       wndm_tm    (:,:) = wndm  (:,:)
-# if defined key_trabbl
-      IF( nn_bbl_ldf == 1 ) THEN
-         ahu_bbl_tm(:,:) = ahu_bbl(:,:) 
-         ahv_bbl_tm(:,:) = ahv_bbl(:,:) 
-      ENDIF
-      IF( nn_bbl_adv == 1 ) THEN
-         utr_bbl_tm(:,:) = utr_bbl(:,:) 
-         vtr_bbl_tm(:,:) = vtr_bbl(:,:) 
-      ENDIF
-# endif
+      IF( ln_trabbl ) THEN
+         IF( nn_bbl_ldf == 1 ) THEN
+            ahu_bbl_tm(:,:) = ahu_bbl(:,:) 
+            ahv_bbl_tm(:,:) = ahv_bbl(:,:) 
+         ENDIF
+         IF( nn_bbl_adv == 1 ) THEN
+            utr_bbl_tm(:,:) = utr_bbl(:,:) 
+            vtr_bbl_tm(:,:) = vtr_bbl(:,:) 
+         ENDIF
+      ENDIF
       !
       !
@@ -530,49 +543,46 @@
       !!-------------------------------------------------------------------
       USE lib_mpp, ONLY: ctl_warn
-      INTEGER ::  ierr
-      !!-------------------------------------------------------------------
-      !
-      ALLOCATE( un_temp(jpi,jpj,jpk)        ,  vn_temp(jpi,jpj,jpk)  ,   &
-         &      wn_temp(jpi,jpj,jpk)        ,  avt_temp(jpi,jpj,jpk) ,   &
-         &      rhop_temp(jpi,jpj,jpk)      ,  rhop_tm(jpi,jpj,jpk) ,   &
-         &      sshn_temp(jpi,jpj)          ,  sshb_temp(jpi,jpj) ,      &
-         &      ssha_temp(jpi,jpj)          ,                           &
-#if defined key_trabbl
-         &      ahu_bbl_temp(jpi,jpj)       ,  ahv_bbl_temp(jpi,jpj),    &
-         &      utr_bbl_temp(jpi,jpj)       ,  vtr_bbl_temp(jpi,jpj),    &
-#endif
-         &      rnf_temp(jpi,jpj)           ,  h_rnf_temp(jpi,jpj) ,     &
-         &      tsn_temp(jpi,jpj,jpk,2)     ,  emp_b_temp(jpi,jpj),      &
-         &      emp_temp(jpi,jpj)           ,  fmmflx_temp(jpi,jpj),     &
-         &      hmld_temp(jpi,jpj)          ,  qsr_temp(jpi,jpj) ,       &
-         &      fr_i_temp(jpi,jpj)          ,  fr_i_tm(jpi,jpj) ,        &
-         &      wndm_temp(jpi,jpj)          ,  wndm_tm(jpi,jpj) ,        &
-# if defined key_zdfddm
-         &      avs_tm(jpi,jpj,jpk)         ,  avs_temp(jpi,jpj,jpk) ,   &
-# endif
-         &      hdivn_temp(jpi,jpj,jpk)     ,  hdivb_temp(jpi,jpj,jpk),  &
-         &      un_tm(jpi,jpj,jpk)          ,  vn_tm(jpi,jpj,jpk)  ,     &
-         &      avt_tm(jpi,jpj,jpk)                                ,     &
-         &      sshn_tm(jpi,jpj)            ,  sshb_hold(jpi,jpj) ,      &
-         &      tsn_tm(jpi,jpj,jpk,2)       ,                            &
-         &      emp_tm(jpi,jpj)             ,  fmmflx_tm(jpi,jpj)  ,     &
-         &      emp_b_hold(jpi,jpj)         ,                            &
-         &      hmld_tm(jpi,jpj)            ,  qsr_tm(jpi,jpj) ,         &
-#if defined key_trabbl
-         &      ahu_bbl_tm(jpi,jpj)         ,  ahv_bbl_tm(jpi,jpj),      &
-         &      utr_bbl_tm(jpi,jpj)         ,  vtr_bbl_tm(jpi,jpj),      &
-#endif
-         &      rnf_tm(jpi,jpj)             ,  h_rnf_tm(jpi,jpj) , STAT=trc_sub_alloc )  
+      INTEGER ::  ierr(3)
+      !!-------------------------------------------------------------------
+      !
+      ierr(:) = 0
+      !
+      ALLOCATE( un_temp(jpi,jpj,jpk)      ,  vn_temp(jpi,jpj,jpk)   ,     &
+         &      wn_temp(jpi,jpj,jpk)      ,                               &
+         &      rhop_temp(jpi,jpj,jpk)    ,  rhop_tm(jpi,jpj,jpk)   ,     &
+         &      sshn_temp(jpi,jpj)        ,  sshb_temp(jpi,jpj)     ,     &
+         &      ssha_temp(jpi,jpj)        ,                               &
+         &      rnf_temp(jpi,jpj)         ,  h_rnf_temp(jpi,jpj)    ,     &
+         &      tsn_temp(jpi,jpj,jpk,2)   ,  emp_b_temp(jpi,jpj)    ,     &
+         &      emp_temp(jpi,jpj)         ,  fmmflx_temp(jpi,jpj)   ,     &
+         &      hmld_temp(jpi,jpj)        ,  qsr_temp(jpi,jpj)      ,     &
+         &      fr_i_temp(jpi,jpj)        ,  fr_i_tm(jpi,jpj)       ,     &
+         &      wndm_temp(jpi,jpj)        ,  wndm_tm(jpi,jpj)       ,     &
+         &      avs_tm(jpi,jpj,jpk)       ,  avs_temp(jpi,jpj,jpk)  ,     &
+         &      hdivn_temp(jpi,jpj,jpk)   ,  hdivb_temp(jpi,jpj,jpk),     &
+         &      un_tm(jpi,jpj,jpk)        ,  vn_tm(jpi,jpj,jpk)     ,     &
+         &      sshn_tm(jpi,jpj)          ,  sshb_hold(jpi,jpj)     ,     &
+         &      tsn_tm(jpi,jpj,jpk,2)     ,                               &
+         &      emp_tm(jpi,jpj)           ,  fmmflx_tm(jpi,jpj)     ,     &
+         &      emp_b_hold(jpi,jpj)       ,                               &
+         &      hmld_tm(jpi,jpj)          ,  qsr_tm(jpi,jpj)        ,     &
+         &      rnf_tm(jpi,jpj)           ,  h_rnf_tm(jpi,jpj)      , STAT=ierr(1) )  
+      !
+      IF( l_ldfslp ) THEN
+         ALLOCATE( uslp_temp(jpi,jpj,jpk) ,  wslpi_temp(jpi,jpj,jpk),     &
+            &      vslp_temp(jpi,jpj,jpk) ,  wslpj_temp(jpi,jpj,jpk),     &
+            &      uslp_tm  (jpi,jpj,jpk) ,  wslpi_tm  (jpi,jpj,jpk),     &
+            &      vslp_tm  (jpi,jpj,jpk) ,  wslpj_tm  (jpi,jpj,jpk), STAT=ierr(2) )
+      ENDIF
+      IF( ln_trabbl ) THEN
+         ALLOCATE( ahu_bbl_temp(jpi,jpj)  , utr_bbl_temp(jpi,jpj)   ,     &
+            &      ahv_bbl_temp(jpi,jpj)  , vtr_bbl_temp(jpi,jpj)   ,     &
+            &      ahu_bbl_tm  (jpi,jpj)  , utr_bbl_tm  (jpi,jpj)   ,     &
+            &      ahv_bbl_tm  (jpi,jpj)  , vtr_bbl_tm  (jpi,jpj)   , STAT=ierr(3) ) 
+      ENDIF
+      !
+      trc_sub_alloc = MAXVAL( ierr )
       !
       IF( trc_sub_alloc /= 0 )   CALL ctl_warn('trc_sub_alloc: failed to allocate arrays')
-      !
-      IF( l_ldfslp ) THEN
-         ALLOCATE( uslp_temp(jpi,jpj,jpk)   ,  wslpi_temp(jpi,jpj,jpk),      &
-            &      vslp_temp(jpi,jpj,jpk)   ,  wslpj_temp(jpi,jpj,jpk),      &
-            &      uslp_tm  (jpi,jpj,jpk)   ,  wslpi_tm  (jpi,jpj,jpk),      &
-            &      vslp_tm  (jpi,jpj,jpk)   ,  wslpj_tm  (jpi,jpj,jpk),  STAT=trc_sub_alloc )
-      ENDIF
-      !
-      IF( trc_sub_alloc /= 0 )   CALL ctl_warn('trc_sub_alloc: failed to allocate ldf_slp arrays')
       !
    END FUNCTION trc_sub_alloc
Index: /branches/2017/dev_merge_2017/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_MOBILIS
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_MOBILIS	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_MOBILIS	(revision 9019)
@@ -8,5 +8,5 @@
 module load intel/compiler/64/14.0/2013_sp1.2.144
 module load openmpi/intel/64/1.6.5
-module load slurm/2.5.7
+module load slurm/16.05.8
 
 #
Index: /branches/2017/dev_merge_2017/NEMOGCM/SETTE/README
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/SETTE/README	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/SETTE/README	(revision 9019)
@@ -45,5 +45,5 @@
                INPUT_DIR   	   : directory in which store input files (tar file)
                TMPDIR      	   : temporary directory NEEDED ONLY FOR IBM machines (put EXP00 directory)
-	       NEMO_VALIDATION_DIR : directory in which create NEMO_VALIDATION tree, and store restart, solver.stat, tracer.stat and ocean.output files in
+	       NEMO_VALIDATION_DIR : directory in which create NEMO_VALIDATION tree, and store restart, run.stat, tracer.stat and ocean.output files in
       			             tree NEMO_VALIDATION_DIR/WCONFIG_NAME/WCOMPILER_NAME/TEST_NAME/REVISION_NUMBER(or DATE)
  in fcm_job.sh :
Index: /branches/2017/dev_merge_2017/NEMOGCM/SETTE/all_functions.sh
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/SETTE/all_functions.sh	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/SETTE/all_functions.sh	(revision 9019)
@@ -220,17 +220,17 @@
     fi
     # Save output & debug files in NEMO_VALIDATION tree
-    echo "saving ocean & ice output, solver.stat, tracer.stat files ...." >> ${SETTE_DIR}/output.sette
+    echo "saving ocean & ice output, run.stat, tracer.stat files ...." >> ${SETTE_DIR}/output.sette
     echo "            " >> ${SETTE_DIR}/output.sette
     [ -f ${EXE_DIR}/ocean.output ] && cp ${EXE_DIR}/*ocean.output ${NEMO_VALID}/.
-    [ -f ${EXE_DIR}/solver.stat ] && cp ${EXE_DIR}/*solver.stat ${NEMO_VALID}/.
+    [ -f ${EXE_DIR}/run.stat ] && cp ${EXE_DIR}/*run.stat ${NEMO_VALID}/.
     [ -f ${EXE_DIR}/output.namelist.dyn ] && cp ${EXE_DIR}/*output.nam* ${NEMO_VALID}/.
     [ -f ${EXE_DIR}/tracer.stat ] && cp ${EXE_DIR}/*tracer.stat ${NEMO_VALID}/.
 
-    if [ -n "$(ls ${NEMO_VALID}/*solver*)" ] ; then
-	echo "moved solver.stat in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
-	echo "moved solver.stat in ${NEMO_VALID} directory"  
+    if [ -n "$(ls ${NEMO_VALID}/*run*)" ] ; then
+	echo "moved run.stat in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
+	echo "moved run.stat in ${NEMO_VALID} directory"  
     else
-	echo "problem in looking for solver.stat file in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
-	echo "solver.stat IS NOT in ${NEMO_VALID} directory" 
+	echo "problem in looking for run.stat file in ${NEMO_VALID} directory"  >> ${SETTE_DIR}/output.sette
+	echo "run.stat IS NOT in ${NEMO_VALID} directory" 
     fi
     if [ -n "$(ls ${NEMO_VALID}/*ocean.output*)" ] ; then
Index: /branches/2017/dev_merge_2017/NEMOGCM/SETTE/input_ISOMIP.cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/SETTE/input_ISOMIP.cfg	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/SETTE/input_ISOMIP.cfg	(revision 9019)
@@ -0,0 +1,1 @@
+ISOMIP_v3.7.tar ISOMIP_v3.7
Index: /branches/2017/dev_merge_2017/NEMOGCM/SETTE/param.cfg
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/SETTE/param.cfg	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/SETTE/param.cfg	(revision 9019)
@@ -1,4 +1,4 @@
 #- forcing files storing
-FORCING_DIR=~/FORCING
+FORCING_DIR=/workgpfs/rech/omr/romr009/FORCING
 #- input files storing
 INPUT_DIR=${CONFIG_DIR}/${NEW_CONF}/EXP00
@@ -6,3 +6,3 @@
 #TMPDIR=${CONFIG_DIR}/${NEW_CONF}/EXP00
 #- VALIDATION files storing
-NEMO_VALIDATION_DIR=~/NEMO_VALIDATION_DIR
+NEMO_VALIDATION_DIR=/workgpfs/rech/omr/romr009/CNRS_merge_2017
Index: /branches/2017/dev_merge_2017/NEMOGCM/SETTE/sette.sh
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/SETTE/sette.sh	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/SETTE/sette.sh	(revision 9019)
@@ -56,5 +56,5 @@
 #   set_namelist     : function declared in all_functions that sets namelist parameters 
 #   post_test_tidyup : creates validation storage directory and copies required output files 
-#                      (solver.stat and ocean.output) in it after execution of test.
+#                      (run.stat and ocean.output) in it after execution of test.
 #
 #  VALIDATION tree is:
@@ -133,15 +133,15 @@
 cp BATCH_TEMPLATE/${JOB_PREFIX}-${COMPILER} job_batch_template || exit
 # Description of configuration tested:
-# GYRE_PISCES       :  1 &  2
-# ORCA2_LIM3_PISCES :  3 &  4
-# ORCA2_OFF_PISCES  :  5 &  6
-# AMM12             :  7 &  8 
-# SAS               :  9     fos SAS there is no solver so is useless to test REPRO
-# ISOMIP            : 10 & 11
-# ORCA2_LIM3_OBS    : 12
-# ORCA2_AGRIF_LIM3  : 13 & 14 
-#                     15 & 16 
-
-for config in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
+# GYRE_PISCES       :  1 
+# ORCA2_LIM3_PISCES :  2 
+# ORCA2_OFF_PISCES  :  3 
+# AMM12             :  4 
+# SAS               :  5     fos SAS there is no run.stat so is useless to test REPRO
+# ISOMIP            :  6
+# ORCA2_LIM3_OBS    :  7
+# ORCA2_AGRIF_LIM3  :  8 
+# ORCA2AGR          :  9 & 10  AGRIF active with no zoom, compared to no AGRIF cpp key
+
+for config in 1 2 3 4 5 6 7 8 9 10
 do
 
@@ -151,5 +151,5 @@
     export TEST_NAME="LONG"
     cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n GYREPIS_LONG -r GYRE_PISCES -j 8 del_key ${DEL_KEYS}
+    . ./makenemo -m ${CMP_NAM} -n GYREPIS_ST -r GYRE_PISCES -j 8 del_key ${DEL_KEYS}
     cd ${SETTE_DIR}
     . ./param.cfg
@@ -220,11 +220,8 @@
     cd ${SETTE_DIR}
     . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
-fi
-
-if [ ${config} -eq 2 ] ;  then
+
     ## Reproducibility tests for GYRE_PISCES
     export TEST_NAME="REPRO_4_8"
     cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n GYREPIS_32 -r GYRE_PISCES -j 8 del_key ${DEL_KEYS}
     cd ${SETTE_DIR}
     . ./param.cfg
@@ -287,9 +284,9 @@
 
 # TESTS FOR ORCA2_LIM3_PISCES CONFIGURATION
-if [ ${config} -eq 3 ] ;  then
+if [ ${config} -eq 2 ] ;  then
     ## Restartability tests for ORCA2_LIM3_PISCES
     export TEST_NAME="LONG"
     cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n ORCA2LIM3PIS_LONG -r ORCA2_LIM3_PISCES -j 8 del_key ${DEL_KEYS}
+    . ./makenemo -m ${CMP_NAM} -n ORCA2LIM3PIS_ST -r ORCA2_LIM3_PISCES -j 8 del_key ${DEL_KEYS}
     cd ${SETTE_DIR}
     . ./param.cfg
@@ -311,4 +308,6 @@
     set_namelist namelist_cfg jpnj 8
     set_namelist namelist_cfg jpnij 32
+    set_namelist namelist_ice_cfg ln_icediachk .true.
+##    set_namelist namelist_ice_cfg ln_icediahsb .true.
     set_namelist namelist_top_cfg ln_trcdta .false.
     # put ln_ironsed, ln_river, ln_ndepo, ln_dust to false
@@ -349,9 +348,11 @@
     set_namelist namelist_cfg jpnj 8
     set_namelist namelist_cfg jpnij 32
+    set_namelist namelist_ice_cfg ln_icediachk .true.
+##    set_namelist namelist_ice_cfg ln_icediahsb .true.
     set_namelist namelist_top_cfg ln_rsttr .true.
     set_namelist namelist_top_cfg nn_rsttr 2
     set_namelist namelist_cfg cn_ocerst_in \"O2L3P_LONG_00000075_restart\"
+    set_namelist namelist_top_cfg cn_trcrst_in \"O2L3P_LONG_00000075_restart_trc\"
     set_namelist namelist_ice_cfg cn_icerst_in \"O2L3P_LONG_00000075_restart_ice\"
-    set_namelist namelist_top_cfg cn_trcrst_in \"O2L3P_LONG_00000075_restart_trc\"
     # put ln_ironsed, ln_river, ln_ndepo, ln_dust
     # if not you need input files, and for tests is not necessary
@@ -384,19 +385,17 @@
     cd ${SETTE_DIR}
     . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
-fi
-
-if [ ${config} -eq 4 ] ;  then
+
     ## Reproducibility tests for ORCA2_LIM3_PISCES
     export TEST_NAME="REPRO_4_8"
     cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n ORCA2LIM3PIS_32 -r ORCA2_LIM3_PISCES -j 8 del_key ${DEL_KEYS}
-    cd ${SETTE_DIR}
-    . ./param.cfg
-    . ./all_functions.sh
-    . ./prepare_exe_dir.sh
-    JOB_FILE=${EXE_DIR}/run_job.sh
-    NPROC=32
-    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
-    cd ${EXE_DIR}
+    cd ${SETTE_DIR}
+    . ./param.cfg
+    . ./all_functions.sh
+    . ./prepare_exe_dir.sh
+    JOB_FILE=${EXE_DIR}/run_job.sh
+    NPROC=32
+    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
+    cd ${EXE_DIR}
+    set_namelist namelist_cfg cn_exp \"O2L3P_48\"
     set_namelist namelist_cfg nn_it000 1
     set_namelist namelist_cfg nn_itend 75
@@ -410,4 +409,6 @@
     set_namelist namelist_cfg jpnj 8
     set_namelist namelist_cfg jpnij 32
+    set_namelist namelist_ice_cfg ln_icediachk .true.
+    set_namelist namelist_ice_cfg ln_icediahsb .true.
     set_namelist namelist_top_cfg ln_trcdta .false.
     # put ln_ironsed, ln_river, ln_ndepo, ln_dust to false
@@ -441,4 +442,5 @@
     if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
     cd ${EXE_DIR}
+    set_namelist namelist_cfg cn_exp \"O2L3P_84\"
     set_namelist namelist_cfg nn_it000 1
     set_namelist namelist_cfg nn_itend 75
@@ -451,4 +453,6 @@
     set_namelist namelist_cfg jpnj 4
     set_namelist namelist_cfg jpnij 32
+    set_namelist namelist_ice_cfg ln_icediachk .true.
+    set_namelist namelist_ice_cfg ln_icediahsb .true.
     set_namelist namelist_top_cfg ln_trcdta .false.
     # put ln_ironsed, ln_river, ln_ndepo, ln_dust to false
@@ -477,9 +481,9 @@
 
 # TESTS FOR ORCA2_OFF_PISCES CONFIGURATION
-if [ ${config} -eq 5 ] ;  then
+if [ ${config} -eq 3 ] ;  then
     ## Restartability tests for ORCA2_OFF_PISCES
     export TEST_NAME="LONG"
     cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n ORCA2OFFPIS_LONG -r ORCA2_OFF_PISCES -j 8 del_key ${DEL_KEYS}
+    . ./makenemo -m ${CMP_NAM} -n ORCA2OFFPIS_ST -r ORCA2_OFF_PISCES -j 8 del_key ${DEL_KEYS}
     cd ${SETTE_DIR}
     . ./param.cfg
@@ -566,19 +570,17 @@
     cd ${SETTE_DIR}
     . ./fcm_job.sh $NPROC  ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
-fi
-
-if [ ${config} -eq 6 ] ;  then
+
     ## Reproducibility tests for ORCA2_OFF_PISCES
     export TEST_NAME="REPRO_4_8"
     cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n ORCA2OFFPIS_32 -r ORCA2_OFF_PISCES -j 8 del_key ${DEL_KEYS}
-    cd ${SETTE_DIR}
-    . ./param.cfg
-    . ./all_functions.sh
-    . ./prepare_exe_dir.sh
-    JOB_FILE=${EXE_DIR}/run_job.sh
-    NPROC=32
-    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
-    cd ${EXE_DIR}
+    cd ${SETTE_DIR}
+    . ./param.cfg
+    . ./all_functions.sh
+    . ./prepare_exe_dir.sh
+    JOB_FILE=${EXE_DIR}/run_job.sh
+    NPROC=32
+    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
+    cd ${EXE_DIR}
+    set_namelist namelist_cfg cn_exp \"OFFP_48\"
     set_namelist namelist_cfg nn_it000 1
     set_namelist namelist_cfg nn_itend 40
@@ -621,4 +623,5 @@
     if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
     cd ${EXE_DIR}
+    set_namelist namelist_cfg cn_exp \"OFFP_84\"
     set_namelist namelist_cfg nn_it000 1
     set_namelist namelist_cfg nn_itend 40
@@ -656,17 +659,18 @@
 
 # TESTS FOR AMM12 CONFIGURATION
-if [ ${config} -eq 7 ] ;  then
+if [ ${config} -eq 4 ] ;  then
     ## Restartability tests for AMM12
     export TEST_NAME="LONG"
     cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n AMM12_LONG -r AMM12 -j 8 del_key ${DEL_KEYS}
-    cd ${SETTE_DIR}
-    . ./param.cfg
-    . ./all_functions.sh
-    . ./prepare_exe_dir.sh
-    JOB_FILE=${EXE_DIR}/run_job.sh
-    NPROC=32
-    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
-    cd ${EXE_DIR}
+    . ./makenemo -m ${CMP_NAM} -n AMM12_ST -r AMM12 -j 8 del_key ${DEL_KEYS}
+    cd ${SETTE_DIR}
+    . ./param.cfg
+    . ./all_functions.sh
+    . ./prepare_exe_dir.sh
+    JOB_FILE=${EXE_DIR}/run_job.sh
+    NPROC=32
+    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
+    cd ${EXE_DIR}
+    set_namelist namelist_cfg cn_exp \"AMM12_LONG\"
     set_namelist namelist_cfg nn_it000 1
     set_namelist namelist_cfg nn_itend 576
@@ -677,4 +681,8 @@
     set_namelist namelist_cfg ln_read_cfg .true.
     set_namelist namelist_cfg ln_linssh .false.
+##SF 
+    set_namelist namelist_cfg ln_lin .true.
+    set_namelist namelist_cfg ln_loglayer .false.
+##SF
     set_namelist namelist_cfg jpni 4
     set_namelist namelist_cfg jpnj 8
@@ -692,4 +700,5 @@
     . ./prepare_exe_dir.sh
     cd ${EXE_DIR}
+    set_namelist namelist_cfg cn_exp \"AMM12_SHORT\"
     set_namelist namelist_cfg nn_it000 289
     set_namelist namelist_cfg nn_itend 576
@@ -699,4 +708,8 @@
     set_namelist namelist_cfg ln_read_cfg .true.
     set_namelist namelist_cfg ln_linssh .false.
+##SF 
+    set_namelist namelist_cfg ln_lin .true.
+    set_namelist namelist_cfg ln_loglayer .false.
+##SF
     set_namelist namelist_cfg jpni 4
     set_namelist namelist_cfg jpnj 8
@@ -704,10 +717,10 @@
     set_namelist namelist_cfg ln_rstart .true.
     set_namelist namelist_cfg nn_rstctl 2
-    set_namelist namelist_cfg cn_ocerst_in \"AMM12_00000288_restart_oce_out\"
+    set_namelist namelist_cfg cn_ocerst_in \"AMM12_LONG_00000288_restart\"
     set_namelist namelist_cfg nn_date0 20120102
     for (( i=1; i<=$NPROC; i++)) ; do
         L_NPROC=$(( $i - 1 ))
         L_NPROC=`printf "%04d\n" ${L_NPROC}`
-        ln -sf ../LONG/AMM12_00000288_restart_oce_out_${L_NPROC}.nc .
+        ln -sf ../LONG/AMM12_LONG_00000288_restart_${L_NPROC}.nc .
     done
     if [ ${USING_MPMD} == "yes" ] ; then
@@ -720,19 +733,17 @@
     cd ${SETTE_DIR}
     . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
-fi
-
-if [ ${config} -eq 8 ] ;  then
+
 ## Reproducibility tests for AMM12
     export TEST_NAME="REPRO_8_4"
     cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n AMM12_32 -r AMM12 -j 8 del_key ${DEL_KEYS}
-    cd ${SETTE_DIR}
-    . ./param.cfg
-    . ./all_functions.sh
-    . ./prepare_exe_dir.sh
-    JOB_FILE=${EXE_DIR}/run_job.sh
-    NPROC=32
-    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
-    cd ${EXE_DIR}
+    cd ${SETTE_DIR}
+    . ./param.cfg
+    . ./all_functions.sh
+    . ./prepare_exe_dir.sh
+    JOB_FILE=${EXE_DIR}/run_job.sh
+    NPROC=32
+    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
+    cd ${EXE_DIR}
+    set_namelist namelist_cfg cn_exp \"AMM12_84\"
     set_namelist namelist_cfg nn_it000 1
     set_namelist namelist_cfg nn_itend 576
@@ -742,4 +753,8 @@
     set_namelist namelist_cfg ln_read_cfg .true.
     set_namelist namelist_cfg ln_linssh .false.
+##SF 
+    set_namelist namelist_cfg ln_lin .true.
+    set_namelist namelist_cfg ln_loglayer .false.
+##SF
     set_namelist namelist_cfg jpni 8
     set_namelist namelist_cfg jpnj 4
@@ -761,4 +776,5 @@
     if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
     cd ${EXE_DIR}
+    set_namelist namelist_cfg cn_exp \"AMM12_48\"
     set_namelist namelist_cfg nn_it000 1
     set_namelist namelist_cfg nn_itend 576
@@ -768,4 +784,8 @@
     set_namelist namelist_cfg ln_read_cfg .true.
     set_namelist namelist_cfg ln_linssh .false.
+##SF 
+    set_namelist namelist_cfg ln_lin .true.
+    set_namelist namelist_cfg ln_loglayer .false.
+##SF
     set_namelist namelist_cfg jpni 4
     set_namelist namelist_cfg jpnj 8
@@ -784,9 +804,9 @@
 
 # TESTS FOR ORCA2_SAS_LIM3 CONFIGURATION
-if [ ${config} -eq 9 ] ;  then
+if [ ${config} -eq 5 ] ;  then
     ## Restartability tests for SAS
     export TEST_NAME="LONG"
     cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n SAS_LONG -r ORCA2_SAS_LIM3 -j 8 del_key ${DEL_KEYS}
+    . ./makenemo -m ${CMP_NAM} -n SAS_ST -r ORCA2_SAS_LIM3 -j 8 del_key ${DEL_KEYS}
     cd ${SETTE_DIR}
     . ./param.cfg
@@ -810,4 +830,5 @@
     set_namelist namelist_cfg jpnj 8
     set_namelist namelist_cfg jpnij 32
+    set_namelist namelist_ice_cfg ln_icediachk .true.
     if [ ${USING_MPMD} == "yes" ] ; then
        set_xio_using_server iodef.xml true
@@ -836,5 +857,5 @@
     set_namelist namelist_cfg ln_rstart .true.
     set_namelist namelist_cfg nn_rstctl 2
-    set_namelist namelist_cfg nn_date0 010106
+    set_namelist namelist_cfg nn_date0 010109
     set_namelist namelist_cfg cn_ocerst_in \"SAS_00000120_restart\"
     set_namelist namelist_ice_cfg cn_icerst_in \"SAS_00000120_restart_ice\"
@@ -857,9 +878,9 @@
 
 # TESTS FOR ISOMIP CONFIGURATION
-if [ ${config} -eq 10 ] ;  then
+if [ ${config} -eq 6 ] ;  then
     ## Restartability tests for ISOMIP
     export TEST_NAME="LONG"
     cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n ISOMIP_LONG -r ISOMIP -a TEST_CASES -j 8 del_key ${DEL_KEYS}
+    . ./makenemo -m ${CMP_NAM} -n ISOMIP_ST -r ISOMIP -a TEST_CASES -j 8 del_key ${DEL_KEYS}
     cd ${SETTE_DIR}
     . ./param.cfg
@@ -875,5 +896,15 @@
     set_namelist namelist_cfg nn_stock 48
     set_namelist namelist_cfg ln_clobber .true.
-    set_namelist namelist_cfg ln_read_cfg .false.
+    #SF come back to reading of domain_cfg for ISOMIP
+    #SF change after merge, when usrdef_zgr will be correct
+    set_namelist namelist_cfg ln_read_cfg .true.
+    set_namelist namelist_cfg cn_domcfg ISOMIP_zps_domcfg
+    #SF come back to reading of domain_cfg for ISOMIP
+    set_namelist namelist_cfg ln_icebergs .false.
+    set_namelist namelist_cfg ln_bergdia .false.
+    #SF TO BE REMOVED AFTER BUG CORRECTION OF ln_not_lin drg
+    set_namelist namelist_cfg ln_non_lin .false.
+    set_namelist namelist_cfg ln_lin .true.
+    #SF TO BE REMOVED AFTER BUG CORRECTION OF ln_not_lin drg
     set_namelist namelist_cfg jpni 4
     set_namelist namelist_cfg jpnj 8
@@ -898,5 +929,15 @@
     set_namelist namelist_cfg nn_rstctl 2
     set_namelist namelist_cfg ln_clobber .true.
-    set_namelist namelist_cfg ln_read_cfg .false.
+    #SF come back to reading of domain_cfg for ISOMIP
+    #SF change after merge, when usrdef_zgr will be correct
+    set_namelist namelist_cfg ln_read_cfg .true.
+    set_namelist namelist_cfg cn_domcfg ISOMIP_zps_domcfg
+    #SF come back to reading of domain_cfg for ISOMIP
+    set_namelist namelist_cfg ln_bergdia .false.
+    #SF TO BE REMOVED AFTER BUG CORRECTION OF ln_not_lin drg
+    #SF TO BE REMOVED AFTER BUG CORRECTION OF ln_not_lin drg
+    set_namelist namelist_cfg ln_non_lin .false.
+    set_namelist namelist_cfg ln_lin .true.
+    #SF TO BE REMOVED AFTER BUG CORRECTION OF ln_not_lin drg
     set_namelist namelist_cfg jpni 4
     set_namelist namelist_cfg jpnj 8
@@ -922,24 +963,32 @@
     cd ${SETTE_DIR}
     . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
-fi
-if [ ${config} -eq 11 ] ;  then
+
     ## Reproducibility tests for ISOMIP
     export TEST_NAME="REPRO_4_8"
     cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n ISOMIP_32 -r ISOMIP -a TEST_CASES -j 8 del_key ${DEL_KEYS}
-    cd ${SETTE_DIR}
-    . ./param.cfg
-    . ./all_functions.sh
-    . ./prepare_exe_dir.sh
-    JOB_FILE=${EXE_DIR}/run_job.sh
-    NPROC=32
-    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
-    cd ${EXE_DIR}
-    set_namelist namelist_cfg cn_exp \"ISOMIP_14\"
+    cd ${SETTE_DIR}
+    . ./param.cfg
+    . ./all_functions.sh
+    . ./prepare_exe_dir.sh
+    JOB_FILE=${EXE_DIR}/run_job.sh
+    NPROC=32
+    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
+    cd ${EXE_DIR}
+    set_namelist namelist_cfg cn_exp \"ISOMIP_48\"
     set_namelist namelist_cfg nn_it000 1
     set_namelist namelist_cfg nn_itend 48
     set_namelist namelist_cfg ln_ctl .false.
     set_namelist namelist_cfg ln_clobber .true.
-    set_namelist namelist_cfg ln_read_cfg .false.
+    #SF come back to reading of domain_cfg for ISOMIP
+    #SF change after merge, when usrdef_zgr will be correct
+    set_namelist namelist_cfg ln_read_cfg .true.
+    set_namelist namelist_cfg cn_domcfg ISOMIP_zps_domcfg
+    #SF come back to reading of domain_cfg for ISOMIP
+    set_namelist namelist_cfg ln_bergdia .false.
+    #SF TO BE REMOVED AFTER BUG CORRECTION OF ln_not_lin drg
+    #SF TO BE REMOVED AFTER BUG CORRECTION OF ln_not_lin drg
+    set_namelist namelist_cfg ln_non_lin .false.
+    set_namelist namelist_cfg ln_lin .true.
+    #SF TO BE REMOVED AFTER BUG CORRECTION OF ln_not_lin drg
     set_namelist namelist_cfg jpni 4
     set_namelist namelist_cfg jpnj 8
@@ -962,10 +1011,20 @@
     if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
     cd ${EXE_DIR}
-    set_namelist namelist_cfg cn_exp \"ISOMIP_22\"
+    set_namelist namelist_cfg cn_exp \"ISOMIP_84\"
     set_namelist namelist_cfg nn_it000 1
     set_namelist namelist_cfg nn_itend 48
     set_namelist namelist_cfg ln_ctl .false.
     set_namelist namelist_cfg ln_clobber .true.
-    set_namelist namelist_cfg ln_read_cfg .false.
+    #SF come back to reading of domain_cfg for ISOMIP
+    #SF change after merge, when usrdef_zgr will be correct
+    set_namelist namelist_cfg ln_read_cfg .true.
+    set_namelist namelist_cfg cn_domcfg ISOMIP_zps_domcfg
+    #SF come back to reading of domain_cfg for ISOMIP
+    set_namelist namelist_cfg ln_bergdia .false.
+    #SF TO BE REMOVED AFTER BUG CORRECTION OF ln_not_lin drg
+    #SF TO BE REMOVED AFTER BUG CORRECTION OF ln_not_lin drg
+    set_namelist namelist_cfg ln_non_lin .false.
+    set_namelist namelist_cfg ln_lin .true.
+    #SF TO BE REMOVED AFTER BUG CORRECTION OF ln_not_lin drg
     set_namelist namelist_cfg jpni 8
     set_namelist namelist_cfg jpnj 4
@@ -985,17 +1044,18 @@
 ## Test assimilation interface code, OBS and ASM for reproducibility
 ## Restartability not tested (ASM code not restartable while increments are being applied)
-if [ ${config} -eq 12 ] ; then
+if [ ${config} -eq 7 ] ; then
    ## Reproducibility tests for ORCA2_LIM3_OBS
     export TEST_NAME="REPRO_4_8"
     cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n ORCA2_LIM3_OBS -r ORCA2_LIM3_PISCES -d "OPA_SRC LIM_SRC_3"  -j 8 add_key "key_asminc" del_key "key_top"
-    cd ${SETTE_DIR}
-    . ./param.cfg
-    . ./all_functions.sh
-    . ./prepare_exe_dir.sh
-    JOB_FILE=${EXE_DIR}/run_job.sh
-    NPROC=32
-    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
-    cd ${EXE_DIR}
+    . ./makenemo -m ${CMP_NAM} -n ORCA2_LIM3_OBS_ST -r ORCA2_LIM3_PISCES -d "OPA_SRC LIM_SRC_3"  -j 8 add_key "key_asminc" del_key "key_top"
+    cd ${SETTE_DIR}
+    . ./param.cfg
+    . ./all_functions.sh
+    . ./prepare_exe_dir.sh
+    JOB_FILE=${EXE_DIR}/run_job.sh
+    NPROC=32
+    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
+    cd ${EXE_DIR}
+    set_namelist namelist_cfg cn_exp \"O2L3OBS_48\"
     set_namelist namelist_cfg nn_it000 1
     set_namelist namelist_cfg nn_itend 75
@@ -1051,4 +1111,5 @@
     if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
     cd ${EXE_DIR}
+    set_namelist namelist_cfg cn_exp \"O2L3OBS_84\"
     set_namelist namelist_cfg nn_it000 1
     set_namelist namelist_cfg nn_itend 75
@@ -1097,56 +1158,10 @@
     . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
 fi
-# TEST FOR ORCA2_LIM3_AGRIF : simple test of running AGRIF (no restartability neither reproducibility tests)
-if [ ${config} -eq 13 ] ;  then
-    ## ORCA2_LIM3 with Agulhas AGRIF zoom in MPI
-    export TEST_NAME="SHORT"
-    cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n ORCA2AGUL_1_2 -r ORCA2_LIM3_PISCES -d "OPA_SRC LIM_SRC_3 NST_SRC" -j 8 add_key "key_agrif" del_key "key_zdftmx key_top"
-    cd ${SETTE_DIR}
-    . ./param.cfg
-    . ./all_functions.sh
-    . ./prepare_exe_dir.sh
-    JOB_FILE=${EXE_DIR}/run_job.sh
-    NPROC=2
-    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
-    cd ${EXE_DIR}
-    set_namelist namelist_cfg nn_it000 1
-    set_namelist namelist_cfg nn_itend 75
-    set_namelist namelist_cfg ln_ctl .false.
-    set_namelist namelist_cfg ln_clobber .true.
-    set_namelist namelist_cfg ln_read_cfg .true.
-    set_namelist namelist_cfg ln_linssh .true.
-    set_namelist namelist_cfg ln_hpg_sco .false.
-    set_namelist namelist_cfg ln_hpg_zps .true. 
-    set_namelist namelist_cfg nn_fwb 0
-    set_namelist namelist_cfg jpni 1
-    set_namelist namelist_cfg jpnj 2
-    set_namelist namelist_cfg jpnij 2
-    set_namelist 1_namelist_cfg nn_it000 1
-    set_namelist 1_namelist_cfg nn_itend 150
-    set_namelist 1_namelist_cfg ln_ctl .false.
-    set_namelist 1_namelist_cfg ln_clobber .true.
-    set_namelist 1_namelist_cfg ln_read_cfg .true.
-    set_namelist 1_namelist_cfg ln_linssh .true.
-    set_namelist 1_namelist_cfg ln_hpg_sco .false.
-    set_namelist 1_namelist_cfg ln_hpg_zps .true. 
-    if [ ${USING_MPMD} == "yes" ] ; then
-       set_xio_using_server iodef.xml true
-    else
-       set_xio_using_server iodef.xml false
-    fi
-    cd ${SETTE_DIR}
-    . ./prepare_job.sh input_ORCA2_LIM3_AGRIF.cfg $NPROC ${TEST_NAME} ${MPIRUN_FLAG} ${JOB_FILE} ${NUM_XIOSERVERS}
-    cd ${SETTE_DIR}
-    . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
-fi
-
-# test code corruption with AGRIF
-# Compile and run with or without AGRIF ORCA2_LIM3
-if [ ${config} -eq 14 ] ;  then
-    # First run same as 15 but without zoom
-    export TEST_NAME="SHORT_NOZOOM"
-    cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n ORCA2AGUL_2_2 -r ORCA2_LIM3_PISCES -d "OPA_SRC LIM_SRC_3 NST_SRC" -j 8 add_key "key_agrif" del_key "key_zdftmx key_top"
+# TEST FOR ORCA2_LIM3_AGRIF : AGULHAS AGRIF
+if [ ${config} -eq 8 ] ;  then
+## Restartability tests
+    export TEST_NAME="LONG"
+    cd ${CONFIG_DIR0}
+    . ./makenemo -m ${CMP_NAM} -n ORCA2AGR_ST -r ORCA2_LIM3_PISCES -d "OPA_SRC LIM_SRC_3 NST_SRC" -j 8 add_key "key_agrif" del_key "key_top"
     cd ${SETTE_DIR}
     . ./param.cfg
@@ -1157,7 +1172,8 @@
     if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
     cd ${EXE_DIR}
-    set_namelist namelist_cfg nn_it000 1
-    set_namelist namelist_cfg nn_itend 75
-    set_namelist namelist_cfg ln_ctl .false.
+    set_namelist namelist_cfg cn_exp \"O2AGRIF_LONG\"
+    set_namelist namelist_cfg nn_it000 1
+    set_namelist namelist_cfg nn_itend 150
+    set_namelist namelist_cfg nn_stock 75
     set_namelist namelist_cfg ln_clobber .true.
     set_namelist namelist_cfg ln_read_cfg .true.
@@ -1169,81 +1185,5 @@
     set_namelist namelist_cfg jpnj 2
     set_namelist namelist_cfg jpnij 4
-# 
-#   Set the number of fine grids to zero:    
-    sed -i "1s/.*/0/" ${EXE_DIR}/AGRIF_FixedGrids.in
-
-    if [ ${USING_MPMD} == "yes" ] ; then
-       set_xio_using_server iodef.xml true
-    else
-       set_xio_using_server iodef.xml false
-    fi
-    cd ${SETTE_DIR}
-    . ./prepare_job.sh input_ORCA2_LIM3_AGRIF.cfg $NPROC ${TEST_NAME} ${MPIRUN_FLAG} ${JOB_FILE} ${NUM_XIOSERVERS}
-    cd ${SETTE_DIR}
-    . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
-
-    export TEST_NAME="SHORT_NOAGRIF"
-    cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n ORCA2AGUL_2_2_NAG -r ORCA2_LIM3_PISCES -d "OPA_SRC LIM_SRC_3 NST_SRC" -j 8 del_key "key_zdftmx key_top"
-    cd ${SETTE_DIR}
-    . ./param.cfg
-    . ./all_functions.sh
-    . ./prepare_exe_dir.sh
-    JOB_FILE=${EXE_DIR}/run_job.sh
-    NPROC=4
-    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
-    cd ${EXE_DIR}
-    set_namelist namelist_cfg nn_it000 1
-    set_namelist namelist_cfg nn_itend 75
-    set_namelist namelist_cfg ln_ctl .false.
-    set_namelist namelist_cfg ln_clobber .true.
-    set_namelist namelist_cfg ln_read_cfg .true.
-    set_namelist namelist_cfg ln_linssh .true.
-    set_namelist namelist_cfg ln_hpg_sco .false.
-    set_namelist namelist_cfg ln_hpg_zps .true. 
-    set_namelist namelist_cfg nn_fwb 0
-    set_namelist namelist_cfg jpni 2
-    set_namelist namelist_cfg jpnj 2
-    set_namelist namelist_cfg jpnij 4
-#
-    if [ ${USING_MPMD} == "yes" ] ; then
-       set_xio_using_server iodef.xml true
-    else
-       set_xio_using_server iodef.xml false
-    fi
-    cd ${SETTE_DIR}
-    . ./prepare_job.sh input_ORCA2_LIM3_AGRIF.cfg $NPROC ${TEST_NAME} ${MPIRUN_FLAG} ${JOB_FILE} ${NUM_XIOSERVERS}
-    cd ${SETTE_DIR}
-    . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
-
-fi
-
-## Restartability tests for ORCA2_LIM3_AGRIF 
-if [ ${config} -eq 15 ] ;  then
-    export TEST_NAME="LONG"
-    cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n ORCA2AGUL_LONG -r ORCA2_LIM3_PISCES -d "OPA_SRC LIM_SRC_3 NST_SRC" -j 8 add_key "key_agrif key_zdftmx" del_key "key_zdftmx_new key_top"
-    cd ${SETTE_DIR}
-    . ./param.cfg
-    . ./all_functions.sh
-    . ./prepare_exe_dir.sh
-    JOB_FILE=${EXE_DIR}/run_job.sh
-    NPROC=4
-    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
-    cd ${EXE_DIR}
-    set_namelist namelist_cfg cn_exp \"O2LP_LONG\"
-    set_namelist namelist_cfg nn_it000 1
-    set_namelist namelist_cfg nn_itend 150
-    set_namelist namelist_cfg nn_stock 75
-    set_namelist namelist_cfg ln_clobber .true.
-    set_namelist namelist_cfg ln_read_cfg .true.
-    set_namelist namelist_cfg ln_linssh .true.
-    set_namelist namelist_cfg ln_hpg_sco .false.
-    set_namelist namelist_cfg ln_hpg_zps .true. 
-    set_namelist namelist_cfg nn_fwb 0
-    set_namelist namelist_cfg jpni 2
-    set_namelist namelist_cfg jpnj 2
-    set_namelist namelist_cfg jpnij 4
-    set_namelist 1_namelist_cfg cn_exp \"O2LP_LONG\"
+    set_namelist 1_namelist_cfg cn_exp \"O2AGRIF_LONG\"
     set_namelist 1_namelist_cfg nn_it000 1
     set_namelist 1_namelist_cfg nn_itend 300
@@ -1254,4 +1194,5 @@
     set_namelist 1_namelist_cfg ln_read_cfg .true.
     set_namelist 1_namelist_cfg ln_linssh .true.
+    set_namelist 1_namelist_cfg ln_zdfiwm .false.
     set_namelist 1_namelist_cfg ln_hpg_sco .false.
     set_namelist 1_namelist_cfg ln_hpg_zps .true. 
@@ -1269,5 +1210,5 @@
     . ./prepare_exe_dir.sh
     cd ${EXE_DIR}
-    set_namelist namelist_cfg cn_exp \"O2LP_SHORT\"
+    set_namelist namelist_cfg cn_exp \"O2AGRIF_SHORT\"
     set_namelist namelist_cfg nn_it000 76
     set_namelist namelist_cfg nn_itend 150
@@ -1284,5 +1225,5 @@
     set_namelist namelist_cfg jpnj 2
     set_namelist namelist_cfg jpnij 4
-    set_namelist 1_namelist_cfg cn_exp \"O2LP_SHORT\"
+    set_namelist 1_namelist_cfg cn_exp \"O2AGRIF_SHORT\"
     set_namelist 1_namelist_cfg nn_it000 151
     set_namelist 1_namelist_cfg nn_itend 300
@@ -1294,18 +1235,19 @@
     set_namelist 1_namelist_cfg ln_read_cfg .true.
     set_namelist 1_namelist_cfg ln_linssh .true.
+    set_namelist 1_namelist_cfg ln_zdfiwm .false.
     set_namelist 1_namelist_cfg ln_hpg_sco .false.
     set_namelist 1_namelist_cfg ln_hpg_zps .true. 
-    set_namelist namelist_cfg cn_ocerst_in \"O2LP_LONG_00000075_restart\"
-    set_namelist namelist_ice_cfg cn_icerst_in \"O2LP_LONG_00000075_restart_ice\"
-    set_namelist 1_namelist_cfg cn_ocerst_in \"O2LP_LONG_00000150_restart\"
-    set_namelist 1_namelist_ice_cfg cn_icerst_in \"O2LP_LONG_00000150_restart_ice\"
+    set_namelist namelist_cfg cn_ocerst_in \"O2AGRIF_LONG_00000075_restart\"
+    set_namelist namelist_ice_cfg cn_icerst_in \"O2AGRIF_LONG_00000075_restart_ice\"
+    set_namelist 1_namelist_cfg cn_ocerst_in \"O2AGRIF_LONG_00000150_restart\"
+    set_namelist 1_namelist_ice_cfg cn_icerst_in \"O2AGRIF_LONG_00000150_restart_ice\"
 
     for (( i=1; i<=$NPROC; i++)) ; do
         L_NPROC=$(( $i - 1 ))
         L_NPROC=`printf "%04d\n" ${L_NPROC}`
-        ln -sf ../LONG/O2LP_LONG_00000075_restart_${L_NPROC}.nc .
-        ln -sf ../LONG/O2LP_LONG_00000075_restart_ice_${L_NPROC}.nc .
-        ln -sf ../LONG/1_O2LP_LONG_00000150_restart_${L_NPROC}.nc .
-        ln -sf ../LONG/1_O2LP_LONG_00000150_restart_ice_${L_NPROC}.nc .
+        ln -sf ../LONG/O2AGRIF_LONG_00000075_restart_${L_NPROC}.nc .
+        ln -sf ../LONG/O2AGRIF_LONG_00000075_restart_ice_${L_NPROC}.nc .
+        ln -sf ../LONG/1_O2AGRIF_LONG_00000150_restart_${L_NPROC}.nc .
+        ln -sf ../LONG/1_O2AGRIF_LONG_00000150_restart_ice_${L_NPROC}.nc .
     done
     if [ ${USING_MPMD} == "yes" ] ; then
@@ -1318,11 +1260,9 @@
     cd ${SETTE_DIR}
     . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
-fi
+
 
 ## Reproducibility tests for ORCA2_LIM3_AGRIF
-if [ ${config} -eq 16 ] ;  then
     export TEST_NAME="REPRO_4_4"
     cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n ORCA2AGUL_16 -r ORCA2_LIM3_PISCES -d "OPA_SRC LIM_SRC_3 NST_SRC" -j 8 add_key "key_agrif key_zdftmx" del_key "key_zdftmx_new key_top"
     cd ${SETTE_DIR}
     . ./param.cfg
@@ -1333,4 +1273,5 @@
     if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
     cd ${EXE_DIR}
+    set_namelist namelist_cfg cn_exp \"O2AGRIF_44\"
     set_namelist namelist_cfg nn_it000 1
     set_namelist namelist_cfg nn_itend 75
@@ -1351,4 +1292,5 @@
     set_namelist 1_namelist_cfg ln_clobber .true.
     set_namelist 1_namelist_cfg ln_read_cfg .true.
+    set_namelist 1_namelist_cfg ln_zdfiwm .false.
     set_namelist 1_namelist_cfg ln_linssh .true.
     set_namelist 1_namelist_cfg ln_hpg_sco .false.
@@ -1372,4 +1314,5 @@
     if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
     cd ${EXE_DIR}
+    set_namelist namelist_cfg cn_exp \"O2AGRIF_28\"
     set_namelist namelist_cfg nn_it000 1
     set_namelist namelist_cfg nn_itend 75
@@ -1388,7 +1331,9 @@
     set_namelist 1_namelist_cfg nn_fsbc 1
     set_namelist 1_namelist_cfg ln_ctl .false.
+    set_namelist 1_namelist_cfg nn_fsbc 1
     set_namelist 1_namelist_cfg ln_clobber .true.
     set_namelist 1_namelist_cfg ln_read_cfg .true.
     set_namelist 1_namelist_cfg ln_linssh .true.
+    set_namelist 1_namelist_cfg ln_zdfiwm .false.
     set_namelist 1_namelist_cfg ln_hpg_sco .false.
     set_namelist 1_namelist_cfg ln_hpg_zps .true. 
@@ -1405,3 +1350,88 @@
 fi
 
+# test code corruption with AGRIF
+if [ ${config} -eq 9 ] ;  then
+
+# Compile with AGRIF but run with no zoom
+    export TEST_NAME="AGRIFNOZ"
+    cd ${CONFIG_DIR0}
+    . ./makenemo -m ${CMP_NAM} -n ORCA2AGUL_NOZOOM_ST -r ORCA2_LIM3_PISCES -d "OPA_SRC LIM_SRC_3 NST_SRC" -j 8 add_key "key_agrif" del_key "key_top"
+    cd ${SETTE_DIR}
+    . ./param.cfg
+    . ./all_functions.sh
+    . ./prepare_exe_dir.sh
+    JOB_FILE=${EXE_DIR}/run_job.sh
+    NPROC=4
+    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
+    cd ${EXE_DIR}
+    set_namelist namelist_cfg cn_exp \"AGRIFNOZ_SHORT\"
+    set_namelist namelist_cfg nn_it000 1
+    set_namelist namelist_cfg nn_itend 75
+    set_namelist namelist_cfg ln_ctl .false.
+    set_namelist namelist_cfg ln_clobber .true.
+    set_namelist namelist_cfg ln_read_cfg .true.
+    set_namelist namelist_cfg ln_linssh .true.
+    set_namelist namelist_cfg ln_hpg_sco .false.
+    set_namelist namelist_cfg ln_hpg_zps .true. 
+    set_namelist namelist_cfg nn_fwb 0
+    set_namelist namelist_cfg jpni 2
+    set_namelist namelist_cfg jpnj 2
+    set_namelist namelist_cfg jpnij 4
+    set_namelist namelist_cfg ln_icebergs .false.   
+# 
+#   Set the number of fine grids to zero:    
+    sed -i "1s/.*/0/" ${EXE_DIR}/AGRIF_FixedGrids.in
+
+    if [ ${USING_MPMD} == "yes" ] ; then
+       set_xio_using_server iodef.xml true
+    else
+       set_xio_using_server iodef.xml false
+    fi
+    cd ${SETTE_DIR}
+    . ./prepare_job.sh input_ORCA2_LIM3_AGRIF.cfg $NPROC ${TEST_NAME} ${MPIRUN_FLAG} ${JOB_FILE} ${NUM_XIOSERVERS}
+    cd ${SETTE_DIR}
+    . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
+
+fi
+
+if [ ${config} -eq 10 ] ;  then
+# Compile with same option as 9 = ORCA2AGUL_NOZOOM, except ne key_agrif to check AGRIF does not hurt...
+    export TEST_NAME="AGRIFNO"
+    cd ${CONFIG_DIR0}
+    . ./makenemo -m ${CMP_NAM} -n ORCA2AGUL_NOAGR_ST -r ORCA2_LIM3_PISCES -d "OPA_SRC LIM_SRC_3 NST_SRC" -j 8 del_key "key_top"
+    cd ${SETTE_DIR}
+    . ./param.cfg
+    . ./all_functions.sh
+    . ./prepare_exe_dir.sh
+    JOB_FILE=${EXE_DIR}/run_job.sh
+    NPROC=4
+    if [ -f ${JOB_FILE} ] ; then \rm ${JOB_FILE} ; fi
+    cd ${EXE_DIR}
+    set_namelist namelist_cfg cn_exp \"AGRIFNO_SHORT\"
+    set_namelist namelist_cfg nn_it000 1
+    set_namelist namelist_cfg nn_itend 75
+    set_namelist namelist_cfg ln_ctl .false.
+    set_namelist namelist_cfg ln_clobber .true.
+    set_namelist namelist_cfg ln_read_cfg .true.
+    set_namelist namelist_cfg ln_linssh .true.
+    set_namelist namelist_cfg ln_hpg_sco .false.
+    set_namelist namelist_cfg ln_hpg_zps .true. 
+    set_namelist namelist_cfg nn_fwb 0
+    set_namelist namelist_cfg jpni 2
+    set_namelist namelist_cfg jpnj 2
+    set_namelist namelist_cfg jpnij 4
+    set_namelist namelist_cfg ln_icebergs .false.       
+#
+    if [ ${USING_MPMD} == "yes" ] ; then
+       set_xio_using_server iodef.xml true
+    else
+       set_xio_using_server iodef.xml false
+    fi
+    cd ${SETTE_DIR}
+    . ./prepare_job.sh input_ORCA2_LIM3_AGRIF.cfg $NPROC ${TEST_NAME} ${MPIRUN_FLAG} ${JOB_FILE} ${NUM_XIOSERVERS}
+    cd ${SETTE_DIR}
+    . ./fcm_job.sh $NPROC ${JOB_FILE} ${INTERACT_FLAG} ${MPIRUN_FLAG}
+
+fi
+
 done
Index: /branches/2017/dev_merge_2017/NEMOGCM/SETTE/sette_beginner.sh
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/SETTE/sette_beginner.sh	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/SETTE/sette_beginner.sh	(revision 9019)
@@ -55,5 +55,5 @@
 #   set_namelist     : function declared in all_functions that sets namelist parameters 
 #   post_test_tidyup : creates validation storage directory and copies required output files 
-#                      (solver.stat and ocean.output) in it after execution of test.
+#                      (run.stat and ocean.output) in it after execution of test.
 #
 #  VALIDATION tree is:
Index: /branches/2017/dev_merge_2017/NEMOGCM/SETTE/sette_rpt.SAS.sh
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/SETTE/sette_rpt.SAS.sh	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/SETTE/sette_rpt.SAS.sh	(revision 9019)
@@ -0,0 +1,317 @@
+#!/bin/bash -f
+#set -vx
+#
+# simple SETTE report generator.
+#
+# This version should be run in the SETTE directory. 
+# The machine name will be picked up from the sette.sh script but the location of the
+# validation directory needs to be set here (currently assumed to reside in the ../CONFIG directory)
+#
+#########################################################################################
+######################### Start of function definitions #################################
+##
+
+function restfile() {
+# Rebuild ice restart for SAS CONFIG, and restartability checks. Expects LONG and SHORT run directories.
+# For Stand Alone Surface configuration ocean is not running, just run ice model; so no outputs ocean files.
+# Compares LONG rebuild restart ice file with equivalent entry from the SHORT rebuild restart ice file.
+#
+  vdir=$1
+  nam=$2
+  pass=$3
+#
+  if [ -d $vdir/$nam ]; then
+    dorv=`ls -1rt $vdir/$nam/$mach/ | tail -1l `
+    dorv=`echo $dorv | sed -e 's:.*/::'`
+    rep1=`ls -1rt $vdir/$nam/$mach/$dorv/ | tail -2l | head -1 `
+    rep2=`ls -1rt $vdir/$nam/$mach/$dorv/ | tail -1l`
+    cd ${SAS_RESTART_DIR}/LONG
+    #SF add here compilation of rebuild_tools to rebuild restart files, and add comparison of restart files
+    cd ${TOOLS_DIR}
+    ./maketools -n REBUILD_NEMO -m ${mach} > /dev/null 2>&1
+    cd ${TOOLS_DIR}/REBUILD_NEMO
+    #SF echo "REBUILD LONG restart SAS files, without standard output"
+    ./rebuild_nemo -t 4 ../../CONFIG/SAS_LONG/LONG/SAS_00000100_restart_ice  $NPROC > /dev/null 2>&1
+    #SF echo "REBUILD SHORT restart SAS files, without standard output"
+    ./rebuild_nemo -t 4 ../../CONFIG/SAS_LONG/SHORT/SAS_00000100_restart_ice $NPROC >&-
+    cd ${SAS_RESTART_DIR}/LONG
+    #SF echo "COPY rebuild restart files"
+    cp SAS_00000100_restart_ice.nc $vdir/$nam/$mach/$dorv/LONG/.
+    cp ../SHORT/SAS_00000100_restart_ice.nc $vdir/$nam/$mach/$dorv/SHORT/.
+
+    f1o=$vdir/$nam/$mach/$dorv/LONG/SAS_00000100_restart_ice.nc
+    f2o=$vdir/$nam/$mach/$dorv/SHORT/SAS_00000100_restart_ice.nc
+    if  [ ! -f $f1o ] &&  [ ! -f $f2o ] ; then
+      printf "%-20s %s\n" $nam " REBUILD SAS restart ice DOES NOT exists; incomplete test";
+      return;
+    fi
+    #
+    done_oce=0
+    #
+    if  [  -f $f1o ] && [  -f $f2o ]; then
+      cmp -s $f1o $f2o 
+      #SF  cmp SAS_00000100_restart_ice.nc  ../SHORT/SAS_00000100_restart_ice.nc  > diff_restart.txt
+      if [ $? == 0 ]; then
+        if [ $pass == 0 ]; then
+          printf "%-20s %s %s\n" $nam  " SAS restart files are IDENTICAL :  passed : " $dorv
+        fi
+      else
+        printf "%-20s %s %s\n" $nam  " SAS restart files are DIFFERENT : FAILED : " $dorv 
+        #
+	# Offer view of differences on the second pass
+	#
+        if [ $pass == 1 ]; then
+          echo "BE CAREFUL:  NEED cdo to see differences!!!!! "
+          echo "DO which cdo and replace cdo PATH to the cdo command in SETTE_rpt.sh "
+          echo "IF cdo is not available you need to do difference of netcdf file by hand"
+          echo "<return> to view restart_ice.nc differences"
+          read y
+#SF           cdo -diffv $f1o $f2o
+          /smplocal/pub/cdo/1.5.9/bin/cdo -diffv $f1o $f2o
+          done_oce=1
+          #echo "<return> to continue"
+          #read y
+        fi
+      fi
+    fi
+#
+fi
+}
+
+function resttest() { 
+#
+# Restartability checks. Expects LONG and SHORT run directories
+# Compares end of LONG stat files with equivalent entries from the SHORT stat files.
+#
+  vdir=$1
+  nam=$2
+  pass=$3
+#
+  if [ -d $vdir/$nam ]; then
+    dorv=`ls -1rt $vdir/$nam/$mach/ | tail -1l `
+    dorv=`echo $dorv | sed -e 's:.*/::'`
+    f1o=$vdir/$nam/$mach/$dorv/LONG/ocean.output
+    f1s=$vdir/$nam/$mach/$dorv/LONG/run.stat
+    f1t=$vdir/$nam/$mach/$dorv/LONG/tracer.stat
+    f2o=$vdir/$nam/$mach/$dorv/SHORT/ocean.output
+    f2s=$vdir/$nam/$mach/$dorv/SHORT/run.stat
+    f2t=$vdir/$nam/$mach/$dorv/SHORT/tracer.stat
+
+    if  [ ! -f $f1s ] &&  [ ! -f $f1t ] ; then 
+      printf "%-20s %s\n" $nam " incomplete test";
+      return; 
+    fi
+    if  [ ! -f $f2s ] &&  [ ! -f $f2t ] ; then 
+      printf "%-20s %s\n" $nam " incomplete test";
+      return; 
+    fi
+#
+    done_oce=0
+
+    if  [  -f $f1s ] && [  -f $f2s ]; then 
+      nl=(`wc -l $f2s`)
+      tail -${nl[0]} $f1s > f1.tmp$$
+      cmp -s f1.tmp$$ $f2s
+      if [ $? == 0 ]; then
+        if [ $pass == 0 ]; then 
+          printf "%-20s %s %s\n" $nam  " run.stat restartability  passed : " $dorv
+        fi
+      else
+        printf "%-20s %s %s\n" $nam  " run.stat restartability  FAILED : " $dorv 
+#
+# Offer view of differences on the second pass
+#
+        if [ $pass == 1 ]; then
+          echo "<return> to view run.stat differences"
+          read y
+          sdiff f1.tmp$$ $f2s
+          echo "<return> to view ocean.output differences"
+          read y
+          sdiff $f1o $f2o | grep "|"
+          done_oce=1
+          echo "<return> to continue"
+          read y
+        fi
+      fi
+    fi
+#
+# Check tracer.stat files (if they exist)
+#
+    if  [  -f $f1t ] && [  -f $f2t ]; then
+      nl=(`wc -l $f2t`)
+      tail -${nl[0]} $f1t > f1.tmp$$
+      cmp -s f1.tmp$$ $f2t
+      if [ $? == 0 ]; then
+        if [ $pass == 0 ]; then 
+          printf "%-20s %s %s\n" $nam  " tracer.stat restartability  passed : " $dorv
+        fi
+      else
+        printf "%-20s %s %s\n" $nam  " tracer.stat restartability  FAILED : " $dorv 
+#
+# Offer view of differences on the second pass
+#
+        if [ $pass == 1 ]; then
+          echo "<return> to view tracer.stat differences"
+          read y
+          sdiff f1.tmp$$ $f2t
+#
+# Only offer ocean.output view if it has not been viewed previously
+#
+          if [ $done_oce == 0 ]; then
+            echo "<return> to view ocean.output differences"
+            read y
+            sdiff $f1o $f2o | grep "|"
+          fi
+          echo "<return> to continue"
+          read y
+        fi
+      fi
+    fi
+    rm f1.tmp$$
+  fi
+}
+
+function reprotest(){
+#
+# Reproducibility checks. Expects REPRO_N_M and REPRO_I_J run directories
+# Compares end of stat files from each
+#
+  vdir=$1
+  nam=$2
+  pass=$3
+#
+  if [ -d $vdir/$nam ]; then
+    dorv=`ls -1rt $vdir/$nam/$mach/ | tail -1l `
+    dorv=`echo $dorv | sed -e 's:.*/::'`
+    rep1=`ls -1rt $vdir/$nam/$mach/$dorv/ | tail -2l | head -1 `
+    rep2=`ls -1rt $vdir/$nam/$mach/$dorv/ | tail -1l`
+    f1o=$vdir/$nam/$mach/$dorv/$rep1/ocean.output
+    f1s=$vdir/$nam/$mach/$dorv/$rep1/run.stat
+    f1t=$vdir/$nam/$mach/$dorv/$rep1/tracer.stat
+    f2o=$vdir/$nam/$mach/$dorv/$rep2/ocean.output
+    f2s=$vdir/$nam/$mach/$dorv/$rep2/run.stat
+    f2t=$vdir/$nam/$mach/$dorv/$rep2/tracer.stat
+
+    if  [ ! -f $f1s ] && [ ! -f $f1t ] ; then 
+      printf "%-20s %s\n" $nam " incomplete test";
+      return; 
+    fi
+    if  [ ! -f $f2s ] && [ ! -f $f2t ] ; then 
+      printf "%-20s %s\n" $nam " incomplete test";
+      return; 
+    fi
+#
+    done_oce=0
+
+    if  [ -f $f1s ] && [ -f $f2s ] ; then
+      cmp -s $f1s $f2s
+      if [ $? == 0 ]; then
+        if [ $pass == 0 ]; then 
+          printf "%-20s %s %s\n" $nam  " run.stat reproducibility passed : " $dorv
+        fi
+      else
+        printf "%-20s %s %s\n" $nam  " run.stat reproducibility FAILED : " $dorv 
+#
+# Offer view of differences on the second pass
+#
+        if [ $pass == 1 ]; then
+          echo "<return> to view run.stat differences"
+          read y
+          sdiff f1.tmp$$ $f2s
+          echo "<return> to view ocean.output differences"
+          read y
+          sdiff $f1o $f2o | grep "|"
+          done_oce=1
+          echo "<return> to continue"
+          read y
+        fi
+      fi
+    fi
+#
+# Check tracer.stat files (if they exist)
+#
+    if  [ -f $f1t ] && [ -f $f2t ] ; then
+      cmp -s $f1t $f2t
+      if [ $? == 0 ]; then
+        if [ $pass == 0 ]; then           printf "%-20s %s %s\n" $nam  " tracer.stat reproducibility passed : " $dorv
+        fi
+      else
+        printf "%-20s %s %s\n" $nam  " tracer.stat reproducibility  FAILED : " $dorv
+#
+# Offer view of differences on the second pass
+#
+        if [ $pass == 1 ]; then
+          echo "<return> to view tracer.stat differences"
+          read y
+          sdiff $f1t $f2t
+#
+# Only offer ocean.output view if it has not been viewed previously
+#
+          if [ $done_oce == 0 ]; then
+            echo "<return> to view ocean.output differences"
+            read y
+            sdiff $f1o $f2o | grep "|"
+          fi
+          echo "<return> to continue"
+          read y
+        fi
+      fi
+    fi
+  fi
+}
+########################### END of function definitions #################################
+##                                                                                     ##
+##    Main script                                                                      ##
+##                                                                                     ##
+#########################################################################################
+#
+  mach=`grep "COMPILER=" ./sette.sh | sed -e 's/COMPILER=//'`
+  NEMO_VALID=`grep "NEMO_VALIDATION_DIR=" ./param.cfg | sed -e 's/NEMO_VALIDATION_DIR=//'`
+# Directory to run the tests
+ SETTE_DIR=$(cd $(dirname "$0"); pwd)
+ MAIN_DIR=$(dirname $SETTE_DIR)
+ CONFIG_DIR0=${MAIN_DIR}/CONFIG
+ TOOLS_DIR=${MAIN_DIR}/TOOLS
+ COMPIL_DIR=${TOOLS_DIR}/COMPILE
+ NPROC=32
+
+  SAS_RESTART_DIR=${CONFIG_DIR0}/SAS_LONG
+#
+  if [ ! -d $NEMO_VALID ]; then
+    echo "$NEMO_VALID validation directory not found"
+    exit
+  fi
+#
+
+# The script also needs the date or revision tag. Currently this is taken from the latest sub-directory found in each directory
+#  
+for pass in  0 1 
+do
+#
+ if [ $pass == 1 ]; then echo "---------------2nd pass------------------";fi
+#
+
+# Rebuild and restartability test for SAS
+#
+ for restart_file in WSAS_LONG
+ do
+ #  restfile $SAS_RESTART_DIR LONG $pass
+   restfile $NEMO_VALID $restart_file $pass
+ done
+#
+# Restartability test
+#
+ for restart_test in WGYREPIS_LONG WORCA2LIM3PIS_LONG WORCA2OFFPIS_LONG WAMM12_LONG WISOMIP_LONG WORCA2AGUL_LONG
+ do
+   resttest $NEMO_VALID $restart_test $pass
+ done
+#
+# Reproducibility tests
+#
+ for repro_test in WGYREPIS_32 WORCA2LIM3PIS_32 WORCA2OFFPIS_32 WAMM12_32 WISOMIP_32 WORCA2_LIM3_OBS WORCA2AGUL_1_2 WORCA2AGUL_16 WORCA2AGUL_2_2_NAG
+ do
+   reprotest $NEMO_VALID $repro_test $pass
+ done
+#
+done
+exit
Index: /branches/2017/dev_merge_2017/NEMOGCM/SETTE/sette_rpt.sh
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/SETTE/sette_rpt.sh	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/SETTE/sette_rpt.sh	(revision 9019)
@@ -1,5 +1,4 @@
 #!/bin/bash -f
-#set -vx
-#
+# set -vx
 # simple SETTE report generator.
 #
@@ -17,7 +16,11 @@
 # Compares LONG rebuild restart ice file with equivalent entry from the SHORT rebuild restart ice file.
 #
+# check nco module loaded, and load it if not
+if [ ! $( echo $LOADEDMODULES | grep cdo ) ]; then module load cdo >& /dev/null ; fi
+#
   vdir=$1
   nam=$2
   pass=$3
+
 #
   if [ -d $vdir/$nam ]; then
@@ -32,7 +35,7 @@
     cd ${TOOLS_DIR}/REBUILD_NEMO
     #SF echo "REBUILD LONG restart SAS files, without standard output"
-    ./rebuild_nemo -t 4 ../../CONFIG/SAS_LONG/LONG/SAS_00000240_restart_ice  $NPROC > /dev/null 2>&1
+    ./rebuild_nemo -t 4 ../../CONFIG/SAS_ST/LONG/SAS_00000240_restart_ice  $NPROC > /dev/null 2>&1
     #SF echo "REBUILD SHORT restart SAS files, without standard output"
-    ./rebuild_nemo -t 4 ../../CONFIG/SAS_LONG/SHORT/SAS_00000240_restart_ice $NPROC >&-
+    ./rebuild_nemo -t 4 ../../CONFIG/SAS_ST/SHORT/SAS_00000240_restart_ice $NPROC >&-
     cd ${SAS_RESTART_DIR}/LONG
     #SF echo "COPY rebuild restart files"
@@ -49,20 +52,30 @@
     done_oce=0
     #
-    if  [  -f $f1o ] && [  -f $f2o ]; then
-      cmp -s $f1o $f2o 
-      #SF  cmp SAS_00000240_restart_ice.nc  ../SHORT/SAS_00000240_restart_ice.nc  > diff_restart.txt
-      if [ $? == 0 ]; then
-        if [ $pass == 0 ]; then
-          printf "%-20s %s %s\n" $nam  " SAS restart files are IDENTICAL :  passed : " $dorv
-        fi
-      else
-        printf "%-20s %s %s\n" $nam  " SAS restart files are DIFFERENT : FAILED : " $dorv 
+  if  [  -f $f1o ] && [  -f $f2o ]; then
+## Compare the two netcdf files
+    cdo diffn $f1o $f2o > cdo_diff.out 2> /dev/null
+## Identical if cdo_diff.out exists but has zero size
+    if [ ! -s cdo_diff.out ]; then
+       difi=0
+    else
+## Identical if first character of $dif ==0
+       dif=$( grep -om1 '[0-9]* of [0-9]* records differ' cdo_diff.out )
+# difi contains the first character of summary of cdo dif. if = 0, then 0 record differ between the 2 files    
+       if [ -n "$dif" ]; then
+           difi=`echo $dif | cut -c -1`
+       fi
+    fi
+    \rm cdo_diff.out 
+
+    if [ $difi == 0 ]; then	
+       if [ $pass == 0 ]; then
+         printf "%-20s %s %s\n" $nam  " ice restarts are IDENTICAL  passed : " $dorv
+       fi
+    else
+       printf "%-20s %s %s\n" $nam  " ice restarts are DIFFERENT  FAILED : " $dorv 
         #
 	# Offer view of differences on the second pass
 	#
         if [ $pass == 1 ]; then
-          echo "BE CAREFUL:  NEED cdo to see differences!!!!! "
-          echo "DO which cdo and replace cdo PATH to the cdo command in SETTE_rpt.sh "
-          echo "IF cdo is not available you need to do difference of netcdf file by hand"
           echo "<return> to view restart_ice.nc differences"
           read y
@@ -72,6 +85,9 @@
           #read y
         fi
-      fi
-    fi
+    fi
+  else
+      printf "%-20s %s\n" $nam " incomplete test";
+      return;
+  fi
 #
 fi
@@ -91,8 +107,8 @@
     dorv=`echo $dorv | sed -e 's:.*/::'`
     f1o=$vdir/$nam/$mach/$dorv/LONG/ocean.output
-    f1s=$vdir/$nam/$mach/$dorv/LONG/solver.stat
+    f1s=$vdir/$nam/$mach/$dorv/LONG/run.stat
     f1t=$vdir/$nam/$mach/$dorv/LONG/tracer.stat
     f2o=$vdir/$nam/$mach/$dorv/SHORT/ocean.output
-    f2s=$vdir/$nam/$mach/$dorv/SHORT/solver.stat
+    f2s=$vdir/$nam/$mach/$dorv/SHORT/run.stat
     f2t=$vdir/$nam/$mach/$dorv/SHORT/tracer.stat
 
@@ -114,13 +130,13 @@
       if [ $? == 0 ]; then
         if [ $pass == 0 ]; then 
-          printf "%-20s %s %s\n" $nam  " solver.stat restartability  passed : " $dorv
+          printf "%-20s %s %s\n" $nam  " run.stat    restartability  passed : " $dorv
         fi
       else
-        printf "%-20s %s %s\n" $nam  " solver.stat restartability  FAILED : " $dorv 
+        printf "%-20s %s %s\n" $nam  " run.stat    restartability  FAILED : " $dorv 
 #
 # Offer view of differences on the second pass
 #
         if [ $pass == 1 ]; then
-          echo "<return> to view solver.stat differences"
+          echo "<return> to view run.stat differences"
           read y
           sdiff f1.tmp$$ $f2s
@@ -183,11 +199,11 @@
     dorv=`ls -1rt $vdir/$nam/$mach/ | tail -1l `
     dorv=`echo $dorv | sed -e 's:.*/::'`
-    rep1=`ls -1rt $vdir/$nam/$mach/$dorv/ | tail -2l | head -1 `
-    rep2=`ls -1rt $vdir/$nam/$mach/$dorv/ | tail -1l`
+    rep1=`ls -1rt $vdir/$nam/$mach/$dorv/ | grep REPRO | tail -2l | head -1 `
+    rep2=`ls -1rt $vdir/$nam/$mach/$dorv/ | grep REPRO | tail -1l`
     f1o=$vdir/$nam/$mach/$dorv/$rep1/ocean.output
-    f1s=$vdir/$nam/$mach/$dorv/$rep1/solver.stat
+    f1s=$vdir/$nam/$mach/$dorv/$rep1/run.stat
     f1t=$vdir/$nam/$mach/$dorv/$rep1/tracer.stat
     f2o=$vdir/$nam/$mach/$dorv/$rep2/ocean.output
-    f2s=$vdir/$nam/$mach/$dorv/$rep2/solver.stat
+    f2s=$vdir/$nam/$mach/$dorv/$rep2/run.stat
     f2t=$vdir/$nam/$mach/$dorv/$rep2/tracer.stat
 
@@ -207,13 +223,13 @@
       if [ $? == 0 ]; then
         if [ $pass == 0 ]; then 
-          printf "%-20s %s %s\n" $nam  " solver.stat reproducibility passed : " $dorv
+          printf "%-20s %s %s\n" $nam  " run.stat    reproducibility passed : " $dorv
         fi
       else
-        printf "%-20s %s %s\n" $nam  " solver.stat reproducibility FAILED : " $dorv 
+        printf "%-20s %s %s\n" $nam  " run.stat    reproducibility FAILED : " $dorv 
 #
 # Offer view of differences on the second pass
 #
         if [ $pass == 1 ]; then
-          echo "<return> to view solver.stat differences"
+          echo "<return> to view run.stat differences"
           read y
           sdiff f1.tmp$$ $f2s
@@ -257,4 +273,58 @@
       fi
     fi
+  fi
+}
+
+function identictest(){
+#
+#  checks AGRIF does not corrupe results with no AGRIF zoom. Expects ORCA2AGUL/AGRIFNOZ and ORCA2AGUL_NAGR/AGRIFNO  run directories
+# Compares solver.stat files for each
+#
+  vdir=$1
+  dir1=$2
+  dir2=$3
+  pass=$4
+#
+  if [ -d $vdir/$dir1 ] && [ -d $vdir/$dir2 ]; then
+    dorv1=`ls -1rt $vdir/$dir1/$mach/ | tail -1l `
+    dorv1=`echo $dorv1 | sed -e 's:.*/::'`
+    dorv2=`ls -1rt $vdir/$dir2/$mach/ | tail -1l `
+    dorv2=`echo $dorv2 | sed -e 's:.*/::'`
+
+    rep1=`ls -1rt $vdir/$dir1/$mach/$dorv1/ |  tail -2l | head -1 `
+    rep2=`ls -1rt $vdir/$dir2/$mach/$dorv2/ |  tail -1l`
+    f1s=$vdir/$dir1/$mach/$dorv1/$rep1/run.stat
+    f2s=$vdir/$dir2/$mach/$dorv2/$rep2/run.stat
+
+    if  [ ! -f $f1s ] && [ ! -f $f2s ] ; then 
+      printf "%-20s %s\n" $dir1 $dir2 " incomplete test";
+      return; 
+    fi
+#
+    done_oce=0
+
+    if  [ -f $f1s ] && [ -f $f2s ] ; then
+      cmp -s $f1s $f2s
+      if [ $? == 0 ]; then
+        if [ $pass == 0 ]; then 
+          printf "%-20s %s %s %s %s\n" $rep1 $rep2  " AGRIF: run.stat unchanged - test  passed : " $dorv1 $dorv2
+        fi
+      else
+        printf "%-20s %s %s %s %s\n" $rep1 $rep2  " for AGRIF, run.stat test FAILED : " $dorv1 $dorv2
+#
+# Offer view of differences on the second pass
+#
+        if [ $pass == 1 ]; then
+          echo "<return> to view run.stat differences"
+          read y
+          sdiff $f1s $f2s
+          done_oce=1
+          echo "<return> to continue"
+          read y
+        fi
+      fi
+    fi
+  else
+    printf "%-20s %s\n" $dir1 $dir2 " incomplete test";
   fi
 }
@@ -267,13 +337,5 @@
   mach=`grep "COMPILER=" ./sette.sh | sed -e 's/COMPILER=//'`
   NEMO_VALID=`grep "NEMO_VALIDATION_DIR=" ./param.cfg | sed -e 's/NEMO_VALIDATION_DIR=//'`
-# Directory to run the tests
- SETTE_DIR=$(cd $(dirname "$0"); pwd)
- MAIN_DIR=$(dirname $SETTE_DIR)
- CONFIG_DIR0=${MAIN_DIR}/CONFIG
- TOOLS_DIR=${MAIN_DIR}/TOOLS
- COMPIL_DIR=${TOOLS_DIR}/COMPILE
- NPROC=32
-
-  SAS_RESTART_DIR=${CONFIG_DIR0}/SAS_LONG
+  NEMO_VALID=`eval "echo $NEMO_VALID"`
 #
   if [ ! -d $NEMO_VALID ]; then
@@ -282,5 +344,21 @@
   fi
 #
-
+# Directory to run the tests
+  SETTE_DIR=$(cd $(dirname "$0"); pwd)
+  MAIN_DIR=$(dirname $SETTE_DIR)
+  CONFIG_DIR0=${MAIN_DIR}/CONFIG
+  TOOLS_DIR=${MAIN_DIR}/TOOLS
+  COMPIL_DIR=${TOOLS_DIR}/COMPILE
+  NPROC=32
+  SAS_RESTART_DIR=${CONFIG_DIR0}/SAS_ST
+#
+# Show current revision tag and branch name
+#
+cmd="svn"
+[ ! -d "$SETTE_DIR/.svn" ] && cmd="git $cmd"
+revision=`$cmd info | grep Revision | cut -d ":" -f 2 | tr -d ' '`
+branchname=`$cmd info | grep URL | rev | cut -d "/" -f 3 | rev`
+echo "SETTE validation report : $branchname @ r$revision"
+#
 # The script also needs the date or revision tag. Currently this is taken from the latest sub-directory found in each directory
 #  
@@ -293,7 +371,6 @@
 # Rebuild and restartability test for SAS
 #
- for restart_file in WSAS_LONG
+ for restart_file in WSAS_ST
  do
- #  restfile $SAS_RESTART_DIR LONG $pass
    restfile $NEMO_VALID $restart_file $pass
  done
@@ -301,5 +378,5 @@
 # Restartability test
 #
- for restart_test in WGYREPIS_LONG WORCA2LIM3PIS_LONG WORCA2OFFPIS_LONG WAMM12_LONG WISOMIP_LONG WORCA2AGUL_LONG
+ for restart_test in WGYREPIS_ST WORCA2LIM3PIS_ST WORCA2OFFPIS_ST WAMM12_ST WISOMIP_ST WORCA2AGR_ST
  do
    resttest $NEMO_VALID $restart_test $pass
@@ -308,9 +385,23 @@
 # Reproducibility tests
 #
- for repro_test in WGYREPIS_32 WORCA2LIM3PIS_32 WORCA2OFFPIS_32 WAMM12_32 WISOMIP_32 WORCA2_LIM3_OBS WORCA2AGUL_1_2 WORCA2AGUL_16 WORCA2AGUL_2_2_NAG
+ for repro_test in WGYREPIS_ST WORCA2LIM3PIS_ST WORCA2OFFPIS_ST WAMM12_ST WISOMIP_ST WORCA2_LIM3_OBS_ST WORCA2AGR_ST
  do
    reprotest $NEMO_VALID $repro_test $pass
  done
-#
+
+
+
+# AGRIF special check
+ dir1=WORCA2AGUL_NOZOOM_ST
+ dir2=WORCA2AGUL_NOAGR_ST
+ identictest $NEMO_VALID $dir1 $dir2 $pass 
+
+
 done
+#
+## Additional checks for ORCA2AGUL/FIRST standalone AGRIF test
+## still to be added
+
+
+
 exit
Index: /branches/2017/dev_merge_2017/NEMOGCM/SETTE/sette_xios.sh
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/SETTE/sette_xios.sh	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/SETTE/sette_xios.sh	(revision 9019)
@@ -52,5 +52,5 @@
 #   set_namelist     : function declared in all_functions that sets namelist parameters 
 #   post_test_tidyup : creates validation storage directory and copies required output files 
-#                      (solver.stat and ocean.output) in it after execution of test.
+#                      (run.stat and ocean.output) in it after execution of test.
 #
 #  VALIDATION tree is:
Index: /branches/2017/dev_merge_2017/NEMOGCM/TOOLS/DOMAINcfg/README_configs_namcfg_namdom
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/TOOLS/DOMAINcfg/README_configs_namcfg_namdom	(revision 9019)
+++ /branches/2017/dev_merge_2017/NEMOGCM/TOOLS/DOMAINcfg/README_configs_namcfg_namdom	(revision 9019)
@@ -0,0 +1,609 @@
+
+
+This README file contains the informations for the &namcfg namelist for some configurations whic are not one of the reference configurations.
+These informations wher previoulsy in NEMO/OPA_SRC_par_*.h90 files. The full test with these configurations has not been done.
+
+
+ORCA_R4
+=======
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   cp_cfg      =  "orca"               !  name of the configuration
+   jp_cfg      =       4               !  resolution of the configuration
+   jpidta      =      92               !  1st lateral dimension ( >= jpi )
+   jpjdta      =      76               !  2nd    "         "    ( >= jpj )
+   jpkdta      =      31               !  number of levels      ( >= jpk )
+   jpiglo      =      92               !  1st dimension of global domain --> i =jpidta
+   jpjglo      =      76               !  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)
+/
+!-----------------------------------------------------------------------
+&namdom        !  
+!-----------------------------------------------------------------------
+   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.0             !  Minimum vertical spacing
+   pphmax      =  999999.0             !  Maximum depth
+   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
+   ppa2        =  999999.0             !  Double tanh function parameters
+   ppkth2      =  999999.0             !
+   ppacr2      =  999999.0             !
+/
+
+ORCA_R1 75 vertical levels
+=======
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   cp_cfg      =  "orca"               !  name of the configuration
+   jp_cfg      =       1               !  resolution of the configuration
+   jpidta      =     362               !  1st lateral dimension ( >= jpi )
+   jpjdta      =     292               !  2nd    "         "    ( >= jpj )
+   jpkdta      =      75               !  number of levels      ( >= jpk )
+   jpiglo      =     362               !  1st dimension of global domain --> i =jpidta
+   jpjglo      =     292               !  2nd    -                  -    --> j  =jpjdta
+   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
+   jpjzoom     =       1               !  in data domain indices
+   jperio      =       6               !  lateral cond. type (between 0 and 6)
+/
+!-----------------------------------------------------------------------
+&namdom        !  
+!-----------------------------------------------------------------------
+   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       =   -3958.951371276829  !  ORCA r4, r2 and r05 coefficients
+   ppa0        =     103.9530096000000 ! (default coefficients)
+   ppa1        =       2.415951269000000   !
+   ppkth       =      15.35101370000000    !
+   ppacr       =       7.0             !
+   ppdzmin     =  999999.0             !  Minimum vertical spacing
+   pphmax      =  999999.0             !  Maximum depth
+   ldbletanh   =   .TRUE.              !  Use/do not use double tanf function for vertical coordinates
+   ppa2        =     100.7609285000000 !  Double tanh function parameters
+   ppkth2      =      48.02989372000000    !
+   ppacr2      =      13.00000000000   !
+/
+
+
+ORCA_R1 46 vertical levels
+=======
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   cp_cfg      =  "orca"               !  name of the configuration
+   jp_cfg      =       1               !  resolution of the configuration
+   jpidta      =     362               !  1st lateral dimension ( >= jpi )
+   jpjdta      =     292               !  2nd    "         "    ( >= jpj )
+   jpkdta      =      46               !  number of levels      ( >= jpk )
+   jpiglo      =     362               !  1st dimension of global domain --> i =jpidta
+   jpjglo      =     292               !  2nd    -                  -    --> j  =jpjdta
+   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
+   jpjzoom     =       1               !  in data domain indices
+   jperio      =       6               !  lateral cond. type (between 0 and 6)
+/
+!-----------------------------------------------------------------------
+&namdom        !  
+!-----------------------------------------------------------------------
+   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       =  999998.0             !  ORCA r4, r2 and r05 coefficients
+   ppa0        =  999998.0             ! (default coefficients)
+   ppa1        =  999998.0             !
+   ppkth       =      23.563           !
+   ppacr       =       9.0             !
+   ppdzmin     =       6.0             !  Minimum vertical spacing
+   pphmax      =    5750.              !  Maximum depth
+   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
+   ppa2        =  999999.0             !  Double tanh function parameters
+   ppkth2      =  999999.0             !
+   ppacr2      =  999999.0             !
+/
+ORCA_R05 
+========
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   cp_cfg      =  "orca"               !  name of the configuration
+   jp_cfg      =      05               !  resolution of the configuration
+   jpidta      =     722               !  1st lateral dimension ( >= jpi )
+   jpjdta      =     511               !  2nd    "         "    ( >= jpj )
+   jpkdta      =      31               !  number of levels      ( >= jpk )
+   jpiglo      =     722               !  1st dimension of global domain --> i =jpidta
+   jpjglo      =     511               !  2nd    -                  -    --> j  =jpjdta
+   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
+   jpjzoom     =       1               !  in data domain indices
+   jperio      =       6               !  lateral cond. type (between 0 and 6)
+/
+!-----------------------------------------------------------------------
+&namdom        !  
+!-----------------------------------------------------------------------
+   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.0             !  Minimum vertical spacing
+   pphmax      =  999999.0             !  Maximum depth
+   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
+   ppa2        =  999999.0             !  Double tanh function parameters
+   ppkth2      =  999999.0             !
+   ppacr2      =  999999.0             !
+/
+
+
+ORCA_R05 Antarctic zoom
+========
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   cp_cfg      =  "orca"               !  name of the configuration
+   cp_cfz      =  "antarctic"          !  name of the zoom of configuration
+   jp_cfg      =      05               !  resolution of the configuration
+   jpidta      =     722               !  1st lateral dimension ( >= jpi )
+   jpjdta      =     511               !  2nd    "         "    ( >= jpj )
+   jpkdta      =      31               !  number of levels      ( >= jpk )
+   jpiglo      =     722               !  1st dimension of global domain --> i =jpidta
+   jpjglo      =     187               !  2nd    -                  -    --> j  =jpjdta
+   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
+   jpjzoom     =       1               !  in data domain indices
+   jperio      =       1               !  lateral cond. type (between 0 and 6)
+/
+!-----------------------------------------------------------------------
+&namdom        !  
+!-----------------------------------------------------------------------
+   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.0             !  Minimum vertical spacing
+   pphmax      =  999999.0             !  Maximum depth
+   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
+   ppa2        =  999999.0             !  Double tanh function parameters
+   ppkth2      =  999999.0             !
+   ppacr2      =  999999.0             !
+/
+
+
+ORCA_R05 Arctic zoom
+========
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   cp_cfg      =  "orca"               !  name of the configuration
+   cp_cfz      =  "arctic"             !  name of the zoom of configuration
+   jp_cfg      =      05               !  resolution of the configuration
+   jpidta      =     722               !  1st lateral dimension ( >= jpi )
+   jpjdta      =     511               !  2nd    "         "    ( >= jpj )
+   jpkdta      =      31               !  number of levels      ( >= jpk )
+   jpiglo      =     562               !  1st dimension of global domain --> i =jpidta
+   jpjglo      =     211               !  2nd    -                  -    --> j  =jpjdta
+   jpizoom     =      81               !  left bottom (i,j) indices of the zoom
+   jpjzoom     =     301               !  in data domain indices
+   jperio      =       5               !  lateral cond. type (between 0 and 6)
+/
+!-----------------------------------------------------------------------
+&namdom        !  
+!-----------------------------------------------------------------------
+   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.0             !  Minimum vertical spacing
+   pphmax      =  999999.0             !  Maximum depth
+   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
+   ppa2        =  999999.0             !  Double tanh function parameters
+   ppkth2      =  999999.0             !
+   ppacr2      =  999999.0             !
+/
+
+ORCA2 - Antarctic zoom
+======================
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   cp_cfg      =  "orca"               !  name of the configuration
+   cp_cfz      =  "antarctic"          !  name of the zoom of 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      =      50               !  2nd    -                  -    --> j  =jpjdta
+   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
+   jpjzoom     =       1               !  in data domain indices
+   jperio      =       1               !  lateral cond. type (between 0 and 6)
+/
+!-----------------------------------------------------------------------
+&namdom        !  
+!-----------------------------------------------------------------------
+   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.              !
+/
+
+
+ORCA2 - Arctic zoom
+=================== 
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   cp_cfg      =  "orca"               !  name of the configuration
+   cp_cfz      =  "arctic"             !  name of the zoom of 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      =     142               !  1st dimension of global domain --> i =jpidta
+   jpjglo      =      53               !  2nd    -                  -    --> j  =jpjdta
+   jpizoom     =      21               !  left bottom (i,j) indices of the zoom
+   jpjzoom     =      97               !  in data domain indices
+   jperio      =       3               !  lateral cond. type (between 0 and 6)
+/
+!-----------------------------------------------------------------------
+&namdom        !  
+!-----------------------------------------------------------------------
+   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.              !
+/
+
+
+ORCA025 - 75 vertical levels
+=======
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   cp_cfg      =  "orca"               !  name of the configuration
+   jp_cfg      =     025               !  resolution of the configuration
+   jpidta      =    1442               !  1st lateral dimension ( >= jpi )
+   jpjdta      =    1021               !  2nd    "         "    ( >= jpj )
+   jpkdta      =      75               !  number of levels      ( >= jpk )
+   jpiglo      =    1442               !  1st dimension of global domain --> i =jpidta
+   jpjglo      =    1021               !  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)
+/
+!-----------------------------------------------------------------------
+&namdom        !  
+!-----------------------------------------------------------------------
+   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       =   -3958.951371276829  !  ORCA r4, r2 and r05 coefficients
+   ppa0        =    103.9530096000000  ! (default coefficients)
+   ppa1        =      2.415951269000000  !
+   ppkth       =     15.35101370000000 !
+   ppacr       =       7.0             !
+   ppdzmin     =  999999.0             !  Minimum vertical spacing
+   pphmax      =  999999.0             !  Maximum depth
+   ldbletanh   =   .TRUE.              !  Use/do not use double tanf function for vertical coordinates
+   ppa2        =     100.7609285000000 !  Double tanh function parameters
+   ppkth2      =      48.02989372000000  !
+   ppacr2      =      13.              !
+/
+
+
+ORCA025 - 46 vertical levels
+=======
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   cp_cfg      =  "orca"               !  name of the configuration
+   jp_cfg      =    1442               !  resolution of the configuration
+   jpidta      =    1021               !  1st lateral dimension ( >= jpi )
+   jpjdta      =     511               !  2nd    "         "    ( >= jpj )
+   jpkdta      =      46               !  number of levels      ( >= jpk )
+   jpiglo      =    1442               !  1st dimension of global domain --> i =jpidta
+   jpjglo      =    1021               !  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)
+/
+!-----------------------------------------------------------------------
+&namdom        !  
+!-----------------------------------------------------------------------
+   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       =  999998.0             !  ORCA r4, r2 and r05 coefficients
+   ppa0        =  999998.0             ! (default coefficients)
+   ppa1        =  999998.0             !
+   ppkth       =      23.563           !
+   ppacr       =       9.0             !
+   ppdzmin     =       6.0             !  Minimum vertical spacing
+   pphmax      =    5750.0             !  Maximum depth
+   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
+   ppa2        =  999999.0             !  Double tanh function parameters
+   ppkth2      =  999999.0             !
+   ppacr2      =  999999.0             !
+/
+EEL R2: channel
+======
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   cp_cfg      =   "eel"               !  name of the configuration
+   jp_cfg      =       2               !  resolution of the configuration
+   jpidta      =      83               !  1st lateral dimension ( >= jpi )
+   jpjdta      =     242               !  2nd    "         "    ( >= jpj )
+   jpkdta      =      30               !  number of levels      ( >= jpk )
+   jpiglo      =      83               !  1st dimension of global domain --> i =jpidta
+   jpjglo      =     242               !  2nd    -                  -    --> j  =jpjdta
+   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
+   jpjzoom     =       1               !  in data domain indices
+   jperio      =       1               !  lateral cond. type (between 0 and 6)
+/
+!-----------------------------------------------------------------------
+&namdom        !  
+!-----------------------------------------------------------------------
+   jphgr_msh   =       3               !  type of horizontal mesh
+   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    =  999999.0             !  zonal      grid-spacing (degrees)
+   ppe2_deg    =  999999.0             !  meridional grid-spacing (degrees)
+   ppe1_m      =    2000.0             !  zonal      grid-spacing (degrees)
+   ppe2_m      =    2000.0             !  meridional grid-spacing (degrees)
+   ppsur       =   -2033.194295283385  !  ORCA r4, r2 and r05 coefficients
+   ppa0        =     155.8325369664153 ! (default coefficients)
+   ppa1        =     146.3615918601890 !
+   ppkth       =      17.28520372419791  !
+   ppacr       =       5.0             !
+   ppdzmin     =  999999.0             !  Minimum vertical spacing
+   pphmax      =  999999.0             !  Maximum depth
+   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
+   ppa2        =  999999.0             !  Double tanh function parameters
+   ppkth2      =  999999.0             !
+   ppacr2      =  999999.0             !
+/
+
+
+EEL R5: channel
+======
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   cp_cfg      =   "eel"               !  name of the configuration
+   jp_cfg      =       5               !  resolution of the configuration
+   jpidta      =      66               !  1st lateral dimension ( >= jpi )
+   jpjdta      =      66               !  2nd    "         "    ( >= jpj )
+   jpkdta      =      31               !  number of levels      ( >= jpk )
+   jpiglo      =      66               !  1st dimension of global domain --> i =jpidta
+   jpjglo      =      66               !  2nd    -                  -    --> j  =jpjdta
+   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
+   jpjzoom     =       1               !  in data domain indices
+   jperio      =       1               !  lateral cond. type (between 0 and 6)
+/
+!-----------------------------------------------------------------------
+&namdom        !  
+!-----------------------------------------------------------------------
+   jphgr_msh   =       2               !  type of horizontal mesh
+   ppglam0     =       0.0             !  longitude of first raw and column T-point (jphgr_msh = 1)
+   ppgphi0     =      43.436430714     ! 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      =    8000.0             !  zonal      grid-spacing (degrees)
+   ppe2_m      =    8000.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.0             !  Minimum vertical spacing
+   pphmax      =  999999.0             !  Maximum depth
+   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
+   ppa2        =  999999.0             !  Double tanh function parameters
+   ppkth2      =  999999.0             !
+   ppacr2      =  999999.0             !
+/
+
+
+EEL R6: 6 km resolution channel
+======
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   cp_cfg      =   "eel"               !  name of the configuration
+   jp_cfg      =       6               !  resolution of the configuration
+   jpidta      =      29               !  1st lateral dimension ( >= jpi )
+   jpjdta      =      83               !  2nd    "         "    ( >= jpj )
+   jpkdta      =      30               !  number of levels      ( >= jpk )
+   jpiglo      =      29               !  1st dimension of global domain --> i =jpidta
+   jpjglo      =      83               !  2nd    -                  -    --> j  =jpjdta
+   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
+   jpjzoom     =       1               !  in data domain indices
+   jperio      =       1               !  lateral cond. type (between 0 and 6)
+/
+!-----------------------------------------------------------------------
+&namdom        !  
+!-----------------------------------------------------------------------
+   jphgr_msh   =       3               !  type of horizontal mesh
+   ppglam0     =       0.0             !  longitude of first raw and column T-point (jphgr_msh = 1)
+   ppgphi0     =      35.              ! 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      =    6000.0             !  zonal      grid-spacing (degrees)
+   ppe2_m      =    6000.0             !  meridional grid-spacing (degrees)
+   ppsur       =   -2033.194295283385  !  ORCA r4, r2 and r05 coefficients
+   ppa0        =     155.8325369664153 ! (default coefficients)
+   ppa1        =     146.3615918601890 !
+   ppkth       =      17.28520372419791   !
+   ppacr       =       5.0             !
+   ppdzmin     =  999999.0             !  Minimum vertical spacing
+   pphmax      =  999999.0             !  Maximum depth
+   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
+   ppa2        =  999999.0             !  Double tanh function parameters
+   ppkth2      =  999999.0             !
+   ppacr2      =  999999.0             !
+/
+
+
+POMME: 025
+======
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   cp_cfg      =   "pomme"             !  name of the configuration
+   jp_cfg      =     025               !  resolution of the configuration
+   jpidta      =      30               !  1st lateral dimension ( >= jpi )
+   jpjdta      =      40               !  2nd    "         "    ( >= jpj )
+   jpkdta      =      46               !  number of levels      ( >= jpk )
+   jpiglo      =      30               !  1st dimension of global domain --> i =jpidta
+   jpjglo      =      40               !  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)
+/
+!-----------------------------------------------------------------------
+&namdom        !  
+!-----------------------------------------------------------------------
+   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       =  999998.0             !  ORCA r4, r2 and r05 coefficients
+   ppa0        =  999998.0             ! (default coefficients)
+   ppa1        =  999998.0             !
+   ppkth       =      23.563           !
+   ppacr       =       9.0             !
+   ppdzmin     =       6.0             !  Minimum vertical spacing
+   pphmax      =    5750.0             !  Maximum depth
+   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
+   ppa2        =  999999.0             !  Double tanh function parameters
+   ppkth2      =  999999.0             !
+   ppacr2      =  999999.0             !
+/
+
+C1D - 1D configuration. Add key_c1d in active cpp keys
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   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      =       3               !  1st dimension of global domain --> i =jpidta
+   jpjglo      =       3               !  2nd    -                  -    --> j  =jpjdta
+! Choose postion of the 1D column: 
+!            jpizoom =   61, jpjzoom =   133  (160W,75N)
+!            jpizoom =   61, jpjzoom =   110  (160W,50N)
+!            jpizoom =   61, jpjzoom =   97   (160W,30N)
+!            jpizoom =   61, jpjzoom =   86   (160W,10N)
+!            jpizoom =   61, jpjzoom =   49   (160W,30S)
+!            jpizoom =   61, jpjzoom =   27   (160W,60S)
+!            jpizoom =   61, jpjzoom =    7   (160W,75S)
+!            jpizoom =   110,jpjzoom =   97   (64W,31.5N) BATS site
+   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)
+/
+!-----------------------------------------------------------------------
+&namdom        !  
+!-----------------------------------------------------------------------
+   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.              !
+/
Index: /branches/2017/dev_merge_2017/NEMOGCM/TOOLS/DOMAINcfg/field_def.xml
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/TOOLS/DOMAINcfg/field_def.xml	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/TOOLS/DOMAINcfg/field_def.xml	(revision 9019)
@@ -98,5 +98,33 @@
          <field id="tpt_dep"      long_name="T-point depth"                  standard_name="depth_below_geoid"   unit="m"   grid_ref="grid_T_3D" />
          <field id="e3tdef"       long_name="T-cell thickness deformation"                                       unit="%"   grid_ref="grid_T_3D" />
-      </field_group>
+       </field_group>
+
+       <!-- OSMOSIS diagnostics -->
+       <field_group id="OSMOSIS_T" grid_ref="grid_T_2D" operation="instant" >
+         <field id="ghamt"          long_name="non-local temperature flux"    grid_ref="grid_T_3D"  unit="deg m/s"        />
+         <field id="ghams"          long_name="non-local salinity flux"        grid_ref="grid_T_3D"   unit="psu m/s"        />
+         <field id="zwth0"          long_name="surface non-local temperature flux"                             unit="deg m/s"        />
+         <field id="zws0"          long_name="surface non-local salinity flux"                                     unit="psu m/s"        />
+         <field id="hbl"          long_name="boundary layer depth"                                                unit="m"        />
+         <field id="hbli"          long_name="initial boundary layer depth"                                     unit="m"        />
+         <field id="dstokes"          long_name="stokes drift  depth scale"                                     unit="m"        />
+         <field id="zustke"          long_name="magnitude of stokes drift  at T-points"                     unit="m/s"        />
+         <field id="zwstrc"          long_name="convective velocity scale"                                  unit="m/s"        />
+         <field id="zwstrl"          long_name="langmuir velocity scale"                                   unit="m/s"        />
+         <field id="zustar"          long_name="friction velocity"                                           unit="m/s"        />
+         <field id="zhbl"          long_name="boundary layer depth"                                           unit="m"        />
+         <field id="zhml"          long_name="mixed layer depth"                                           unit="m"        />
+       </field_group>
+    
+       <field_group id="OSMOSIS_U" grid_ref="grid_U_2D" >
+         <field id="ghamu"          long_name="non-local u-momentum flux"        grid_ref="grid_U_3D"   unit="m^2/s^2"        />
+         <field id="us_x"          long_name="i component of Stokes drift"                             unit="m/s"        />
+       </field_group>
+   
+       <field_group id="OSMOSIS_V" grid_ref="grid_V_2D" >
+         <field id="ghamv"          long_name="non-local v-momentum flux"        grid_ref="grid_V_3D"   unit="m^2/s^2"        />
+         <field id="us_y"          long_name="j component of Stokes drift"                             unit="m/s"        />
+       </field_group>
+
 
       <!-- Tides -->
Index: /branches/2017/dev_merge_2017/NEMOGCM/TOOLS/DOMAINcfg/namelist_ref
===================================================================
--- /branches/2017/dev_merge_2017/NEMOGCM/TOOLS/DOMAINcfg/namelist_ref	(revision 9018)
+++ /branches/2017/dev_merge_2017/NEMOGCM/TOOLS/DOMAINcfg/namelist_ref	(revision 9019)
@@ -272,13 +272,8 @@
                            !  =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")
+                           !  =2-3 ice-model used                       ("key_lim3", "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
@@ -670,8 +665,4 @@
    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'  ,    ''    ,   ''     ,     ''
