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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/ice.F90	(revision 8486)
@@ -17,5 +17,5 @@
    PRIVATE
 
-   PUBLIC    ice_alloc  !  Called in ice_init
+   PUBLIC    ice_alloc  ! called by icestp.F90
 
    !!======================================================================
@@ -288,10 +288,12 @@
    REAL(wp), PUBLIC ::   r1_nlay_s        !: 1 / nlay_s 
    REAL(wp), PUBLIC ::   rswitch          !: switch for the presence of ice (1) or not (0)
-   REAL(wp), PUBLIC, PARAMETER ::   epsi06   = 1.e-06_wp  !: small number 
-   REAL(wp), PUBLIC, PARAMETER ::   epsi10   = 1.e-10_wp  !: small number 
-   REAL(wp), PUBLIC, PARAMETER ::   epsi20   = 1.e-20_wp  !: small number 
+   REAL(wp), PUBLIC, PARAMETER ::   epsi06 = 1.e-06_wp  !: small number 
+   REAL(wp), PUBLIC, PARAMETER ::   epsi10 = 1.e-10_wp  !: small number 
+   REAL(wp), PUBLIC, PARAMETER ::   epsi20 = 1.e-20_wp  !: small number 
+   !
+   LOGICAL , PUBLIC ::   l_piling         !: =T simple conservative piling, comparable with LIM2
 
    !                                     !!** define arrays
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   u_oce, v_oce !: surface ocean velocity used in ice dynamics
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   u_oce,v_oce !: surface ocean velocity used in ice dynamics
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hicol       !: ice collection thickness accreted in leads
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   strength    !: ice strength
@@ -499,5 +501,5 @@
    !
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/ice1D.F90	(revision 8486)
@@ -8,14 +8,15 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                       LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   USE ice     , ONLY :   nlay_i, nlay_s, jpl   ! number of ice/snow layers and categories
+   !
    USE in_out_manager ! I/O manager
    USE lib_mpp        ! MPP library
-   USE ice, ONLY :   nlay_i, nlay_s, jpl
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC ice1D_alloc ! Routine called by nemogcm.F90
+   PUBLIC   ice1D_alloc   ! called by icestp.F90
 
    !!----------------------
@@ -26,4 +27,6 @@
    !: are the variables corresponding to 2d vectors
 
+!! please, DOCTOR naming convention   starting by i means LOCAL integer
+!!         ===>>>  rename idxice  as nidice or nidthd, or nidx_thd or midx ... ?
    INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   idxice !: selected points for ice thermo
    INTEGER , PUBLIC                                  ::   nidx   !  number of selected points
@@ -151,5 +154,5 @@
    
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: ice1D.F90 8379 2017-07-26 15:35:49Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceadv.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceadv.F90	(revision 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceadv.F90	(revision 8486)
@@ -10,24 +10,23 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   ice_adv      : advection/diffusion process of sea ice
+   !!   '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
-   USE ice            ! ice variables
-   USE icevar         ! 
-   USE iceadv_prather ! advection scheme (Prather)
-   USE iceadv_umx     ! advection scheme (ultimate-macho)
+   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 wrk_nemo       ! work arrays
    USE prtctl         ! Print control
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
    USE timing         ! Timing
-   USE icectl         ! control prints
 
    IMPLICIT NONE
@@ -36,10 +35,10 @@
    PUBLIC   ice_adv    ! called by icestp
 
-   INTEGER  ::   ncfl                 ! number of ice time step with CFL>1/2  
+   INTEGER ::   ncfl   ! number of ice time step with CFL>1/2  
 
    !! * Substitution
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! 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)
@@ -48,5 +47,5 @@
 
    SUBROUTINE ice_adv( kt ) 
-      !!-------------------------------------------------------------------
+      !!----------------------------------------------------------------------
       !!                   ***  ROUTINE ice_adv ***
       !!                    
@@ -60,5 +59,5 @@
       !!
       !! ** action :
-      !!---------------------------------------------------------------------
+      !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt   ! number of iteration
       !
@@ -73,16 +72,15 @@
       REAL(wp), DIMENSION(jpi,jpj,jpl)       ::   zhimax, zviold, zvsold
       ! --- ultimate macho only --- !
-      REAL(wp)                               ::   zdt
-      REAL(wp), POINTER, DIMENSION(:,:)      ::   zudy, zvdx, zcu_box, zcv_box
+      REAL(wp) ::   zdt
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:)      ::   zudy, zvdx, zcu_box, zcv_box
       ! --- prather only --- !
-      REAL(wp), POINTER, DIMENSION(:,:)      ::   zarea
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   z0opw
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   z0ice, z0snw, z0ai, z0es , z0smi , z0oi
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:)     ::   zarea
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::   z0opw
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::   z0ice, z0snw, z0ai, z0es , z0smi , z0oi
       ! MV MP 2016
-      REAL(wp), POINTER, DIMENSION(:,:,:)    ::   z0ap , z0vp
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::   z0ap , z0vp
       REAL(wp) ::   za_old
       ! END MV MP 2016
-      REAL(wp), POINTER, DIMENSION(:,:,:,:)  ::   z0ei
-      !!
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) ::   z0ei
       !!---------------------------------------------------------------------
       IF( nn_timing == 1 )  CALL timing_start('iceadv')
@@ -90,6 +88,6 @@
       IF( kt == nit000 .AND. lwp ) THEN
          WRITE(numout,*)''
-         WRITE(numout,*)'iceadv'
-         WRITE(numout,*)'~~~~~~'
+         WRITE(numout,*)'iceadv : sea-ice advection'
+         WRITE(numout,*)'~~~~~~~'
          ncfl = 0                ! nb of time step with CFL > 1/2
       ENDIF
@@ -127,4 +125,5 @@
          DO jj = 2, jpjm1
             DO ji = 2, jpim1
+!!gm use of MAXVAL here is very probably less efficient than expending the 9 values
                zhimax(ji,jj,jl) = MAXVAL( ht_i(ji-1:ji+1,jj-1:jj+1,jl) + ht_s(ji-1:ji+1,jj-1:jj+1,jl) )
             END DO
@@ -156,5 +155,5 @@
                        !=============================!
       
-         CALL wrk_alloc( jpi,jpj, zudy, zvdx, zcu_box, zcv_box )
+         ALLOCATE( zudy(jpi,jpj) , zvdx(jpi,jpj) , zcu_box(jpi,jpj) , zcv_box(jpi,jpj) )
       
          IF( kt == nit000 .AND. lwp ) THEN
@@ -212,5 +211,5 @@
          END DO
          !
-         CALL wrk_dealloc( jpi,jpj, zudy, zvdx, zcu_box, zcv_box )
+         DEALLOCATE( zudy, zvdx, zcu_box, zcv_box )
          
                        !=============================!
@@ -218,9 +217,8 @@
                        !=============================!
 
-         CALL wrk_alloc( jpi,jpj,            zarea )
-         CALL wrk_alloc( jpi,jpj,1,          z0opw )
-         CALL wrk_alloc( jpi,jpj,jpl,        z0ice, z0snw, z0ai, z0es , z0smi , z0oi )
-         CALL wrk_alloc( jpi,jpj,jpl,        z0ap , z0vp )
-         CALL wrk_alloc( jpi,jpj,nlay_i,jpl, z0ei )
+         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( kt == nit000 .AND. lwp ) THEN
@@ -237,22 +235,20 @@
          z0opw(:,:,1) = ato_i(:,:) * e1e2t(:,:)             ! Open water area 
          DO jl = 1, jpl
-            z0snw (:,:,jl)  = v_s  (:,:,  jl) * e1e2t(:,:)  ! Snow volume
-            z0ice(:,:,jl)   = v_i  (:,:,  jl) * e1e2t(:,:)  ! Ice  volume
-            z0ai  (:,:,jl)  = a_i  (:,:,  jl) * e1e2t(:,:)  ! Ice area
-            z0smi (:,:,jl)  = smv_i(:,:,  jl) * e1e2t(:,:)  ! Salt content
-            z0oi (:,:,jl)   = oa_i (:,:,  jl) * e1e2t(:,:)  ! Age content
-            z0es (:,:,jl)   = e_s  (:,:,1,jl) * e1e2t(:,:)  ! Snow heat content
+            z0snw(:,:,jl) = v_s  (:,:,  jl) * e1e2t(:,:)  ! Snow volume
+            z0ice(:,:,jl) = v_i  (:,:,  jl) * e1e2t(:,:)  ! Ice  volume
+            z0ai (:,:,jl) = a_i  (:,:,  jl) * e1e2t(:,:)  ! Ice area
+            z0smi(:,:,jl) = smv_i(:,:,  jl) * e1e2t(:,:)  ! Salt content
+            z0oi (:,:,jl) = oa_i (:,:,  jl) * e1e2t(:,:)  ! Age content
+            z0es (:,:,jl) = e_s  (:,:,1,jl) * e1e2t(:,:)  ! Snow heat content
             DO jk = 1, nlay_i
-               z0ei  (:,:,jk,jl) = e_i  (:,:,jk,jl) * e1e2t(:,:) ! Ice  heat content
+               z0ei(:,:,jk,jl) = e_i(:,:,jk,jl) * e1e2t(:,:) ! Ice  heat content
             END DO
             ! MV MP 2016
             IF ( nn_pnd_scheme > 0 ) THEN
-               z0ap  (:,:,jl)  = a_ip (:,:,jl) * e1e2t(:,:) ! Melt pond fraction
-               z0vp  (:,:,jl)  = v_ip (:,:,jl) * e1e2t(:,:) ! Melt pond volume
+               z0ap(:,:,jl)  = a_ip(:,:,jl) * e1e2t(:,:) ! Melt pond fraction
+               z0vp(:,:,jl)  = v_ip(:,:,jl) * e1e2t(:,:) ! Melt pond volume
             ENDIF
             ! END MV MP 2016
-
-         END DO
-
+         END DO
 
          IF( MOD( ( kt - 1) / nn_fsbc , 2 ) == 0 ) THEN       !==  odd ice time step:  adv_x then adv_y  ==!
@@ -383,18 +379,12 @@
             ! END MV MP 2016
          END DO
-
+         !
          at_i(:,:) = a_i(:,:,1)      ! total ice fraction
          DO jl = 2, jpl
             at_i(:,:) = at_i(:,:) + a_i(:,:,jl)
          END DO
-         
-         CALL wrk_dealloc( jpi,jpj,            zarea )
-         CALL wrk_dealloc( jpi,jpj,1,          z0opw )
-         CALL wrk_dealloc( jpi,jpj,jpl,        z0ice, z0snw, z0ai, z0es , z0smi , z0oi )
-         ! MV MP 2016
-         CALL wrk_dealloc( jpi,jpj,jpl,        z0ap , z0vp )
-         ! END MV MP 2016
-         CALL wrk_dealloc( jpi,jpj,nlay_i,jpl, z0ei )
-
+         !
+         DEALLOCATE( zarea , z0opw , z0ice, z0snw , z0ai , z0es , z0smi , z0oi , z0ap , z0vp , z0ei )
+         !
       END SELECT
       
@@ -411,27 +401,25 @@
       
       IF( nn_limdyn == 2) THEN
-
-         ! zap small areas
-         CALL ice_var_zapsmall
-           
-         !--- Thickness correction in case too high --- !
-         DO jl = 1, jpl
+         !
+         CALL ice_var_zapsmall      !--- zap small areas ---!
+         !
+         DO jl = 1, jpl             !--- Thickness correction in case too high --- !
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  
+                  ! 
                   IF ( v_i(ji,jj,jl) > 0._wp ) THEN
-                     
+                     !
                      rswitch          = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi20 ) )
                      ht_i  (ji,jj,jl) = v_i (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
                      ht_s  (ji,jj,jl) = v_s (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-                     
+                     !
                      zdv  = v_i(ji,jj,jl) + v_s(ji,jj,jl) - zviold(ji,jj,jl) - zvsold(ji,jj,jl)  
-                     
+                     !
                      IF ( ( zdv >  0.0 .AND. (ht_i(ji,jj,jl)+ht_s(ji,jj,jl)) > zhimax(ji,jj,jl) .AND. zatold(ji,jj) < 0.80 ) .OR. &
                         & ( zdv <= 0.0 .AND. (ht_i(ji,jj,jl)+ht_s(ji,jj,jl)) > zhimax(ji,jj,jl) ) ) THEN
-                        
+                        !
                         rswitch        = MAX( 0._wp, SIGN( 1._wp, zhimax(ji,jj,jl) - epsi20 ) )
                         a_i(ji,jj,jl)  = rswitch * ( v_i(ji,jj,jl) + v_s(ji,jj,jl) ) / MAX( zhimax(ji,jj,jl), epsi20 )
-                        
+                        !
                         ! small correction due to *rswitch for a_i
                         v_i  (ji,jj,jl)        = rswitch * v_i  (ji,jj,jl)
@@ -447,16 +435,14 @@
                         ENDIF
                         ! END MV MP 2016
-                                                
+                        !
                      ENDIF
-                     
+                     !
                   ENDIF
-                
+                  !
                END DO
             END DO
          END DO
-         ! -------------------------------------------------
-         
-         ! Force the upper limit of ht_i to always be < hi_max (99 m).
-         DO jj = 1, jpj
+         
+         DO jj = 1, jpj             !--- bound ht_i to hi_max (99 m).
             DO ji = 1, jpi
                ! MV MP 2016
@@ -474,6 +460,5 @@
             END DO
          END DO
-
-
+         !
       ENDIF
          
@@ -482,16 +467,24 @@
       !------------------------------------------------------------
       !
-      at_i(:,:) = SUM( a_i(:,:,:), dim=3 )
-      IF ( nn_limdyn == 1 .OR. ( ( nn_monocat == 2 ) .AND. ( jpl == 1 ) ) ) THEN ! simple conservative piling, comparable with LIM2
+!!gm remplace the test by, l_piling a logical compute one for all in icestp.F90 (and its declaration in ice.F90
+!!gm      IF ( nn_limdyn == 1 .OR. ( ( nn_monocat == 2 ) .AND. ( jpl == 1 ) ) ) THEN ! simple conservative piling, comparable with LIM2
+      IF( l_piling ) THEN
+         at_i(:,:) = SUM( a_i(:,:,:), dim=3 )
          DO jl = 1, jpl
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  rswitch       = MAX( 0._wp, SIGN( 1._wp, at_i(ji,jj) - epsi20 ) )
-                  zda           = rswitch * MIN( rn_amax_2d(ji,jj) - at_i(ji,jj), 0._wp )  &
-                     &                    * a_i(ji,jj,jl) / MAX( at_i(ji,jj), epsi20 )
+                  rswitch = MAX( 0._wp, SIGN( 1._wp, at_i(ji,jj) - epsi20 ) )
+                  zda     = rswitch * MIN( rn_amax_2d(ji,jj) - at_i(ji,jj), 0._wp ) * a_i(ji,jj,jl) / MAX( at_i(ji,jj), epsi20 )
                   a_i(ji,jj,jl) = a_i(ji,jj,jl) + zda
                END DO
             END DO
          END DO
+!!gm better and faster coding?
+!         DO jl = 1, jpl
+!            WHERE( at_i(:,:) > epsi20 )
+!               a_i(:,:,jl) = a_i(:,:,jl) * (  1._wp + MIN( rn_amax_2d(:,:) - at_i(:,:) , 0._wp ) / at_i(:,:)  )
+!            END WHERE
+!         END DO
+!!gm end
       ENDIF
       
@@ -527,8 +520,6 @@
    !!   Default option         Empty Module                No sea-ice model
    !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE ice_adv        ! Empty routine
-   END SUBROUTINE ice_adv
 #endif
+
    !!======================================================================
 END MODULE iceadv
Index: /branches/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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceadv_prather.F90	(revision 8486)
@@ -5,22 +5,22 @@
    !!======================================================================
    !! 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.
+   !!            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_x  : advection of sea ice on x axis
-   !!   ice_adv_y  : advection of sea ice on y axis
-   !!----------------------------------------------------------------------
-   USE dom_oce          ! ocean domain
-   USE ice              ! LIM-3 variables
+   !!   'key_lim3'                                       LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_adv_x     : advection of sea ice on x axis
+   !!   ice_adv_y     : advection of sea ice on y axis
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean domain
+   USE ice            ! sea-ice variables
    !
-   USE lbclnk           ! lateral boundary condition - MPP exchanges
-   USE in_out_manager   ! I/O manager
-   USE prtctl           ! Print control
-   USE lib_mpp          ! MPP library
-   USE lib_fortran      ! to use key_nosignedzero
+   USE lbclnk         ! lateral boundary condition - MPP exchanges
+   USE in_out_manager ! I/O manager
+   USE prtctl         ! Print control
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! to use key_nosignedzero
 
    IMPLICIT NONE
@@ -33,5 +33,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! 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)
@@ -41,5 +41,5 @@
    SUBROUTINE ice_adv_x( pdf, put , pcrh, psm , ps0 ,   &
       &                  psx, psxx, psy , psyy, psxy )
-      !!---------------------------------------------------------------------
+      !!----------------------------------------------------------------------
       !!                **  routine ice_adv_x  **
       !!  
@@ -52,5 +52,5 @@
       !!
       !! Reference:  Prather, 1986, JGR, 91, D6. 6671-6681.
-      !!--------------------------------------------------------------------
+      !!----------------------------------------------------------------------
       REAL(wp)                    , INTENT(in   ) ::   pdf                ! reduction factor for the time step
       REAL(wp)                    , INTENT(in   ) ::   pcrh               ! call ice_adv_x then ice_adv_y (=1) or the opposite (=0)
@@ -68,5 +68,5 @@
       REAL(wp), DIMENSION(jpi,jpj) ::   zfm , zfxx , zfyy  , zfxy   !  -      -
       REAL(wp), DIMENSION(jpi,jpj) ::   zalg, zalg1, zalg1q         !  -      -
-      !---------------------------------------------------------------------
+      !-----------------------------------------------------------------------
 
       ! Limitation of moments.                                           
Index: /branches/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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceadv_umx.F90	(revision 8486)
@@ -4,21 +4,19 @@
    !! LIM sea-ice model : sea-ice advection using the ULTIMATE-MACHO scheme
    !!==============================================================================
-   !! History :  3.5  !  2014-11  (C. Rousset, G. Madec)  Original code
-   !!----------------------------------------------------------------------
-
+   !! 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      : compute a tracer value at velocity points using ULTIMATE scheme at various orders
-   !!   macho         : 
+   !!   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 
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                  LIM 3.0 sea-ice model
    !!----------------------------------------------------------------------
    USE phycst         ! physical constant
    USE dom_oce        ! ocean domain
-   USE sbc_oce, ONLY: nn_fsbc   ! ocean surface boundary condition
-   USE ice            ! ice variables
+   USE sbc_oce , ONLY : nn_fsbc   ! update frequency of surface boundary condition
+   USE ice            ! sea-ice variables
    !
    USE in_out_manager ! I/O manager
@@ -33,11 +31,11 @@
    PUBLIC   ice_adv_umx    ! routine called by iceadv.F90
       
-   REAL(wp) ::   z1_6   = 1._wp / 6._wp   ! =1/6
-   REAL(wp) ::   z1_120 = 1._wp / 120._wp ! =1/120
+   REAL(wp) ::   z1_6   = 1._wp /   6._wp   ! =1/6
+   REAL(wp) ::   z1_120 = 1._wp / 120._wp   ! =1/120
 
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! 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)
@@ -58,9 +56,9 @@
       !! ** Action : - pt  the after advective tracer
       !!----------------------------------------------------------------------
-      INTEGER                     , INTENT(in   )           ::   kt         ! number of iteration
-      REAL(wp)                    , INTENT(in   )           ::   pdt        ! tracer time-step
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   )           ::   puc, pvc   ! 2 ice velocity components => u*e2
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(in   )           ::   pubox, pvbox   ! upstream velocity
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout)           ::   ptc        ! tracer content field
+      INTEGER                     , 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  
@@ -68,5 +66,6 @@
       REAL(wp) ::   zfp_ui, zfp_vj   !   -      -
       REAL(wp) ::   zfm_ui, zfm_vj   !   -      -
-      REAL(wp), DIMENSION(jpi,jpj) :: zt_ups, zfu_ups, zfv_ups, ztrd, zfu_ho, zfv_ho, zt_u, zt_v
+      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
       !!----------------------------------------------------------------------
       !
@@ -394,7 +393,6 @@
       !
       SELECT CASE (k_order )
-         !
-      CASE( 1 )                                                   !==  1st order central TIM  ==! (Eq. 21)
-         !        
+      !
+      CASE( 1 )                                                !==  1st order central TIM  ==! (Eq. 21)
          DO jj = 1, jpjm1
             DO ji = 1, jpi
@@ -404,5 +402,5 @@
          END DO
          !
-      CASE( 2 )                                                   !==  2nd order central TIM  ==! (Eq. 23)
+      CASE( 2 )                                                !==  2nd order central TIM  ==! (Eq. 23)
          DO jj = 1, jpjm1
             DO ji = 1, jpi
@@ -414,6 +412,5 @@
          CALL lbc_lnk( pt_v(:,:) , 'V',  1. )
          !
-      CASE( 3 )                                                   !==  3rd order central TIM  ==! (Eq. 24)
-         !
+      CASE( 3 )                                                !==  3rd order central TIM  ==! (Eq. 24)
          DO jj = 1, jpjm1
             DO ji = 1, jpi
@@ -428,6 +425,5 @@
          END DO
          !
-      CASE( 4 )                                                   !==  4th order central TIM  ==! (Eq. 27)
-         !
+      CASE( 4 )                                                !==  4th order central TIM  ==! (Eq. 27)
          DO jj = 1, jpjm1
             DO ji = 1, jpi
@@ -442,6 +438,5 @@
          END DO
          !
-      CASE( 5 )                                                   !==  5th order central TIM  ==! (Eq. 29)
-         !
+      CASE( 5 )                                                !==  5th order central TIM  ==! (Eq. 29)
          DO jj = 1, jpjm1
             DO ji = 1, jpi
@@ -569,10 +564,6 @@
    !!   Default option           Dummy module      NO LIM 3.0 sea-ice model
    !!----------------------------------------------------------------------
-CONTAINS
-   !
-   SUBROUTINE ice_adv_umx     ! Dummy routine
-      WRITE(*,*) 'ice_adv_umx: You should not have seen this print! error?'
-   END SUBROUTINE ice_adv_umx
 #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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icealb.F90	(revision 8486)
@@ -4,15 +4,14 @@
    !! Ocean forcing:  bulk thermohaline forcing of the ice
    !!=====================================================================
-   !! History :
-   !!   NEMO     4.0  ! 2017-07  (C. Rousset) Split ice and ocean albedos
-   !!----------------------------------------------------------------------
-   !!   ice_alb    : albedo for ice (clear and overcast skies)
-   !!   alb_init   : initialisation of albedo computation
+   !! History :  4.0  ! 2017-07  (C. Rousset) Split ice and ocean albedos
    !!----------------------------------------------------------------------
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                  LIM 3.0 sea-ice model
-   !!----------------------------------------------------------------------
-   USE ice, ONLY : jpl
+   !!   'key_lim3'                                    LIM 3.0 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_alb       : albedo for ice (clear and overcast skies)
+   !!   alb_init      : initialisation of albedo computation
+   !!----------------------------------------------------------------------
+   USE ice     , ONLY : jpl   ! number of ice category
    USE phycst         ! physical constants
    !
@@ -24,18 +23,22 @@
    PRIVATE
 
-   PUBLIC   ice_alb   ! routine called icestp.F90
-
-   REAL(wp), PUBLIC, PARAMETER ::   rn_alb_oce = 0.066   ! ocean or lead albedo (Pegau and Paulson, Ann. Glac. 2001)
+   PUBLIC   ice_alb   ! routine called in iceforcing.F90 and iceupdate.F90
+
+   REAL(wp), PUBLIC, PARAMETER ::   rn_alb_oce = 0.066   !: ocean or lead albedo (Pegau and Paulson, Ann. Glac. 2001)
+
+!!gm real variable name starting with a "c" NOT DOCTOR !!!!
    INTEGER  ::   albd_init = 0       ! control flag for initialization  
-   REAL(wp) ::   c1        = 0.05    ! snow thickness (only for nn_ice_alb=0)
-   REAL(wp) ::   c2        = 0.10    !  "        "
-   REAL(wp) ::   rcloud    = 0.06    ! cloud effect on albedo (only-for nn_ice_alb=0)
+   REAL(wp) , PARAMETER ::   c1        = 0.05    ! snow thickness (only for nn_ice_alb=0)
+   REAL(wp) , PARAMETER ::   c2        = 0.10    !  "        "
+   REAL(wp) , PARAMETER ::   rcloud    = 0.06    ! cloud effect on albedo (only-for nn_ice_alb=0)
+   REAL(wp) , PARAMETER ::   r1_c1 = 1. / c1
+   REAL(wp) , PARAMETER ::   r1_c2 = 1. / c2
  
-   !                             !!* namelist namsbc_alb
+   !                             !!* namelist namsbc_alb *
    INTEGER  ::   nn_ice_alb
    REAL(wp) ::   rn_alb_sdry, rn_alb_smlt, rn_alb_idry, rn_alb_imlt, rn_alb_dpnd
 
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , NEMO Consortium (2010)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: icealb.F90 8268 2017-07-03 15:01:04Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -76,30 +79,27 @@
       !!                Brandt et al. 2005, J. Climate, vol 18
       !!                Grenfell & Perovich 2004, JGR, vol 109 
-      !!
-      !!----------------------------------------------------------------------
-      !!
-      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   pt_ice              !  ice surface temperature (Kelvin)
-      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   ph_ice              !  sea-ice thickness
-      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   ph_snw              !  snow depth
-      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   pafrac_pnd          !  melt pond relative fraction (per unit ice area)
-      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   ph_pnd              !  melt pond depth
-      LOGICAL , INTENT(in   )                   ::   ld_pnd              !  melt ponds radiatively active or not
-      REAL(wp), INTENT(  out), DIMENSION(:,:,:) ::   pa_ice_cs           !  albedo of ice under clear    sky
-      REAL(wp), INTENT(  out), DIMENSION(:,:,:) ::   pa_ice_os           !  albedo of ice under overcast sky
-      !
-      INTEGER  ::   ji, jj, jl                                           ! dummy loop indices
-      REAL(wp) ::   zswitch, z1_c1, z1_c2
-      REAL(wp) ::   zhref_pnd                                 
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   pt_ice       !  ice surface temperature (Kelvin)
+      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   ph_ice       !  sea-ice thickness
+      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   ph_snw       !  snow depth
+      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   pafrac_pnd   !  melt pond relative fraction (per unit ice area)
+      REAL(wp), INTENT(in   ), DIMENSION(:,:,:) ::   ph_pnd       !  melt pond depth
+      LOGICAL , INTENT(in   )                   ::   ld_pnd       !  melt ponds radiatively active or not
+      REAL(wp), INTENT(  out), DIMENSION(:,:,:) ::   pa_ice_cs    !  albedo of ice under clear    sky
+      REAL(wp), INTENT(  out), DIMENSION(:,:,:) ::   pa_ice_os    !  albedo of ice under overcast sky
+      !
+      INTEGER  ::   ji, jj, jl                ! dummy loop indices
+      REAL(wp) ::   zswitch, z1_c1, z1_c2     ! local scalar
+      REAL(wp) ::   z1_href_pnd               !   -      -                 
       REAL(wp) ::   zalb_sm, zalb_sf, zalb_st ! albedo of snow melting, freezing, total
       !
-      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zalb, zalb_it             ! intermediate variable & albedo of ice (snow free)
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zalb, zalb_it   ! intermediate variable & albedo of ice (snow free)
 !! MV MP
-      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zalb_pnd                  ! ponded sea ice albedo
-      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zalb_ice                  ! bare sea ice albedo
-      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zalb_snw                  ! snow-covered sea ice albedo
-      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zafrac_snw                ! relative snow fraction
-      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zafrac_ice                ! relative ice fraction
-      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zafrac_pnd                ! relative ice fraction (effective)
-      !!
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zalb_pnd        ! ponded sea ice albedo
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zalb_ice        ! bare sea ice albedo
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zalb_snw        ! snow-covered sea ice albedo
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zafrac_snw      ! relative snow fraction
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zafrac_ice      ! relative ice fraction
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zafrac_pnd      ! relative ice fraction (effective)
       !!---------------------------------------------------------------------
 
@@ -120,14 +120,11 @@
       ENDIF
 
-      SELECT CASE ( nn_ice_alb )
-
-      !------------------------------------------
-      !  Shine and Henderson-Sellers (1985)
-      !------------------------------------------
-      ! NB: This parameterization is based on clear sky values
-
-      CASE( 0 )
-       
-         ! Thickness-dependent bare ice albedo
+      SELECT CASE ( nn_ice_alb )       ! select a parameterization
+      !
+      !              !------------------------------------------
+      CASE( 0 )      !  Shine and Henderson-Sellers (1985)     !   (based on clear sky values)
+         !           !------------------------------------------
+         !
+         !                       ! Thickness-dependent bare ice albedo
          WHERE     ( 1.5  < ph_ice                     )  ;  zalb_it = zalb
          ELSE WHERE( 1.0  < ph_ice .AND. ph_ice <= 1.5 )  ;  zalb_it = 0.472  + 2.0 * ( zalb - 0.472 ) * ( ph_ice - 1.0 )
@@ -137,35 +134,37 @@
          ELSE WHERE                                       ;  zalb_it = 0.1    + 3.6    * ph_ice
          END WHERE
-
-         IF ( ld_pnd ) THEN
-            ! Depth-dependent ponded ice albedo
-            zhref_pnd = 0.05        ! Characteristic length scale for thickness dependence of ponded ice albedo, Lecomte et al (2015)
-            zalb_pnd  = rn_alb_dpnd - ( rn_alb_dpnd - zalb_it ) * EXP( - ph_pnd / zhref_pnd ) 
-
-            ! Snow-free ice albedo is a function of pond fraction
-            WHERE ( ph_snw == 0._wp .AND. pt_ice >= rt0_ice )   ; zalb_it = zalb_it * ( 1. - pafrac_pnd  ) + zalb_pnd * pafrac_pnd ;   END WHERE
+         !
+         IF ( ld_pnd ) THEN      ! Depth-dependent ponded ice albedo
+            z1_href_pnd = 1. / 0.05    ! inverse of the characteristic length scale (Lecomte et al. 2015)
+            zalb_pnd  = rn_alb_dpnd - ( rn_alb_dpnd - zalb_it ) * EXP( - ph_pnd * z1_href_pnd ) 
+            !                          ! Snow-free ice albedo is a function of pond fraction
+            WHERE ( ph_snw == 0._wp .AND. pt_ice >= rt0_ice )   
+               zalb_it = zalb_it * ( 1. - pafrac_pnd  ) + zalb_pnd * pafrac_pnd 
+            END WHERE
          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
                DO ji = 1, jpi
-                  ! Freezing snow
+                  !                    ! Freezing snow
                   ! no effect of underlying ice layer IF snow thickness > c1. Albedo does not depend on snow thick if > c2
-                  zswitch   = 1._wp - MAX( 0._wp , SIGN( 1._wp , - ( ph_snw(ji,jj,jl) - c1 ) ) )
-                  zalb_sf   = ( 1._wp - zswitch ) * (  zalb_it(ji,jj,jl)  &
-                     &                           + ph_snw(ji,jj,jl) * ( rn_alb_sdry - zalb_it(ji,jj,jl) ) / c1  )   &
-                     &        +         zswitch   * rn_alb_sdry  
-
-                  ! Melting snow
+                  zswitch = 1._wp - MAX( 0._wp , SIGN( 1._wp , - ( ph_snw(ji,jj,jl) - c1 ) ) )
+                  zalb_sf = ( 1._wp - zswitch ) * (  zalb_it(ji,jj,jl)  &
+                     &                                   + ph_snw(ji,jj,jl) * ( rn_alb_sdry - zalb_it(ji,jj,jl) ) * r1_c1  )   &
+                     &    +           zswitch   * rn_alb_sdry  
+                     !
+                  !                    ! Melting snow
                   ! no effect of underlying ice layer. Albedo does not depend on snow thick IF > c2
-                  zswitch   = MAX( 0._wp , SIGN( 1._wp , ph_snw(ji,jj,jl) - c2 ) )
-                  zalb_sm = ( 1._wp - zswitch ) * ( rn_alb_imlt + ph_snw(ji,jj,jl) * ( rn_alb_smlt - rn_alb_imlt ) / c2 )   &
-                      &     +         zswitch   *   rn_alb_smlt 
+                  zswitch = MAX( 0._wp , SIGN( 1._wp , ph_snw(ji,jj,jl) - c2 ) )
+                  zalb_sm = ( 1._wp - zswitch ) * ( rn_alb_imlt + ph_snw(ji,jj,jl) * ( rn_alb_smlt - rn_alb_imlt ) * r1_c2 )   &
+                     &      +         zswitch   *   rn_alb_smlt 
+                     !
+                  !                    ! Snow albedo
+                  zswitch =  MAX( 0._wp , SIGN( 1._wp , pt_ice(ji,jj,jl) - rt0_snow ) )   
+                  zalb_st =  zswitch * zalb_sm + ( 1._wp - zswitch ) * zalb_sf
                   !
-                  ! Snow albedo
-                  zswitch  =  MAX( 0._wp , SIGN( 1._wp , pt_ice(ji,jj,jl) - rt0_snow ) )   
-                  zalb_st  =  zswitch * zalb_sm + ( 1._wp - zswitch ) * zalb_sf
-               
-                  ! Surface albedo
+                  !                    ! Surface albedo
                   zswitch             = 1._wp - MAX( 0._wp , SIGN( 1._wp , - ph_snw(ji,jj,jl) ) )
                   pa_ice_cs(ji,jj,jl) = zswitch * zalb_st + ( 1._wp - zswitch ) * zalb_it(ji,jj,jl)
@@ -174,53 +173,50 @@
             END DO
          END DO
-
+         !
          pa_ice_os(:,:,:) = pa_ice_cs(:,:,:) + rcloud       ! Oberhuber correction for overcast sky
-
-      !------------------------------------------
-      !  New parameterization (2016)
-      !------------------------------------------
-      ! NB: This parameterization is based on overcast skies values
-      
-      CASE( 1 ) 
-
-! compilation of values from literature (reference overcast sky values)
-!        rn_alb_sdry = 0.85      ! dry snow
-!        rn_alb_smlt = 0.75      ! melting snow
-!        rn_alb_idry = 0.60      ! bare frozen ice
-!        rn_alb_dpnd = 0.36      ! ponded-ice overcast albedo (Lecomte et al, 2015)
-!                                ! early melt pnds 0.27, late melt ponds 0.14 Grenfell & Perovich
-! Perovich et al 2002 (Sheba) => the only dataset for which all types of ice/snow were retrieved
-!        rn_alb_sdry = 0.85      ! dry snow
-!        rn_alb_smlt = 0.72      ! melting snow
-!        rn_alb_idry = 0.65      ! bare frozen ice
-! Brandt et al 2005 (East Antarctica)
-!        rn_alb_sdry = 0.87      ! dry snow
-!        rn_alb_smlt = 0.82      ! melting snow
-!        rn_alb_idry = 0.54      ! bare frozen ice
-! 
-         ! Computation of snow-free ice albedo 
+         !
+         !
+         !           !------------------------------------------
+      CASE( 1 )      !  New parameterization (2016)            !    (based on overcast sky values)
+         !           !------------------------------------------
+         !
+         !                    compilation of values from literature (reference overcast sky values)
+         !                          rn_alb_sdry = 0.85      ! dry snow
+         !                          rn_alb_smlt = 0.75      ! melting snow
+         !                          rn_alb_idry = 0.60      ! bare frozen ice
+         !                          rn_alb_dpnd = 0.36      ! ponded-ice overcast albedo (Lecomte et al, 2015)
+         !                                                  ! early melt pnds 0.27, late melt ponds 0.14 Grenfell & Perovich
+         !                    Perovich et al 2002 (Sheba) => the only dataset for which all types of ice/snow were retrieved
+         !                          rn_alb_sdry = 0.85      ! dry snow
+         !                          rn_alb_smlt = 0.72      ! melting snow
+         !                          rn_alb_idry = 0.65      ! bare frozen ice
+         !                    Brandt et al 2005 (East Antarctica)
+         !                          rn_alb_sdry = 0.87      ! dry snow
+         !                          rn_alb_smlt = 0.82      ! melting snow
+         !                          rn_alb_idry = 0.54      ! bare frozen ice
+         ! 
+         !              !--- Computation of snow-free ice albedo 
          z1_c1 = 1. / ( LOG(1.5) - LOG(0.05) ) 
          z1_c2 = 1. / 0.05
 
-         ! Accounting for the ice-thickness dependency
-         WHERE     ( 1.5  < ph_ice                     )        ;  zalb_it = zalb
-         ELSE WHERE( 0.05 < ph_ice .AND. ph_ice <= 1.5 )        ;  zalb_it = zalb     + ( 0.18 - zalb     ) * z1_c1 *  &
-            &                                                                     ( LOG(1.5) - LOG(ph_ice) )
-         ELSE WHERE                                             ;  zalb_it = rn_alb_oce + ( 0.18 - rn_alb_oce ) * z1_c2 * ph_ice
-         END WHERE
-
-         IF ( ld_pnd ) THEN
-            ! Depth-dependent ponded ice albedo
-            zhref_pnd = 0.05        ! Characteristic length scale for thickness dependence of ponded ice albedo, Lecomte et al (2015)
-            zalb_pnd  = rn_alb_dpnd - ( rn_alb_dpnd - zalb_it ) * EXP( - ph_pnd / zhref_pnd ) 
-
-            ! Snow-free ice albedo is weighted mean of ponded ice and bare ice contributions
-            WHERE ( ph_snw == 0._wp .AND. pt_ice >= rt0_ice )   ;  zalb_it = zalb_it * ( 1. - pafrac_pnd  ) + zalb_pnd * pafrac_pnd ;  END WHERE
+         !              !--- Accounting for the ice-thickness dependency
+         WHERE     ( 1.5  < ph_ice                     )   ;   zalb_it = zalb
+         ELSE WHERE( 0.05 < ph_ice .AND. ph_ice <= 1.5 )   ;   zalb_it = zalb + ( 0.18 - zalb ) * z1_c1 * ( LOG(1.5) - LOG(ph_ice) )
+         ELSE WHERE                                        ;   zalb_it = rn_alb_oce + ( 0.18 - rn_alb_oce ) * z1_c2 * ph_ice
+         END WHERE
+         !
+         IF ( ld_pnd ) THEN      ! Depth-dependent ponded ice albedo
+            z1_href_pnd = 0.05        ! inverse of the characteristic length scale (Lecomte et al. 2015)
+            zalb_pnd  = rn_alb_dpnd - ( rn_alb_dpnd - zalb_it ) * EXP( - ph_pnd * z1_href_pnd ) 
+            !
+            !                    ! Snow-free ice albedo is weighted mean of ponded ice and bare ice contributions
+            WHERE ( ph_snw == 0._wp .AND. pt_ice >= rt0_ice )
+               zalb_it = zalb_it * ( 1. - pafrac_pnd  ) + zalb_pnd * pafrac_pnd
+            END WHERE
          ENDIF 
-
+         !
+         !              !--- Overcast sky surface albedo (accounting for snow, ice melt ponds)
          z1_c1 = 1. / 0.02
          z1_c2 = 1. / 0.03
-         
-         ! Overcast sky surface albedo (accounting for snow, ice melt ponds)
          DO jl = 1, jpl
             DO jj = 1, jpj
@@ -241,69 +237,62 @@
             END DO
          END DO
-
-         ! Clear sky surface albedo
+         !
+         !              !--- Clear sky surface albedo
          pa_ice_cs = pa_ice_os - ( - 0.1010 * pa_ice_os * pa_ice_os + 0.1933 * pa_ice_os - 0.0148 ); 
-
-      !---------------------------------------------------
-      !  Fractional surface-based parameterization (2017)
-      !---------------------------------------------------
-      CASE( 2 ) 
- 
-      ! MV: I propose this formulation that is more elegant, and more easy to expand towards
-      !     varying pond and snow fraction.
-      !     Formulation 1 has issues to handle ponds and snow together that
-      !     can't easily be fixed. This one handles it better, I believe.
-
-          !-----------------------------------------
-          ! Snow, bare ice and ponded ice fractions 
-          !-----------------------------------------
-          ! Specific fractions (zafrac) refer to relative area covered by snow within each ice category
-
-          !--- Effective pond fraction (for now, we prevent melt ponds and snow at the same time)
-          zafrac_pnd = 0._wp
-          IF ( ld_pnd ) THEN  
-             WHERE( ph_snw == 0._wp ) ;  zafrac_pnd = pafrac_pnd ;  END WHERE  ! Snow fully "shades" melt ponds
-          ENDIF         
-
-          !--- Specific snow fraction (for now, prescribed)
-          WHERE     ( ph_snw > 0._wp     ) ;  zafrac_snw = 1.
-          ELSE WHERE                       ;  zafrac_snw = 0.
-          END WHERE
- 
-          !--- Specific ice fraction 
-          zafrac_ice = 1. - zafrac_snw - zafrac_pnd
- 
-          !--------------------------------------------------
-          ! Snow-covered, pond-covered, and bare ice albedos
-          !--------------------------------------------------
-          ! Bare ice albedo
-          z1_c1 = 1. / ( LOG(1.5) - LOG(0.05) ) 
-          z1_c2 = 1. / 0.05
-          WHERE     ( 1.5  < ph_ice                     )  ;  zalb_ice = zalb
-          ELSE WHERE( 0.05 < ph_ice .AND. ph_ice <= 1.5 )  ;  zalb_ice = zalb     + ( 0.18 - zalb     ) * z1_c1 *  &
+         !
+         !
+         !           !------------------------------------------
+      CASE( 2 )      !  Fractional surface-based parameterization (2017)
+         !           !------------------------------------------
+         !              MV: I propose this formulation that is more elegant, and more easy to expand towards
+         !              varying pond and snow fraction.
+         !              Formulation 1 has issues to handle ponds and snow together that can't easily be fixed. 
+         !              This one handles it better, I believe.
+         !
+         !                 !==  Snow, bare ice and ponded ice fractions  ==!
+         !
+         !                       ! Specific fractions (zafrac) refer to relative area covered by snow within each ice category
+         !
+         !                       !--- Effective pond fraction (for now, we prevent melt ponds and snow at the same time)
+         zafrac_pnd = 0._wp
+         IF ( ld_pnd ) THEN  
+            WHERE( ph_snw == 0._wp ) ;  zafrac_pnd = pafrac_pnd ;  END WHERE  ! Snow fully "shades" melt ponds
+         ENDIF         
+         !
+         !                       !--- Specific snow fraction (for now, prescribed)
+         WHERE     ( ph_snw > 0._wp     ) ;  zafrac_snw = 1.
+         ELSE WHERE                       ;  zafrac_snw = 0.
+         END WHERE
+         !
+         !                       !--- Specific ice fraction 
+         zafrac_ice = 1. - zafrac_snw - zafrac_pnd
+         !
+         !                 !==  Snow-covered, pond-covered, and bare ice albedos  ==!
+         !
+         !                       !--- Bare ice albedo
+         z1_c1 = 1. / ( LOG(1.5) - LOG(0.05) ) 
+         z1_c2 = 1. / 0.05
+         WHERE     ( 1.5  < ph_ice                     )  ;  zalb_ice = zalb
+         ELSE WHERE( 0.05 < ph_ice .AND. ph_ice <= 1.5 )  ;  zalb_ice = zalb     + ( 0.18 - zalb     ) * z1_c1 *  &
             &                                                                       ( LOG(1.5) - LOG(ph_ice) )
-          ELSE WHERE                                       ;  zalb_ice = rn_alb_oce + ( 0.18 - rn_alb_oce ) * z1_c2 * ph_ice
-          END WHERE
-
-          ! Snow-covered ice albedo (freezing, melting cases)
-          z1_c1 = 1. / 0.02
-          z1_c2 = 1. / 0.03
-         
-          WHERE( pt_ice < rt0_snow ) ; zalb_snw = rn_alb_sdry - ( rn_alb_sdry - zalb_ice ) * EXP( - ph_snw * z1_c1 );
-          ELSE WHERE                 ; zalb_snw = rn_alb_smlt - ( rn_alb_smlt - zalb_ice ) * EXP( - ph_snw * z1_c2 );
-          END WHERE
-
-          ! Depth-dependent ponded ice albedo
-          IF ( ld_pnd ) THEN
-             zhref_pnd = 0.05        ! Characteristic length scale for thickness dependence of ponded ice albedo, Lecomte et al (2015)
-             zalb_pnd  = rn_alb_dpnd - ( rn_alb_dpnd - zalb_ice ) * EXP( - ph_pnd / zhref_pnd ) 
-          ELSE
-             zalb_pnd  = rn_alb_dpnd
-          ENDIF
-
-          ! Surface albedo is weighted mean of snow, ponds and bare ice contributions
-          pa_ice_os = zafrac_snw * zalb_snw  +  zafrac_pnd * zalb_pnd  +  zafrac_ice * zalb_ice
-          
-          pa_ice_cs = pa_ice_os - ( - 0.1010 * pa_ice_os * pa_ice_os + 0.1933 * pa_ice_os - 0.0148 )
+         ELSE WHERE                                       ;  zalb_ice = rn_alb_oce + ( 0.18 - rn_alb_oce ) * z1_c2 * ph_ice
+         END WHERE
+         !
+         z1_c1 = 1. / 0.02       !--- Snow-covered ice albedo (freezing, melting cases)
+         z1_c2 = 1. / 0.03
+         !
+         WHERE( pt_ice < rt0_snow ) ; zalb_snw = rn_alb_sdry - ( rn_alb_sdry - zalb_ice ) * EXP( - ph_snw * z1_c1 );
+         ELSE WHERE                 ; zalb_snw = rn_alb_smlt - ( rn_alb_smlt - zalb_ice ) * EXP( - ph_snw * z1_c2 );
+         END WHERE
+         !
+         IF ( ld_pnd ) THEN      !--- Depth-dependent ponded ice albedo
+            z1_href_pnd = 0.05        ! inverse of the characteristic length scale (Lecomte et al. 2015)
+            zalb_pnd  = rn_alb_dpnd - ( rn_alb_dpnd - zalb_ice ) * EXP( - ph_pnd * z1_href_pnd ) 
+         ELSE
+            zalb_pnd  = rn_alb_dpnd
+         ENDIF
+         !                       !--- Surface albedo is weighted mean of snow, ponds and bare ice contributions
+         pa_ice_os = zafrac_snw * zalb_snw  +  zafrac_pnd * zalb_pnd  +  zafrac_ice * zalb_ice
+         pa_ice_cs = pa_ice_os - ( - 0.1010 * pa_ice_os * pa_ice_os + 0.1933 * pa_ice_os - 0.0148 )
 
       END SELECT
@@ -311,4 +300,5 @@
    END SUBROUTINE ice_alb
 
+
    SUBROUTINE alb_init
       !!----------------------------------------------------------------------
@@ -320,4 +310,5 @@
       !!----------------------------------------------------------------------
       INTEGER  ::   ios                 ! Local integer output status for namelist read
+      !!
       NAMELIST/namicealb/ nn_ice_alb, rn_alb_sdry, rn_alb_smlt, rn_alb_idry, rn_alb_imlt, rn_alb_dpnd
       !!----------------------------------------------------------------------
@@ -353,9 +344,4 @@
    !!   Default option           Dummy module      NO LIM 3.0 sea-ice model
    !!----------------------------------------------------------------------
-CONTAINS
-   !
-   SUBROUTINE ice_alb     ! Dummy routine
-      WRITE(*,*) 'ice_alb: You should not have seen this print! error?'
-   END SUBROUTINE ice_alb
 #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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icecor.F90	(revision 8486)
@@ -9,31 +9,31 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!    ice_cor   : computes update of sea-ice global variables from trend terms
-   !!----------------------------------------------------------------------
-   USE dom_oce
-   USE phycst          ! physical constants
-   USE ice
-   USE ice1D           ! LIM thermodynamic sea-ice variables
-   USE iceitd
-   USE icevar
-   USE icectl          ! control prints
+   !!   'key_lim3'                                       LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!    ice_cor      : computes update of sea-ice global variables from trend terms
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean domain
+   USE phycst         ! physical constants
+   USE ice            ! sea-ice: variable
+   USE ice1D          ! sea-ice: thermodynamic sea-ice variables
+   USE iceitd         ! sea-ice: rebining
+   USE icevar         ! sea-ice: operations
+   USE icectl         ! sea-ice: control prints
    !
-   USE in_out_manager  ! I/O manager
-   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE lbclnk          ! lateral boundary condition - MPP link
-   USE lib_mpp         ! MPP library
-   USE timing          ! Timing
+   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 lib_mpp        ! MPP library
+   USE timing         ! Timing
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   ice_cor
+   PUBLIC   ice_cor   ! called by icestp.F90
 
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: icecor.F90 8378 2017-07-26 13:55:59Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -41,38 +41,40 @@
 CONTAINS
 
-   SUBROUTINE ice_cor( kt , kn )
-      !!-------------------------------------------------------------------
+   SUBROUTINE ice_cor( kt, kn )
+      !!----------------------------------------------------------------------
       !!               ***  ROUTINE ice_cor  ***
       !!               
-      !! ** Purpose :  Computes update of sea-ice global variables at 
-      !!               the end of the dynamics.
-      !!                
-      !!---------------------------------------------------------------------
+      !! ** Purpose :   Computes corrections on sea-ice global variables at 
+      !!              the end of the dynamics.
+      !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt    ! number of iteration
       INTEGER, INTENT(in) ::   kn    ! 1 = after dyn ; 2 = after thermo
+      !
       INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      REAL(wp) ::   zsal
-      REAL(wp) ::   zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
-      !!-------------------------------------------------------------------
-      IF( nn_timing == 1 )  CALL timing_start('icecor')
-
+      REAL(wp) ::   zsal, zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b, zzc
+      !!----------------------------------------------------------------------
+      IF( nn_timing == 1 )   CALL timing_start('icecor')
+      !
       IF( kt == nit000 .AND. lwp .AND. kn == 2 ) THEN
          WRITE(numout,*)
-         WRITE(numout,*)' icecor ' 
-         WRITE(numout,*)' ~~~~~~ '
-      ENDIF
-
-      ! conservation test
-      IF( ln_limdiachk ) CALL ice_cons_hsm(0, 'icecor', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      !----------------------------------------------------------------------
-      ! Constrain the thickness of the smallest category above himin
-      !----------------------------------------------------------------------
-      IF( kn == 2 ) THEN
-         
+         WRITE(numout,*)' icecor :  correct sea ice variables if out of bounds ' 
+         WRITE(numout,*)' ~~~~~~~'
+      ENDIF
+      !                             !--- conservation test
+      IF( ln_limdiachk )   CALL ice_cons_hsm(0, 'icecor', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      !
+      !
+      !                             !-----------------------------------------------------
+      IF( kn == 2 ) THEN            !  thickness of the smallest category above himin    !
+         !                          !-----------------------------------------------------
+         !
          DO jj = 1, jpj 
             DO ji = 1, jpi
+!!gm replace this
                rswitch = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,1) - epsi20 ) )   !0 if no ice and 1 if yes
                ht_i(ji,jj,1) = v_i (ji,jj,1) / MAX( a_i(ji,jj,1) , epsi20 ) * rswitch
+!!gm by more readable coding (not slower coding since already a IF in the loop):
+!               IF( a_i(ji,jj,1) >= epsi20 )   ht_i(ji,jj,1) = v_i (ji,jj,1) / a_i(ji,jj,1)
+!!gm
                IF( v_i(ji,jj,1) > 0._wp .AND. ht_i(ji,jj,1) < rn_himin ) THEN
                   a_i (ji,jj,1) = a_i (ji,jj,1) * ht_i(ji,jj,1) / rn_himin
@@ -80,38 +82,50 @@
             END DO
          END DO
-
-      ENDIF
-         
-      !----------------------------------------------------
-      ! ice concentration should not exceed amax 
-      !-----------------------------------------------------
-      at_i(:,:) = 0._wp
-      DO jl = 1, jpl
+         !
+      ENDIF
+
+      !                             !-----------------------------------------------------
+      at_i(:,:) = a_i(:,:,1)        !  ice concentration should not exceed amax          !
+      DO jl = 2, jpl                !-----------------------------------------------------
          at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
       END DO
-
+      !
+!!gm   Question   it seams to me that we have the following equality (dropping the "(ji,jj)":
+!      ( 1. - ( 1. - rn_amax_2d / at_i ) ) =  ( 1. - ( at_i - rn_amax_2d ) / at_i )
+!                                          =  ( at_i - ( at_i - rn_amax_2d ) ) / at_i
+!                                          =  ( + rn_amax_2d  ) / at_i
+!                                          =  rn_amax_2d / at_i
+!     No ?  if yes see "!!gm   better" juste below 
+!gm
       DO jl  = 1, jpl
          DO jj = 1, jpj
             DO ji = 1, jpi
                IF( at_i(ji,jj) > rn_amax_2d(ji,jj) .AND. a_i(ji,jj,jl) > 0._wp ) THEN
-                  a_i (ji,jj,jl) = a_i (ji,jj,jl) * ( 1._wp - ( 1._wp - rn_amax_2d(ji,jj) / at_i(ji,jj) ) )
+                  a_i(ji,jj,jl) = a_i(ji,jj,jl) * ( 1._wp - ( 1._wp - rn_amax_2d(ji,jj) / at_i(ji,jj) ) )
+!!gm   better:    a_i(ji,jj,jl) = a_i(ji,jj,jl) * rn_amax_2d(ji,jj) / at_i(ji,jj)           
                ENDIF
             END DO
          END DO
       END DO
+!!gm  Other question:  why testing a_i(ji,jj,jl) > 0._wp ?   a_i is >=0, a multiplication by 0 does not change the results....
+!!gm  so at the end, the loop can be recoded without IF as:
+!      WHERE( at_i(:,:) > rn_amax_2d(:,:) )
+!         DO jl  = 1, jpl
+!            a_i(:,:,jl) = a_i(:,:,jl) * MAX( rn_amax_2d(:,:), at_i(:,:) ) / at_i(:,:)
+!         END DO
+!      END WHERE
+!!gm  No?
     
-      !---------------------
-      ! Ice salinity bounds
-      !---------------------
-      IF (  nn_icesal == 2  ) THEN 
-         DO jl = 1, jpl
+      !                             !-----------------------------------------------------
+      IF (  nn_icesal == 2  ) THEN  !  Ice salinity bounds                               !
+      !                             !-----------------------------------------------------
+         zzc = rhoic * r1_rdtice
+         DO jl = 1, jpl                  ! salinity stays in bounds [Simin,Simax]
             DO jj = 1, jpj 
                DO ji = 1, jpi
-                  zsal            = smv_i(ji,jj,jl)
-                  ! salinity stays in bounds
-                  rswitch         = 1._wp - MAX( 0._wp, SIGN( 1._wp, - v_i(ji,jj,jl) ) )
-                  smv_i(ji,jj,jl) = rswitch * MAX( MIN( rn_simax * v_i(ji,jj,jl), smv_i(ji,jj,jl) ), rn_simin * v_i(ji,jj,jl) )
+                  zsal = smv_i(ji,jj,jl)
+                  smv_i(ji,jj,jl) = MIN(  MAX( rn_simin*v_i(ji,jj,jl) , smv_i(ji,jj,jl) ) , rn_simax*v_i(ji,jj,jl)  )
                   ! associated salt flux
-                  sfx_res(ji,jj) = sfx_res(ji,jj) - ( smv_i(ji,jj,jl) - zsal ) * rhoic * r1_rdtice
+                  sfx_res(ji,jj) = sfx_res(ji,jj) - ( smv_i(ji,jj,jl) - zsal ) * zzc
                END DO
             END DO
@@ -119,50 +133,52 @@
       ENDIF
 
-      !----------------------------------------------------
-      ! Rebin categories with thickness out of bounds
-      !----------------------------------------------------
-      IF ( jpl > 1 ) CALL ice_itd_reb
-
-      !-----------------
-      ! zap small values
-      !-----------------
-      CALL ice_var_zapsmall
-
-      !----------------------------------------------
-      ! Ice drift. Corrections to avoid wrong values
-      !----------------------------------------------
-      IF( kn == 2 ) THEN
-         DO jj = 2, jpjm1
+      !                             !-----------------------------------------------------
+      !                             !  Rebin categories with thickness out of bounds     !
+      !                             !-----------------------------------------------------
+      IF ( jpl > 1 )   CALL ice_itd_reb
+
+      !                             !-----------------------------------------------------
+      CALL ice_var_zapsmall         !  Zap small values                                  !
+      !                             !-----------------------------------------------------
+
+      !                             !-----------------------------------------------------
+      IF( kn == 2 ) THEN            !  Ice drift case: Corrections to avoid wrong values !
+         DO jj = 2, jpjm1           !-----------------------------------------------------
             DO ji = 2, jpim1
-               IF ( at_i(ji,jj) == 0._wp ) THEN ! what to do if there is no ice
-                  IF ( at_i(ji+1,jj) == 0._wp ) u_ice(ji,jj)   = 0._wp ! right side
-                  IF ( at_i(ji-1,jj) == 0._wp ) u_ice(ji-1,jj) = 0._wp ! left side
-                  IF ( at_i(ji,jj+1) == 0._wp ) v_ice(ji,jj)   = 0._wp ! upper side
-                  IF ( at_i(ji,jj-1) == 0._wp ) v_ice(ji,jj-1) = 0._wp ! bottom side
+               IF ( at_i(ji,jj) == 0._wp ) THEN    ! what to do if there is no ice
+                  IF ( at_i(ji+1,jj) == 0._wp )   u_ice(ji  ,jj) = 0._wp   ! right side
+                  IF ( at_i(ji-1,jj) == 0._wp )   u_ice(ji-1,jj) = 0._wp   ! left side
+                  IF ( at_i(ji,jj+1) == 0._wp )   v_ice(ji,jj  ) = 0._wp   ! upper side
+                  IF ( at_i(ji,jj-1) == 0._wp )   v_ice(ji,jj-1) = 0._wp   ! bottom side
                ENDIF
             END DO
          END DO
-         !lateral boundary conditions
-         CALL lbc_lnk_multi( u_ice, 'U', -1., v_ice, 'V', -1. )
-         !mask velocities
-         u_ice(:,:) = u_ice(:,:) * umask(:,:,1)
+         CALL lbc_lnk_multi( u_ice, 'U', -1., v_ice, 'V', -1. )            ! lateral boundary conditions
+         !
+!!gm  I think masking here is unnecessary, u_ice already masked and we only introduce zeros in the field
+         u_ice(:,:) = u_ice(:,:) * umask(:,:,1)                            ! mask velocities
          v_ice(:,:) = v_ice(:,:) * vmask(:,:,1)
       ENDIF
-      
-      ! -------------------------------------------------
-      ! Diagnostics
-      ! -------------------------------------------------
-      IF( kn == 1 ) THEN
+
+!!gm I guess the trends are only out on demand 
+!!   So please, only do this is it exite an iom_use of on a these variables
+!!   furthermore, only allocate the diag_ arrays in this case 
+!!   and do the iom_put here so that it is only a local allocation
+!!gm 
+      !                             !-----------------------------------------------------
+      SELECT CASE( kn )             !  Diagnostics                                       !
+      !                             !-----------------------------------------------------
+      CASE( 1 )                        !--- dyn trend diagnostics
          DO jl  = 1, jpl
             afx_dyn(:,:) = afx_dyn(:,:) + ( a_i(:,:,jl) - a_i_b(:,:,jl) ) * r1_rdtice
          END DO
-         
+         !
+!!gm   here I think the number of ice cat is too small to use a SUM instruction...
          DO jj = 1, jpj
             DO ji = 1, jpi            
-               ! heat content variation (W.m-2)
-               diag_heat(ji,jj) = - ( SUM( e_i(ji,jj,1:nlay_i,:) - e_i_b(ji,jj,1:nlay_i,:) ) +  & 
-                  &                   SUM( e_s(ji,jj,1:nlay_s,:) - e_s_b(ji,jj,1:nlay_s,:) )    &
-                  &                 ) * r1_rdtice
-               ! salt, volume
+               !                 ! heat content variation (W.m-2)
+               diag_heat(ji,jj) = - (  SUM( e_i(ji,jj,1:nlay_i,:) - e_i_b(ji,jj,1:nlay_i,:) )    & 
+                  &                  + SUM( e_s(ji,jj,1:nlay_s,:) - e_s_b(ji,jj,1:nlay_s,:) )  ) * r1_rdtice
+               !                 ! salt, volume
                diag_smvi(ji,jj) = SUM( smv_i(ji,jj,:) - smv_i_b(ji,jj,:) ) * rhoic * r1_rdtice
                diag_vice(ji,jj) = SUM( v_i  (ji,jj,:) - v_i_b  (ji,jj,:) ) * rhoic * r1_rdtice
@@ -170,21 +186,20 @@
             END DO
          END DO
-         
-      ELSEIF( kn == 2 ) THEN
-         
+         !
+      CASE( 2 )                        !--- thermo trend diagnostics & ice aging
+         !
          DO jl  = 1, jpl
-            oa_i(:,:,jl) = oa_i(:,:,jl) + a_i(:,:,jl) * rdt_ice          ! ice natural aging
-            afx_thd(:,:) = afx_thd(:,:) + ( a_i(:,:,jl) - a_i_b(:,:,jl) ) * r1_rdtice
-         END DO
-         afx_tot = afx_thd + afx_dyn
-         
+            oa_i(:,:,jl) = oa_i(:,:,jl) +   a_i(:,:,jl)                   * rdt_ice       ! ice natural aging incrementation
+            afx_thd(:,:) = afx_thd(:,:) + ( a_i(:,:,jl) - a_i_b(:,:,jl) ) * r1_rdtice     ! thermo tendancy
+         END DO
+         afx_tot(:,:) = afx_thd(:,:) + afx_dyn(:,:)
+         !
+!!gm   here I think the number of ice cat is too small to use a SUM instruction...
          DO jj = 1, jpj
             DO ji = 1, jpi            
-               ! heat content variation (W.m-2)
-               diag_heat(ji,jj) = diag_heat(ji,jj) -  &
-                  &               ( SUM( e_i(ji,jj,1:nlay_i,:) - e_i_b(ji,jj,1:nlay_i,:) ) +  & 
-                  &                 SUM( e_s(ji,jj,1:nlay_s,:) - e_s_b(ji,jj,1:nlay_s,:) )    &
-                  &               ) * r1_rdtice   
-               ! salt, volume
+               !                 ! heat content variation (W.m-2)
+               diag_heat(ji,jj) = diag_heat(ji,jj) - (  SUM( e_i(ji,jj,1:nlay_i,:) - e_i_b(ji,jj,1:nlay_i,:) )    & 
+                  &                                   + SUM( e_s(ji,jj,1:nlay_s,:) - e_s_b(ji,jj,1:nlay_s,:) )  ) * r1_rdtice
+               !                 ! salt, volume
                diag_smvi(ji,jj) = diag_smvi(ji,jj) + SUM( smv_i(ji,jj,:) - smv_i_b(ji,jj,:) ) * rhoic * r1_rdtice
                diag_vice(ji,jj) = diag_vice(ji,jj) + SUM( v_i  (ji,jj,:) - v_i_b  (ji,jj,:) ) * rhoic * r1_rdtice
@@ -192,20 +207,24 @@
             END DO
          END DO
-         
-      ENDIF
-      
-      ! conservation test
-      IF( ln_limdiachk ) CALL ice_cons_hsm(1, 'icecor', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      ! control prints
-      IF( ln_ctl )       CALL ice_prt3D( 'icecor' )
-      IF( ln_limctl .AND. kn == 2 )  &
-         &               CALL ice_prt( kt, iiceprt, jiceprt, 2, ' - Final state - ' )
-   
-      IF( nn_timing == 1 )  CALL timing_stop('icecor')
-
+         !
+      END SELECT
+      !
+      !                                !--- conservation test
+      IF( ln_limdiachk )   CALL ice_cons_hsm(1, 'icecor', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      !
+      !                                !--- control prints
+      IF( ln_ctl )                    CALL ice_prt3D( 'icecor' )
+      IF( ln_limctl .AND. kn == 2 )   CALL ice_prt( kt, iiceprt, jiceprt, 2, ' - Final state - ' )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('icecor')
+      !
    END SUBROUTINE ice_cor
 
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option           Dummy module      NO LIM 3.0 sea-ice model
+   !!----------------------------------------------------------------------
 #endif
 
+   !!======================================================================
 END MODULE icecor
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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icectl.F90	(revision 8486)
@@ -9,5 +9,5 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!   'key_lim3'                                       LIM3 sea-ice model
    !!----------------------------------------------------------------------
    !!    ice_ctl   : control prints in case of crash
@@ -15,17 +15,17 @@
    !!    ice_prt3D : control prints of ice arrays
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE ice             ! LIM-3: ice variables
-   USE ice1D           ! LIM-3: thermodynamical variables
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice   fields
-   USE phycst          ! Define parameters for the routines
+   USE 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 sbc_oce        ! Surface boundary condition: ocean fields
+   USE sbc_ice        ! Surface boundary condition: ice   fields
+   USE phycst         ! Define parameters for the routines
    !
-   USE lib_mpp         ! MPP library
-   USE timing          ! Timing
-   USE in_out_manager  ! I/O manager
-   USE prtctl          ! Print control
-   USE lib_fortran     ! 
+   USE lib_mpp        ! MPP library
+   USE timing         ! Timing
+   USE in_out_manager ! I/O manager
+   USE prtctl         ! Print control
+   USE lib_fortran    ! 
 
    IMPLICIT NONE
@@ -41,14 +41,13 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: icectl.F90 5043 2015-01-28 16:44:18Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
    SUBROUTINE ice_cons_hsm( icount, cd_routine, zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b )
-      !!--------------------------------------------------------------------------------------------------------
-      !!                                        ***  ROUTINE ice_cons_hsm ***
+      !!----------------------------------------------------------------------
+      !!                       ***  ROUTINE ice_cons_hsm ***
       !!
       !! ** Purpose : Test the conservation of heat, salt and mass for each ice routine
@@ -61,8 +60,9 @@
       !!              For salt and heat thresholds, ice is considered to have a salinity of 10 
       !!              and a heat content of 3e5 J/kg (=latent heat of fusion) 
-      !!--------------------------------------------------------------------------------------------------------
-      INTEGER         , INTENT(in)    :: icount        ! determine wether this is the beggining of the routine (0) or the end (1)
-      CHARACTER(len=*), INTENT(in)    :: cd_routine    ! name of the routine
-      REAL(wp)        , INTENT(inout) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
+      !!----------------------------------------------------------------------
+      INTEGER         , INTENT(in)    ::   icount        ! called at: =0 the begining of the routine, =1  the end
+      CHARACTER(len=*), INTENT(in)    ::   cd_routine    ! name of the routine
+      REAL(wp)        , INTENT(inout) ::   zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b   ! ????
+      !!
       REAL(wp)                        :: zvi,   zsmv,   zei,   zfs,   zfw,   zft
       REAL(wp)                        :: zvmin, zamin, zamax 
@@ -70,30 +70,33 @@
       REAL(wp)                        :: zarea, zv_sill, zs_sill, zh_sill
       REAL(wp), PARAMETER             :: zconv = 1.e-9 ! convert W to GW and kg to Mt
-
+      !!----------------------------------------------------------------------
+
+!!gm  Note that glo_sum for a 2D or 3D array use a multiplication by tmask_i(ji,jj)
+!!    so below  the  * tmask(:,:,1) is useless   ===>> I have removed them
+!!    I also move the conversion factor from then glo_sum argument (become a single multiplication
+ 
       IF( icount == 0 ) THEN
-
-         ! salt flux
+         !                          ! salt flux
          zfs_b  = glob_sum(  ( sfx_bri(:,:) + sfx_bog(:,:) + sfx_bom(:,:) + sfx_sum(:,:) + sfx_sni(:,:) +  &
             &                  sfx_opw(:,:) + sfx_res(:,:) + sfx_dyn(:,:) + sfx_sub(:,:) + sfx_lam(:,:)    &
-            &                ) *  e1e2t(:,:) * tmask(:,:,1) * zconv )
-
-         ! water flux
+            &                ) *  e1e2t(:,:) ) * zconv 
+         !
+         !                          ! water flux
          zfw_b  = glob_sum( -( wfx_bog(:,:) + wfx_bom(:,:)     + wfx_sum(:,:)     + wfx_sni(:,:)     +                     &
             &                  wfx_opw(:,:) + wfx_res(:,:)     + wfx_dyn(:,:)     + wfx_lam(:,:)     + wfx_ice_sub(:,:) +  &
-            &                  wfx_snw_sni(:,:) + wfx_snw_sum(:,:) + wfx_snw_dyn(:,:) + wfx_snw_sub(:,:) + wfx_spr(:,:)        &
-            &                ) * e1e2t(:,:) * tmask(:,:,1) * zconv )
-
-         ! heat flux
+            &                  wfx_snw_sni(:,:) + wfx_snw_sum(:,:) + wfx_snw_dyn(:,:) + wfx_snw_sub(:,:) + wfx_spr(:,:)    &
+            &                ) * e1e2t(:,:) ) * zconv
+         !
+         !                          ! heat flux
          zft_b  = glob_sum(  ( hfx_sum(:,:) + hfx_bom(:,:) + hfx_bog(:,:) + hfx_dif(:,:) + hfx_opw(:,:) + hfx_snw(:,:)  & 
             &                - hfx_thd(:,:) - hfx_dyn(:,:) - hfx_res(:,:) - hfx_sub(:,:) - hfx_spr(:,:)   &
-            &                ) *  e1e2t(:,:) * tmask(:,:,1) * zconv )
-
-         zvi_b  = glob_sum( SUM( v_i * rhoic + v_s * rhosn, dim=3 ) * e1e2t * tmask(:,:,1) * zconv )
-
-         zsmv_b = glob_sum( SUM( smv_i * rhoic            , dim=3 ) * e1e2t * tmask(:,:,1) * zconv )
-
-         zei_b  = glob_sum( ( SUM( SUM( e_i(:,:,1:nlay_i,:), dim=4 ), dim=3 ) +  &
-            &                 SUM( SUM( e_s(:,:,1:nlay_s,:), dim=4 ), dim=3 )    &
-                            ) * e1e2t * tmask(:,:,1) * zconv )
+            &                ) *  e1e2t(:,:) ) * zconv
+
+         zvi_b  = glob_sum( SUM( v_i * rhoic + v_s * rhosn, dim=3 ) * e1e2t * zconv )
+
+         zsmv_b = glob_sum( SUM( smv_i * rhoic            , dim=3 ) * e1e2t * zconv )
+
+         zei_b  = glob_sum( (  SUM( SUM( e_i(:,:,1:nlay_i,:), dim=4 ), dim=3 )     &
+            &                + SUM( SUM( e_s(:,:,1:nlay_s,:), dim=4 ), dim=3 )   ) * e1e2t ) * zconv
 
       ELSEIF( icount == 1 ) THEN
@@ -102,5 +105,5 @@
          zfs  = glob_sum(  ( sfx_bri(:,:) + sfx_bog(:,:) + sfx_bom(:,:) + sfx_sum(:,:) + sfx_sni(:,:) +  &
             &                sfx_opw(:,:) + sfx_res(:,:) + sfx_dyn(:,:) + sfx_sub(:,:) + sfx_lam(:,:)    & 
-            &              ) * e1e2t(:,:) * tmask(:,:,1) * zconv ) - zfs_b
+            &              ) * e1e2t(:,:) ) * zconv - zfs_b
 
          ! water flux
@@ -108,25 +111,25 @@
             &                wfx_opw(:,:) + wfx_res(:,:)     + wfx_dyn(:,:)     + wfx_lam(:,:)     + wfx_ice_sub(:,:) +  &
             &                wfx_snw_sni(:,:) + wfx_snw_sum(:,:) + wfx_snw_dyn(:,:) + wfx_snw_sub(:,:) + wfx_spr(:,:)        &
-            &              ) * e1e2t(:,:) * tmask(:,:,1) * zconv ) - zfw_b
+            &              ) * e1e2t(:,:) ) * zconv - zfw_b
 
          ! heat flux
          zft  = glob_sum(  ( hfx_sum(:,:) + hfx_bom(:,:) + hfx_bog(:,:) + hfx_dif(:,:) + hfx_opw(:,:) + hfx_snw(:,:)  & 
             &              - hfx_thd(:,:) - hfx_dyn(:,:) - hfx_res(:,:) - hfx_sub(:,:) - hfx_spr(:,:)   &
-            &              ) * e1e2t(:,:) * tmask(:,:,1) * zconv ) - zft_b
+            &              ) * e1e2t(:,:) ) * zconv - zft_b
  
          ! outputs
-         zvi  = ( ( glob_sum( SUM( v_i * rhoic + v_s * rhosn, dim=3 )  &
-            &                    * e1e2t * tmask(:,:,1) * zconv ) - zvi_b ) * r1_rdtice - zfw ) * rday
-
-         zsmv = ( ( glob_sum( SUM( smv_i * rhoic            , dim=3 )  &
-            &                    * e1e2t * tmask(:,:,1) * zconv ) - zsmv_b ) * r1_rdtice + zfs ) * rday
-
-         zei  = ( glob_sum( ( SUM( SUM( e_i(:,:,1:nlay_i,:), dim=4 ), dim=3 ) +  &
-            &                 SUM( SUM( e_s(:,:,1:nlay_s,:), dim=4 ), dim=3 )    &
-            &                ) * e1e2t * tmask(:,:,1) * zconv ) - zei_b ) * r1_rdtice + zft
+         zvi  = ( ( glob_sum( SUM( v_i * rhoic + v_s * rhosn, dim=3 ) * e1e2t  ) * zconv  &
+            &       - zvi_b ) * r1_rdtice - zfw ) * rday
+
+         zsmv = ( ( glob_sum( SUM( smv_i * rhoic            , dim=3 ) * e1e2t ) * zconv  &
+            &       - zsmv_b ) * r1_rdtice + zfs ) * rday
+
+         zei  = ( glob_sum( (  SUM( SUM( e_i(:,:,1:nlay_i,:), dim=4 ), dim=3 )   &
+            &                + SUM( SUM( e_s(:,:,1:nlay_s,:), dim=4 ), dim=3 ) ) * e1e2t ) * zconv   &
+            &   - zei_b ) * r1_rdtice + zft
 
          ! zvtrp and zetrp must be close to 0 if the advection scheme is conservative
-         zvtrp = glob_sum( ( diag_trp_vi * rhoic + diag_trp_vs * rhosn ) * e1e2t * tmask(:,:,1) * zconv ) * rday 
-         zetrp = glob_sum( ( diag_trp_ei         + diag_trp_es         ) * e1e2t * tmask(:,:,1) * zconv )
+         zvtrp = glob_sum( ( diag_trp_vi * rhoic + diag_trp_vs * rhosn ) * e1e2t  ) * zconv * rday 
+         zetrp = glob_sum( ( diag_trp_ei         + diag_trp_es         ) * e1e2t  ) * zconv
 
          zvmin = glob_min( v_i )
@@ -135,5 +138,5 @@
 
          ! set threshold values and calculate the ice area (+epsi10 to set a threshold > 0 when there is no ice) 
-         zarea   = glob_sum( SUM( a_i + epsi10, dim=3 ) * e1e2t * zconv ) ! in 1.e9 m2
+         zarea   = glob_sum( SUM( a_i + epsi10, dim=3 ) * e1e2t ) * zconv ! in 1.e9 m2
          zv_sill = zarea * 2.5e-5
          zs_sill = zarea * 25.e-5
@@ -156,5 +159,5 @@
             IF (      zamin  < -epsi10 ) WRITE(numout,*) 'violation a_i<0               (',cd_routine,') = ',zamin
          ENDIF
-
+         !
       ENDIF
 
@@ -163,6 +166,6 @@
 
    SUBROUTINE ice_cons_final( cd_routine )
-      !!---------------------------------------------------------------------------------------------------------
-      !!                                   ***  ROUTINE ice_cons_final ***
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE ice_cons_final ***
       !!
       !! ** Purpose : Test the conservation of heat, salt and mass at the end of each ice time-step
@@ -174,29 +177,32 @@
       !!              For salt and heat thresholds, ice is considered to have a salinity of 10 
       !!              and a heat content of 3e5 J/kg (=latent heat of fusion) 
-      !!--------------------------------------------------------------------------------------------------------
+      !!----------------------------------------------------------------------
       CHARACTER(len=*), INTENT(in)    :: cd_routine    ! name of the routine
       REAL(wp)                        :: zhfx, zsfx, zvfx
       REAL(wp)                        :: zarea, zv_sill, zs_sill, zh_sill
       REAL(wp), PARAMETER             :: zconv = 1.e-9 ! convert W to GW and kg to Mt
+      !!----------------------------------------------------------------------
 
       ! heat flux
       zhfx  = glob_sum( ( hfx_in - hfx_out - diag_heat - diag_trp_ei - diag_trp_es   &
       !  &              - SUM( qevap_ice * a_i_b, dim=3 )                           & !!clem: I think this line must be commented (but need check)
-         &              ) * e1e2t * tmask(:,:,1) * zconv ) 
+         &              ) * e1e2t ) * zconv
       ! salt flux
-      zsfx  = glob_sum( ( sfx + diag_smvi ) * e1e2t * tmask(:,:,1) * zconv ) * rday
+      zsfx  = glob_sum( ( sfx + diag_smvi ) * e1e2t ) * zconv * rday
       ! water flux
-      zvfx  = glob_sum( ( wfx_ice + wfx_snw + wfx_spr + wfx_sub + diag_vice + diag_vsnw ) * e1e2t * tmask(:,:,1) * zconv ) * rday
+      zvfx  = glob_sum( ( wfx_ice + wfx_snw + wfx_spr + wfx_sub + diag_vice + diag_vsnw ) * e1e2t ) * zconv * rday
 
       ! set threshold values and calculate the ice area (+epsi10 to set a threshold > 0 when there is no ice) 
-      zarea   = glob_sum( SUM( a_i + epsi10, dim=3 ) * e1e2t * zconv ) ! in 1.e9 m2
+      zarea   = glob_sum( SUM( a_i + epsi10, dim=3 ) * e1e2t ) * zconv ! in 1.e9 m2
       zv_sill = zarea * 2.5e-5
       zs_sill = zarea * 25.e-5
       zh_sill = zarea * 10.e-5
 
-      IF( ABS( zvfx ) > zv_sill ) WRITE(numout,*) 'violation vfx    [Mt/day]       (',cd_routine,')  = ',(zvfx)
-      IF( ABS( zsfx ) > zs_sill ) WRITE(numout,*) 'violation sfx    [psu*Mt/day]   (',cd_routine,')  = ',(zsfx)
-      IF( ABS( zhfx ) > zh_sill ) WRITE(numout,*) 'violation hfx    [GW]           (',cd_routine,')  = ',(zhfx)
-
+      IF(lwp) THEN
+         IF( ABS( zvfx ) > zv_sill )   WRITE(numout,*) 'violation vfx    [Mt/day]       (',cd_routine,')  = ',(zvfx)
+         IF( ABS( zsfx ) > zs_sill )   WRITE(numout,*) 'violation sfx    [psu*Mt/day]   (',cd_routine,')  = ',(zsfx)
+         IF( ABS( zhfx ) > zh_sill )   WRITE(numout,*) 'violation hfx    [GW]           (',cd_routine,')  = ',(zhfx)
+      ENDIF
+      !
    END SUBROUTINE ice_cons_final
 
@@ -671,12 +677,6 @@
    !!   Default option         Empty Module               No LIM3 sea-ice model
    !!--------------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE ice_ctl     ! Empty routine
-   END SUBROUTINE ice_ctl
-   SUBROUTINE ice_prt     ! Empty routine
-   END SUBROUTINE ice_prt
-   SUBROUTINE ice_prt3D   ! Empty routine
-   END SUBROUTINE ice_prt3D
 #endif
+
    !!======================================================================
 END MODULE icectl
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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icedia.F90	(revision 8486)
@@ -1,8 +1,9 @@
 MODULE icedia
    !!======================================================================
-   !!                       ***  MODULE limdia_hsb   ***
-   !!  LIM-3 sea ice model :   diagnostics of ice model 
+   !!                       ***  MODULE icedia  ***
+   !!  Sea-Ice model :   global budgets 
    !!======================================================================
    !! History :  3.4  ! 2012-10  (C. Rousset)  original code
+   !!            4.0  ! 2017-08  (C. Rousset)  fits nemo4.0 standards
    !!----------------------------------------------------------------------
 #if defined key_lim3
@@ -10,18 +11,20 @@
    !!   'key_lim3'                                       LIM3 sea-ice model
    !!----------------------------------------------------------------------
-   !!   lim_dia_hsb        : computation and output of the time evolution of keys variables
-   !!   lim_dia_hsb_init   : initialization and namelist read
-   !!----------------------------------------------------------------------
-   USE ice             ! LIM-3: sea-ice variable
-   USE dom_oce         ! ocean domain
-   USE sbc_oce, ONLY: sfx         ! surface boundary condition: ocean fields
-   USE daymod          ! model calendar
-   USE phycst          ! physical constant
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! MPP library
-   USE timing          ! preformance summary
-   USE iom             ! I/O manager
-   USE lib_fortran     ! glob_sum
-   USE icerst          ! ice restart
+   !!    ice_dia      : diagnostic of the sea-ice global heat content, salt content and volume conservation
+   !!    ice_dia_init : initialization of budget calculation
+   !!    ice_dia_rst  : read/write budgets restart
+   !!----------------------------------------------------------------------
+   USE ice            ! LIM-3: sea-ice variable
+   USE dom_oce        ! ocean domain
+   USE phycst         ! physical constant
+   USE daymod         ! model calendar
+   USE sbc_oce , ONLY : sfx   ! surface boundary condition: ocean fields
+   USE icerst         ! ice restart
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE timing         ! preformance summary
+   USE iom            ! I/O manager
+   USE lib_fortran    ! glob_sum
 
    IMPLICIT NONE
@@ -36,11 +39,9 @@
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.4 , NEMO Consortium (2012)
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: icedia.F90 8413 2017-08-07 17:05:39Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -49,11 +50,13 @@
       !!                  ***  ROUTINE ice_dia  ***
       !!     
-      !! ** Purpose: Compute the ice global heat content, salt content and volume conservation
-      !!	
-      !!---------------------------------------------------------------------------
-      INTEGER, INTENT(in) :: kt    ! number of iteration
-      !!
-      real(wp)   ::   zbg_ivol, zbg_svol, zbg_area, zbg_isal, zbg_item ,zbg_stem
-      REAL(wp)   ::   z_frc_voltop, z_frc_volbot, z_frc_sal, z_frc_temtop, z_frc_tembot  
+      !! ** Purpose:   Compute the sea-ice global heat content, salt content 
+      !!             and volume conservation
+      !!---------------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time step 
+      !!
+      REAL(wp)   ::   zbg_ivol, zbg_item, zbg_area, zbg_isal
+      REAL(wp)   ::   zbg_svol, zbg_stem
+      REAL(wp)   ::   z_frc_voltop, z_frc_temtop, z_frc_sal
+      REAL(wp)   ::   z_frc_volbot, z_frc_tembot  
       REAL(wp)   ::   zdiff_vol, zdiff_sal, zdiff_tem  
       !!---------------------------------------------------------------------------
@@ -62,26 +65,28 @@
       IF( kt == nit000 .AND. lwp ) THEN
          WRITE(numout,*)
-         WRITE(numout,*)'icedia'
+         WRITE(numout,*)'icedia : outpout ice diagnostics (integrated over the domain)'
          WRITE(numout,*)'~~~~~~'
       ENDIF
 
+!!gm glob_sum includes a " * tmask_i ", so remove  " * tmask(:,:,1) "
+
       ! ----------------------- !
       ! 1 -  Contents !
       ! ----------------------- !
-      zbg_ivol = glob_sum( vt_i(:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )                  ! ice volume (km3)
-      zbg_svol = glob_sum( vt_s(:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )                  ! snow volume (km3)
-      zbg_area = glob_sum( at_i(:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-6 )                  ! area (km2)
-      zbg_isal = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 ) ! salt content (pss*km3)
-      zbg_item = glob_sum( et_i * e1e2t(:,:) * tmask(:,:,1) * 1.e-20 )                      ! heat content (1.e20 J)
-      zbg_stem = glob_sum( et_s * e1e2t(:,:) * tmask(:,:,1) * 1.e-20 )                      ! heat content (1.e20 J)
+      zbg_ivol = glob_sum( vt_i(:,:) * e1e2t(:,:) ) * 1.e-9                  ! ice volume (km3)
+      zbg_svol = glob_sum( vt_s(:,:) * e1e2t(:,:) ) * 1.e-9                  ! snow volume (km3)
+      zbg_area = glob_sum( at_i(:,:) * e1e2t(:,:) ) * 1.e-6                  ! area (km2)
+      zbg_isal = glob_sum( SUM( smv_i(:,:,:), dim=3 ) * e1e2t(:,:) ) * 1.e-9 ! salt content (pss*km3)
+      zbg_item = glob_sum( et_i * e1e2t(:,:) ) * 1.e-20                      ! heat content (1.e20 J)
+      zbg_stem = glob_sum( et_s * e1e2t(:,:) ) * 1.e-20                      ! heat content (1.e20 J)
       
       ! ---------------------------!
       ! 2 - Trends due to forcing  !
       ! ---------------------------!
-      z_frc_volbot = r1_rau0 * glob_sum( - ( wfx_ice(:,:) + wfx_snw(:,:) + wfx_err_sub(:,:) ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )  ! freshwater flux ice/snow-ocean 
-      z_frc_voltop = r1_rau0 * glob_sum( - ( wfx_sub(:,:) + wfx_spr(:,:) ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )                     ! freshwater flux ice/snow-atm
-      z_frc_sal    = r1_rau0 * glob_sum( - sfx(:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )                                            ! salt fluxes ice/snow-ocean
-      z_frc_tembot =           glob_sum( hfx_out(:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-20 )                                         ! heat on top of ocean (and below ice)
-      z_frc_temtop =           glob_sum( hfx_in (:,:) * e1e2t(:,:) * tmask(:,:,1) * 1.e-20 )                                         ! heat on top of ice-coean
+      z_frc_volbot = r1_rau0 * glob_sum( - ( wfx_ice(:,:) + wfx_snw(:,:) + wfx_err_sub(:,:) ) * e1e2t(:,:) ) * 1.e-9  ! freshwater flux ice/snow-ocean 
+      z_frc_voltop = r1_rau0 * glob_sum( - ( wfx_sub(:,:) + wfx_spr(:,:) ) * e1e2t(:,:) ) * 1.e-9                     ! freshwater flux ice/snow-atm
+      z_frc_sal    = r1_rau0 * glob_sum(   - sfx(:,:) * e1e2t(:,:) ) * 1.e-9                                          ! salt fluxes ice/snow-ocean
+      z_frc_tembot =           glob_sum( hfx_out(:,:) * e1e2t(:,:) ) * 1.e-20                                         ! heat on top of ocean (and below ice)
+      z_frc_temtop =           glob_sum( hfx_in (:,:) * e1e2t(:,:) ) * 1.e-20                                         ! heat on top of ice-coean
       !
       frc_voltop  = frc_voltop  + z_frc_voltop  * rdt_ice ! km3
@@ -94,11 +99,8 @@
       ! 3 -  Content variations !
       ! ----------------------- !
-      zdiff_vol = r1_rau0 * glob_sum( ( rhoic * vt_i(:,:) + rhosn * vt_s(:,:) - vol_loc_ini(:,:)  &  ! freshwater trend (km3) 
-         &                            ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 ) 
-      zdiff_sal = r1_rau0 * glob_sum( ( rhoic * SUM( smv_i(:,:,:), dim=3 ) - sal_loc_ini(:,:)     &  ! salt content trend (km3*pss)
-         &                            ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-9 )
-      zdiff_tem =           glob_sum( ( et_i(:,:) + et_s(:,:) - tem_loc_ini(:,:)                  &  ! heat content trend (1.e20 J)
-      !  &                            + SUM( qevap_ice * a_i_b, dim=3 ) &     !! clem: I think this line should be commented (but needs a check)
-         &                            ) * e1e2t(:,:) * tmask(:,:,1) * 1.e-20 )
+      zdiff_vol = r1_rau0 * glob_sum( ( rhoic*vt_i(:,:) + rhosn*vt_s(:,:) - vol_loc_ini(:,:) ) * e1e2t(:,:) ) * 1.e-9 ! freshwater trend (km3) 
+      zdiff_sal = r1_rau0 * glob_sum( ( rhoic* SUM( smv_i(:,:,:), dim=3 ) - sal_loc_ini(:,:) ) * e1e2t(:,:) ) * 1.e-9 ! salt content trend (km3*pss)
+      zdiff_tem =           glob_sum( ( et_i(:,:) + et_s(:,:)             - tem_loc_ini(:,:) ) * e1e2t(:,:) ) * 1.e-20 ! heat content trend (1.e20 J)
+      !                               + SUM( qevap_ice * a_i_b, dim=3 )       !! clem: I think this term should not be there (but needs a check)
 
       ! ----------------------- !
@@ -112,27 +114,32 @@
       ! 5 - Diagnostics writing !
       ! ----------------------- !
-      !
-      IF( iom_use('ibgvolume') )  CALL iom_put( 'ibgvolume' , zdiff_vol        )   ! ice/snow volume  drift            (km3 equivalent ocean water)         
-      IF( iom_use('ibgsaltco') )  CALL iom_put( 'ibgsaltco' , zdiff_sal        )   ! ice salt content drift            (psu*km3 equivalent ocean water)
-      IF( iom_use('ibgheatco') )  CALL iom_put( 'ibgheatco' , zdiff_tem        )   ! ice/snow heat content drift       (1.e20 J)
-      IF( iom_use('ibgheatfx') )  CALL iom_put( 'ibgheatfx' , zdiff_tem /      &   ! ice/snow heat flux drift          (W/m2)
-         &                                                    glob_sum( e1e2t(:,:) * tmask(:,:,1) * 1.e-20 * kt*rdt ) )
-
-      IF( iom_use('ibgfrcvoltop') )  CALL iom_put( 'ibgfrcvoltop' , frc_voltop )   ! vol  forcing ice/snw-atm          (km3 equivalent ocean water) 
-      IF( iom_use('ibgfrcvolbot') )  CALL iom_put( 'ibgfrcvolbot' , frc_volbot )   ! vol  forcing ice/snw-ocean        (km3 equivalent ocean water) 
-      IF( iom_use('ibgfrcsal') )     CALL iom_put( 'ibgfrcsal'    , frc_sal    )   ! sal - forcing                     (psu*km3 equivalent ocean water)   
-      IF( iom_use('ibgfrctemtop') )  CALL iom_put( 'ibgfrctemtop' , frc_temtop )   ! heat on top of ice/snw/ocean      (1.e20 J)   
-      IF( iom_use('ibgfrctembot') )  CALL iom_put( 'ibgfrctembot' , frc_tembot )   ! heat on top of ocean(below ice)   (1.e20 J)   
-      IF( iom_use('ibgfrchfxtop') )  CALL iom_put( 'ibgfrchfxtop' , frc_temtop / & ! heat on top of ice/snw/ocean      (W/m2) 
-         &                                                    glob_sum( e1e2t(:,:) * tmask(:,:,1) * 1.e-20 * kt*rdt ) )
-      IF( iom_use('ibgfrchfxbot') )  CALL iom_put( 'ibgfrchfxbot' , frc_tembot / & ! heat on top of ocean(below ice)   (W/m2) 
-         &                                                    glob_sum( e1e2t(:,:) * tmask(:,:,1) * 1.e-20 * kt*rdt ) )
-
-      IF( iom_use('ibgvol_tot' ) )  CALL iom_put( 'ibgvol_tot'  , zbg_ivol     )   ! ice volume                        (km3)
-      IF( iom_use('sbgvol_tot' ) )  CALL iom_put( 'sbgvol_tot'  , zbg_svol     )   ! snow volume                       (km3)
-      IF( iom_use('ibgarea_tot') )  CALL iom_put( 'ibgarea_tot' , zbg_area     )   ! ice area                          (km2)
-      IF( iom_use('ibgsalt_tot') )  CALL iom_put( 'ibgsalt_tot' , zbg_isal     )   ! ice salinity content              (pss*km3)
-      IF( iom_use('ibgheat_tot') )  CALL iom_put( 'ibgheat_tot' , zbg_item     )   ! ice heat content                  (1.e20 J)
-      IF( iom_use('sbgheat_tot') )  CALL iom_put( 'sbgheat_tot' , zbg_stem     )   ! snow heat content                 (1.e20 J)
+!!gm I don't understand the division by the ocean surface (i.e. glob_sum( e1e2t(:,:) ) * 1.e-20 * kt*rdt )
+!!   and its multiplication bu kt ! is it really what we want ? what is this quantity ?
+!!   IF it is really what we want, compute it at kt=nit000, not 3 time by time-step !
+!!   kt*rdt  : you mean rdtice ?
+!!gm
+      !
+      IF( iom_use('ibgvolume')    )   CALL iom_put( 'ibgvolume' , zdiff_vol     )   ! ice/snow volume  drift            (km3 equivalent ocean water)         
+      IF( iom_use('ibgsaltco')    )   CALL iom_put( 'ibgsaltco' , zdiff_sal     )   ! ice salt content drift            (psu*km3 equivalent ocean water)
+      IF( iom_use('ibgheatco')    )   CALL iom_put( 'ibgheatco' , zdiff_tem     )   ! ice/snow heat content drift       (1.e20 J)
+      IF( iom_use('ibgheatfx')    )   CALL iom_put( 'ibgheatfx' ,               &   ! ice/snow heat flux drift          (W/m2)
+         &                                                     zdiff_tem /glob_sum( e1e2t(:,:) * 1.e-20 * kt*rdt ) )
+
+      IF( iom_use('ibgfrcvoltop') )   CALL iom_put( 'ibgfrcvoltop' , frc_voltop )   ! vol  forcing ice/snw-atm          (km3 equivalent ocean water) 
+      IF( iom_use('ibgfrcvolbot') )   CALL iom_put( 'ibgfrcvolbot' , frc_volbot )   ! vol  forcing ice/snw-ocean        (km3 equivalent ocean water) 
+      IF( iom_use('ibgfrcsal')    )   CALL iom_put( 'ibgfrcsal'    , frc_sal    )   ! sal - forcing                     (psu*km3 equivalent ocean water)   
+      IF( iom_use('ibgfrctemtop') )   CALL iom_put( 'ibgfrctemtop' , frc_temtop )   ! heat on top of ice/snw/ocean      (1.e20 J)   
+      IF( iom_use('ibgfrctembot') )   CALL iom_put( 'ibgfrctembot' , frc_tembot )   ! heat on top of ocean(below ice)   (1.e20 J)   
+      IF( iom_use('ibgfrchfxtop') )   CALL iom_put( 'ibgfrchfxtop' ,            &   ! heat on top of ice/snw/ocean      (W/m2) 
+         &                                                          frc_temtop / glob_sum( e1e2t(:,:) ) * 1.e-20 * kt*rdt  )
+      IF( iom_use('ibgfrchfxbot') )   CALL iom_put( 'ibgfrchfxbot' ,            &   ! heat on top of ocean(below ice)   (W/m2) 
+         &                                                          frc_tembot / glob_sum( e1e2t(:,:) ) * 1.e-20 * kt*rdt  )
+
+      IF( iom_use('ibgvol_tot' )  )   CALL iom_put( 'ibgvol_tot'  , zbg_ivol     )   ! ice volume                       (km3)
+      IF( iom_use('sbgvol_tot' )  )   CALL iom_put( 'sbgvol_tot'  , zbg_svol     )   ! snow volume                      (km3)
+      IF( iom_use('ibgarea_tot')  )   CALL iom_put( 'ibgarea_tot' , zbg_area     )   ! ice area                         (km2)
+      IF( iom_use('ibgsalt_tot')  )   CALL iom_put( 'ibgsalt_tot' , zbg_isal     )   ! ice salinity content             (pss*km3)
+      IF( iom_use('ibgheat_tot')  )   CALL iom_put( 'ibgheat_tot' , zbg_item     )   ! ice heat content                 (1.e20 J)
+      IF( iom_use('sbgheat_tot')  )   CALL iom_put( 'sbgheat_tot' , zbg_stem     )   ! snow heat content                (1.e20 J)
       !
       IF( lrst_ice )   CALL ice_dia_rst( 'WRITE', kt_ice )
@@ -174,79 +181,79 @@
          RETURN
       ENDIF
-
+      !
       CALL ice_dia_rst( 'READ' )  !* read or initialize all required files
       !
    END SUBROUTINE ice_dia_init
 
+
    SUBROUTINE ice_dia_rst( cdrw, kt )
-     !!---------------------------------------------------------------------
-     !!                   ***  ROUTINE limdia_rst  ***
-     !!                     
-     !! ** Purpose :   Read or write DIA file in restart file
-     !!
-     !! ** Method  :   use of IOM library
-     !!----------------------------------------------------------------------
-     CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
-     INTEGER         , INTENT(in), OPTIONAL ::   kt     ! ice time-step
-     REAL(wp)                     ::   ziter
-     INTEGER                      ::   iter
-     !
-     !!----------------------------------------------------------------------
-     !
-     IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
-        IF( ln_rstart ) THEN                   !* Read the restart file
-           !
-           CALL iom_get( numrir, 'kt_ice' , ziter )
-           IF(lwp) WRITE(numout,*)
-           IF(lwp) WRITE(numout,*) ' ice_dia_rst read at time step = ', ziter
-           IF(lwp) WRITE(numout,*) '~~~~~~~'
-           CALL iom_get( numrir, 'frc_voltop' , frc_voltop  )
-           CALL iom_get( numrir, 'frc_volbot' , frc_volbot  )
-           CALL iom_get( numrir, 'frc_temtop' , frc_temtop  )
-           CALL iom_get( numrir, 'frc_tembot' , frc_tembot  )
-           CALL iom_get( numrir, 'frc_sal'    , frc_sal     )
-           CALL iom_get( numrir, jpdom_autoglo, 'vol_loc_ini', vol_loc_ini )
-           CALL iom_get( numrir, jpdom_autoglo, 'tem_loc_ini', tem_loc_ini )
-           CALL iom_get( numrir, jpdom_autoglo, 'sal_loc_ini', sal_loc_ini )
-        ELSE
-           IF(lwp) WRITE(numout,*)
-           IF(lwp) WRITE(numout,*) ' ice_dia at initial state '
-           IF(lwp) WRITE(numout,*) '~~~~~~~'
-           ! set trends to 0
-           frc_voltop  = 0._wp                                          
-           frc_volbot  = 0._wp                                          
-           frc_temtop  = 0._wp                                                 
-           frc_tembot  = 0._wp                                                 
-           frc_sal     = 0._wp                                                 
-           ! record initial ice volume, salt and temp
-           vol_loc_ini(:,:) = rhoic * vt_i(:,:) + rhosn * vt_s(:,:)  ! ice/snow volume (kg/m2)
-           tem_loc_ini(:,:) = et_i(:,:) + et_s(:,:)                  ! ice/snow heat content (J)
-           sal_loc_ini(:,:) = rhoic * SUM( smv_i(:,:,:), dim=3 )     ! ice salt content (pss*kg/m2)
-           
-       ENDIF
-
-     ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
-        !                                   ! -------------------
-        iter = kt + nn_fsbc - 1   ! ice restarts are written at kt == nitrst - nn_fsbc + 1
-
-        IF( iter == nitrst ) THEN
-           IF(lwp) WRITE(numout,*)
-           IF(lwp) WRITE(numout,*) ' ice_dia_rst write at time step = ', kt
-           IF(lwp) WRITE(numout,*) '~~~~~~~'
-        ENDIF
-
-        ! Write in numriw (if iter == nitrst)
-        ! ------------------ 
-        CALL iom_rstput( iter, nitrst, numriw, 'frc_voltop' , frc_voltop  )
-        CALL iom_rstput( iter, nitrst, numriw, 'frc_volbot' , frc_volbot  )
-        CALL iom_rstput( iter, nitrst, numriw, 'frc_temtop' , frc_temtop  )
-        CALL iom_rstput( iter, nitrst, numriw, 'frc_tembot' , frc_tembot  )
-        CALL iom_rstput( iter, nitrst, numriw, 'frc_sal'    , frc_sal     )
-        CALL iom_rstput( iter, nitrst, numriw, 'vol_loc_ini', vol_loc_ini )
-        CALL iom_rstput( iter, nitrst, numriw, 'tem_loc_ini', tem_loc_ini )
-        CALL iom_rstput( iter, nitrst, numriw, 'sal_loc_ini', sal_loc_ini )
-        !
-     ENDIF
-     !
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE limdia_rst  ***
+      !!                     
+      !! ** Purpose :   Read or write DIA file in restart file
+      !!
+      !! ** Method  :   use of IOM library
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*) , INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
+      INTEGER, OPTIONAL, INTENT(in) ::   kt     ! ice time-step
+      !
+      INTEGER  ::   iter    ! local integer
+      REAL(wp) ::   ziter   ! local scalar
+      !!----------------------------------------------------------------------
+      !
+      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
+         IF( ln_rstart ) THEN                   !* Read the restart file
+            !
+            CALL iom_get( numrir, 'kt_ice' , ziter )
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) ' ice_dia_rst read at time step = ', ziter
+            IF(lwp) WRITE(numout,*) '~~~~~~~'
+            CALL iom_get( numrir, 'frc_voltop' , frc_voltop  )
+            CALL iom_get( numrir, 'frc_volbot' , frc_volbot  )
+            CALL iom_get( numrir, 'frc_temtop' , frc_temtop  )
+            CALL iom_get( numrir, 'frc_tembot' , frc_tembot  )
+            CALL iom_get( numrir, 'frc_sal'    , frc_sal     )
+            CALL iom_get( numrir, jpdom_autoglo, 'vol_loc_ini', vol_loc_ini )
+            CALL iom_get( numrir, jpdom_autoglo, 'tem_loc_ini', tem_loc_ini )
+            CALL iom_get( numrir, jpdom_autoglo, 'sal_loc_ini', sal_loc_ini )
+         ELSE
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) ' ice_dia at initial state '
+            IF(lwp) WRITE(numout,*) '~~~~~~~'
+            ! set trends to 0
+            frc_voltop  = 0._wp                                          
+            frc_volbot  = 0._wp                                          
+            frc_temtop  = 0._wp                                                 
+            frc_tembot  = 0._wp                                                 
+            frc_sal     = 0._wp                                                 
+            ! record initial ice volume, salt and temp
+            vol_loc_ini(:,:) = rhoic * vt_i(:,:) + rhosn * vt_s(:,:)  ! ice/snow volume (kg/m2)
+            tem_loc_ini(:,:) = et_i(:,:) + et_s(:,:)                  ! ice/snow heat content (J)
+            sal_loc_ini(:,:) = rhoic * SUM( smv_i(:,:,:), dim=3 )     ! ice salt content (pss*kg/m2)
+         ENDIF
+         !
+      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
+         !                                   ! -------------------
+         iter = kt + nn_fsbc - 1   ! ice restarts are written at kt == nitrst - nn_fsbc + 1
+         !
+         IF( iter == nitrst ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) ' ice_dia_rst write at time step = ', kt
+            IF(lwp) WRITE(numout,*) '~~~~~~~'
+         ENDIF
+         !
+         ! Write in numriw (if iter == nitrst)
+         ! ------------------ 
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_voltop' , frc_voltop  )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_volbot' , frc_volbot  )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_temtop' , frc_temtop  )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_tembot' , frc_tembot  )
+         CALL iom_rstput( iter, nitrst, numriw, 'frc_sal'    , frc_sal     )
+         CALL iom_rstput( iter, nitrst, numriw, 'vol_loc_ini', vol_loc_ini )
+         CALL iom_rstput( iter, nitrst, numriw, 'tem_loc_ini', tem_loc_ini )
+         CALL iom_rstput( iter, nitrst, numriw, 'sal_loc_ini', sal_loc_ini )
+         !
+      ENDIF
+      !
    END SUBROUTINE ice_dia_rst
  
@@ -255,8 +262,6 @@
    !!   Default option :         Empty module          NO LIM sea-ice model
    !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE ice_dia          ! Empty routine
-   END SUBROUTINE ice_dia
 #endif
+
    !!======================================================================
 END MODULE icedia
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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceforcing.F90	(revision 8486)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                       ***  MODULE  iceforcing  ***
-   !! call surface forcing for sea ice model
+   !! Sea-Ice :   air-ice forcing fields
    !!=====================================================================
    !! History :  4.0  ! 2017-08  (C. Rousset) Original code
@@ -10,21 +10,20 @@
    !!   'key_lim3' :                                  LIM 3.0 sea-ice model
    !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE ice             ! LIM-3: ice variables
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE ice            ! sea-ice variables
+   USE sbc_oce        ! Surface boundary condition: ocean fields
+   USE sbc_ice        ! Surface boundary condition: ice   fields
+   USE usrdef_sbc     ! user defined: surface boundary condition
+   USE sbcblk         ! Surface boundary condition: bulk
+   USE sbccpl         ! Surface boundary condition: coupled interface
+   USE icealb         ! ice albedo
    !
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice   fields
-   USE usrdef_sbc      ! user defined: surface boundary condition
-   USE sbcblk          ! Surface boundary condition: bulk
-   USE sbccpl          ! Surface boundary condition: coupled interface
-   USE icealb          ! ice albedo
-   !
-   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 timing          ! Timing
+   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 timing         ! Timing
 
    IMPLICIT NONE
@@ -37,5 +36,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , UCL NEMO Consortium (2011)
+   !! NEMO/ICE 4.0 , UCL NEMO Consortium (2017)
    !! $Id: icestp.F90 8319 2017-07-11 15:00:44Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -113,13 +112,12 @@
       !!                alb_ice                                  = albedo above sea ice
       !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt      ! ocean time step
-      INTEGER, INTENT(in) ::   ksbc    ! type of sbc flux ( 1 = user defined formulation, 
-                                       !                    3 = bulk formulation,
-                                       !                    4 = Pure Coupled formulation)
+      INTEGER, INTENT(in) ::   kt     ! ocean time step
+      INTEGER, INTENT(in) ::   ksbc   ! flux formulation (user defined, bulk or Pure Coupled)
+      !
       INTEGER  ::   ji, jj, jl                                ! dummy loop index
       REAL(wp), DIMENSION(jpi,jpj,jpl) ::   zalb_os, zalb_cs  ! ice albedo under overcast/clear sky
       REAL(wp), DIMENSION(jpi,jpj)     ::   zalb              ! 2D workspace
       !!----------------------------------------------------------------------
-
+      !
       IF( nn_timing == 1 )   CALL timing_start('ice_forcing_flx')
 
@@ -136,5 +134,6 @@
       DO jl = 1, jpl
          DO jj = 2, jpjm1
-            DO ji = 2, jpim1                                
+            DO ji = 2, jpim1
+!!gm cldf_ice is a real, DOCTOR naming rule: start with cd means CHARACTER passed in argument !
                alb_ice(ji,jj,jl) = ( 1. - cldf_ice ) * zalb_cs(ji,jj,jl) + cldf_ice * zalb_os(ji,jj,jl)
             END DO
@@ -143,31 +142,34 @@
       CALL lbc_lnk( alb_ice, 'T', 1. )
       
-      ! --- fluxes over sea ice --- !
-      SELECT CASE( ksbc )
-         CASE( jp_usr )                                          ! user defined formulation
-                                   CALL usrdef_sbc_ice_flx( kt )
-
-         CASE( jp_blk )                                          ! bulk formulation
-                                   CALL blk_ice_flx( t_su, alb_ice )
-            IF( ln_mixcpl      )   CALL sbc_cpl_ice_flx( picefr=at_i_b, palbi=alb_ice, psst=sst_m, pist=t_su )
-            IF( nn_limflx /= 2 )   CALL ice_flx_dist( t_su, alb_ice, qns_ice, qsr_ice, dqns_ice, evap_ice, devap_ice, nn_limflx )
-
-         CASE ( jp_purecpl )                                     ! coupled formulation
-                                   CALL sbc_cpl_ice_flx( picefr=at_i_b, palbi=alb_ice, psst=sst_m, pist=t_su )
-            IF( nn_limflx == 2 )   CALL ice_flx_dist( t_su, alb_ice, qns_ice, qsr_ice, dqns_ice, evap_ice, devap_ice, nn_limflx )
-      END SELECT
-
-      ! --- albedo output --- !
-      WHERE( at_i_b <= epsi06 )  ;  zalb(:,:) = rn_alb_oce
-      ELSEWHERE                  ;  zalb(:,:) = SUM( alb_ice * a_i_b, dim=3 ) / at_i_b
-      END WHERE
-      IF( iom_use('icealb'  ) )  CALL iom_put( "icealb" , zalb(:,:) )   ! ice albedo
-
-      zalb(:,:) = SUM( alb_ice * a_i_b, dim=3 ) + rn_alb_oce * ( 1._wp - at_i_b )
-      IF( iom_use('albedo'  ) )  CALL iom_put( "albedo" , zalb(:,:) )   ! surface albedo
-      !
+      SELECT CASE( ksbc )      !==  fluxes over sea ice  ==!
+      !
+      CASE( jp_usr )                !--- user defined formulation
+                                CALL usrdef_sbc_ice_flx( kt )
+         !
+      CASE( jp_blk )                !--- bulk formulation
+                                CALL blk_ice_flx( t_su, alb_ice )    ! 
+         IF( ln_mixcpl      )   CALL sbc_cpl_ice_flx( picefr=at_i_b, palbi=alb_ice, psst=sst_m, pist=t_su )
+         IF( nn_limflx /= 2 )   CALL ice_flx_dist( t_su, alb_ice, qns_ice, qsr_ice, dqns_ice, evap_ice, devap_ice, nn_limflx )
+         !
+      CASE ( jp_purecpl )           !--- coupled formulation
+                                CALL sbc_cpl_ice_flx( picefr=at_i_b, palbi=alb_ice, psst=sst_m, pist=t_su )
+         IF( nn_limflx == 2 )   CALL ice_flx_dist( t_su, alb_ice, qns_ice, qsr_ice, dqns_ice, evap_ice, devap_ice, nn_limflx )
+         !
+      END SELECT
+
+      IF( iom_use('icealb') ) THEN    !--- output ice albedo
+         WHERE( at_i_b <= epsi06 )   ;   zalb(:,:) = rn_alb_oce
+         ELSEWHERE                   ;   zalb(:,:) = SUM( alb_ice * a_i_b, dim=3 ) / at_i_b
+         END WHERE
+         CALL iom_put( "icealb" , zalb(:,:) )   ! ice albedo
+      ENDIF
+
+      IF( iom_use('albedo') ) THEN  !--- surface albedo
+         zalb(:,:) = SUM( alb_ice * a_i_b, dim=3 ) + rn_alb_oce * ( 1._wp - at_i_b )
+         CALL iom_put( "albedo" , zalb(:,:) )
+      ENDIF
       !
       IF( nn_timing == 1 )   CALL timing_stop('ice_forcing_flx')
-
+      !
    END SUBROUTINE ice_forcing_flx
 
@@ -177,6 +179,6 @@
       !!                  ***  ROUTINE ice_flx_dist  ***
       !!
-      !! ** Purpose :   update the ice surface boundary condition by averaging and / or
-      !!                redistributing fluxes on ice categories
+      !! ** Purpose :   update the ice surface boundary condition by averaging 
+      !!              and/or redistributing fluxes on ice categories
       !!
       !! ** Method  :   average then redistribute
@@ -208,30 +210,40 @@
       IF( nn_timing == 1 )  CALL timing_start('ice_flx_dist')
       !
-      SELECT CASE( k_limflx )                              !==  averaged on all ice categories  ==!
+      SELECT CASE( k_limflx )       !==  averaged on all ice categories  ==!
+      !
       CASE( 0 , 1 )
-         !
-         z_qns_m  (:,:) = fice_ice_ave ( pqns_ice (:,:,:) )
-         z_qsr_m  (:,:) = fice_ice_ave ( pqsr_ice (:,:,:) )
-         z_dqn_m  (:,:) = fice_ice_ave ( pdqn_ice (:,:,:) )
-         z_evap_m (:,:) = fice_ice_ave ( pevap_ice (:,:,:) )
-         z_devap_m(:,:) = fice_ice_ave ( pdevap_ice (:,:,:) )
+         z_qns_m  (:,:) = fice_ice_ave( pqns_ice  (:,:,:) )
+         z_qsr_m  (:,:) = fice_ice_ave( pqsr_ice  (:,:,:) )
+         z_dqn_m  (:,:) = fice_ice_ave( pdqn_ice  (:,:,:) )
+         z_evap_m (:,:) = fice_ice_ave( pevap_ice (:,:,:) )
+         z_devap_m(:,:) = fice_ice_ave( pdevap_ice(:,:,:) )
+!!gm faster coding
+!    REAL(wp), DIMENSION(jpi,jpj) ::   z1_at_i   ! 
+! ...
+!      WHERE ( at_i (:,:) > 0._wp )   ; z1_at_i(:,:) = 1._wp / at_i (:,:)
+!      ELSEWHERE                      ; z1_at_i(:,:) = 0._wp
+!      END WHERE
+!      z_qns_m  (:,:) = SUM( a_i(:,:,:) * pqns_ice  (:,:,:) , dim=3 ) * z1_at_i(:,:)
+!      z_qsr_m  (:,:) = SUM( a_i(:,:,:) * pqsr_ice  (:,:,:) , dim=3 ) * z1_at_i(:,:)
+!      z_dqn_m  (:,:) = SUM( a_i(:,:,:) * pdqn_ice  (:,:,:) , dim=3 ) * z1_at_i(:,:)
+!      z_evap_m (:,:) = SUM( a_i(:,:,:) * pevap_ice (:,:,:) , dim=3 ) * z1_at_i(:,:)
+!      z_devap_m(:,:) = SUM( a_i(:,:,:) * pdevap_ice(:,:,:) , dim=3 ) * z1_at_i(:,:)
+!! and remove the 2 functions: fice_ice_ave and fice_cell_ave
+!!gm
          DO jl = 1, jpl
-            pdqn_ice  (:,:,jl) = z_dqn_m(:,:)
+            pdqn_ice  (:,:,jl) = z_dqn_m  (:,:)
             pdevap_ice(:,:,jl) = z_devap_m(:,:)
-         END DO
-         !
-         DO jl = 1, jpl
-            pqns_ice (:,:,jl) = z_qns_m(:,:)
-            pqsr_ice (:,:,jl) = z_qsr_m(:,:)
-            pevap_ice(:,:,jl) = z_evap_m(:,:)
-         END DO
-         !
-      END SELECT
-      !
-      SELECT CASE( k_limflx )                              !==  redistribution on all ice categories  ==!
+            pqns_ice  (:,:,jl) = z_qns_m (:,:)
+            pqsr_ice  (:,:,jl) = z_qsr_m (:,:)
+            pevap_ice (:,:,jl) = z_evap_m(:,:)
+         END DO
+         !
+      END SELECT
+      !
+      SELECT CASE( k_limflx )       !==  redistribution on all ice categories  ==!
       CASE( 1 , 2 )
          !
-         zalb_m(:,:) = fice_ice_ave ( palb_ice (:,:,:) )
-         ztem_m(:,:) = fice_ice_ave ( ptn_ice  (:,:,:) )
+         zalb_m(:,:) = fice_ice_ave( palb_ice(:,:,:) )
+         ztem_m(:,:) = fice_ice_ave( ptn_ice (:,:,:) )
          DO jl = 1, jpl
             pqns_ice (:,:,jl) = pqns_ice (:,:,jl) + pdqn_ice  (:,:,jl) * ( ptn_ice(:,:,jl) - ztem_m(:,:) )
@@ -246,19 +258,17 @@
    END SUBROUTINE ice_flx_dist
 
-
+!!gm TO BE REMOVED ====>>>>>
    FUNCTION fice_cell_ave ( ptab )
       !!--------------------------------------------------------------------------
       !! * Compute average over categories, for grid cell (ice covered and free ocean)
       !!--------------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj) :: fice_cell_ave
-      REAL(wp), DIMENSION(jpi,jpj,jpl), INTENT (in) :: ptab
+      REAL(wp), DIMENSION(jpi,jpj,jpl), INTENT(in) :: ptab
+      REAL(wp), DIMENSION(jpi,jpj)                 :: fice_cell_ave
       INTEGER :: jl
       !!--------------------------------------------------------------------------
-
-      fice_cell_ave (:,:) = 0._wp
-      DO jl = 1, jpl
-         fice_cell_ave (:,:) = fice_cell_ave (:,:) + a_i (:,:,jl) * ptab (:,:,jl)
+      fice_cell_ave(:,:) = a_i(:,:,1) * ptab (:,:,1)
+      DO jl = 2, jpl
+         fice_cell_ave(:,:) = fice_cell_ave(:,:) + a_i(:,:,jl) * ptab (:,:,jl)
       END DO
-
    END FUNCTION fice_cell_ave
 
@@ -268,14 +278,18 @@
       !! * Compute average over categories, for ice covered part of grid cell
       !!--------------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj) :: fice_ice_ave
-      REAL(wp), DIMENSION(jpi,jpj,jpl), INTENT(in) :: ptab
-     !!--------------------------------------------------------------------------
-
+      REAL(wp), DIMENSION(jpi,jpj,jpl), INTENT(in) ::   ptab   !
+      REAL(wp), DIMENSION(jpi,jpj)                 :: fice_ice_ave
+      !!--------------------------------------------------------------------------
       WHERE ( at_i (:,:) > 0.0_wp ) ; fice_ice_ave (:,:) = fice_cell_ave( ptab (:,:,:) ) / at_i (:,:)
       ELSEWHERE                     ; fice_ice_ave (:,:) = 0.0_wp
       END WHERE
-      
    END FUNCTION fice_ice_ave
 
+!!gm <<<<<<====  end of TO BE REMOVED 
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :         Empty module          NO LIM sea-ice model
+   !!----------------------------------------------------------------------
 #endif
 
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceist.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceist.F90	(revision 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceist.F90	(revision 8486)
@@ -5,13 +5,15 @@
    !!======================================================================
    !! History :  2.0  ! 2004-01 (C. Ethe, G. Madec)  Original code
-   !!            3.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!             -   ! 2014    (C. Rousset) add N/S initializations
+   !!            3.0  ! 2007    (M. Vancoppenolle)  Rewrite for ice cats
+   !!            3.0  ! 2009-11 (M. Vancoppenolle)  Enhanced version for ice cats
+   !!            3.0  ! 2011-02 (G. Madec)  dynamical allocation
+   !!             -   ! 2014    (C. Rousset)  add N/S initializations
    !!----------------------------------------------------------------------
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                    LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   ice_ist      :  Initialisation of diagnostics ice variables
-   !!   ice_ist_init :  initialization of ice state and namelist read
+   !!   'key_lim3'                                       LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_ist       :  initialization of diagnostics ice variables
+   !!   ice_ist_init  :  initialization of ice state and namelist read
    !!----------------------------------------------------------------------
    USE phycst         ! physical constant
@@ -34,5 +36,5 @@
    PRIVATE
 
-   PUBLIC   ice_ist      ! routine called by lim_init.F90
+   PUBLIC   ice_ist      ! called by icestp.F90
 
    INTEGER , PARAMETER ::   jpfldi = 6           ! maximum number of files to read
@@ -45,5 +47,5 @@
    TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   si  ! structure of input fields (file informations, fields read)
    !!----------------------------------------------------------------------
-   !!   LIM 3.0,  UCL-LOCEAN-IPSL (2008)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: iceist.F90 8378 2017-07-26 13:55:59Z clem $
    !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
@@ -51,4 +53,5 @@
 CONTAINS
 
+!!gm  better name:  ice_istate
    SUBROUTINE ice_ist
       !!-------------------------------------------------------------------
@@ -71,11 +74,5 @@
       !! ** Notes   : o_i, t_su, t_s, t_i, s_i must be filled everywhere, even
       !!              where there is no ice (clem: I do not know why, is it mandatory?) 
-      !!
-      !! History :
-      !!   2.0  !  01-04  (C. Ethe, G. Madec)  Original code
-      !!   3.0  !  2007   (M. Vancoppenolle)   Rewrite for ice cats
-      !!   4.0  !  09-11  (M. Vancoppenolle)   Enhanced version for ice cats
       !!--------------------------------------------------------------------
-      !! * Local variables
       INTEGER    :: ji, jj, jk, jl             ! dummy loop indices
       REAL(wp)   :: ztmelts, zdh
@@ -591,7 +588,4 @@
    !!   Default option :         Empty module          NO LIM sea-ice model
    !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE ice_ist          ! Empty routine
-   END SUBROUTINE ice_ist
 #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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceitd.F90	(revision 8486)
@@ -11,5 +11,5 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                   LIM3 sea-ice model
+   !!   'key_lim3'                                       LIM3 sea-ice model
    !!----------------------------------------------------------------------
    !!   ice_itd_rem   :
@@ -18,16 +18,16 @@
    !!   ice_itd_shiftice :
    !!----------------------------------------------------------------------
-   USE par_oce          ! ocean parameters
-   USE dom_oce          ! ocean domain
-   USE phycst           ! physical constants (ocean directory) 
-   USE ice1D            ! LIM-3 thermodynamic variables
-   USE ice              ! LIM-3 variables
-   USE icectl           ! conservation tests
-   USE icetab
+   USE par_oce        ! ocean parameters
+   USE dom_oce        ! ocean domain
+   USE phycst         ! physical constants 
+   USE ice1D          ! sea-ice: thermodynamic variables
+   USE ice            ! sea-ice: variables
+   USE icectl         ! sea-ice: conservation tests
+   USE icetab         ! sea-ice: convert 1D<=>2D
    !
-   USE prtctl           ! Print control
-   USE in_out_manager   ! I/O manager
-   USE lib_mpp          ! MPP library
-   USE lib_fortran      ! to use key_nosignedzero
+   USE prtctl         ! Print control
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! to use key_nosignedzero
 
    IMPLICIT NONE
@@ -38,5 +38,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: iceitd.F90 8420 2017-08-08 12:18:46Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -86,5 +86,5 @@
       !  1) Identify grid cells with ice
       !-----------------------------------------------------------------------------------------------
-      nidx = 0 ; idxice(:) = 0
+      nidx = 0   ;   idxice(:) = 0
       DO jj = 1, jpj
          DO ji = 1, jpi
@@ -118,5 +118,5 @@
          ! --- New boundaries for category 1:jpl-1 --- !
          DO jl = 1, jpl - 1
-
+            !
             DO ji = 1, nidx
                !
@@ -134,5 +134,5 @@
                   zhbnew(ji,jl) = hi_max(jl)
                ENDIF
-            
+               !
                ! --- 2 conditions for remapping --- !
                ! 1) hn(t+1)+espi < Hn* < hn+1(t+1)-epsi               
@@ -148,5 +148,5 @@
             END DO
          END DO
-         
+         !
          ! --- New boundaries for category jpl --- !
          DO ji = 1, nidx
@@ -164,5 +164,5 @@
             IF( ht_ib_2d(ji,1) > ( hi_max(1) - epsi10 ) )   idxice(ji) = 0
          END DO
-
+         !
          !-----------------------------------------------------------------------------------------------
          !  3) Identify cells where remapping
@@ -178,5 +178,5 @@
          idxice(:) = idxice2(:)
          nidx      = nidx2
-         
+         !
       ENDIF
    
@@ -186,27 +186,27 @@
       !-----------------------------------------------------------------------------------------------
       IF( nidx > 0 ) THEN
-
-         zhb0(:) = hi_max(0) ; zhb1(:) = hi_max(1)
-         g0(:,:) = 0._wp     ; g1(:,:) = 0._wp 
-         hL(:,:) = 0._wp     ; hR(:,:) = 0._wp 
-         
+         !
+         zhb0(:) = hi_max(0)   ;   zhb1(:) = hi_max(1)
+         g0(:,:) = 0._wp       ;   g1(:,:) = 0._wp 
+         hL(:,:) = 0._wp       ;   hR(:,:) = 0._wp 
+         !
          DO jl = 1, jpl
-
+            !
             CALL tab_2d_1d( nidx, idxice(1:nidx), ht_ib_1d(1:nidx), ht_i_b(:,:,jl) )
             CALL tab_2d_1d( nidx, idxice(1:nidx), ht_i_1d (1:nidx), ht_i(:,:,jl)   )
             CALL tab_2d_1d( nidx, idxice(1:nidx), a_i_1d  (1:nidx), a_i(:,:,jl)    )
             CALL tab_2d_1d( nidx, idxice(1:nidx), v_i_1d  (1:nidx), v_i(:,:,jl)    )
-
+            !
             IF( jl == 1 ) THEN
-               
+               !  
                ! --- g(h) for category 1 --- !
-               CALL ice_itd_glinear( zhb0(1:nidx), zhb1(1:nidx), ht_ib_1d(1:nidx), a_i_1d(1:nidx),  &   ! in
-                  &                  g0(1:nidx,1), g1(1:nidx,1), hL(1:nidx,1)    , hR(1:nidx,1) )       ! out
-               
+               CALL ice_itd_glinear( zhb0(1:nidx)  , zhb1(1:nidx)  , ht_ib_1d(1:nidx)  , a_i_1d(1:nidx)  ,  &   ! in
+                  &                  g0  (1:nidx,1), g1  (1:nidx,1), hL      (1:nidx,1), hR    (1:nidx,1)   )   ! out
+                  !
                ! Area lost due to melting of thin ice
                DO ji = 1, nidx
-                  
+                  !
                   IF( a_i_1d(ji) > epsi10 ) THEN
-                     
+                     !
                      zdh0 =  ht_i_1d(ji) - ht_ib_1d(ji)                
                      IF( zdh0 < 0.0 ) THEN      !remove area from category 1
@@ -214,5 +214,5 @@
                         !Integrate g(1) from 0 to dh0 to estimate area melted
                         zetamax = MIN( zdh0, hR(ji,1) ) - hL(ji,1)
-                        
+                        !
                         IF( zetamax > 0.0 ) THEN
                            zx1    = zetamax
@@ -227,24 +227,24 @@
                            v_i_1d(ji)  = a_i_1d(ji) * ht_i_1d(ji) ! clem-useless ?
                         ENDIF
-                        
+                        !
                      ELSE ! if ice accretion zdh0 > 0
                         ! zhbnew was 0, and is shifted to the right to account for thin ice growth in openwater (F0 = f1)
                         zhbnew(ji,0) = MIN( zdh0, hi_max(1) ) 
                      ENDIF
-                     
+                     !
                   ENDIF
-                  
+                  !
                END DO
-
+               !
                CALL tab_1d_2d( nidx, idxice(1:nidx), ht_i_1d (1:nidx), ht_i(:,:,jl)   )
                CALL tab_1d_2d( nidx, idxice(1:nidx), a_i_1d  (1:nidx), a_i(:,:,jl)    )
                CALL tab_1d_2d( nidx, idxice(1:nidx), v_i_1d  (1:nidx), v_i(:,:,jl)    )
-               
+               !
             ENDIF ! jl=1
-            
+            !
             ! --- g(h) for each thickness category --- !  
-            CALL ice_itd_glinear( zhbnew(1:nidx,jl-1), zhbnew(1:nidx,jl), ht_i_1d(1:nidx), a_i_1d(1:nidx),  &  ! in
-               &                  g0(1:nidx,jl)      , g1(1:nidx,jl)    , hL(1:nidx,jl)  , hR(1:nidx,jl) )     ! out
-
+            CALL ice_itd_glinear( zhbnew(1:nidx,jl-1), zhbnew(1:nidx,jl), ht_i_1d(1:nidx)   , a_i_1d(1:nidx)   ,  &   ! in
+               &                  g0    (1:nidx,jl  ), g1    (1:nidx,jl), hL     (1:nidx,jl), hR    (1:nidx,jl)   )   ! out
+            !
          END DO
          
@@ -253,7 +253,7 @@
          !-----------------------------------------------------------------------------------------------
          DO jl = 1, jpl - 1
-            
+            !
             DO ji = 1, nidx
-               
+               !
                ! left and right integration limits in eta space
                IF (zhbnew(ji,jl) > hi_max(jl)) THEN ! Hn* > Hn => transfer from jl to jl+1
@@ -267,5 +267,5 @@
                ENDIF
                zetamax = MAX( zetamax, zetamin ) ! no transfer if etamax < etamin
-               
+               !
                zx1  = zetamax - zetamin
                zwk1 = zetamin * zetamin
@@ -278,5 +278,5 @@
                zdaice(ji,jl) = g1(ji,jcat)*zx2 + g0(ji,jcat)*zx1
                zdvice(ji,jl) = g1(ji,jcat)*zx3 + g0(ji,jcat)*zx2 + zdaice(ji,jl)*hL(ji,jcat)
-               
+               !
             END DO
          END DO
@@ -305,13 +305,13 @@
             ENDIF
          END DO
-
+         !
          CALL tab_1d_2d( nidx, idxice(1:nidx), ht_i_1d (1:nidx), ht_i(:,:,1)   )
          CALL tab_1d_2d( nidx, idxice(1:nidx), a_i_1d  (1:nidx), a_i(:,:,1)    )
          CALL tab_1d_2d( nidx, idxice(1:nidx), a_ip_1d (1:nidx), a_ip(:,:,1)    )
-        
+         !
       ENDIF
-
-      IF( ln_limdiachk ) CALL ice_cons_hsm(1, 'iceitd_rem', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
+      !
+      IF( ln_limdiachk )   CALL ice_cons_hsm(1, 'iceitd_rem', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      !
    END SUBROUTINE ice_itd_rem
 
@@ -325,5 +325,4 @@
       !! ** Method  :   g(h) is linear and written as: g(eta) = g1(eta) + g0
       !!                with eta = h - HL
-      !!                
       !!------------------------------------------------------------------
       REAL(wp), DIMENSION(:), INTENT(in   ) ::   HbL, HbR      ! left and right category boundaries
@@ -333,4 +332,5 @@
       !
       INTEGER  ::   ji           ! horizontal indices
+      REAL(wp) ::   z1_3 , z2_3  ! 1/3 , 2/3
       REAL(wp) ::   zh13         ! HbL + 1/3 * (HbR - HbL)
       REAL(wp) ::   zh23         ! HbL + 2/3 * (HbR - HbL)
@@ -339,36 +339,39 @@
       !!------------------------------------------------------------------
       !
-         DO ji = 1, nidx
-            !
-            IF( paice(ji) > epsi10  .AND. phice(ji) > 0._wp )  THEN
-
-               ! Initialize hL and hR
-               phL(ji) = HbL(ji)
-               phR(ji) = HbR(ji)
-
-               ! Change hL or hR if hice falls outside central third of range,
-               ! so that hice is in the central third of the range [HL HR]
-               zh13 = 1.0 / 3.0 * ( 2.0 * phL(ji) +       phR(ji) )
-               zh23 = 1.0 / 3.0 * (       phL(ji) + 2.0 * phR(ji) )
-
-               IF    ( phice(ji) < zh13 ) THEN   ;   phR(ji) = 3._wp * phice(ji) - 2._wp * phL(ji) ! move HR to the left
-               ELSEIF( phice(ji) > zh23 ) THEN   ;   phL(ji) = 3._wp * phice(ji) - 2._wp * phR(ji) ! move HL to the right
-               ENDIF
-
-               ! Compute coefficients of g(eta) = g0 + g1*eta
-               zdhr = 1._wp / (phR(ji) - phL(ji))
-               zwk1 = 6._wp * paice(ji) * zdhr
-               zwk2 = ( phice(ji) - phL(ji) ) * zdhr
-               pg0(ji) = zwk1 * ( 2._wp / 3._wp - zwk2 )      ! Eq. 14
-               pg1(ji) = 2._wp * zdhr * zwk1 * ( zwk2 - 0.5 ) ! Eq. 14
-               !
-            ELSE  ! remap_flag = .false. or a_i < epsi10 
-               phL(ji) = 0._wp
-               phR(ji) = 0._wp
-               pg0(ji) = 0._wp
-               pg1(ji) = 0._wp
-            ENDIF
-            !
-         END DO
+      z1_3 = 1._wp / 3._wp
+      z2_3 = 2._wp / 3._wp
+      !
+      DO ji = 1, nidx
+         !
+         IF( paice(ji) > epsi10  .AND. phice(ji) > 0._wp )  THEN
+            !
+            ! Initialize hL and hR
+            phL(ji) = HbL(ji)
+            phR(ji) = HbR(ji)
+            !
+            ! Change hL or hR if hice falls outside central third of range,
+            ! so that hice is in the central third of the range [HL HR]
+            zh13 = z1_3 * ( 2._wp * phL(ji) +         phR(ji) )
+            zh23 = z1_3 * (         phL(ji) + 2._wp * phR(ji) )
+            !
+            IF    ( phice(ji) < zh13 ) THEN   ;   phR(ji) = 3._wp * phice(ji) - 2._wp * phL(ji) ! move HR to the left
+            ELSEIF( phice(ji) > zh23 ) THEN   ;   phL(ji) = 3._wp * phice(ji) - 2._wp * phR(ji) ! move HL to the right
+            ENDIF
+            !
+            ! Compute coefficients of g(eta) = g0 + g1*eta
+            zdhr = 1._wp / (phR(ji) - phL(ji))
+            zwk1 = 6._wp * paice(ji) * zdhr
+            zwk2 = ( phice(ji) - phL(ji) ) * zdhr
+            pg0(ji) = zwk1 * ( z2_3 - zwk2 )                    ! Eq. 14
+            pg1(ji) = 2._wp * zdhr * zwk1 * ( zwk2 - 0.5_wp )   ! Eq. 14
+            !
+         ELSE  ! remap_flag = .false. or a_i < epsi10 
+            phL(ji) = 0._wp
+            phR(ji) = 0._wp
+            pg0(ji) = 0._wp
+            pg1(ji) = 0._wp
+         ENDIF
+         !
+      END DO
       !
    END SUBROUTINE ice_itd_glinear
@@ -381,18 +384,14 @@
       !! ** Purpose :   shift ice across category boundaries, conserving everything
       !!              ( area, volume, energy, age*vol, and mass of salt )
-      !!
-      !! ** Method  :
       !!------------------------------------------------------------------
       INTEGER , DIMENSION(:,:), INTENT(in) ::   kdonor   ! donor category index
       REAL(wp), DIMENSION(:,:), INTENT(in) ::   pdaice   ! ice area transferred across boundary
       REAL(wp), DIMENSION(:,:), INTENT(in) ::   pdvice   ! ice volume transferred across boundary
-
-      INTEGER ::   ii,ij, ji, jj, jl, jl2, jl1, jk   ! dummy loop indices
-
-      REAL(wp), DIMENSION(jpij,jpl) ::   zaTsfn
-      REAL(wp), DIMENSION(jpij)     ::   zworka            ! temporary array used here
-      REAL(wp), DIMENSION(jpij)     ::   zworkv            ! temporary array used here
-
+      !
+      INTEGER  ::   ji, jj, jl, jk     ! dummy loop indices
+      INTEGER  ::   ii, ij, jl2, jl1   ! local integers
       REAL(wp) ::   ztrans             ! ice/snow transferred
+      REAL(wp), DIMENSION(jpij)     ::   zworka, zworkv   ! workspace
+      REAL(wp), DIMENSION(jpij,jpl) ::   zaTsfn           !  -    -
       !!------------------------------------------------------------------
          
@@ -421,52 +420,57 @@
       DO jl = 1, jpl - 1
          DO ji = 1, nidx
-            
+            !
             jl1 = kdonor(ji,jl)
-            IF    ( jl1 == jl  ) THEN   ;   jl2 = jl1+1
-            ELSE                        ;   jl2 = jl 
-            ENDIF
-
-            rswitch    = MAX( 0._wp , SIGN( 1._wp , v_i_2d(ji,jl1) - epsi10 ) )
-            zworkv(ji) = pdvice(ji,jl) / MAX( v_i_2d(ji,jl1), epsi10 ) * rswitch
-
-            rswitch    = MAX( 0._wp , SIGN( 1._wp , a_i_2d(ji,jl1) - epsi10 ) )
-            zworka(ji) = pdaice(ji,jl) / MAX( a_i_2d(ji,jl1), epsi10 ) * rswitch        
-               
-            ! Ice areas
-            a_i_2d(ji,jl1) = a_i_2d(ji,jl1) - pdaice(ji,jl)
+            IF ( jl1 == jl  ) THEN   ;   jl2 = jl1+1
+            ELSE                     ;   jl2 = jl 
+            ENDIF
+            !
+!!gm use of rswitch not faster as there is already IF in the DO-loop ==>>> use IF which is more readable
+!            rswitch    = MAX( 0._wp , SIGN( 1._wp , v_i_2d(ji,jl1) - epsi10 ) )
+!            zworkv(ji) = pdvice(ji,jl) / MAX( v_i_2d(ji,jl1), epsi10 ) * rswitch
+!            !
+!            rswitch    = MAX( 0._wp , SIGN( 1._wp , a_i_2d(ji,jl1) - epsi10 ) )
+!            zworka(ji) = pdaice(ji,jl) / MAX( a_i_2d(ji,jl1), epsi10 ) * rswitch        
+
+            IF( v_i_2d(ji,jl1) >= epsi10 ) THEN   ;   zworkv(ji) = pdvice(ji,jl) / v_i_2d(ji,jl1)
+            ELSE                                  ;   zworkv(ji) = 0._wp
+            ENDIF
+            IF( a_i_2d(ji,jl1) >= epsi10 ) THEN   ;   zworka(ji) = pdaice(ji,jl) / a_i_2d(ji,jl1)
+            ELSE                                  ;   zworka(ji) = 0._wp
+            ENDIF
+!!gm end
+            !
+            a_i_2d(ji,jl1) = a_i_2d(ji,jl1) - pdaice(ji,jl)       ! Ice areas
             a_i_2d(ji,jl2) = a_i_2d(ji,jl2) + pdaice(ji,jl)
-               
-            ! Ice volumes
-            v_i_2d(ji,jl1) = v_i_2d(ji,jl1) - pdvice(ji,jl) 
+            !
+            v_i_2d(ji,jl1) = v_i_2d(ji,jl1) - pdvice(ji,jl)       ! Ice volumes
             v_i_2d(ji,jl2) = v_i_2d(ji,jl2) + pdvice(ji,jl)
-            
-            ! Snow volumes
-            ztrans         = v_s_2d(ji,jl1) * zworkv(ji)
+            !
+            ztrans         = v_s_2d(ji,jl1) * zworkv(ji)          ! Snow volumes
             v_s_2d(ji,jl1) = v_s_2d(ji,jl1) - ztrans
             v_s_2d(ji,jl2) = v_s_2d(ji,jl2) + ztrans 
-                       
-            ! Ice age 
-            ztrans             = oa_i_2d(ji,jl1) * pdaice(ji,jl) !!clem: should be * zworka(ji) but it does not work
+            !          
+            !                                                     ! Ice age 
+            ztrans             = oa_i_2d(ji,jl1) * pdaice(ji,jl)  !!clem: should be * zworka(ji) but it does not work ????
             oa_i_2d(ji,jl1)    = oa_i_2d(ji,jl1) - ztrans
             oa_i_2d(ji,jl2)    = oa_i_2d(ji,jl2) + ztrans
-            
-            ! Ice salinity
-            ztrans             = smv_i_2d(ji,jl1) * zworkv(ji)
+            !
+            ztrans             = smv_i_2d(ji,jl1) * zworkv(ji)    ! Ice salinity
+
             smv_i_2d(ji,jl1)   = smv_i_2d(ji,jl1) - ztrans
             smv_i_2d(ji,jl2)   = smv_i_2d(ji,jl2) + ztrans
-            
-            ! Surface temperature
-            ztrans          = t_su_2d(ji,jl1) * pdaice(ji,jl) !!clem: should be * zworka(ji) but it does not work
+            !
+            !                                                     ! Surface temperature
+            ztrans          = t_su_2d(ji,jl1) * pdaice(ji,jl)     !!clem: should be * zworka(ji) but it does not work ????
             zaTsfn(ji,jl1)  = zaTsfn(ji,jl1) - ztrans
             zaTsfn(ji,jl2)  = zaTsfn(ji,jl2) + ztrans
-               
+            !  
             ! MV MP 2016 
             IF ( nn_pnd_scheme > 0 ) THEN
-               ! Pond fraction
+               !                                                  ! Pond fraction
                ztrans          = a_ip_2d(ji,jl1) * pdaice(ji,jl) !!clem: should be * zworka(ji) but it does not work
                a_ip_2d(ji,jl1) = a_ip_2d(ji,jl1) - ztrans
                a_ip_2d(ji,jl2) = a_ip_2d(ji,jl2) + ztrans
-               
-               ! Pond volume (also proportional to da/a)
+               !                                                  ! Pond volume (also proportional to da/a)
                ztrans          = v_ip_2d(ji,jl1) * pdaice(ji,jl) !!clem: should be * zworka(ji) but it does not work
                v_ip_2d(ji,jl1) = v_ip_2d(ji,jl1) - ztrans
@@ -474,19 +478,17 @@
             ENDIF
             ! END MV MP 2016 
-               
-         END DO
-
-         ! Snow heat content
-         DO jk = 1, nlay_s
-
+         END DO
+         !
+         DO jk = 1, nlay_s         !--- Snow heat content
+            !
             DO ji = 1, nidx
                ii = MOD( idxice(ji) - 1, jpi ) + 1
                ij = ( idxice(ji) - 1 ) / jpi + 1
-
+               !
                jl1 = kdonor(ji,jl)
                IF(jl1 == jl) THEN  ;  jl2 = jl+1
                ELSE                ;  jl2 = jl
                ENDIF
-               
+               !
                ztrans            = e_s(ii,ij,jk,jl1) * zworkv(ji)
                e_s(ii,ij,jk,jl1) = e_s(ii,ij,jk,jl1) - ztrans
@@ -495,16 +497,14 @@
          END DO
 
-         
-         ! Ice heat content
-         DO jk = 1, nlay_i
+         DO jk = 1, nlay_i         !--- Ice heat content
             DO ji = 1, nidx
                ii = MOD( idxice(ji) - 1, jpi ) + 1
                ij = ( idxice(ji) - 1 ) / jpi + 1
-               
+               !
                jl1 = kdonor(ji,jl)
                IF(jl1 == jl) THEN  ;  jl2 = jl+1
                ELSE                ;  jl2 = jl
                ENDIF
-               
+               !
                ztrans            = e_i(ii,ij,jk,jl1) * zworkv(ji)
                e_i(ii,ij,jk,jl1) = e_i(ii,ij,jk,jl1) - ztrans
@@ -512,5 +512,5 @@
             END DO
          END DO
-         
+         !
       END DO                   ! boundaries, 1 to jpl-1
       
@@ -521,5 +521,5 @@
          DO ji = 1, nidx
             IF ( a_i_2d(ji,jl) > epsi10 ) THEN 
-               ht_i_2d(ji,jl)  =  v_i_2d   (ji,jl) / a_i_2d(ji,jl) 
+               ht_i_2d(ji,jl)  =  v_i_2d(ji,jl) / a_i_2d(ji,jl) 
                t_su_2d(ji,jl)  =  zaTsfn(ji,jl) / a_i_2d(ji,jl) 
             ELSE
@@ -529,15 +529,14 @@
          END DO
       END DO
-      
-      CALL tab_2d_3d( nidx, idxice(1:nidx), ht_i_2d (1:nidx,1:jpl), ht_i   )
-      CALL tab_2d_3d( nidx, idxice(1:nidx), a_i_2d  (1:nidx,1:jpl), a_i    )
-      CALL tab_2d_3d( nidx, idxice(1:nidx), v_i_2d  (1:nidx,1:jpl), v_i    )
-      CALL tab_2d_3d( nidx, idxice(1:nidx), v_s_2d  (1:nidx,1:jpl), v_s    )
-      CALL tab_2d_3d( nidx, idxice(1:nidx), oa_i_2d (1:nidx,1:jpl), oa_i   )
-      CALL tab_2d_3d( nidx, idxice(1:nidx), smv_i_2d(1:nidx,1:jpl), smv_i  )
-      CALL tab_2d_3d( nidx, idxice(1:nidx), a_ip_2d (1:nidx,1:jpl), a_ip   )
-      CALL tab_2d_3d( nidx, idxice(1:nidx), v_ip_2d (1:nidx,1:jpl), v_ip   )
-      CALL tab_2d_3d( nidx, idxice(1:nidx), t_su_2d (1:nidx,1:jpl), t_su   )
-
+      !
+      CALL tab_2d_3d( nidx, idxice(1:nidx), ht_i_2d (1:nidx,1:jpl), ht_i  )
+      CALL tab_2d_3d( nidx, idxice(1:nidx), a_i_2d  (1:nidx,1:jpl), a_i   )
+      CALL tab_2d_3d( nidx, idxice(1:nidx), v_i_2d  (1:nidx,1:jpl), v_i   )
+      CALL tab_2d_3d( nidx, idxice(1:nidx), v_s_2d  (1:nidx,1:jpl), v_s   )
+      CALL tab_2d_3d( nidx, idxice(1:nidx), oa_i_2d (1:nidx,1:jpl), oa_i  )
+      CALL tab_2d_3d( nidx, idxice(1:nidx), smv_i_2d(1:nidx,1:jpl), smv_i )
+      CALL tab_2d_3d( nidx, idxice(1:nidx), a_ip_2d (1:nidx,1:jpl), a_ip  )
+      CALL tab_2d_3d( nidx, idxice(1:nidx), v_ip_2d (1:nidx,1:jpl), v_ip  )
+      CALL tab_2d_3d( nidx, idxice(1:nidx), t_su_2d (1:nidx,1:jpl), t_su  )
       !
    END SUBROUTINE ice_itd_shiftice
@@ -559,17 +558,13 @@
       REAL(wp), DIMENSION(jpij,jpl-1) ::   zdaice, zdvice   ! ice area and volume transferred
       !!------------------------------------------------------------------
-      
-      DO jl = 1, jpl-1
-         jdonor(:,jl) = 0
-         zdaice(:,jl) = 0._wp
-         zdvice(:,jl) = 0._wp
-      END DO
-
-      !---------------------------------------
-      ! identify thicknesses that are too big
-      !---------------------------------------
-      DO jl = 1, jpl - 1
-
-         nidx = 0 ; idxice(:) = 0
+      !
+      jdonor(:,:) = 0
+      zdaice(:,:) = 0._wp
+      zdvice(:,:) = 0._wp
+      !
+      !                       !---------------------------------------
+      DO jl = 1, jpl-1        ! identify thicknesses that are too big
+         !                    !---------------------------------------
+         nidx = 0   ;   idxice(:) = 0
          DO jj = 1, jpj
             DO ji = 1, jpi
@@ -578,11 +573,11 @@
                   idxice( nidx ) = (jj - 1) * jpi + ji                  
                ENDIF
-            ENDDO
-         ENDDO
-         
+            END DO
+         END DO
+         !
 !!clem   CALL tab_2d_1d( nidx, idxice(1:nidx), ht_i_1d (1:nidx), ht_i(:,:,jl)   )
          CALL tab_2d_1d( nidx, idxice(1:nidx), a_i_1d  (1:nidx), a_i(:,:,jl)    )
          CALL tab_2d_1d( nidx, idxice(1:nidx), v_i_1d  (1:nidx), v_i(:,:,jl)    )
-
+         !
          DO ji = 1, nidx
             jdonor(ji,jl)  = jl 
@@ -597,7 +592,6 @@
             zdaice(ji,jl)  = a_i_1d(ji) * 0.5_wp
             zdvice(ji,jl)  = v_i_1d(ji) - zdaice(ji,jl) * ( hi_max(jl) + hi_max(jl-1) ) * 0.5_wp
-            
-         END DO
-
+         END DO
+         !
          IF( nidx > 0 ) THEN
             CALL ice_itd_shiftice( jdonor(1:nidx,:), zdaice(1:nidx,:), zdvice(1:nidx,:) )  ! Shift jl=>jl+1
@@ -610,9 +604,7 @@
       END DO
 
-      !-----------------------------------------
-      ! Identify thicknesses that are too small
-      !-----------------------------------------
-      DO jl = jpl - 1, 1, -1
-
+      !                       !-----------------------------------------
+      DO jl = jpl-1, 1, -1    ! Identify thicknesses that are too small
+         !                    !-----------------------------------------
          nidx = 0 ; idxice(:) = 0
          DO jj = 1, jpj
@@ -622,7 +614,7 @@
                   idxice( nidx ) = (jj - 1) * jpi + ji                  
                ENDIF
-            ENDDO
-         ENDDO
-
+            END DO
+         END DO
+         !
          CALL tab_2d_1d( nidx, idxice(1:nidx), a_i_1d  (1:nidx), a_i(:,:,jl+1)    ) ! jl+1 is ok
          CALL tab_2d_1d( nidx, idxice(1:nidx), v_i_1d  (1:nidx), v_i(:,:,jl+1)    ) ! jl+1 is ok
@@ -632,5 +624,5 @@
             zdvice(ji,jl) = v_i_1d(ji)
          END DO
-         
+         !
          IF( nidx > 0 ) THEN
             CALL ice_itd_shiftice( jdonor(1:nidx,:), zdaice(1:nidx,:), zdvice(1:nidx,:) )  ! Shift jl+1=>jl
@@ -640,10 +632,15 @@
             zdvice(1:nidx,jl) = 0._wp
          ENDIF
-
+         !
       END DO
       !
    END SUBROUTINE ice_itd_reb
 
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :         Empty module          NO LIM sea-ice model
+   !!----------------------------------------------------------------------
 #endif
+
    !!======================================================================
 END MODULE iceitd
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerdgrft.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerdgrft.F90	(revision 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerdgrft.F90	(revision 8486)
@@ -12,19 +12,19 @@
    !!   'key_lim3'                                      LIM-3 sea-ice model
    !!----------------------------------------------------------------------
-   USE par_oce          ! ocean parameters
-   USE dom_oce          ! ocean domain
-   USE phycst           ! physical constants (ocean directory) 
-   USE sbc_oce, ONLY: sss_m, sst_m          ! surface boundary condition: ocean fields
-   USE ice1D            ! LIM thermodynamics
-   USE ice              ! LIM variables
-   USE icevar           ! LIM
-   USE icectl           ! control prints
+   USE par_oce        ! ocean parameters
+   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
+   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
@@ -32,7 +32,7 @@
 
    PUBLIC   ice_rdgrft               ! called by ice_stp
-   PUBLIC   ice_rdgrft_icestrength
-   PUBLIC   ice_rdgrft_init
-   PUBLIC   ice_rdgrft_alloc        ! called by ice_init 
+   PUBLIC   ice_rdgrft_icestrength   ! called by icerhg_evp
+   PUBLIC   ice_rdgrft_init          ! called by ice_stp
+   PUBLIC   ice_rdgrft_alloc         ! called by ice_init 
 
    !-----------------------------------------------------------------------
@@ -52,9 +52,14 @@
    REAL(wp), PARAMETER ::   kraft   = 0.5_wp    ! rafting multipliyer
 
-   REAL(wp) ::   Cp                             ! 
+!!gm Cp is  1) not DOCTOR, 
+!!          2) misleading name: heat capacity instead of a constant,
+!!          3) recomputed at each time-step, whereas it is stored in the module memory...
+!!             ===>>> compute it one for all inside the IF( kt == nit000 ) (i.e. without the ".AND. lwp")
+   REAL(wp)            ::   Cp                  ! ??? !!gm  Not doctor ! 
+   
    !
    !
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 3.3 , UCL - NEMO Consortium (2010)
+   !! 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)
@@ -66,9 +71,7 @@
       !!                ***  ROUTINE ice_rdgrft_alloc ***
       !!---------------------------------------------------------------------!
-      ALLOCATE(                                                                      &
-         !* Variables shared among ridging subroutines
-         &      asum (jpi,jpj)     , athorn(jpi,jpj,0:jpl) , aksum (jpi,jpj)     ,   &
-         &      hrmin(jpi,jpj,jpl) , hraft(jpi,jpj,jpl)    , aridge(jpi,jpj,jpl) ,   &
-         &      hrmax(jpi,jpj,jpl) , krdg (jpi,jpj,jpl)    , araft (jpi,jpj,jpl) , STAT=ice_rdgrft_alloc )
+      ALLOCATE( asum (jpi,jpj)     , athorn(jpi,jpj,0:jpl) , aksum (jpi,jpj)     ,     &
+         &      hrmin(jpi,jpj,jpl) , hraft (jpi,jpj,jpl)   , aridge(jpi,jpj,jpl) ,     &
+         &      hrmax(jpi,jpj,jpl) , krdg  (jpi,jpj,jpl)   , araft (jpi,jpj,jpl) , STAT=ice_rdgrft_alloc )
          !
       IF( ice_rdgrft_alloc /= 0 )   CALL ctl_warn( 'ice_rdgrft_alloc: failed to allocate arrays' )
@@ -105,14 +108,14 @@
       INTEGER, INTENT(in) ::   kt     ! number of iteration
       !!
-      INTEGER  ::   ji, jj, jk, jl        ! dummy loop index
-      INTEGER  ::   niter                 ! local integer 
-      INTEGER  ::   iterate_ridging       ! if true, repeat the ridging
-      REAL(wp) ::   za, zfac              ! local scalar
+      INTEGER  ::   ji, jj, jk, jl     ! dummy loop index
+      INTEGER  ::   niter              ! local integer 
+      INTEGER  ::   iterate_ridging    ! if =1, repeat the ridging
+      REAL(wp) ::   za, zfac, zcs_2    ! local scalar
       CHARACTER (len = 15) ::   fieldid
-      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
+      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    
@@ -124,22 +127,33 @@
       IF( kt == nit000 .AND. lwp ) THEN
          WRITE(numout,*)
-         WRITE(numout,*)'icerdgrft'
-         WRITE(numout,*)'~~~~~~~~~'
+         WRITE(numout,*)'icerdgrft : ice ridging and rafting'
+         WRITE(numout,*)'~~~~~~~~~~'
       ENDIF
-
-      ! conservation test
-      IF( ln_limdiachk ) CALL ice_cons_hsm(0, 'icerdgrft', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+!!gm should be:      
+!      IF( kt == nit000 ) THEN
+!         IF(lwp) WRITE(numout,*)
+!         IF(lwp) WRITE(numout,*)'icerdgrft : ???'
+!         IF(lwp) WRITE(numout,*)'~~~~~~~~~~'
+!         !
+!         Cp    = 0.5 * grav * (rau0-rhoic) * rhoic * r1_rau0      ! proport const for PE
+!         !
+!!gm why not adding here zcs_2 computation
+!         !
+!      ENDIF
+!!gm end
+      
+      !                    ! conservation test
+      IF( ln_limdiachk )   CALL ice_cons_hsm(0, 'icerdgrft', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
 
       !-----------------------------------------------------------------------------!
       ! 1) Thickness categories boundaries, ice / o.w. concentrations, init_ons
       !-----------------------------------------------------------------------------!
-      Cp = 0.5 * grav * (rau0-rhoic) * rhoic * r1_rau0             ! proport const for PE
-      !
-      CALL ice_rdgrft_ridgeprep                                    ! prepare ridging
-      !
-
-      DO jj = 1, jpj                                     ! Initialize arrays.
+      Cp    = 0.5 * grav * (rau0-rhoic) * rhoic * r1_rau0      ! proport const for PE
+      zcs_2 = rn_cs * 0.5_wp
+      !
+      CALL ice_rdgrft_ridgeprep                             ! prepare ridging
+      !
+      DO jj = 1, jpj                                        ! Initialize arrays.
          DO ji = 1, jpi
-
             !-----------------------------------------------------------------------------!
             ! 2) Dynamical inputs (closing rate, divu_adv, opning)
@@ -161,5 +175,5 @@
             !  (thick, newly ridged ice).
 
-            closing_net(ji,jj) = rn_cs * 0.5 * ( delta_i(ji,jj) - ABS( divu_i(ji,jj) ) ) - MIN( divu_i(ji,jj), 0._wp )
+            closing_net(ji,jj) = zcs_2 * ( delta_i(ji,jj) - ABS( divu_i(ji,jj) ) ) - MIN( divu_i(ji,jj), 0._wp )
 
             ! 2.2 divu_adv
@@ -233,7 +247,5 @@
          ! 3.3 Redistribute area, volume, and energy.
          !-----------------------------------------------------------------------------!
-
          CALL ice_rdgrft_ridgeshift( opning, closing_gross )
-
          
          ! 3.4 Compute total area of ice plus open water after ridging.
@@ -246,5 +258,4 @@
          ! 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
@@ -262,14 +273,11 @@
             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.
-
+         ! iterated globally because of the boundary update in the smoothing.
          niter = niter + 1
-
+         !
          IF( iterate_ridging == 1 ) THEN
             CALL ice_rdgrft_ridgeprep
@@ -279,5 +287,5 @@
             ENDIF
          ENDIF
-
+         !
       END DO !! on the do while over iter
 
@@ -287,12 +295,14 @@
       ! control prints
       !-----------------------------------------------------------------------------!
-      ! conservation test
-      IF( ln_limdiachk ) CALL ice_cons_hsm(1, 'icerdgrft', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      ! control prints
-      IF( ln_ctl )       CALL ice_prt3D( 'icerdgrft' )
+      !                    ! conservation test
+      IF( ln_limdiachk )   CALL ice_cons_hsm(1, 'icerdgrft', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+
+      !                    ! control prints
+      IF( ln_ctl       )   CALL ice_prt3D( 'icerdgrft' )
       !
       IF( nn_timing == 1 )  CALL timing_stop('icerdgrft')
+      !
    END SUBROUTINE ice_rdgrft
+
 
    SUBROUTINE ice_rdgrft_ridgeprep
@@ -305,37 +315,44 @@
       !!              participating in ridging and of the resulting ridges.
       !!---------------------------------------------------------------------!
-      INTEGER  ::   ji,jj, jl    ! dummy loop indices
-      REAL(wp) ::   Gstari, astari, hrmean, zdummy   ! local scalar
+      INTEGER  ::   ji, jj, jl    ! dummy loop indices
+      REAL(wp) ::   Gstari, astari, hrmean, zdummy   ! local scalar     !!gm DOCTOR norme should start with z !!!!!
       REAL(wp), DIMENSION(jpi,jpj,-1:jpl) ::   Gsum      ! Gsum(n) = sum of areas in categories 0 to n
       !------------------------------------------------------------------------------!
 
-      Gstari     = 1.0/rn_gstar    
-      astari     = 1.0/rn_astar    
-      aksum(:,:)    = 0.0
-      athorn(:,:,:) = 0.0
-      aridge(:,:,:) = 0.0
-      araft (:,:,:) = 0.0
-
-      ! Zero out categories with very small areas
-      CALL ice_var_zapsmall
-
-      ! Ice thickness needed for rafting
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               rswitch = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi20 ) )
-               ht_i(ji,jj,jl) = v_i (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-           END DO
-         END DO
-      END DO
+      Gstari        = 1._wp / rn_gstar    
+      astari        = 1._wp / rn_astar    
+      aksum(:,:)    = 0._wp
+      athorn(:,:,:) = 0._wp
+      aridge(:,:,:) = 0._wp
+      araft (:,:,:) = 0._wp
+
+      CALL ice_var_zapsmall   ! Zero out categories with very small areas
+
+!      DO jl = 1, jpl          ! Ice thickness needed for rafting
+!         DO jj = 1, jpj
+!            DO ji = 1, jpi
+!!gm               rswitch = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi20 ) )
+!!gm               ht_i(ji,jj,jl) = v_i (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
+!               IF( a_i(ji,jj,jl) >= epsi20 ) THEN   ;   ht_i(ji,jj,jl) = v_i (ji,jj,jl) / a_i(ji,jj,jl)
+!               ELSE                                 ;   ht_i(ji,jj,jl) = 0._wp
+!               ENDIF
+!           END DO
+!         END DO
+!      END DO
+!!gm or even better :
+!     !                       ! Ice thickness needed for rafting
+      WHERE( a_i(:,:,:) >= epsi20 )   ;   ht_i(:,:,:) = v_i (:,:,:) / a_i(:,:,:)
+      ELSEWHERE                       ;   ht_i(:,:,:) = 0._wp
+      END WHERE
+!!gm end
 
       !------------------------------------------------------------------------------!
       ! 1) Participation function 
       !------------------------------------------------------------------------------!
-
+      !
       ! Compute total area of ice plus open water.
       ! This is in general not equal to one because of divergence during transport
       asum(:,:) = ato_i(:,:) + SUM( a_i, dim=3 )
-
+      !
       ! Compute cumulative thickness distribution function
       ! Compute the cumulative thickness distribution function Gsum,
@@ -348,5 +365,5 @@
          Gsum(:,:,jl) = Gsum(:,:,jl-1) + a_i(:,:,jl)
       END DO
-
+      !
       ! Normalize the cumulative distribution to 1
       DO jl = 0, jpl
@@ -366,5 +383,5 @@
       ! athorn is always >= 0 and SUM(athorn(0:jpl))=1
       !-----------------------------------------------------------------
-
+      !
       IF( nn_partfun == 0 ) THEN       !--- Linear formulation (Thorndike et al., 1975)
          DO jl = 0, jpl    
@@ -383,5 +400,5 @@
             END DO
          END DO
-
+         !
       ELSE                             !--- Exponential, more stable formulation (Lipscomb et al, 2007)
          !                        
@@ -396,7 +413,6 @@
       ENDIF
 
-      ! --- Ridging and rafting participation concentrations --- !
-      IF( ln_rafting .AND. ln_ridging ) THEN
-         !
+      !                                !--- Ridging and rafting participation concentrations
+      IF( ln_rafting .AND. ln_ridging ) THEN             !- ridging & rafting
          DO jl = 1, jpl
             DO jj = 1, jpj 
@@ -408,17 +424,12 @@
             END DO
          END DO
-         !
-      ELSEIF( ln_ridging .AND. .NOT. ln_rafting ) THEN
-         !
+      ELSEIF( ln_ridging .AND. .NOT.ln_rafting ) THEN   !- ridging alone
          DO jl = 1, jpl
             aridge(:,:,jl) = athorn(:,:,jl)
          END DO
-         !
-      ELSEIF( ln_rafting .AND. .NOT. ln_ridging ) THEN
-         !
+      ELSEIF( ln_rafting .AND. .NOT.ln_ridging ) THEN   !- rafting alone   
          DO jl = 1, jpl
             araft(:,:,jl) = athorn(:,:,jl)
          END DO
-         !
       ENDIF
 
@@ -454,16 +465,14 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               
-               IF( athorn(ji,jj,jl) > 0._wp ) THEN
+               IF ( athorn(ji,jj,jl) > 0._wp ) THEN
                   hrmean          = MAX( SQRT( rn_hstar * ht_i(ji,jj,jl) ), ht_i(ji,jj,jl) * krdgmin )
                   hrmin(ji,jj,jl) = MIN( 2._wp * ht_i(ji,jj,jl), 0.5_wp * ( hrmean + ht_i(ji,jj,jl) ) )
                   hrmax(ji,jj,jl) = 2._wp * hrmean - hrmin(ji,jj,jl)
                   hraft(ji,jj,jl) = ht_i(ji,jj,jl) / kraft
-                  krdg(ji,jj,jl)  = ht_i(ji,jj,jl) / MAX( hrmean, epsi20 )
-
+                  krdg (ji,jj,jl) = ht_i(ji,jj,jl) / MAX( hrmean, epsi20 )
+                  !
                   ! Normalization factor : aksum, ensures mass conservation
                   aksum(ji,jj) = aksum(ji,jj) + aridge(ji,jj,jl) * ( 1._wp - krdg(ji,jj,jl) )    &
                      &                        + araft (ji,jj,jl) * ( 1._wp - kraft          )
-
                ELSE
                   hrmin(ji,jj,jl)  = 0._wp 
@@ -472,9 +481,7 @@
                   krdg (ji,jj,jl)  = 1._wp
                ENDIF
-
             END DO
          END DO
       END DO
-      !
       !
    END SUBROUTINE ice_rdgrft_ridgeprep
@@ -493,5 +500,5 @@
       REAL(wp), DIMENSION(jpi,jpj), INTENT(in   ) ::   closing_gross  ! rate at which area removed, excluding area of new ridges
       !
-      CHARACTER (len=80) ::   fieldid   ! field identifier
+      CHARACTER (len=80) ::   fieldid   ! field identifier     !!gm DOCTOR name wrong
       !
       INTEGER ::   ji, jj, jl, jl1, jl2, jk   ! dummy loop indices
@@ -740,10 +747,9 @@
 
                ! Compute the fraction of rafted ice area and volume going to thickness category jl2
-               IF( hraft(ji,jj,jl1) <= hi_max(jl2) .AND. hraft(ji,jj,jl1) >  hi_max(jl2-1) ) THEN
-                  zswitch(ij) = 1._wp
-               ELSE
-                  zswitch(ij) = 0._wp                  
+!!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) )
@@ -756,11 +762,10 @@
                ! MV MP 2016
                IF ( nn_pnd_scheme > 0 ) THEN
-                  v_ip (ji,jj,jl2) = v_ip (ji,jj,jl2)  + ( vprdg (ij) * rn_fpondrdg * fvol(ij)  +   &
-                                                       &   vprft (ij) * rn_fpondrft * zswitch(ij) )
-                  a_ip (ji,jj,jl2) = a_ip(ji,jj,jl2)   + ( aprdg2(ij) * rn_fpondrdg * farea +       & 
-                                                       &   aprft2(ij) * rn_fpondrft * zswitch(ji) )
+                  v_ip (ji,jj,jl2) = v_ip(ji,jj,jl2) + (   vprdg (ij) * rn_fpondrdg * fvol   (ij)   &
+                     &                                   + vprft (ij) * rn_fpondrft * zswitch(ij)   )
+                  a_ip (ji,jj,jl2) = a_ip(ji,jj,jl2) + (   aprdg2(ij) * rn_fpondrdg * farea         & 
+                     &                                   + aprft2(ij) * rn_fpondrft * zswitch(ji)   )
                ENDIF
                ! END MV MP 2016
-
             END DO
 
@@ -774,5 +779,5 @@
             !
          END DO ! jl2
-         
+         !
       END DO ! jl1 (deforming categories)
 
@@ -782,4 +787,5 @@
       !
    END SUBROUTINE ice_rdgrft_ridgeshift
+
 
    SUBROUTINE ice_rdgrft_icestrength( kstrngth )
@@ -798,7 +804,8 @@
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kstrngth    ! = 1 for Rothrock formulation, 0 for Hibler (1979)
+      !
       INTEGER             ::   ji,jj, jl   ! dummy loop indices
-      INTEGER             ::   ksmooth     ! smoothing the resistance to deformation
-      INTEGER             ::   numts_rm    ! number of time steps for the P smoothing
+      INTEGER             ::   ksmooth     ! smoothing the resistance to deformation    !!gm not DOCTOR : start with i !!!
+      INTEGER             ::   numts_rm    ! number of time steps for the P smoothing    !!gm not DOCTOR : start with i !!!
       REAL(wp)            ::   zp, z1_3    ! local scalars
       REAL(wp), DIMENSION(jpi,jpj) ::   zworka           ! temporary array used here
@@ -880,10 +887,8 @@
       ! 6) Smoothing ice strength
       !------------------------------------------------------------------------------!
-      !
-      !-------------------
-      ! Spatial smoothing
-      !-------------------
-      IF ( ksmooth == 1 ) THEN
-
+      SELECT CASE( ksmooth )
+      !                       !-------------------
+      CASE( 1 )               ! Spatial smoothing
+         !                    !-------------------
          DO jj = 2, jpjm1
             DO ji = 2, jpim1
@@ -905,17 +910,13 @@
          END DO
          CALL lbc_lnk( strength, 'T', 1. )
-
-      ENDIF
-
-      !--------------------
-      ! Temporal smoothing
-      !--------------------
-      IF ( ksmooth == 2 ) THEN
-
+         !
+         !                    !--------------------
+      CASE( 2 )               ! Temporal smoothing
+         !                    !--------------------
          IF ( kt_ice == nit000 ) THEN
             zstrp1(:,:) = 0._wp
             zstrp2(:,:) = 0._wp
          ENDIF
-
+         !
          DO jj = 2, jpjm1
             DO ji = 2, jpim1
@@ -925,20 +926,20 @@
                   IF ( zstrp2(ji,jj) > 0._wp ) numts_rm = numts_rm + 1
                   zp = ( strength(ji,jj) + zstrp1(ji,jj) + zstrp2(ji,jj) ) / numts_rm
-                  zstrp2(ji,jj) = zstrp1(ji,jj)
-                  zstrp1(ji,jj) = strength(ji,jj)
+                  zstrp2  (ji,jj) = zstrp1  (ji,jj)
+                  zstrp1  (ji,jj) = strength(ji,jj)
                   strength(ji,jj) = zp
                ENDIF
             END DO
          END DO
-
          CALL lbc_lnk( strength, 'T', 1. )      ! Boundary conditions
-
-      ENDIF ! ksmooth
+         !
+      END SELECT
       !
    END SUBROUTINE ice_rdgrft_icestrength
+
 
    SUBROUTINE ice_rdgrft_init
       !!-------------------------------------------------------------------
-      !!                   ***  ROUTINE ice_rdgrft_init ***
+      !!                  ***  ROUTINE ice_rdgrft_init ***
       !!
       !! ** Purpose :   Physical constants and parameters linked 
@@ -952,7 +953,8 @@
       !!-------------------------------------------------------------------
       INTEGER :: ios                 ! Local integer output status for namelist read
-      NAMELIST/namiceitdme/ rn_cs, nn_partfun, rn_gstar, rn_astar,             & 
-        &                   ln_ridging, rn_hstar, rn_por_rdg, rn_fsnowrdg, rn_fpondrdg, & 
-                            ln_rafting, rn_hraft, rn_craft,   rn_fsnowrft, rn_fpondrft
+      !!
+      NAMELIST/namiceitdme/ rn_cs     , nn_partfun, rn_gstar  , rn_astar   ,                & 
+         &                  ln_ridging, rn_hstar  , rn_por_rdg, rn_fsnowrdg, rn_fpondrdg,   & 
+         &                  ln_rafting, rn_hraft  , rn_craft  , rn_fsnowrft, rn_fpondrft
       !!-------------------------------------------------------------------
       !
@@ -960,5 +962,5 @@
       READ  ( numnam_ice_ref, namiceitdme, IOSTAT = ios, ERR = 901)
 901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namiceitdme in reference namelist', lwp )
-
+      !
       REWIND( numnam_ice_cfg )              ! Namelist namiceitdme in configuration namelist : Ice mechanical ice redistribution
       READ  ( numnam_ice_cfg, namiceitdme, IOSTAT = ios, ERR = 902 )
@@ -992,12 +994,6 @@
    !!   Default option         Empty module          NO LIM-3 sea-ice model
    !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE ice_rdgrft           ! Empty routines
-   END SUBROUTINE ice_rdgrft
-   SUBROUTINE ice_rdgrft_icestrength
-   END SUBROUTINE ice_rdgrft_icestrength
-   SUBROUTINE ice_rdgrft_init
-   END SUBROUTINE ice_rdgrft_init
 #endif
+
    !!======================================================================
 END MODULE icerdgrft
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerhg.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerhg.F90	(revision 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerhg.F90	(revision 8486)
@@ -10,21 +10,21 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                 LIM3 sea-ice model
+   !!   '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              ! LIM-3 variables
-   USE icerhg_evp       ! EVP rheology
-   USE icectl           ! control prints
-   USE icevar
+   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 icevar         ! sea-ice: operations
    !
-   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
+   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
@@ -37,5 +37,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! 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)
@@ -53,28 +53,28 @@
       !!                      - shear, divergence and delta (shear_i, divu_i, delta_i)
       !!--------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt     ! number of iteration
+      INTEGER, INTENT(in) ::   kt     ! ice time step
       !!
-      INTEGER  :: jl ! dummy loop indices
+      INTEGER  ::   jl   ! dummy loop indices
       REAL(wp) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
       !!--------------------------------------------------------------------
-
+      !
       IF( nn_timing == 1 )  CALL timing_start('icerhg')
-
+      !
       IF( kt == nit000 .AND. lwp ) THEN
          WRITE(numout,*)
-         WRITE(numout,*)'icerhg'
-         WRITE(numout,*)'~~~~~~'
+         WRITE(numout,*)'ice_rhg : sea-ice rheology'
+         WRITE(numout,*)'~~~~~~~~'
       ENDIF
 
-      CALL ice_var_agg(1)   ! aggregate ice categories
+      CALL ice_var_agg(1)           ! -- aggregate ice categories
       !
-      ! conservation test
-      IF( ln_limdiachk ) CALL ice_cons_hsm(0, 'icerhg', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-      
-      ! Landfast ice parameterization: define max bottom friction
-      tau_icebfr(:,:) = 0._wp
-      IF( ln_landfast ) THEN
+      !                             ! -- conservation test
+      IF( ln_limdiachk )   CALL ice_cons_hsm(0, 'icerhg', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      !                      
+      IF( ln_landfast ) THEN        ! -- Landfast ice parameterization: define max bottom friction
          DO jl = 1, jpl
-            WHERE( ht_i(:,:,jl) > ht_n(:,:) * rn_gamma )  tau_icebfr(:,:) = tau_icebfr(:,:) + a_i(:,:,jl) * rn_icebfr
+            WHERE( ht_i(:,:,jl) > ht_n(:,:) * rn_gamma )   ;   tau_icebfr(:,:) = tau_icebfr(:,:) + a_i(:,:,jl) * rn_icebfr
+            ELSEWHERE                                      ;   tau_icebfr(:,:) = 0._wp
+            END WHERE
          END DO
       ENDIF
@@ -83,25 +83,22 @@
       ! Rheology (ice dynamics)
       ! -----------------------   
-      IF( nn_limdyn /= 0 ) THEN                          ! -- Ice dynamics
-
+      IF( nn_limdyn /= 0 ) THEN     ! -- Ice dynamics
+         !
          CALL ice_rhg_evp( stress1_i, stress2_i, stress12_i, u_ice, v_ice, shear_i, divu_i, delta_i )
-
-      ELSE
-
-         u_ice(:,:) = rn_uice * umask(:,:,1)             !     or prescribed velocity
+         !
+      ELSE                          ! -- prescribed uniform velocity
+         !
+         u_ice(:,:) = rn_uice * umask(:,:,1)
          v_ice(:,:) = rn_vice * vmask(:,:,1)
          !!CALL RANDOM_NUMBER(u_ice(:,:))
          !!CALL RANDOM_NUMBER(v_ice(:,:))
-
+         !
       ENDIF
       !
-      ! conservation test
-      IF( ln_limdiachk ) CALL ice_cons_hsm(1, 'icerhg', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      ! Control prints
-      IF( ln_ctl )       CALL ice_prt3D( 'icerhg' )
+      !                                                   !- conservation test
+      IF( ln_limdiachk   )   CALL ice_cons_hsm(1, 'icerhg', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      IF( ln_ctl         )   CALL ice_prt3D  ('icerhg')   !- Control prints
+      IF( nn_timing == 1 )   CALL timing_stop('icerhg')   !- timing
       !
-      IF( nn_timing == 1 )  CALL timing_stop('icerhg')
-
    END SUBROUTINE ice_rhg
 
@@ -119,54 +116,62 @@
       !! ** input   :   Namelist namicedyn
       !!-------------------------------------------------------------------
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namicedyn/ nn_limadv, nn_limadv_ord,                                &
-         &                nn_icestr, rn_pe_rdg, rn_pstar, rn_crhg, ln_icestr_bvf,  &
-         &                rn_ishlat, rn_cio, rn_creepl, rn_ecc,                    &
-         &                nn_nevp, rn_relast, ln_landfast, rn_gamma, rn_icebfr, rn_lfrelax
+      INTEGER ::   ios   ! Local integer output status for namelist read
+      !!
+      NAMELIST/namicedyn/ nn_limadv  , nn_limadv_ord,                                       &
+         &                nn_icestr  , rn_pe_rdg, rn_pstar , rn_crhg, ln_icestr_bvf     ,   &
+         &                rn_ishlat  , rn_cio   , rn_creepl, rn_ecc , nn_nevp, rn_relast,   &
+         &                ln_landfast, rn_gamma , rn_icebfr, rn_lfrelax
       !!-------------------------------------------------------------------
-
-      REWIND( numnam_ice_ref )              ! Namelist namicedyn in reference namelist : Ice dynamics
+      !
+      REWIND( numnam_ice_ref )         ! Namelist namicedyn in reference namelist : Ice dynamics
       READ  ( numnam_ice_ref, namicedyn, IOSTAT = ios, ERR = 901)
 901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicedyn in reference namelist', lwp )
-
-      REWIND( numnam_ice_cfg )              ! Namelist namicedyn in configuration namelist : Ice dynamics
+      !
+      REWIND( numnam_ice_cfg )         ! Namelist namicedyn in configuration namelist : Ice dynamics
       READ  ( numnam_ice_cfg, namicedyn, IOSTAT = ios, ERR = 902 )
 902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicedyn in configuration namelist', lwp )
       IF(lwm) WRITE ( numoni, namicedyn )
-      
-      IF(lwp) THEN                        ! control print
+      !
+      IF(lwp) THEN                     ! control print
          WRITE(numout,*)
          WRITE(numout,*) 'ice_rhg_init : ice parameters for ice dynamics '
          WRITE(numout,*) '~~~~~~~~~~~~'
-         ! limtrp
-         WRITE(numout,*)'    choose the advection scheme (-1=Prather, 0=Ulimate-Macho)   nn_limadv     = ', nn_limadv 
-         WRITE(numout,*)'    choose the order of the scheme (if ultimate)                nn_limadv_ord = ', nn_limadv_ord  
-         ! icerdgrft
-         WRITE(numout,*)'    ice strength parameterization (0=Hibler 1=Rothrock)         nn_icestr     = ', nn_icestr 
-         WRITE(numout,*)'    Ratio of ridging work to PotEner change in ridging          rn_pe_rdg     = ', rn_pe_rdg 
-         WRITE(numout,*) '   first bulk-rheology parameter                               rn_pstar      = ', rn_pstar
-         WRITE(numout,*) '   second bulk-rhelogy parameter                               rn_crhg       = ', rn_crhg
-         WRITE(numout,*)'    Including brine volume in ice strength comp.                ln_icestr_bvf = ', ln_icestr_bvf
-         ! icerhg_evp
-         WRITE(numout,*) '   lateral boundary condition for sea ice dynamics             rn_ishlat     = ', rn_ishlat
-         WRITE(numout,*) '   drag coefficient for oceanic stress                         rn_cio        = ', rn_cio
-         WRITE(numout,*) '   creep limit                                                 rn_creepl     = ', rn_creepl
-         WRITE(numout,*) '   eccentricity of the elliptical yield curve                  rn_ecc        = ', rn_ecc
-         WRITE(numout,*) '   number of iterations for subcycling                         nn_nevp       = ', nn_nevp
-         WRITE(numout,*) '   ratio of elastic timescale over ice time step               rn_relast     = ', rn_relast
-         WRITE(numout,*) '   Landfast: param (T or F)                                    ln_landfast   = ', ln_landfast
-         WRITE(numout,*) '      T: fraction of ocean depth that ice must reach           rn_gamma      = ', rn_gamma
-         WRITE(numout,*) '      T: maximum bottom stress per unit area of contact        rn_icebfr     = ', rn_icebfr
-         WRITE(numout,*) '      T: relax time scale (s-1) to reach static friction       rn_lfrelax    = ', rn_lfrelax
+         WRITE(numout,*) '   Namelist namicedyn'
+         WRITE(numout,*) '      advection scheme for ice transport (limtrp)'
+         WRITE(numout,*) '         type of advection scheme (-1=Prather, 0=Ulimate-Macho)   nn_limadv     = ', nn_limadv 
+         WRITE(numout,*) '         order of the scheme for Ultimate-Macho case              nn_limadv_ord = ', nn_limadv_ord
+         WRITE(numout,*) '      ridging/rafting (icerdgrft)'
+         WRITE(numout,*) '         ice strength parameterization (0=Hibler 1=Rothrock)      nn_icestr     = ', nn_icestr 
+         WRITE(numout,*) '         Ratio of ridging work to PotEner change in ridging       rn_pe_rdg     = ', rn_pe_rdg 
+         WRITE(numout,*) '         1st bulk-rheology parameter                              rn_pstar      = ', rn_pstar
+         WRITE(numout,*) '         2nd bulk-rhelogy parameter                               rn_crhg       = ', rn_crhg
+         WRITE(numout,*) '         brine volume included in ice strength computation        ln_icestr_bvf = ', ln_icestr_bvf
+         WRITE(numout,*) '      rheology EVP (icerhg_evp)'
+         WRITE(numout,*) '         lateral boundary condition for sea ice dynamics          rn_ishlat     = ', rn_ishlat
+         WRITE(numout,*) '         drag coefficient for oceanic stress                      rn_cio        = ', rn_cio
+         WRITE(numout,*) '         creep limit                                              rn_creepl     = ', rn_creepl
+         WRITE(numout,*) '         eccentricity of the elliptical yield curve               rn_ecc        = ', rn_ecc
+         WRITE(numout,*) '         number of iterations for subcycling                      nn_nevp       = ', nn_nevp
+         WRITE(numout,*) '         ratio of elastic timescale over ice time step            rn_relast     = ', rn_relast
+         WRITE(numout,*) '      Landfast: param (T or F)                                    ln_landfast   = ', ln_landfast
+         WRITE(numout,*) '         fraction of ocean depth that ice must reach              rn_gamma      = ', rn_gamma
+         WRITE(numout,*) '         maximum bottom stress per unit area of contact           rn_icebfr     = ', rn_icebfr
+         WRITE(numout,*) '         relax time scale (s-1) to reach static friction          rn_lfrelax    = ', rn_lfrelax
       ENDIF
       !
-      IF     (      rn_ishlat == 0.                ) THEN   ;   IF(lwp) WRITE(numout,*) '   ice lateral  free-slip '
-      ELSEIF (      rn_ishlat == 2.                ) THEN   ;   IF(lwp) WRITE(numout,*) '   ice lateral  no-slip '
-      ELSEIF ( 0. < rn_ishlat .AND. rn_ishlat < 2. ) THEN   ;   IF(lwp) WRITE(numout,*) '   ice lateral  partial-slip '
-      ELSEIF ( 2. < rn_ishlat                      ) THEN   ;   IF(lwp) WRITE(numout,*) '   ice lateral  strong-slip '
+      IF     (      rn_ishlat == 0.                ) THEN   ;   IF(lwp) WRITE(numout,*) '   ===>>>   ice lateral  free-slip'
+      ELSEIF (      rn_ishlat == 2.                ) THEN   ;   IF(lwp) WRITE(numout,*) '   ===>>>   ice lateral  no-slip'
+      ELSEIF ( 0. < rn_ishlat .AND. rn_ishlat < 2. ) THEN   ;   IF(lwp) WRITE(numout,*) '   ===>>>   ice lateral  partial-slip'
+      ELSEIF ( 2. < rn_ishlat                      ) THEN   ;   IF(lwp) WRITE(numout,*) '   ===>>>   ice lateral  strong-slip'
       ENDIF
+      !
+      IF( .NOT. ln_landfast )   tau_icebfr(:,:) = 0._wp     ! NO Landfast ice : set to zero one for all
       !
    END SUBROUTINE ice_rhg_init
 
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty module          NO LIM-3 sea-ice model
+   !!----------------------------------------------------------------------
 #endif 
 
Index: /branches/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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerhg_evp.F90	(revision 8486)
@@ -45,5 +45,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! 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)
@@ -386,6 +386,5 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1               
-
-               ! U points
+               !                   !--- 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)    &
@@ -394,6 +393,6 @@
                   &                    ) * 2._wp * r1_e1u(ji,jj)                                                              &
                   &                  ) * r1_e1e2u(ji,jj)
-
-               ! V points
+                  !
+                  !                !--- 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)    &
@@ -402,13 +401,13 @@
                   &                    ) * 2._wp * r1_e2v(ji,jj)                                                              &
                   &                  ) * r1_e1e2v(ji,jj)
-
-               ! u_ice at V point
+                  !
+                  !                !--- u_ice at V point
                u_iceV(ji,jj) = 0.5_wp * ( ( u_ice(ji,jj  ) + u_ice(ji-1,jj  ) ) * e2t(ji,jj+1)     &
                   &                     + ( u_ice(ji,jj+1) + u_ice(ji-1,jj+1) ) * e2t(ji,jj  ) ) * z1_e2t0(ji,jj) * vmask(ji,jj,1)
-               
-               ! v_ice at U point
+                  !
+                  !                !--- v_ice at U point
                v_iceU(ji,jj) = 0.5_wp * ( ( v_ice(ji  ,jj) + v_ice(ji  ,jj-1) ) * e1t(ji+1,jj)     &
                   &                     + ( v_ice(ji+1,jj) + v_ice(ji+1,jj-1) ) * e1t(ji  ,jj) ) * z1_e1t0(ji,jj) * umask(ji,jj,1)
-
+               !
             END DO
          END DO
@@ -417,32 +416,30 @@
          !  Bouillon et al. 2013 (eq 47-48) => unstable unless alpha, beta are chosen wisely and large nn_nevp
          !  Bouillon et al. 2009 (eq 34-35) => stable
-         IF( MOD(jter,2) .EQ. 0 ) THEN ! even iterations
-            
+         IF( MOD(jter,2) == 0 ) THEN ! even iterations
+            !
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1
-
-                  ! tau_io/(v_oce - v_ice)
+                     !                 !--- tau_io/(v_oce - v_ice)
                   zTauO = zaV(ji,jj) * zrhoco * SQRT( ( v_ice (ji,jj) - v_oce (ji,jj) ) * ( v_ice (ji,jj) - v_oce (ji,jj) )  &
                      &                              + ( u_iceV(ji,jj) - u_oceV(ji,jj) ) * ( u_iceV(ji,jj) - u_oceV(ji,jj) ) )
-
-                  ! Ocean-to-Ice stress
+                     !                 !--- Ocean-to-Ice stress
                   ztauy_oi(ji,jj) = zTauO * ( v_oce(ji,jj) - v_ice(ji,jj) )
-
-                  ! tau_bottom/v_ice
+                     !
+                     !                 !--- tau_bottom/v_ice
                   zvel  = MAX( zepsi, SQRT( v_ice(ji,jj) * v_ice(ji,jj) + u_iceV(ji,jj) * u_iceV(ji,jj) ) )
                   zTauB = - tau_icebfr(ji,jj) / zvel
-
-                  ! Coriolis at V-points (energy conserving formulation)
+                     !
+                     !                 !--- Coriolis at V-points (energy conserving formulation)
                   zCory(ji,jj)  = - 0.25_wp * r1_e2v(ji,jj) *  &
                      &    ( zmf(ji,jj  ) * ( e2u(ji,jj  ) * u_ice(ji,jj  ) + e2u(ji-1,jj  ) * u_ice(ji-1,jj  ) )  &
                      &    + zmf(ji,jj+1) * ( e2u(ji,jj+1) * u_ice(ji,jj+1) + e2u(ji-1,jj+1) * u_ice(ji-1,jj+1) ) )
-
-                  ! Sum of external forces (explicit solution) = F + tau_ia + Coriolis + spg + tau_io
+                     !
+                     !                 !--- 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
+                     !
+                     !                 !--- 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)
+                     !
+                     !                 !--- ice velocity using implicit formulation (cf Madec doc & Bouillon 2009)
                   v_ice(ji,jj) = ( (           rswitch   * ( zmV_t(ji,jj) * v_ice(ji,jj)                   &  ! previous velocity
                      &                                     + zTauE + zTauO * v_ice(ji,jj)                  &  ! F + tau_ia + Coriolis + spg + tau_io(only ocean part)
@@ -451,13 +448,14 @@
                      &             ) * zswitchV(ji,jj) + v_oce(ji,jj) * ( 1._wp - zswitchV(ji,jj) )        &  ! v_ice = v_oce if mass < zmmin
                      &           ) * zmaskV(ji,jj)
+                     !
                   ! Bouillon 2013
                   !!v_ice(ji,jj) = ( zmV_t(ji,jj) * ( zbeta * v_ice(ji,jj) + v_ice_b(ji,jj) )                  &
                   !!   &           + zfV(ji,jj) + 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( v_ice, 'V', -1. )
-            
+            !
 #if defined key_agrif
 !!            CALL agrif_interp_lim3( 'V', jter, nn_nevp )
@@ -465,5 +463,5 @@
 #endif
             IF( ln_bdy ) CALL bdy_ice_dyn( 'V' )
-
+            !
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1
@@ -505,5 +503,5 @@
             END DO
             CALL lbc_lnk( u_ice, 'U', -1. )
-            
+            !
 #if defined key_agrif
 !!            CALL agrif_interp_lim3( 'U', jter, nn_nevp )
@@ -511,7 +509,7 @@
 #endif
             IF( ln_bdy ) CALL bdy_ice_dyn( 'U' )
-
+            !
          ELSE ! odd iterations
-
+            !
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1
@@ -553,5 +551,5 @@
             END DO
             CALL lbc_lnk( u_ice, 'U', -1. )
-            
+            !
 #if defined key_agrif
 !!            CALL agrif_interp_lim3( 'U', jter, nn_nevp )
@@ -559,5 +557,5 @@
 #endif
             IF( ln_bdy ) CALL bdy_ice_dyn( 'U' )
-
+            !
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1
@@ -599,5 +597,5 @@
             END DO
             CALL lbc_lnk( v_ice, 'V', -1. )
-            
+            !
 #if defined key_agrif
 !!            CALL agrif_interp_lim3( 'V', jter, nn_nevp )
@@ -605,5 +603,5 @@
 #endif
             IF( ln_bdy ) CALL bdy_ice_dyn( 'V' )
-
+            !
          ENDIF
          
@@ -675,5 +673,8 @@
       ! 5) SIMIP diagnostics
       !------------------------------------------------------------------------------!
-                           
+
+!!gm  encapsulate with a flag (iom_use of the variable or better a flag defined one for all testing if one of the
+!!    diag is output.  NB the diag_...  are should only be ALLOCATED if the flag is true !
+
       DO jj = 2, jpjm1
          DO ji = 2, jpim1
@@ -714,13 +715,13 @@
 
       CALL lbc_lnk_multi(   diag_sig1   , 'T',  1., diag_sig2   , 'T',  1.,   &
-                 &          diag_dssh_dx, 'U', -1., diag_dssh_dy, 'V', -1.,   &
-                 &          diag_corstrx, 'U', -1., diag_corstry, 'V', -1.,   & 
-                 &          diag_intstrx, 'U', -1., diag_intstry, 'V', -1.    )
+         &                  diag_dssh_dx, 'U', -1., diag_dssh_dy, 'V', -1.,   &
+         &                  diag_corstrx, 'U', -1., diag_corstry, 'V', -1.,   & 
+         &                  diag_intstrx, 'U', -1., diag_intstry, 'V', -1.    )
 
       CALL lbc_lnk_multi(   diag_utau_oi, 'U', -1., diag_vtau_oi, 'V', -1.    )
 
-      CALL lbc_lnk_multi(   diag_xmtrp_ice, 'U', -1., diag_xmtrp_snw, 'U', -1., &
-                 &          diag_xatrp    , 'U', -1., diag_ymtrp_ice, 'V', -1., &
-                 &          diag_ymtrp_snw, 'V', -1., diag_yatrp    , 'V', -1.  )
+      CALL lbc_lnk_multi(   diag_xmtrp_ice, 'U', -1., diag_xmtrp_snw, 'U', -1.,   &
+         &                  diag_xatrp    , 'U', -1., diag_ymtrp_ice, 'V', -1.,   &
+         &                  diag_ymtrp_snw, 'V', -1., diag_yatrp    , 'V', -1.    )
 
       !
@@ -734,10 +735,8 @@
          CALL prt_ctl_info(charout)
          CALL prt_ctl(tab2d_1=u_ice, clinfo1=' ice_rhg_evp  : u_ice :', tab2d_2=v_ice, clinfo2=' v_ice :')
-      ENDIF
-
-      ! print charge ellipse
-      ! This can be desactivated once the user is sure that the stress state
-      ! lie on the charge ellipse. See Bouillon et al. 08 for more details
-      IF(ln_ctl) THEN
+         !
+         ! print charge ellipse
+         ! This can be desactivated once the user is sure that the stress state
+      ! lie on the charge ellipse. See Bouillon et al. (2008) for more details
          IF( MOD(kt_ice+nn_fsbc-1,nwrite) == 0 ) THEN
             WRITE(charout,FMT="('ice_rhg_evp  :', I4, I6, I1, I1, A10)") 1000, kt_ice, 0, 0, ' ch. ell. '
@@ -760,4 +759,8 @@
    END SUBROUTINE ice_rhg_evp
 
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty module          NO LIM-3 sea-ice model
+   !!----------------------------------------------------------------------
 #endif
 
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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icerst.F90	(revision 8486)
@@ -4,11 +4,11 @@
    !! Ice restart :  write the ice restart file
    !!======================================================================
-   !! History:   -   ! 2005-04 (M. Vancoppenolle) Original code
-   !!           3.0  ! 2008-03 (C. Ethe) restart files in using IOM interface
-   !!           4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !! History:   3.0  ! 2005-04 (M. Vancoppenolle) Original code
+   !!             -   ! 2008-03 (C. Ethe) restart files in using IOM interface
+   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
    !!----------------------------------------------------------------------
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                   LIM sea-ice model
+   !!   'key_lim3'                                        LIM sea-ice model
    !!----------------------------------------------------------------------
    !!   ice_rst_opn   : open ice restart file
@@ -38,5 +38,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: icerst.F90 8411 2017-08-07 16:09:12Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -123,4 +123,9 @@
       CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter   , wp ) )      ! date
 
+!!gm   It is possible and easy to define a 3D domain size (jpi,jpj,jpl) or use a SIZE( tab, DIM=3) in iom_rtput )
+!!gm         ===>>> just a simple   iom_rstput( iter, nitrst, numriw, 'v_i', v_i )  etc...
+!!gm   "just" ask Sebatien
+
+
       ! Prognostic variables 
       DO jl = 1, jpl 
@@ -639,9 +644,4 @@
    !!   Default option :       Empty module            NO LIM sea-ice model
    !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE ice_rst_read             ! Empty routine
-   END SUBROUTINE ice_rst_read
-   SUBROUTINE ice_rst_write            ! Empty routine
-   END SUBROUTINE ice_rst_write
 #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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icestp.F90	(revision 8486)
@@ -17,47 +17,41 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                  LIM 3.0 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   ice_stp  : sea-ice model time-stepping and update ocean sbc over ice-covered area
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE ice             ! LIM-3: ice variables
-   USE ice1D           ! LIM-3: thermodynamical variables
+   !!   '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  : 
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE c1d            ! 1D vertical configuration
+   USE ice            ! sea-ice: variables
+   USE ice1D          ! sea-ice: thermodynamical 1D variables
    !
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice   fields
-   USE iceforcing      ! Surface boundary condition for sea ice
+   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          ! Ice rheology
-   USE iceadv          ! Ice advection
-   USE icethd          ! Ice thermodynamics
-   USE icerdgrft       ! Ice ridging/rafting
-   USE iceupdate       ! sea surface boundary condition
-   USE icedia          ! Ice budget diagnostics
-   USE icewri          ! Ice outputs
-   USE icerst          ! Ice restarts
-   USE icecor          ! Ice corrections
-   USE icevar          ! Ice variables switch
-   USE icectl          !
+   USE phycst         ! Define parameters for the routines
+   USE eosbn2         ! equation of state
+   USE icerhg         ! sea-ice: rheology
+   USE iceadv         ! sea-ice: advection
+   USE icethd         ! sea-ice: thermodynamics
+   USE icerdgrft      ! sea-ice: ridging/rafting
+   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
+   USE limmp          ! sea-ice: melt ponds
    ! END MV MP 2016
-   USE iceist          ! LIM initial state
-   USE icethd_sal      ! LIM ice thermodynamics: salinity
+   USE iceist         ! sea-ice: initial state
+   USE icethd_sal     ! sea-ice: thermodynamics and salinity
    !
-   USE c1d             ! 1D vertical configuration
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O manager library
-   USE prtctl          ! Print control
-   USE lib_fortran     !
-   USE lbclnk          ! lateral boundary condition - MPP link
-   USE lib_mpp         ! MPP library
-   USE timing          ! Timing
-
-   USE bdy_oce   , ONLY: ln_bdy
-   USE bdyice          ! unstructured open boundary data
+   USE bdy_oce , ONLY : ln_bdy   ! flag for bdy
+   USE bdyice         ! unstructured open boundary data for sea-ice
 # if defined key_agrif
    USE agrif_ice
@@ -65,15 +59,30 @@
    USE agrif_lim3_interp
 # endif
+   !
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O manager library
+   USE prtctl         ! Print control
+   USE lib_fortran    ! 
+   USE lbclnk         ! lateral boundary condition - MPP link
+   USE lib_mpp        ! MPP library
+   USE timing         ! Timing
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC ice_stp  ! routine called by sbcmod.F90
-   PUBLIC ice_init ! routine called by sbcmod.F90
+   PUBLIC   ice_stp    ! called by sbcmod.F90
+   PUBLIC   ice_init   ! called by sbcmod.F90
+
+   INTEGER ::              nice_dyn   ! choice of the type of advection scheme
+   !                                  ! associated indices:
+   INTEGER, PARAMETER ::   np_dynNO   = 0   ! no ice dynamics and ice advection
+   INTEGER, PARAMETER ::   np_dynFULL = 1   ! full ice dynamics  (rheology + advection + ridging/rafting + correction)
+   INTEGER, PARAMETER ::   np_dyn     = 2   ! no ridging/rafting (rheology + advection                   + correction)
+   INTEGER, PARAMETER ::   np_dynPURE = 3   ! pure dynamics      (rheology + advection) 
 
    !! * Substitutions
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 4.0 , UCL NEMO Consortium (2011)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: icestp.F90 8319 2017-07-11 15:00:44Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -85,6 +94,6 @@
       !!                  ***  ROUTINE ice_stp  ***
       !!
-      !! ** Purpose :   update the ocean surface boundary condition via the
-      !!                Louvain la Neuve Sea Ice Model time stepping
+      !! ** Purpose :   sea-ice model time-stepping and update ocean surface
+      !!              boundary condition over ice-covered area
       !!
       !! ** Method  :   ice model time stepping
@@ -102,66 +111,73 @@
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt      ! ocean time step
-      INTEGER, INTENT(in) ::   ksbc    ! type of sbc flux ( 1 = user defined formulation, 
-                                       !                    3 = bulk formulation,
-                                       !                    4 = Pure Coupled formulation)
-      INTEGER  ::   jl                 ! dummy loop index
-      !!----------------------------------------------------------------------
-
+      INTEGER, INTENT(in) ::   ksbc    ! flux formulation (user defined, bulk, or Pure Coupled)
+      !
+      INTEGER ::   jl   ! dummy loop index
+      !!----------------------------------------------------------------------
+      !
       IF( nn_timing == 1 )   CALL timing_start('ice_stp')
-
-      !-----------------------!
-      ! --- Ice time step --- !
-      !-----------------------!
-      IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN
-         
-         ! Ice model time step
-         kt_ice = kt
-
+      !
+      !                                      !-----------------------!
+      IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN   ! --- Ice time step --- !
+         !                                   !-----------------------!
+         !
+         kt_ice = kt       ! Ice model time step
+         !
 # if defined key_agrif
          IF( .NOT. Agrif_Root() )  lim_nbstep = MOD( lim_nbstep, Agrif_irhot() * Agrif_Parent(nn_fsbc) / nn_fsbc ) + 1
 # endif
 
-         ! mean surface ocean current at ice velocity point (C-grid dynamics :  U- & V-points as the ocean)
+         !                 ! mean surface ocean current at ice velocity point
          u_oce(:,:) = ssu_m(:,:) * umask(:,:,1)
          v_oce(:,:) = ssv_m(:,:) * vmask(:,:,1)
-
-         ! masked sea surface freezing temperature [Kelvin] (set to rt0 over land)
+!!gm the umask, vmask above is useless as ssu_m, ssv_m are build from masked un,vn (used t be here for B-grid sea-ice)
+
+         !                 ! masked sea surface freezing temperature [Kelvin] (set to rt0 over land)
          CALL eos_fzp( sss_m(:,:) , t_bo(:,:) )
          t_bo(:,:) = ( t_bo(:,:) + rt0 ) * tmask(:,:,1) + rt0 * ( 1._wp - tmask(:,:,1) )
          !
-                                      CALL ice_bef         ! Store previous ice values
+         CALL ice_bef      ! Store previous ice values
+         !
          !------------------------------------------------!
          ! --- Dynamical coupling with the atmosphere --- !
          !------------------------------------------------!
-         ! it provides:
+         ! It provides the following fields used in sea ice model:
          !    utau_ice, vtau_ice = surface ice stress [N/m2]
-         !--------------------------------------------------
-                                      CALL ice_forcing_tau( kt, ksbc, utau_ice, vtau_ice )
+         !------------------------------------------------!
+         CALL ice_forcing_tau( kt, ksbc, utau_ice, vtau_ice )
                                       
-         !-------------------------------------------------------!
-         ! --- ice dynamics and transport (except in 1D case) ---!
-         !-------------------------------------------------------!
-                                      CALL ice_diag0           ! set diag of mass, heat and salt fluxes to 0
-                                      CALL ice_rst_opn( kt )   ! Open Ice restart file
-         !
-         ! --- zap this if no ice dynamics --- !
-         IF( .NOT. lk_c1d .AND. ln_limdyn ) THEN
-                                      CALL ice_rhg( kt )       ! -- rheology  
-                                      CALL ice_adv( kt )       ! -- advection
-            IF( nn_limdyn == 2 .AND. nn_monocat /= 2 )  &      ! -- ridging/rafting
-               &                      CALL ice_rdgrft( kt )         
-            IF( nn_limdyn == 2 )      CALL ice_cor( kt , 1 )   ! -- Corrections
-            !
-         ENDIF
-         ! ---
-         
+         !-------------------------------------!
+         ! --- ice dynamics and advection  --- !
+         !-------------------------------------!
+         CALL ice_diag0             ! set diag of mass, heat and salt fluxes to 0
+         CALL ice_rst_opn( kt )     ! Open Ice restart file (if necessary) 
+         !
+         SELECT CASE( nice_dyn )   
+         CASE ( np_dynFULL )          !==  all dynamical processes  ==!
+            CALL ice_rhg   ( kt )          ! -- rheology  
+            CALL ice_adv   ( kt )          ! -- advection of ice
+            CALL ice_rdgrft( kt )          ! -- ridging/rafting 
+            CALL ice_cor   ( kt , 1 )      ! -- Corrections
+         CASE ( np_dyn )              !==  pure dynamics only ==!   (no ridging/rafting)   (nono cat. case 2)
+            CALL ice_rhg   ( kt )          ! -- rheology  
+            CALL ice_adv   ( kt )          ! -- advection of ice
+            CALL ice_cor   ( kt , 1 )      ! -- Corrections
+         CASE ( np_dynPURE )          !==  pure dynamics only ==!   (nn_limdyn= 0 or 1 )
+            CALL ice_rhg   ( kt )          ! -- rheology  
+            CALL ice_adv   ( kt )          ! -- advection of ice
+         END SELECT
+         !
+         !                          !==  lateral boundary conditions  ==!
 #if defined key_agrif
-         IF( .NOT. Agrif_Root() )     CALL agrif_interp_lim3('T')
+         IF( .NOT. Agrif_Root()     )   CALL agrif_interp_lim3('T')   ! -- AGRIF 
 #endif
-         IF( ln_limthd .AND. ln_bdy ) CALL bdy_ice( kt )       ! -- bdy ice thermo 
-         ! previous lead fraction and ice volume for flux calculations
-                                      CALL ice_var_glo2eqv     ! ht_i and ht_s for ice albedo calculation
-                                      CALL ice_var_agg(1)      ! at_i for coupling 
-                                      CALL ice_bef
+         IF( ln_limthd .AND. ln_bdy )   CALL bdy_ice( kt )            ! -- bdy ice thermo
+         !
+         !
+         !                          !==  previous lead fraction and ice volume for flux calculations
+         !
+         CALL ice_var_glo2eqv            ! ht_i and ht_s for ice albedo calculation
+         CALL ice_var_agg(1)             ! at_i for coupling 
+         CALL ice_bef                    ! Store previous ice values
 
          !------------------------------------------------------!
@@ -169,33 +185,33 @@
          !------------------------------------------------------!
          ! It provides the following fields used in sea ice model:
-         !    fr1_i0  , fr2_i0                         = 1sr & 2nd fraction of qsr penetration in ice  [%]
-         !    emp_oce , emp_ice                        = E-P over ocean and sea ice                    [Kg/m2/s]
-         !    sprecip                                  = solid precipitation                           [Kg/m2/s]
-         !    evap_ice                                 = sublimation                                   [Kg/m2/s]
-         !    qsr_tot , qns_tot                        = solar & non solar heat flux (total)           [W/m2]
-         !    qsr_ice , qns_ice                        = solar & non solar heat flux over ice          [W/m2]
-         !    dqns_ice                                 = non solar  heat sensistivity                  [W/m2]
-         !    qemp_oce, qemp_ice, qprec_ice, qevap_ice = sensible heat (associated with evap & precip) [W/m2]
-         !------------------------------------------------------------------------------------------------------
-                                      CALL ice_forcing_flx( kt, ksbc )
+         !    fr1_i0  , fr2_i0     = 1sr & 2nd fraction of qsr penetration in ice  [%]
+         !    emp_oce , emp_ice    = E-P over ocean and sea ice                    [Kg/m2/s]
+         !    sprecip              = solid precipitation                           [Kg/m2/s]
+         !    evap_ice             = sublimation                                   [Kg/m2/s]
+         !    qsr_tot , qns_tot    = solar & non solar heat flux (total)           [W/m2]
+         !    qsr_ice , qns_ice    = solar & non solar heat flux over ice          [W/m2]
+         !    dqns_ice             = non solar  heat sensistivity                  [W/m2]
+         !    qemp_oce, qemp_ice,  = sensible heat (associated with evap & precip) [W/m2]
+         !    qprec_ice, qevap_ice
+         !------------------------------------------------------!
+         CALL ice_forcing_flx( kt, ksbc )
 
          !----------------------------!
          ! --- ice thermodynamics --- !
          !----------------------------!
-         ! --- zap this if no ice thermo --- !
-         IF( ln_limthd )              CALL ice_thd( kt )        ! -- Ice thermodynamics      
+         IF( ln_limthd )            CALL ice_thd( kt )          ! -- Ice thermodynamics      
 
          ! MV MP 2016
-         IF ( ln_pnd )                CALL lim_mp( kt )         ! -- Melt ponds
+         IF ( ln_pnd )              CALL lim_mp( kt )           ! -- Melt ponds
          ! END MV MP 2016
 
-         IF( ln_limthd )              CALL ice_cor( kt , 2 )    ! -- Corrections
+         IF( ln_limthd )            CALL ice_cor( kt , 2 )      ! -- Corrections
          ! ---
 # if defined key_agrif
-         IF( .NOT. Agrif_Root() )     CALL agrif_update_lim3( kt )
+         IF( .NOT. Agrif_Root() )   CALL agrif_update_lim3( kt )
 # endif
-                                      CALL ice_var_glo2eqv      ! necessary calls (at least for coupling)
-                                      CALL ice_var_agg( 2 )     ! necessary calls (at least for coupling)
-                                      !
+                                    CALL ice_var_glo2eqv        ! necessary calls (at least for coupling)
+                                    CALL ice_var_agg( 2 )       ! necessary calls (at least for coupling)
+                                    !
 !! clem: one should switch the calculation of the fluxes onto the parent grid but the following calls do not work
 !!       moreover it should only be called at the update frequency (as in agrif_lim3_update.F90)
@@ -203,13 +219,13 @@
 !!         IF( .NOT. Agrif_Root() )   CALL Agrif_ChildGrid_To_ParentGrid()
 !!# endif
-                                      CALL ice_update_flx( kt )    ! -- Update surface ocean mass, heat and salt fluxes
+                                    CALL ice_update_flx( kt )   ! -- Update ocean surface mass, heat and salt fluxes
 !!# if defined key_agrif
 !!         IF( .NOT. Agrif_Root() )   CALL Agrif_ParentGrid_To_ChildGrid()
 !!# endif
-         IF( ln_limdiahsb )           CALL ice_dia( kt )     ! -- Diagnostics and outputs 
+         IF( ln_limdiahsb )           CALL ice_dia( kt )        ! -- Diagnostics and outputs 
          !
                                       CALL ice_wri( 1 )         ! -- Ice outputs 
          !
-         IF( kt == nit000 .AND. ln_rstart )   &
+         IF( kt == nit000 .AND. ln_rstart )   &                !!gm  I don't understand the ln_rstart, if needed, add a comment, please
             &                         CALL iom_close( numrir )  ! close input ice restart file
          !
@@ -287,11 +303,11 @@
       IF( ln_limdiahsb) CALL ice_dia_init  ! initialization for diags
       !
-      fr_i(:,:)     = at_i(:,:)         ! initialisation of sea-ice fraction
+      fr_i  (:,:)   = at_i(:,:)         ! initialisation of sea-ice fraction
       tn_ice(:,:,:) = t_su(:,:,:)       ! initialisation of surface temp for coupled simu
       !
       DO jj = 1, jpj
          DO ji = 1, jpi
-            IF( gphit(ji,jj) > 0._wp ) THEN  ;  rn_amax_2d(ji,jj) = rn_amax_n  ! NH
-            ELSE                             ;  rn_amax_2d(ji,jj) = rn_amax_s  ! SH
+            IF( gphit(ji,jj) > 0._wp ) THEN   ;   rn_amax_2d(ji,jj) = rn_amax_n  ! NH
+            ELSE                              ;   rn_amax_2d(ji,jj) = rn_amax_s  ! SH
             ENDIF
          END DO
@@ -318,71 +334,84 @@
       !!-------------------------------------------------------------------
       !
-      REWIND( numnam_ice_ref )              ! Namelist namicerun in reference namelist : Parameters for ice
+      REWIND( numnam_ice_ref )      ! Namelist namicerun in reference namelist : Parameters for ice
       READ  ( numnam_ice_ref, namicerun, IOSTAT = ios, ERR = 901)
 901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicerun in reference namelist', lwp )
 
-      REWIND( numnam_ice_cfg )              ! Namelist namicerun in configuration namelist : Parameters for ice
+      REWIND( numnam_ice_cfg )      ! Namelist namicerun in configuration namelist : Parameters for ice
       READ  ( numnam_ice_cfg, namicerun, IOSTAT = ios, ERR = 902 )
 902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicerun in configuration namelist', lwp )
       IF(lwm) WRITE ( numoni, namicerun )
       !
-      REWIND( numnam_ice_ref )              ! Namelist namicediag in reference namelist : Parameters for ice
+      REWIND( numnam_ice_ref )      ! Namelist namicediag in reference namelist : Parameters for ice
       READ  ( numnam_ice_ref, namicediag, IOSTAT = ios, ERR = 903)
 903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicediag in reference namelist', lwp )
 
-      REWIND( numnam_ice_cfg )              ! Namelist namicediag in configuration namelist : Parameters for ice
+      REWIND( numnam_ice_cfg )      ! Namelist namicediag in configuration namelist : Parameters for ice
       READ  ( numnam_ice_cfg, namicediag, IOSTAT = ios, ERR = 904 )
 904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicediag in configuration namelist', lwp )
       IF(lwm) WRITE ( numoni, namicediag )
       !
-      IF(lwp) THEN                        ! control print
+      IF(lwp) THEN                  ! control print
          WRITE(numout,*)
          WRITE(numout,*) 'ice_run_init : ice share parameters for dynamics/advection/thermo of sea-ice'
          WRITE(numout,*) ' ~~~~~~'
-         WRITE(numout,*) '   number of ice  categories                              jpl    = ', jpl
-         WRITE(numout,*) '   number of ice  layers                                  nlay_i = ', nlay_i
-         WRITE(numout,*) '   number of snow layers                                  nlay_s = ', nlay_s
-         WRITE(numout,*) '   virtual ITD mono-category param (1-4) or not (0)   nn_monocat = ', nn_monocat
-         WRITE(numout,*) '   maximum ice concentration for NH                              = ', rn_amax_n 
-         WRITE(numout,*) '   maximum ice concentration for SH                              = ', rn_amax_s
-         WRITE(numout,*) '   Ice thermodynamics (T) or not (F)                  ln_limthd  = ', ln_limthd
-         WRITE(numout,*) '   Ice dynamics       (T) or not (F)                  ln_limdyn  = ', ln_limdyn
-         WRITE(numout,*) '     (ln_limdyn=T) Ice dynamics switch                nn_limdyn  = ', nn_limdyn
-         WRITE(numout,*) '       2: total'
-         WRITE(numout,*) '       1: advection only (no diffusion, no ridging/rafting)'
-         WRITE(numout,*) '       0: advection only (as 1 + prescribed velocity, bypass rheology)'
-         WRITE(numout,*) '     (ln_limdyn=T) prescribed u-vel (case nn_limdyn=0)           = ', rn_uice
-         WRITE(numout,*) '     (ln_limdyn=T) prescribed v-vel (case nn_limdyn=0)           = ', rn_vice
+         WRITE(numout,*) '   Namelist namicerun : '
+         WRITE(numout,*) '      number of ice  categories                              jpl    = ', jpl
+         WRITE(numout,*) '      number of ice  layers                                  nlay_i = ', nlay_i
+         WRITE(numout,*) '      number of snow layers                                  nlay_s = ', nlay_s
+         WRITE(numout,*) '      virtual ITD mono-category param (1-4) or not (0)   nn_monocat = ', nn_monocat
+         WRITE(numout,*) '      maximum ice concentration for NH                              = ', rn_amax_n 
+         WRITE(numout,*) '      maximum ice concentration for SH                              = ', rn_amax_s
+         WRITE(numout,*) '      Ice thermodynamics (T) or not (F)                  ln_limthd  = ', ln_limthd
+         WRITE(numout,*) '      Ice dynamics       (T) or not (F)                  ln_limdyn  = ', ln_limdyn
+         WRITE(numout,*) '         associated switch                               nn_limdyn  = ', nn_limdyn
+         WRITE(numout,*) '            =2 all processes (default option)'
+         WRITE(numout,*) '            =1 advection only (no ridging/rafting)'
+         WRITE(numout,*) '            =0 advection only with prescribed velocity given by '
+         WRITE(numout,*) '               a uniform field        (u,v)_ice = (rn_uice,rn_vice) = (', rn_uice,',', rn_vice,')'
          WRITE(numout,*)
-         WRITE(numout,*) '...and ice diagnostics'
-         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~'
-         WRITE(numout,*) '   Diagnose online heat/mass/salt budget     ln_limdiachk  = ', ln_limdiachk
-         WRITE(numout,*) '   Output          heat/mass/salt budget     ln_limdiahsb  = ', ln_limdiahsb
-         WRITE(numout,*) '   control prints in ocean.out for (i,j)=(iiceprt,jiceprt) = ', ln_limctl
-         WRITE(numout,*) '   i-index for control prints (ln_limctl=true)             = ', iiceprt
-         WRITE(numout,*) '   j-index for control prints (ln_limctl=true)             = ', jiceprt
+         WRITE(numout,*) '   Namelist namicediag : '
+         WRITE(numout,*) '      Diagnose online heat/mass/salt budget      ln_limdiachk = ', ln_limdiachk
+         WRITE(numout,*) '      Output          heat/mass/salt budget      ln_limdiahsb = ', ln_limdiahsb
+         WRITE(numout,*) '      control prints for a given grid point         ln_limctl = ', ln_limctl
+         WRITE(numout,*) '         chosen grid point position         (iiceprt,jiceprt) = (', iiceprt,',', jiceprt,')'
       ENDIF
       !
-      IF ( ( jpl > 1 ) .AND. ( nn_monocat == 1 ) ) THEN
+      !                                         !--- check consistency
+      IF ( jpl > 1 .AND. nn_monocat == 1 ) THEN
          nn_monocat = 0
          IF(lwp) WRITE(numout,*)
          IF(lwp) WRITE(numout,*) '   nn_monocat forced to 0 as jpl>1, i.e. multi-category case is chosen'
       ENDIF
-      IF ( ( jpl == 1 ) .AND. ( nn_monocat == 0 ) ) THEN
+      IF ( jpl == 1 .AND. nn_monocat == 0 ) THEN
          CALL ctl_stop( 'STOP', 'ice_run_init : if jpl=1 then nn_monocat should be between 1 and 4' )
       ENDIF
       !
-      ! sea-ice timestep and inverse
-      rdt_ice   = REAL(nn_fsbc) * rdt  
-      r1_rdtice = 1._wp / rdt_ice 
-
-      ! inverse of nlay_i and nlay_s
-      r1_nlay_i = 1._wp / REAL( nlay_i, wp )
+      IF( ln_bdy .AND. ln_limdiachk )   CALL ctl_warn('ice_run_init: online conservation check does not work with BDY')
+      !
+      !                             ! set the choice of ice dynamics
+      IF( lk_c1d .OR. .NOT.ln_limdyn ) THEN
+         nice_dyn = np_dynNO                    !--- no dynamics
+      ELSE
+         SELECT CASE( nn_limdyn )
+         CASE( 2 )                    
+            IF( nn_monocat /= 2 ) THEN          !--- full dynamics (rheology + advection + ridging/rafting + correction)
+               nice_dyn = np_dynFULL
+            ELSE
+               nice_dyn = np_dyn                !--- dynamics without ridging/rafting
+            ENDIF
+         CASE( 0 , 1 )                          !--- dynamics without ridging/rafting and correction 
+            nice_dyn = np_dynPURE
+         END SELECT
+      ENDIF
+      !                                         !--- simple conservative piling, comparable with LIM2
+      l_piling = nn_limdyn == 1 .OR. ( nn_monocat == 2  .AND.  jpl == 1 )
+      !
+      rdt_ice   = REAL(nn_fsbc) * rdt           !--- sea-ice timestep and inverse
+      r1_rdtice = 1._wp / rdt_ice
+      IF( lwp ) WRITE(numout,*) '   ice timestep rdt_ice  = ', rdt_ice
+      !
+      r1_nlay_i = 1._wp / REAL( nlay_i, wp )    !--- inverse of nlay_i and nlay_s
       r1_nlay_s = 1._wp / REAL( nlay_s, wp )
-      !
-      IF( lwp .AND. ln_bdy .AND. ln_limdiachk )  &
-         &   CALL ctl_warn('online conservation check activated but it does not work with BDY')
-      !
-      IF( lwp ) WRITE(numout,*) '   ice timestep rdt_ice  = ', rdt_ice
       !
    END SUBROUTINE ice_run_init
@@ -397,34 +426,34 @@
       !! ** input   :   Namelist namiceitd
       !!-------------------------------------------------------------------
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
+      INTEGER  ::   jl    ! dummy loop index
+      INTEGER  ::   ios   ! Local integer output status for namelist read
+      REAL(wp) ::   zc1, zc2, zc3, zx1          ! local scalars
+      REAL(wp) ::   zhmax, znum, zden, zalpha   !   -      -
+      !!
       NAMELIST/namiceitd/ rn_himean
-      !
-      INTEGER  ::   jl                   ! dummy loop index
-      REAL(wp) ::   zc1, zc2, zc3, zx1   ! local scalars
-      REAL(wp) ::   zhmax, znum, zden, zalpha !
       !!------------------------------------------------------------------
       !
-      REWIND( numnam_ice_ref )              ! Namelist namiceitd in reference namelist : Parameters for ice
+      REWIND( numnam_ice_ref )      ! Namelist namiceitd in reference namelist : Parameters for ice
       READ  ( numnam_ice_ref, namiceitd, IOSTAT = ios, ERR = 905)
 905   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namiceitd in reference namelist', lwp )
 
-      REWIND( numnam_ice_cfg )              ! Namelist namiceitd in configuration namelist : Parameters for ice
+      REWIND( numnam_ice_cfg )      ! Namelist namiceitd in configuration namelist : Parameters for ice
       READ  ( numnam_ice_cfg, namiceitd, IOSTAT = ios, ERR = 906 )
 906   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namiceitd in configuration namelist', lwp )
       IF(lwm) WRITE ( numoni, namiceitd )
       !
-      IF(lwp) THEN                        ! control print
+      IF(lwp) THEN                  ! control print
          WRITE(numout,*)
          WRITE(numout,*) 'ice_itd_init : Initialization of ice cat distribution '
          WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) '   mean ice thickness in the domain            rn_himean = ', rn_himean
+         WRITE(numout,*) '   Namelist namicerun : '
+         WRITE(numout,*) '      mean ice thickness in the domain               rn_himean = ', rn_himean
       ENDIF
       !
-      !----------------------------------
-      !- Thickness categories boundaries
-      !----------------------------------
-      !
-      !==  h^(-alpha) function  ==!
-      zalpha = 0.05_wp
+      !-----------------------------------!
+      !  Thickness categories boundaries  !
+      !-----------------------------------!
+      !
+      zalpha = 0.05_wp              ! max of each category (from h^(-alpha) function)
       zhmax  = 3._wp * rn_himean
       DO jl = 1, jpl
@@ -441,8 +470,9 @@
       !
       IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) '      Thickness category boundaries '
-      IF(lwp) WRITE(numout,*) '         hi_max ', hi_max(0:jpl)
+      IF(lwp) WRITE(numout,*) '   ===>>>   resulting thickness category boundaries :'
+      IF(lwp) WRITE(numout,*) '            hi_max(:)= ', hi_max(0:jpl)
       !
    END SUBROUTINE ice_itd_init
+
 
    SUBROUTINE ice_bef
@@ -472,9 +502,17 @@
          END DO   
       END DO
-      CALL lbc_lnk_multi( a_i_b, 'T', 1., v_i_b , 'T', 1., v_s_b , 'T', 1., smv_i_b, 'T', 1., &
-         &               oa_i_b, 'T', 1., ht_i_b, 'T', 1., ht_s_b, 'T', 1. )
+      CALL lbc_lnk_multi(  a_i_b, 'T', 1., v_i_b , 'T', 1., ht_i_b, 'T', 1., smv_i_b, 'T', 1.,   &
+         &                oa_i_b, 'T', 1., v_s_b , 'T', 1., ht_s_b, 'T', 1. )
       CALL lbc_lnk( e_i_b, 'T', 1. )
       CALL lbc_lnk( e_s_b, 'T', 1. )
       
+!!gm Question:  here , a_i_b, u_ice and v_ice  are defined over the whole domain, 
+!!gm            so why not just a copy over the whole domain and no lbc_lnk ?
+!!gm            that is some thing like:
+!            at_i_b(:,:)  = SUM( a_i_b(:,:,:), dim=3 )
+!            u_ice_b(:,:) = u_ice(:,:)
+!            v_ice_b(:,:) = v_ice(:,:)
+!    idem for the loop above
+!!gm
       ! ice velocities & total concentration
       DO jj = 2, jpjm1
@@ -486,5 +524,5 @@
       END DO
       CALL lbc_lnk_multi( at_i_b, 'T', 1., u_ice_b , 'U', -1., v_ice_b , 'V', -1. )
-      
+      !
    END SUBROUTINE ice_bef
 
@@ -552,10 +590,8 @@
    !!----------------------------------------------------------------------
 CONTAINS
-   !
    SUBROUTINE ice_stp ( kt, ksbc )     ! Dummy routine
       INTEGER, INTENT(in) ::   kt, ksbc
       WRITE(*,*) 'ice_stp: You should not have seen this print! error?', kt
    END SUBROUTINE ice_stp
-   !
    SUBROUTINE ice_init                 ! Dummy routine
    END SUBROUTINE ice_init
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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icetab.F90	(revision 8486)
@@ -24,10 +24,9 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: icetab.F90 8369 2017-07-25 14:38:38Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 CONTAINS
-
 
    SUBROUTINE tab_3d_2d( ndim1d, tab_ind, tab1d, tab2d )
@@ -51,4 +50,5 @@
    END SUBROUTINE tab_3d_2d
 
+
    SUBROUTINE tab_2d_1d( ndim1d, tab_ind, tab1d, tab2d )
       !!----------------------------------------------------------------------
@@ -68,4 +68,5 @@
       END DO
    END SUBROUTINE tab_2d_1d
+
 
    SUBROUTINE tab_2d_3d( ndim1d, tab_ind, tab1d, tab2d )
@@ -89,4 +90,5 @@
    END SUBROUTINE tab_2d_3d
 
+
    SUBROUTINE tab_1d_2d( ndim1d, tab_ind, tab1d, tab2d )
       !!----------------------------------------------------------------------
@@ -107,5 +109,10 @@
    END SUBROUTINE tab_1d_2d
 
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option           Dummy module      NO LIM 3.0 sea-ice model
+   !!----------------------------------------------------------------------
 #endif
+
    !!======================================================================
 END MODULE icetab
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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd.F90	(revision 8486)
@@ -15,5 +15,5 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!   'key_lim3'                                       LIM3 sea-ice model
    !!----------------------------------------------------------------------
    !!   ice_thd       : thermodynamic of sea ice
@@ -23,4 +23,5 @@
    USE dom_oce        ! ocean space and time domain variables
    USE ice            ! sea-ice variables
+!!gm list trop longue ==>>> why not passage en argument d'appel ?
    USE sbc_oce , ONLY : sss_m, sst_m, e3t_m, utau, vtau, ssu_m, ssv_m, frq_m, qns_tot, qsr_tot, sprecip, ln_cpl
    USE sbc_ice , ONLY : qsr_oce, qns_oce, qemp_oce, qsr_ice, qns_ice, dqns_ice, evap_ice, qprec_ice, qevap_ice, &
@@ -53,5 +54,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: icethd.F90 8420 2017-08-08 12:18:46Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -75,6 +76,4 @@
       !!             - call ice_thd_temp to  retrieve temperature from ice enthalpy
       !!             - back to the geographic grid
-      !!     
-      !! ** References : 
       !!---------------------------------------------------------------------
       INTEGER, INTENT(in) :: kt    ! number of iteration
@@ -93,10 +92,10 @@
       IF( kt == nit000 .AND. lwp ) THEN
          WRITE(numout,*)
-         WRITE(numout,*)' icethd '
-         WRITE(numout,*)' ~~~~~~~'
+         WRITE(numout,*)' icethd : sea-ice thermodynamics'
+         WRITE(numout,*)' ~~~~~~~~'
       ENDIF
       
       ! conservation test
-      IF( ln_limdiachk ) CALL ice_cons_hsm(0, 'icethd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      IF( ln_limdiachk )   CALL ice_cons_hsm( 0, 'icethd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b )
 
       CALL ice_var_glo2eqv
@@ -231,9 +230,9 @@
             dh_snowice(1:nidx) = 0._wp ; dh_i_sub (1:nidx) = 0._wp
             !
-            IF( ln_limdH )    CALL ice_thd_dif                      ! --- Ice/Snow Temperature profile --- !
-            !
-            IF( ln_limdH )    CALL ice_thd_dh                       ! --- Ice/Snow thickness --- !    
-            !
-            IF( ln_limdH )    CALL ice_thd_ent( e_i_1d(1:nidx,:) )  ! --- Ice enthalpy remapping --- !
+            IF( ln_limdH ) THEN                                     ! --- growing/melting --- !
+                              CALL ice_thd_dif                             ! Ice/Snow Temperature profile
+                              CALL ice_thd_dh                              ! Ice/Snow thickness   
+                              CALL ice_thd_ent( e_i_1d(1:nidx,:) )         ! Ice enthalpy remapping
+            ENDIF
             !
                               CALL ice_thd_sal                      ! --- Ice salinity --- !    
@@ -241,4 +240,8 @@
                               CALL ice_thd_temp                     ! --- temperature update --- !
             !
+!!gm please create a new logical (l_thd_lam or a better explicit name) set one for all in icestp.F90 module
+!!gm        l_thd_lam = ln_limdH .AND. ( ( nn_monocat == 1 .OR. nn_monocat == 4 ) .AND. jpl == 1 )
+!!gm        by the way, the different options associated with nn_monocat =1 to 4  are quite impossible to identify
+!!gm        more comment to add when ready the namelist, with an explicit print in the ocean.output
             IF( ln_limdH ) THEN
                IF ( ( nn_monocat == 1 .OR. nn_monocat == 4 ) .AND. jpl == 1 ) THEN
@@ -259,18 +262,18 @@
       oa_i(:,:,:) = o_i(:,:,:) * a_i(:,:,:)
 
-      IF( ln_limdiachk ) CALL ice_cons_hsm(1, 'icethd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-      !
-                         CALL ice_var_zapsmall           ! --- remove very small ice concentration (<1e-10) --- !
-      !                                                  !     & make sure at_i=SUM(a_i) & ato_i=1 where at_i=0
+      IF( ln_limdiachk )   CALL ice_cons_hsm( 1, 'icethd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b )
+      !
+                           CALL ice_var_zapsmall           ! --- remove very small ice concentration (<1e-10) --- !
+      !                                                    !     & make sure at_i=SUM(a_i) & ato_i=1 where at_i=0
       !                   
-      IF( jpl > 1 )      CALL ice_itd_rem( kt )          ! --- Transport ice between thickness categories --- !
-      !
-      IF( ln_limdO )     CALL ice_thd_lac                ! --- frazil ice growing in leads --- !
-      !
-      IF( ln_limctl )    CALL ice_prt( kt, iiceprt, jiceprt, 1, ' - ice thermodyn. - ' )   ! control print
-      IF( ln_ctl )       CALL ice_prt3D( 'icethd' )      ! Control print
+      IF( jpl > 1 )        CALL ice_itd_rem( kt )          ! --- Transport ice between thickness categories --- !
+      !
+      IF( ln_limdO )       CALL ice_thd_lac                ! --- frazil ice growing in leads --- !
+      !
+      IF( ln_limctl )      CALL ice_prt( kt, iiceprt, jiceprt, 1, ' - ice thermodyn. - ' )   ! control print
+      IF( ln_ctl )         CALL ice_prt3D( 'icethd' )      ! Control print
       !
       IF( nn_timing == 1 )  CALL timing_stop('icethd')
-
+      !
    END SUBROUTINE ice_thd 
 
@@ -341,5 +344,5 @@
 
 
-   SUBROUTINE ice_thd_1d2d( jl, kn )
+   SUBROUTINE ice_thd_1d2d( kl, kn )
       !!-----------------------------------------------------------------------
       !!                   ***  ROUTINE ice_thd_1d2d *** 
@@ -347,38 +350,38 @@
       !! ** Purpose :   move arrays from 1d to 2d and the reverse
       !!-----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   jl       ! ice cat
-      INTEGER, INTENT(in) ::   kn       ! 1= from 2D to 1D   ;   2= from 1D to 2D
-      !
-      INTEGER             ::   jk       ! dummy loop indices
+      INTEGER, INTENT(in) ::   kl   ! index of the ice category 
+      INTEGER, INTENT(in) ::   kn   ! 1= from 2D to 1D   ;   2= from 1D to 2D
+      !
+      INTEGER ::   jk   ! dummy loop indices
       !!-----------------------------------------------------------------------
       !
       SELECT CASE( kn )
-      !
-      CASE( 1 )            ! from 2D to 1D
-         !
+      !                    !---------------------!
+      CASE( 1 )            !==  from 2D to 1D  ==!
+         !                 !---------------------!
          CALL tab_2d_1d( nidx, idxice(1:nidx), at_i_1d(1:nidx), at_i             )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), a_i_1d (1:nidx), a_i(:,:,jl)      )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), ht_i_1d(1:nidx), ht_i(:,:,jl)     )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), ht_s_1d(1:nidx), ht_s(:,:,jl)     )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), t_su_1d(1:nidx), t_su(:,:,jl)     )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), sm_i_1d(1:nidx), sm_i(:,:,jl)     )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), a_i_1d (1:nidx), a_i (:,:,kl)     )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), ht_i_1d(1:nidx), ht_i(:,:,kl)     )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), ht_s_1d(1:nidx), ht_s(:,:,kl)     )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), t_su_1d(1:nidx), t_su(:,:,kl)     )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), sm_i_1d(1:nidx), sm_i(:,:,kl)     )
          DO jk = 1, nlay_s
-            CALL tab_2d_1d( nidx, idxice(1:nidx), t_s_1d(1:nidx,jk), t_s(:,:,jk,jl)   )
-            CALL tab_2d_1d( nidx, idxice(1:nidx), e_s_1d(1:nidx,jk), e_s(:,:,jk,jl)   )
+            CALL tab_2d_1d( nidx, idxice(1:nidx), t_s_1d(1:nidx,jk), t_s(:,:,jk,kl)   )
+            CALL tab_2d_1d( nidx, idxice(1:nidx), e_s_1d(1:nidx,jk), e_s(:,:,jk,kl)   )
          END DO
          DO jk = 1, nlay_i
-            CALL tab_2d_1d( nidx, idxice(1:nidx), t_i_1d(1:nidx,jk), t_i(:,:,jk,jl)   )
-            CALL tab_2d_1d( nidx, idxice(1:nidx), e_i_1d(1:nidx,jk), e_i(:,:,jk,jl)   )
-            CALL tab_2d_1d( nidx, idxice(1:nidx), s_i_1d(1:nidx,jk), s_i(:,:,jk,jl)   )
+            CALL tab_2d_1d( nidx, idxice(1:nidx), t_i_1d(1:nidx,jk), t_i(:,:,jk,kl)   )
+            CALL tab_2d_1d( nidx, idxice(1:nidx), e_i_1d(1:nidx,jk), e_i(:,:,jk,kl)   )
+            CALL tab_2d_1d( nidx, idxice(1:nidx), s_i_1d(1:nidx,jk), s_i(:,:,jk,kl)   )
          END DO
          !
          CALL tab_2d_1d( nidx, idxice(1:nidx), qprec_ice_1d(1:nidx), qprec_ice        )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), qsr_ice_1d  (1:nidx), qsr_ice(:,:,jl)  )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), qsr_ice_1d  (1:nidx), qsr_ice (:,:,kl) )
          CALL tab_2d_1d( nidx, idxice(1:nidx), fr1_i0_1d   (1:nidx), fr1_i0           )
          CALL tab_2d_1d( nidx, idxice(1:nidx), fr2_i0_1d   (1:nidx), fr2_i0           )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), qns_ice_1d  (1:nidx), qns_ice(:,:,jl)  )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), ftr_ice_1d  (1:nidx), ftr_ice(:,:,jl)  )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), evap_ice_1d (1:nidx), evap_ice(:,:,jl) )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), dqns_ice_1d (1:nidx), dqns_ice(:,:,jl) )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), qns_ice_1d  (1:nidx), qns_ice (:,:,kl) )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), ftr_ice_1d  (1:nidx), ftr_ice (:,:,kl) )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), evap_ice_1d (1:nidx), evap_ice(:,:,kl) )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), dqns_ice_1d (1:nidx), dqns_ice(:,:,kl) )
          CALL tab_2d_1d( nidx, idxice(1:nidx), t_bo_1d     (1:nidx), t_bo             )
          CALL tab_2d_1d( nidx, idxice(1:nidx), sprecip_1d  (1:nidx), sprecip          ) 
@@ -435,18 +438,19 @@
          DO jk = 1, nlay_i
             WHERE( ht_i_1d(1:nidx)>0._wp ) e_i_1d(1:nidx,jk) = e_i_1d(1:nidx,jk) / (ht_i_1d(1:nidx) * a_i_1d(1:nidx)) * nlay_i
-         ENDDO
+         END DO
          DO jk = 1, nlay_s
             WHERE( ht_s_1d(1:nidx)>0._wp ) e_s_1d(1:nidx,jk) = e_s_1d(1:nidx,jk) / (ht_s_1d(1:nidx) * a_i_1d(1:nidx)) * nlay_s
-         ENDDO
-         !
-      CASE( 2 )            ! from 1D to 2D
-         !
+         END DO
+         !
+         !                 !---------------------!
+      CASE( 2 )            !==  from 1D to 2D  ==!
+         !                 !---------------------!
          ! --- Change units of e_i, e_s from J/m3 to J/m2 --- !
          DO jk = 1, nlay_i
             e_i_1d(1:nidx,jk) = e_i_1d(1:nidx,jk) * ht_i_1d(1:nidx) * a_i_1d(1:nidx) * r1_nlay_i
-         ENDDO
+         END DO
          DO jk = 1, nlay_s
             e_s_1d(1:nidx,jk) = e_s_1d(1:nidx,jk) * ht_s_1d(1:nidx) * a_i_1d(1:nidx) * r1_nlay_s
-         ENDDO
+         END DO
          !
          ! Change thickness to volume
@@ -456,69 +460,70 @@
          
          CALL tab_1d_2d( nidx, idxice(1:nidx), at_i_1d(1:nidx), at_i             )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), a_i_1d (1:nidx), a_i(:,:,jl)      )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), ht_i_1d(1:nidx), ht_i(:,:,jl)     )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), ht_s_1d(1:nidx), ht_s(:,:,jl)     )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), t_su_1d(1:nidx), t_su(:,:,jl)     )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), sm_i_1d(1:nidx), sm_i(:,:,jl)     )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), a_i_1d (1:nidx), a_i (:,:,kl)     )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), ht_i_1d(1:nidx), ht_i(:,:,kl)     )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), ht_s_1d(1:nidx), ht_s(:,:,kl)     )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), t_su_1d(1:nidx), t_su(:,:,kl)     )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), sm_i_1d(1:nidx), sm_i(:,:,kl)     )
          DO jk = 1, nlay_s
-            CALL tab_1d_2d( nidx, idxice(1:nidx), t_s_1d(1:nidx,jk), t_s(:,:,jk,jl)   )
-            CALL tab_1d_2d( nidx, idxice(1:nidx), e_s_1d(1:nidx,jk), e_s(:,:,jk,jl)   )
+            CALL tab_1d_2d( nidx, idxice(1:nidx), t_s_1d(1:nidx,jk), t_s(:,:,jk,kl) )
+            CALL tab_1d_2d( nidx, idxice(1:nidx), e_s_1d(1:nidx,jk), e_s(:,:,jk,kl) )
          END DO
          DO jk = 1, nlay_i
-            CALL tab_1d_2d( nidx, idxice(1:nidx), t_i_1d(1:nidx,jk), t_i(:,:,jk,jl)   )
-            CALL tab_1d_2d( nidx, idxice(1:nidx), e_i_1d(1:nidx,jk), e_i(:,:,jk,jl)   )
-            CALL tab_1d_2d( nidx, idxice(1:nidx), s_i_1d(1:nidx,jk), s_i(:,:,jk,jl)   )
-         END DO
-         !
-         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_snw_sni_1d(1:nidx), wfx_snw_sni   )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_snw_sum_1d(1:nidx), wfx_snw_sum   )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_sub_1d    (1:nidx), wfx_sub       )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_snw_sub_1d(1:nidx), wfx_snw_sub   )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_ice_sub_1d(1:nidx), wfx_ice_sub   )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_err_sub_1d(1:nidx), wfx_err_sub   )
-         !
-         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_bog_1d (1:nidx), wfx_bog          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_bom_1d (1:nidx), wfx_bom          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_sum_1d (1:nidx), wfx_sum          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_sni_1d (1:nidx), wfx_sni          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_res_1d (1:nidx), wfx_res          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_spr_1d (1:nidx), wfx_spr          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_lam_1d (1:nidx), wfx_lam          )
-         !
-         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_bog_1d (1:nidx), sfx_bog          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_bom_1d (1:nidx), sfx_bom          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_sum_1d (1:nidx), sfx_sum          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_sni_1d (1:nidx), sfx_sni          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_bri_1d (1:nidx), sfx_bri          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_res_1d (1:nidx), sfx_res          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_sub_1d (1:nidx), sfx_sub          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_lam_1d (1:nidx), sfx_lam          )
-         !
-         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_thd_1d (1:nidx), hfx_thd          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_spr_1d (1:nidx), hfx_spr          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_sum_1d (1:nidx), hfx_sum          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_bom_1d (1:nidx), hfx_bom          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_bog_1d (1:nidx), hfx_bog          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_dif_1d (1:nidx), hfx_dif          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_opw_1d (1:nidx), hfx_opw          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_snw_1d (1:nidx), hfx_snw          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_sub_1d (1:nidx), hfx_sub          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_err_1d (1:nidx), hfx_err          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_res_1d (1:nidx), hfx_res          )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_err_dif_1d(1:nidx), hfx_err_dif   )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_err_rem_1d(1:nidx), hfx_err_rem   )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_out_1d (1:nidx), hfx_out          )
-         !
-         CALL tab_1d_2d( nidx, idxice(1:nidx), qns_ice_1d  (1:nidx), qns_ice(:,:,jl)  )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), ftr_ice_1d  (1:nidx), ftr_ice(:,:,jl)  )
+            CALL tab_1d_2d( nidx, idxice(1:nidx), t_i_1d(1:nidx,jk), t_i(:,:,jk,kl) )
+            CALL tab_1d_2d( nidx, idxice(1:nidx), e_i_1d(1:nidx,jk), e_i(:,:,jk,kl) )
+            CALL tab_1d_2d( nidx, idxice(1:nidx), s_i_1d(1:nidx,jk), s_i(:,:,jk,kl) )
+         END DO
+         !
+         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_snw_sni_1d(1:nidx), wfx_snw_sni )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_snw_sum_1d(1:nidx), wfx_snw_sum )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_sub_1d    (1:nidx), wfx_sub     )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_snw_sub_1d(1:nidx), wfx_snw_sub )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_ice_sub_1d(1:nidx), wfx_ice_sub )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_err_sub_1d(1:nidx), wfx_err_sub )
+         !
+         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_bog_1d (1:nidx), wfx_bog        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_bom_1d (1:nidx), wfx_bom        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_sum_1d (1:nidx), wfx_sum        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_sni_1d (1:nidx), wfx_sni        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_res_1d (1:nidx), wfx_res        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_spr_1d (1:nidx), wfx_spr        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_lam_1d (1:nidx), wfx_lam        )
+         !
+         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_bog_1d (1:nidx), sfx_bog        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_bom_1d (1:nidx), sfx_bom        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_sum_1d (1:nidx), sfx_sum        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_sni_1d (1:nidx), sfx_sni        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_bri_1d (1:nidx), sfx_bri        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_res_1d (1:nidx), sfx_res        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_sub_1d (1:nidx), sfx_sub        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_lam_1d (1:nidx), sfx_lam        )
+         !
+         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_thd_1d (1:nidx), hfx_thd        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_spr_1d (1:nidx), hfx_spr        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_sum_1d (1:nidx), hfx_sum        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_bom_1d (1:nidx), hfx_bom        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_bog_1d (1:nidx), hfx_bog        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_dif_1d (1:nidx), hfx_dif        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_opw_1d (1:nidx), hfx_opw        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_snw_1d (1:nidx), hfx_snw        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_sub_1d (1:nidx), hfx_sub        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_err_1d (1:nidx), hfx_err        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_res_1d (1:nidx), hfx_res        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_err_dif_1d(1:nidx), hfx_err_dif )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_err_rem_1d(1:nidx), hfx_err_rem )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_out_1d (1:nidx), hfx_out        )
+         !
+         CALL tab_1d_2d( nidx, idxice(1:nidx), qns_ice_1d(1:nidx), qns_ice(:,:,kl) )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), ftr_ice_1d(1:nidx), ftr_ice(:,:,kl) )
          !
          ! SIMIP diagnostics         
-         CALL tab_1d_2d( nidx, idxice(1:nidx), t_si_1d      (1:nidx), t_si(:,:,jl)      )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), diag_fc_bo_1d(1:nidx), diag_fc_bo        )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), diag_fc_su_1d(1:nidx), diag_fc_su        )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), t_si_1d      (1:nidx), t_si(:,:,kl) )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), diag_fc_bo_1d(1:nidx), diag_fc_bo   )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), diag_fc_su_1d(1:nidx), diag_fc_su   )
          ! extensive variables
-         CALL tab_1d_2d( nidx, idxice(1:nidx), v_i_1d  (1:nidx), v_i  (:,:,jl) )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), v_s_1d  (1:nidx), v_s  (:,:,jl) )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), smv_i_1d(1:nidx), smv_i(:,:,jl) )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), v_i_1d  (1:nidx), v_i  (:,:,kl) )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), v_s_1d  (1:nidx), v_s  (:,:,kl) )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), smv_i_1d(1:nidx), smv_i(:,:,kl) )
+         !
       END SELECT
       !
@@ -538,5 +543,6 @@
       !! ** input   :   Namelist namicether
       !!-------------------------------------------------------------------
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
+      INTEGER  ::   ios   ! Local integer output status for namelist read
+      !!
       NAMELIST/namicethd/ rn_kappa_i, nn_ice_thcon, ln_dqnsice, rn_cdsn,                                  &
          &                ln_limdH, rn_betas,                                                             &
@@ -559,4 +565,5 @@
          WRITE(numout,*) 'ice_thd_init : Ice Thermodynamics'
          WRITE(numout,*) '~~~~~~~~~~~~~'
+         WRITE(numout,*)'   Namelist namicethd'
          WRITE(numout,*)'   -- icethd_dif --'
          WRITE(numout,*)'      extinction radiation parameter in sea ice               rn_kappa_i   = ', rn_kappa_i
@@ -573,8 +580,8 @@
          WRITE(numout,*)'   -- icethd_lac --'
          WRITE(numout,*)'      activate ice growth in open-water (T) or not (F)        ln_limdO     = ', ln_limdO
-         WRITE(numout,*)'      ice thick. for lateral accretion                        rn_hnewice   = ', rn_hnewice
+         WRITE(numout,*)'      ice thickness for lateral accretion                     rn_hnewice   = ', rn_hnewice
          WRITE(numout,*)'      Frazil ice thickness as a function of wind or not       ln_frazil    = ', ln_frazil
          WRITE(numout,*)'      Maximum proportion of frazil ice collecting at bottom   rn_maxfrazb  = ', rn_maxfrazb
-         WRITE(numout,*)'      Thresold relative drift speed for collection of frazil  rn_vfrazb    = ', rn_vfrazb
+         WRITE(numout,*)'      Threshold relative drift speed for collection of frazil rn_vfrazb    = ', rn_vfrazb
          WRITE(numout,*)'      Squeezing coefficient for collection of frazil          rn_Cfrazb    = ', rn_Cfrazb
          WRITE(numout,*)'   -- iceitd --'
@@ -588,17 +595,17 @@
       IF(lwp) WRITE(numout,*)
       SELECT CASE( nn_limflx )         ! LIM3 Multi-category heat flux formulation
-      CASE ( -1 )
+      CASE( -1  )
          IF(lwp) WRITE(numout,*) '   LIM3: use per-category fluxes (nn_limflx = -1) '
-         IF( ln_cpl )   CALL ctl_stop( 'sbc_init : the chosen nn_limflx for LIM3 in coupled mode must be 0 or 2' )
-      CASE ( 0  )
+         IF( ln_cpl )   CALL ctl_stop( 'ice_thd_init : the chosen nn_limflx for LIM3 in coupled mode must be 0 or 2' )
+      CASE(  0  )
          IF(lwp) WRITE(numout,*) '   LIM3: use average per-category fluxes (nn_limflx = 0) '
-      CASE ( 1  )
+      CASE(  1  )
          IF(lwp) WRITE(numout,*) '   LIM3: use average then redistribute per-category fluxes (nn_limflx = 1) '
-         IF( ln_cpl )   CALL ctl_stop( 'sbc_init : the chosen nn_limflx for LIM3 in coupled mode must be 0 or 2' )
-      CASE ( 2  )
+         IF( ln_cpl )   CALL ctl_stop( 'ice_thd_init : the chosen nn_limflx for LIM3 in coupled mode must be 0 or 2' )
+      CASE(  2  )
          IF(lwp) WRITE(numout,*) '   LIM3: Redistribute a single flux over categories (nn_limflx = 2) '
-         IF( .NOT. ln_cpl )   CALL ctl_stop( 'sbc_init : the chosen nn_limflx for LIM3 in forced mode cannot be 2' )
+         IF( .NOT. ln_cpl )   CALL ctl_stop( 'ice_thd_init : the chosen nn_limflx for LIM3 in forced mode cannot be 2' )
       CASE DEFAULT
-         CALL ctl_stop( 'sbcmod: LIM3 option, nn_limflx, should be between -1 and 2' )
+         CALL ctl_stop( 'ice_thd_init: LIM3 option, nn_limflx, should be between -1 and 2' )
       END SELECT
       !
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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_da.F90	(revision 8486)
@@ -4,5 +4,5 @@
    !! LIM-3 sea-ice :  computation of lateral melting in the ice
    !!======================================================================
-   !! History :   4.0   ! 2016-03 (C. Rousset) original code
+   !! History :  4.0  ! 2016-03 (C. Rousset)  original code
    !!---------------------------------------------------------------------
 #if defined key_lim3
@@ -10,10 +10,10 @@
    !!   'key_lim3'                                      LIM-3 sea-ice model
    !!----------------------------------------------------------------------
-   !!   ice_thd_da   : sea ice lateral melting
+   !!   ice_thd_da    : sea ice lateral melting
    !!----------------------------------------------------------------------
    USE par_oce        ! ocean parameters
    USE phycst         ! physical constants (ocean directory)
-   USE ice            ! LIM variables
-   USE ice1D          ! thermodynamic sea-ice variables
+   USE ice            ! sea-ice: variables
+   USE ice1D          ! sea-ice: thermodynamic 1D variables
    !
    USE lib_mpp        ! MPP library
@@ -23,8 +23,8 @@
    PRIVATE
 
-   PUBLIC   ice_thd_da        ! called by icethd module
+   PUBLIC   ice_thd_da   ! called by icethd.F90
 
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: icethd_da.F90 5123 2015-03-04 16:06:03Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -32,4 +32,6 @@
 CONTAINS
 
+!!gm  even comment line of more than 130 character may cause compilation errors
+!!gm         ===>>> reformat the text
    SUBROUTINE ice_thd_da
       !!-------------------------------------------------------------------
@@ -106,7 +108,5 @@
       REAL(wp), DIMENSION(jpij) ::   zda_tot
       !!---------------------------------------------------------------------
-
-      !------------------------------------------------------------!
-      !------------------------------------------------------------!
+      !
       zastar = 1._wp / ( 1._wp - (rn_dmin / zdmax)**(1._wp/rn_beta) )
       DO ji = 1, nidx   
@@ -136,5 +136,5 @@
             ! new concentration
             a_i_1d(ji) = a_i_1d(ji) - zda
-            
+
             ! ensure that ht_i = 0 where a_i = 0
             IF( a_i_1d(ji) == 0._wp ) THEN
@@ -151,8 +151,6 @@
    !!   Default option         Dummy Module          No LIM-3 sea-ice model
    !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE ice_thd_da          ! Empty routine
-   END SUBROUTINE ice_thd_da
 #endif
+
    !!======================================================================
 END MODULE icethd_da
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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_dh.F90	(revision 8486)
@@ -12,5 +12,5 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!   'key_lim3'                                       LIM3 sea-ice model
    !!----------------------------------------------------------------------
    !!   ice_thd_dh    : vertical accr./abl. and lateral ablation of sea ice
@@ -36,5 +36,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: icethd_dh.F90 8420 2017-08-08 12:18:46Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -66,8 +66,8 @@
       !!              Vancoppenolle et al.,2009, Ocean Modelling
       !!------------------------------------------------------------------
-      INTEGER  ::   ji , jk        ! dummy loop indices
-      INTEGER  ::   iter
-
-      REAL(wp) ::   ztmelts             ! local scalar
+      INTEGER  ::   ji, jk       ! dummy loop indices
+      INTEGER  ::   iter         ! local integer
+
+      REAL(wp) ::   ztmelts      ! local scalar
       REAL(wp) ::   zdum       
       REAL(wp) ::   zfracs       ! fractionation coefficient for bottom salt entrapment
@@ -104,12 +104,11 @@
       REAL(wp) :: zswitch_sal
 
-      ! Heat conservation 
-      INTEGER  ::   num_iter_max
+      INTEGER  ::   num_iter_max      ! Heat conservation 
       !!------------------------------------------------------------------
 
       ! Discriminate between varying salinity (nn_icesal=2) and prescribed cases (other values)
       SELECT CASE( nn_icesal )                  ! varying salinity or not
-         CASE( 1, 3 ) ;   zswitch_sal = 0._wp   ! prescribed salinity profile
-         CASE( 2 )    ;   zswitch_sal = 1._wp   ! varying salinity profile
+         CASE( 1, 3 )   ;   zswitch_sal = 0._wp   ! prescribed salinity profile
+         CASE( 2 )      ;   zswitch_sal = 1._wp   ! varying salinity profile
       END SELECT
 
@@ -127,6 +126,6 @@
             h_i_old (ji,jk) = ht_i_1d(ji) * r1_nlay_i
             eh_i_old(ji,jk) = e_i_1d(ji,jk) * h_i_old(ji,jk)
-         ENDDO
-      ENDDO
+         END DO
+      END DO
       !
       !------------------------------------------------------------------------------!
@@ -142,5 +141,4 @@
       END DO
 
-      !
       !------------------------------------------------------------------------------!
       ! If snow temperature is above freezing point, then snow melts 
@@ -163,5 +161,4 @@
       !  2) Computing layer thicknesses and enthalpies.            !
       !------------------------------------------------------------!
-      !
       DO jk = 1, nlay_i
          DO ji = 1, nidx
@@ -170,5 +167,5 @@
          END DO
       END DO
-      !
+
       !------------------------------------------------------------------------------|
       !  3) Surface ablation and sublimation                                         |
@@ -389,5 +386,5 @@
       END DO
 
-      !
+
       !------------------------------------------------------------------------------!
       ! 4) Basal growth / melt                                                       !
@@ -664,4 +661,5 @@
    !! ** Purpose :   Compute distribution of precip over the ice
    !!--------------------------------------------------------------------------
+!!gm  I think it can be usefull to set this as a FUNCTION, not a SUBROUTINE....
    SUBROUTINE ice_thd_snwblow_2d( pin, pout )
       REAL(wp), DIMENSION(:,:), INTENT(in   ) :: pin   ! previous fraction lead ( 1. - a_i_b )
@@ -676,12 +674,8 @@
    END SUBROUTINE ice_thd_snwblow_1d
 
-   
 #else
    !!----------------------------------------------------------------------
    !!   Default option                               NO  LIM3 sea-ice model
    !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE ice_thd_dh          ! Empty routine
-   END SUBROUTINE ice_thd_dh
 #endif
 
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_dif.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_dif.F90	(revision 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_dif.F90	(revision 8486)
@@ -18,6 +18,6 @@
    USE par_oce        ! ocean parameters
    USE phycst         ! physical constants (ocean directory) 
-   USE ice            ! LIM-3 variables
-   USE ice1D          ! LIM-3: thermodynamics
+   USE ice            ! sea-ice: variables
+   USE ice1D          ! sea-ice: thermodynamics
    !
    USE in_out_manager ! I/O manager
@@ -31,5 +31,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: icethd_dif.F90 8420 2017-08-08 12:18:46Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -67,5 +67,4 @@
       !!           of temperature
       !!
-      !!
       !! ** Inputs / Ouputs : (global commons)
       !!           surface temperature : t_su_1d
@@ -75,16 +74,5 @@
       !!           profile of the ice/snow layers : z_i, z_s
       !!           total ice/snow thickness : ht_i_1d, ht_s_1d
-      !!
-      !! ** External : 
-      !!
-      !! ** References :
-      !!
-      !! ** History :
-      !!           (02-2003) Martin Vancoppenolle, Louvain-la-Neuve, Belgium
-      !!           (06-2005) Martin Vancoppenolle, 3d version
-      !!           (11-2006) Vectorized by Xavier Fettweis (UCL-ASTR)
-      !!           (04-2007) Energy conservation tested by M. Vancoppenolle
       !!------------------------------------------------------------------
-      !! * Local variables
       INTEGER ::   ji             ! spatial loop index
       INTEGER ::   ii, ij         ! temporary dummy loop index
@@ -796,4 +784,5 @@
    END SUBROUTINE ice_thd_dif
 
+
    SUBROUTINE ice_thd_enmelt
       !!-----------------------------------------------------------------------
@@ -830,8 +819,6 @@
    !!                   Dummy Module                 No LIM-3 sea-ice model
    !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE ice_thd_dif          ! Empty routine
-   END SUBROUTINE ice_thd_dif
 #endif
+
    !!======================================================================
 END MODULE icethd_dif
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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_ent.F90	(revision 8486)
@@ -15,5 +15,5 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!   'key_lim3'                                       LIM3 sea-ice model
    !!----------------------------------------------------------------------
    !!   ice_thd_ent   : ice redistribution of enthalpy
@@ -36,5 +36,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: icethd_ent.F90 8420 2017-08-08 12:18:46Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -86,6 +86,6 @@
             zeh_cum0(ji,jk0) = zeh_cum0(ji,jk0-1) + eh_i_old(ji,jk0-1)
             zh_cum0 (ji,jk0) = zh_cum0 (ji,jk0-1) + h_i_old (ji,jk0-1)
-         ENDDO
-      ENDDO
+         END DO
+      END DO
 
       !------------------------------------
@@ -95,5 +95,5 @@
       DO ji = 1, nidx
          zhnew(ji) = SUM( h_i_old(ji,0:nlay_i+1) ) * r1_nlay_i  
-      ENDDO
+      END DO
 
       ! new layers interfaces
@@ -102,6 +102,6 @@
          DO ji = 1, nidx
             zh_cum1(ji,jk1) = zh_cum1(ji,jk1-1) + zhnew(ji)
-         ENDDO
-      ENDDO
+         END DO
+      END DO
 
       zeh_cum1(:,0:nlay_i) = 0._wp 
@@ -115,7 +115,7 @@
                      &             / ( zh_cum0(ji,jk0) - zh_cum0(ji,jk0-1) )
                ENDIF
-            ENDDO
-         ENDDO
-      ENDDO
+            END DO
+         END DO
+      END DO
       ! to ensure that total heat content is strictly conserved, set:
       zeh_cum1(:,nlay_i) = zeh_cum0(:,nlay_i+2) 
@@ -126,6 +126,6 @@
             rswitch      = MAX( 0._wp , SIGN( 1._wp , zhnew(ji) - epsi20 ) ) 
             qnew(ji,jk1) = rswitch * ( zeh_cum1(ji,jk1) - zeh_cum1(ji,jk1-1) ) / MAX( zhnew(ji), epsi20 )
-         ENDDO
-      ENDDO
+         END DO
+      END DO
 
       ! --- diag error on heat remapping --- !
@@ -143,7 +143,4 @@
    !!   Default option                               NO  LIM3 sea-ice model
    !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE ice_thd_ent          ! Empty routine
-   END SUBROUTINE ice_thd_ent
 #endif
 
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_lac.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_lac.F90	(revision 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_lac.F90	(revision 8486)
@@ -11,5 +11,5 @@
 #if defined key_lim3
    !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!   'key_lim3'                                       LIM3 sea-ice model
    !!----------------------------------------------------------------------
    !!   lim_lat_acr   : lateral accretion of ice
@@ -20,10 +20,10 @@
    USE sbc_oce , ONLY : sss_m
    USE sbc_ice , ONLY : utau_ice, vtau_ice
-   USE ice1D          ! LIM thermodynamics
-   USE ice            ! LIM variables
-   USE icetab         ! LIM 2D <==> 1D
-   USE icectl         ! LIM conservation
-   USE icethd_ent
-   USE icevar
+   USE ice1D          ! sea-ice: thermodynamics
+   USE ice            ! sea-ice: variables
+   USE icetab         ! sea-ice: 2D <==> 1D
+   USE icectl         ! sea-ice: conservation
+   USE icethd_ent     ! sea-ice: thermodynamics, enthalpy
+   USE icevar         ! sea-ice: operations
    !
    USE in_out_manager ! I/O manager
@@ -35,8 +35,8 @@
    PRIVATE
 
-   PUBLIC ice_thd_lac     ! called by ice_thd
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   PUBLIC   ice_thd_lac   ! called by ice_thd
+
+   !!----------------------------------------------------------------------
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: icethd_lac.F90 8420 2017-08-08 12:18:46Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -133,6 +133,6 @@
 
       ! Default new ice thickness
-      WHERE( qlead(:,:) < 0._wp ) ; hicol(:,:) = rn_hnewice
-      ELSEWHERE                   ; hicol(:,:) = 0._wp
+      WHERE( qlead(:,:) < 0._wp )   ;   hicol(:,:) = rn_hnewice
+      ELSEWHERE                     ;   hicol(:,:) = 0._wp
       END WHERE
 
@@ -486,7 +486,4 @@
    !!   Default option                               NO  LIM3 sea-ice model
    !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE ice_thd_lac           ! Empty routine
-   END SUBROUTINE ice_thd_lac
 #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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_sal.F90	(revision 8486)
@@ -31,5 +31,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: icethd_sal.F90 8420 2017-08-08 12:18:46Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -102,5 +102,4 @@
       !------------------------------------------------------------------------------|
       IF(  nn_icesal == 3  )   CALL ice_var_salprof1d
-
       !
    END SUBROUTINE ice_thd_sal
@@ -119,6 +118,7 @@
       !!-------------------------------------------------------------------
       INTEGER  ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namicesal/ ln_limdS, nn_icesal, rn_icesal, rn_sal_gd, rn_time_gd,   &
-         &                rn_sal_fl, rn_time_fl, rn_simax, rn_simin 
+      !!
+      NAMELIST/namicesal/ ln_limdS , nn_icesal , rn_icesal, rn_sal_gd, rn_time_gd,   &
+         &                rn_sal_fl, rn_time_fl, rn_simax , rn_simin 
       !!-------------------------------------------------------------------
       !
@@ -126,5 +126,5 @@
       READ  ( numnam_ice_ref, namicesal, IOSTAT = ios, ERR = 901)
 901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicesal in reference namelist', lwp )
-
+      !
       REWIND( numnam_ice_cfg )              ! Namelist namicesal in configuration namelist : Ice salinity
       READ  ( numnam_ice_cfg, namicesal, IOSTAT = ios, ERR = 902 )
@@ -154,4 +154,5 @@
    !!----------------------------------------------------------------------
 #endif
+
    !!======================================================================
 END MODULE icethd_sal
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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceupdate.F90	(revision 8486)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                       ***  MODULE iceupdate   ***
-   !!           computation of the flux at the sea ice/ocean interface
+   !!  Sea-ice :   computation of the flux at the sea ice/ocean interface
    !!======================================================================
    !! History :   -   ! 2006-07 (M. Vancoppelle)  LIM3 original code
@@ -27,14 +27,18 @@
    USE phycst         ! physical constants
    USE dom_oce        ! ocean domain
-   USE ice            ! LIM sea-ice variables
-   USE sbc_ice , ONLY : emp_oce, qns_oce, qsr_oce, qemp_oce, emp_ice, qsr_ice, qemp_ice, qevap_ice, alb_ice, tn_ice, cldf_ice,  &
+   USE ice            ! sea-ice: variables
+!!gm  It should be probably better to pass these variable in argument of the routine, 
+!!gm  rather than having this long list in USE. This will also highlight what is updated, and what is just use.
+   USE sbc_ice , ONLY : emp_oce, qns_oce, qsr_oce , qemp_oce ,                             &
+      &                 emp_ice, qsr_ice, qemp_ice, qevap_ice, alb_ice, tn_ice, cldf_ice,  &
       &                 snwice_mass, snwice_mass_b, snwice_fmass
    USE sbc_oce , ONLY : nn_fsbc, ln_ice_embd, sfx, fr_i, qsr_tot, qns, qsr, fmmflx, emp, taum, utau, vtau
+!!gm end
    USE sbccpl         ! Surface boundary condition: coupled interface
    USE icealb         ! albedo parameters
    USE traqsr         ! add penetration of solar flux in the calculation of heat budget
    USE domvvl         ! Variable volume
-   USE icectl         !
-   USE bdy_oce  , ONLY: ln_bdy
+   USE icectl         ! ???
+   USE bdy_oce , ONLY : ln_bdy
    !
    USE in_out_manager ! I/O manager
@@ -59,5 +63,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: iceupdate.F90 8411 2017-08-07 16:09:12Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -72,5 +76,5 @@
          &      sice_0(jpi,jpj) , vtau_oce(jpi,jpj) , tmod_io(jpi,jpj), STAT=ice_update_alloc)
          !
-      IF( lk_mpp             )   CALL mpp_sum( ice_update_alloc )
+      IF( lk_mpp                )   CALL mpp_sum( ice_update_alloc )
       IF( ice_update_alloc /= 0 )   CALL ctl_warn('ice_update_alloc: failed to allocate arrays')
    END FUNCTION ice_update_alloc
@@ -138,4 +142,6 @@
                zqsr = zqsr - a_i_b(ji,jj,jl) * (  qsr_ice(ji,jj,jl) - ftr_ice(ji,jj,jl) ) 
             END DO
+!!gm  why not like almost everywhere else :
+!!gm        zqsr = qsr_tot(ji,jj) - SUM( a_i_b(ji,jj,:) * (  qsr_ice(ji,jj,:) - ftr_ice(ji,jj,:) )
 
             ! Total heat flux reaching the ocean = hfx_out (W.m-2) 
@@ -170,5 +176,5 @@
             ! mass flux from ice/ocean
             wfx_ice(ji,jj) = wfx_bog(ji,jj) + wfx_bom(ji,jj) + wfx_sum(ji,jj) + wfx_sni(ji,jj)   &
-                           + wfx_opw(ji,jj) + wfx_dyn(ji,jj) + wfx_res(ji,jj) + wfx_lam(ji,jj) 
+               &           + wfx_opw(ji,jj) + wfx_dyn(ji,jj) + wfx_res(ji,jj) + wfx_lam(ji,jj) 
 
             IF ( ln_pnd_fw )   wfx_ice(ji,jj) = wfx_ice(ji,jj) + wfx_pnd(ji,jj)
@@ -189,9 +195,8 @@
             ! Mass of snow and ice per unit area   
             !----------------------------------------
-            ! save mass from the previous ice time step
-            snwice_mass_b(ji,jj) = snwice_mass(ji,jj)                  
-            ! new mass per unit area
+            snwice_mass_b(ji,jj) = snwice_mass(ji,jj)       ! save mass from the previous ice time step
+            !                                               ! new mass per unit area
             snwice_mass  (ji,jj) = tmask(ji,jj,1) * ( rhosn * vt_s(ji,jj) + rhoic * vt_i(ji,jj)  ) 
-            ! time evolution of snow+ice mass
+            !                                               ! time evolution of snow+ice mass
             snwice_fmass (ji,jj) = ( snwice_mass(ji,jj) - snwice_mass_b(ji,jj) ) * r1_rdtice
             
@@ -209,20 +214,19 @@
       !------------------------------------------------------------------------!
       CALL ice_alb( t_su, ht_i, ht_s, a_ip_frac, h_ip, ln_pnd_rad, zalb_cs, zalb_os ) ! cloud-sky and overcast-sky ice albedos
-
-      alb_ice(:,:,:) = ( 1. - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:)
-
-      ! conservation test
-      IF( ln_limdiachk .AND. .NOT. ln_bdy)  CALL ice_cons_final( 'iceupdate' )
-
-      ! control prints
+      !
+      alb_ice(:,:,:) = ( 1._wp - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:)
+
+      !                    ! conservation test
+      IF( ln_limdiachk .AND. .NOT. ln_bdy)   CALL ice_cons_final( 'iceupdate' )
+      !                    ! control prints
       IF( ln_limctl )   CALL ice_prt( kt, iiceprt, jiceprt, 3, ' - Final state ice_update - ' )
-      IF( ln_ctl )      CALL ice_prt3D( 'iceupdate' )
-
-      IF( nn_timing == 1 )  CALL timing_stop('ice_update_flx')
-
+      IF( ln_ctl    )   CALL ice_prt3D( 'iceupdate' )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('ice_update_flx')
+      !
    END SUBROUTINE ice_update_flx
 
 
-   SUBROUTINE ice_update_tau( kt , pu_oce, pv_oce )
+   SUBROUTINE ice_update_tau( kt, pu_oce, pv_oce )
       !!-------------------------------------------------------------------
       !!                ***  ROUTINE ice_update_tau ***
@@ -312,8 +316,6 @@
       !!                  ***  ROUTINE ice_update_init  ***
       !!             
-      !! ** Purpose : Preparation of the file ice_evolu for the output of
-      !!      the temporal evolution of key variables
+      !! ** Purpose :   ???
       !!
-      !! ** input   : Namelist namicedia
       !!-------------------------------------------------------------------
       INTEGER  ::   ji, jj, jk               ! dummy loop indices
@@ -322,5 +324,5 @@
       !
       IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'ice_update_init : LIM-3 sea-ice - surface boundary condition'
+      IF(lwp) WRITE(numout,*) 'ice_update_init :   sea-ice   ????'
       IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~   '
 
@@ -328,8 +330,7 @@
       IF( ice_update_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'ice_update_init : unable to allocate standard arrays' )
       !
-      soce_0(:,:) = soce                     ! constant SSS and ice salinity used in levitating sea-ice case
+      soce_0(:,:) = soce                     ! constant SSS and ice salinity used in levitating case 0 (i.e. virtual salt flux)
       sice_0(:,:) = sice
-      !                                      ! decrease ocean & ice reference salinities in the Baltic Sea area
-      WHERE( 14._wp <= glamt(:,:) .AND. glamt(:,:) <= 32._wp .AND.   &
+      WHERE( 14._wp <= glamt(:,:) .AND. glamt(:,:) <= 32._wp .AND.   &   ! reduced values in the Baltic Sea area
          &   54._wp <= gphit(:,:) .AND. gphit(:,:) <= 66._wp         ) 
          soce_0(:,:) = 4._wp
@@ -337,5 +338,5 @@
       END WHERE
       !
-      IF( .NOT. ln_rstart ) THEN
+      IF( .NOT.ln_rstart ) THEN              ! set 
          !
          snwice_mass  (:,:) = tmask(:,:,1) * ( rhosn * vt_s(:,:) + rhoic * vt_i(:,:)  )   ! snow+ice mass
@@ -350,8 +351,28 @@
             IF( .NOT.ln_linssh ) THEN
                DO jk = 1,jpkm1                     ! adjust initial vertical scale factors
-                  e3t_n(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshn(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
-                  e3t_b(:,:,jk) = e3t_0(:,:,jk)*( 1._wp + sshb(:,:)*tmask(:,:,1)/(ht_0(:,:) + 1.0 - tmask(:,:,1)) )
+                  e3t_n(:,:,jk) = e3t_0(:,:,jk) * (  1._wp + sshn(:,:)*tmask(:,:,1) / (ht_0(:,:) + 1._wp - tmask(:,:,1) )  )
+                  e3t_b(:,:,jk) = e3t_0(:,:,jk) * (  1._wp + sshb(:,:)*tmask(:,:,1) / (ht_0(:,:) + 1._wp - tmask(:,:,1) )  )
                END DO
                e3t_a(:,:,:) = e3t_b(:,:,:)
+!!gm  we are in no-restart case, so sshn=sshb   ==>> faster calculation:
+!!    REAL(wp) ::   ze3t   ! local scalar
+!!    REAL(wp), DIMENSION(jpi,jpj) ::   z2d   ! workspace
+!!
+!!             WHERE( ht_0(:,:) > 0 )   ;   z2d(:,:) = 1._wp + sshn(:,:)*tmask(:,:,1) / ht_0(:,:)
+!!             ELSEWHERE                ;   z2d(:,:) = 1._wp
+!!             END WHERE
+!!             DO jk = 1,jpkm1                     ! adjust initial vertical scale factors                
+!!                ze3t = e3t_0(:,:,jk) * z2d(:,:)
+!!                e3t_n(:,:,jk) = ze3t
+!!                e3t_b(:,:,jk) = ze3t
+!!                e3t_a(:,:,jk) = ze3t
+!!             END DO
+!!gm  but since it is only done at the initialisation....  just the following can be acceptable:
+!               DO jk = 1,jpkm1                     ! adjust initial vertical scale factors
+!                  e3t_n(:,:,jk) = e3t_0(:,:,jk) * (  1._wp + sshn(:,:)*tmask(:,:,1) / (ht_0(:,:) + 1._wp - tmask(:,:,1))  )
+!               END DO
+!               e3t_b(:,:,:) = e3t_n(:,:,:)
+!               e3t_a(:,:,:) = e3t_n(:,:,:)
+!!gm end               
                ! Reconstruction of all vertical scale factors at now and before time-steps
                ! =========================================================================
@@ -377,7 +398,7 @@
                gde3w_n(:,:,1) = gdept_n(:,:,1) - sshn(:,:)
                DO jk = 2, jpk
-                  gdept_n(:,:,jk) = gdept_n(:,:,jk-1) + e3w_n(:,:,jk)
+                  gdept_n(:,:,jk) = gdept_n(:,:,jk-1) + e3w_n(:,:,jk  )
                   gdepw_n(:,:,jk) = gdepw_n(:,:,jk-1) + e3t_n(:,:,jk-1)
-                  gde3w_n(:,:,jk) = gdept_n(:,:,jk  ) - sshn   (:,:)
+                  gde3w_n(:,:,jk) = gdept_n(:,:,jk  ) - sshn (:,:)
                END DO
             ENDIF
@@ -387,4 +408,8 @@
    END SUBROUTINE ice_update_init
 
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Dummy module          NO  LIM3 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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icevar.F90	(revision 8486)
@@ -31,8 +31,19 @@
    !! History :   -   ! 2006-01 (M. Vancoppenolle) Original code
    !!            3.4  ! 2011-02 (G. Madec) dynamical allocation
+   !!            3.5  ! 2012    (M. Vancoppenolle)  add ice_var_itd
+   !!            3.6  ! 2014-01 (C. Rousset) add ice_var_zapsmall, rewrite ice_var_itd
    !!----------------------------------------------------------------------
 #if defined key_lim3
    !!----------------------------------------------------------------------
    !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_var_agg       : integrate variables over layers and categories
+   !!   ice_var_glo2eqv   : transform from VGLO to VEQV
+   !!   ice_var_eqv2glo   : transform from VEQV to VGLO
+   !!   ice_var_salprof   : salinity profile in the ice
+   !!   ice_var_bv        : brine volume
+   !!   ice_var_salprof1d : salinity profile in the ice 1D
+   !!   ice_var_zapsmall  : remove very small area and volume
+   !!   ice_var_itd       : convert 1-cat to multiple cat
    !!----------------------------------------------------------------------
    USE par_oce        ! ocean parameters
@@ -59,5 +70,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 3.5 , UCL - NEMO Consortium (2011)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: icevar.F90 8422 2017-08-08 13:58:05Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -69,84 +80,62 @@
       !!                ***  ROUTINE ice_var_agg  ***
       !!
-      !! ** Purpose :   aggregates ice-thickness-category variables to all-ice variables
-      !!              i.e. it turns VGLO into VAGG
-      !! ** Method  :
-      !!
-      !! ** Arguments : n = 1, at_i vt_i only
-      !!                n = 2 everything
-      !!
-      !! note : you could add an argument when you need only at_i, vt_i
-      !!        and when you need everything
-      !!------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kn     ! =1 at_i & vt only ; = what is needed
-      !
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      !!------------------------------------------------------------------
-
-      ! integrated values
-      vt_i (:,:) = SUM( v_i, dim=3 )
-      vt_s (:,:) = SUM( v_s, dim=3 )
-      at_i (:,:) = SUM( a_i, dim=3 )
+      !! ** Purpose :   aggregates ice-thickness-category variables to 
+      !!              all-ice variables, i.e. it turns VGLO into VAGG
+      !!------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kn     ! =1 state variables only
+      !                                 ! >1 state variables + others
+      !
+      INTEGER ::   ji, jj, jk, jl   ! dummy loop indices
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   z1_at_i, z1_vt_i
+      !!------------------------------------------------------------------
+      !
+      !                                      ! integrated values
+      vt_i(:,:) =       SUM( v_i(:,:,:)           , dim=3 )
+      vt_s(:,:) =       SUM( v_s(:,:,:)           , dim=3 )
+      at_i(:,:) =       SUM( a_i(:,:,:)           , dim=3 )
       et_s(:,:)  = SUM( SUM( e_s(:,:,:,:), dim=4 ), dim=3 )
       et_i(:,:)  = SUM( SUM( e_i(:,:,:,:), dim=4 ), dim=3 )
 
       ! MV MP 2016
-      IF ( ln_pnd ) THEN
-         at_ip(:,:) = SUM( a_ip, dim=3 )
-         vt_ip(:,:) = SUM( v_ip, dim=3 )
+      IF ( ln_pnd ) THEN                     ! Melt pond
+         at_ip(:,:) = SUM( a_ip(:,:,:), dim=3 )
+         vt_ip(:,:) = SUM( v_ip(:,:,:), dim=3 )
       ENDIF
       ! END MP 2016
 
-      ! open water fraction
-      DO jj = 1, jpj
+      DO jj = 1, jpj                         ! open water fraction
          DO ji = 1, jpi
             ato_i(ji,jj) = MAX( 1._wp - at_i(ji,jj), 0._wp )   
          END DO
       END DO
+!!gm I think this should do the work :
+!      ato_i(:,:) = MAX( 1._wp - at_i(:,:), 0._wp )  
+!!gm end
 
       IF( kn > 1 ) THEN
-
-         ! mean ice/snow thickness
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               rswitch      = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi10 ) ) 
-               htm_i(ji,jj) = vt_i(ji,jj) / MAX( at_i(ji,jj) , epsi10 ) * rswitch
-               htm_s(ji,jj) = vt_s(ji,jj) / MAX( at_i(ji,jj) , epsi10 ) * rswitch
-            ENDDO
-         ENDDO
-
-         ! mean temperature (K), salinity and age
-         smt_i(:,:) = 0._wp
-         tm_i(:,:)  = 0._wp
-         tm_su(:,:) = 0._wp
-         tm_si(:,:) = 0._wp
-         om_i (:,:) = 0._wp
-         DO jl = 1, jpl
-            
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  rswitch      = MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi10 ) )
-                  tm_su(ji,jj) = tm_su(ji,jj) + rswitch * ( t_su(ji,jj,jl) - rt0 ) * a_i(ji,jj,jl) / MAX( at_i(ji,jj) , epsi10 )
-                  tm_si(ji,jj) = tm_si(ji,jj) + rswitch * ( t_si(ji,jj,jl) - rt0 ) * a_i(ji,jj,jl) / MAX( at_i(ji,jj) , epsi10 )
-                  om_i (ji,jj) = om_i (ji,jj) + rswitch *   oa_i(ji,jj,jl)                         / MAX( at_i(ji,jj) , epsi06 )
-               END DO
-            END DO
-            
-            DO jk = 1, nlay_i
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     rswitch = MAX( 0._wp , SIGN( 1._wp , vt_i(ji,jj) - epsi10 ) )
-                     tm_i(ji,jj)  = tm_i(ji,jj)  + r1_nlay_i * rswitch * ( t_i(ji,jj,jk,jl) - rt0 ) * v_i(ji,jj,jl)  &
-                        &            / MAX( vt_i(ji,jj) , epsi10 )
-                     smt_i(ji,jj) = smt_i(ji,jj) + r1_nlay_i * rswitch * s_i(ji,jj,jk,jl) * v_i(ji,jj,jl)  &
-                        &            / MAX( vt_i(ji,jj) , epsi10 )
-                  END DO
-               END DO
-            END DO
-         END DO
-         tm_i  = tm_i  + rt0
-         tm_su = tm_su + rt0
-         tm_si = tm_si + rt0
-         !
+         !
+         ALLOCATE( z1_at_i(jpi,jpj) , z1_vt_i(jpi,jpj) )
+         WHERE( at_i(:,:) > epsi10 )   ;   z1_at_i(:,:) = 1._wp / at_i(:,:)
+         ELSEWHERE                     ;   z1_at_i(:,:) = 0._wp
+         END WHERE
+         WHERE( vt_i(:,:) > epsi10 )   ;   z1_vt_i(:,:) = 1._wp / vt_i(:,:)
+         ELSEWHERE                     ;   z1_vt_i(:,:) = 0._wp
+         END WHERE
+         !
+         !                          ! mean ice/snow thickness
+         htm_i(:,:) = vt_i(:,:) * z1_at_i(:,:)
+         htm_s(:,:) = vt_s(:,:) * z1_at_i(:,:)
+         !         
+         !                          ! mean temperature (K), salinity and age
+         tm_su(:,:) = SUM( t_su(:,:,:) * a_i(:,:,:) , dim=3 ) * z1_at_i(ji,jj)
+         tm_si(:,:) = SUM( t_si(:,:,:) * a_i(:,:,:) , dim=3 ) * z1_at_i(ji,jj)
+         om_i (:,:) = SUM( oa_i(:,:,:)              , dim=3 ) * z1_at_i(ji,jj)
+         !
+         tm_i (:,:) = r1_nlay_i * SUM( SUM( t_i(:,:,:,:) * v_i(:,:,:), dim=4 ) , dim=3 ) * z1_vt_i(:,:)
+         smt_i(:,:) = r1_nlay_i * SUM( SUM( s_i(:,:,:,:) * v_i(:,:,:), dim=4 ) , dim=3 ) * z1_vt_i(:,:)
+!
+!!gm  QUESTION 1 : why salinity is named smt_i  and not just sm_i ?   since the 4D field is named s_i. (NB for temp: tm_i, t_i)
+         !
+         DEALLOCATE( z1_at_i , z1_vt_i )
       ENDIF
       !
@@ -158,53 +147,48 @@
       !!                ***  ROUTINE ice_var_glo2eqv ***
       !!
-      !! ** Purpose :   computes equivalent variables as function of global variables 
-      !!              i.e. it turns VGLO into VEQV
+      !! ** 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, zaaa, zbbb, zccc, zdiscrim     ! local scalars
-      REAL(wp) ::   ztmelts, ze_s, zfac1, zfac2   !   -      -
-      !!------------------------------------------------------------------
+      REAL(wp) ::   ze_i, z1_CpR, zdiscrim, zaaa, z1_2aaa             ! local scalars
+      REAL(wp) ::   ze_s, zL_Cp , ztmelts , zbbb, zccc                !   -      -
+      REAL(wp) ::   zhmax, z1_zhmax, zsm_i, zcpMcpic, zt_i   !   -      -
+      REAL(wp) ::   zlay_i, zlay_s   !   -      -
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z1_a_i, z1_v_i
+      !!------------------------------------------------------------------
+
+!!gm Question 1:  here use epsi20 , in ice_var_agg it is epsi10 which is used...  why ??
+
+!!gm Question 2:  It is possible to define existence of sea-ice in a common way between 
+!!                ice area and ice volume ?
+!!                the idea is to be able to define one for all at the begining of this routine
+!!                a criteria for icy area (i.e. a_i > epsi20 and v_i > epsi20 )
 
       !-------------------------------------------------------
       ! Ice thickness, snow thickness, ice salinity, ice age
       !-------------------------------------------------------
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               rswitch = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi20 ) )   !0 if no ice and 1 if yes
-               ht_i(ji,jj,jl) = v_i (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-            END DO
-         END DO
-      END DO
-      ! Force the upper limit of ht_i to always be < hi_max (99 m).
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            rswitch = MAX( 0._wp , SIGN( 1._wp, ht_i(ji,jj,jpl) - epsi20 ) )
-            ht_i(ji,jj,jpl) = MIN( ht_i(ji,jj,jpl) , hi_max(jpl) )
-            a_i (ji,jj,jpl) = v_i(ji,jj,jpl) / MAX( ht_i(ji,jj,jpl) , epsi20 ) * rswitch
-         END DO
-      END DO
-
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               rswitch = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi20 ) )   !0 if no ice and 1 if yes
-               ht_s(ji,jj,jl) = v_s (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-               o_i(ji,jj,jl)  = oa_i(ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-            END DO
-         END DO
-      END DO
+      !                                            !--- inverse of the ice area
+      WHERE( a_i(:,:,:) > epsi20 )   ;   z1_a_i(:,:,:) = 1._wp / a_i(:,:,:)
+      ELSEWHERE                      ;   z1_a_i(:,:,:) = 0._wp
+      END WHERE
+      !
+      ht_i(:,:,:) = v_i (:,:,:) * z1_a_i(:,:,:)    !--- ice thickness
+
+	  zhmax    =          hi_max(jpl)
+      z1_zhmax =  1._wp / hi_max(jpl)               
+      WHERE( ht_i(:,:,jpl) > zhmax )               !--- bound ht_i by hi_max (i.e. 99 m) with associated update of ice area
+         ht_i  (:,:,jpl) = zhmax
+         a_i   (:,:,jpl) = v_i(:,:,jpl) * z1_zhmax 
+         z1_a_i(:,:,jpl) = zhmax / v_i(:,:,jpl)          ! NB: v_i always /=0 as ht_i > hi_max
+      END WHERE
+
+      ht_s(:,:,:) = v_s (:,:,:) * z1_a_i(:,:,:)    !--- snow thickness
       
-      IF(  nn_icesal == 2  )THEN
-         DO jl = 1, jpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  rswitch = MAX( 0._wp , SIGN( 1._wp, v_i(ji,jj,jl) - epsi20 ) )   !0 if no ice and 1 if yes
-                  sm_i(ji,jj,jl) = smv_i(ji,jj,jl) / MAX( v_i(ji,jj,jl) , epsi20 ) * rswitch
-                  !                                      ! bounding salinity
-                  sm_i(ji,jj,jl) = MAX( sm_i(ji,jj,jl), rn_simin )
-               END DO
-            END DO
-         END DO
+      o_i(:,:,:)  = oa_i(:,:,:) * z1_a_i(:,:,:)    !--- ice age
+
+      IF( nn_icesal == 2 )THEN                     !--- salinity (with a minimum value imposed everywhere)
+         WHERE( v_i(:,:,:) > epsi20 )   ;   sm_i(:,:,:) = MAX( rn_simin , smv_i(:,:,:) / v_i(:,:,:) )
+         ELSEWHERE                      ;   sm_i(:,:,:) = rn_simin
+         END WHERE
       ENDIF
 
@@ -212,21 +196,29 @@
 
       !-------------------
-      ! Ice temperatures
+      ! Ice temperature   [K]   (with a minimum value (rt0 - 100.) imposed everywhere)
       !-------------------
+      zlay_i   = REAL( nlay_i , wp )    ! number of layers
+      zaaa     = cpic                   ! Conversion q(S,T) -> T (second order equation)
+      z1_2aaa  = 1._wp / 2._wp *zaaa
+      zcpMcpic = rcp - cpic
       DO jl = 1, jpl
          DO jk = 1, nlay_i
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  !                                                              ! Energy of melting e(S,T) [J.m-3]
-                  rswitch = MAX( 0.0 , SIGN( 1.0 , v_i(ji,jj,jl) - epsi20 ) )     ! rswitch = 0 if no ice and 1 if yes
-                  ze_i    = rswitch * e_i(ji,jj,jk,jl) / MAX( v_i(ji,jj,jl) , epsi20 ) * REAL(nlay_i,wp) 
-                  ztmelts = -tmut * s_i(ji,jj,jk,jl) + rt0              ! Ice layer melt temperature
-                  !
-                  zaaa       =  cpic                  ! Conversion q(S,T) -> T (second order equation)
-                  zbbb       =  ( rcp - cpic ) * ( ztmelts - rt0 ) + ze_i * r1_rhoic - lfus
-                  zccc       =  lfus * (ztmelts-rt0)
-                  zdiscrim   =  SQRT( MAX(zbbb*zbbb - 4._wp*zaaa*zccc , 0._wp) )
-                  t_i(ji,jj,jk,jl) = rt0 + rswitch *( - zbbb - zdiscrim ) / ( 2.0 *zaaa )
-                  t_i(ji,jj,jk,jl) = MIN( ztmelts, MAX( rt0 - 100._wp, t_i(ji,jj,jk,jl) ) )  ! -100 < t_i < ztmelts
+                  IF ( v_i(ji,jj,jl) > epsi20 ) THEN     !--- icy area 
+                     !
+                     ze_i    =   e_i(ji,jj,jk,jl) / v_i(ji,jj,jl) * zlay_i               ! Energy of melting e(S,T) [J.m-3]
+                     ztmelts = - s_i(ji,jj,jk,jl) * tmut                                 ! Ice layer melt temperature [C]
+                     !
+                     zbbb     =  zcpMcpic * ztmelts + ze_i * r1_rhoic - lfus
+                     zccc     =  lfus * ztmelts
+                     zdiscrim =  SQRT(  MAX( zbbb*zbbb - 4._wp*zaaa*zccc , 0._wp)  )
+                     zt_i     = - ( zbbb + zdiscrim ) * z1_2aaa                          ! [C]
+                     t_i(ji,jj,jk,jl) = MAX( -100._wp , MIN( zt_i , ztmelts )  ) + rt0   ! [K] with bounds: -100 < zt_i < ztmelts
+                     !
+                  ELSE                                !--- no ice
+                     t_i(ji,jj,jk,jl) =  rt0 - 100._wp                                   ! impose 173.15 K (i.e. -100 C)
+!!clem: I think we should impose rt0 instead
+                  ENDIF
                END DO
             END DO
@@ -235,22 +227,27 @@
 
       !--------------------
-      ! Snow temperatures
+      ! Snow temperature   [K]   (with a minimum value (rt0 - 100.) imposed everywhere)
       !--------------------
-      zfac1 = 1._wp / ( rhosn * cpic )
-      zfac2 = lfus / cpic  
-      DO jl = 1, jpl
-         DO jk = 1, nlay_s
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  !Energy of melting q(S,T) [J.m-3]
-                  rswitch = MAX( 0._wp , SIGN( 1._wp , v_s(ji,jj,jl) - epsi20 ) )     ! rswitch = 0 if no ice and 1 if yes
-                  ze_s  = rswitch * e_s(ji,jj,jk,jl) / MAX( v_s(ji,jj,jl) , epsi20 ) * REAL(nlay_s,wp)
-                  !
-                  t_s(ji,jj,jk,jl) = rt0 + rswitch * ( - zfac1 * ze_s + zfac2 )
-                  t_s(ji,jj,jk,jl) = MIN( rt0, MAX( rt0 - 100._wp , t_s(ji,jj,jk,jl) ) )     ! -100 < t_s < rt0
-               END DO
-            END DO
-         END DO
+      z1_CpR = 1._wp / ( cpic * rhosn )
+      zL_Cp  = lfus  /   cpic
+      zlay_s = REAL( nlay_s , wp )
+      DO jk = 1, nlay_s
+         WHERE( v_s(:,:,:) > epsi20 )        !--- icy area
+            t_s(:,:,jk,:) = MAX(  -100._wp , MIN( - z1_CpR * ( e_s(:,:,jk,:)/v_s(:,:,:)*zlay_s ) + zL_Cp , 0._wp )  ) + rt0       
+         ELSEWHERE                           !--- no ice
+            t_s(:,:,jk,:) =  rt0 - 100._wp         ! impose 173.15 K (i.e. -100 C)
+         END WHERE
       END DO
+!!gm perhaps better like this (?) :  (if this compile, yes! one test instead of nlay_s tests)
+!      WHERE( v_s(:,:,:) > epsi20 )        !--- icy area
+!         DO jk = 1, nlay_s
+!            t_s(:,:,jk,:) = MAX(  -100._wp , MIN( - z1_CpR * ( e_s(:,:,jk,:)/v_s(:,:,:)*zlay_s ) + zL_Cp , 0._wp )  ) + rt0       
+!         END DO
+!      ELSEWHERE                           !--- no ice
+!         DO jk = 1, nlay_s
+!            t_s(:,:,jk,:) =  rt0 - 100._wp      ! impose 173.15 K (i.e. -100 C)
+!         END DO
+!      END WHERE
+!!gm end better ?
 
       ! integrated values 
@@ -259,6 +256,6 @@
       at_i (:,:) = SUM( a_i, dim=3 )
 
-      ! MV MP 2016
-      ! probably should resum for melt ponds ???
+! MV MP 2016
+! probably should resum for melt ponds ???
 
       !
@@ -270,13 +267,10 @@
       !!                ***  ROUTINE ice_var_eqv2glo ***
       !!
-      !! ** Purpose :   computes global variables as function of equivalent variables
-      !!                i.e. it turns VEQV into VGLO
-      !! ** Method  :
-      !!
-      !! ** History :  (01-2006) Martin Vancoppenolle, UCL-ASTR
-      !!------------------------------------------------------------------
-      !
-      v_i(:,:,:)   = ht_i(:,:,:) * a_i(:,:,:)
-      v_s(:,:,:)   = ht_s(:,:,:) * a_i(:,:,:)
+      !! ** Purpose :   computes global variables as function of 
+      !!              equivalent variables,  i.e. it turns VEQV into VGLO
+      !!------------------------------------------------------------------
+      !
+      v_i  (:,:,:) = ht_i(:,:,:) * a_i(:,:,:)
+      v_s  (:,:,:) = ht_s(:,:,:) * a_i(:,:,:)
       smv_i(:,:,:) = sm_i(:,:,:) * v_i(:,:,:)
       !
@@ -300,53 +294,45 @@
       !!------------------------------------------------------------------
       INTEGER  ::   ji, jj, jk, jl   ! dummy loop index
-      REAL(wp) ::   zfac0, zfac1, zsal
-      REAL(wp) ::   zswi0, zswi01, zargtemp , zs_zero   
-      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z_slope_s, zalpha
+      REAL(wp) ::   zsal, z1_dS
+      REAL(wp) ::   zargtemp , zs0, zs
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   z_slope_s, zalpha    ! case 2 only
       REAL(wp), PARAMETER :: zsi0 = 3.5_wp
       REAL(wp), PARAMETER :: zsi1 = 4.5_wp
       !!------------------------------------------------------------------
 
-      !---------------------------------------
-      ! Vertically constant, constant in time
-      !---------------------------------------
-      IF(  nn_icesal == 1  )  THEN
+!!gm  much much more secure to defined when reading nn_icesal in the namelist integers =1, 2, 3  with explicit names
+!!       for example np_Scst_noProfile = 1  ;  np_Svar_linProfile = 2   ;   np_Scst_fixProfile
+
+!!gm Question: Remove the option 3 ?  How many years since it last use ? 
+
+      SELECT CASE ( nn_icesal )
+      !
+      !              !---------------------------------------!
+      CASE( 1 )      !  constant salinity in time and space  !
+         !           !---------------------------------------!
          s_i (:,:,:,:) = rn_icesal
          sm_i(:,:,:)   = rn_icesal
-      ENDIF
-
-      !-----------------------------------
-      ! Salinity profile, varying in time
-      !-----------------------------------
-      IF(  nn_icesal == 2  ) THEN
+         !
+         !           !---------------------------------------------!
+      CASE( 2 )      !  time varying salinity with linear profile  !
+         !           !---------------------------------------------!
+         !
+         ALLOCATE( z_slope_s(jpi,jpj,jpl) , zalpha(jpi,jpj,jpl) )
          !
          DO jk = 1, nlay_i
             s_i(:,:,jk,:)  = sm_i(:,:,:)
          END DO
-         !
-         DO jl = 1, jpl                               ! Slope of the linear profile 
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  rswitch = MAX( 0._wp , SIGN( 1._wp , ht_i(ji,jj,jl) - epsi20 ) )
-                  z_slope_s(ji,jj,jl) = rswitch * 2._wp * sm_i(ji,jj,jl) / MAX( epsi20 , ht_i(ji,jj,jl) )
-               END DO
-            END DO
-         END DO
-         !
-         zfac0 = 1._wp / ( zsi0 - zsi1 )       ! Weighting factor between zs_zero and zs_inf
-         zfac1 = zsi1  / ( zsi1 - zsi0 )
-         !
-         zalpha(:,:,:) = 0._wp
+         !                                      ! Slope of the linear profile 
+         WHERE( ht_i(:,:,:) > epsi20 )   ;   z_slope_s(:,:,:) = 2._wp * sm_i(:,:,:) / ht_i(:,:,:)
+         ELSEWHERE                       ;   z_slope_s(:,:,:) = 0._wp
+         END WHERE
+         !
+         z1_dS = 1._wp / ( zsi1 - zsi0 )
          DO jl = 1, jpl
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  ! zswi0 = 1 if sm_i le zsi0 and 0 otherwise
-                  zswi0  = MAX( 0._wp   , SIGN( 1._wp  , zsi0 - sm_i(ji,jj,jl) ) ) 
-                  ! zswi01 = 1 if sm_i is between zsi0 and zsi1 and 0 othws 
-                  zswi01 = ( 1._wp - zswi0 ) * MAX( 0._wp   , SIGN( 1._wp  , zsi1 - sm_i(ji,jj,jl) ) ) 
-                  ! If 2.sm_i GE sss_m then rswitch = 1
-                  ! this is to force a constant salinity profile in the Baltic Sea
-                  rswitch = MAX( 0._wp , SIGN( 1._wp , 2._wp * sm_i(ji,jj,jl) - sss_m(ji,jj) ) )
-                  zalpha(ji,jj,jl) = zswi0  + zswi01 * ( sm_i(ji,jj,jl) * zfac0 + zfac1 )
-                  zalpha(ji,jj,jl) = zalpha(ji,jj,jl) * ( 1._wp - rswitch )
+                  zalpha(ji,jj,jl) = MAX(  0._wp , MIN( ( zsi1 - sm_i(ji,jj,jl) ) * z1_dS , 1._wp )  )
+                  !                             ! force a constant profile when SSS too low (Baltic Sea)
+                  IF( 2._wp * sm_i(ji,jj,jl) >= sss_m(ji,jj) )   zalpha(ji,jj,jl) = 0._wp  
                END DO
             END DO
@@ -358,10 +344,8 @@
                DO jj = 1, jpj
                   DO ji = 1, jpi
-                     !                                      ! linear profile with 0 at the surface
-                     zs_zero = z_slope_s(ji,jj,jl) * ( REAL(jk,wp) - 0.5_wp ) * ht_i(ji,jj,jl) * r1_nlay_i
-                     !                                      ! weighting the profile
-                     s_i(ji,jj,jk,jl) = zalpha(ji,jj,jl) * zs_zero + ( 1._wp - zalpha(ji,jj,jl) ) * sm_i(ji,jj,jl)
-                     !                                      ! bounding salinity
-                     s_i(ji,jj,jk,jl) = MIN( rn_simax, MAX( s_i(ji,jj,jk,jl), rn_simin ) )
+                     !                          ! linear profile with 0 surface value
+                     zs0 = z_slope_s(ji,jj,jl) * ( REAL(jk,wp) - 0.5_wp ) * ht_i(ji,jj,jl) * r1_nlay_i
+                     zs  = zalpha(ji,jj,jl) * zs0 + ( 1._wp - zalpha(ji,jj,jl) ) * sm_i(ji,jj,jl)     ! weighting the profile
+                     s_i(ji,jj,jk,jl) = MIN( rn_simax, MAX( zs, rn_simin ) )
                   END DO
                END DO
@@ -369,23 +353,26 @@
          END DO
          !
-      ENDIF ! nn_icesal
-
-      !-------------------------------------------------------
-      ! Vertically varying salinity profile, constant in time
-      !-------------------------------------------------------
-
-      IF(  nn_icesal == 3  ) THEN      ! Schwarzacher (1959) multiyear salinity profile (mean = 2.30)
+         DEALLOCATE( z_slope_s , zalpha )
+         !
+         !           !-------------------------------------------!
+      CASE( 3 )      ! constant salinity with a fix profile      ! (Schwarzacher (1959) multiyear salinity profile
+         !           !-------------------------------------------!                                   (mean = 2.30)
          !
          sm_i(:,:,:) = 2.30_wp
+!!gm Remark: if we keep the case 3, then compute an store one for all time-step
+!!           a array  S_prof(1:nlay_i) containing the calculation and just do:
+!         DO jk = 1, nlay_i
+!            s_i(:,:,jk,:) = S_prof(jk)
+!         END DO
+!!gm end
          !
          DO jl = 1, jpl
             DO jk = 1, nlay_i
                zargtemp  = ( REAL(jk,wp) - 0.5_wp ) * r1_nlay_i
-               zsal =  1.6_wp * (  1._wp - COS( rpi * zargtemp**(0.407_wp/(0.573_wp+zargtemp)) )  )
-               s_i(:,:,jk,jl) =  zsal
-            END DO
-         END DO
-         !
-      ENDIF ! nn_icesal
+               s_i(:,:,jk,jl) =  1.6_wp * (  1._wp - COS( rpi * zargtemp**(0.407_wp/(0.573_wp+zargtemp)) )  )
+            END DO
+         END DO
+         !
+      END SELECT
       !
    END SUBROUTINE ice_var_salprof
@@ -405,25 +392,18 @@
       !!------------------------------------------------------------------
       !
-      bvm_i(:,:)   = 0._wp
+!!gm I prefere to use WHERE / ELSEWHERE  to set it to zero only where needed   <<<=== to be done
+!!   instead of setting everything to zero as just below
       bv_i (:,:,:) = 0._wp
       DO jl = 1, jpl
          DO jk = 1, nlay_i
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  rswitch        = ( 1._wp - MAX( 0._wp , SIGN( 1._wp , (t_i(ji,jj,jk,jl) - rt0) + epsi10 ) )  )
-                  bv_i(ji,jj,jl) = bv_i(ji,jj,jl) - rswitch * tmut * s_i(ji,jj,jk,jl) * r1_nlay_i  &
-                     &                            / MIN( t_i(ji,jj,jk,jl) - rt0, - epsi10 )
-               END DO
-            END DO
-         END DO
-         
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               rswitch      = MAX( 0._wp , SIGN( 1._wp , vt_i(ji,jj) - epsi10 ) )
-               bvm_i(ji,jj) = bvm_i(ji,jj) + rswitch * bv_i(ji,jj,jl) * v_i(ji,jj,jl) / MAX( vt_i(ji,jj), epsi10 )
-            END DO
+            WHERE( t_i(:,:,jk,jl) < rt0 - epsi10 )   
+               bv_i(:,:,jl) = bv_i(:,:,jl) - tmut * s_i(:,:,jk,jl) * r1_nlay_i / ( t_i(:,:,jk,jl) - rt0 )
+            END WHERE
          END DO
       END DO
-      !
+      WHERE( vt_i(:,:) > epsi20 )   bvm_i(:,:) = SUM( bv_i(:,:,:) * v_i(:,:,:) , dim=3 ) / vt_i(:,:)
+      ELSEWHERE                     bvm_i(:,:) = 0._wp
+	  END WHERE
+	  !
    END SUBROUTINE ice_var_bv
 
@@ -437,62 +417,51 @@
       !!-------------------------------------------------------------------
       INTEGER  ::   ji, jk    ! dummy loop indices
-      REAL(wp) ::   zfac0, zfac1, zargtemp, zsal   ! local scalars
-      REAL(wp) ::   zalpha, zswi0, zswi01, zs_zero              !   -      -
-      !
-      REAL(wp), DIMENSION(jpij) ::   z_slope_s
+      REAL(wp) ::   zargtemp, zsal, z1_dS   ! local scalars
+      REAL(wp) ::   zalpha, zs, zs0              !   -      -
+      !
+      REAL(wp), ALLOCATABLE, DIMENSION(:) ::   z_slope_s   !
       REAL(wp), PARAMETER :: zsi0 = 3.5_wp
       REAL(wp), PARAMETER :: zsi1 = 4.5_wp
       !!---------------------------------------------------------------------
-
-      !---------------------------------------
-      ! Vertically constant, constant in time
-      !---------------------------------------
-      IF( nn_icesal == 1 )   s_i_1d(:,:) = rn_icesal
-
-      !------------------------------------------------------
-      ! Vertically varying salinity profile, varying in time
-      !------------------------------------------------------
-
-      IF(  nn_icesal == 2  ) THEN
-         !
-         DO ji = 1, nidx          ! Slope of the linear profile zs_zero
+      !
+      SELECT CASE ( nn_icesal )
+      !
+      !              !---------------------------------------!
+      CASE( 1 )      !  constant salinity in time and space  !
+         !           !---------------------------------------!
+         s_i_1d(:,:) = rn_icesal
+         !
+         !           !---------------------------------------------!
+      CASE( 2 )      !  time varying salinity with linear profile  !
+         !           !---------------------------------------------!
+         !
+         ALLOCATE( z_slope_s(jpij) )
+         !
+         DO ji = 1, nidx          ! Slope of the linear profile
             rswitch = MAX( 0._wp , SIGN( 1._wp , ht_i_1d(ji) - epsi20 ) )
             z_slope_s(ji) = rswitch * 2._wp * sm_i_1d(ji) / MAX( epsi20 , ht_i_1d(ji) )
          END DO
 
-         ! Weighting factor between zs_zero and zs_inf
-         !---------------------------------------------
-         zfac0 = 1._wp / ( zsi0 - zsi1 )
-         zfac1 = zsi1 / ( zsi1 - zsi0 )
+         z1_dS = 1._wp / ( zsi1 - zsi0 )
          DO jk = 1, nlay_i
             DO ji = 1, nidx
-               ! zswi0 = 1 if sm_i le zsi0 and 0 otherwise
-               zswi0  = MAX( 0._wp , SIGN( 1._wp  , zsi0 - sm_i_1d(ji) ) ) 
-               ! zswi01 = 1 if sm_i is between zsi0 and zsi1 and 0 othws 
-               zswi01 = ( 1._wp - zswi0 ) * MAX( 0._wp , SIGN( 1._wp , zsi1 - sm_i_1d(ji) ) ) 
-               ! if 2.sm_i GE sss_m then rswitch = 1
-               ! this is to force a constant salinity profile in the Baltic Sea
-               rswitch = MAX( 0._wp , SIGN( 1._wp , 2._wp * sm_i_1d(ji) - sss_1d(ji) ) )
+               zalpha = MAX(  0._wp , MIN(  ( zsi1 - sm_i_1d(ji) ) * z1_dS , 1._wp  )  )
+               IF( 2._wp * sm_i_1d(ji) >= sss_1d(ji) )   zalpha = 0._wp               ! cst profile when SSS too low (Baltic Sea)
                !
-               zalpha = (  zswi0 + zswi01 * ( sm_i_1d(ji) * zfac0 + zfac1 )  ) * ( 1._wp - rswitch )
-               !
-               zs_zero = z_slope_s(ji) * ( REAL(jk,wp) - 0.5_wp ) * ht_i_1d(ji) * r1_nlay_i
-               ! weighting the profile
-               s_i_1d(ji,jk) = zalpha * zs_zero + ( 1._wp - zalpha ) * sm_i_1d(ji)
-               ! bounding salinity
-               s_i_1d(ji,jk) = MIN( rn_simax, MAX( s_i_1d(ji,jk), rn_simin ) )
-            END DO 
-         END DO 
-
-      ENDIF 
-
-      !-------------------------------------------------------
-      ! Vertically varying salinity profile, constant in time
-      !-------------------------------------------------------
-
-      IF( nn_icesal == 3 ) THEN      ! Schwarzacher (1959) multiyear salinity profile (mean = 2.30)
+               zs0 = z_slope_s(ji) * ( REAL(jk,wp) - 0.5_wp ) * ht_i_1d(ji) * r1_nlay_i   ! linear profile with 0 surface value
+               zs  = zalpha * zs0 + ( 1._wp - zalpha ) * sm_i_1d(ji)                      ! weighting the profile
+               s_i_1d(ji,jk) = MIN( rn_simax , MAX( zs , rn_simin ) )                     ! bounding salinity
+            END DO
+         END DO
+         !
+         DEALLOCATE( z_slope_s )
+
+         !           !-------------------------------------------!
+      CASE( 3 )      ! constant salinity with a fix profile      ! (Schwarzacher (1959) multiyear salinity profile
+         !           !-------------------------------------------!                                   (mean = 2.30)
          !
          sm_i_1d(:) = 2.30_wp
          !
+!!gm cf remark in ice_var_salprof routine, CASE( 3 )
          DO jk = 1, nlay_i
             zargtemp  = ( REAL(jk,wp) - 0.5_wp ) * r1_nlay_i
@@ -503,7 +472,8 @@
          END DO
          !
-      ENDIF
+      END SELECT
       !
    END SUBROUTINE ice_var_salprof1d
+
 
    SUBROUTINE ice_var_zapsmall
@@ -512,12 +482,11 @@
       !!
       !! ** Purpose :   Remove too small sea ice areas and correct fluxes
-      !!
-      !! history : LIM3.5 - 01-2014 (C. Rousset) original code
       !!-------------------------------------------------------------------
       INTEGER  ::   ji, jj, jl, jk   ! dummy loop indices
       REAL(wp) ::   zsal, zvi, zvs, zei, zes, zvp
       !!-------------------------------------------------------------------
-      DO jl = 1, jpl
-
+      !
+      DO jl = 1, jpl       !==  loop over the categories  ==!
+         !
          !-----------------------------------------------------------------
          ! Zap ice energy and use ocean heat to melt ice
@@ -526,4 +495,5 @@
             DO jj = 1 , jpj
                DO ji = 1 , jpi
+!!gm I think we can do better/faster  :  to be discussed
                   rswitch          = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi10 ) )
                   rswitch          = MAX( 0._wp , SIGN( 1._wp, v_i(ji,jj,jl) - epsi10 ) ) * rswitch
@@ -588,10 +558,12 @@
 
       ! to be sure that at_i is the sum of a_i(jl)
-      at_i (:,:) = 0._wp
-      DO jl = 1, jpl
+      at_i (:,:) = a_i(:,:,1)
+	  vt_i (:,:) = v_i(:,:,1)
+      DO jl = 2, jpl
          at_i(:,:) = at_i(:,:) + a_i(:,:,jl)
+	     vt_i(:,:) = vt_i(:,:) + v_i(:,:,jl)
       END DO
 
-      ! open water = 1 if at_i=0
+      ! open water = 1 if at_i=0 (no re-calculation of ato_i here)
       DO jj = 1, jpj
          DO ji = 1, jpi
@@ -600,7 +572,7 @@
          END DO
       END DO
-
       !
    END SUBROUTINE ice_var_zapsmall
+
 
    SUBROUTINE ice_var_itd( zhti, zhts, zai, zht_i, zht_s, za_i )
@@ -633,10 +605,5 @@
       !!
       !!  (Example of application: BDY forcings when input are cell averaged)  
-      !!
       !!-------------------------------------------------------------------
-      !! History : LIM3.5 - 2012    (M. Vancoppenolle)  Original code
-      !!                    2014    (C. Rousset)        Rewriting
-      !!-------------------------------------------------------------------
-      !! Local variables
       INTEGER  :: ji, jk, jl             ! dummy loop indices
       INTEGER  :: ijpij, i_fill, jl0  
@@ -645,9 +612,10 @@
       REAL(wp), DIMENSION(:,:), INTENT(inout) ::   zht_i, zht_s, za_i ! output ice/snow variables
       INTEGER , DIMENSION(4)                  ::   itest
- 
+      !!-------------------------------------------------------------------
+
       !--------------------------------------------------------------------
       ! initialisation of variables
       !--------------------------------------------------------------------
-      ijpij = SIZE(zhti,1)
+      ijpij = SIZE( zhti , 1 )
       zht_i(1:ijpij,1:jpl) = 0._wp
       zht_s(1:ijpij,1:jpl) = 0._wp
@@ -766,9 +734,8 @@
                zht_s(ji,jl) = MAX( 0._wp, zht_s(ji,jl) - zdh * rhoic * r1_rhosn )
             ENDIF
-         ENDDO
-      ENDDO
+         END DO
+      END DO
       !
     END SUBROUTINE ice_var_itd
-
 
 #else
@@ -776,7 +743,4 @@
    !!   Default option         Dummy module          NO  LIM3 sea-ice model
    !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE ice_var_itd
-   END SUBROUTINE ice_var_itd
 #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 8485)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icewri.F90	(revision 8486)
@@ -8,31 +8,31 @@
    !!   'key_lim3'                                      LIM3 sea-ice model
    !!----------------------------------------------------------------------
-   !!   ice_wri      : write of the diagnostics variables in ouput file 
+   !!   ice_wri       : write of the diagnostics variables in ouput file 
    !!   ice_wri_state : write for initial state or/and abandon
    !!----------------------------------------------------------------------
-   USE ioipsl
-   USE dianam          ! build name of file (routine)
-   USE phycst
-   USE dom_oce
-   USE sbc_oce
-   USE sbc_ice         ! Surface boundary condition: ice fields
-   USE ice
-   USE icevar
+   USE dianam         ! build name of file (routine)
+   USE phycst         ! physical constant
+   USE dom_oce        ! domain: ocean
+   USE sbc_oce        ! surf. boundary cond.: ocean
+   USE sbc_ice        ! Surface boundary condition: ice fields
+   USE ice            ! sea-ice: variables
+   USE icevar         ! sea-ice: operations
    !
-   USE in_out_manager
-   USE lbclnk
-   USE lib_mpp         ! MPP library
-   USE iom
-   USE timing          ! Timing
-   USE lib_fortran     ! Fortran utilities
+   USE ioipsl         !
+   USE in_out_manager !
+   USE lbclnk         !
+   USE lib_mpp        ! MPP library
+   USE iom            !
+   USE timing         ! Timing
+   USE lib_fortran    ! Fortran utilities
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC ice_wri        ! routine called by lim_step.F90
+   PUBLIC ice_wri        ! called by ice_stp
    PUBLIC ice_wri_state  ! called by dia_wri_state 
 
    !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! NEMO/ICE 4.0 , NEMO Consortium (2017)
    !! $Id: icewri.F90 8409 2017-08-07 15:29:21Z clem $
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -55,21 +55,16 @@
       REAL(wp) ::  z2da, z2db, ztmp, zrho1, zrho2, zmiss_val
       REAL(wp) ::  zs12, zshear
+      REAL(wp), DIMENSION(jpi,jpj)     ::  z2d, zswi, zmiss !  2D workspace
+      REAL(wp), DIMENSION(jpi,jpj)     ::  zfb              ! ice freeboard
+      REAL(wp), DIMENSION(jpi,jpj)     ::  zamask, zamask15 ! 15% concentration mask
+      REAL(wp), DIMENSION(jpi,jpj)     ::  zsig1, zsig2, zsig3
       REAL(wp), DIMENSION(jpi,jpj,jpl) ::  zswi2, zmiss2
-      REAL(wp), DIMENSION(jpi,jpj)   ::  z2d, zswi, zmiss !  2D workspace
-      REAL(wp), DIMENSION(jpi,jpj)   ::  zfb              ! ice freeboard
-      REAL(wp), DIMENSION(jpi,jpj)   ::  zamask, zamask15 ! 15% concentration mask
-      REAL(wp), DIMENSION(jpi,jpj)   ::  zsig1, zsig2, zsig3
-
+      !
       ! Global ice diagnostics (SIMIP)
-      REAL(wp) ::  zdiag_area_nh, &   ! area, extent, volume
-         &         zdiag_extt_nh, &
-         &         zdiag_area_sh, & 
-         &         zdiag_extt_sh, & 
-         &         zdiag_volu_nh, & 
-         &         zdiag_volu_sh 
-
+      REAL(wp) ::  zdiag_area_nh, zdiag_extt_nh, zdiag_volu_nh   ! area, extent, volume
+      REAL(wp) ::  zdiag_area_sh, zdiag_extt_sh, zdiag_volu_sh 
       !!-------------------------------------------------------------------
 
-      IF( nn_timing == 1 )  CALL timing_start('icewri')
+      IF( nn_timing == 1 )   CALL timing_start('icewri')
 
       !----------------------------------------
@@ -77,6 +72,5 @@
       !----------------------------------------
 
-      ! brine volume
-      CALL ice_var_bv 
+      CALL ice_var_bv      ! brine volume
 
       ! tresholds for outputs
@@ -96,7 +90,7 @@
       END DO
 
-      zmiss_val     = 1.0e20
-      zmiss(:,:)    = zmiss_val * ( 1. - zswi(:,:) )
-      zmiss2(:,:,:) = zmiss_val * ( 1. - zswi2(:,:,:) )
+      zmiss_val     = 1.e20_wp
+      zmiss (:,:)   = zmiss_val * ( 1._wp - zswi (:,:) )
+      zmiss2(:,:,:) = zmiss_val * ( 1._wp - zswi2(:,:,:) )
 
       !----------------------------------------
@@ -112,32 +106,33 @@
       IF( iom_use('qt_ice' ) )   CALL iom_put( "qt_ice"  , SUM( ( qns_ice(:,:,:) + qsr_ice(:,:,:) )   &
          &                                                      * a_i_b(:,:,:), dim=3 ) + qemp_ice(:,:) )
+!!gm I don't understand the variable below.... why not multiplied by a_i_b or (1-a_i_b) ??? 
       IF( iom_use('qemp_oce') )  CALL iom_put( "qemp_oce" , qemp_oce(:,:) )  
       IF( iom_use('qemp_ice') )  CALL iom_put( "qemp_ice" , qemp_ice(:,:) )  
-      IF( iom_use('emp_oce' ) )  CALL iom_put( "emp_oce"  , emp_oce(:,:) )   ! emp over ocean (taking into account the snow blown away from the ice)
-      IF( iom_use('emp_ice' ) )  CALL iom_put( "emp_ice"  , emp_ice(:,:) )   ! emp over ice   (taking into account the snow blown away from the ice)
+      IF( iom_use('emp_oce' ) )  CALL iom_put( "emp_oce"  , emp_oce (:,:) )   ! emp over ocean (taking into account the snow blown away from the ice)
+      IF( iom_use('emp_ice' ) )  CALL iom_put( "emp_ice"  , emp_ice (:,:) )   ! emp over ice   (taking into account the snow blown away from the ice)
 
       ! velocity
-      IF ( iom_use('uice_ipa') ) CALL iom_put( "uice_ipa"     , u_ice      )       ! ice velocity u component
-      IF ( iom_use('vice_ipa') ) CALL iom_put( "vice_ipa"     , v_ice      )       ! ice velocity v component
-
-      IF ( ( iom_use( "icevel" ) ) .OR. ( iom_use( "icevel_mv" ) ) ) THEN 
+      IF( iom_use('uice_ipa') )  CALL iom_put( "uice_ipa" , u_ice         )   ! ice velocity u component
+      IF( iom_use('vice_ipa') )  CALL iom_put( "vice_ipa" , v_ice         )   ! ice velocity v component
+
+      IF( iom_use('icevel') .OR. iom_use('icevel_mv') ) THEN 
          DO jj = 2 , jpjm1
             DO ji = 2 , jpim1
-               z2da  = ( u_ice(ji,jj) * umask(ji,jj,1) + u_ice(ji-1,jj) * umask(ji-1,jj,1) ) * 0.5_wp
-               z2db  = ( v_ice(ji,jj) * vmask(ji,jj,1) + v_ice(ji,jj-1) * vmask(ji,jj-1,1) ) * 0.5_wp
-               z2d(ji,jj) = SQRT( z2da * z2da + z2db * z2db )
+               z2da  = ( u_ice(ji,jj) + u_ice(ji-1,jj) )
+               z2db  = ( v_ice(ji,jj) + v_ice(ji,jj-1) )
+               z2d(ji,jj) = O.5_wp * SQRT( z2da * z2da + z2db * z2db )
            END DO
          END DO
          CALL lbc_lnk( z2d, 'T', 1. )
-         IF ( iom_use( "icevel" )  )   CALL iom_put( "icevel"       , z2d        )                                            ! ice velocity module
-         IF ( iom_use( "icevel_mv" ) ) CALL iom_put( "icevel_mv"    , z2d(:,:) * zswi(:,:) + zmiss(:,:) )                     ! ice velocity module (missing value)
-      ENDIF
-
-      IF ( iom_use( "tau_icebfr" ) )    CALL iom_put( "tau_icebfr"  , tau_icebfr             )  ! ice friction with ocean bottom (landfast ice)  
-      !
-      IF ( iom_use( "miceage" ) )       CALL iom_put( "miceage"     , om_i * zswi * zamask15 )  ! mean ice age
-      IF ( iom_use( "micet" ) )         CALL iom_put( "micet"       , ( tm_i  - rt0 ) * zswi )  ! ice mean    temperature
-      IF ( iom_use( "icest" ) )         CALL iom_put( "icest"       , ( tm_su - rt0 ) * zswi )  ! ice surface temperature
-      IF ( iom_use( "icecolf" ) )       CALL iom_put( "icecolf"     , hicol                  )  ! frazil ice collection thickness
+         IF( iom_use('icevel'   ) )   CALL iom_put( "icevel"       , z2d        )                          ! ice velocity module
+         IF( iom_use('icevel_mv') )   CALL iom_put( "icevel_mv"    , z2d(:,:) * zswi(:,:) + zmiss(:,:) )   ! ice velocity module (missing value)
+      ENDIF
+
+      IF( iom_use('tau_icebfr') )     CALL iom_put( "tau_icebfr"  , tau_icebfr             )  ! ice friction with ocean bottom (landfast ice)  
+      !
+      IF( iom_use('miceage')  )       CALL iom_put( "miceage"     , om_i * zswi * zamask15 )  ! mean ice age
+      IF( iom_use('micet')    )       CALL iom_put( "micet"       , ( tm_i  - rt0 ) * zswi )  ! ice mean    temperature
+      IF( iom_use('icest')    )       CALL iom_put( "icest"       , ( tm_su - rt0 ) * zswi )  ! ice surface temperature
+      IF( iom_use('icecolf')  )       CALL iom_put( "icecolf"     , hicol                  )  ! frazil ice collection thickness
       !
       CALL iom_put( "isst"        , sst_m               )        ! sea surface temperature
@@ -149,5 +144,5 @@
       CALL iom_put( "isnowhc"     , et_s  * zswi        )        ! snow total heat content
       CALL iom_put( "ibrinv"      , bvm_i * zswi * 100. )        ! brine volume
-      CALL iom_put( "snowpre"     , sprecip * 86400.    )        ! snow precipitation 
+      CALL iom_put( "snowpre"     , sprecip * 86400.    )        ! snow precipitation [m/day]
       CALL iom_put( "micesalt"    , smt_i   * zswi      )        ! mean ice salinity
       CALL iom_put( "snowvol"     , vt_s    * zswi      )        ! snow volume
@@ -224,6 +219,7 @@
       CALL iom_put ('hfxspr'     , hfx_spr(:,:)         )   ! Heat content of snow precip 
 
+!!gm ====>>>>>  THIS should be moved in icerhg_evp    (generalize this everywhere it is possible and logic...)
       ! specific outputs for EVP rheology
-      IF( iom_use( "isig1" ) .OR. iom_use( "isig2" ) .OR. iom_use( "isig3" ) ) THEN
+      IF( iom_use('isig1') .OR. iom_use('isig2') .OR. iom_use('isig3') ) THEN
          zsig1(:,:) = 0._wp; zsig2(:,:) = 0._wp; zsig3(:,:) = 0._wp;
          DO jj = 2, jpjm1
@@ -251,5 +247,7 @@
          CALL iom_put( "isig3" , zsig3 )
       ENDIF
-
+!!gm  <<<<<<======= end
+
+!!gm ====>>>>>  THIS should be moved where at_ip, vt_ip are computed fro the last time in the time-step  (limmpd)
       ! MV MP 2016
       IF ( ln_pnd ) THEN
@@ -258,27 +256,24 @@
       ENDIF
       ! END MV MP 2016
+!!gm  <<<<<<======= end
 
       !----------------------------------
       ! Output category-dependent fields
       !----------------------------------
-      IF ( iom_use( "iceconc_cat"  ) )  CALL iom_put( "iceconc_cat"      , a_i   * zswi2   )        ! area for categories
-      IF ( iom_use( "icethic_cat"  ) )  CALL iom_put( "icethic_cat"      , ht_i  * zswi2   )        ! thickness for categories
-      IF ( iom_use( "snowthic_cat" ) )  CALL iom_put( "snowthic_cat"     , ht_s  * zswi2   )        ! snow depth for categories
-      IF ( iom_use( "salinity_cat" ) )  CALL iom_put( "salinity_cat"     , sm_i  * zswi2   )        ! salinity for categories
-      ! ice temperature
-      IF ( iom_use( "icetemp_cat"  ) )  CALL iom_put( "icetemp_cat", ( SUM( t_i(:,:,:,:), dim=3 ) * r1_nlay_i - rt0 ) * zswi2 )
-      ! snow temperature
-      IF ( iom_use( "snwtemp_cat"  ) )  CALL iom_put( "snwtemp_cat", ( SUM( t_s(:,:,:,:), dim=3 ) * r1_nlay_s - rt0 ) * zswi2 )
-      ! ice age
-      IF ( iom_use( "iceage_cat"   ) )  CALL iom_put( "iceage_cat" , o_i * zswi2 ) 
-      ! brine volume
-      IF ( iom_use( "brinevol_cat" ) )  CALL iom_put( "brinevol_cat", bv_i * 100. * zswi2 )
+      IF ( iom_use('iceconc_cat' ) )  CALL iom_put( "iceconc_cat"      , a_i   * zswi2   )        ! area for categories
+      IF ( iom_use('icethic_cat' ) )  CALL iom_put( "icethic_cat"      , ht_i  * zswi2   )        ! thickness for categories
+      IF ( iom_use('snowthic_cat') )  CALL iom_put( "snowthic_cat"     , ht_s  * zswi2   )        ! snow depth for categories
+      IF ( iom_use('salinity_cat') )  CALL iom_put( "salinity_cat"     , sm_i  * zswi2   )        ! salinity for categories
+      IF ( iom_use('icetemp_cat' ) )  CALL iom_put( "icetemp_cat", ( SUM( t_i(:,:,:,:), dim=3 ) * r1_nlay_i - rt0 ) * zswi2 )    ! ice temperature
+      IF ( iom_use('snwtemp_cat' ) )  CALL iom_put( "snwtemp_cat", ( SUM( t_s(:,:,:,:), dim=3 ) * r1_nlay_s - rt0 ) * zswi2 )    ! snow temperature
+      IF ( iom_use('iceage_cat'  ) )  CALL iom_put( "iceage_cat" , o_i * zswi2 )                   ! ice age
+      IF ( iom_use('brinevol_cat') )  CALL iom_put( "brinevol_cat", bv_i * 100. * zswi2 )          ! brine volume
 
       ! MV MP 2016
       IF ( ln_pnd ) THEN
-         IF ( iom_use( "iceamp_cat"  ) )  CALL iom_put( "iceamp_cat"     , a_ip       * zswi2   )       ! melt pond frac for categories
-         IF ( iom_use( "icevmp_cat"  ) )  CALL iom_put( "icevmp_cat"     , v_ip       * zswi2   )       ! melt pond frac for categories
-         IF ( iom_use( "icehmp_cat"  ) )  CALL iom_put( "icehmp_cat"     , h_ip       * zswi2   )       ! melt pond frac for categories
-         IF ( iom_use( "iceafp_cat"  ) )  CALL iom_put( "iceafp_cat"     , a_ip_frac  * zswi2   )       ! melt pond frac for categories
+         IF ( iom_use('iceamp_cat') )  CALL iom_put( "iceamp_cat"     , a_ip       * zswi2   )       ! melt pond frac for categories
+         IF ( iom_use('icevmp_cat') )  CALL iom_put( "icevmp_cat"     , v_ip       * zswi2   )       ! melt pond frac for categories
+         IF ( iom_use('icehmp_cat') )  CALL iom_put( "icehmp_cat"     , h_ip       * zswi2   )       ! melt pond frac for categories
+         IF ( iom_use('iceafp_cat') )  CALL iom_put( "iceafp_cat"     , a_ip_frac  * zswi2   )       ! melt pond frac for categories
       ENDIF
       ! END MV MP 2016
@@ -289,140 +284,137 @@
       zrho1 = ( rau0 - rhoic ) / rau0; zrho2 = rhosn / rau0
 
-      IF  ( iom_use( "icepres"  ) ) CALL iom_put( "icepres"     , zswi(:,:)                     )                                ! Ice presence (1 or 0) 
-      IF  ( iom_use( "icemass"  ) ) CALL iom_put( "icemass"     , rhoic * vt_i(:,:) * zswi(:,:) )                                ! Ice mass per cell area 
-      IF  ( iom_use( "icethic"  ) ) CALL iom_put( "icethic"     , htm_i(:,:) * zamask(:,:)  + ( 1. - zamask(:,:) ) * zmiss_val )     ! Ice thickness 
-      IF  ( iom_use( "snomass"  ) ) CALL iom_put( "snomass"     , rhosn * vt_s(:,:)         * zswi(:,:) + zmiss(:,:) )           ! Snow mass per cell area
-      IF  ( iom_use( "snothic"  ) ) CALL iom_put( "snothic"     , htm_s(:,:) * zamask(:,:)  + ( 1. - zamask(:,:) ) * zmiss_val )     ! Snow thickness       
-
-      IF  ( iom_use( "iceconc_cat_mv"  ) )  CALL iom_put( "iceconc_cat_mv" , a_i(:,:,:)  * zswi2(:,:,:) + zmiss2(:,:,:) )        ! Area for categories
-      IF  ( iom_use( "icethic_cat_mv"  ) )  CALL iom_put( "icethic_cat_mv" , ht_i(:,:,:) * zswi2(:,:,:) + zmiss2(:,:,:) )        ! Thickness for categories
-      IF  ( iom_use( "snowthic_cat_mv" ) )  CALL iom_put( "snowthic_cat_mv", ht_s(:,:,:) * zswi2(:,:,:) + zmiss2(:,:,:) )        ! Snow depth for categories
-
-      IF  ( iom_use( "icestK"   ) ) CALL iom_put( "icestK"      , tm_su(:,:)                * zswi(:,:) + zmiss(:,:) )           ! Ice surface temperature
-      IF  ( iom_use( "icesntK"  ) ) CALL iom_put( "icesntK"     , tm_si(:,:)                * zswi(:,:) + zmiss(:,:) )           ! Snow-ice interface temperature
-      IF  ( iom_use( "icebotK"  ) ) CALL iom_put( "icebotK"     , t_bo(:,:)                 * zswi(:,:) + zmiss(:,:) )           ! Ice bottom temperature
-      IF  ( iom_use( "iceage"   ) ) CALL iom_put( "iceage"      , om_i(:,:) * zamask15(:,:) + ( 1. - zamask15(:,:) ) * zmiss_val )   ! Ice age
-      IF  ( iom_use( "icesmass" ) ) CALL iom_put( "icesmass"    , SUM( smv_i, DIM = 3 ) * rhoic * 1.0e-3 * zswi(:,:) )           ! Mass of salt in sea ice per cell area
-      IF  ( iom_use( "icesal"   ) ) CALL iom_put( "icesal"      , smt_i(:,:)                * zswi(:,:) + zmiss(:,:) )           ! Ice salinity
-
-      IF  ( iom_use( "icefb"    ) ) THEN
+      IF ( iom_use( "icepres"  ) ) CALL iom_put( "icepres"     , zswi(:,:)                     )                                ! Ice presence (1 or 0) 
+      IF ( iom_use( "icemass"  ) ) CALL iom_put( "icemass"     , rhoic * vt_i(:,:) * zswi(:,:) )                                ! Ice mass per cell area 
+      IF ( iom_use( "icethic"  ) ) CALL iom_put( "icethic"     , htm_i(:,:) * zamask(:,:)  + ( 1. - zamask(:,:) ) * zmiss_val )     ! Ice thickness 
+      IF ( iom_use( "snomass"  ) ) CALL iom_put( "snomass"     , rhosn * vt_s(:,:)         * zswi(:,:) + zmiss(:,:) )           ! Snow mass per cell area
+      IF ( iom_use( "snothic"  ) ) CALL iom_put( "snothic"     , htm_s(:,:) * zamask(:,:)  + ( 1. - zamask(:,:) ) * zmiss_val )     ! Snow thickness       
+
+      IF ( iom_use( "iceconc_cat_mv"  ) )  CALL iom_put( "iceconc_cat_mv" , a_i(:,:,:)  * zswi2(:,:,:) + zmiss2(:,:,:) )        ! Area for categories
+      IF ( iom_use( "icethic_cat_mv"  ) )  CALL iom_put( "icethic_cat_mv" , ht_i(:,:,:) * zswi2(:,:,:) + zmiss2(:,:,:) )        ! Thickness for categories
+      IF ( iom_use( "snowthic_cat_mv" ) )  CALL iom_put( "snowthic_cat_mv", ht_s(:,:,:) * zswi2(:,:,:) + zmiss2(:,:,:) )        ! Snow depth for categories
+
+      IF ( iom_use( "icestK"   ) ) CALL iom_put( "icestK"      , tm_su(:,:)                * zswi(:,:) + zmiss(:,:) )           ! Ice surface temperature
+      IF ( iom_use( "icesntK"  ) ) CALL iom_put( "icesntK"     , tm_si(:,:)                * zswi(:,:) + zmiss(:,:) )           ! Snow-ice interface temperature
+      IF ( iom_use( "icebotK"  ) ) CALL iom_put( "icebotK"     , t_bo(:,:)                 * zswi(:,:) + zmiss(:,:) )           ! Ice bottom temperature
+      IF ( iom_use( "iceage"   ) ) CALL iom_put( "iceage"      , om_i(:,:) * zamask15(:,:) + ( 1. - zamask15(:,:) ) * zmiss_val )   ! Ice age
+      IF ( iom_use( "icesmass" ) ) CALL iom_put( "icesmass"    , SUM( smv_i, DIM = 3 ) * rhoic * 1.0e-3 * zswi(:,:) )           ! Mass of salt in sea ice per cell area
+      IF ( iom_use( "icesal"   ) ) CALL iom_put( "icesal"      , smt_i(:,:)                * zswi(:,:) + zmiss(:,:) )           ! Ice salinity
+
+      IF ( iom_use( "icefb"    ) ) THEN
          zfb(:,:) = ( zrho1 * htm_i(:,:) - zrho2 * htm_s(:,:) )                                         
          WHERE( zfb < 0._wp ) ;   zfb = 0._wp ;   END WHERE
-                                    CALL iom_put( "icefb"       , zfb(:,:)                  * zswi(:,:) + zmiss(:,:) )           ! Ice freeboard
-      ENDIF
-
-      IF  ( iom_use( "isnhcneg" ) ) CALL iom_put( "isnhcneg"    , - et_s(:,:)               * zswi(:,:) + zmiss(:,:) )           ! Snow total heat content
-
-      IF  ( iom_use( "dmithd"   ) ) CALL iom_put( "dmithd"      , - wfx_bog - wfx_bom - wfx_sum   &                       ! Sea-ice mass change from thermodynamics
-              &                     - wfx_sni - wfx_opw - wfx_res )
-      IF  ( iom_use( "dmidyn"   ) ) CALL iom_put( "dmidyn"      ,   diag_dmi_dyn             )                            ! Sea-ice mass change from dynamics
-      IF  ( iom_use( "dmiopw"   ) ) CALL iom_put( "dmiopw"      , - wfx_opw                  )                            ! Sea-ice mass change through growth in open water
-      IF  ( iom_use( "dmibog"   ) ) CALL iom_put( "dmibog"      , - wfx_bog                  )                            ! Sea-ice mass change through basal growth
-      IF  ( iom_use( "dmisni"   ) ) CALL iom_put( "dmisni"      , - wfx_sni                  )                            ! Sea-ice mass change through snow-to-ice conversion
-      IF  ( iom_use( "dmisum"   ) ) CALL iom_put( "dmisum"      , - wfx_sum                  )                            ! Sea-ice mass change through surface melting
-      IF  ( iom_use( "dmibom"   ) ) CALL iom_put( "dmibom"      , - wfx_bom                  )                            ! Sea-ice mass change through bottom melting
-
-      IF  ( iom_use( "dmtsub"   ) ) CALL iom_put( "dmtsub"      , - wfx_sub                  )                            ! Sea-ice mass change through evaporation and sublimation
-      IF  ( iom_use( "dmssub"   ) ) CALL iom_put( "dmssub"      , - wfx_snw_sub              )                            ! Snow mass change through sublimation
-      IF  ( iom_use( "dmisub"   ) ) CALL iom_put( "dmisub"      , - wfx_ice_sub              )                            ! Sea-ice mass change through sublimation
-
-      IF  ( iom_use( "dmsspr"   ) ) CALL iom_put( "dmsspr"      , - wfx_spr                  )                            ! Snow mass change through snow fall
-      IF  ( iom_use( "dmsssi"   ) ) CALL iom_put( "dmsssi"      ,   wfx_sni*rhosn/rhoic      )                            ! Snow mass change through snow-to-ice conversion
-
-      IF  ( iom_use( "dmsmel"   ) ) CALL iom_put( "dmsmel"      , - wfx_snw_sum              )                            ! Snow mass change through melt
-      IF  ( iom_use( "dmsdyn"   ) ) CALL iom_put( "dmsdyn"      ,   diag_dms_dyn             )                            ! Snow mass change through dynamics
-
-      IF  ( iom_use( "hfxsenso" ) ) CALL iom_put( "hfxsenso"    ,   -fhtur(:,:)              * zswi(:,:) + zmiss(:,:) )   ! Sensible oceanic heat flux
-      IF  ( iom_use( "hfxconbo" ) ) CALL iom_put( "hfxconbo"    ,   diag_fc_bo               * zswi(:,:) + zmiss(:,:) )   ! Bottom conduction flux
-      IF  ( iom_use( "hfxconsu" ) ) CALL iom_put( "hfxconsu"    ,   diag_fc_su               * zswi(:,:) + zmiss(:,:) )   ! Surface conduction flux
-
-      IF  ( iom_use( "wfxtot"   ) ) CALL iom_put( "wfxtot"      ,   wfx_ice(:,:)             * zswi(:,:) + zmiss(:,:) )   ! Total freshwater flux from sea ice
-      IF  ( iom_use( "wfxsum"   ) ) CALL iom_put( "wfxsum"      ,   wfx_sum(:,:)             * zswi(:,:) + zmiss(:,:) )   ! Freshwater flux from sea-ice surface
-      IF  ( iom_use( "sfx_mv"   ) ) CALL iom_put( "sfx_mv"      ,   sfx(:,:) * 0.001         * zswi(:,:) + zmiss(:,:) )   ! Total salt flux
-
-      IF  ( iom_use( "uice_mv"  ) ) CALL iom_put( "uice_mv"     ,   u_ice(:,:)               * zswi(:,:) + zmiss(:,:) )   ! ice velocity u component
-      IF  ( iom_use( "vice_mv"  ) ) CALL iom_put( "vice_mv"     ,   v_ice(:,:)               * zswi(:,:) + zmiss(:,:) )   ! ice velocity v component
+                                   CALL iom_put( "icefb"       , zfb(:,:)                  * zswi(:,:) + zmiss(:,:) )           ! Ice freeboard
+      ENDIF
+
+      IF ( iom_use( "isnhcneg" ) ) CALL iom_put( "isnhcneg"    , - et_s(:,:)               * zswi(:,:) + zmiss(:,:) )           ! Snow total heat content
+
+      IF ( iom_use( "dmithd"   ) ) CALL iom_put( "dmithd"      , - wfx_bog - wfx_bom - wfx_sum   &                       ! Sea-ice mass change from thermodynamics
+              &                                                   - wfx_sni - wfx_opw - wfx_res )
+      IF ( iom_use( "dmidyn"   ) ) CALL iom_put( "dmidyn"      ,   diag_dmi_dyn             )                            ! Sea-ice mass change from dynamics
+      IF ( iom_use( "dmiopw"   ) ) CALL iom_put( "dmiopw"      , - wfx_opw                  )                            ! Sea-ice mass change through growth in open water
+      IF ( iom_use( "dmibog"   ) ) CALL iom_put( "dmibog"      , - wfx_bog                  )                            ! Sea-ice mass change through basal growth
+      IF ( iom_use( "dmisni"   ) ) CALL iom_put( "dmisni"      , - wfx_sni                  )                            ! Sea-ice mass change through snow-to-ice conversion
+      IF ( iom_use( "dmisum"   ) ) CALL iom_put( "dmisum"      , - wfx_sum                  )                            ! Sea-ice mass change through surface melting
+      IF ( iom_use( "dmibom"   ) ) CALL iom_put( "dmibom"      , - wfx_bom                  )                            ! Sea-ice mass change through bottom melting
+
+      IF ( iom_use( "dmtsub"   ) ) CALL iom_put( "dmtsub"      , - wfx_sub                  )                            ! Sea-ice mass change through evaporation and sublimation
+      IF ( iom_use( "dmssub"   ) ) CALL iom_put( "dmssub"      , - wfx_snw_sub              )                            ! Snow mass change through sublimation
+      IF ( iom_use( "dmisub"   ) ) CALL iom_put( "dmisub"      , - wfx_ice_sub              )                            ! Sea-ice mass change through sublimation
+
+      IF ( iom_use( "dmsspr"   ) ) CALL iom_put( "dmsspr"      , - wfx_spr                  )                            ! Snow mass change through snow fall
+      IF ( iom_use( "dmsssi"   ) ) CALL iom_put( "dmsssi"      ,   wfx_sni*rhosn/rhoic      )                            ! Snow mass change through snow-to-ice conversion
+
+      IF ( iom_use( "dmsmel"   ) ) CALL iom_put( "dmsmel"      , - wfx_snw_sum              )                            ! Snow mass change through melt
+      IF ( iom_use( "dmsdyn"   ) ) CALL iom_put( "dmsdyn"      ,   diag_dms_dyn             )                            ! Snow mass change through dynamics
+
+      IF ( iom_use( "hfxsenso" ) ) CALL iom_put( "hfxsenso"    ,   -fhtur(:,:)              * zswi(:,:) + zmiss(:,:) )   ! Sensible oceanic heat flux
+      IF ( iom_use( "hfxconbo" ) ) CALL iom_put( "hfxconbo"    ,   diag_fc_bo               * zswi(:,:) + zmiss(:,:) )   ! Bottom conduction flux
+      IF ( iom_use( "hfxconsu" ) ) CALL iom_put( "hfxconsu"    ,   diag_fc_su               * zswi(:,:) + zmiss(:,:) )   ! Surface conduction flux
+
+      IF ( iom_use( "wfxtot"   ) ) CALL iom_put( "wfxtot"      ,   wfx_ice(:,:)             * zswi(:,:) + zmiss(:,:) )   ! Total freshwater flux from sea ice
+      IF ( iom_use( "wfxsum"   ) ) CALL iom_put( "wfxsum"      ,   wfx_sum(:,:)             * zswi(:,:) + zmiss(:,:) )   ! Freshwater flux from sea-ice surface
+      IF ( iom_use( "sfx_mv"   ) ) CALL iom_put( "sfx_mv"      ,   sfx(:,:) * 0.001         * zswi(:,:) + zmiss(:,:) )   ! Total salt flux
+
+      IF ( iom_use( "uice_mv"  ) ) CALL iom_put( "uice_mv"     ,   u_ice(:,:)               * zswi(:,:) + zmiss(:,:) )   ! ice velocity u component
+      IF ( iom_use( "vice_mv"  ) ) CALL iom_put( "vice_mv"     ,   v_ice(:,:)               * zswi(:,:) + zmiss(:,:) )   ! ice velocity v component
       
-      IF  ( iom_use( "xmtrpice" ) ) CALL iom_put( "xmtrpice"     ,  diag_xmtrp_ice(:,:)      )                            ! X-component of sea-ice mass transport (kg/s)
-      IF  ( iom_use( "ymtrpice" ) ) CALL iom_put( "ymtrpice"     ,  diag_ymtrp_ice(:,:)      )                            ! Y-component of sea-ice mass transport 
-
-      IF  ( iom_use( "xmtrpsnw" ) ) CALL iom_put( "xmtrpsnw"     ,  diag_xmtrp_snw(:,:)      )                            ! X-component of snow mass transport (kg/s)
-      IF  ( iom_use( "ymtrpsnw" ) ) CALL iom_put( "ymtrpsnw"     ,  diag_ymtrp_snw(:,:)      )                            ! Y-component of snow mass transport
-
-      IF  ( iom_use( "xatrp"    ) ) CALL iom_put( "xatrp"        ,  diag_xatrp(:,:)              )                        ! X-component of ice area transport
-      IF  ( iom_use( "yatrp"    ) ) CALL iom_put( "yatrp"        ,  diag_yatrp(:,:)              )                        ! Y-component of ice area transport
-
-      IF  ( iom_use( "utau_ice" ) ) CALL iom_put( "utau_ice"     ,  utau_ice(:,:)            * zswi(:,:) + zmiss(:,:) )   ! Wind stress term in force balance (x)
-      IF  ( iom_use( "vtau_ice" ) ) CALL iom_put( "vtau_ice"     ,  vtau_ice(:,:)            * zswi(:,:) + zmiss(:,:) )   ! Wind stress term in force balance (y)
-
-      IF  ( iom_use( "utau_oi"  ) ) CALL iom_put( "utau_oi"     ,   diag_utau_oi(:,:)        * zswi(:,:) + zmiss(:,:) )   ! Ocean stress term in force balance (x)
-      IF  ( iom_use( "vtau_oi"  ) ) CALL iom_put( "vtau_oi"     ,   diag_vtau_oi(:,:)        * zswi(:,:) + zmiss(:,:) )   ! Ocean stress term in force balance (y)
-
-      IF  ( iom_use( "icestr"   ) ) CALL iom_put( "icestr"      ,   strength(:,:)            * zswi(:,:) + zmiss(:,:) )   ! Ice strength
-
-      IF  ( iom_use( "dssh_dx"  ) ) CALL iom_put( "dssh_dx"     ,   diag_dssh_dx(:,:)        * zswi(:,:) + zmiss(:,:) )   ! Sea-surface tilt term in force balance (x)
-      IF  ( iom_use( "dssh_dy"  ) ) CALL iom_put( "dssh_dy"     ,   diag_dssh_dy(:,:)        * zswi(:,:) + zmiss(:,:) )   ! Sea-surface tilt term in force balance (y)
-
-      IF  ( iom_use( "corstrx"  ) ) CALL iom_put( "corstrx"     ,   diag_corstrx(:,:)        * zswi(:,:) + zmiss(:,:) )   ! Coriolis force term in force balance (x)
-      IF  ( iom_use( "corstry"  ) ) CALL iom_put( "corstry"     ,   diag_corstry(:,:)        * zswi(:,:) + zmiss(:,:) )   ! Coriolis force term in force balance (y)
-
-      IF  ( iom_use( "intstrx"  ) ) CALL iom_put( "intstrx"     ,   diag_intstrx(:,:)        * zswi(:,:) + zmiss(:,:) )   ! Internal force term in force balance (x)
-      IF  ( iom_use( "intstry"  ) ) CALL iom_put( "intstry"     ,   diag_intstry(:,:)        * zswi(:,:) + zmiss(:,:) )   ! Internal force term in force balance (y)
-
-      IF  ( iom_use( "normstr"  ) ) CALL iom_put( "normstr"     ,   diag_sig1(:,:)           * zswi(:,:) + zmiss(:,:) )   ! Normal stress
-      IF  ( iom_use( "sheastr"  ) ) CALL iom_put( "sheastr"     ,   diag_sig2(:,:)           * zswi(:,:) + zmiss(:,:) )   ! Shear stress
+      IF ( iom_use( "xmtrpice" ) ) CALL iom_put( "xmtrpice"     ,  diag_xmtrp_ice(:,:)      )                            ! X-component of sea-ice mass transport (kg/s)
+      IF ( iom_use( "ymtrpice" ) ) CALL iom_put( "ymtrpice"     ,  diag_ymtrp_ice(:,:)      )                            ! Y-component of sea-ice mass transport 
+
+      IF ( iom_use( "xmtrpsnw" ) ) CALL iom_put( "xmtrpsnw"     ,  diag_xmtrp_snw(:,:)      )                            ! X-component of snow mass transport (kg/s)
+      IF ( iom_use( "ymtrpsnw" ) ) CALL iom_put( "ymtrpsnw"     ,  diag_ymtrp_snw(:,:)      )                            ! Y-component of snow mass transport
+
+      IF ( iom_use( "xatrp"    ) ) CALL iom_put( "xatrp"        ,  diag_xatrp(:,:)              )                        ! X-component of ice area transport
+      IF ( iom_use( "yatrp"    ) ) CALL iom_put( "yatrp"        ,  diag_yatrp(:,:)              )                        ! Y-component of ice area transport
+
+      IF ( iom_use( "utau_ice" ) ) CALL iom_put( "utau_ice"     ,  utau_ice(:,:)            * zswi(:,:) + zmiss(:,:) )   ! Wind stress term in force balance (x)
+      IF ( iom_use( "vtau_ice" ) ) CALL iom_put( "vtau_ice"     ,  vtau_ice(:,:)            * zswi(:,:) + zmiss(:,:) )   ! Wind stress term in force balance (y)
+
+      IF ( iom_use( "utau_oi"  ) ) CALL iom_put( "utau_oi"     ,   diag_utau_oi(:,:)        * zswi(:,:) + zmiss(:,:) )   ! Ocean stress term in force balance (x)
+      IF ( iom_use( "vtau_oi"  ) ) CALL iom_put( "vtau_oi"     ,   diag_vtau_oi(:,:)        * zswi(:,:) + zmiss(:,:) )   ! Ocean stress term in force balance (y)
+
+      IF ( iom_use( "icestr"   ) ) CALL iom_put( "icestr"      ,   strength(:,:)            * zswi(:,:) + zmiss(:,:) )   ! Ice strength
+
+      IF ( iom_use( "dssh_dx"  ) ) CALL iom_put( "dssh_dx"     ,   diag_dssh_dx(:,:)        * zswi(:,:) + zmiss(:,:) )   ! Sea-surface tilt term in force balance (x)
+      IF ( iom_use( "dssh_dy"  ) ) CALL iom_put( "dssh_dy"     ,   diag_dssh_dy(:,:)        * zswi(:,:) + zmiss(:,:) )   ! Sea-surface tilt term in force balance (y)
+
+      IF ( iom_use( "corstrx"  ) ) CALL iom_put( "corstrx"     ,   diag_corstrx(:,:)        * zswi(:,:) + zmiss(:,:) )   ! Coriolis force term in force balance (x)
+      IF ( iom_use( "corstry"  ) ) CALL iom_put( "corstry"     ,   diag_corstry(:,:)        * zswi(:,:) + zmiss(:,:) )   ! Coriolis force term in force balance (y)
+
+      IF ( iom_use( "intstrx"  ) ) CALL iom_put( "intstrx"     ,   diag_intstrx(:,:)        * zswi(:,:) + zmiss(:,:) )   ! Internal force term in force balance (x)
+      IF ( iom_use( "intstry"  ) ) CALL iom_put( "intstry"     ,   diag_intstry(:,:)        * zswi(:,:) + zmiss(:,:) )   ! Internal force term in force balance (y)
+
+      IF ( iom_use( "normstr"  ) ) CALL iom_put( "normstr"     ,   diag_sig1(:,:)           * zswi(:,:) + zmiss(:,:) )   ! Normal stress
+      IF ( iom_use( "sheastr"  ) ) CALL iom_put( "sheastr"     ,   diag_sig2(:,:)           * zswi(:,:) + zmiss(:,:) )   ! Shear stress
 
       !--------------------------------
       ! Global ice diagnostics (SIMIP)
       !--------------------------------
-
-      IF ( iom_use( "NH_icearea" ) .OR. iom_use( "NH_icevolu" ) .OR. iom_use( "NH_iceextt" ) )   THEN   ! NH integrated diagnostics
- 
-         WHERE( ff_t > 0._wp ); zswi(:,:) = 1.0e-12
-         ELSEWHERE            ; zswi(:,:) = 0.
+      !
+      IF ( iom_use( "NH_icearea" ) .OR. iom_use( "NH_icevolu" ) .OR. iom_use( "NH_iceextt" ) )   THEN   ! NH diagnostics
+         !
+         WHERE( ff_t > 0._wp )   ;   zswi(:,:) = 1.0e-12
+         ELSEWHERE               ;   zswi(:,:) = 0.
          END WHERE 
-
          zdiag_area_nh = glob_sum( at_i(:,:) * zswi(:,:) * e1e2t(:,:) )
          zdiag_volu_nh = glob_sum( vt_i(:,:) * zswi(:,:) * e1e2t(:,:) )
-
-         WHERE( ff_t > 0._wp .AND. at_i > 0.15 ); zswi(:,:) = 1.0e-12
-         ELSEWHERE                              ; zswi(:,:) = 0.
+         !
+         WHERE( ff_t > 0._wp .AND. at_i > 0.15 )   ; zswi(:,:) = 1.0e-12
+         ELSEWHERE                                 ; zswi(:,:) = 0.
          END WHERE 
-
          zdiag_extt_nh = glob_sum( zswi(:,:) * e1e2t(:,:) )
-
-         IF ( iom_use( "NH_icearea" ) ) CALL iom_put( "NH_icearea" ,  zdiag_area_nh  )
-         IF ( iom_use( "NH_icevolu" ) ) CALL iom_put( "NH_icevolu" ,  zdiag_volu_nh  )
-         IF ( iom_use( "NH_iceextt" ) ) CALL iom_put( "NH_iceextt" ,  zdiag_extt_nh  )
-
-      ENDIF
-
-      IF ( iom_use( "SH_icearea" ) .OR. iom_use( "SH_icevolu" ) .OR. iom_use( "SH_iceextt" ) )   THEN   ! SH integrated diagnostics
-
+         !
+         IF ( iom_use( "NH_icearea" ) )   CALL iom_put( "NH_icearea" ,  zdiag_area_nh  )
+         IF ( iom_use( "NH_icevolu" ) )   CALL iom_put( "NH_icevolu" ,  zdiag_volu_nh  )
+         IF ( iom_use( "NH_iceextt" ) )   CALL iom_put( "NH_iceextt" ,  zdiag_extt_nh  )
+         !
+      ENDIF
+      !
+      IF ( iom_use( "SH_icearea" ) .OR. iom_use( "SH_icevolu" ) .OR. iom_use( "SH_iceextt" ) )   THEN   ! SH diagnostics
+         !
          WHERE( ff_t < 0._wp ); zswi(:,:) = 1.0e-12; 
          ELSEWHERE            ; zswi(:,:) = 0.
          END WHERE 
-
          zdiag_area_sh = glob_sum( at_i(:,:) * zswi(:,:) * e1e2t(:,:) ) 
          zdiag_volu_sh = glob_sum( vt_i(:,:) * zswi(:,:) * e1e2t(:,:) )
-
+         !
          WHERE( ff_t < 0._wp .AND. at_i > 0.15 ); zswi(:,:) = 1.0e-12
          ELSEWHERE                              ; zswi(:,:) = 0.
          END WHERE 
-
          zdiag_extt_sh = glob_sum( zswi(:,:) * e1e2t(:,:) )
-
+         !
          IF ( iom_use( "SH_icearea" ) ) CALL iom_put( "SH_icearea", zdiag_area_sh )
          IF ( iom_use( "SH_icevolu" ) ) CALL iom_put( "SH_icevolu", zdiag_volu_sh )
          IF ( iom_use( "SH_iceextt" ) ) CALL iom_put( "SH_iceextt", zdiag_extt_sh )
-
+         !
       ENDIF 
-
-      !     !  Create an output files (output.lim.abort.nc) if S < 0 or u > 20 m/s
-      !     IF( kindic < 0 )   CALL ice_wri_state( 'output.abort' )
-      !     not yet implemented
-      
+      !
+!!CR      !     !  Create an output files (output.lim.abort.nc) if S < 0 or u > 20 m/s
+!!CR      !     IF( kindic < 0 )   CALL ice_wri_state( 'output.abort' )
+!!CR      !     not yet implemented
+!!gm  idem for the ocean...  Ask Seb how to get read of ioipsl....
+      !
       IF( nn_timing == 1 )  CALL timing_stop('icewri')
-      
+      !
    END SUBROUTINE ice_wri
 
@@ -437,6 +429,5 @@
       !!      ocean state in case of abnormal end of a simulation
       !!
-      !! History :
-      !!   4.0  !  2013-06  (C. Rousset)
+      !! History :   4.0  !  2013-06  (C. Rousset)
       !!----------------------------------------------------------------------
       INTEGER, INTENT( in )   ::   kt               ! ocean time-step index)
@@ -445,7 +436,8 @@
       REAL(wp), DIMENSION(jpl) :: jcat
       !!----------------------------------------------------------------------
+      !
       DO jl = 1, jpl
          jcat(jl) = REAL(jl)
-      ENDDO
+      END DO
       
       CALL histvert( kid, "ncatice", "Ice Categories","", jpl, jcat, nz_i, "up")
@@ -557,6 +549,7 @@
       ! Close the file
       ! -----------------
+!!gm I don't understand why the file is not closed !
       !CALL histclo( kid )
-
+      !
     END SUBROUTINE ice_wri_state
 
@@ -565,7 +558,4 @@
    !!   Default option :         Empty module          NO LIM sea-ice model
    !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE ice_wri          ! Empty routine
-   END SUBROUTINE ice_wri
 #endif
 
