Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/ice.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/ice.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/ice.F90	(revision 8534)
@@ -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
@@ -150,7 +150,7 @@
    !!=====================================================================
 
-   !!--------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    !! * Share Module variables
-   !!--------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    !                                     !!** ice-generic parameters namelist (nampar) **
    INTEGER           , PUBLIC ::   jpl             !: number of ice  categories 
@@ -308,7 +308,7 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ftr_ice        !: transmitted solar radiation under ice
 
-   !!--------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    !! * Ice global state variables
-   !!--------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    !! Variables defined for each ice category
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ht_i      !: Ice thickness (m)
@@ -356,7 +356,7 @@
    ! END MV MP 2016
 
-   !!--------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    !! * 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 
@@ -372,7 +372,7 @@
    ! END MV MP 2016
 
-   !!--------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    !! * Old values of global variables
-   !!--------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   v_s_b, v_i_b, ht_s_b, ht_i_b  !: snow and ice volumes/thickness
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   a_i_b, smv_i_b, oa_i_b        !:
@@ -382,13 +382,13 @@
    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 
    !
-   !!--------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    !! * Ice diagnostics
-   !!--------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    ! thd refers to changes induced by thermodynamics
    ! trp   ''         ''     ''       advection (transport of ice)
@@ -406,7 +406,7 @@
 
    !
-   !!--------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
    !! * 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) 
@@ -541,5 +541,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_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/ice1D.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/ice1D.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/ice1D.F90	(revision 8534)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                       ***  MODULE ice1D  ***
-   !! LIM sea-ice :   Ice thermodynamics in 1D
+   !! sea-ice :   Ice thermodynamics variables in 1D
    !!=====================================================================
    !! History :  3.0  !  2002-11  (C. Ethe)  F90: Free form and module
@@ -8,5 +8,5 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                       LIM3 sea-ice model
+   !!   'key_lim3'                                       ESIM sea-ice model
    !!----------------------------------------------------------------------
    USE ice     , ONLY :   nlay_i, nlay_s, jpl   ! number of ice/snow layers and categories
@@ -223,5 +223,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option :         Empty module          NO LIM sea-ice model
+   !!   Default option :         Empty module         NO ESIM sea-ice model
    !!----------------------------------------------------------------------
 CONTAINS
Index: anches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceadv.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceadv.F90	(revision 8533)
+++ 	(revision )
@@ -1,181 +1,0 @@
-MODULE iceadv
-   !!======================================================================
-   !!                       ***  MODULE iceadv   ***
-   !! 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
-   !!----------------------------------------------------------------------
-   !!   ice_adv       : advection/diffusion process of sea ice
-   !!----------------------------------------------------------------------
-   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 iceadv_prather ! sea-ice: advection scheme (Prather)
-   USE iceadv_umx     ! sea-ice: advection scheme (ultimate-macho)
-   USE icectl         ! sea-ice: control prints
-   !
-   USE in_out_manager ! I/O manager
-   USE lbclnk         ! lateral boundary conditions -- MPP exchanges
-   USE lib_mpp        ! MPP library
-   USE prtctl         ! Print control
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE timing         ! Timing
-   USE iom            !
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   ice_adv        ! called by icestp
-   PUBLIC   ice_adv_init   ! called by icestp
-
-   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: iceadv.F90 8373 2017-07-25 17:44:54Z clem $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE ice_adv( kt ) 
-      !!----------------------------------------------------------------------
-      !!                   ***  ROUTINE ice_adv ***
-      !!                    
-      !! ** purpose : advection 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_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('iceadv')
- 
-      IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'ice_adv: sea-ice advection'
-         WRITE(numout,*) '~~~~~~~'
-      ENDIF
-      
-      ! conservation test
-      IF( ln_icediachk )   CALL ice_cons_hsm(0, 'iceadv', 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_adv_umx( nn_UMx, kt, u_ice, v_ice,  &
-            &              ato_i, v_i, v_s, smv_i, oa_i, a_i, a_ip, v_ip, e_s, e_i )
-      !                                !-----------------------!
-      CASE( np_advPRA )                ! PRATHER scheme        !
-         !                             !-----------------------!
-         CALL ice_adv_prather( kt, u_ice, v_ice,  &
-            &                  ato_i, v_i, v_s, smv_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_smv(:,:) = SUM(     smv_i(:,:,:)          - smv_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('icetrp') )   CALL iom_put( "icetrp" , diag_trp_vi * rday  )         ! ice volume transport
-      IF( iom_use('snwtrp') )   CALL iom_put( "snwtrp" , diag_trp_vs * rday  )         ! snw volume transport
-      IF( iom_use('saltrp') )   CALL iom_put( "saltrp" , diag_trp_smv * rday * rhoic ) ! salt content transport
-      IF( iom_use('deitrp') )   CALL iom_put( "deitrp" , diag_trp_ei         )         ! advected ice enthalpy (W/m2)
-      IF( iom_use('destrp') )   CALL iom_put( "destrp" , diag_trp_es         )         ! advected snw enthalpy (W/m2)
-
-      IF( lrst_ice ) THEN                       !* write Prather fields in the restart file
-         IF( ln_adv_Pra )   CALL adv_pra_rst( 'WRITE', kt )
-      ENDIF
-               
-      ! controls
-      IF( ln_icediachk   )   CALL ice_cons_hsm(1, 'iceadv', 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 ('iceadv')                                                             ! timing
-      !
-   END SUBROUTINE ice_adv
-
-
-   SUBROUTINE ice_adv_init
-      !!-------------------------------------------------------------------
-      !!                  ***  ROUTINE ice_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_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_adv_init: choose one and only one ice advection scheme (ln_adv_Pra or ln_adv_UMx)' )
-      !
-      IF( ln_adv_Pra )   CALL adv_pra_rst( 'READ' )  !* read or initialize all required files
-      !
-   END SUBROUTINE ice_adv_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Empty Module                No sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-
-   !!======================================================================
-END MODULE iceadv
-
Index: anches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceadv_prather.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceadv_prather.F90	(revision 8533)
+++ 	(revision )
@@ -1,1004 +1,0 @@
-MODULE iceadv_prather 
-   !!======================================================================
-   !!                       ***  MODULE iceadv_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
-   !!----------------------------------------------------------------------
-   !!   ice_adv_prather     : advection of sea ice using Prather scheme
-   !!----------------------------------------------------------------------
-   USE dom_oce        ! ocean domain
-   USE ice            ! sea-ice variables
-   USE sbc_oce , ONLY : nn_fsbc   ! frequency of sea-ice call
-   !
-   USE lbclnk         ! lateral boundary condition - MPP exchanges
-   USE in_out_manager ! I/O manager
-   USE iom            ! I/O library
-   USE prtctl         ! Print control
-   USE lib_mpp        ! MPP library
-   USE lib_fortran    ! to use key_nosignedzero
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   ice_adv_prather   ! called by iceadv
-   PUBLIC   adv_pra_rst       ! called by iceadv
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
-   !! $Id: iceadv.F90 6746 2016-06-27 17:20:57Z clem $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE ice_adv_prather( kt, pu_ice, pv_ice,  &
-      &                        pato_i, pv_i, pv_s, psmv_i, poa_i, pa_i, pa_ip, pv_ip, pe_s, pe_i )
-      !!----------------------------------------------------------------------
-      !!                **  routine ice_adv_prather  **
-      !!  
-      !! ** 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) ::   psmv_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_adv_prather: 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) = psmv_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 ( nn_pnd_scheme > 0 ) 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 ( nn_pnd_scheme > 0 ) 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 ( nn_pnd_scheme > 0 ) 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(:,:)
-         psmv_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
-         ! MV MP 2016
-         IF ( nn_pnd_scheme > 0 ) THEN
-            pa_ip  (:,:,jl)   = z0ap (:,:,jl) * r1_e1e2t(:,:)
-            pv_ip  (:,:,jl)   = z0vp (:,:,jl) * r1_e1e2t(:,:)
-         ENDIF
-         ! END MV MP 2016
-      END DO
-      !
-      DEALLOCATE( zarea , z0opw , z0ice, z0snw , z0ai , z0es , z0smi , z0oi , z0ap , z0vp , z0ei )
-      !
-   END SUBROUTINE ice_adv_prather
-   
-   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_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) :: z2d
-      !!----------------------------------------------------------------------
-      !
-      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialize
-         !                                   ! ---------------
-         IF( ln_rstart ) THEN                   !* Read the restart file
-            !
-            id1 = iom_varid( numrir, 'sxopw' , ldstop = .FALSE. )
-            !
-            IF( id1 > 0 ) THEN      ! fields exist
-               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
-               ! MV MP 2016
-               IF ( nn_pnd_scheme > 0 ) THEN
-                  DO jl = 1, jpl 
-                     WRITE(zchar,'(I2.2)') jl
-                     znam = 'sxap'//'_htc'//zchar
-                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-                     sxap(:,:,jl) = z2d(:,:)
-                     znam = 'syap'//'_htc'//zchar
-                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-                     syap(:,:,jl) = z2d(:,:)
-                     znam = 'sxxap'//'_htc'//zchar
-                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-                     sxxap(:,:,jl) = z2d(:,:)
-                     znam = 'syyap'//'_htc'//zchar
-                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-                     syyap(:,:,jl) = z2d(:,:)
-                     znam = 'sxyap'//'_htc'//zchar
-                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-                     sxyap(:,:,jl) = z2d(:,:)
-
-                     znam = 'sxvp'//'_htc'//zchar
-                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-                     sxvp(:,:,jl) = z2d(:,:)
-                     znam = 'syvp'//'_htc'//zchar
-                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-                     syvp(:,:,jl) = z2d(:,:)
-                     znam = 'sxxvp'//'_htc'//zchar
-                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-                     sxxvp(:,:,jl) = z2d(:,:)
-                     znam = 'syyvp'//'_htc'//zchar
-                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-                     syyvp(:,:,jl) = z2d(:,:)
-                     znam = 'sxyvp'//'_htc'//zchar
-                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-                     sxyvp(:,:,jl) = z2d(:,:)
-                  END DO
-               ENDIF
-               ! END MV MP 2016
-
-               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
-               !
-            ELSE                                     ! start rheology from rest
-               IF(lwp) WRITE(numout,*) '   ==>>   previous run without Prather, set moments to 0'
-               sxopw (:,:) = 0._wp   ;   sxice (:,:,:) = 0._wp   ;   sxsn (:,:,:)  = 0._wp   ;   sxa  (:,:,:) = 0._wp
-               syopw (:,:) = 0._wp   ;   syice (:,:,:) = 0._wp   ;   sysn (:,:,:)  = 0._wp   ;   sya  (:,:,:) = 0._wp
-               sxxopw(:,:) = 0._wp   ;   sxxice(:,:,:) = 0._wp   ;   sxxsn(:,:,:)  = 0._wp   ;   sxxa (:,:,:) = 0._wp
-               syyopw(:,:) = 0._wp   ;   syyice(:,:,:) = 0._wp   ;   syysn(:,:,:)  = 0._wp   ;   syya (:,:,:) = 0._wp
-               sxyopw(:,:) = 0._wp   ;   sxyice(:,:,:) = 0._wp   ;   sxysn(:,:,:)  = 0._wp   ;   sxya (:,:,:) = 0._wp
-               !
-               sxc0  (:,:,:) = 0._wp   ;   sxe  (:,:,:,:) = 0._wp   ;   sxsal  (:,:,:) = 0._wp   ;   sxage  (:,:,:) = 0._wp
-               syc0  (:,:,:) = 0._wp   ;   sye  (:,:,:,:) = 0._wp   ;   sysal  (:,:,:) = 0._wp   ;   syage  (:,:,:) = 0._wp
-               sxxc0 (:,:,:) = 0._wp   ;   sxxe (:,:,:,:) = 0._wp   ;   sxxsal (:,:,:) = 0._wp   ;   sxxage (:,:,:) = 0._wp
-               syyc0 (:,:,:) = 0._wp   ;   syye (:,:,:,:) = 0._wp   ;   syysal (:,:,:) = 0._wp   ;   syyage (:,:,:) = 0._wp
-               sxyc0 (:,:,:) = 0._wp   ;   sxye (:,:,:,:) = 0._wp   ;   sxysal (:,:,:) = 0._wp   ;   sxyage (:,:,:) = 0._wp
-               ! MV MP 2016
-               IF ( nn_pnd_scheme > 0 ) THEN
-                  sxap  (:,:,:) = 0._wp    ; sxvp  (:,:,:) = 0._wp 
-                  syap  (:,:,:) = 0._wp    ; syvp  (:,:,:) = 0._wp 
-                  sxxap (:,:,:) = 0._wp    ; sxxvp (:,:,:) = 0._wp 
-                  syyap (:,:,:) = 0._wp    ; syyvp (:,:,:) = 0._wp 
-                  sxyap (:,:,:) = 0._wp    ; sxyvp (:,:,:) = 0._wp
-               ENDIF
-               ! END MV MP 2016
-            ENDIF
-         ELSE                                   !* Start from rest
-            IF(lwp) WRITE(numout,*) '   ==>>   start from rest: set moments to 0'
-            sxopw (:,:) = 0._wp   ;   sxice (:,:,:) = 0._wp   ;   sxsn (:,:,:)  = 0._wp   ;   sxa  (:,:,:) = 0._wp
-            syopw (:,:) = 0._wp   ;   syice (:,:,:) = 0._wp   ;   sysn (:,:,:)  = 0._wp   ;   sya  (:,:,:) = 0._wp
-            sxxopw(:,:) = 0._wp   ;   sxxice(:,:,:) = 0._wp   ;   sxxsn(:,:,:)  = 0._wp   ;   sxxa (:,:,:) = 0._wp
-            syyopw(:,:) = 0._wp   ;   syyice(:,:,:) = 0._wp   ;   syysn(:,:,:)  = 0._wp   ;   syya (:,:,:) = 0._wp
-            sxyopw(:,:) = 0._wp   ;   sxyice(:,:,:) = 0._wp   ;   sxysn(:,:,:)  = 0._wp   ;   sxya (:,:,:) = 0._wp
-            !
-            sxc0  (:,:,:) = 0._wp   ;   sxe  (:,:,:,:) = 0._wp   ;   sxsal  (:,:,:) = 0._wp   ;   sxage  (:,:,:) = 0._wp
-            syc0  (:,:,:) = 0._wp   ;   sye  (:,:,:,:) = 0._wp   ;   sysal  (:,:,:) = 0._wp   ;   syage  (:,:,:) = 0._wp
-            sxxc0 (:,:,:) = 0._wp   ;   sxxe (:,:,:,:) = 0._wp   ;   sxxsal (:,:,:) = 0._wp   ;   sxxage (:,:,:) = 0._wp
-            syyc0 (:,:,:) = 0._wp   ;   syye (:,:,:,:) = 0._wp   ;   syysal (:,:,:) = 0._wp   ;   syyage (:,:,:) = 0._wp
-            sxyc0 (:,:,:) = 0._wp   ;   sxye (:,:,:,:) = 0._wp   ;   sxysal (:,:,:) = 0._wp   ;   sxyage (:,:,:) = 0._wp
-            ! MV MP 2016
-            IF ( nn_pnd_scheme > 0 ) THEN
-               sxap  (:,:,:) = 0._wp    ; sxvp  (:,:,:) = 0._wp 
-               syap  (:,:,:) = 0._wp    ; syvp  (:,:,:) = 0._wp 
-               sxxap (:,:,:) = 0._wp    ; sxxvp (:,:,:) = 0._wp 
-               syyap (:,:,:) = 0._wp    ; syyvp (:,:,:) = 0._wp 
-               sxyap (:,:,:) = 0._wp    ; sxyvp (:,:,:) = 0._wp
-            ENDIF
-            ! END MV MP 2016
-         ENDIF
-         !
-      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
-         !                                   ! -------------------
-         IF(lwp) WRITE(numout,*) '---- adv-rst ----'
-         iter = kt + nn_fsbc - 1             ! ice restarts are written at kt == nitrst - nn_fsbc + 1
-         !
-         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
-         ! MV MP 2016
-         IF ( nn_pnd_scheme > 0 ) THEN
-            DO jl = 1, jpl 
-               WRITE(zchar,'(I2.2)') jl
-               znam = 'sxap'//'_htc'//zchar
-               z2d(:,:) = sxap(:,:,jl)
-               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-               znam = 'syap'//'_htc'//zchar
-               z2d(:,:) = syap(:,:,jl)
-               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-               znam = 'sxxap'//'_htc'//zchar
-               z2d(:,:) = sxxap(:,:,jl)
-               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-               znam = 'syyap'//'_htc'//zchar
-               z2d(:,:) = syyap(:,:,jl)
-               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-               znam = 'sxyap'//'_htc'//zchar
-               z2d(:,:) = sxyap(:,:,jl)
-               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-   
-               znam = 'sxvp'//'_htc'//zchar
-               z2d(:,:) = sxvp(:,:,jl)
-               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-               znam = 'syvp'//'_htc'//zchar
-               z2d(:,:) = syvp(:,:,jl)
-               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-               znam = 'sxxvp'//'_htc'//zchar
-               z2d(:,:) = sxxvp(:,:,jl)
-               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-               znam = 'syyvp'//'_htc'//zchar
-               z2d(:,:) = syyvp(:,:,jl)
-               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-               znam = 'sxyvp'//'_htc'//zchar
-               z2d(:,:) = sxyvp(:,:,jl)
-               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
-            END DO
-         ENDIF
-         !
-      ENDIF
-      !
-   END SUBROUTINE adv_pra_rst
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option            Dummy module         NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-
-   !!======================================================================
-END MODULE iceadv_prather
Index: anches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceadv_umx.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceadv_umx.F90	(revision 8533)
+++ 	(revision )
@@ -1,662 +1,0 @@
-MODULE iceadv_umx
-   !!==============================================================================
-   !!                       ***  MODULE  iceadv_umx  ***
-   !! LIM sea-ice model : 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'                                    LIM 3.0 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   ice_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 lbclnk         ! lateral boundary conditions -- MPP exchanges
-   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_adv_umx    ! called by iceadv.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: iceadv_umx.F90 4499 2014-02-18 15:14:31Z timgraham $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE ice_adv_umx( k_order, kt, pu_ice, pv_ice,  &
-      &                    pato_i, pv_i, pv_s, psmv_i, poa_i, pa_i, pa_ip, pv_ip, pe_s, pe_i )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE ice_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) ::   psmv_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_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, psmv_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 ( nn_pnd_scheme > 0 ) 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_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
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('ice_adv_umx')
-      !
-      !  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 = 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( k_order, kt, 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. )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('ice_adv_umx')
-      !
-   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( nn_timing == 1 )  CALL timing_start('macho')
-      !
-      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      
-      !
-      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), DIMENSION(jpi,jpj) :: ztu1, ztu2, ztu3, ztu4
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('ultimate_x')
-      !
-      !                                                     !--  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
-      !
-      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), DIMENSION(jpi,jpj) :: ztv1, ztv2, ztv3, ztv4
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('ultimate_y')
-      !
-      !                                                     !--  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
-      !
-      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), DIMENSION(jpi,jpj) :: zbetup, zbetdo, zbup, zbdo, zmsk, zdiv
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('nonosc_2d')
-      !
-      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)
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('nonosc_2d')
-      !
-   END SUBROUTINE nonosc_2d
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option           Dummy module      NO LIM 3.0 sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-
-   !!======================================================================
-END MODULE iceadv_umx
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icealb.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icealb.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icealb.F90	(revision 8534)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                       ***  MODULE  icealb  ***
-   !! Ocean forcing:  bulk thermohaline forcing of the ice
+   !! Atmospheric forcing:  Albedo over sea ice
    !!=====================================================================
    !! History :  4.0  ! 2017-07  (C. Rousset) Split ice and ocean albedos
@@ -8,8 +8,8 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                    LIM 3.0 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   ice_alb       : albedo for ice (clear and overcast skies)
-   !!   alb_init      : initialisation of albedo computation
+   !!   '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
@@ -19,4 +19,5 @@
    USE lib_mpp        ! MPP library
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -109,5 +110,7 @@
       REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zafrac_pnd      ! relative ice fraction (effective)
       !!---------------------------------------------------------------------
-
+      !
+      IF( nn_timing == 1 )   CALL timing_start('icealb')
+      !
       !-----------------------------------------------------
       !  Snow-free albedo (no ice thickness dependence yet)
@@ -147,6 +150,4 @@
          ENDIF 
          !
-!!gm: optimization ( rn_alb_smlt - rn_alb_imlt ) * r1_c2 can be computed one for all 
-!!gm  before the DO-loop below
          DO jl = 1, jpl
             DO jj = 1, jpj
@@ -301,4 +302,6 @@
       END SELECT
       !
+      IF( nn_timing == 1 )   CALL timing_stop('icealb')
+      !
    END SUBROUTINE ice_alb
 
@@ -343,5 +346,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option           Dummy module      NO LIM 3.0 sea-ice model
+   !!   Default option           Dummy module         NO ESIM sea-ice model
    !!----------------------------------------------------------------------
 #endif
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icecor.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icecor.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icecor.F90	(revision 8534)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                     ***  MODULE  icecor  ***
-   !!   LIM-3 : Update of sea-ice global variables at the end of the time step
+   !!   ESIM : Corrections on sea-ice variables at the end of the time step
    !!======================================================================
    !! History :  3.0  !  2006-04  (M. Vancoppenolle) Original code
@@ -9,7 +9,7 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                       LIM3 sea-ice model
+   !!   'key_lim3'                                       ESIM sea-ice model
    !!----------------------------------------------------------------------
-   !!    ice_cor      : computes update of sea-ice global variables from trend terms
+   !!    ice_cor      : corrections on sea-ice variables
    !!----------------------------------------------------------------------
    USE dom_oce        ! ocean domain
@@ -22,9 +22,9 @@
    !
    USE in_out_manager ! I/O manager
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE lbclnk         ! lateral boundary condition - MPP link
+   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
-   USE iom            !
 
    IMPLICIT NONE
@@ -47,5 +47,5 @@
       !!               
       !! ** Purpose :   Computes corrections on sea-ice global variables at 
-      !!              the end of the dynamics.
+      !!              the end of the dynamics (kn=1) and thermodynamics (kn=2)
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt    ! number of iteration
@@ -184,5 +184,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option           Dummy module      NO LIM 3.0 sea-ice model
+   !!   Default option           Dummy module         NO ESIM sea-ice model
    !!----------------------------------------------------------------------
 #endif
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icectl.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icectl.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icectl.F90	(revision 8534)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                     ***  MODULE  icectl  ***
-   !!   LIM-3 : control and printing
+   !!   sea-ice : controls and prints
    !!======================================================================
    !! History :  3.5  !  2015-01  (M. Vancoppenolle) Original code
@@ -9,23 +9,25 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                       LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!    ice_ctl   : control prints in case of crash
-   !!    ice_prt   : ice control print at a given grid point
-   !!    ice_prt3D : control prints of ice arrays
-   !!----------------------------------------------------------------------
+   !!   '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            ! LIM-3: ice variables
-   USE ice1D          ! LIM-3: thermodynamical variables
+   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 phycst         ! Define parameters for the routines
    !
+   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 in_out_manager ! I/O manager
    USE prtctl         ! Print control
-   USE lib_fortran    ! 
 
    IMPLICIT NONE
@@ -48,5 +50,5 @@
 
    SUBROUTINE ice_cons_hsm( icount, cd_routine, pdiag_v, pdiag_s, pdiag_t, pdiag_fv, pdiag_fs, pdiag_ft )
-      !!----------------------------------------------------------------------
+      !!-------------------------------------------------------------------
       !!                       ***  ROUTINE ice_cons_hsm ***
       !!
@@ -60,5 +62,5 @@
       !!              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
@@ -70,5 +72,5 @@
       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
@@ -143,10 +145,10 @@
             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 == 'iceadv' ) THEN
+            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 /= 'iceadv' .AND. cd_routine /= 'icerdgrft' )  &
+            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
@@ -159,5 +161,5 @@
 
    SUBROUTINE ice_cons_final( cd_routine )
-      !!----------------------------------------------------------------------
+      !!-------------------------------------------------------------------
       !!                     ***  ROUTINE ice_cons_final ***
       !!
@@ -170,10 +172,10 @@
       !!              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
@@ -204,5 +206,5 @@
    
    SUBROUTINE ice_ctl( kt )
-      !!-----------------------------------------------------------------------
+      !!-------------------------------------------------------------------
       !!                   ***  ROUTINE ice_ctl *** 
       !!                 
@@ -415,5 +417,5 @@
    
    SUBROUTINE ice_prt( kt, ki, kj, kn, cd1 )
-      !!-----------------------------------------------------------------------
+      !!-------------------------------------------------------------------
       !!                   ***  ROUTINE ice_prt *** 
       !!                 
@@ -596,10 +598,10 @@
 
    SUBROUTINE ice_prt3D( cd_routine )
-      !!---------------------------------------------------------------------------------------------------------
-      !!                                   ***  ROUTINE ice_prt3D ***
+      !!-------------------------------------------------------------------
+      !!                  ***  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
@@ -664,7 +666,7 @@
 
 #else
-   !!--------------------------------------------------------------------------
-   !!   Default option         Empty Module               No LIM3 sea-ice model
-   !!--------------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty Module           No ESIM sea-ice model
+   !!----------------------------------------------------------------------
 #endif
 
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedia.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedia.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedia.F90	(revision 8534)
@@ -15,16 +15,16 @@
    !!    ice_dia_rst  : read/write budgets restart
    !!----------------------------------------------------------------------
-   USE ice            ! LIM-3: sea-ice variable
    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 icerst         ! ice restart
+   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 timing         ! preformance summary
-   USE iom            ! I/O manager
-   USE lib_fortran    ! glob_sum
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -279,5 +279,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_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn.F90	(revision 8534)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                     ***  MODULE  icedyn  ***
-   !!   Sea-Ice dynamics :  
+   !!   Sea-Ice dynamics : master routine for sea ice dynamics 
    !!======================================================================
    !! history :  4.0  ! 2017-09  (C. Rousset)  original code 
@@ -8,23 +8,23 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                       LIM3 sea-ice model
+   !!   'key_lim3'                                       ESIM sea-ice model
    !!----------------------------------------------------------------------
    !!   ice_dyn       : dynamics of sea ice
-   !!   ice_dyn_init  : initialisation of sea-ice dynamics
+   !!   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 icerhg         ! sea-ice: rheology
-   USE iceadv         ! sea-ice: advection
-   USE icerdgrft      ! sea-ice: ridging/rafting
+   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 lbclnk         ! lateral boundary conditions - MPP exchanges
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
    USE lib_mpp        ! MPP library
-   USE in_out_manager ! I/O manager
-   USE iom            ! I/O manager
-   USE lib_fortran    ! glob_sum
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE lbclnk         ! lateral boundary conditions (or mpp links)
    USE timing         ! Timing
 
@@ -73,5 +73,5 @@
       !!--------------------------------------------------------------------
       !
-      IF( nn_timing == 1 )  CALL timing_start('icedyn')
+      IF( nn_timing == 1 )   CALL timing_start('icedyn')
       !
       IF( kt == nit000 .AND. lwp ) THEN
@@ -104,19 +104,19 @@
 
       CASE ( np_dynFULL )          !==  all dynamical processes  ==!
-         CALL ice_rhg   ( kt )                            ! -- rheology  
-         CALL ice_adv   ( kt )   ;   CALL Hbig( zhmax )   ! -- advection of ice + correction on ice thickness
-         CALL ice_rdgrft( kt )                            ! -- ridging/rafting 
-         CALL ice_cor   ( kt , 1 )                        ! -- Corrections
+         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_rhg   ( kt )                            ! -- rheology  
-         CALL ice_adv   ( kt )                            ! -- advection of ice
-         CALL Hpiling                                     ! -- simple pile-up (replaces ridging/rafting)
-         CALL ice_cor   ( kt , 1 )                        ! -- Corrections
+         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_rhg   ( kt )                            ! -- rheology  
-         CALL ice_adv   ( kt )                            ! -- advection of ice
-         CALL Hpiling                                     ! -- simple pile-up (replaces ridging/rafting)
+         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)
@@ -125,5 +125,5 @@
          !!CALL RANDOM_NUMBER(u_ice(:,:))
          !!CALL RANDOM_NUMBER(v_ice(:,:))
-         CALL ice_adv   ( kt )                            ! -- advection of ice
+         CALL ice_dyn_adv   ( kt )                            ! -- advection of ice
 
       END SELECT
@@ -269,7 +269,7 @@
       IF( .NOT. ln_landfast )   tau_icebfr(:,:) = 0._wp
       !
-      CALL ice_rdgrft_init          ! set ice ridging/rafting parameters
-      CALL ice_rhg_init             ! set ice rheology parameters
-      CALL ice_adv_init             ! set ice advection parameters
+      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
@@ -277,5 +277,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option         Empty module          NO LIM-3 sea-ice model
+   !!   Default option         Empty module           NO ESIM sea-ice model
    !!----------------------------------------------------------------------
 #endif 
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv.F90	(revision 8534)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv.F90	(revision 8534)
@@ -0,0 +1,179 @@
+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, smv_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, smv_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_smv(:,:) = SUM(     smv_i(:,:,:)          - smv_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('icetrp') )   CALL iom_put( "icetrp" , diag_trp_vi * rday  )         ! ice volume transport
+      IF( iom_use('snwtrp') )   CALL iom_put( "snwtrp" , diag_trp_vs * rday  )         ! snw volume transport
+      IF( iom_use('saltrp') )   CALL iom_put( "saltrp" , diag_trp_smv * rday * rhoic ) ! salt content transport
+      IF( iom_use('deitrp') )   CALL iom_put( "deitrp" , diag_trp_ei         )         ! advected ice enthalpy (W/m2)
+      IF( iom_use('destrp') )   CALL iom_put( "destrp" , diag_trp_es         )         ! advected snw enthalpy (W/m2)
+
+      IF( lrst_ice ) THEN                       !* write Prather fields in the restart file
+         IF( ln_adv_Pra )   CALL adv_pra_rst( 'WRITE', kt )
+      ENDIF
+               
+      ! 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_rst( 'READ' )  !* 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_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv_pra.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv_pra.F90	(revision 8534)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv_pra.F90	(revision 8534)
@@ -0,0 +1,1004 @@
+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
+   !!----------------------------------------------------------------------
+   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_rst       ! called by icedyn_adv
+
+   !! * 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, psmv_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) ::   psmv_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) = psmv_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 ( nn_pnd_scheme > 0 ) 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 ( nn_pnd_scheme > 0 ) 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 ( nn_pnd_scheme > 0 ) 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(:,:)
+         psmv_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
+         ! MV MP 2016
+         IF ( nn_pnd_scheme > 0 ) THEN
+            pa_ip  (:,:,jl)   = z0ap (:,:,jl) * r1_e1e2t(:,:)
+            pv_ip  (:,:,jl)   = z0vp (:,:,jl) * r1_e1e2t(:,:)
+         ENDIF
+         ! END MV MP 2016
+      END DO
+      !
+      DEALLOCATE( zarea , z0opw , z0ice, z0snw , z0ai , z0es , z0smi , z0oi , z0ap , z0vp , z0ei )
+      !
+   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_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) :: z2d
+      !!----------------------------------------------------------------------
+      !
+      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialize
+         !                                   ! ---------------
+         IF( ln_rstart ) THEN                   !* Read the restart file
+            !
+            id1 = iom_varid( numrir, 'sxopw' , ldstop = .FALSE. )
+            !
+            IF( id1 > 0 ) THEN      ! fields exist
+               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
+               ! MV MP 2016
+               IF ( nn_pnd_scheme > 0 ) THEN
+                  DO jl = 1, jpl 
+                     WRITE(zchar,'(I2.2)') jl
+                     znam = 'sxap'//'_htc'//zchar
+                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+                     sxap(:,:,jl) = z2d(:,:)
+                     znam = 'syap'//'_htc'//zchar
+                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+                     syap(:,:,jl) = z2d(:,:)
+                     znam = 'sxxap'//'_htc'//zchar
+                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+                     sxxap(:,:,jl) = z2d(:,:)
+                     znam = 'syyap'//'_htc'//zchar
+                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+                     syyap(:,:,jl) = z2d(:,:)
+                     znam = 'sxyap'//'_htc'//zchar
+                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+                     sxyap(:,:,jl) = z2d(:,:)
+
+                     znam = 'sxvp'//'_htc'//zchar
+                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+                     sxvp(:,:,jl) = z2d(:,:)
+                     znam = 'syvp'//'_htc'//zchar
+                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+                     syvp(:,:,jl) = z2d(:,:)
+                     znam = 'sxxvp'//'_htc'//zchar
+                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+                     sxxvp(:,:,jl) = z2d(:,:)
+                     znam = 'syyvp'//'_htc'//zchar
+                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+                     syyvp(:,:,jl) = z2d(:,:)
+                     znam = 'sxyvp'//'_htc'//zchar
+                     CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
+                     sxyvp(:,:,jl) = z2d(:,:)
+                  END DO
+               ENDIF
+               ! END MV MP 2016
+
+               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
+               !
+            ELSE                                     ! start rheology from rest
+               IF(lwp) WRITE(numout,*) '   ==>>   previous run without Prather, set moments to 0'
+               sxopw (:,:) = 0._wp   ;   sxice (:,:,:) = 0._wp   ;   sxsn (:,:,:)  = 0._wp   ;   sxa  (:,:,:) = 0._wp
+               syopw (:,:) = 0._wp   ;   syice (:,:,:) = 0._wp   ;   sysn (:,:,:)  = 0._wp   ;   sya  (:,:,:) = 0._wp
+               sxxopw(:,:) = 0._wp   ;   sxxice(:,:,:) = 0._wp   ;   sxxsn(:,:,:)  = 0._wp   ;   sxxa (:,:,:) = 0._wp
+               syyopw(:,:) = 0._wp   ;   syyice(:,:,:) = 0._wp   ;   syysn(:,:,:)  = 0._wp   ;   syya (:,:,:) = 0._wp
+               sxyopw(:,:) = 0._wp   ;   sxyice(:,:,:) = 0._wp   ;   sxysn(:,:,:)  = 0._wp   ;   sxya (:,:,:) = 0._wp
+               !
+               sxc0  (:,:,:) = 0._wp   ;   sxe  (:,:,:,:) = 0._wp   ;   sxsal  (:,:,:) = 0._wp   ;   sxage  (:,:,:) = 0._wp
+               syc0  (:,:,:) = 0._wp   ;   sye  (:,:,:,:) = 0._wp   ;   sysal  (:,:,:) = 0._wp   ;   syage  (:,:,:) = 0._wp
+               sxxc0 (:,:,:) = 0._wp   ;   sxxe (:,:,:,:) = 0._wp   ;   sxxsal (:,:,:) = 0._wp   ;   sxxage (:,:,:) = 0._wp
+               syyc0 (:,:,:) = 0._wp   ;   syye (:,:,:,:) = 0._wp   ;   syysal (:,:,:) = 0._wp   ;   syyage (:,:,:) = 0._wp
+               sxyc0 (:,:,:) = 0._wp   ;   sxye (:,:,:,:) = 0._wp   ;   sxysal (:,:,:) = 0._wp   ;   sxyage (:,:,:) = 0._wp
+               ! MV MP 2016
+               IF ( nn_pnd_scheme > 0 ) THEN
+                  sxap  (:,:,:) = 0._wp    ; sxvp  (:,:,:) = 0._wp 
+                  syap  (:,:,:) = 0._wp    ; syvp  (:,:,:) = 0._wp 
+                  sxxap (:,:,:) = 0._wp    ; sxxvp (:,:,:) = 0._wp 
+                  syyap (:,:,:) = 0._wp    ; syyvp (:,:,:) = 0._wp 
+                  sxyap (:,:,:) = 0._wp    ; sxyvp (:,:,:) = 0._wp
+               ENDIF
+               ! END MV MP 2016
+            ENDIF
+         ELSE                                   !* Start from rest
+            IF(lwp) WRITE(numout,*) '   ==>>   start from rest: set moments to 0'
+            sxopw (:,:) = 0._wp   ;   sxice (:,:,:) = 0._wp   ;   sxsn (:,:,:)  = 0._wp   ;   sxa  (:,:,:) = 0._wp
+            syopw (:,:) = 0._wp   ;   syice (:,:,:) = 0._wp   ;   sysn (:,:,:)  = 0._wp   ;   sya  (:,:,:) = 0._wp
+            sxxopw(:,:) = 0._wp   ;   sxxice(:,:,:) = 0._wp   ;   sxxsn(:,:,:)  = 0._wp   ;   sxxa (:,:,:) = 0._wp
+            syyopw(:,:) = 0._wp   ;   syyice(:,:,:) = 0._wp   ;   syysn(:,:,:)  = 0._wp   ;   syya (:,:,:) = 0._wp
+            sxyopw(:,:) = 0._wp   ;   sxyice(:,:,:) = 0._wp   ;   sxysn(:,:,:)  = 0._wp   ;   sxya (:,:,:) = 0._wp
+            !
+            sxc0  (:,:,:) = 0._wp   ;   sxe  (:,:,:,:) = 0._wp   ;   sxsal  (:,:,:) = 0._wp   ;   sxage  (:,:,:) = 0._wp
+            syc0  (:,:,:) = 0._wp   ;   sye  (:,:,:,:) = 0._wp   ;   sysal  (:,:,:) = 0._wp   ;   syage  (:,:,:) = 0._wp
+            sxxc0 (:,:,:) = 0._wp   ;   sxxe (:,:,:,:) = 0._wp   ;   sxxsal (:,:,:) = 0._wp   ;   sxxage (:,:,:) = 0._wp
+            syyc0 (:,:,:) = 0._wp   ;   syye (:,:,:,:) = 0._wp   ;   syysal (:,:,:) = 0._wp   ;   syyage (:,:,:) = 0._wp
+            sxyc0 (:,:,:) = 0._wp   ;   sxye (:,:,:,:) = 0._wp   ;   sxysal (:,:,:) = 0._wp   ;   sxyage (:,:,:) = 0._wp
+            ! MV MP 2016
+            IF ( nn_pnd_scheme > 0 ) THEN
+               sxap  (:,:,:) = 0._wp    ; sxvp  (:,:,:) = 0._wp 
+               syap  (:,:,:) = 0._wp    ; syvp  (:,:,:) = 0._wp 
+               sxxap (:,:,:) = 0._wp    ; sxxvp (:,:,:) = 0._wp 
+               syyap (:,:,:) = 0._wp    ; syyvp (:,:,:) = 0._wp 
+               sxyap (:,:,:) = 0._wp    ; sxyvp (:,:,:) = 0._wp
+            ENDIF
+            ! END MV MP 2016
+         ENDIF
+         !
+      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
+         !                                   ! -------------------
+         IF(lwp) WRITE(numout,*) '---- adv-rst ----'
+         iter = kt + nn_fsbc - 1             ! ice restarts are written at kt == nitrst - nn_fsbc + 1
+         !
+         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
+         ! MV MP 2016
+         IF ( nn_pnd_scheme > 0 ) THEN
+            DO jl = 1, jpl 
+               WRITE(zchar,'(I2.2)') jl
+               znam = 'sxap'//'_htc'//zchar
+               z2d(:,:) = sxap(:,:,jl)
+               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+               znam = 'syap'//'_htc'//zchar
+               z2d(:,:) = syap(:,:,jl)
+               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+               znam = 'sxxap'//'_htc'//zchar
+               z2d(:,:) = sxxap(:,:,jl)
+               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+               znam = 'syyap'//'_htc'//zchar
+               z2d(:,:) = syyap(:,:,jl)
+               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+               znam = 'sxyap'//'_htc'//zchar
+               z2d(:,:) = sxyap(:,:,jl)
+               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+   
+               znam = 'sxvp'//'_htc'//zchar
+               z2d(:,:) = sxvp(:,:,jl)
+               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+               znam = 'syvp'//'_htc'//zchar
+               z2d(:,:) = syvp(:,:,jl)
+               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+               znam = 'sxxvp'//'_htc'//zchar
+               z2d(:,:) = sxxvp(:,:,jl)
+               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+               znam = 'syyvp'//'_htc'//zchar
+               z2d(:,:) = syyvp(:,:,jl)
+               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+               znam = 'sxyvp'//'_htc'//zchar
+               z2d(:,:) = sxyvp(:,:,jl)
+               CALL iom_rstput( iter, nitrst, numriw, znam , z2d )
+            END DO
+         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_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv_umx.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv_umx.F90	(revision 8534)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_adv_umx.F90	(revision 8534)
@@ -0,0 +1,658 @@
+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)
+   USE timing         ! Timing
+
+   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, psmv_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) ::   psmv_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, psmv_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 ( nn_pnd_scheme > 0 ) 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 = 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( k_order, kt, 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. )
+      !
+   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( nn_timing == 1 )  CALL timing_start('macho')
+      !
+      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      
+      !
+!!      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), DIMENSION(jpi,jpj) :: ztu1, ztu2, ztu3, ztu4
+      !!----------------------------------------------------------------------
+      !
+!!      IF( nn_timing == 1 )  CALL timing_start('ultimate_x')
+      !
+      !                                                     !--  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
+      !
+!!      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), DIMENSION(jpi,jpj) :: ztv1, ztv2, ztv3, ztv4
+      !!----------------------------------------------------------------------
+      !
+!!      IF( nn_timing == 1 )  CALL timing_start('ultimate_y')
+      !
+      !                                                     !--  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
+      !
+!!      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), DIMENSION(jpi,jpj) :: zbetup, zbetdo, zbup, zbdo, zmsk, zdiv
+      !!----------------------------------------------------------------------
+      !
+!!      IF( nn_timing == 1 )  CALL timing_start('nonosc_2d')
+      !
+      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)
+      !
+!!      IF( nn_timing == 1 )  CALL timing_stop('nonosc_2d')
+      !
+   END SUBROUTINE nonosc_2d
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option           Dummy module         NO ESIM sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icedyn_adv_umx
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rdgrft.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rdgrft.F90	(revision 8534)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rdgrft.F90	(revision 8534)
@@ -0,0 +1,930 @@
+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 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(:,:)   ::   asum     ! sum of total ice and open water area
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   aksum    ! ratio of area removed to area ridged
+   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), 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)
+   REAL(wp)            ::   zdrho                   ! 
+   !
+   ! ** 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
+   LOGICAL  ::   ln_str_R75       ! ice strength parameterization (Rothrock75)
+   REAL(wp) ::   rn_perdg         ! ridging work divided by pot. energy change in ridging
+   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( asum (jpi,jpj)     , apartf (jpi,jpj,0:jpl) , aksum (jpi,jpj)     ,     &
+         &      hrmin(jpi,jpj,jpl) , hraft  (jpi,jpj,jpl)   , aridge(jpi,jpj,jpl) ,     &
+         &      hrmax(jpi,jpj,jpl) , hi_hrdg(jpi,jpj,jpl)   , araft (jpi,jpj,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  ::   niter              ! local integer 
+      INTEGER  ::   iterate_ridging    ! if =1, repeat the ridging
+      REAL(wp) ::   zfac               ! local scalar
+      REAL(wp), DIMENSION(jpi,jpj) ::   closing_net     ! net rate at which area is removed    (1/s)
+      !                                                 ! (ridging ice area - area of new ridges) / dt
+      REAL(wp), DIMENSION(jpi,jpj) ::   divu_adv        ! divu as implied by transport scheme  (1/s)
+      REAL(wp), DIMENSION(jpi,jpj) ::   opning          ! rate of opening due to divergence/shear
+      REAL(wp), DIMENSION(jpi,jpj) ::   closing_gross   ! rate at which area removed, not counting area of new ridges
+      !
+      INTEGER, PARAMETER ::   nitermax = 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,*)'~~~~~~~~~~~~~'
+         !
+         zdrho = 0.5 * grav * (rau0-rhoic) * rhoic * r1_rau0      ! proport const for PE
+         !
+      ENDIF      
+
+      !-----------------------------------------------------------------------------!
+      ! 1) Thickness categories boundaries, ice / o.w. concentrations, init_ons
+      !-----------------------------------------------------------------------------!
+      !
+      CALL rdgrft_prep                             ! 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_csrdg * 0.5_wp * ( 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.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
+         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
+               zfac   = ( opning(ji,jj) - apartf(ji,jj,0) * closing_gross(ji,jj) ) * rdt_ice
+               IF    ( zfac < 0._wp .AND. zfac > - ato_i(ji,jj) ) THEN                  ! would lead to negative ato_i
+                  opning(ji,jj) = apartf(ji,jj,0) * closing_gross(ji,jj) - ato_i(ji,jj) * r1_rdtice 
+               ELSEIF( zfac > 0._wp .AND. zfac > ( asum(ji,jj) - ato_i(ji,jj) ) ) THEN  ! would lead to ato_i > asum
+                  opning(ji,jj) = apartf(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
+                  zfac = apartf(ji,jj,jl) * closing_gross(ji,jj) * rdt_ice
+                  IF( zfac  >  a_i(ji,jj,jl) ) THEN
+                     closing_gross(ji,jj) = closing_gross(ji,jj) * a_i(ji,jj,jl) / zfac
+                  ENDIF
+               END DO
+            END DO
+         END DO
+
+         ! 3.2 Redistribute area, volume, and energy.
+         !-----------------------------------------------------------------------------!
+         CALL rdgrft_shift( opning, closing_gross )
+         
+         ! 3.3 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.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 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 rdgrft_prep
+            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 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
+      !!---------------------------------------------------------------------!
+      !!                ***  ROUTINE rdgrft_prep ***
+      !!
+      !! ** 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) ::   z1_gstar, z1_astar, zhmean, zdummy   ! local scalar
+      REAL(wp), DIMENSION(jpi,jpj,-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    
+
+      CALL ice_var_zapsmall   ! Zero out categories with very small areas
+
+      !                       ! Ice thickness needed for rafting
+      WHERE( a_i(:,:,:) >= epsi20 )   ;   ht_i(:,:,:) = v_i (:,:,:) / a_i(:,:,:)
+      ELSEWHERE                       ;   ht_i(:,:,:) = 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
+      asum(:,:) = ato_i(:,:) + SUM( a_i, dim=3 )
+      !
+      ! 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) = 0._wp
+      zGsum(:,:,0 ) = ato_i(:,:) / asum(:,:)
+      DO jl = 1, jpl
+         zGsum(:,:,jl) = ( ato_i(:,:) + SUM( a_i(:,:,1:jl), dim=3 ) ) / asum(:,:) ! 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 jj = 1, jpj 
+               DO ji = 1, jpi
+                  IF    ( zGsum(ji,jj,jl)   < rn_gstar ) THEN
+                     apartf(ji,jj,jl) = z1_gstar * ( zGsum(ji,jj,jl) - zGsum(ji,jj,jl-1) ) * &
+                        &                          ( 2._wp - ( zGsum(ji,jj,jl-1) + zGsum(ji,jj,jl) ) * z1_gstar )
+                  ELSEIF( zGsum(ji,jj,jl-1) < rn_gstar ) THEN
+                     apartf(ji,jj,jl) = z1_gstar * ( rn_gstar        - zGsum(ji,jj,jl-1) ) *  &
+                        &                          ( 2._wp - ( zGsum(ji,jj,jl-1) + rn_gstar        ) * z1_gstar )
+                  ELSE
+                     apartf(ji,jj,jl) = 0._wp
+                  ENDIF
+               END DO
+            END DO
+         END DO
+         !
+      ELSEIF( ln_partf_exp ) THEN      !--- Exponential, more stable formulation (Lipscomb et al, 2007)
+         !                        
+         zdummy = 1._wp / ( 1._wp - EXP(-z1_astar) )        ! precompute exponential terms using zGsum as a work array
+         DO jl = -1, jpl
+            zGsum(:,:,jl) = EXP( -zGsum(:,:,jl) * z1_astar ) * zdummy
+         END DO
+         DO jl = 0, jpl
+            apartf(:,:,jl) = zGsum(:,:,jl-1) - zGsum(:,:,jl)
+         END DO
+         !
+      ENDIF
+
+      !                                !--- Ridging and rafting participation concentrations
+      IF( ln_rafting .AND. ln_ridging ) THEN             !- ridging & rafting
+         DO jl = 1, jpl
+            DO jj = 1, jpj 
+               DO ji = 1, jpi
+                  aridge(ji,jj,jl) = ( 1._wp + TANH ( rn_craft * ( ht_i(ji,jj,jl) - rn_hraft ) ) ) * 0.5_wp * apartf(ji,jj,jl)
+                  araft (ji,jj,jl) = apartf(ji,jj,jl) - aridge(ji,jj,jl)
+               END DO
+            END DO
+         END DO
+      ELSEIF( ln_ridging .AND. .NOT. ln_rafting ) THEN   !- ridging alone
+         aridge(:,:,:) = apartf(:,:,1:jpl)
+         araft (:,:,:) = 0._wp
+      ELSEIF( ln_rafting .AND. .NOT. ln_ridging ) THEN   !- rafting alone   
+        aridge(:,:,:) = 0._wp
+         araft (:,:,:) = apartf(:,:,1:jpl)
+      ELSE                                               !- no ridging & no rafting
+         aridge(:,:,:) = 0._wp
+         araft (:,:,:) = 0._wp         
+      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.
+      !
+      ! 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(:,:) = apartf(:,:,0)
+      zdummy = 1._wp / hi_hrft
+      ! Transfer function
+      DO jl = 1, jpl !all categories have a specific transfer function
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF ( apartf(ji,jj,jl) > 0._wp ) THEN
+                  zhmean            = MAX( SQRT( rn_hstar * ht_i(ji,jj,jl) ), ht_i(ji,jj,jl) * hrdg_hi_min )
+                  hrmin  (ji,jj,jl) = MIN( 2._wp * ht_i(ji,jj,jl), 0.5_wp * ( zhmean + ht_i(ji,jj,jl) ) )
+                  hrmax  (ji,jj,jl) = 2._wp * zhmean - hrmin(ji,jj,jl)
+                  hraft  (ji,jj,jl) = ht_i(ji,jj,jl) * zdummy
+                  hi_hrdg(ji,jj,jl) = ht_i(ji,jj,jl) / MAX( zhmean, epsi20 )
+                  !
+                  ! Normalization factor : aksum, ensures mass conservation
+                  aksum(ji,jj) = aksum(ji,jj) + aridge(ji,jj,jl) * ( 1._wp - hi_hrdg(ji,jj,jl) )    &
+                     &                        + araft (ji,jj,jl) * ( 1._wp - hi_hrft )
+               ELSE
+                  hrmin  (ji,jj,jl) = 0._wp 
+                  hrmax  (ji,jj,jl) = 0._wp 
+                  hraft  (ji,jj,jl) = 0._wp 
+                  hi_hrdg(ji,jj,jl) = 1._wp
+               ENDIF
+            END DO
+         END DO
+      END DO
+      !
+   END SUBROUTINE rdgrft_prep
+
+
+   SUBROUTINE rdgrft_shift( opning, closing_gross )
+      !!----------------------------------------------------------------------
+      !!                ***  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.
+      !!----------------------------------------------------------------------
+      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 retreats, excluding area of new ridges
+      !
+      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 and new area going to jl2
+
+      INTEGER , DIMENSION(jpij) ::   indxi, indxj     ! compressed indices
+      REAL(wp), DIMENSION(jpij) ::   zswitch, fvol    ! new ridge volume going to jl2
+
+      REAL(wp), DIMENSION(jpij) ::   afrac            ! fraction of category area ridged 
+      REAL(wp), DIMENSION(jpij) ::   ardg1 , ardg2    ! area of ice ridged & new ridges
+      REAL(wp), DIMENSION(jpij) ::   vsrdg , esrdg    ! snow volume & energy of ridging ice
+      ! MV MP 2016
+      REAL(wp), DIMENSION(jpij) ::   vprdg            ! pond volume of ridging ice
+      REAL(wp), DIMENSION(jpij) ::   aprdg1           ! pond area of ridging ice
+      REAL(wp), DIMENSION(jpij) ::   aprdg2           ! pond area of ridging ice
+      ! END MV MP 2016
+      REAL(wp), DIMENSION(jpij) ::   dhr, dhr2        ! hrmax - hrmin  &  hrmax^2 - hrmin^2
+
+      REAL(wp), DIMENSION(jpij) ::   vrdg1            ! volume of ice ridged
+      REAL(wp), DIMENSION(jpij) ::   vrdg2            ! volume of new ridges
+      REAL(wp), DIMENSION(jpij) ::   vsw              ! volume of seawater trapped into ridges
+      REAL(wp), DIMENSION(jpij) ::   srdg1            ! sal*volume of ice ridged
+      REAL(wp), DIMENSION(jpij) ::   srdg2            ! sal*volume of new ridges
+      REAL(wp), DIMENSION(jpij) ::   smsw             ! sal*volume of water trapped into ridges
+      REAL(wp), DIMENSION(jpij) ::   oirdg1, oirdg2   ! ice age of ice ridged
+
+      REAL(wp), DIMENSION(jpij) ::   afrft            ! fraction of category area rafted
+      REAL(wp), DIMENSION(jpij) ::   arft1 , arft2    ! area of ice rafted and new rafted zone
+      REAL(wp), DIMENSION(jpij) ::   virft , vsrft    ! ice & snow volume of rafting ice
+      ! MV MP 2016
+      REAL(wp), DIMENSION(jpij) ::   vprft            ! pond volume of rafting ice
+      REAL(wp), DIMENSION(jpij) ::   aprft1           ! pond area of rafted ice
+      REAL(wp), DIMENSION(jpij) ::   aprft2           ! pond area of new rafted ice
+      ! END MV MP 2016
+      REAL(wp), DIMENSION(jpij) ::   esrft , smrft    ! snow energy & salinity of rafting ice
+      REAL(wp), DIMENSION(jpij) ::   oirft1, oirft2   ! ice age of ice rafted
+
+      REAL(wp), DIMENSION(jpij,nlay_i) ::   eirft     ! ice energy of rafting ice
+      REAL(wp), DIMENSION(jpij,nlay_i) ::   erdg1     ! enth*volume of ice ridged
+      REAL(wp), DIMENSION(jpij,nlay_i) ::   erdg2     ! enth*volume of new ridges
+      REAL(wp), DIMENSION(jpij,nlay_i) ::   ersw      ! enth of water trapped into ridges
+      !!----------------------------------------------------------------------
+
+      !-------------------------------------------------------------------------------
+      ! 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) - apartf(ji,jj,0) * closing_gross(ji,jj) ) * rdt_ice )
+         END DO
+      END DO
+
+      !-----------------------------------------------------------------
+      ! 2) 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
+
+         !------------------------------------------------
+         ! 2.1) Identify grid cells with nonzero ridging
+         !------------------------------------------------
+         icells = 0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( apartf(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)
+
+            !--------------------------------------------------------------------
+            ! 2.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
+
+            !---------------------------------------------------------------
+            ! 2.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) * hi_hrdg(ji,jj,jl1)
+            arft2(ij) = arft1(ij) * hi_hrft
+
+            !--------------------------------------------------------------------------
+            ! 2.4) Substract area, volume, and energy from ridging 
+            !     / rafting category n1.
+            !--------------------------------------------------------------------------
+            vrdg1(ij) = v_i(ji,jj,jl1) * afrac(ij)
+            vrdg2(ij) = vrdg1(ij) * ( 1. + rn_porordg )
+            vsw  (ij) = vrdg1(ij) * rn_porordg
+
+            vsrdg (ij) = v_s  (ji,jj,  jl1) * afrac(ij)
+            esrdg (ij) = e_s  (ji,jj,1,jl1) * afrac(ij)
+            !MV MP 2016
+            IF ( nn_pnd_scheme > 0 ) THEN
+               aprdg1(ij) = a_ip(ji,jj, jl1) * afrac(ij)
+               aprdg2(ij) = a_ip(ji,jj, jl1) * afrac(ij) * hi_hrdg(ji,jj,jl1)
+               vprdg(ij)  = v_ip(ji,jj, jl1) * afrac(ij)
+            ENDIF
+            ! END MV MP 2016
+            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) * hi_hrdg(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)
+            !MV MP 2016
+            IF ( nn_pnd_scheme > 0 ) THEN
+               aprft1(ij) = a_ip (ji,jj,  jl1) * afrft(ij)
+               aprft2(ij) = a_ip (ji,jj,  jl1) * afrft(ij) * hi_hrft
+               vprft(ij)  = v_ip(ji,jj,jl1)    * afrft(ij)
+            ENDIF
+            ! END MV MP 2016
+            srdg1 (ij) = smv_i(ji,jj,  jl1) * afrac(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) * hi_hrft 
+
+            !-----------------------------------------------------------------
+            ! 2.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
+
+            !------------------------------------------            
+            ! 2.6 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_dyn(ji,jj) = wfx_snw_dyn(ji,jj) + ( rhosn * vsrdg(ij) * ( 1._wp - rn_fsnwrdg )   & 
+               &                                      + rhosn * vsrft(ij) * ( 1._wp - rn_fsnwrft ) ) * r1_rdtice  ! fresh water source for ocean
+
+            hfx_dyn(ji,jj) = hfx_dyn(ji,jj) + ( - esrdg(ij) * ( 1._wp - rn_fsnwrdg )         & 
+               &                                - esrft(ij) * ( 1._wp - rn_fsnwrft ) ) * r1_rdtice        ! heat sink for ocean (<0, W.m-2)
+
+            ! MV MP 2016
+            !------------------------------------------            
+            ! 2.7 Put the melt pond water in the ocean
+            !------------------------------------------            
+            !  Place part of the melt pond volume into the ocean. 
+            IF ( ( nn_pnd_scheme > 0 ) .AND. ln_pnd_fw ) THEN
+               wfx_pnd(ji,jj) = wfx_pnd(ji,jj) + ( rhofw * vprdg(ij) * ( 1._wp - rn_fpndrdg )   & 
+               &                                 + rhofw * vprft(ij) * ( 1._wp - rn_fpndrft ) ) * r1_rdtice  ! fresh water source for ocean
+            ENDIF
+            ! END MV MP 2016
+
+            !-----------------------------------------------------------------
+            ! 2.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)
+
+            ! MV MP 2016
+            IF ( nn_pnd_scheme > 0 ) THEN
+               v_ip (ji,jj,jl1) = v_ip (ji,jj,jl1) - vprdg (ij) - vprft (ij)
+               a_ip (ji,jj,jl1) = a_ip (ji,jj,jl1) - aprdg1(ij) - aprft1(ij)
+            ENDIF
+            ! END MV MP 2016
+
+         END DO
+
+         !--------------------------------------------------------------------
+         ! 2.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
+
+         !-------------------------------------------------------------------------------
+         ! 3) 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
+!!gm see above               IF( hraft(ji,jj,jl1) <= hi_max(jl2) .AND. hraft(ji,jj,jl1) >  hi_max(jl2-1) ) THEN
+               IF( hi_max(jl2-1) < hraft(ji,jj,jl1) .AND. hraft(ji,jj,jl1) <= hi_max(jl2)  ) 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_fsnwrdg * fvol(ij)  +  &
+                  &                                        vsrft (ij) * rn_fsnwrft * zswitch(ij) )
+               e_s  (ji,jj,1,jl2) = e_s  (ji,jj,1,jl2) + ( esrdg (ij) * rn_fsnwrdg * fvol(ij)  +  &
+                  &                                        esrft (ij) * rn_fsnwrft * zswitch(ij) )
+               ! MV MP 2016
+               IF ( nn_pnd_scheme > 0 ) THEN
+                  v_ip (ji,jj,jl2) = v_ip(ji,jj,jl2) + (   vprdg (ij) * rn_fpndrdg * fvol   (ij)   &
+                     &                                   + vprft (ij) * rn_fpndrft * zswitch(ij)   )
+                  a_ip (ji,jj,jl2) = a_ip(ji,jj,jl2) + (   aprdg2(ij) * rn_fpndrdg * farea         & 
+                     &                                   + aprft2(ij) * rn_fpndrft * zswitch(ji)   )
+               ENDIF
+               ! END MV MP 2016
+            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)
+      !
+   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
+      !!----------------------------------------------------------------------
+
+      !                              !--------------------------------------------------!
+      CALL rdgrft_prep               ! Thickness distribution of ridging and ridged ice !
+      !                              !--------------------------------------------------!
+
+      !                              !--------------------------------------------------!
+      IF( ln_str_R75 ) THEN          ! Ice strength => Rothrock (1975) method           !
+      !                              !--------------------------------------------------!
+         z1_3 = 1._wp / 3._wp
+         DO jl = 1, jpl
+            WHERE( apartf(:,:,jl) > 0._wp )
+               strength(:,:) =  -         apartf(:,:,jl) * ht_i   (:,:,jl) * ht_i(:,:,jl)   &  ! PE loss from deforming ice
+                  &             + 2._wp * araft (:,:,jl) * ht_i   (:,:,jl) * ht_i(:,:,jl)   &  ! PE gain from rafting ice
+                  &             +         aridge(:,:,jl) * hi_hrdg(:,:,jl) * z1_3 *         &  ! PE gain from ridging ice
+                  &                      ( hrmax(:,:,jl) * hrmax  (:,:,jl) +                &
+                  &                        hrmin(:,:,jl) * hrmin  (:,:,jl) +                &
+                  &                        hrmax(:,:,jl) * hrmin  (:,:,jl) )
+            ELSEWHERE
+               strength(:,:) = 0._wp
+            END WHERE
+         END DO
+         strength(:,:) = rn_perdg * zdrho * strength(:,:) / aksum(:,:) * tmask(:,:,1)
+                         ! where zdrho = (g/2)*(rhow-rhoi)*(rhoi/rhow) and rn_perdg accounts for frictional dissipation
+         ismooth = 1
+      !                              !--------------------------------------------------!
+      ELSEIF( 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
+         !
+      ENDIF
+      !                              !--------------------------------------------------!
+      SELECT CASE( ismooth )         ! Smoothing ice strength                           !
+      !                              !--------------------------------------------------!
+      CASE( 1 )               !--- Spatial smoothing
+         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. )
+         !
+      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 ( ( asum(ji,jj) - ato_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, &
+         &                    ln_str_R75, rn_perdg,          &
+         &                    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,*) '      ice strength parameterization Rothrock (1975)            ln_str_R75   = ', ln_str_R75 
+         WRITE(numout,*) '            Ratio of ridging work to PotEner change in ridging rn_perdg     = ', rn_perdg 
+         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_str_H79 .AND. ln_str_R75 ) .OR. ( .NOT.ln_str_H79 .AND. .NOT.ln_str_R75 ) ) THEN
+         CALL ctl_stop( 'ice_dyn_rdgrft_init: choose one and only one formulation for ice strength (ln_str_H79 or ln_str_R75)' )
+      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_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rhg.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rhg.F90	(revision 8534)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rhg.F90	(revision 8534)
@@ -0,0 +1,150 @@
+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, u_ice, v_ice, 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, 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,*) '         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_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rhg_evp.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rhg_evp.F90	(revision 8534)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedyn_rhg_evp.F90	(revision 8534)
@@ -0,0 +1,883 @@
+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
+   !!----------------------------------------------------------------------
+   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 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
+   !
+#if defined key_agrif
+   USE agrif_lim3_interp
+#endif
+   USE bdy_oce   , ONLY: ln_bdy 
+   USE bdyice 
+
+   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, pu_ice, pv_ice, 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 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, INTENT(in) ::   kt      ! time step
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pstress1_i, pstress2_i, pstress12_i
+      REAL(wp), DIMENSION(:,:), INTENT(  out) ::   pu_ice, pv_ice, 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) ::   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, 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) ::   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
+      !
+      !------------------------------------------------------------------------------!
+      ! 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)
+      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 (:,:) = 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)
+
+            ! 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) = pu_ice(:,jj) ! velocity at previous time step
+               zv_ice(:,jj) = pv_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) = ( ( pu_ice(ji,jj+1) * r1_e1u(ji,jj+1) - pu_ice(ji,jj) * r1_e1u(ji,jj) ) * e1f(ji,jj) * e1f(ji,jj)   &
+                  &         + ( pv_ice(ji+1,jj) * r1_e2v(ji+1,jj) - pv_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) * pu_ice(ji,jj) - e2u(ji-1,jj) * pu_ice(ji-1,jj)   &
+                  &    + e1v(ji,jj) * pv_ice(ji,jj) - e1v(ji,jj-1) * pv_ice(ji,jj-1)   &
+                  &    ) * r1_e1e2t(ji,jj)
+               zdiv2 = zdiv * zdiv
+               
+               ! tension at T points
+               zdt  = ( ( pu_ice(ji,jj) * r1_e2u(ji,jj) - pu_ice(ji-1,jj) * r1_e2u(ji-1,jj) ) * e2t(ji,jj) * e2t(ji,jj)   &
+                  &   - ( pv_ice(ji,jj) * r1_e1v(ji,jj) - pv_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 * ( ( pu_ice(ji,jj  ) + pu_ice(ji-1,jj  ) ) * e2t(ji,jj+1)     &
+                  &                     + ( pu_ice(ji,jj+1) + pu_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 * ( ( pv_ice(ji  ,jj) + pv_ice(ji  ,jj-1) ) * e1t(ji+1,jj)     &
+                  &                     + ( pv_ice(ji+1,jj) + pv_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) == 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( ( pv_ice(ji,jj) - v_oce (ji,jj) ) * ( pv_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) - pv_ice(ji,jj) )
+                     !
+                     !                 !--- tau_bottom/v_ice
+                  zvel  = MAX( zepsi, SQRT( pv_ice(ji,jj) * pv_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  ) * pu_ice(ji,jj  ) + e2u(ji-1,jj  ) * pu_ice(ji-1,jj  ) )  &
+                     &    + zmf(ji,jj+1) * ( e2u(ji,jj+1) * pu_ice(ji,jj+1) + e2u(ji-1,jj+1) * pu_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 ) ) )
+                     !
+                     !                 !--- ice velocity using implicit formulation (cf Madec doc & Bouillon 2009)
+                  pv_ice(ji,jj) = ( (           rswitch   * ( zmV_t(ji,jj)  * pv_ice(ji,jj)                            &  ! previous velocity
+                     &                                      + zTauE + zTauO * pv_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 ) * pv_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
+                  !!pv_ice(ji,jj) = ( zmV_t(ji,jj) * ( zbeta * pv_ice(ji,jj) + pv_ice_b(ji,jj) )                  &
+                  !!   &           + zfV(ji,jj) + zCory(ji,jj) + 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( pv_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( ( pu_ice(ji,jj) - u_oce (ji,jj) ) * ( pu_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) - pu_ice(ji,jj) )
+
+                  ! tau_bottom/u_ice
+                  zvel  = MAX( zepsi, SQRT( v_iceU(ji,jj) * v_iceU(ji,jj) + pu_ice(ji,jj) * pu_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) * pv_ice(ji  ,jj) + e1v(ji  ,jj-1) * pv_ice(ji  ,jj-1) )  &
+                     &    + zmf(ji+1,jj) * ( e1v(ji+1,jj) * pv_ice(ji+1,jj) + e1v(ji+1,jj-1) * pv_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 ) ) )
+
+                  ! ice velocity using implicit formulation (cf Madec doc & Bouillon 2009)
+                  pu_ice(ji,jj) = ( (           rswitch   * ( zmU_t(ji,jj)  * pu_ice(ji,jj)                            &  ! previous velocity
+                     &                                      + zTauE + zTauO * pu_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 ) * pu_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
+                  !!pu_ice(ji,jj) = ( zmU_t(ji,jj) * ( zbeta * pu_ice(ji,jj) + pu_ice_b(ji,jj) )                  &
+                  !!   &           + zfU(ji,jj) + zCorx(ji,jj) + 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( pu_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( ( pu_ice(ji,jj) - u_oce (ji,jj) ) * ( pu_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) - pu_ice(ji,jj) )
+
+                  ! tau_bottom/u_ice
+                  zvel  = MAX( zepsi, SQRT( v_iceU(ji,jj) * v_iceU(ji,jj) + pu_ice(ji,jj) * pu_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) * pv_ice(ji  ,jj) + e1v(ji  ,jj-1) * pv_ice(ji  ,jj-1) )  &
+                     &    + zmf(ji+1,jj) * ( e1v(ji+1,jj) * pv_ice(ji+1,jj) + e1v(ji+1,jj-1) * pv_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 ) ) )
+
+                  ! ice velocity using implicit formulation (cf Madec doc & Bouillon 2009)
+                  pu_ice(ji,jj) = ( (           rswitch   * ( zmU_t(ji,jj)  * pu_ice(ji,jj)                            &  ! previous velocity
+                     &                                      + zTauE + zTauO * pu_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 ) * pu_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
+                  !!pu_ice(ji,jj) = ( zmU_t(ji,jj) * ( zbeta * pu_ice(ji,jj) + pu_ice_b(ji,jj) )                  &
+                  !!   &           + zfU(ji,jj) + zCorx(ji,jj) + 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( pu_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( ( pv_ice(ji,jj) - v_oce (ji,jj) ) * ( pv_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) - pv_ice(ji,jj) )
+
+                  ! tau_bottom/v_ice
+                  zvel  = MAX( zepsi, SQRT( pv_ice(ji,jj) * pv_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  ) * pu_ice(ji,jj  ) + e2u(ji-1,jj  ) * pu_ice(ji-1,jj  ) )  &
+                     &    + zmf(ji,jj+1) * ( e2u(ji,jj+1) * pu_ice(ji,jj+1) + e2u(ji-1,jj+1) * pu_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 (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)
+                  pv_ice(ji,jj) = ( (           rswitch   * ( zmV_t(ji,jj)  * pv_ice(ji,jj)                            &  ! previous velocity
+                     &                                      + zTauE + zTauO * pv_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 ) * pv_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
+                  !!pv_ice(ji,jj) = ( zmV_t(ji,jj) * ( zbeta * pv_ice(ji,jj) + pv_ice_b(ji,jj) )                  &
+                  !!   &           + zfV(ji,jj) + zCory(ji,jj) + 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( pv_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( pu_ice(:,jj) - zu_ice(:,jj) ), ABS( pv_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) = ( ( pu_ice(ji,jj+1) * r1_e1u(ji,jj+1) - pu_ice(ji,jj) * r1_e1u(ji,jj) ) * e1f(ji,jj) * e1f(ji,jj)   &
+               &         + ( pv_ice(ji+1,jj) * r1_e2v(ji+1,jj) - pv_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  = ( ( pu_ice(ji,jj) * r1_e2u(ji,jj) - pu_ice(ji-1,jj) * r1_e2u(ji-1,jj) ) * e2t(ji,jj) * e2t(ji,jj)   &
+               &   - ( pv_ice(ji,jj) * r1_e1v(ji,jj) - pv_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) * pu_ice(ji,jj) - e2u(ji-1,jj) * pu_ice(ji-1,jj)   &
+               &             + e1v(ji,jj) * pv_ice(ji,jj) - e1v(ji,jj-1) * pv_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 --- !
+      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('idive')  )   CALL iom_put( "idive"  , pdivu_i(:,:)   * zswi(:,:) )   ! divergence
+      IF( iom_use('ishear') )   CALL iom_put( "ishear" , 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 * pu_ice(ji,jj) * e2u(ji,jj) * rswitch
+               zfac_y = 0.5 * pv_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_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceforcing.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceforcing.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceforcing.F90	(revision 8534)
@@ -8,21 +8,21 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                  LIM 3.0 sea-ice model
+   !!   '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 ice            ! sea-ice: 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 usrdef_sbc     ! Surface boundary condition: user defined
    USE sbcblk         ! Surface boundary condition: bulk
    USE sbccpl         ! Surface boundary condition: coupled interface
-   USE icealb         ! ice albedo
+   USE icealb         ! sae-ice: albedo
    !
+   USE in_out_manager ! I/O manager
    USE iom            ! I/O manager library
-   USE in_out_manager ! I/O manager
-   USE lbclnk         ! lateral boundary condition - MPP link
    USE lib_mpp        ! MPP library
-   USE lib_fortran    !
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE lbclnk         ! lateral boundary conditions (or mpp links)
    USE timing         ! Timing
 
@@ -44,5 +44,5 @@
 
    SUBROUTINE ice_forcing_tau( kt, ksbc, utau_ice, vtau_ice )
-      !!---------------------------------------------------------------------
+      !!-------------------------------------------------------------------
       !!                  ***  ROUTINE ice_forcing_tau  ***
       !!
@@ -51,5 +51,5 @@
       !! ** 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, 
@@ -60,7 +60,7 @@
       INTEGER  ::   ji, jj                 ! dummy loop index
       REAL(wp), DIMENSION(jpi,jpj) ::   zutau_ice, zvtau_ice 
-      !!----------------------------------------------------------------------
-
-      IF( nn_timing == 1 )   CALL timing_start('ice_forcing_tau')
+      !!-------------------------------------------------------------------
+
+      IF( nn_timing == 1 )   CALL timing_start('ice_forcing')
 
       IF( kt == nit000 .AND. lwp ) THEN
@@ -87,5 +87,5 @@
       ENDIF
 
-      IF( nn_timing == 1 )   CALL timing_stop('ice_forcing_tau')
+      IF( nn_timing == 1 )   CALL timing_stop('ice_forcing')
       !
    END SUBROUTINE ice_forcing_tau
@@ -93,5 +93,5 @@
    
    SUBROUTINE ice_forcing_flx( kt, ksbc )
-      !!---------------------------------------------------------------------
+      !!-------------------------------------------------------------------
       !!                  ***  ROUTINE ice_forcing_flx  ***
       !!
@@ -112,5 +112,5 @@
       !!                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)
@@ -119,7 +119,7 @@
       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( nn_timing == 1 )   CALL timing_start('ice_forcing')
 
       IF( kt == nit000 .AND. lwp ) THEN
@@ -164,5 +164,5 @@
       ENDIF
       !
-      IF( nn_timing == 1 )   CALL timing_stop('ice_forcing_flx')
+      IF( nn_timing == 1 )   CALL timing_stop('ice_forcing')
       !
    END SUBROUTINE ice_forcing_flx
@@ -170,5 +170,5 @@
 
    SUBROUTINE ice_flx_dist( ptn_ice, palb_ice, pqns_ice, pqsr_ice, pdqn_ice, pevap_ice, pdevap_ice, k_iceflx )
-      !!---------------------------------------------------------------------
+      !!-------------------------------------------------------------------
       !!                  ***  ROUTINE ice_flx_dist  ***
       !!
@@ -184,5 +184,5 @@
       !!                                                 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
@@ -206,6 +206,4 @@
       REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   ztem_m    ! Mean temperature over all categories
       !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('ice_flx_dist')
       !
       WHERE ( at_i (:,:) > 0._wp )   ; z1_at_i(:,:) = 1._wp / at_i (:,:)
@@ -253,6 +251,4 @@
          !
       END SELECT
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('ice_flx_dist')
       !
    END SUBROUTINE ice_flx_dist
@@ -315,5 +311,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_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceistate.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceistate.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceistate.F90	(revision 8534)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                     ***  MODULE  iceistate  ***
-   !!              Initialisation of diagnostics ice variables
+   !!   sea-ice : Initialization of ice variables
    !!======================================================================
    !! History :  2.0  ! 2004-01 (C. Ethe, G. Madec)  Original code
@@ -12,10 +12,9 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                       LIM3 sea-ice model
+   !!   'key_lim3'                                       ESIM sea-ice model
    !!----------------------------------------------------------------------
    !!   ice_istate       :  initialization of diagnostics ice variables
    !!   ice_istate_init  :  initialization of ice state and namelist read
    !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
    USE phycst         ! physical constant
    USE oce            ! dynamics and tracers variables
@@ -29,8 +28,8 @@
    !
    USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
    USE lib_mpp        ! MPP library
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
    USE fldread        ! read input fields
-   USE iom
 
    IMPLICIT NONE
@@ -82,10 +81,10 @@
       !!                values in the namelist            
       !!
-      !! ** Steps   :   1) Read namelist
-      !!                2) Basal temperature; ice and hemisphere masks
+      !! ** 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) Diagnostic arrays
-      !!                6) Lateral boundary conditions
+      !!                5) snow-ice mass computation
+      !!                6) store before fields
       !!
       !! ** Notes   : o_i, t_su, t_s, t_i, s_i must be filled everywhere, even
@@ -109,5 +108,5 @@
 
       !--------------------------------------------------------------------
-      ! 1) Read namelist
+      ! 1) Set surface and bottom temperatures to initial values
       !--------------------------------------------------------------------
       !
@@ -122,11 +121,13 @@
       t_bo(:,:) = ( t_bo(:,:) + rt0 ) * tmask(:,:,1) 
 
-      !--------------------------------------------------------------------
-      ! 2) Initialization of sea ice state variables
-      !--------------------------------------------------------------------
       IF( ln_iceini ) THEN
+         !-----------------------------------------------------------
+         ! 2) Compute or read sea ice variables ===> single category
+         !-----------------------------------------------------------
          !
-         IF( ln_iceini_file )THEN
-         !
+         !                             !---------------!
+         IF( ln_iceini_file )THEN      ! Read a file   !
+            !                          !---------------!
+            !
             zht_i_ini(:,:)  = si(jp_hti)%fnow(:,:,1)
             zht_s_ini(:,:)  = si(jp_hts)%fnow(:,:,1)
@@ -139,18 +140,15 @@
             ELSEWHERE                       ; zswitch(:,:) = 0._wp
             END WHERE
+            zvt_i_ini(:,:) = zht_i_ini(:,:) * zat_i_ini(:,:)
             !
-         ELSE ! ln_iceini_file = F
-
-            !--------------------------------------------------------------------
-            ! 3) Basal temperature, ice mask
-            !--------------------------------------------------------------------
-            ! no ice if sst <= t-freez + ttest
+         !                             !---------------!
+         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
 
-            !-----------------------------
-            ! 3.1) Hemisphere-dependent arrays
-            !-----------------------------
             ! assign initial thickness, concentration, snow depth and salinity to an hemisphere-dependent array
             WHERE( ff_t(:,:) >= 0._wp )
@@ -169,11 +167,11 @@
                ztm_i_ini(:,:) = rn_tmi_ini_s * zswitch(:,:)
             END WHERE
+            zvt_i_ini(:,:) = zht_i_ini(:,:) * zat_i_ini(:,:)
             !
-         ENDIF ! ln_iceini_file
+         ENDIF
          
-         zvt_i_ini(:,:) = zht_i_ini(:,:) * zat_i_ini(:,:)   ! ice volume
-         !---------------------------------------------------------------------
-         ! 3.2) Distribute ice concentration and thickness into the categories
-         !---------------------------------------------------------------------
+         !------------------------------------------------------------------
+         ! 3) Distribute ice concentration and thickness into the categories
+         !------------------------------------------------------------------
          ! a gaussian distribution for ice concentration is used
          ! then we check whether the distribution fullfills
@@ -187,5 +185,5 @@
                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
+                  ! find which category (jl0) the input ice thickness falls into
                   jl0 = jpl
                   DO jl = 1, jpl
@@ -196,31 +194,24 @@
                   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                                               !====================================
+                  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
-
-                     ! 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
+                     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)
-
-                     ! *** case ice is thicker: fill categories >1
-                     ELSE
-
-                        ! Fill ice thicknesses in the (i_fill-1) cat by hmean 
+                     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
                         !
-                        !--- Concentrations
+                        ! concentration
                         za_i_ini(ji,jj,jl0) = zat_i_ini(ji,jj) / SQRT(REAL(jpl))
                         DO jl = 1, i_fill - 1
@@ -230,9 +221,7 @@
                            ENDIF
                         END DO
-                        !
-                        ! Concentration in the last (i_fill) category
+
+                        ! last 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 ) 
@@ -252,29 +241,23 @@
                         ENDIF
                         !
-                     ENDIF ! case ice is thick or thin
-
-                     !---------------------
+                     ENDIF
+
                      ! Compatibility tests
-                     !---------------------
-                     ! Test 1: area conservation
-                     zconv = ABS( zat_i_ini(ji,jj) - SUM( za_i_ini(ji,jj,1:jpl) ) )
+                     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
                      
-                     ! Test 2: volume conservation
-                     zconv = ABS(       zat_i_ini(ji,jj)       * zht_i_ini(ji,jj)   &
+                     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
                      
-                     ! 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
+                     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 ?
                      
-                     ! 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
+                        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
-                  !                                         !============================
+                     !                                                          !----------------------------
+                  END DO                                                        ! end iteration on categories
+                  !                                                             !----------------------------
                   !
                   IF( lwp .AND. SUM(itest) /= 4 ) THEN 
@@ -288,5 +271,5 @@
                   ENDIF
                
-               ENDIF !  zat_i_ini(ji,jj) > 0._wp .AND. zht_i_ini(ji,jj) > 0._wp
+               ENDIF
                !
             END DO   
@@ -294,5 +277,5 @@
 
          !---------------------------------------------------------------------
-         ! 3.3) Space-dependent arrays for ice state variables
+         ! 4) Fill in sea ice arrays
          !---------------------------------------------------------------------
 
@@ -426,14 +409,12 @@
          at_i (:,:) = at_i (:,:) + a_i (:,:,jl)
       END DO
-
-      !--------------------------------------------------------------------
-      ! 4) Global ice variables for output diagnostics                    | 
-      !--------------------------------------------------------------------
+      !
+      ! --- set ice velocities --- !
       u_ice (:,:)     = 0._wp
       v_ice (:,:)     = 0._wp
       !
-      !--------------------------------------------------------------------
-      ! Snow-ice mass (case ice is fully embedded)                    | 
-      !--------------------------------------------------------------------
+      !----------------------------------------------
+      ! 5) Snow-ice mass (case ice is fully embedded)
+      !----------------------------------------------
       snwice_mass  (:,:) = tmask(:,:,1) * ( rhosn * vt_s(:,:) + rhoic * vt_i(:,:)  )   ! snow+ice mass
       snwice_mass_b(:,:) = snwice_mass(:,:)
@@ -556,17 +537,17 @@
          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
+         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
 
@@ -595,5 +576,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_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceitd.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceitd.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceitd.F90	(revision 8534)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                       ***  MODULE iceitd ***
-   !!   LIM3 ice model : ice thickness distribution: Thermodynamics
+   !!   sea-ice : ice thickness distribution
    !!======================================================================
    !! History :   -   !          (W. H. Lipscomb and E.C. Hunke) CICE (c) original code
@@ -11,12 +11,10 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                       LIM3 sea-ice model
+   !!   'key_lim3'                                       ESIM sea-ice model
    !!----------------------------------------------------------------------
-   !!   ice_itd_rem   :
-   !!   ice_itd_reb   :
-   !!   ice_itd_glinear  :
-   !!   ice_itd_shiftice :
+   !!   ice_itd_init   : read ice thicknesses mean and min from namelist
+   !!   ice_itd_rem    : redistribute ice thicknesses after thermo growth and melt
+   !!   ice_itd_reb    : rebin ice thicknesses into bounded categories
    !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
    USE dom_oce        ! ocean domain
    USE phycst         ! physical constants 
@@ -26,8 +24,8 @@
    USE icetab         ! sea-ice: convert 1D<=>2D
    !
-   USE prtctl         ! Print control
    USE in_out_manager ! I/O manager
    USE lib_mpp        ! MPP library
-   USE lib_fortran    ! to use key_nosignedzero
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE prtctl         ! Print control
 
    IMPLICIT NONE
@@ -36,8 +34,8 @@
    PUBLIC   ice_itd_init  ! called in icestp
    PUBLIC   ice_itd_rem   ! called in icethd
-   PUBLIC   ice_itd_reb   ! called in iceerr
-
-   ! ** ice-thickness distribution namelist (namitd) **
-   REAL(wp) ::   rn_himean        ! mean thickness of the domain (used to compute the distribution)
+   PUBLIC   ice_itd_reb   ! called in icecor
+
+   ! ** namelist (namitd) **
+   REAL(wp) ::   rn_himean   ! mean thickness of the domain
 
    !!----------------------------------------------------------------------
@@ -53,9 +51,9 @@
       !!
       !! ** Purpose :   computes the redistribution of ice thickness
-      !!              after thermodynamic growth of ice thickness
-      !!
-      !! ** Method  : Linear remapping 
-      !!
-      !! References : W.H. Lipscomb, JGR 2001
+      !!                after thermodynamic growth of ice thickness
+      !!
+      !! ** Method  :   Linear remapping 
+      !!
+      !! References :   W.H. Lipscomb, JGR 2001
       !!------------------------------------------------------------------
       INTEGER , INTENT (in) ::   kt      ! Ocean time step 
@@ -696,5 +694,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option :         Empty module          NO LIM sea-ice model
+   !!   Default option :         Empty module         NO ESIM sea-ice model
    !!----------------------------------------------------------------------
 #endif
Index: anches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerdgrft.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerdgrft.F90	(revision 8533)
+++ 	(revision )
@@ -1,926 +1,0 @@
-MODULE icerdgrft
-   !!======================================================================
-   !!                       ***  MODULE icerdgrft ***
-   !! 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 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 icevar         ! sea-ice: operations
-   USE icectl         ! sea-ice: control prints
-   !
-   USE lbclnk         ! lateral boundary condition - MPP exchanges
-   USE lib_mpp        ! MPP library
-   USE in_out_manager ! I/O manager
-   USE iom            ! I/O manager
-   USE lib_fortran    ! glob_sum
-   USE timing         ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   ice_rdgrft        ! called by icestp
-   PUBLIC   ice_strength      ! called by icerhg_evp
-   PUBLIC   ice_rdgrft_init   ! called by icedyn
-
-   ! Variables shared among ridging subroutines
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   asum     ! sum of total ice and open water area
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   aksum    ! ratio of area removed to area ridged
-   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), 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)
-   REAL(wp)            ::   zdrho                   ! 
-   !
-   ! ** 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
-   LOGICAL  ::   ln_str_R75       ! ice strength parameterization (Rothrock75)
-   REAL(wp) ::   rn_perdg         ! ridging work divided by pot. energy change in ridging
-   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: icerdgrft.F90 8378 2017-07-26 13:55:59Z clem $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION ice_rdgrft_alloc()
-      !!---------------------------------------------------------------------!
-      !!                ***  ROUTINE ice_rdgrft_alloc ***
-      !!---------------------------------------------------------------------!
-      ALLOCATE( asum (jpi,jpj)     , apartf (jpi,jpj,0:jpl) , aksum (jpi,jpj)     ,     &
-         &      hrmin(jpi,jpj,jpl) , hraft  (jpi,jpj,jpl)   , aridge(jpi,jpj,jpl) ,     &
-         &      hrmax(jpi,jpj,jpl) , hi_hrdg(jpi,jpj,jpl)   , araft (jpi,jpj,jpl) , STAT=ice_rdgrft_alloc )
-
-      IF( lk_mpp                )   CALL mpp_sum ( ice_rdgrft_alloc )
-      IF( ice_rdgrft_alloc /= 0 )   CALL ctl_warn( 'ice_rdgrft_alloc: failed to allocate arrays' )
-      !
-   END FUNCTION ice_rdgrft_alloc
-
-
-   SUBROUTINE ice_rdgrft( kt )
-      !!---------------------------------------------------------------------!
-      !!                ***  ROUTINE ice_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  ::   niter              ! local integer 
-      INTEGER  ::   iterate_ridging    ! if =1, repeat the ridging
-      REAL(wp) ::   zfac               ! local scalar
-      REAL(wp), DIMENSION(jpi,jpj) ::   closing_net     ! net rate at which area is removed    (1/s)
-      !                                                 ! (ridging ice area - area of new ridges) / dt
-      REAL(wp), DIMENSION(jpi,jpj) ::   divu_adv        ! divu as implied by transport scheme  (1/s)
-      REAL(wp), DIMENSION(jpi,jpj) ::   opning          ! rate of opening due to divergence/shear
-      REAL(wp), DIMENSION(jpi,jpj) ::   closing_gross   ! rate at which area removed, not counting area of new ridges
-      !
-      INTEGER, PARAMETER ::   nitermax = 20    
-      !!-----------------------------------------------------------------------------
-      ! controls
-      IF( nn_timing == 1 )   CALL timing_start('icerdgrft')                                                             ! timing
-      IF( ln_icediachk   )   CALL ice_cons_hsm(0, 'icerdgrft', 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_rdgrft: ice ridging and rafting'
-         IF(lwp) WRITE(numout,*)'~~~~~~~~~~'
-         !
-         zdrho = 0.5 * grav * (rau0-rhoic) * rhoic * r1_rau0      ! proport const for PE
-         !
-      ENDIF      
-
-      !-----------------------------------------------------------------------------!
-      ! 1) Thickness categories boundaries, ice / o.w. concentrations, init_ons
-      !-----------------------------------------------------------------------------!
-      !
-      CALL rdgrft_prep                             ! 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_csrdg * 0.5_wp * ( 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.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
-         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
-               zfac   = ( opning(ji,jj) - apartf(ji,jj,0) * closing_gross(ji,jj) ) * rdt_ice
-               IF    ( zfac < 0._wp .AND. zfac > - ato_i(ji,jj) ) THEN                  ! would lead to negative ato_i
-                  opning(ji,jj) = apartf(ji,jj,0) * closing_gross(ji,jj) - ato_i(ji,jj) * r1_rdtice 
-               ELSEIF( zfac > 0._wp .AND. zfac > ( asum(ji,jj) - ato_i(ji,jj) ) ) THEN  ! would lead to ato_i > asum
-                  opning(ji,jj) = apartf(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
-                  zfac = apartf(ji,jj,jl) * closing_gross(ji,jj) * rdt_ice
-                  IF( zfac  >  a_i(ji,jj,jl) ) THEN
-                     closing_gross(ji,jj) = closing_gross(ji,jj) * a_i(ji,jj,jl) / zfac
-                  ENDIF
-               END DO
-            END DO
-         END DO
-
-         ! 3.2 Redistribute area, volume, and energy.
-         !-----------------------------------------------------------------------------!
-         CALL rdgrft_shift( opning, closing_gross )
-         
-         ! 3.3 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.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 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 rdgrft_prep
-            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 ice_var_agg( 1 ) 
-
-      ! controls
-      IF( ln_icediachk   )   CALL ice_cons_hsm(1, 'icerdgrft', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
-      IF( ln_ctl         )   CALL ice_prt3D   ('icerdgrft')                                                             ! prints
-      IF( nn_timing == 1 )   CALL timing_stop ('icerdgrft')                                                             ! timing
-      !
-   END SUBROUTINE ice_rdgrft
-
-
-   SUBROUTINE rdgrft_prep
-      !!---------------------------------------------------------------------!
-      !!                ***  ROUTINE rdgrft_prep ***
-      !!
-      !! ** 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) ::   z1_gstar, z1_astar, zhmean, zdummy   ! local scalar
-      REAL(wp), DIMENSION(jpi,jpj,-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    
-
-      CALL ice_var_zapsmall   ! Zero out categories with very small areas
-
-      !                       ! Ice thickness needed for rafting
-      WHERE( a_i(:,:,:) >= epsi20 )   ;   ht_i(:,:,:) = v_i (:,:,:) / a_i(:,:,:)
-      ELSEWHERE                       ;   ht_i(:,:,:) = 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
-      asum(:,:) = ato_i(:,:) + SUM( a_i, dim=3 )
-      !
-      ! 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) = 0._wp
-      zGsum(:,:,0 ) = ato_i(:,:) / asum(:,:)
-      DO jl = 1, jpl
-         zGsum(:,:,jl) = ( ato_i(:,:) + SUM( a_i(:,:,1:jl), dim=3 ) ) / asum(:,:) ! 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 jj = 1, jpj 
-               DO ji = 1, jpi
-                  IF    ( zGsum(ji,jj,jl)   < rn_gstar ) THEN
-                     apartf(ji,jj,jl) = z1_gstar * ( zGsum(ji,jj,jl) - zGsum(ji,jj,jl-1) ) * &
-                        &                          ( 2._wp - ( zGsum(ji,jj,jl-1) + zGsum(ji,jj,jl) ) * z1_gstar )
-                  ELSEIF( zGsum(ji,jj,jl-1) < rn_gstar ) THEN
-                     apartf(ji,jj,jl) = z1_gstar * ( rn_gstar        - zGsum(ji,jj,jl-1) ) *  &
-                        &                          ( 2._wp - ( zGsum(ji,jj,jl-1) + rn_gstar        ) * z1_gstar )
-                  ELSE
-                     apartf(ji,jj,jl) = 0._wp
-                  ENDIF
-               END DO
-            END DO
-         END DO
-         !
-      ELSEIF( ln_partf_exp ) THEN      !--- Exponential, more stable formulation (Lipscomb et al, 2007)
-         !                        
-         zdummy = 1._wp / ( 1._wp - EXP(-z1_astar) )        ! precompute exponential terms using zGsum as a work array
-         DO jl = -1, jpl
-            zGsum(:,:,jl) = EXP( -zGsum(:,:,jl) * z1_astar ) * zdummy
-         END DO
-         DO jl = 0, jpl
-            apartf(:,:,jl) = zGsum(:,:,jl-1) - zGsum(:,:,jl)
-         END DO
-         !
-      ENDIF
-
-      !                                !--- Ridging and rafting participation concentrations
-      IF( ln_rafting .AND. ln_ridging ) THEN             !- ridging & rafting
-         DO jl = 1, jpl
-            DO jj = 1, jpj 
-               DO ji = 1, jpi
-                  aridge(ji,jj,jl) = ( 1._wp + TANH ( rn_craft * ( ht_i(ji,jj,jl) - rn_hraft ) ) ) * 0.5_wp * apartf(ji,jj,jl)
-                  araft (ji,jj,jl) = apartf(ji,jj,jl) - aridge(ji,jj,jl)
-               END DO
-            END DO
-         END DO
-      ELSEIF( ln_ridging .AND. .NOT. ln_rafting ) THEN   !- ridging alone
-         aridge(:,:,:) = apartf(:,:,1:jpl)
-         araft (:,:,:) = 0._wp
-      ELSEIF( ln_rafting .AND. .NOT. ln_ridging ) THEN   !- rafting alone   
-        aridge(:,:,:) = 0._wp
-         araft (:,:,:) = apartf(:,:,1:jpl)
-      ELSE                                               !- no ridging & no rafting
-         aridge(:,:,:) = 0._wp
-         araft (:,:,:) = 0._wp         
-      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.
-      !
-      ! 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(:,:) = apartf(:,:,0)
-      zdummy = 1._wp / hi_hrft
-      ! Transfer function
-      DO jl = 1, jpl !all categories have a specific transfer function
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF ( apartf(ji,jj,jl) > 0._wp ) THEN
-                  zhmean            = MAX( SQRT( rn_hstar * ht_i(ji,jj,jl) ), ht_i(ji,jj,jl) * hrdg_hi_min )
-                  hrmin  (ji,jj,jl) = MIN( 2._wp * ht_i(ji,jj,jl), 0.5_wp * ( zhmean + ht_i(ji,jj,jl) ) )
-                  hrmax  (ji,jj,jl) = 2._wp * zhmean - hrmin(ji,jj,jl)
-                  hraft  (ji,jj,jl) = ht_i(ji,jj,jl) * zdummy
-                  hi_hrdg(ji,jj,jl) = ht_i(ji,jj,jl) / MAX( zhmean, epsi20 )
-                  !
-                  ! Normalization factor : aksum, ensures mass conservation
-                  aksum(ji,jj) = aksum(ji,jj) + aridge(ji,jj,jl) * ( 1._wp - hi_hrdg(ji,jj,jl) )    &
-                     &                        + araft (ji,jj,jl) * ( 1._wp - hi_hrft )
-               ELSE
-                  hrmin  (ji,jj,jl) = 0._wp 
-                  hrmax  (ji,jj,jl) = 0._wp 
-                  hraft  (ji,jj,jl) = 0._wp 
-                  hi_hrdg(ji,jj,jl) = 1._wp
-               ENDIF
-            END DO
-         END DO
-      END DO
-      !
-   END SUBROUTINE rdgrft_prep
-
-
-   SUBROUTINE rdgrft_shift( opning, closing_gross )
-      !!----------------------------------------------------------------------
-      !!                ***  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.
-      !!----------------------------------------------------------------------
-      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 retreats, excluding area of new ridges
-      !
-      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 and new area going to jl2
-
-      INTEGER , DIMENSION(jpij) ::   indxi, indxj     ! compressed indices
-      REAL(wp), DIMENSION(jpij) ::   zswitch, fvol    ! new ridge volume going to jl2
-
-      REAL(wp), DIMENSION(jpij) ::   afrac            ! fraction of category area ridged 
-      REAL(wp), DIMENSION(jpij) ::   ardg1 , ardg2    ! area of ice ridged & new ridges
-      REAL(wp), DIMENSION(jpij) ::   vsrdg , esrdg    ! snow volume & energy of ridging ice
-      ! MV MP 2016
-      REAL(wp), DIMENSION(jpij) ::   vprdg            ! pond volume of ridging ice
-      REAL(wp), DIMENSION(jpij) ::   aprdg1           ! pond area of ridging ice
-      REAL(wp), DIMENSION(jpij) ::   aprdg2           ! pond area of ridging ice
-      ! END MV MP 2016
-      REAL(wp), DIMENSION(jpij) ::   dhr, dhr2        ! hrmax - hrmin  &  hrmax^2 - hrmin^2
-
-      REAL(wp), DIMENSION(jpij) ::   vrdg1            ! volume of ice ridged
-      REAL(wp), DIMENSION(jpij) ::   vrdg2            ! volume of new ridges
-      REAL(wp), DIMENSION(jpij) ::   vsw              ! volume of seawater trapped into ridges
-      REAL(wp), DIMENSION(jpij) ::   srdg1            ! sal*volume of ice ridged
-      REAL(wp), DIMENSION(jpij) ::   srdg2            ! sal*volume of new ridges
-      REAL(wp), DIMENSION(jpij) ::   smsw             ! sal*volume of water trapped into ridges
-      REAL(wp), DIMENSION(jpij) ::   oirdg1, oirdg2   ! ice age of ice ridged
-
-      REAL(wp), DIMENSION(jpij) ::   afrft            ! fraction of category area rafted
-      REAL(wp), DIMENSION(jpij) ::   arft1 , arft2    ! area of ice rafted and new rafted zone
-      REAL(wp), DIMENSION(jpij) ::   virft , vsrft    ! ice & snow volume of rafting ice
-      ! MV MP 2016
-      REAL(wp), DIMENSION(jpij) ::   vprft            ! pond volume of rafting ice
-      REAL(wp), DIMENSION(jpij) ::   aprft1           ! pond area of rafted ice
-      REAL(wp), DIMENSION(jpij) ::   aprft2           ! pond area of new rafted ice
-      ! END MV MP 2016
-      REAL(wp), DIMENSION(jpij) ::   esrft , smrft    ! snow energy & salinity of rafting ice
-      REAL(wp), DIMENSION(jpij) ::   oirft1, oirft2   ! ice age of ice rafted
-
-      REAL(wp), DIMENSION(jpij,nlay_i) ::   eirft     ! ice energy of rafting ice
-      REAL(wp), DIMENSION(jpij,nlay_i) ::   erdg1     ! enth*volume of ice ridged
-      REAL(wp), DIMENSION(jpij,nlay_i) ::   erdg2     ! enth*volume of new ridges
-      REAL(wp), DIMENSION(jpij,nlay_i) ::   ersw      ! enth of water trapped into ridges
-      !!----------------------------------------------------------------------
-
-      !-------------------------------------------------------------------------------
-      ! 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) - apartf(ji,jj,0) * closing_gross(ji,jj) ) * rdt_ice )
-         END DO
-      END DO
-
-      !-----------------------------------------------------------------
-      ! 2) 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
-
-         !------------------------------------------------
-         ! 2.1) Identify grid cells with nonzero ridging
-         !------------------------------------------------
-         icells = 0
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( apartf(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)
-
-            !--------------------------------------------------------------------
-            ! 2.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
-
-            !---------------------------------------------------------------
-            ! 2.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) * hi_hrdg(ji,jj,jl1)
-            arft2(ij) = arft1(ij) * hi_hrft
-
-            !--------------------------------------------------------------------------
-            ! 2.4) Substract area, volume, and energy from ridging 
-            !     / rafting category n1.
-            !--------------------------------------------------------------------------
-            vrdg1(ij) = v_i(ji,jj,jl1) * afrac(ij)
-            vrdg2(ij) = vrdg1(ij) * ( 1. + rn_porordg )
-            vsw  (ij) = vrdg1(ij) * rn_porordg
-
-            vsrdg (ij) = v_s  (ji,jj,  jl1) * afrac(ij)
-            esrdg (ij) = e_s  (ji,jj,1,jl1) * afrac(ij)
-            !MV MP 2016
-            IF ( nn_pnd_scheme > 0 ) THEN
-               aprdg1(ij) = a_ip(ji,jj, jl1) * afrac(ij)
-               aprdg2(ij) = a_ip(ji,jj, jl1) * afrac(ij) * hi_hrdg(ji,jj,jl1)
-               vprdg(ij)  = v_ip(ji,jj, jl1) * afrac(ij)
-            ENDIF
-            ! END MV MP 2016
-            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) * hi_hrdg(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)
-            !MV MP 2016
-            IF ( nn_pnd_scheme > 0 ) THEN
-               aprft1(ij) = a_ip (ji,jj,  jl1) * afrft(ij)
-               aprft2(ij) = a_ip (ji,jj,  jl1) * afrft(ij) * hi_hrft
-               vprft(ij)  = v_ip(ji,jj,jl1)    * afrft(ij)
-            ENDIF
-            ! END MV MP 2016
-            srdg1 (ij) = smv_i(ji,jj,  jl1) * afrac(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) * hi_hrft 
-
-            !-----------------------------------------------------------------
-            ! 2.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
-
-            !------------------------------------------            
-            ! 2.6 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_dyn(ji,jj) = wfx_snw_dyn(ji,jj) + ( rhosn * vsrdg(ij) * ( 1._wp - rn_fsnwrdg )   & 
-               &                                      + rhosn * vsrft(ij) * ( 1._wp - rn_fsnwrft ) ) * r1_rdtice  ! fresh water source for ocean
-
-            hfx_dyn(ji,jj) = hfx_dyn(ji,jj) + ( - esrdg(ij) * ( 1._wp - rn_fsnwrdg )         & 
-               &                                - esrft(ij) * ( 1._wp - rn_fsnwrft ) ) * r1_rdtice        ! heat sink for ocean (<0, W.m-2)
-
-            ! MV MP 2016
-            !------------------------------------------            
-            ! 2.7 Put the melt pond water in the ocean
-            !------------------------------------------            
-            !  Place part of the melt pond volume into the ocean. 
-            IF ( ( nn_pnd_scheme > 0 ) .AND. ln_pnd_fw ) THEN
-               wfx_pnd(ji,jj) = wfx_pnd(ji,jj) + ( rhofw * vprdg(ij) * ( 1._wp - rn_fpndrdg )   & 
-               &                                 + rhofw * vprft(ij) * ( 1._wp - rn_fpndrft ) ) * r1_rdtice  ! fresh water source for ocean
-            ENDIF
-            ! END MV MP 2016
-
-            !-----------------------------------------------------------------
-            ! 2.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)
-
-            ! MV MP 2016
-            IF ( nn_pnd_scheme > 0 ) THEN
-               v_ip (ji,jj,jl1) = v_ip (ji,jj,jl1) - vprdg (ij) - vprft (ij)
-               a_ip (ji,jj,jl1) = a_ip (ji,jj,jl1) - aprdg1(ij) - aprft1(ij)
-            ENDIF
-            ! END MV MP 2016
-
-         END DO
-
-         !--------------------------------------------------------------------
-         ! 2.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
-
-         !-------------------------------------------------------------------------------
-         ! 3) 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
-!!gm see above               IF( hraft(ji,jj,jl1) <= hi_max(jl2) .AND. hraft(ji,jj,jl1) >  hi_max(jl2-1) ) THEN
-               IF( hi_max(jl2-1) < hraft(ji,jj,jl1) .AND. hraft(ji,jj,jl1) <= hi_max(jl2)  ) 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_fsnwrdg * fvol(ij)  +  &
-                  &                                        vsrft (ij) * rn_fsnwrft * zswitch(ij) )
-               e_s  (ji,jj,1,jl2) = e_s  (ji,jj,1,jl2) + ( esrdg (ij) * rn_fsnwrdg * fvol(ij)  +  &
-                  &                                        esrft (ij) * rn_fsnwrft * zswitch(ij) )
-               ! MV MP 2016
-               IF ( nn_pnd_scheme > 0 ) THEN
-                  v_ip (ji,jj,jl2) = v_ip(ji,jj,jl2) + (   vprdg (ij) * rn_fpndrdg * fvol   (ij)   &
-                     &                                   + vprft (ij) * rn_fpndrft * zswitch(ij)   )
-                  a_ip (ji,jj,jl2) = a_ip(ji,jj,jl2) + (   aprdg2(ij) * rn_fpndrdg * farea         & 
-                     &                                   + aprft2(ij) * rn_fpndrft * zswitch(ji)   )
-               ENDIF
-               ! END MV MP 2016
-            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)
-      !
-   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
-      !!----------------------------------------------------------------------
-
-      !                              !--------------------------------------------------!
-      CALL rdgrft_prep               ! Thickness distribution of ridging and ridged ice !
-      !                              !--------------------------------------------------!
-
-      !                              !--------------------------------------------------!
-      IF( ln_str_R75 ) THEN          ! Ice strength => Rothrock (1975) method           !
-      !                              !--------------------------------------------------!
-         z1_3 = 1._wp / 3._wp
-         DO jl = 1, jpl
-            WHERE( apartf(:,:,jl) > 0._wp )
-               strength(:,:) =  -         apartf(:,:,jl) * ht_i   (:,:,jl) * ht_i(:,:,jl)   &  ! PE loss from deforming ice
-                  &             + 2._wp * araft (:,:,jl) * ht_i   (:,:,jl) * ht_i(:,:,jl)   &  ! PE gain from rafting ice
-                  &             +         aridge(:,:,jl) * hi_hrdg(:,:,jl) * z1_3 *         &  ! PE gain from ridging ice
-                  &                      ( hrmax(:,:,jl) * hrmax  (:,:,jl) +                &
-                  &                        hrmin(:,:,jl) * hrmin  (:,:,jl) +                &
-                  &                        hrmax(:,:,jl) * hrmin  (:,:,jl) )
-            ELSEWHERE
-               strength(:,:) = 0._wp
-            END WHERE
-         END DO
-         strength(:,:) = rn_perdg * zdrho * strength(:,:) / aksum(:,:) * tmask(:,:,1)
-                         ! where zdrho = (g/2)*(rhow-rhoi)*(rhoi/rhow) and rn_perdg accounts for frictional dissipation
-         ismooth = 1
-      !                              !--------------------------------------------------!
-      ELSEIF( 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
-         !
-      ENDIF
-      !                              !--------------------------------------------------!
-      SELECT CASE( ismooth )         ! Smoothing ice strength                           !
-      !                              !--------------------------------------------------!
-      CASE( 1 )               !--- Spatial smoothing
-         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. )
-         !
-      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 ( ( asum(ji,jj) - ato_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_rdgrft_init
-      !!-------------------------------------------------------------------
-      !!                  ***  ROUTINE ice_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, &
-         &                    ln_str_R75, rn_perdg,          &
-         &                    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_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,*) '      ice strength parameterization Rothrock (1975)            ln_str_R75   = ', ln_str_R75 
-         WRITE(numout,*) '            Ratio of ridging work to PotEner change in ridging rn_perdg     = ', rn_perdg 
-         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_str_H79 .AND. ln_str_R75 ) .OR. ( .NOT.ln_str_H79 .AND. .NOT.ln_str_R75 ) ) THEN
-         CALL ctl_stop( 'ice_rdgrft_init: choose one and only one formulation for ice strength (ln_str_H79 or ln_str_R75)' )
-      ENDIF
-      !
-      IF ( ( ln_partf_lin .AND. ln_partf_exp ) .OR. ( .NOT.ln_partf_lin .AND. .NOT.ln_partf_exp ) ) THEN
-         CALL ctl_stop( 'ice_rdgrft_init: choose one and only one participation function (ln_partf_lin or ln_partf_exp)' )
-      ENDIF
-      !                              ! allocate tke arrays
-      IF( ice_rdgrft_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'ice_rdgrft_init: unable to allocate arrays' )
-      !
-  END SUBROUTINE ice_rdgrft_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Empty module          NO LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-
-   !!======================================================================
-END MODULE icerdgrft
Index: anches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerhg.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerhg.F90	(revision 8533)
+++ 	(revision )
@@ -1,151 +1,0 @@
-MODULE icerhg
-   !!======================================================================
-   !!                     ***  MODULE  icerhg  ***
-   !!   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
-   !!----------------------------------------------------------------------
-   !!    ice_rhg      : computes ice velocities
-   !!    ice_rhg_init : initialization and namelist read
-   !!----------------------------------------------------------------------
-   USE phycst         ! physical constants
-   USE dom_oce        ! ocean space and time domain
-   USE ice            ! sea-ice: variables
-   USE icerhg_evp     ! sea-ice: EVP rheology
-   USE icectl         ! sea-ice: control prints
-   !
-   USE lbclnk         ! lateral boundary conditions - MPP exchanges
-   USE lib_mpp        ! MPP library
-   USE in_out_manager ! I/O manager
-   USE lib_fortran    ! glob_sum
-   USE timing         ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   ice_rhg        ! called by icestp.F90
-   PUBLIC   ice_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: icerhg.F90 8378 2017-07-26 13:55:59Z clem $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE ice_rhg( kt )
-      !!-------------------------------------------------------------------
-      !!               ***  ROUTINE ice_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('icerhg')                                                             ! timing
-      IF( ln_icediachk   )   CALL ice_cons_hsm(0, 'icerhg', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
-      !
-      IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*)'ice_rhg: sea-ice rheology'
-         WRITE(numout,*)'~~~~~~~'
-      ENDIF
-
-      ! --------
-      ! Rheology
-      ! --------   
-      SELECT CASE( nice_rhg )
-      !                                !------------------------!
-      CASE( np_rhgEVP )                ! Elasto-Viscous-Plastic !
-         !                             !------------------------!
-         CALL ice_rhg_evp( kt, stress1_i, stress2_i, stress12_i, u_ice, v_ice, 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, 'icerhg', rdiag_v, rdiag_s, rdiag_t, rdiag_fv, rdiag_fs, rdiag_ft) ! conservation
-      IF( ln_ctl         )   CALL ice_prt3D   ('icerhg')                                                             ! prints
-      IF( nn_timing == 1 )   CALL timing_stop ('icerhg')                                                             ! timing
-      !
-   END SUBROUTINE ice_rhg
-
-   SUBROUTINE ice_rhg_init
-      !!-------------------------------------------------------------------
-      !!                  ***  ROUTINE ice_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, 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_rhg_init: ice parameters for ice dynamics '
-         WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) '   Namelist namdyn_rhg:'
-         WRITE(numout,*) '      rheology EVP (icerhg_evp)                            ln_rhg_EVP = ', ln_rhg_EVP
-         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_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_rhg_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Empty module          NO LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-#endif 
-
-   !!======================================================================
-END MODULE icerhg
Index: anches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerhg_evp.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerhg_evp.F90	(revision 8533)
+++ 	(revision )
@@ -1,888 +1,0 @@
-MODULE icerhg_evp
-   !!======================================================================
-   !!                     ***  MODULE  icerhg_evp  ***
-   !!   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 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
-   !!----------------------------------------------------------------------
-   !!   ice_rhg_evp       : computes ice velocities
-   !!----------------------------------------------------------------------
-   USE phycst         ! Physical constant
-   USE par_oce        ! Ocean parameters
-   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 icerdgrft      ! sea-ice: ice strength
-   !
-   USE lbclnk         ! Lateral Boundary Condition / MPP link
-   USE lib_mpp        ! MPP library
-   USE in_out_manager ! I/O manager
-   USE prtctl         ! Print control
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE iom            !
-#if defined key_agrif
-   USE agrif_lim3_interp
-#endif
-   USE bdy_oce   , ONLY: ln_bdy 
-   USE bdyice 
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   ice_rhg_evp   ! called by icerhg.F90
-   PUBLIC   rhg_evp_rst   ! called by icerhg.F90
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
-   !! $Id: icerhg_evp.F90 8378 2017-07-26 13:55:59Z clem $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE ice_rhg_evp( kt, pstress1_i, pstress2_i, pstress12_i, pu_ice, pv_ice, pshear_i, pdivu_i, pdelta_i )
-      !!-------------------------------------------------------------------
-      !!                 ***  SUBROUTINE ice_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   : 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, INTENT(in) ::   kt      ! time step
-      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pstress1_i, pstress2_i, pstress12_i
-      REAL(wp), DIMENSION(:,:), INTENT(  out) ::   pu_ice, pv_ice, 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) ::   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, 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) ::   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_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
-      !
-      !------------------------------------------------------------------------------!
-      ! 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)
-      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 (:,:) = 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)
-
-            ! 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) = pu_ice(:,jj) ! velocity at previous time step
-               zv_ice(:,jj) = pv_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) = ( ( pu_ice(ji,jj+1) * r1_e1u(ji,jj+1) - pu_ice(ji,jj) * r1_e1u(ji,jj) ) * e1f(ji,jj) * e1f(ji,jj)   &
-                  &         + ( pv_ice(ji+1,jj) * r1_e2v(ji+1,jj) - pv_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) * pu_ice(ji,jj) - e2u(ji-1,jj) * pu_ice(ji-1,jj)   &
-                  &    + e1v(ji,jj) * pv_ice(ji,jj) - e1v(ji,jj-1) * pv_ice(ji,jj-1)   &
-                  &    ) * r1_e1e2t(ji,jj)
-               zdiv2 = zdiv * zdiv
-               
-               ! tension at T points
-               zdt  = ( ( pu_ice(ji,jj) * r1_e2u(ji,jj) - pu_ice(ji-1,jj) * r1_e2u(ji-1,jj) ) * e2t(ji,jj) * e2t(ji,jj)   &
-                  &   - ( pv_ice(ji,jj) * r1_e1v(ji,jj) - pv_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 * ( ( pu_ice(ji,jj  ) + pu_ice(ji-1,jj  ) ) * e2t(ji,jj+1)     &
-                  &                     + ( pu_ice(ji,jj+1) + pu_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 * ( ( pv_ice(ji  ,jj) + pv_ice(ji  ,jj-1) ) * e1t(ji+1,jj)     &
-                  &                     + ( pv_ice(ji+1,jj) + pv_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) == 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( ( pv_ice(ji,jj) - v_oce (ji,jj) ) * ( pv_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) - pv_ice(ji,jj) )
-                     !
-                     !                 !--- tau_bottom/v_ice
-                  zvel  = MAX( zepsi, SQRT( pv_ice(ji,jj) * pv_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  ) * pu_ice(ji,jj  ) + e2u(ji-1,jj  ) * pu_ice(ji-1,jj  ) )  &
-                     &    + zmf(ji,jj+1) * ( e2u(ji,jj+1) * pu_ice(ji,jj+1) + e2u(ji-1,jj+1) * pu_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 ) ) )
-                     !
-                     !                 !--- ice velocity using implicit formulation (cf Madec doc & Bouillon 2009)
-                  pv_ice(ji,jj) = ( (           rswitch   * ( zmV_t(ji,jj)  * pv_ice(ji,jj)                            &  ! previous velocity
-                     &                                      + zTauE + zTauO * pv_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 ) * pv_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
-                  !!pv_ice(ji,jj) = ( zmV_t(ji,jj) * ( zbeta * pv_ice(ji,jj) + pv_ice_b(ji,jj) )                  &
-                  !!   &           + zfV(ji,jj) + zCory(ji,jj) + 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( pv_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( ( pu_ice(ji,jj) - u_oce (ji,jj) ) * ( pu_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) - pu_ice(ji,jj) )
-
-                  ! tau_bottom/u_ice
-                  zvel  = MAX( zepsi, SQRT( v_iceU(ji,jj) * v_iceU(ji,jj) + pu_ice(ji,jj) * pu_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) * pv_ice(ji  ,jj) + e1v(ji  ,jj-1) * pv_ice(ji  ,jj-1) )  &
-                     &    + zmf(ji+1,jj) * ( e1v(ji+1,jj) * pv_ice(ji+1,jj) + e1v(ji+1,jj-1) * pv_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 ) ) )
-
-                  ! ice velocity using implicit formulation (cf Madec doc & Bouillon 2009)
-                  pu_ice(ji,jj) = ( (           rswitch   * ( zmU_t(ji,jj)  * pu_ice(ji,jj)                            &  ! previous velocity
-                     &                                      + zTauE + zTauO * pu_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 ) * pu_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
-                  !!pu_ice(ji,jj) = ( zmU_t(ji,jj) * ( zbeta * pu_ice(ji,jj) + pu_ice_b(ji,jj) )                  &
-                  !!   &           + zfU(ji,jj) + zCorx(ji,jj) + 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( pu_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( ( pu_ice(ji,jj) - u_oce (ji,jj) ) * ( pu_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) - pu_ice(ji,jj) )
-
-                  ! tau_bottom/u_ice
-                  zvel  = MAX( zepsi, SQRT( v_iceU(ji,jj) * v_iceU(ji,jj) + pu_ice(ji,jj) * pu_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) * pv_ice(ji  ,jj) + e1v(ji  ,jj-1) * pv_ice(ji  ,jj-1) )  &
-                     &    + zmf(ji+1,jj) * ( e1v(ji+1,jj) * pv_ice(ji+1,jj) + e1v(ji+1,jj-1) * pv_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 ) ) )
-
-                  ! ice velocity using implicit formulation (cf Madec doc & Bouillon 2009)
-                  pu_ice(ji,jj) = ( (           rswitch   * ( zmU_t(ji,jj)  * pu_ice(ji,jj)                            &  ! previous velocity
-                     &                                      + zTauE + zTauO * pu_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 ) * pu_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
-                  !!pu_ice(ji,jj) = ( zmU_t(ji,jj) * ( zbeta * pu_ice(ji,jj) + pu_ice_b(ji,jj) )                  &
-                  !!   &           + zfU(ji,jj) + zCorx(ji,jj) + 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( pu_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( ( pv_ice(ji,jj) - v_oce (ji,jj) ) * ( pv_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) - pv_ice(ji,jj) )
-
-                  ! tau_bottom/v_ice
-                  zvel  = MAX( zepsi, SQRT( pv_ice(ji,jj) * pv_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  ) * pu_ice(ji,jj  ) + e2u(ji-1,jj  ) * pu_ice(ji-1,jj  ) )  &
-                     &    + zmf(ji,jj+1) * ( e2u(ji,jj+1) * pu_ice(ji,jj+1) + e2u(ji-1,jj+1) * pu_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 (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)
-                  pv_ice(ji,jj) = ( (           rswitch   * ( zmV_t(ji,jj)  * pv_ice(ji,jj)                            &  ! previous velocity
-                     &                                      + zTauE + zTauO * pv_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 ) * pv_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
-                  !!pv_ice(ji,jj) = ( zmV_t(ji,jj) * ( zbeta * pv_ice(ji,jj) + pv_ice_b(ji,jj) )                  &
-                  !!   &           + zfV(ji,jj) + zCory(ji,jj) + 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( pv_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( pu_ice(:,jj) - zu_ice(:,jj) ), ABS( pv_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) = ( ( pu_ice(ji,jj+1) * r1_e1u(ji,jj+1) - pu_ice(ji,jj) * r1_e1u(ji,jj) ) * e1f(ji,jj) * e1f(ji,jj)   &
-               &         + ( pv_ice(ji+1,jj) * r1_e2v(ji+1,jj) - pv_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  = ( ( pu_ice(ji,jj) * r1_e2u(ji,jj) - pu_ice(ji-1,jj) * r1_e2u(ji-1,jj) ) * e2t(ji,jj) * e2t(ji,jj)   &
-               &   - ( pv_ice(ji,jj) * r1_e1v(ji,jj) - pv_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) * pu_ice(ji,jj) - e2u(ji-1,jj) * pu_ice(ji-1,jj)   &
-               &             + e1v(ji,jj) * pv_ice(ji,jj) - e1v(ji,jj-1) * pv_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 --- !
-      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('idive')  )   CALL iom_put( "idive"  , pdivu_i(:,:)   * zswi(:,:) )   ! divergence
-      IF( iom_use('ishear') )   CALL iom_put( "ishear" , 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 * pu_ice(ji,jj) * e2u(ji,jj) * rswitch
-               zfac_y = 0.5 * pv_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_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 LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-
-   !!==============================================================================
-END MODULE icerhg_evp
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerst.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerst.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerst.F90	(revision 8534)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                     ***  MODULE  icerst  ***
-   !! Ice restart :  write the ice restart file
+   !!   sea-ice :  write/read the ice restart file
    !!======================================================================
    !! History:   3.0  ! 2005-04 (M. Vancoppenolle) Original code
@@ -10,9 +10,9 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                        LIM sea-ice model
-   !!----------------------------------------------------------------------
-   !!   ice_rst_opn   : open ice restart file
-   !!   ice_rst_write : write of the restart file 
-   !!   ice_rst_read  : read  the restart file 
+   !!   '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
@@ -22,7 +22,8 @@
    !
    USE in_out_manager ! I/O manager
-   USE iom            ! I/O library
+   USE iom            ! I/O manager library
    USE lib_mpp        ! MPP library
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -44,5 +45,5 @@
       !!                    ***  ice_rst_opn  ***
       !!
-      !! ** purpose  :   output of sea-ice variable in a netcdf file
+      !! ** purpose  :   open restart file
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt       ! number of iteration
@@ -95,5 +96,5 @@
       !!                    ***  ice_rst_write  ***
       !!
-      !! ** purpose  :   output of sea-ice variable in a netcdf file
+      !! ** purpose  :   write restart file
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt     ! number of iteration
@@ -105,4 +106,6 @@
       REAL(wp), DIMENSION(jpi,jpj) :: z2d
       !!----------------------------------------------------------------------
+
+      IF( nn_timing == 1 )   CALL timing_start('ice_rst')
 
       iter = kt + nn_fsbc - 1   ! ice restarts are written at kt == nitrst - nn_fsbc + 1
@@ -184,4 +187,5 @@
       ENDIF
       !
+      IF( nn_timing == 1 ) CALL timing_stop('ice_rst')
       !
    END SUBROUTINE ice_rst_write
@@ -192,5 +196,5 @@
       !!                    ***  ice_rst_read  ***
       !!
-      !! ** purpose  :   read of sea-ice variable restart in a netcdf file
+      !! ** purpose  :   read restart file
       !!----------------------------------------------------------------------
       INTEGER  :: jk, jl
@@ -202,4 +206,6 @@
       LOGICAL           ::   llok
       !!----------------------------------------------------------------------
+
+      IF( nn_timing == 1 )   CALL timing_start('ice_rst')
 
       IF(lwp) THEN
@@ -279,9 +285,11 @@
       CALL iom_get( numrir, jpdom_autoglo, 'v_ice', v_ice )
 
+      IF( nn_timing == 1 ) CALL timing_stop('ice_rst')
+
    END SUBROUTINE ice_rst_read
 
 #else
    !!----------------------------------------------------------------------
-   !!   Default option :       Empty module            NO LIM sea-ice model
+   !!   Default option :       Empty module           NO ESIM sea-ice model
    !!----------------------------------------------------------------------
 #endif
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icestp.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icestp.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icestp.F90	(revision 8534)
@@ -3,6 +3,5 @@
    !!                       ***  MODULE  icestp  ***
    !! 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
+   !!                   covered area using ESIM sea-ice model
    !!=====================================================================
    !! History :  2.0  ! 2006-12  (M. Vancoppenolle) Original code
@@ -17,9 +16,8 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                    LIM 3.0 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   ice_stp       : sea-ice model time-stepping and update ocean surf. boundary cond. over ice-covered area
-   !!   ice_init      :
-   !!   ice_run_init  : 
+   !!   '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
@@ -29,27 +27,21 @@
    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 phycst         ! Define parameters for the routines
-   USE eosbn2         ! equation of state
-   USE icerhg         ! sea-ice: rheology
-   USE iceadv         ! sea-ice: advection
    USE icedyn         ! sea-ice: dynamics
    USE icethd         ! sea-ice: thermodynamics
-   USE icerdgrft      ! sea-ice: ridging/rafting
+   USE limmp          ! sea-ice: melt ponds
+   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 icecor         ! sea-ice: corrections
    USE icevar         ! sea-ice: operations
    USE icectl         ! sea-ice: control
-   ! MV MP 2016
-   USE limmp          ! sea-ice: melt ponds
-   ! END MV MP 2016
    USE iceistate      ! sea-ice: initial state
-   USE icethd_sal     ! sea-ice: thermodynamics and salinity
    USE iceitd         ! sea-ice: remapping thickness distribution
    USE icealb         ! sea-ice: albedo
@@ -65,9 +57,8 @@
    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
-   USE lib_fortran    ! 
-   USE lbclnk         ! lateral boundary condition - MPP link
-   USE lib_mpp        ! MPP library
-   USE timing         ! Timing
 
    IMPLICIT NONE
@@ -202,12 +193,12 @@
 !!         IF( .NOT. Agrif_Root() )   CALL Agrif_ParentGrid_To_ChildGrid()
 !!# endif
-         IF( ln_icediahsb )         CALL ice_dia( kt )        ! -- Diagnostics and outputs 
-         !
-                                    CALL ice_wri( 1 )         ! -- 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
+         IF( ln_icediahsb )         CALL ice_dia( kt )          ! -- Diagnostics and outputs 
+         !
+                                    CALL ice_wri( 1 )           ! -- 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
@@ -230,5 +221,5 @@
       !!                  ***  ROUTINE ice_init  ***
       !!
-      !! ** purpose :   Allocate all the dynamic arrays of the LIM-3 modules
+      !! ** purpose :   Initialize sea-ice parameters
       !!----------------------------------------------------------------------
       INTEGER :: ji, jj, ierr
@@ -265,6 +256,6 @@
          CALL ice_rst_read
       ENDIF
+      CALL ice_var_glo2eqv
       CALL ice_var_agg(2)
-      CALL ice_var_glo2eqv
       !
       CALL ice_forcing_init            ! set ice-ocean and ice-atm. coupling parameters
@@ -301,7 +292,7 @@
       !!                  ***  ROUTINE par_init ***
       !!
-      !! ** Purpose :   Definition some run parameter for ice model
-      !!
-      !! ** Method  :   Read the nampar namelist and check the parameter
+      !! ** Purpose :   Definition generic parameters for ice model
+      !!
+      !! ** Method  :   Read namelist and check the parameter
       !!                values called at the first timestep (nit000)
       !!
@@ -444,5 +435,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option           Dummy module      NO LIM 3.0 sea-ice model
+   !!   Default option           Dummy module         NO ESIM sea-ice model
    !!----------------------------------------------------------------------
 CONTAINS
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icetab.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icetab.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icetab.F90	(revision 8534)
@@ -2,10 +2,12 @@
    !!======================================================================
    !!                       ***  MODULE icetab   ***
-   !!   LIM ice model : transform 1D (2D) array to a 2D (1D) table
+   !!   sea-ice : transform 1D (2D) array to a 2D (1D) table
    !!======================================================================
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!   '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
@@ -111,5 +113,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option           Dummy module      NO LIM 3.0 sea-ice model
+   !!   Default option           Dummy module         NO ESIM sea-ice model
    !!----------------------------------------------------------------------
 #endif
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd.F90	(revision 8534)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                  ***  MODULE icethd   ***
-   !!  LIM-3 :   ice thermodynamic
+   !!   sea-ice : master routine for thermodynamics
    !!======================================================================
    !! History :  LIM  ! 2000-01 (M.A. Morales Maqueda, H. Goosse, T. Fichefet) LIM-1
@@ -15,32 +15,32 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                       LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   ice_thd       : thermodynamic of sea ice
-   !!   ice_thd_init  : initialisation of sea-ice thermodynamic
+   !!   '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
+   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, &
       &                 fr1_i0, fr2_i0
-   USE ice1D          ! thermodynamic sea-ice variables
-   USE icethd_zdf     ! vertical diffusion
-   USE icethd_dh      ! ice-snow growth and melt
-   USE icethd_da      ! lateral melting
-   USE icethd_sal     ! ice salinity
-   USE icethd_ent     ! ice enthalpy redistribution
-   USE icethd_do      ! lateral accretion
-   USE iceitd         ! remapping thickness distribution
-   USE icetab         ! 1D <==> 2D transformation
-   USE icevar         !
-   USE icectl         ! control print
+   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 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 lbclnk         ! lateral boundary condition - MPP links
    USE lib_mpp        ! MPP library
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE lbclnk         ! lateral boundary conditions (or mpp links)
    USE timing         ! Timing
 
@@ -84,4 +84,6 @@
       !!             - 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
@@ -578,5 +580,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option         Dummy module          NO  LIM3 sea-ice model
+   !!   Default option         Dummy module          NO  ESIM sea-ice model
    !!----------------------------------------------------------------------
 #endif
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_da.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_da.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_da.F90	(revision 8534)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                       ***  MODULE icethd_da ***
-   !! LIM-3 sea-ice :  computation of lateral melting in the ice
+   !!   sea-ice : lateral melting
    !!======================================================================
    !! History :  4.0  ! 2016-03 (C. Rousset)  original code
@@ -8,7 +8,8 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   ice_thd_da    : sea ice lateral melting
+   !!   '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
@@ -195,5 +196,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option         Dummy Module          No LIM-3 sea-ice model
+   !!   Default option         Dummy Module           NO ESIM sea-ice model
    !!----------------------------------------------------------------------
 #endif
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_dh.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_dh.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_dh.F90	(revision 8534)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                       ***  MODULE icethd_dh ***
-   !!  LIM-3 :   thermodynamic growth and decay of the ice 
+   !!   seaice : thermodynamic growth and melt 
    !!======================================================================
    !! History :  LIM  ! 2003-05 (M. Vancoppenolle) Original code in 1D
@@ -12,23 +12,24 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                       LIM3 sea-ice model
+   !!   'key_lim3'                                       ESIM sea-ice model
    !!----------------------------------------------------------------------
-   !!   ice_thd_dh    : vertical accr./abl. and lateral ablation of sea ice
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-   USE phycst         ! physical constants (OCE directory) 
-   USE ice            ! LIM variables
-   USE ice1D          ! LIM thermodynamics
+   !!   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 (allows no signed zero when 'key_nosignedzero' defined)  
+   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
+   PUBLIC   ice_thd_dh        ! called by ice_thd
+   PUBLIC   ice_thd_snwblow   ! called in sbcblk/sbcclio/sbccpl and here
 
    INTERFACE ice_thd_snwblow
@@ -47,5 +48,5 @@
       !!                ***  ROUTINE ice_thd_dh  ***
       !!
-      !! ** Purpose :   determines variations of ice and snow thicknesses.
+      !! ** Purpose :   compute ice and snow thickness changes due to growing/melting
       !!
       !! ** Method  :   Ice/Snow surface melting arises from imbalance in surface fluxes
@@ -679,5 +680,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option                               NO  LIM3 sea-ice model
+   !!   Default option                                NO ESIM sea-ice model
    !!----------------------------------------------------------------------
 #endif
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_do.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_do.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_do.F90	(revision 8534)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                       ***  MODULE icethd_do   ***
-   !!                lateral thermodynamic growth of the ice 
+   !!   sea-ice: sea ice growth in the leads (open water)  
    !!======================================================================
    !! History :  LIM  ! 2005-12 (M. Vancoppenolle)  Original code
@@ -11,14 +11,14 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                       LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   ice_thd_do   : ice growth in open water (=lateral accretion of ice)
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-   USE dom_oce        ! domain variables
+   !!   '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
+   USE ice1D          ! sea-ice: thermodynamics variables
    USE ice            ! sea-ice: variables
    USE icetab         ! sea-ice: 2D <==> 1D
@@ -30,6 +30,6 @@
    USE in_out_manager ! I/O manager
    USE lib_mpp        ! MPP library
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE lbclnk         ! lateral boundary conditions (or mpp links)
 
    IMPLICIT NONE
@@ -59,5 +59,4 @@
       !! ** 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
@@ -495,5 +494,5 @@
       !!                 
       !! ** Purpose :   Physical constants and parameters associated with
-      !!                ice thermodynamics
+      !!                ice growth in the leads
       !!
       !! ** Method  :   Read the namthd_do namelist and check the parameters
@@ -534,5 +533,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option                               NO  LIM3 sea-ice model
+   !!   Default option                                NO ESIM sea-ice model
    !!----------------------------------------------------------------------
 #endif
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_ent.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_ent.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_ent.F90	(revision 8534)
@@ -2,7 +2,6 @@
    !!======================================================================
    !!                       ***  MODULE icethd_ent   ***
-   !!                  Redistribution of Enthalpy in the ice
-   !!                        on the new vertical grid
-   !!                       after vertical growth/decay
+   !!   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
@@ -15,14 +14,13 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                       LIM3 sea-ice model
+   !!   'key_lim3'                                       ESIM sea-ice model
    !!----------------------------------------------------------------------
    !!   ice_thd_ent   : ice redistribution of enthalpy
    !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
    USE dom_oce        ! domain variables
    USE domain         !
    USE phycst         ! physical constants
-   USE ice            ! LIM variables
-   USE ice1D          ! LIM thermodynamics
+   USE ice            ! sea-ice: variables
+   USE ice1D          ! sea-ice: thermodynamics variables
    !
    USE in_out_manager ! I/O manager
@@ -67,12 +65,12 @@
       !! References : Bitz & Lipscomb, JGR 99; Vancoppenolle et al., GRL, 2005
       !!-------------------------------------------------------------------
-      REAL(wp), INTENT(inout), DIMENSION(:,:) :: qnew          ! new enthlapies (J.m-3, remapped)
-
+      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
+      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
       !!-------------------------------------------------------------------
 
@@ -141,5 +139,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option                               NO  LIM3 sea-ice model
+   !!   Default option                                NO ESIM sea-ice model
    !!----------------------------------------------------------------------
 #endif
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_sal.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_sal.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_sal.F90	(revision 8534)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                       ***  MODULE icethd_sal ***
-   !! LIM-3 sea-ice :  computation of salinity variations in the ice
+   !!   sea-ice : computation of salinity variations in the ice
    !!======================================================================
    !! History :   -   ! 2003-05 (M. Vancoppenolle) UCL-ASTR first coding for LIM3-1D
@@ -10,17 +10,18 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM-3 sea-ice model
+   !!   'key_lim3'                                       ESIM sea-ice model
    !!----------------------------------------------------------------------
-   !!   ice_thd_sal   : salinity variations in the ice
+   !!   ice_thd_sal        : salinity variations in the ice
+   !!   ice_thd_sal_init   : initialization
    !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-   USE phycst         ! physical constants (ocean directory)
-   USE ice            ! LIM variables
-   USE ice1D          ! LIM thermodynamics
-   USE icevar         ! LIM variables
+   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 (allows no signed zero when 'key_nosignedzero' defined)  
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
 
    IMPLICIT NONE
@@ -153,5 +154,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option         Dummy Module          No LIM-3 sea-ice model
+   !!   Default option         Dummy Module           No ESIM sea-ice model
    !!----------------------------------------------------------------------
 #endif
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_zdf.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_zdf.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_zdf.F90	(revision 8534)
@@ -2,6 +2,5 @@
    !!======================================================================
    !!                       ***  MODULE icethd_zdf ***
-   !!                       heat diffusion in sea ice 
-   !!                   computation of surface and inner T  
+   !!   sea-ice: vertical heat diffusion in sea ice (computation of temperatures) 
    !!======================================================================
    !! History :  LIM  ! 02-2003 (M. Vancoppenolle) original 1D code
@@ -14,20 +13,20 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!   'key_lim3'                                       ESIM sea-ice model
    !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
+   USE dom_oce        ! ocean space and time domain
    USE phycst         ! physical constants (ocean directory) 
    USE ice            ! sea-ice: variables
-   USE ice1D          ! sea-ice: thermodynamics
+   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)  
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   ice_thd_zdf        ! called by ice_thd
-   PUBLIC   ice_thd_zdf_init   ! called by ice_stp
+   PUBLIC   ice_thd_zdf        ! called by icethd
+   PUBLIC   ice_thd_zdf_init   ! called by icestp
 
    !!** namelist (namthd_zdf) **
@@ -47,5 +46,5 @@
 
    SUBROUTINE ice_thd_zdf
-      !!------------------------------------------------------------------
+      !!-------------------------------------------------------------------
       !!                ***  ROUTINE ice_thd_zdf  ***
       !! ** Purpose :
@@ -63,9 +62,9 @@
       !!
       !!           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
+      !!           1.  initialization of ice-snow layers thicknesses
+      !!           2.  Internal absorbed and transmitted radiation
+      !!           Then iterative procedure begins
+      !!           3.  Thermal conductivity
       !!           4.  Kappa factors
-      !!           Then iterative procedure begins
       !!           5.  specific heat in the ice
       !!           6.  eta factors
@@ -75,4 +74,5 @@
       !!           Iterative procedure ends according to a criterion on evolution
       !!           of temperature
+      !!           10. Fluxes at the interfaces
       !!
       !! ** Inputs / Ouputs : (global commons)
@@ -82,5 +82,5 @@
       !!           number of layers in the ice/snow: nlay_i, nlay_s
       !!           total ice/snow thickness : ht_i_1d, ht_s_1d
-      !!------------------------------------------------------------------
+      !!-------------------------------------------------------------------
       INTEGER ::   ji, jk         ! spatial loop index
       INTEGER ::   numeq          ! current reference number of equation
@@ -149,7 +149,7 @@
       END DO
 
-      !------------------------------------------------------------------------------!
-      ! 1) Initialization                                                            !
-      !------------------------------------------------------------------------------!
+      !------------------
+      ! 1) Initialization
+      !------------------
       DO ji = 1, nidx
          isnow(ji)= 1._wp - MAX( 0._wp , SIGN(1._wp, - ht_s_1d(ji) ) )  ! is there snow or not
@@ -173,13 +173,11 @@
       t_su_1d(1:nidx)   = MIN( t_su_1d(1:nidx), rt0 - ztsu_err )   ! necessary
       !
-      !------------------------------------------------------------------------------|
-      ! 2) Radiation	                                                             |
-      !------------------------------------------------------------------------------|
+      !-------------
+      ! 2) Radiation
+      !-------------
       !
       z1_hsu = 1._wp / 0.1_wp ! threshold for the computation of i0
       DO ji = 1, nidx
-         !-------------------
-         ! Computation of i0
-         !-------------------
+         ! --- 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.
@@ -193,8 +191,6 @@
          i0(ji) = ( 1._wp - isnow(ji) ) * ( fr1_i0_1d(ji) + zfac * fr2_i0_1d(ji) )
 
-         !-------------------------------------------------------
-         ! Solar radiation absorbed / transmitted at the surface
-         ! Derivative of the non solar flux
-         !-------------------------------------------------------
+         ! --- Solar radiation absorbed / transmitted at the surface --- !
+         !     Derivative of the non solar flux
          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
@@ -203,7 +199,5 @@
       END DO
 
-      !---------------------------------------------------------
-      ! Transmission - absorption of solar radiation in the ice
-      !---------------------------------------------------------
+      ! --- Transmission/absorption of solar radiation in the ice --- !
       zradtr_s(1:nidx,0) = zftrice(1:nidx)
       DO jk = 1, nlay_s
@@ -227,12 +221,10 @@
 
       ftr_ice_1d(1:nidx) = zradtr_i(1:nidx,nlay_i)   ! record radiation transmitted below the ice
-
-      !------------------------------------------------------------------------------|
-      !  3) Iterative procedure begins                                               |
-      !------------------------------------------------------------------------------|
       !
       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 )
+      !                                                          !----------------------------!
+      DO WHILE ( zdti_max > zdti_bnd .AND. iconv < iconv_max )   ! Iterative procedure begins !
+         !                                                       !----------------------------!
          !
          iconv = iconv + 1
@@ -241,8 +233,7 @@
          ztsb(1:nidx,:) = t_s_1d(1:nidx,:)
          !
-         !------------------------------------------------------------------------------|
-         ! 4) Sea ice thermal conductivity                                              |
-         !------------------------------------------------------------------------------|
-         !
+         !--------------------------------
+         ! 3) Sea ice thermal conductivity
+         !--------------------------------
          IF( ln_cndi_U64 ) THEN         !-- Untersteiner (1964) formula: k = k0 + beta.S/T
             !
@@ -277,8 +268,5 @@
          ztcond_i(1:nidx,:) = MAX( zkimin, ztcond_i(1:nidx,:) )        
          !
-         !------------------------------------------------------------------------------|
-         !  5) G(he) - enhancement of thermal conductivity in mono-category case        |
-         !------------------------------------------------------------------------------|
-         !
+         !--- 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
@@ -309,8 +297,7 @@
          END SELECT
          !
-         !------------------------------------------------------------------------------|
-         !  6) kappa factors                                                            |
-         !------------------------------------------------------------------------------|
-         !
+         !-----------------
+         ! 4) kappa factors
+         !-----------------
          !--- Snow
          DO jk = 0, nlay_s-1
@@ -338,8 +325,7 @@
          END DO
          !
-         !------------------------------------------------------------------------------|
-         ! 7) Sea ice specific heat, eta factors                                        |
-         !------------------------------------------------------------------------------|
-         !
+         !--------------------------------------
+         ! 5) Sea ice specific heat, eta factors
+         !--------------------------------------
          DO jk = 1, nlay_i
             DO ji = 1, nidx
@@ -355,8 +341,7 @@
          END DO
          !
-         !------------------------------------------------------------------------------|
-         ! 8) surface flux computation                                                  |
-         !------------------------------------------------------------------------------|
-         !
+         !----------------------------
+         ! 6) surface flux computation
+         !----------------------------
          IF ( ln_dqns_i ) THEN 
             DO ji = 1, nidx
@@ -370,8 +355,7 @@
          END DO
          !
-         !------------------------------------------------------------------------------|
-         ! 9) tridiagonal system terms                                                  |
-         !------------------------------------------------------------------------------|
-         !
+         !----------------------------
+         ! 7) 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
@@ -414,9 +398,7 @@
 
          DO ji = 1, nidx
-            IF ( ht_s_1d(ji) > 0.0 ) THEN
-               !
-               !------------------------------------------------------------------------------|
-               !  snow-covered cells                                                          |
-               !------------------------------------------------------------------------------|
+            !                               !---------------------!
+            IF ( ht_s_1d(ji) > 0.0 ) THEN   !  snow-covered cells !
+               !                            !---------------------!
                !
                !!snow interior terms (bottom equation has the same form as the others)
@@ -435,9 +417,6 @@
                ENDIF
 
-               IF ( t_su_1d(ji) < rt0 ) THEN
-
-                  !------------------------------------------------------------------------------|
-                  !  case 1 : no surface melting - snow present                                  |
-                  !------------------------------------------------------------------------------|
+               IF ( t_su_1d(ji) < rt0 ) THEN   !--  case 1 : no surface melting
+
                   numeqmin(ji)    =  1
                   numeqmax(ji)    =  nlay_i + nlay_s + 1
@@ -455,9 +434,5 @@
                   zindterm(ji,2) =  ztsold(ji,1) + zeta_s(ji,1) * zradab_s(ji,1)
 
-               ELSE 
-                  !
-                  !------------------------------------------------------------------------------|
-                  !  case 2 : surface is melting - snow present                                  |
-                  !------------------------------------------------------------------------------|
+               ELSE                            !--  case 2 : surface is melting
                   !
                   numeqmin(ji)    =  2
@@ -471,15 +446,9 @@
                      &             ( zradab_s(ji,1) + zkappa_s(ji,0) * zg1s * t_su_1d(ji) ) 
                ENDIF
-            ELSE
+            !                               !---------------------!
+            ELSE                            ! cells without snow  !
+               !                            !---------------------!
                !
-               !------------------------------------------------------------------------------|
-               !  cells without snow                                                          |
-               !------------------------------------------------------------------------------|
-               !
-               IF ( t_su_1d(ji) < rt0 ) THEN
-                  !
-                  !------------------------------------------------------------------------------|
-                  !  case 3 : no surface melting - no snow                                       |
-                  !------------------------------------------------------------------------------|
+               IF ( t_su_1d(ji) < rt0 ) THEN   !--  case 1 : no surface melting
                   !
                   numeqmin(ji)      =  nlay_s + 1
@@ -512,11 +481,6 @@
                   ENDIF
 
-               ELSE
-
-                  !
-                  !------------------------------------------------------------------------------|
-                  ! case 4 : surface is melting - no snow                                        |
-                  !------------------------------------------------------------------------------|
-                  !
+               ELSE                            !--  case 2 : surface is melting
+
                   numeqmin(ji)    =  nlay_s + 2
                   numeqmax(ji)    =  nlay_i + nlay_s + 1
@@ -543,11 +507,9 @@
          END DO
          !
-         !------------------------------------------------------------------------------|
-         ! 10) tridiagonal system solving                                               |
-         !------------------------------------------------------------------------------|
-         !
+         !------------------------------
+         ! 8) tridiagonal system solving
+         !------------------------------
          ! Solve the tridiagonal system with Gauss elimination method.
-         ! Thomas algorithm, from Computational fluid Dynamics, J.D. ANDERSON, 
-         ! McGraw-Hill 1984.	
+         ! Thomas algorithm, from Computational fluid Dynamics, J.D. ANDERSON, McGraw-Hill 1984.	
 
          maxnumeqmax = 0
@@ -595,8 +557,7 @@
          END DO
          !
-         !--------------------------------------------------------------------------
-         !  11) Has the scheme converged ?, end of the iterative procedure         |
-         !--------------------------------------------------------------------------
-         !
+         !--------------------------------------------------------------
+         ! 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
@@ -632,9 +593,8 @@
          WRITE(numout,*) ' iconv    : ', iconv
       ENDIF
-
-      !
-      !-------------------------------------------------------------------------!
-      !   12) Fluxes at the interfaces                                          !
-      !-------------------------------------------------------------------------!
+      !
+      !-----------------------------
+      ! 10) Fluxes at the interfaces
+      !-----------------------------
       DO ji = 1, nidx
          !                                ! surface ice conduction flux
@@ -694,5 +654,5 @@
 
    SUBROUTINE ice_thd_enmelt
-      !!-----------------------------------------------------------------------
+      !!-------------------------------------------------------------------
       !!                   ***  ROUTINE ice_thd_enmelt *** 
       !!                 
@@ -764,5 +724,5 @@
       !
       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 conductivity (ln_cndi_U64 or ln_cndi_P07)' )
+         CALL ctl_stop( 'ice_thd_zdf_init: choose one and only one formulation for thermal conduction (ln_cndi_U64 or ln_cndi_P07)' )
       ENDIF
       !
@@ -771,5 +731,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!                   Dummy Module                 No ESIM sea-ice model
+   !!   Default option       Dummy Module             No ESIM sea-ice model
    !!----------------------------------------------------------------------
 #endif
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceupdate.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceupdate.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceupdate.F90	(revision 8534)
@@ -16,5 +16,5 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                    LIM 3.0 sea-ice model
+   !!   'key_lim3'                                       ESIM sea-ice model
    !!----------------------------------------------------------------------
    !!   ice_update_alloc : allocate the iceupdate arrays
@@ -23,5 +23,4 @@
    !!   ice_update_tau   : update i- and j-stresses, and its modulus at the ocean surface
    !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
    USE oce     , ONLY : sshn, sshb
    USE phycst         ! physical constants
@@ -42,8 +41,8 @@
    !
    USE in_out_manager ! I/O manager
-   USE iom            ! xIO server
-   USE lbclnk         ! ocean lateral boundary condition - MPP exchanges
+   USE iom            ! I/O manager library
    USE lib_mpp        ! MPP library
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE lbclnk         ! lateral boundary conditions (or mpp links)
    USE timing         ! Timing
 
@@ -110,5 +109,5 @@
       REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zalb_cs, zalb_os     ! 3D workspace
       !!---------------------------------------------------------------------
-      IF( nn_timing == 1 )  CALL timing_start('ice_update_flx')
+      IF( nn_timing == 1 )  CALL timing_start('ice_update')
 
       IF( kt == nit000 .AND. lwp ) THEN
@@ -213,5 +212,5 @@
       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_flx')                                  ! timing
+      IF( nn_timing == 1                 )   CALL timing_stop   ('ice_update')                                      ! timing
       !
    END SUBROUTINE ice_update_flx
@@ -251,5 +250,5 @@
       !!---------------------------------------------------------------------
 
-      IF( nn_timing == 1 )  CALL timing_start('ice_update_tau')
+      IF( nn_timing == 1 )  CALL timing_start('ice_update')
 
       IF( kt == nit000 .AND. lwp ) THEN
@@ -297,5 +296,5 @@
       CALL lbc_lnk_multi( utau, 'U', -1., vtau, 'V', -1. )   ! lateral boundary condition
       !
-      IF( nn_timing == 1 )  CALL timing_stop('ice_update_tau')
+      IF( nn_timing == 1 )  CALL timing_stop('ice_update')
       !  
    END SUBROUTINE ice_update_tau
@@ -373,5 +372,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option         Dummy module          NO  LIM3 sea-ice model
+   !!   Default option         Dummy module           NO ESIM sea-ice model
    !!----------------------------------------------------------------------
 #endif 
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icevar.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icevar.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icevar.F90	(revision 8534)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                       ***  MODULE icevar ***
-   !!                 Different sets of ice model variables 
+   !!   sea-ice:     Different sets of ice model variables 
    !!                   how to switch from one to another
    !!
@@ -36,5 +36,5 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!   'key_lim3'                                       ESIM sea-ice model
    !!----------------------------------------------------------------------
    !!   ice_var_agg       : integrate variables over layers and categories
@@ -47,13 +47,13 @@
    !!   ice_var_itd       : convert 1-cat to multiple cat
    !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
+   USE dom_oce        ! ocean space and time domain
    USE phycst         ! physical constants (ocean directory) 
    USE sbc_oce , ONLY : sss_m
-   USE ice            ! ice variables
-   USE ice1D          ! ice variables (thermodynamics)
+   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)  
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
 
    IMPLICIT NONE
@@ -77,10 +77,10 @@
 
    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
@@ -88,5 +88,5 @@
       INTEGER ::   ji, jj, jk, jl   ! dummy loop indices
       REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   z1_at_i, z1_vt_i
-      !!------------------------------------------------------------------
+      !!-------------------------------------------------------------------
       !
       !                                      ! integrated values
@@ -143,10 +143,10 @@
 
    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
@@ -155,5 +155,5 @@
       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 
@@ -242,10 +242,10 @@
 
    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  (:,:,:) = ht_i(:,:,:) * a_i(:,:,:)
@@ -257,5 +257,5 @@
 
    SUBROUTINE ice_var_salprof
-      !!------------------------------------------------------------------
+      !!-------------------------------------------------------------------
       !!                ***  ROUTINE ice_var_salprof ***
       !!
@@ -270,5 +270,5 @@
       !!
       !! ** References : Vancoppenolle et al., 2007
-      !!------------------------------------------------------------------
+      !!-------------------------------------------------------------------
       INTEGER  ::   ji, jj, jk, jl   ! dummy loop index
       REAL(wp) ::   zsal, z1_dS
@@ -277,5 +277,5 @@
       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 ? 
@@ -355,5 +355,5 @@
 
    SUBROUTINE ice_var_bv
-      !!------------------------------------------------------------------
+      !!-------------------------------------------------------------------
       !!                ***  ROUTINE ice_var_bv ***
       !!
@@ -363,7 +363,7 @@
       !!
       !! 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
@@ -398,5 +398,5 @@
       REAL(wp), PARAMETER :: zsi0 = 3.5_wp
       REAL(wp), PARAMETER :: zsi1 = 4.5_wp
-      !!---------------------------------------------------------------------
+      !!-------------------------------------------------------------------
       !
       SELECT CASE ( nn_icesal )
@@ -543,5 +543,5 @@
 
    SUBROUTINE ice_var_itd( zhti, zhts, zai, zht_i, zht_s, za_i )
-      !!------------------------------------------------------------------
+      !!-------------------------------------------------------------------
       !!                ***  ROUTINE ice_var_itd   ***
       !!
@@ -579,8 +579,11 @@
       INTEGER , DIMENSION(4)                  ::   itest
       !!-------------------------------------------------------------------
-
-      !--------------------------------------------------------------------
-      ! initialisation of variables
-      !--------------------------------------------------------------------
+      !
+      ! ----------------------------------------
+      ! 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
       ijpij = SIZE( zhti , 1 )
       zht_i(1:ijpij,1:jpl) = 0._wp
@@ -588,7 +591,4 @@
       za_i (1:ijpij,1:jpl) = 0._wp
 
-      ! ----------------------------------------
-      ! distribution over the jpl ice categories
-      ! ----------------------------------------
       DO ji = 1, ijpij
          
@@ -604,31 +604,24 @@
             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                                               !====================================
+            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
-               
-               ! 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
+               IF ( i_fill == 1 ) THEN      !-- case very thin ice: fill only category 1
                   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 
+               ELSE                         !-- case ice is thicker: fill categories >1
+                  ! thickness
                   DO jl = 1, i_fill - 1
                      zht_i(ji,jl) = hi_mean(jl)
                   END DO
                   
-                  ! Concentrations in the (i_fill-1) categories 
+                  ! concentration
                   za_i(ji,jl0) = zai(ji) / SQRT(REAL(jpl))
                   DO jl = 1, i_fill - 1
@@ -639,8 +632,6 @@
                   END DO
                   
-                  ! Concentration in the last (i_fill) category
+                  ! last 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 ) 
@@ -659,34 +650,26 @@
                   ENDIF
                
-               ENDIF ! case ice is thick or thin
+               ENDIF
             
-               !---------------------
                ! Compatibility tests
-               !--------------------- 
-               ! Test 1: area conservation
-               zconv = ABS( zai(ji) - SUM( za_i(ji,1:jpl) ) )
-               IF ( zconv < epsi06 ) itest(1) = 1
+               zconv = ABS( zai(ji) - SUM( za_i(ji,1:jpl) ) ) 
+               IF ( zconv < epsi06 ) itest(1) = 1                                        ! Test 1: area conservation
             
-               ! 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
+               IF ( zconv < epsi06 ) itest(2) = 1                                        ! Test 2: volume conservation
                
-               ! Test 3: thickness of the last category is in-bounds ?
-               IF ( zht_i(ji,i_fill) >= hi_max(i_fill-1) ) itest(3) = 1
+               IF ( zht_i(ji,i_fill) >= hi_max(i_fill-1) ) itest(3) = 1                  ! Test 3: thickness of the last category is in-bounds ?
                
-               ! Test 4: positivity of ice concentrations
                itest(4) = 1
                DO jl = 1, i_fill
-                  IF ( za_i(ji,jl) < 0._wp ) itest(4) = 0
+                  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 ! if zhti > 0
-      END DO ! i loop
-
-      ! ------------------------------------------------
-      ! Adding Snow in each category where za_i is not 0
-      ! ------------------------------------------------ 
+               !                                         !----------------------------
+         ENDIF
+      END DO
+
+      ! Add Snow in each category where za_i is not 0
       DO jl = 1, jpl
          DO ji = 1, ijpij
@@ -707,5 +690,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option         Dummy module          NO  LIM3 sea-ice model
+   !!   Default option         Dummy module           NO ESIM sea-ice model
    !!----------------------------------------------------------------------
 #endif
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icewri.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icewri.F90	(revision 8533)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icewri.F90	(revision 8534)
@@ -2,9 +2,9 @@
    !!======================================================================
    !!                     ***  MODULE  icewri  ***
-   !!         Ice diagnostics :  write ice output files
+   !!   sea-ice : output ice variables
    !!======================================================================
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!   'key_lim3'                                       ESIM sea-ice model
    !!----------------------------------------------------------------------
    !!   ice_wri       : write of the diagnostics variables in ouput file 
@@ -20,10 +20,10 @@
    !
    USE ioipsl         !
-   USE in_out_manager !
-   USE lbclnk         !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
    USE lib_mpp        ! MPP library
-   USE iom            !
+   USE lib_fortran    ! fortran utilities (glob_sum + no signed zero)
+   USE lbclnk         ! lateral boundary conditions (or mpp links)
    USE timing         ! Timing
-   USE lib_fortran    ! Fortran utilities
 
    IMPLICIT NONE
@@ -485,5 +485,5 @@
 #else
    !!----------------------------------------------------------------------
-   !!   Default option :         Empty module          NO LIM sea-ice model
+   !!   Default option :         Empty module         NO ESIM sea-ice model
    !!----------------------------------------------------------------------
 #endif
