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 8421)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/ice.F90	(revision 8422)
@@ -77,7 +77,6 @@
    !! - ice_adv : ice advection                                           |
    !! - ice_rdgrft : ice ridging and rafting                              |
-   !! - lim_thd : ice halo-thermodynamics                                 |
-   !! - lim_itd_th : thermodynamic changes in ice thickness distribution  |
-   !!                and creation of new ice                              |
+   !! - ice_thd : ice halo-thermodynamics and creation of new ice         |
+   !! - ice_itd : thermodynamic changes in ice thickness distribution     |
    !!                                                                     |
    !! See the associated routines for more information                    |
@@ -150,6 +149,4 @@
    !! bv_i        !      -      !    relative brine volume        | ???   | 
    !!=====================================================================
-
-   LOGICAL, PUBLIC ::   con_i = .false.   ! switch for conservation test
 
    !!--------------------------------------------------------------------------
@@ -221,5 +218,5 @@
 
    !                                     !!** ice-thermodynamics namelist (namicethd) **
-                                          ! -- limthd_dif -- !
+                                          ! -- icethd_dif -- !
    REAL(wp), PUBLIC ::   rn_kappa_i       !: coef. for the extinction of radiation Grenfell et al. (2006) [1/m]
    INTEGER , PUBLIC ::   nn_ice_thcon     !: thermal conductivity: =0 Untersteiner (1964) ; =1 Pringle et al (2007)
@@ -227,12 +224,12 @@
    INTEGER , PUBLIC ::   nn_monocat       !: virtual ITD mono-category parameterizations (1-4) or not (0)
    REAL(wp), PUBLIC ::   rn_cdsn          !: thermal conductivity of the snow [W/m/K]
-                                          ! -- limthd_dh -- !
+                                          ! -- icethd_dh -- !
    LOGICAL , PUBLIC ::   ln_limdH         !: activate ice thickness change from growing/melting (T) or not (F)
    REAL(wp), PUBLIC ::   rn_betas         !: coef. for partitioning of snowfall between leads and sea ice
-                                          ! -- limthd_da -- !
+                                          ! -- icethd_da -- !
    LOGICAL , PUBLIC ::   ln_limdA         !: activate lateral melting param. (T) or not (F)
    REAL(wp), PUBLIC ::   rn_beta          !: coef. beta for lateral melting param.
    REAL(wp), PUBLIC ::   rn_dmin          !: minimum floe diameter for lateral melting param.
-                                          ! -- limthd_lac -- !
+                                          ! -- icethd_lac -- !
    LOGICAL , PUBLIC ::   ln_limdO         !: activate ice growth in open-water (T) or not (F)
    REAL(wp), PUBLIC ::   rn_hnewice       !: thickness for new ice formation (m)
@@ -241,5 +238,5 @@
    REAL(wp), PUBLIC ::   rn_vfrazb        !: threshold drift speed for collection of bottom frazil ice
    REAL(wp), PUBLIC ::   rn_Cfrazb        !: squeezing coefficient for collection of bottom frazil ice
-                                          ! -- limitd_th -- !
+                                          ! -- iceitd -- !
    REAL(wp), PUBLIC ::   rn_himin         !: minimum ice thickness
 
@@ -366,5 +363,5 @@
 
    ! heat flux associated with ice-ocean mass exchange
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_thd     !: ice-ocean heat flux from thermo processes (limthd_dh) [W.m-2]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_thd     !: ice-ocean heat flux from thermo processes (icethd_dh) [W.m-2]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_dyn     !: ice-ocean heat flux from ridging                      [W.m-2]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hfx_res     !: residual heat flux due to correction of ice thickness [W.m-2]
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceerr1.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceerr1.F90	(revision 8421)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceerr1.F90	(revision 8422)
@@ -17,5 +17,5 @@
    USE ice
    USE ice1D           ! LIM thermodynamic sea-ice variables
-   USE limitd_th
+   USE iceitd
    USE limvar
    USE icecons         ! conservation tests
@@ -104,5 +104,5 @@
       ! Rebin categories with thickness out of bounds
       !----------------------------------------------------
-      IF ( jpl > 1 ) CALL lim_itd_th_reb
+      IF ( jpl > 1 ) CALL ice_itd_reb
 
       !-----------------
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceerr2.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceerr2.F90	(revision 8421)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceerr2.F90	(revision 8422)
@@ -16,6 +16,6 @@
    USE phycst          ! physical constants
    USE ice
-   USE ice1D         ! LIM thermodynamic sea-ice variables
-   USE limitd_th
+   USE ice1D           ! LIM thermodynamic sea-ice variables
+   USE iceitd
    USE limvar
    USE icecons         ! conservation tests
@@ -118,5 +118,5 @@
       ! Rebin categories with thickness out of bounds
       !----------------------------------------------------
-      IF ( jpl > 1 ) CALL lim_itd_th_reb
+      IF ( jpl > 1 ) CALL ice_itd_reb
 
       !-----------------
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceistate.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceistate.F90	(revision 8421)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceistate.F90	(revision 8422)
@@ -307,5 +307,5 @@
                   ! This case below should not be used if (ht_s/ht_i) is ok in namelist
                   ! In case snow load is in excess that would lead to transformation from snow to ice
-                  ! Then, transfer the snow excess into the ice (different from limthd_dh)
+                  ! Then, transfer the snow excess into the ice (different from icethd_dh)
                   zdh = MAX( 0._wp, ( rhosn * ht_s(ji,jj,jl) + ( rhoic - rau0 ) * ht_i(ji,jj,jl) ) * r1_rau0 ) 
                   ! recompute ht_i, ht_s avoiding out of bounds values
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 8422)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceitd.F90	(revision 8422)
@@ -0,0 +1,650 @@
+MODULE iceitd
+   !!======================================================================
+   !!                       ***  MODULE iceitd ***
+   !!   LIM3 ice model : ice thickness distribution: Thermodynamics
+   !!======================================================================
+   !! History :   -   !          (W. H. Lipscomb and E.C. Hunke) CICE (c) original code
+   !!            3.0  ! 2005-12  (M. Vancoppenolle) adaptation to LIM-3
+   !!             -   ! 2006-06  (M. Vancoppenolle) adaptation to include salt, age
+   !!             -   ! 2007-04  (M. Vancoppenolle) Mass conservation checked
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3' :                                   LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_itd_rem   :
+   !!   ice_itd_reb   :
+   !!   ice_itd_glinear  :
+   !!   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 limvar           ! LIM-3 variables
+   USE icecons          ! conservation tests
+   USE icetab
+   !
+   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
+   PRIVATE
+
+   PUBLIC   ice_itd_rem   ! called in icethd
+   PUBLIC   ice_itd_reb   ! called in iceerr
+
+   !!----------------------------------------------------------------------
+   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
+   !! $Id: iceitd.F90 8420 2017-08-08 12:18:46Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_itd_rem( kt )
+      !!------------------------------------------------------------------
+      !!                ***  ROUTINE ice_itd_rem ***
+      !!
+      !! ** Purpose :   computes the redistribution of ice thickness
+      !!              after thermodynamic growth of ice thickness
+      !!
+      !! ** Method  : Linear remapping 
+      !!
+      !! References : W.H. Lipscomb, JGR 2001
+      !!------------------------------------------------------------------
+      INTEGER , INTENT (in) ::   kt      ! Ocean time step 
+      !
+      INTEGER  ::   ji, jj, jl, jcat     ! dummy loop index
+      INTEGER  ::   nidx2                ! local integer
+      REAL(wp) ::   zx1, zwk1, zdh0, zetamin, zdamax   ! local scalars
+      REAL(wp) ::   zx2, zwk2, zda0, zetamax           !   -      -
+      REAL(wp) ::   zx3        
+      REAL(wp) ::   zslope          ! used to compute local thermodynamic "speeds"
+      REAL(wp) ::   zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b ! conservation check
+
+      INTEGER , DIMENSION(jpij)       ::   idxice2         ! compute remapping or not
+      INTEGER , DIMENSION(jpij,jpl-1) ::   jdonor          ! donor category index
+      REAL(wp), DIMENSION(jpij,jpl)   ::   zdhice          ! ice thickness increment
+      REAL(wp), DIMENSION(jpij,jpl)   ::   g0, g1          ! coefficients for fitting the line of the ITD
+      REAL(wp), DIMENSION(jpij,jpl)   ::   hL, hR          ! left and right boundary for the ITD for each thickness
+      REAL(wp), DIMENSION(jpij,jpl-1) ::   zdaice, zdvice  ! local increment of ice area and volume
+      REAL(wp), DIMENSION(jpij)       ::   zhb0, zhb1      ! category boundaries for thinnes categories
+      REAL(wp), DIMENSION(jpij,0:jpl) ::   zhbnew          ! new boundaries of ice categories
+      !!------------------------------------------------------------------
+
+      IF( kt == nit000 .AND. lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_itd_rem  : Remapping the ice thickness distribution'
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+      ENDIF
+
+      IF( ln_limdiachk ) CALL ice_cons_hsm(0, 'iceitd_rem', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+
+      !-----------------------------------------------------------------------------------------------
+      !  1) Identify grid cells with ice
+      !-----------------------------------------------------------------------------------------------
+      nidx = 0 ; idxice(:) = 0
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF ( at_i(ji,jj) > epsi10 ) THEN
+               nidx         = nidx + 1
+               idxice( nidx ) = (jj - 1) * jpi + ji
+            ENDIF
+         END DO
+      END DO
+      
+      !-----------------------------------------------------------------------------------------------
+      !  2) Compute new category boundaries
+      !-----------------------------------------------------------------------------------------------
+      IF( nidx > 0 ) THEN
+
+         zdhice(:,:) = 0._wp
+         zhbnew(:,:) = 0._wp
+
+         CALL tab_3d_2d( nidx, idxice(1:nidx), ht_i_2d (1:nidx,1:jpl), ht_i   )
+         CALL tab_3d_2d( nidx, idxice(1:nidx), ht_ib_2d(1:nidx,1:jpl), ht_i_b )
+         CALL tab_3d_2d( nidx, idxice(1:nidx), a_i_2d  (1:nidx,1:jpl), a_i    )
+         CALL tab_3d_2d( nidx, idxice(1:nidx), a_ib_2d (1:nidx,1:jpl), a_i_b  )
+
+         DO jl = 1, jpl
+            ! Compute thickness change in each ice category
+            DO ji = 1, nidx
+               zdhice(ji,jl) = ht_i_2d(ji,jl) - ht_ib_2d(ji,jl)
+            END DO
+         END DO
+         
+         ! --- New boundaries for category 1:jpl-1 --- !
+         DO jl = 1, jpl - 1
+
+            DO ji = 1, nidx
+               !
+               ! --- New boundary: Hn* = Hn + Fn*dt --- !
+               !     Fn*dt = ( fn + (fn+1 - fn)/(hn+1 - hn) * (Hn - hn) ) * dt = zdhice + zslope * (Hmax - ht_i_b)
+               !
+               IF    ( a_ib_2d(ji,jl) >  epsi10 .AND. a_ib_2d(ji,jl+1) >  epsi10 ) THEN   ! a(jl+1) & a(jl) /= 0
+                  zslope           = ( zdhice(ji,jl+1) - zdhice(ji,jl) ) / ( ht_ib_2d(ji,jl+1) - ht_ib_2d(ji,jl) )
+                  zhbnew(ji,jl) = hi_max(jl) + zdhice(ji,jl) + zslope * ( hi_max(jl) - ht_ib_2d(ji,jl) )
+               ELSEIF( a_ib_2d(ji,jl) >  epsi10 .AND. a_ib_2d(ji,jl+1) <= epsi10 ) THEN   ! a(jl+1)=0 => Hn* = Hn + fn*dt
+                  zhbnew(ji,jl) = hi_max(jl) + zdhice(ji,jl)
+               ELSEIF( a_ib_2d(ji,jl) <= epsi10 .AND. a_ib_2d(ji,jl+1) >  epsi10 ) THEN   ! a(jl)=0 => Hn* = Hn + fn+1*dt
+                  zhbnew(ji,jl) = hi_max(jl) + zdhice(ji,jl+1)
+               ELSE                                                                       ! a(jl+1) & a(jl) = 0 
+                  zhbnew(ji,jl) = hi_max(jl)
+               ENDIF
+            
+               ! --- 2 conditions for remapping --- !
+               ! 1) hn(t+1)+espi < Hn* < hn+1(t+1)-epsi               
+               !    Note: hn(t+1) must not be too close to either HR or HL otherwise a division by nearly 0 is possible 
+               !          in ice_itd_glinear in the case (HR-HL) = 3(Hice - HL) or = 3(HR - Hice)
+               IF( a_i_2d(ji,jl  ) > epsi10 .AND. ht_i_2d(ji,jl  ) > ( zhbnew(ji,jl) - epsi10 ) )   idxice(ji) = 0
+               IF( a_i_2d(ji,jl+1) > epsi10 .AND. ht_i_2d(ji,jl+1) < ( zhbnew(ji,jl) + epsi10 ) )   idxice(ji) = 0
+               
+               ! 2) Hn-1 < Hn* < Hn+1  
+               IF( zhbnew(ji,jl) < hi_max(jl-1) )   idxice(ji) = 0
+               IF( zhbnew(ji,jl) > hi_max(jl+1) )   idxice(ji) = 0
+               
+            END DO
+         END DO
+         
+         ! --- New boundaries for category jpl --- !
+         DO ji = 1, nidx
+            IF( a_i_2d(ji,jpl) > epsi10 ) THEN
+               zhbnew(ji,jpl) = MAX( hi_max(jpl-1), 3._wp * ht_i_2d(ji,jpl) - 2._wp * zhbnew(ji,jpl-1) )
+            ELSE
+               zhbnew(ji,jpl) = hi_max(jpl)  
+            ENDIF
+            
+            ! --- 1 additional condition for remapping (1st category) --- !
+            ! H0+epsi < h1(t) < H1-epsi 
+            !    h1(t) must not be too close to either HR or HL otherwise a division by nearly 0 is possible 
+            !    in ice_itd_glinear in the case (HR-HL) = 3(Hice - HL) or = 3(HR - Hice)
+            IF( ht_ib_2d(ji,1) < ( hi_max(0) + epsi10 ) )   idxice(ji) = 0
+            IF( ht_ib_2d(ji,1) > ( hi_max(1) - epsi10 ) )   idxice(ji) = 0
+         END DO
+
+         !-----------------------------------------------------------------------------------------------
+         !  3) Identify cells where remapping
+         !-----------------------------------------------------------------------------------------------
+         nidx2 = 0 ; idxice2(:) = 0
+         DO ji = 1, nidx
+            IF( idxice(ji) /= 0 ) THEN
+               nidx2 = nidx2 + 1
+               idxice2(nidx2) = idxice(ji)
+               zhbnew(nidx2,:) = zhbnew(ji,:)  ! adjust zhbnew to new indices
+            ENDIF
+         END DO
+         idxice(:) = idxice2(:)
+         nidx      = nidx2
+         
+      ENDIF
+   
+
+      !-----------------------------------------------------------------------------------------------
+      !  4) Compute g(h) 
+      !-----------------------------------------------------------------------------------------------
+      IF( nidx > 0 ) THEN
+
+         zhb0(:) = hi_max(0) ; zhb1(:) = hi_max(1)
+         g0(:,:) = 0._wp     ; g1(:,:) = 0._wp 
+         hL(:,:) = 0._wp     ; hR(:,:) = 0._wp 
+         
+         DO jl = 1, jpl
+
+            CALL tab_2d_1d( 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
+               
+               ! 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
+                        zdh0 = MIN( -zdh0, hi_max(1) )
+                        !Integrate g(1) from 0 to dh0 to estimate area melted
+                        zetamax = MIN( zdh0, hR(ji,1) ) - hL(ji,1)
+                        
+                        IF( zetamax > 0.0 ) THEN
+                           zx1    = zetamax
+                           zx2    = 0.5 * zetamax * zetamax 
+                           zda0   = g1(ji,1) * zx2 + g0(ji,1) * zx1                        ! ice area removed
+                           zdamax = a_i_1d(ji) * (1.0 - ht_i_1d(ji) / ht_ib_1d(ji) ) ! Constrain new thickness <= ht_i                
+                           zda0   = MIN( zda0, zdamax )                                                  ! ice area lost due to melting 
+                           !     of thin ice (zdamax > 0)
+                           ! Remove area, conserving volume
+                           ht_i_1d(ji) = ht_i_1d(ji) * a_i_1d(ji) / ( a_i_1d(ji) - zda0 )
+                           a_i_1d(ji)  = a_i_1d(ji) - zda0
+                           v_i_1d(ji)  = a_i_1d(ji) * 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
+
+         END DO
+         
+         !-----------------------------------------------------------------------------------------------
+         !  5) Compute area and volume to be shifted across each boundary (Eq. 18)
+         !-----------------------------------------------------------------------------------------------
+         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
+                  zetamin = MAX( hi_max(jl)   , hL(ji,jl) ) - hL(ji,jl)   ! hi_max(jl) - hL 
+                  zetamax = MIN( zhbnew(ji,jl), hR(ji,jl) ) - hL(ji,jl)   ! hR - hL
+                  jdonor(ji,jl) = jl
+               ELSE                                 ! Hn* <= Hn => transfer from jl+1 to jl
+                  zetamin = 0.0
+                  zetamax = MIN( hi_max(jl), hR(ji,jl+1) ) - hL(ji,jl+1)  ! hi_max(jl) - hL
+                  jdonor(ji,jl) = jl + 1
+               ENDIF
+               zetamax = MAX( zetamax, zetamin ) ! no transfer if etamax < etamin
+               
+               zx1  = zetamax - zetamin
+               zwk1 = zetamin * zetamin
+               zwk2 = zetamax * zetamax
+               zx2  = 0.5 * ( zwk2 - zwk1 )
+               zwk1 = zwk1 * zetamin
+               zwk2 = zwk2 * zetamax
+               zx3  = 1.0 / 3.0 * ( zwk2 - zwk1 )
+               jcat = jdonor(ji,jl)
+               zdaice(ji,jl) = g1(ji,jcat)*zx2 + g0(ji,jcat)*zx1
+               zdvice(ji,jl) = g1(ji,jcat)*zx3 + g0(ji,jcat)*zx2 + zdaice(ji,jl)*hL(ji,jcat)
+               
+            END DO
+         END DO
+         
+         !----------------------------------------------------------------------------------------------
+         ! 6) Shift ice between categories
+         !----------------------------------------------------------------------------------------------
+         CALL ice_itd_shiftice ( jdonor(1:nidx,:), zdaice(1:nidx,:), zdvice(1:nidx,:) )
+         
+         !----------------------------------------------------------------------------------------------
+         ! 7) Make sure ht_i >= minimum ice thickness hi_min
+         !----------------------------------------------------------------------------------------------
+         CALL tab_2d_1d( nidx, idxice(1:nidx), ht_i_1d (1:nidx), ht_i(:,:,1)   )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), a_i_1d  (1:nidx), a_i(:,:,1)    )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), a_ip_1d (1:nidx), a_ip(:,:,1)    )
+         
+         DO ji = 1, nidx
+            IF ( a_i_1d(ji) > epsi10 .AND. ht_i_1d(ji) < rn_himin ) THEN
+               a_i_1d (ji) = a_i_1d(ji) * ht_i_1d(ji) / rn_himin 
+               ! MV MP 2016
+               IF ( nn_pnd_scheme > 0 ) THEN
+                  a_ip_1d(ji) = a_ip_1d(ji) * ht_i_1d(ji) / rn_himin
+               ENDIF
+               ! END MV MP 2016
+               ht_i_1d(ji) = rn_himin
+            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)
+
+   END SUBROUTINE ice_itd_rem
+
+
+   SUBROUTINE ice_itd_glinear( HbL, Hbr, phice, paice, pg0, pg1, phL, phR )
+      !!------------------------------------------------------------------
+      !!                ***  ROUTINE ice_itd_glinear ***
+      !!
+      !! ** Purpose :   build g(h) satisfying area and volume constraints (Eq. 6 and 9)
+      !!
+      !! ** Method  :   g(h) is linear and written as: g(eta) = g1(eta) + g0
+      !!                with eta = h - HL
+      !!                
+      !!------------------------------------------------------------------
+      REAL(wp), DIMENSION(:), INTENT(in   ) ::   HbL, HbR      ! left and right category boundaries
+      REAL(wp), DIMENSION(:), INTENT(in   ) ::   phice, paice  ! ice thickness and concentration
+      REAL(wp), DIMENSION(:), INTENT(inout) ::   pg0, pg1      ! coefficients in linear equation for g(eta)
+      REAL(wp), DIMENSION(:), INTENT(inout) ::   phL, phR      ! min and max value of range over which g(h) > 0
+      !
+      INTEGER  ::   ji           ! horizontal indices
+      REAL(wp) ::   zh13         ! HbL + 1/3 * (HbR - HbL)
+      REAL(wp) ::   zh23         ! HbL + 2/3 * (HbR - HbL)
+      REAL(wp) ::   zdhr         ! 1 / (hR - hL)
+      REAL(wp) ::   zwk1, zwk2   ! temporary variables
+      !!------------------------------------------------------------------
+      !
+         DO 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
+      !
+   END SUBROUTINE ice_itd_glinear
+
+
+   SUBROUTINE ice_itd_shiftice( kdonor, pdaice, pdvice )
+      !!------------------------------------------------------------------
+      !!                ***  ROUTINE ice_itd_shiftice ***
+      !!
+      !! ** 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
+
+      REAL(wp) ::   ztrans             ! ice/snow transferred
+      !!------------------------------------------------------------------
+         
+      CALL tab_3d_2d( nidx, idxice(1:nidx), ht_i_2d (1:nidx,1:jpl), ht_i   )
+      CALL tab_3d_2d( nidx, idxice(1:nidx), a_i_2d  (1:nidx,1:jpl), a_i    )
+      CALL tab_3d_2d( nidx, idxice(1:nidx), v_i_2d  (1:nidx,1:jpl), v_i    )
+      CALL tab_3d_2d( nidx, idxice(1:nidx), v_s_2d  (1:nidx,1:jpl), v_s    )
+      CALL tab_3d_2d( nidx, idxice(1:nidx), oa_i_2d (1:nidx,1:jpl), oa_i   )
+      CALL tab_3d_2d( nidx, idxice(1:nidx), smv_i_2d(1:nidx,1:jpl), smv_i  )
+      CALL tab_3d_2d( nidx, idxice(1:nidx), a_ip_2d (1:nidx,1:jpl), a_ip   )
+      CALL tab_3d_2d( nidx, idxice(1:nidx), v_ip_2d (1:nidx,1:jpl), v_ip   )
+      CALL tab_3d_2d( nidx, idxice(1:nidx), t_su_2d (1:nidx,1:jpl), t_su   )
+
+      !----------------------------------------------------------------------------------------------
+      ! 1) Define a variable equal to a_i*T_su
+      !----------------------------------------------------------------------------------------------
+      DO jl = 1, jpl
+         DO ji = 1, nidx
+            zaTsfn(ji,jl) = a_i_2d(ji,jl) * t_su_2d(ji,jl)
+         END DO
+      END DO
+      
+      !-------------------------------------------------------------------------------
+      ! 2) Transfer volume and energy between categories
+      !-------------------------------------------------------------------------------
+      DO jl = 1, jpl - 1
+         DO ji = 1, 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)
+            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,jl2) = v_i_2d(ji,jl2) + pdvice(ji,jl)
+            
+            ! Snow volumes
+            ztrans         = v_s_2d(ji,jl1) * zworkv(ji)
+            v_s_2d(ji,jl1) = v_s_2d(ji,jl1) - ztrans
+            v_s_2d(ji,jl2) = v_s_2d(ji,jl2) + ztrans 
+                       
+            ! Ice age 
+            ztrans             = oa_i_2d(ji,jl1) * pdaice(ji,jl) !!clem: should be * zworka(ji) but it does not work
+            oa_i_2d(ji,jl1)    = oa_i_2d(ji,jl1) - ztrans
+            oa_i_2d(ji,jl2)    = oa_i_2d(ji,jl2) + ztrans
+            
+            ! Ice salinity
+            ztrans             = smv_i_2d(ji,jl1) * zworkv(ji)
+            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
+            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
+               ztrans          = a_ip_2d(ji,jl1) * pdaice(ji,jl) !!clem: should be * zworka(ji) but it does not work
+               a_ip_2d(ji,jl1) = a_ip_2d(ji,jl1) - ztrans
+               a_ip_2d(ji,jl2) = a_ip_2d(ji,jl2) + ztrans
+               
+               ! Pond volume (also proportional to da/a)
+               ztrans          = v_ip_2d(ji,jl1) * pdaice(ji,jl) !!clem: should be * zworka(ji) but it does not work
+               v_ip_2d(ji,jl1) = v_ip_2d(ji,jl1) - ztrans
+               v_ip_2d(ji,jl2) = v_ip_2d(ji,jl2) + ztrans
+            ENDIF
+            ! END MV MP 2016 
+               
+         END DO
+
+         ! Snow heat content
+         DO jk = 1, nlay_s
+
+            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
+               e_s(ii,ij,jk,jl2) = e_s(ii,ij,jk,jl2) + ztrans 
+            END DO
+         END DO
+
+         
+         ! Ice heat content
+         DO jk = 1, nlay_i
+            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
+               e_i(ii,ij,jk,jl2) = e_i(ii,ij,jk,jl2) + ztrans 
+            END DO
+         END DO
+         
+      END DO                   ! boundaries, 1 to jpl-1
+      
+      !-------------------------------------------------------------------------------
+      ! 3) Update ice thickness and temperature
+      !-------------------------------------------------------------------------------
+      DO jl = 1, jpl
+         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) 
+               t_su_2d(ji,jl)  =  zaTsfn(ji,jl) / a_i_2d(ji,jl) 
+            ELSE
+               ht_i_2d(ji,jl)  = 0._wp
+               t_su_2d(ji,jl)  = rt0
+            ENDIF
+         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   )
+
+      !
+   END SUBROUTINE ice_itd_shiftice
+   
+
+   SUBROUTINE ice_itd_reb
+      !!------------------------------------------------------------------
+      !!                ***  ROUTINE ice_itd_reb ***
+      !!
+      !! ** Purpose : rebin - rebins thicknesses into defined categories
+      !!
+      !! ** Method  : If a category thickness is out of bounds, shift part (for down to top)
+      !!              or entire (for top to down) area, volume, and energy
+      !!              to the neighboring category
+      !!------------------------------------------------------------------
+      INTEGER ::   ji, jj, jl   ! dummy loop indices
+      !
+      INTEGER , DIMENSION(jpij,jpl-1) ::   jdonor           ! donor category index
+      REAL(wp), DIMENSION(jpij,jpl-1) ::   zdaice, zdvice   ! ice area and volume transferred
+      !!------------------------------------------------------------------
+      
+      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
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( a_i(ji,jj,jl) > epsi10 .AND. v_i(ji,jj,jl) > (a_i(ji,jj,jl) * hi_max(jl)) ) THEN
+                  nidx = nidx + 1
+                  idxice( nidx ) = (jj - 1) * jpi + ji                  
+               ENDIF
+            ENDDO
+         ENDDO
+         
+!!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 
+            ! how much of a_i you send in cat sup is somewhat arbitrary
+!!clem: these do not work properly after a restart (I do not know why)
+!!          zdaice(ji,jl)  = a_i_1d(ji) * ( ht_i_1d(ji) - hi_max(jl) + epsi10 ) / ht_i_1d(ji)  
+!!          zdvice(ji,jl)  = v_i_1d(ji) - ( a_i_1d(ji) - zdaice(ji,jl) ) * ( hi_max(jl) - epsi10 )
+!!clem: these do not work properly after a restart (I do not know why)
+!!            zdaice(ji,jl)  = a_i_1d(ji)
+!!            zdvice(ji,jl)  = v_i_1d(ji)
+!!clem: these are from UCL and work ok
+            zdaice(ji,jl)  = a_i_1d(ji) * 0.5_wp
+            zdvice(ji,jl)  = v_i_1d(ji) - zdaice(ji,jl) * ( hi_max(jl) + hi_max(jl-1) ) * 0.5_wp
+            
+         END DO
+
+         IF( nidx > 0 ) THEN
+            CALL ice_itd_shiftice( jdonor(1:nidx,:), zdaice(1:nidx,:), zdvice(1:nidx,:) )  ! Shift jl=>jl+1
+            ! Reset shift parameters
+            jdonor(1:nidx,jl) = 0
+            zdaice(1:nidx,jl) = 0._wp
+            zdvice(1:nidx,jl) = 0._wp
+         ENDIF
+         !
+      END DO
+
+      !-----------------------------------------
+      ! Identify thicknesses that are too small
+      !-----------------------------------------
+      DO jl = jpl - 1, 1, -1
+
+         nidx = 0 ; idxice(:) = 0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( a_i(ji,jj,jl+1) > epsi10 .AND. v_i(ji,jj,jl+1) <= (a_i(ji,jj,jl+1) * hi_max(jl)) ) THEN
+                  nidx = nidx + 1
+                  idxice( nidx ) = (jj - 1) * jpi + ji                  
+               ENDIF
+            ENDDO
+         ENDDO
+
+         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
+         DO ji = 1, nidx
+            jdonor(ji,jl) = jl + 1
+            zdaice(ji,jl) = a_i_1d(ji) 
+            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
+            ! Reset shift parameters
+            jdonor(1:nidx,jl) = 0
+            zdaice(1:nidx,jl) = 0._wp
+            zdvice(1:nidx,jl) = 0._wp
+         ENDIF
+
+      END DO
+      !
+   END SUBROUTINE ice_itd_reb
+
+#endif
+   !!======================================================================
+END MODULE iceitd
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 8421)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icestp.F90	(revision 8422)
@@ -34,5 +34,5 @@
    USE icerhg          ! Ice rheology
    USE iceadv          ! Ice advection
-   USE limthd          ! Ice thermodynamics
+   USE icethd          ! Ice thermodynamics
    USE icerdgrft       ! Ice ridging/rafting
    USE iceupdate       ! sea surface boundary condition
@@ -48,5 +48,5 @@
    ! END MV MP 2016
    USE iceistate       ! LIM initial state
-   USE limthd_sal      ! LIM ice thermodynamics: salinity
+   USE icethd_sal      ! LIM ice thermodynamics: salinity
    !
    USE c1d             ! 1D vertical configuration
@@ -190,5 +190,5 @@
          !----------------------------!
          ! --- zap this if no ice thermo --- !
-         IF( ln_limthd )              CALL lim_thd( kt )        ! -- Ice thermodynamics      
+         IF( ln_limthd )              CALL ice_thd( kt )        ! -- Ice thermodynamics      
 
          ! MV MP 2016
@@ -271,7 +271,7 @@
       CALL ice_itd_init                ! ice thickness distribution initialization
       !
-      CALL lim_thd_init                ! set ice thermodynics parameters
-      !
-      CALL lim_thd_sal_init            ! set ice salinity parameters
+      CALL ice_thd_init                ! set ice thermodynics parameters
+      !
+      CALL ice_thd_sal_init            ! set ice salinity parameters
        
       ! MV MP 2016
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 8422)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd.F90	(revision 8422)
@@ -0,0 +1,612 @@
+MODULE icethd
+   !!======================================================================
+   !!                  ***  MODULE icethd   ***
+   !!  LIM-3 :   ice thermodynamic
+   !!======================================================================
+   !! History :  LIM  ! 2000-01 (M.A. Morales Maqueda, H. Goosse, T. Fichefet) LIM-1
+   !!            2.0  ! 2002-07 (C. Ethe, G. Madec)  LIM-2 (F90 rewriting)
+   !!            3.0  ! 2005-11 (M. Vancoppenolle)  LIM-3 : Multi-layer thermodynamics + salinity variations
+   !!             -   ! 2007-04 (M. Vancoppenolle) add ice_thd_glohec, ice_thd_con_dh and ice_thd_con_dif
+   !!            3.2  ! 2009-07 (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in wfx_snw
+   !!            3.3  ! 2010-11 (G. Madec) corrected snow melting heat (due to factor betas)
+   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!             -   ! 2012-05 (C. Rousset) add penetration solar flux
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_thd       : thermodynamic of sea ice
+   !!   ice_thd_init  : initialisation of sea-ice thermodynamic
+   !!----------------------------------------------------------------------
+   USE phycst         ! physical constants
+   USE dom_oce        ! ocean space and time domain variables
+   USE ice            ! sea-ice variables
+   USE sbc_oce , ONLY : sss_m, sst_m, e3t_m, utau, vtau, ssu_m, ssv_m, frq_m, qns_tot, qsr_tot, sprecip, ln_cpl
+   USE sbc_ice , ONLY : qsr_oce, qns_oce, qemp_oce, qsr_ice, qns_ice, dqns_ice, evap_ice, qprec_ice, qevap_ice, &
+      &                 fr1_i0, fr2_i0, nn_limflx
+   USE ice1D          ! thermodynamic sea-ice variables
+   USE icethd_dif     ! vertical diffusion
+   USE icethd_dh      ! ice-snow growth and melt
+   USE icethd_da      ! lateral melting
+   USE icethd_sal     ! ice salinity
+   USE icethd_ent     ! ice enthalpy redistribution
+   USE icethd_lac     ! lateral accretion
+   USE iceitd         ! remapping thickness distribution
+   USE icetab         ! 1D <==> 2D transformation
+   USE limvar         !
+   USE icecons        ! conservation tests
+   USE icectl         ! control print
+   !
+   USE in_out_manager ! I/O manager
+   USE lbclnk         ! lateral boundary condition - MPP links
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   USE timing         ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_thd         ! called by limstp module
+   PUBLIC   ice_thd_init    ! called by ice_init
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
+   !! $Id: icethd.F90 8420 2017-08-08 12:18:46Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_thd( kt )
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_thd  ***       
+      !!  
+      !! ** Purpose : This routine manages ice thermodynamics
+      !!         
+      !! ** Action : - Initialisation of some variables
+      !!             - Some preliminary computation (oceanic heat flux
+      !!               at the ice base, snow acc.,heat budget of the leads)
+      !!             - selection of the icy points and put them in an array
+      !!             - call ice_thd_dif  for vertical heat diffusion
+      !!             - call ice_thd_dh   for vertical ice growth and melt
+      !!             - call ice_thd_ent  for enthalpy remapping
+      !!             - call ice_thd_sal  for ice desalination
+      !!             - call ice_thd_temp to  retrieve temperature from ice enthalpy
+      !!             - back to the geographic grid
+      !!     
+      !! ** References : 
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) :: kt    ! number of iteration
+      !
+      INTEGER  :: ji, jj, jk, jl   ! dummy loop indices
+      REAL(wp) :: zfric_u, zqld, zqfr, zqfr_neg
+      REAL(wp) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b ! conservation check
+      REAL(wp), PARAMETER :: zfric_umin = 0._wp           ! lower bound for the friction velocity (cice value=5.e-04)
+      REAL(wp), PARAMETER :: zch        = 0.0057_wp       ! heat transfer coefficient
+      REAL(wp), DIMENSION(jpi,jpj) ::   zu_io, zv_io, zfric   ! ice-ocean velocity (m/s) and frictional velocity (m2/s2)
+      !
+      !!-------------------------------------------------------------------
+
+      IF( nn_timing == 1 )   CALL timing_start('icethd')
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)'' 
+         WRITE(numout,*)' ice_thd '
+         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)
+
+      CALL lim_var_glo2eqv
+
+      !---------------------------------------------!
+      ! computation of friction velocity at T points
+      !---------------------------------------------!
+      IF( ln_limdyn ) THEN
+         zu_io(:,:) = u_ice(:,:) - ssu_m(:,:)
+         zv_io(:,:) = v_ice(:,:) - ssv_m(:,:)
+         DO jj = 2, jpjm1 
+            DO ji = fs_2, fs_jpim1
+               zfric(ji,jj) = rn_cio * ( 0.5_wp *  &
+                  &                    (  zu_io(ji,jj) * zu_io(ji,jj) + zu_io(ji-1,jj) * zu_io(ji-1,jj)   &
+                  &                     + zv_io(ji,jj) * zv_io(ji,jj) + zv_io(ji,jj-1) * zv_io(ji,jj-1) ) ) * tmask(ji,jj,1)
+            END DO
+         END DO
+      ELSE      !  if no ice dynamics => transmit directly the atmospheric stress to the ocean
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1
+               zfric(ji,jj) = r1_rau0 * SQRT( 0.5_wp *  &
+                  &                         (  utau(ji,jj) * utau(ji,jj) + utau(ji-1,jj) * utau(ji-1,jj)   &
+                  &                          + vtau(ji,jj) * vtau(ji,jj) + vtau(ji,jj-1) * vtau(ji,jj-1) ) ) * tmask(ji,jj,1)
+            END DO
+         END DO
+      ENDIF
+      CALL lbc_lnk( zfric, 'T',  1. )
+      !
+      ftr_ice(:,:,:) = 0._wp  ! initialization (part of solar radiation transmitted through the ice)
+
+      !--------------------------------------------------------------------!
+      ! Partial computation of forcing for the thermodynamic sea ice model
+      !--------------------------------------------------------------------!
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            rswitch  = tmask(ji,jj,1) * MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi10 ) ) ! 0 if no ice
+            !
+            !           !  solar irradiance transmission at the mixed layer bottom and used in the lead heat budget
+            !           !  practically no "direct lateral ablation"
+            !           
+            !           !  net downward heat flux from the ice to the ocean, expressed as a function of ocean 
+            !           !  temperature and turbulent mixing (McPhee, 1992)
+            !
+            ! --- Energy received in the lead, zqld is defined everywhere (J.m-2) --- !
+            zqld =  tmask(ji,jj,1) * rdt_ice *  &
+               &    ( ( 1._wp - at_i_b(ji,jj) ) * qsr_oce(ji,jj) * frq_m(ji,jj) +  &
+               &      ( 1._wp - at_i_b(ji,jj) ) * qns_oce(ji,jj) + qemp_oce(ji,jj) )
+
+            ! --- Energy needed to bring ocean surface layer until its freezing (<0, J.m-2) --- !
+            ! includes supercooling potential energy (>0) or "above-freezing" energy (<0)
+            zqfr = tmask(ji,jj,1) * rau0 * rcp * e3t_m(ji,jj) * ( t_bo(ji,jj) - ( sst_m(ji,jj) + rt0 ) )
+
+            ! --- Above-freezing sensible heat content (J/m2 grid)
+            zqfr_neg = tmask(ji,jj,1) * rau0 * rcp * e3t_m(ji,jj) * MIN( ( t_bo(ji,jj) - ( sst_m(ji,jj) + rt0 ) ), 0._wp )
+
+            ! --- Sensible ocean-to-ice heat flux (W/m2)
+            zfric_u      = MAX( SQRT( zfric(ji,jj) ), zfric_umin ) 
+            fhtur(ji,jj) = rswitch * rau0 * rcp * zch  * zfric_u * ( ( sst_m(ji,jj) + rt0 ) - t_bo(ji,jj) ) ! W.m-2
+
+            fhtur(ji,jj) = rswitch * MIN( fhtur(ji,jj), - zqfr_neg * r1_rdtice / MAX( at_i(ji,jj), epsi10 ) )
+            ! upper bound for fhtur: the heat retrieved from the ocean must be smaller than the heat necessary to reach 
+            !                        the freezing point, so that we do not have SST < T_freeze
+            !                        This implies: - ( fhtur(ji,jj) * at_i(ji,jj) * rtdice ) - zqfr >= 0
+
+            !-- Energy Budget of the leads (J.m-2), source of lateral accretion. Must be < 0 to form ice
+            qlead(ji,jj) = MIN( 0._wp , zqld - ( fhtur(ji,jj) * at_i(ji,jj) * rdt_ice ) - zqfr )
+
+            ! If there is ice and leads are warming, then transfer energy from the lead budget and use it for bottom melting 
+            IF( zqld > 0._wp ) THEN
+               fhld (ji,jj) = rswitch * zqld * r1_rdtice / MAX( at_i(ji,jj), epsi10 ) ! divided by at_i since this is (re)multiplied by a_i in icethd_dh.F90
+               qlead(ji,jj) = 0._wp
+            ELSE
+               fhld (ji,jj) = 0._wp
+            ENDIF
+            !
+            ! Net heat flux on top of the ice-ocean [W.m-2]
+            ! ---------------------------------------------
+            hfx_in(ji,jj) = qns_tot(ji,jj) + qsr_tot(ji,jj) 
+         END DO
+      END DO
+      
+      ! In case we bypass open-water ice formation
+      IF( .NOT. ln_limdO )  qlead(:,:) = 0._wp
+      ! In case we bypass growing/melting from top and bottom: we suppose ice is impermeable => ocean is isolated from atmosphere
+      IF( .NOT. ln_limdH )  hfx_in(:,:) = ( 1._wp - at_i_b(:,:) ) * ( qns_oce(:,:) + qsr_oce(:,:) ) + qemp_oce(:,:)
+      IF( .NOT. ln_limdH )  fhtur (:,:) = 0._wp  ;  fhld  (:,:) = 0._wp
+
+      ! ---------------------------------------------------------------------
+      ! Net heat flux on top of the ocean after ice thermo (1st step) [W.m-2]
+      ! ---------------------------------------------------------------------
+      !     First  step here              :  non solar + precip - qlead - qturb
+      !     Second step in icethd_dh      :  heat remaining if total melt (zq_rema) 
+      !     Third  step in iceupdate.F90  :  heat from ice-ocean mass exchange (zf_mass) + solar
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            hfx_out(ji,jj) = ( 1._wp - at_i_b(ji,jj) ) * qns_oce(ji,jj) + qemp_oce(ji,jj)  &  ! Non solar heat flux received by the ocean               
+               &             - qlead(ji,jj) * r1_rdtice                                    &  ! heat flux taken from the ocean where there is open water ice formation
+               &             - at_i(ji,jj) * fhtur(ji,jj)                                  &  ! heat flux taken by turbulence
+               &             - at_i(ji,jj) *  fhld(ji,jj)                                     ! heat flux taken during bottom growth/melt 
+                                                                                              !    (fhld should be 0 while bott growth)
+         END DO
+      END DO
+
+      !-------------------------------------------------------------------------------------------!
+      ! Thermodynamic computation (only on grid points covered by ice) => loop over ice categories
+      !-------------------------------------------------------------------------------------------!
+      DO jl = 1, jpl
+
+         ! select ice covered grid points
+         nidx = 0 ; idxice(:) = 0
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF ( a_i(ji,jj,jl) > epsi10 ) THEN     
+                  nidx         = nidx  + 1
+                  idxice(nidx) = (jj - 1) * jpi + ji
+               ENDIF
+            END DO
+         END DO
+
+         IF( lk_mpp )         CALL mpp_ini_ice( nidx , numout )
+
+         IF( nidx > 0 ) THEN  ! If there is no ice, do nothing.
+            !                                                                
+                              CALL ice_thd_1d2d( jl, 1 )            ! --- Move to 1D arrays --- !
+            !                                                       ! --- & Change units of e_i, e_s from J/m2 to J/m3 --- !
+            !
+            s_i_new   (1:nidx) = 0._wp ; dh_s_tot (1:nidx) = 0._wp  ! --- some init --- !  (important to have them here) 
+            dh_i_surf (1:nidx) = 0._wp ; dh_i_bott(1:nidx) = 0._wp
+            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 --- !
+            !
+                              CALL ice_thd_sal                      ! --- Ice salinity --- !    
+            !
+                              CALL ice_thd_temp                     ! --- temperature update --- !
+            !
+            IF( ln_limdH ) THEN
+               IF ( ( nn_monocat == 1 .OR. nn_monocat == 4 ) .AND. jpl == 1 ) THEN
+                              CALL ice_thd_lam                      ! --- extra lateral melting if monocat --- !
+               END IF
+            END IF
+            !
+            IF( ln_limdA )    CALL ice_thd_da                       ! --- lateral melting --- !
+            !
+                              CALL ice_thd_1d2d( jl, 2 )            ! --- Change units of e_i, e_s from J/m3 to J/m2 --- !
+            !                                                       ! --- & Move to 2D arrays --- !
+            !
+            IF( lk_mpp )      CALL mpp_comm_free( ncomm_ice ) !RB necessary ??
+         ENDIF
+         !
+      END DO
+      ! update ice age (in case a_i changed, i.e. becomes 0 or lateral melting)
+      oa_i(:,:,:) = o_i(:,:,:) * a_i(:,:,:)
+
+      IF( ln_limdiachk ) CALL ice_cons_hsm(1, 'icethd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      !
+                         CALL lim_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( nn_timing == 1 )  CALL timing_stop('icethd')
+
+   END SUBROUTINE ice_thd 
+
+ 
+   SUBROUTINE ice_thd_temp
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_thd_temp *** 
+      !!                 
+      !! ** Purpose :   Computes sea ice temperature (Kelvin) from enthalpy
+      !!
+      !! ** Method  :   Formula (Bitz and Lipscomb, 1999)
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ji, jk   ! dummy loop indices
+      REAL(wp) ::   ztmelts, zaaa, zbbb, zccc, zdiscrim  ! local scalar 
+      !!-------------------------------------------------------------------
+      ! Recover ice temperature
+      DO jk = 1, nlay_i
+         DO ji = 1, nidx
+            ztmelts       =  -tmut * s_i_1d(ji,jk) + rt0
+            ! Conversion q(S,T) -> T (second order equation)
+            zaaa          =  cpic
+            zbbb          =  ( rcp - cpic ) * ( ztmelts - rt0 ) + e_i_1d(ji,jk) * r1_rhoic - lfus
+            zccc          =  lfus * ( ztmelts - rt0 )
+            zdiscrim      =  SQRT( MAX( zbbb * zbbb - 4._wp * zaaa * zccc, 0._wp ) )
+            t_i_1d(ji,jk) =  rt0 - ( zbbb + zdiscrim ) / ( 2._wp * zaaa )
+            
+            ! mask temperature
+            rswitch       =  1._wp - MAX( 0._wp , SIGN( 1._wp , - ht_i_1d(ji) ) ) 
+            t_i_1d(ji,jk) =  rswitch * t_i_1d(ji,jk) + ( 1._wp - rswitch ) * rt0
+         END DO 
+      END DO 
+      !
+   END SUBROUTINE ice_thd_temp
+
+
+   SUBROUTINE ice_thd_lam
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_thd_lam *** 
+      !!                 
+      !! ** Purpose :   Lateral melting in case monocategory
+      !!                          ( dA = A/2h dh )
+      !!-----------------------------------------------------------------------
+      INTEGER  ::   ji                 ! dummy loop indices
+      REAL(wp) ::   zhi_bef            ! ice thickness before thermo
+      REAL(wp) ::   zdh_mel, zda_mel   ! net melting
+      REAL(wp) ::   zvi, zvs           ! ice/snow volumes 
+      !!-----------------------------------------------------------------------
+      !
+      DO ji = 1, nidx
+         zdh_mel = MIN( 0._wp, dh_i_surf(ji) + dh_i_bott(ji) + dh_snowice(ji) + dh_i_sub(ji) )
+         IF( zdh_mel < 0._wp .AND. a_i_1d(ji) > 0._wp )  THEN
+            zvi          = a_i_1d(ji) * ht_i_1d(ji)
+            zvs          = a_i_1d(ji) * ht_s_1d(ji)
+            ! lateral melting = concentration change
+            zhi_bef     = ht_i_1d(ji) - zdh_mel
+            rswitch     = MAX( 0._wp , SIGN( 1._wp , zhi_bef - epsi20 ) )
+            zda_mel     = rswitch * a_i_1d(ji) * zdh_mel / ( 2._wp * MAX( zhi_bef, epsi20 ) )
+            a_i_1d(ji)  = MAX( epsi20, a_i_1d(ji) + zda_mel ) 
+            ! adjust thickness
+            ht_i_1d(ji) = zvi / a_i_1d(ji)            
+            ht_s_1d(ji) = zvs / a_i_1d(ji)            
+            ! retrieve total concentration
+            at_i_1d(ji) = a_i_1d(ji)
+         END IF
+      END DO
+      !
+   END SUBROUTINE ice_thd_lam
+
+
+   SUBROUTINE ice_thd_1d2d( jl, kn )
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_thd_1d2d *** 
+      !!                 
+      !! ** 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
+      !!-----------------------------------------------------------------------
+      !
+      SELECT CASE( kn )
+      !
+      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)     )
+         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)   )
+         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)   )
+         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), 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), t_bo_1d     (1:nidx), t_bo             )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), sprecip_1d  (1:nidx), sprecip          ) 
+         CALL tab_2d_1d( nidx, idxice(1:nidx), fhtur_1d    (1:nidx), fhtur            )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), fhld_1d     (1:nidx), fhld             )
+         !
+         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_snw_sni_1d(1:nidx), wfx_snw_sni   )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_snw_sum_1d(1:nidx), wfx_snw_sum   )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_sub_1d    (1:nidx), wfx_sub       )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_snw_sub_1d(1:nidx), wfx_snw_sub   )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_ice_sub_1d(1:nidx), wfx_ice_sub   )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_err_sub_1d(1:nidx), wfx_err_sub   )
+         !
+         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_bog_1d (1:nidx), wfx_bog          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_bom_1d (1:nidx), wfx_bom          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_sum_1d (1:nidx), wfx_sum          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_sni_1d (1:nidx), wfx_sni          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_res_1d (1:nidx), wfx_res          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_spr_1d (1:nidx), wfx_spr          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_lam_1d (1:nidx), wfx_lam          )
+         !
+         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_bog_1d (1:nidx), sfx_bog          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_bom_1d (1:nidx), sfx_bom          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_sum_1d (1:nidx), sfx_sum          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_sni_1d (1:nidx), sfx_sni          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_bri_1d (1:nidx), sfx_bri          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_res_1d (1:nidx), sfx_res          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_sub_1d (1:nidx), sfx_sub          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_lam_1d (1:nidx), sfx_lam          )
+         !
+         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_thd_1d (1:nidx), hfx_thd          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_spr_1d (1:nidx), hfx_spr          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_sum_1d (1:nidx), hfx_sum          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_bom_1d (1:nidx), hfx_bom          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_bog_1d (1:nidx), hfx_bog          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_dif_1d (1:nidx), hfx_dif          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_opw_1d (1:nidx), hfx_opw          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_snw_1d (1:nidx), hfx_snw          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_sub_1d (1:nidx), hfx_sub          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_err_1d (1:nidx), hfx_err          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_res_1d (1:nidx), hfx_res          )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_err_dif_1d(1:nidx), hfx_err_dif   )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_err_rem_1d(1:nidx), hfx_err_rem   )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_out_1d (1:nidx), hfx_out          )
+         !
+         ! SIMIP diagnostics
+         CALL tab_2d_1d( nidx, idxice(1:nidx), diag_fc_bo_1d(1:nidx), diag_fc_bo   )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), diag_fc_su_1d(1:nidx), diag_fc_su   )
+         ! ocean surface fields
+         CALL tab_2d_1d( nidx, idxice(1:nidx), sst_1d(1:nidx), sst_m )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), sss_1d(1:nidx), sss_m )
+
+         ! --- Change units of e_i, e_s from J/m2 to J/m3 --- !
+         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
+         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
+         !
+         ! --- 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
+         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
+         !
+         ! Change thickness to volume
+         v_i_1d(1:nidx)   = ht_i_1d(1:nidx) * a_i_1d(1:nidx)
+         v_s_1d(1:nidx)   = ht_s_1d(1:nidx) * a_i_1d(1:nidx)
+         smv_i_1d(1:nidx) = sm_i_1d(1:nidx) * v_i_1d(1:nidx)
+         
+         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)     )
+         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)   )
+         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)  )
+         !
+         ! 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        )
+         ! 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) )
+      END SELECT
+      !
+   END SUBROUTINE ice_thd_1d2d
+
+
+   SUBROUTINE ice_thd_init
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_thd_init *** 
+      !!                 
+      !! ** Purpose :   Physical constants and parameters linked to the ice 
+      !!              thermodynamics
+      !!
+      !! ** Method  :   Read the namicethd namelist and check the ice-thermo
+      !!              parameter values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namicether
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ios                 ! Local integer output status for namelist read
+      NAMELIST/namicethd/ rn_kappa_i, nn_ice_thcon, ln_dqnsice, rn_cdsn,                                  &
+         &                ln_limdH, rn_betas,                                                             &
+         &                ln_limdA, rn_beta, rn_dmin,                                                     &
+         &                ln_limdO, rn_hnewice, ln_frazil, rn_maxfrazb, rn_vfrazb, rn_Cfrazb, rn_himin,   &
+         &                nn_limflx
+      !!-------------------------------------------------------------------
+      !
+      REWIND( numnam_ice_ref )              ! Namelist namicethd in reference namelist : Ice thermodynamics
+      READ  ( numnam_ice_ref, namicethd, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicethd in reference namelist', lwp )
+
+      REWIND( numnam_ice_cfg )              ! Namelist namicethd in configuration namelist : Ice thermodynamics
+      READ  ( numnam_ice_cfg, namicethd, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicethd in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namicethd )
+      !
+      !
+      IF(lwp) THEN                          ! control print
+         WRITE(numout,*) 'ice_thd_init : Ice Thermodynamics'
+         WRITE(numout,*) '~~~~~~~~~~~~~'
+         WRITE(numout,*)'   -- icethd_dif --'
+         WRITE(numout,*)'      extinction radiation parameter in sea ice               rn_kappa_i   = ', rn_kappa_i
+         WRITE(numout,*)'      switch for comp. of thermal conductivity in the ice     nn_ice_thcon = ', nn_ice_thcon
+         WRITE(numout,*)'      change the surface non-solar flux with Tsu or not       ln_dqnsice   = ', ln_dqnsice
+         WRITE(numout,*)'      thermal conductivity of the snow                        rn_cdsn      = ', rn_cdsn
+         WRITE(numout,*)'   -- icethd_dh --'
+         WRITE(numout,*)'      activate ice thick change from top/bot (T) or not (F)   ln_limdH     = ', ln_limdH
+         WRITE(numout,*)'      coefficient for ice-lead partition of snowfall          rn_betas     = ', rn_betas
+         WRITE(numout,*)'   -- icethd_da --'
+         WRITE(numout,*)'      activate lateral melting (T) or not (F)                 ln_limdA     = ', ln_limdA
+         WRITE(numout,*)'      Coef. beta for lateral melting param.                   rn_beta      = ', rn_beta
+         WRITE(numout,*)'      Minimum floe diameter for lateral melting param.        rn_dmin      = ', rn_dmin
+         WRITE(numout,*)'   -- 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,*)'      Frazil ice thickness as a function of wind or not       ln_frazil    = ', ln_frazil
+         WRITE(numout,*)'      Maximum proportion of frazil ice collecting at bottom   rn_maxfrazb  = ', rn_maxfrazb
+         WRITE(numout,*)'      Thresold relative drift speed for collection of frazil  rn_vfrazb    = ', rn_vfrazb
+         WRITE(numout,*)'      Squeezing coefficient for collection of frazil          rn_Cfrazb    = ', rn_Cfrazb
+         WRITE(numout,*)'   -- iceitd --'
+         WRITE(numout,*)'      minimum ice thickness                                   rn_himin     = ', rn_himin 
+         WRITE(numout,*)'   -- icestp --'
+         WRITE(numout,*)'      Multicategory heat flux formulation                     nn_limflx    = ', nn_limflx
+      ENDIF
+      !
+      IF ( rn_hnewice < rn_himin )   CALL ctl_stop( 'STOP', 'ice_thd_init : rn_hnewice should be >= rn_himin' )
+      !
+      IF(lwp) WRITE(numout,*)
+      SELECT CASE( nn_limflx )         ! LIM3 Multi-category heat flux formulation
+      CASE ( -1 )
+         IF(lwp) WRITE(numout,*) '   LIM3: use per-category fluxes (nn_limflx = -1) '
+         IF( ln_cpl )   CALL ctl_stop( 'sbc_init : the chosen nn_limflx for LIM3 in coupled mode must be 0 or 2' )
+      CASE ( 0  )
+         IF(lwp) WRITE(numout,*) '   LIM3: use average per-category fluxes (nn_limflx = 0) '
+      CASE ( 1  )
+         IF(lwp) WRITE(numout,*) '   LIM3: use average then redistribute per-category fluxes (nn_limflx = 1) '
+         IF( ln_cpl )   CALL ctl_stop( 'sbc_init : the chosen nn_limflx for LIM3 in coupled mode must be 0 or 2' )
+      CASE ( 2  )
+         IF(lwp) WRITE(numout,*) '   LIM3: Redistribute a single flux over categories (nn_limflx = 2) '
+         IF( .NOT. ln_cpl )   CALL ctl_stop( 'sbc_init : the chosen nn_limflx for LIM3 in forced mode cannot be 2' )
+      CASE DEFAULT
+         CALL ctl_stop( 'sbcmod: LIM3 option, nn_limflx, should be between -1 and 2' )
+      END SELECT
+      !
+   END SUBROUTINE ice_thd_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Dummy module          NO  LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE icethd
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 8422)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_da.F90	(revision 8422)
@@ -0,0 +1,158 @@
+MODULE icethd_da
+   !!======================================================================
+   !!                       ***  MODULE icethd_da ***
+   !! LIM-3 sea-ice :  computation of lateral melting in the ice
+   !!======================================================================
+   !! History :   4.0   ! 2016-03 (C. Rousset) original code
+   !!---------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM-3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   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 lib_mpp        ! MPP library
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_thd_da        ! called by icethd module
+
+   !!----------------------------------------------------------------------
+   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! $Id: icethd_da.F90 5123 2015-03-04 16:06:03Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_thd_da
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_thd_da  ***    
+      !!   
+      !! ** Purpose :   computes sea ice lateral melting
+      !!
+      !! ** Method  :   dA/dt = - P * W   [s-1]
+      !!                   W = melting velocity [m.s-1]
+      !!                   P = perimeter of ice-ocean lateral interface normalized by grid cell area [m.m-2]
+      !!
+      !!                   W = m1 * (Tw -Tf)**m2                    --- originally from Josberger 1979 ---
+      !!                      (Tw - Tf) = elevation of water temp above freezing
+      !!                      m1 and m2 = (1.6e-6 , 1.36) best fit from field experiment near the coast of Prince Patrick Island (Perovich 1983) => static ice
+      !!                      m1 and m2 = (3.0e-6 , 1.36) best fit from MIZEX 84 experiment (Maykut and Perovich 1987) => moving ice
+      !!
+      !!                   P = N * pi * D                           --- from Rothrock and Thorndike 1984 ---
+      !!                      D = mean floe caliper diameter
+      !!                      N = number of floes = ice area / floe area(average) = A / (Cs * D**2)
+      !!                         A = ice concentration
+      !!                         Cs = deviation from a square (square:Cs=1 ; circle:Cs=pi/4 ; floe:Cs=0.66)
+      !!
+      !!                   D = Dmin * ( Astar / (Astar-A) )**beta   --- from Lupkes et al., 2012 (eq. 26-27) ---
+      !!                                                             
+      !!                      Astar = 1 / ( 1 - (Dmin/Dmax)**(1/beta) )
+      !!                      Dmin = minimum floe diameter (recommended to be 8m +- 20%)
+      !!                      Dmax = maximum floe diameter (recommended to be 300m, but it does not impact melting much except for Dmax<100m)
+      !!                      beta = 1.0 +-20% (recommended value)
+      !!                           = 0.3 best fit for western Fram Strait and Antarctica
+      !!                           = 1.4 best fit for eastern Fram Strait
+      !!
+      !! ** Tunable parameters  :   We propose to tune the lateral melting via 2 parameters
+      !!                               Dmin [6-10m]   => 6  vs 8m = +40% melting at the peak (A~0.5)
+      !!                                                 10 vs 8m = -20% melting
+      !!                               beta [0.8-1.2] => decrease = more melt and melt peaks toward higher concentration
+      !!                                                                  (A~0.5 for beta=1 ; A~0.8 for beta=0.2)
+      !!                                                 0.3 = best fit for western Fram Strait and Antarctica
+      !!                                                 1.4 = best fit for eastern Fram Strait
+      !!
+      !! ** Note   :   Former and more simple formulations for floe diameters can be found in Mai (1995), 
+      !!               Birnbaum and Lupkes (2002), Lupkes and Birnbaum (2005). They are reviewed in Lupkes et al 2012
+      !!               A simpler implementation for CICE can be found in Bitz et al (2001) and Tsamados et al (2015)
+      !!
+      !! ** References
+      !!    Bitz, C. M., Holland, M. M., Weaver, A. J., & Eby, M. (2001).
+      !!              Simulating the ice‐thickness distribution in a coupled climate model.
+      !!              Journal of Geophysical Research: Oceans, 106(C2), 2441-2463.
+      !!    Josberger, E. G. (1979).
+      !!              Laminar and turbulent boundary layers adjacent to melting vertical ice walls in salt water
+      !!              (No. SCIENTIFIC-16). WASHINGTON UNIV SEATTLE DEPT OF ATMOSPHERIC SCIENCES.
+      !!    Lüpkes, C., Gryanik, V. M., Hartmann, J., & Andreas, E. L. (2012).
+      !!              A parametrization, based on sea ice morphology, of the neutral atmospheric drag coefficients
+      !!              for weather prediction and climate models.
+      !!              Journal of Geophysical Research: Atmospheres, 117(D13).
+      !!    Maykut, G. A., & Perovich, D. K. (1987).
+      !!              The role of shortwave radiation in the summer decay of a sea ice cover.
+      !!              Journal of Geophysical Research: Oceans, 92(C7), 7032-7044.
+      !!    Perovich, D. K. (1983).
+      !!              On the summer decay of a sea ice cover. (Doctoral dissertation, University of Washington).
+      !!    Rothrock, D. A., & Thorndike, A. S. (1984).
+      !!              Measuring the sea ice floe size distribution.
+      !!              Journal of Geophysical Research: Oceans, 89(C4), 6477-6486.
+      !!    Tsamados, M., Feltham, D., Petty, A., Schroeder, D., & Flocco, D. (2015).
+      !!              Processes controlling surface, bottom and lateral melt of Arctic sea ice in a state of the art sea ice model.
+      !!              Phil. Trans. R. Soc. A, 373(2052), 20140167.
+      !!---------------------------------------------------------------------
+      INTEGER  ::   ji     ! dummy loop indices
+      REAL(wp)            ::   zastar, zdfloe, zperi, zwlat, zda
+      REAL(wp), PARAMETER ::   zdmax = 300._wp
+      REAL(wp), PARAMETER ::   zcs   = 0.66_wp
+      REAL(wp), PARAMETER ::   zm1   = 3.e-6_wp
+      REAL(wp), PARAMETER ::   zm2   = 1.36_wp
+      !
+      REAL(wp), DIMENSION(jpij) ::   zda_tot
+      !!---------------------------------------------------------------------
+
+      !------------------------------------------------------------!
+      !------------------------------------------------------------!
+      zastar = 1._wp / ( 1._wp - (rn_dmin / zdmax)**(1._wp/rn_beta) )
+      DO ji = 1, nidx   
+         ! --- Calculate reduction of total sea ice concentration --- !
+         zdfloe = rn_dmin * ( zastar / ( zastar - at_i_1d(ji) ) )**rn_beta         ! Mean floe caliper diameter [m]
+         zperi  = at_i_1d(ji) * rpi / ( zcs * zdfloe )                             ! Mean perimeter of the floe = N*pi*D = (A/cs*D^2)*pi*D [m.m-2]
+         zwlat  = zm1 * ( MAX( 0._wp, sst_1d(ji) - ( t_bo_1d(ji) - rt0 ) ) )**zm2  ! Melt speed rate [m/s]
+         
+         zda_tot(ji) = MIN( zwlat * zperi * rdt_ice, at_i_1d(ji) )                 ! sea ice concentration decrease (>0)
+      
+         ! --- Distribute reduction among ice categories and calculate associated ice-ocean fluxes --- !
+         IF( a_i_1d(ji) > 0._wp ) THEN
+            ! decrease of concentration for the category jl
+            !    each category contributes to melting in proportion to its concentration
+            zda = MIN( a_i_1d(ji), zda_tot(ji) * a_i_1d(ji) / at_i_1d(ji) )
+            
+            ! Contribution to salt flux
+            sfx_lam_1d(ji) = sfx_lam_1d(ji) + rhoic *  ht_i_1d(ji) * zda * sm_i_1d(ji) * r1_rdtice
+            
+            ! Contribution to heat flux into the ocean [W.m-2], (<0)  
+            hfx_thd_1d(ji) = hfx_thd_1d(ji) - zda * r1_rdtice * ( ht_i_1d(ji) * r1_nlay_i * SUM( e_i_1d(ji,1:nlay_i) )  &
+                                                                + ht_s_1d(ji) * r1_nlay_s * SUM( e_s_1d(ji,1:nlay_s) ) ) 
+            
+            ! Contribution to mass flux
+            wfx_lam_1d(ji) =  wfx_lam_1d(ji) + zda * r1_rdtice * ( rhoic * ht_i_1d(ji) + rhosn * ht_s_1d(ji) )
+            
+            ! 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
+               ht_i_1d(ji) = 0._wp
+               ht_s_1d(ji) = 0._wp
+            ENDIF
+         ENDIF
+      END DO
+      !
+   END SUBROUTINE ice_thd_da
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   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 8422)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_dh.F90	(revision 8422)
@@ -0,0 +1,689 @@
+MODULE icethd_dh
+   !!======================================================================
+   !!                       ***  MODULE icethd_dh ***
+   !!  LIM-3 :   thermodynamic growth and decay of the ice 
+   !!======================================================================
+   !! History :  LIM  ! 2003-05 (M. Vancoppenolle) Original code in 1D
+   !!                 ! 2005-06 (M. Vancoppenolle) 3D version 
+   !!            3.2  ! 2009-07 (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in wfx_snw & wfx_ice
+   !!            3.4  ! 2011-02 (G. Madec) dynamical allocation
+   !!            3.5  ! 2012-10 (G. Madec & co) salt flux + bug fixes 
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_thd_dh    : vertical accr./abl. and lateral ablation of sea ice
+   !!----------------------------------------------------------------------
+   USE par_oce        ! ocean parameters
+   USE phycst         ! physical constants (OCE directory) 
+   USE ice            ! LIM variables
+   USE ice1D          ! LIM thermodynamics
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_thd_dh      ! called by ice_thd
+   PUBLIC   ice_thd_snwblow ! called in sbcblk/sbcclio/sbccpl and here
+
+   INTERFACE ice_thd_snwblow
+      MODULE PROCEDURE ice_thd_snwblow_1d, ice_thd_snwblow_2d
+   END INTERFACE
+
+   !!----------------------------------------------------------------------
+   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
+   !! $Id: icethd_dh.F90 8420 2017-08-08 12:18:46Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_thd_dh
+      !!------------------------------------------------------------------
+      !!                ***  ROUTINE ice_thd_dh  ***
+      !!
+      !! ** Purpose :   determines variations of ice and snow thicknesses.
+      !!
+      !! ** Method  :   Ice/Snow surface melting arises from imbalance in surface fluxes
+      !!              Bottom accretion/ablation arises from flux budget
+      !!              Snow thickness can increase by precipitation and decrease by sublimation
+      !!              If snow load excesses Archmiede limit, snow-ice is formed by
+      !!              the flooding of sea-water in the snow
+      !!
+      !!                 1) Compute available flux of heat for surface ablation
+      !!                 2) Compute snow and sea ice enthalpies
+      !!                 3) Surface ablation and sublimation
+      !!                 4) Bottom accretion/ablation
+      !!                 5) Case of Total ablation
+      !!                 6) Snow ice formation
+      !!
+      !! References : Bitz and Lipscomb, 1999, J. Geophys. Res.
+      !!              Fichefet T. and M. Maqueda 1997, J. Geophys. Res., 102(C6), 12609-12646   
+      !!              Vancoppenolle, Fichefet and Bitz, 2005, Geophys. Res. Let. 
+      !!              Vancoppenolle et al.,2009, Ocean Modelling
+      !!------------------------------------------------------------------
+      INTEGER  ::   ji , jk        ! dummy loop indices
+      INTEGER  ::   iter
+
+      REAL(wp) ::   ztmelts             ! local scalar
+      REAL(wp) ::   zdum       
+      REAL(wp) ::   zfracs       ! fractionation coefficient for bottom salt entrapment
+      REAL(wp) ::   zswi1        ! switch for computation of bottom salinity
+      REAL(wp) ::   zswi12       ! switch for computation of bottom salinity
+      REAL(wp) ::   zswi2        ! switch for computation of bottom salinity
+      REAL(wp) ::   zgrr         ! bottom growth rate
+      REAL(wp) ::   zt_i_new     ! bottom formation temperature
+
+      REAL(wp) ::   zQm          ! enthalpy exchanged with the ocean (J/m2), >0 towards the ocean
+      REAL(wp) ::   zEi          ! specific enthalpy of sea ice (J/kg)
+      REAL(wp) ::   zEw          ! specific enthalpy of exchanged water (J/kg)
+      REAL(wp) ::   zdE          ! specific enthalpy difference (J/kg)
+      REAL(wp) ::   zfmdt        ! exchange mass flux x time step (J/m2), >0 towards the ocean
+
+      REAL(wp), DIMENSION(jpij) ::   zqprec      ! energy of fallen snow                       (J.m-3)
+      REAL(wp), DIMENSION(jpij) ::   zq_su       ! heat for surface ablation                   (J.m-2)
+      REAL(wp), DIMENSION(jpij) ::   zq_bo       ! heat for bottom ablation                    (J.m-2)
+      REAL(wp), DIMENSION(jpij) ::   zq_rema     ! remaining heat at the end of the routine    (J.m-2)
+      REAL(wp), DIMENSION(jpij) ::   zf_tt       ! Heat budget to determine melting or freezing(W.m-2)
+      REAL(wp), DIMENSION(jpij) ::   zevap_rema  ! remaining mass flux from sublimation        (kg.m-2)
+
+      REAL(wp), DIMENSION(jpij) ::   zdh_s_mel   ! snow melt 
+      REAL(wp), DIMENSION(jpij) ::   zdh_s_pre   ! snow precipitation 
+      REAL(wp), DIMENSION(jpij) ::   zdh_s_sub   ! snow sublimation
+
+      REAL(wp), DIMENSION(jpij,nlay_i) ::   zdeltah
+      REAL(wp), DIMENSION(jpij,nlay_i) ::   zh_i      ! ice layer thickness
+      INTEGER , DIMENSION(jpij,nlay_i) ::   icount    ! number of layers vanished by melting 
+
+      REAL(wp), DIMENSION(jpij) ::   zeh_i       ! total ice heat content  (J.m-2)
+      REAL(wp), DIMENSION(jpij) ::   zsnw        ! distribution of snow after wind blowing
+
+      REAL(wp) :: zswitch_sal
+
+      ! Heat conservation 
+      INTEGER  ::   num_iter_max
+      !!------------------------------------------------------------------
+
+      ! Discriminate between varying salinity (nn_icesal=2) and prescribed cases (other values)
+      SELECT CASE( nn_icesal )                  ! varying salinity or not
+         CASE( 1, 3 ) ;   zswitch_sal = 0._wp   ! prescribed salinity profile
+         CASE( 2 )    ;   zswitch_sal = 1._wp   ! varying salinity profile
+      END SELECT
+
+      DO ji = 1, nidx
+         icount (ji,:) = 0
+         zdh_s_mel(ji) = 0._wp
+         e_i_1d(ji,nlay_i+1) = 0._wp ! Initialize enthalpy at nlay_i+1
+      END DO
+
+      ! initialize layer thicknesses and enthalpies
+      h_i_old (1:nidx,0:nlay_i+1) = 0._wp
+      eh_i_old(1:nidx,0:nlay_i+1) = 0._wp
+      DO jk = 1, nlay_i
+         DO ji = 1, nidx
+            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
+      !
+      !------------------------------------------------------------------------------!
+      !  1) Calculate available heat for surface and bottom ablation                 !
+      !------------------------------------------------------------------------------!
+      !
+      DO ji = 1, nidx
+         zdum       = qns_ice_1d(ji) + ( 1._wp - i0(ji) ) * qsr_ice_1d(ji) - fc_su(ji) 
+         zf_tt(ji)  = fc_bo_i(ji) + fhtur_1d(ji) + fhld_1d(ji) 
+
+         zq_su (ji) = MAX( 0._wp, zdum      * rdt_ice ) * MAX( 0._wp , SIGN( 1._wp, t_su_1d(ji) - rt0 ) )
+         zq_bo (ji) = MAX( 0._wp, zf_tt(ji) * rdt_ice )
+      END DO
+
+      !
+      !------------------------------------------------------------------------------!
+      ! If snow temperature is above freezing point, then snow melts 
+      ! (should not happen but sometimes it does)
+      !------------------------------------------------------------------------------!
+      DO ji = 1, nidx
+         IF( t_s_1d(ji,1) > rt0 ) THEN !!! Internal melting
+            ! Contribution to heat flux to the ocean [W.m-2], < 0  
+            hfx_res_1d(ji) = hfx_res_1d(ji) + e_s_1d(ji,1) * ht_s_1d(ji) * a_i_1d(ji) * r1_rdtice
+            ! Contribution to mass flux
+            wfx_snw_sum_1d(ji) = wfx_snw_sum_1d(ji) + rhosn * ht_s_1d(ji) * a_i_1d(ji) * r1_rdtice
+            ! updates
+            ht_s_1d(ji)   = 0._wp
+            e_s_1d (ji,1) = 0._wp
+            t_s_1d (ji,1) = rt0
+         END IF
+      END DO
+
+      !------------------------------------------------------------!
+      !  2) Computing layer thicknesses and enthalpies.            !
+      !------------------------------------------------------------!
+      !
+      DO jk = 1, nlay_i
+         DO ji = 1, nidx
+            zh_i(ji,jk) = ht_i_1d(ji) * r1_nlay_i
+            zeh_i(ji)   = zeh_i(ji) + e_i_1d(ji,jk) * zh_i(ji,jk)
+         END DO
+      END DO
+      !
+      !------------------------------------------------------------------------------|
+      !  3) Surface ablation and sublimation                                         |
+      !------------------------------------------------------------------------------|
+      !
+      !-------------------------
+      ! 3.1 Snow precips / melt
+      !-------------------------
+      ! Snow accumulation in one thermodynamic time step
+      ! snowfall is partitionned between leads and ice
+      ! if snow fall was uniform, a fraction (1-at_i) would fall into leads
+      ! but because of the winds, more snow falls on leads than on sea ice
+      ! and a greater fraction (1-at_i)^beta of the total mass of snow 
+      ! (beta < 1) falls in leads.
+      ! In reality, beta depends on wind speed, 
+      ! and should decrease with increasing wind speed but here, it is 
+      ! considered as a constant. an average value is 0.66
+      ! Martin Vancoppenolle, December 2006
+
+      CALL ice_thd_snwblow( 1. - at_i_1d(1:nidx), zsnw(1:nidx) ) ! snow distribution over ice after wind blowing
+
+      zdeltah(1:nidx,:) = 0._wp
+      DO ji = 1, nidx
+         !-----------
+         ! Snow fall
+         !-----------
+         ! thickness change
+         zdh_s_pre(ji) = zsnw(ji) * sprecip_1d(ji) * rdt_ice * r1_rhosn / at_i_1d(ji)
+         ! enthalpy of the precip (>0, J.m-3)
+         zqprec   (ji) = - qprec_ice_1d(ji)   
+         IF( sprecip_1d(ji) == 0._wp ) zqprec(ji) = 0._wp
+         ! heat flux from snow precip (>0, W.m-2)
+         hfx_spr_1d(ji) = hfx_spr_1d(ji) + zdh_s_pre(ji) * a_i_1d(ji) * zqprec(ji) * r1_rdtice
+         ! mass flux, <0
+         wfx_spr_1d(ji) = wfx_spr_1d(ji) - rhosn * a_i_1d(ji) * zdh_s_pre(ji) * r1_rdtice
+
+         !---------------------
+         ! Melt of falling snow
+         !---------------------
+         ! thickness change
+         rswitch        = MAX( 0._wp , SIGN( 1._wp , zqprec(ji) - epsi20 ) )
+         zdeltah (ji,1) = - rswitch * zq_su(ji) / MAX( zqprec(ji) , epsi20 )
+         zdeltah (ji,1) = MAX( - zdh_s_pre(ji), zdeltah(ji,1) ) ! bound melting 
+         ! heat used to melt snow (W.m-2, >0)
+         hfx_snw_1d(ji) = hfx_snw_1d(ji) - zdeltah(ji,1) * a_i_1d(ji) * zqprec(ji) * r1_rdtice
+         ! snow melting only = water into the ocean (then without snow precip), >0
+         wfx_snw_sum_1d(ji) = wfx_snw_sum_1d(ji) - rhosn * a_i_1d(ji) * zdeltah(ji,1) * r1_rdtice
+         ! updates available heat + precipitations after melting
+         zq_su     (ji) = MAX( 0._wp , zq_su (ji) + zdeltah(ji,1) * zqprec(ji) )      
+         zdh_s_pre (ji) = zdh_s_pre(ji) + zdeltah(ji,1)
+
+         ! update thickness
+         ht_s_1d(ji) = MAX( 0._wp , ht_s_1d(ji) + zdh_s_pre(ji) )
+      END DO
+
+      ! If heat still available (zq_su > 0), then melt more snow
+      zdeltah(1:nidx,:) = 0._wp
+      DO jk = 1, nlay_s
+         DO ji = 1, nidx
+            ! thickness change
+            rswitch          = 1._wp - MAX( 0._wp, SIGN( 1._wp, - ht_s_1d(ji) ) ) 
+            rswitch          = rswitch * ( MAX( 0._wp, SIGN( 1._wp, e_s_1d(ji,jk) - epsi20 ) ) ) 
+            zdeltah  (ji,jk) = - rswitch * zq_su(ji) / MAX( e_s_1d(ji,jk), epsi20 )
+            zdeltah  (ji,jk) = MAX( zdeltah(ji,jk) , - ht_s_1d(ji) ) ! bound melting
+            zdh_s_mel(ji)    = zdh_s_mel(ji) + zdeltah(ji,jk)    
+            ! heat used to melt snow(W.m-2, >0)
+            hfx_snw_1d(ji)   = hfx_snw_1d(ji) - zdeltah(ji,jk) * a_i_1d(ji) * e_s_1d(ji,jk) * r1_rdtice 
+            ! snow melting only = water into the ocean (then without snow precip)
+            wfx_snw_sum_1d(ji)   = wfx_snw_sum_1d(ji) - rhosn * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
+            ! updates available heat + thickness
+            zq_su (ji)  = MAX( 0._wp , zq_su (ji) + zdeltah(ji,jk) * e_s_1d(ji,jk) )
+            ht_s_1d(ji) = MAX( 0._wp , ht_s_1d(ji) + zdeltah(ji,jk) )
+         END DO
+      END DO
+
+      !------------------------------
+      ! 3.2 Sublimation (part1: snow) 
+      !------------------------------
+      ! qla_ice is always >=0 (upwards), heat goes to the atmosphere, therefore snow sublimates
+      ! clem comment: not counted in mass/heat exchange in iceupdate.F90 since this is an exchange with atm. (not ocean)
+      zdeltah(1:nidx,:) = 0._wp
+      DO ji = 1, nidx
+         zdh_s_sub(ji)  = MAX( - ht_s_1d(ji) , - evap_ice_1d(ji) * r1_rhosn * rdt_ice )
+         ! remaining evap in kg.m-2 (used for ice melting later on)
+         zevap_rema(ji)  = evap_ice_1d(ji) * rdt_ice + zdh_s_sub(ji) * rhosn
+         ! Heat flux by sublimation [W.m-2], < 0 (sublimate first snow that had fallen, then pre-existing snow)
+         zdeltah(ji,1)  = MAX( zdh_s_sub(ji), - zdh_s_pre(ji) )
+         hfx_sub_1d(ji) = hfx_sub_1d(ji) + ( zdeltah(ji,1) * zqprec(ji) + ( zdh_s_sub(ji) - zdeltah(ji,1) ) * e_s_1d(ji,1)  &
+            &                              ) * a_i_1d(ji) * r1_rdtice
+         ! Mass flux by sublimation
+         wfx_snw_sub_1d(ji) = wfx_snw_sub_1d(ji) - rhosn * a_i_1d(ji) * zdh_s_sub(ji) * r1_rdtice
+
+         ! new snow thickness
+         ht_s_1d(ji)    =  MAX( 0._wp , ht_s_1d(ji) + zdh_s_sub(ji) )
+         ! update precipitations after sublimation and correct sublimation
+         zdh_s_pre(ji) = zdh_s_pre(ji) + zdeltah(ji,1)
+         zdh_s_sub(ji) = zdh_s_sub(ji) - zdeltah(ji,1)
+      END DO
+      
+      ! --- Update snow diags --- !
+      DO ji = 1, nidx
+         dh_s_tot(ji) = zdh_s_mel(ji) + zdh_s_pre(ji) + zdh_s_sub(ji)
+      END DO
+
+      !-------------------------------------------
+      ! 3.3 Update temperature, energy
+      !-------------------------------------------
+      ! new temp and enthalpy of the snow (remaining snow precip + remaining pre-existing snow)
+      DO jk = 1, nlay_s
+         DO ji = 1,nidx
+            rswitch       = MAX( 0._wp , SIGN( 1._wp, ht_s_1d(ji) - epsi20 ) )
+            e_s_1d(ji,jk) = rswitch / MAX( ht_s_1d(ji), epsi20 ) *           &
+              &            ( ( zdh_s_pre(ji)               ) * zqprec(ji) +  &
+              &              ( ht_s_1d(ji) - zdh_s_pre(ji) ) * rhosn * ( cpic * ( rt0 - t_s_1d(ji,jk) ) + lfus ) )
+         END DO
+      END DO
+
+      !--------------------------
+      ! 3.4 Surface ice ablation 
+      !--------------------------
+      zdeltah(1:nidx,:) = 0._wp ! important
+      DO jk = 1, nlay_i
+         DO ji = 1, nidx
+            ztmelts           = - tmut * s_i_1d(ji,jk) + rt0          ! Melting point of layer k [K]
+            
+            IF( t_i_1d(ji,jk) >= ztmelts ) THEN !!! Internal melting
+
+               zEi            = - e_i_1d(ji,jk) * r1_rhoic            ! Specific enthalpy of layer k [J/kg, <0]       
+               zdE            = 0._wp                                 ! Specific enthalpy difference   (J/kg, <0)
+                                                                      ! set up at 0 since no energy is needed to melt water...(it is already melted)
+               zdeltah(ji,jk) = MIN( 0._wp , - zh_i(ji,jk) )          ! internal melting occurs when the internal temperature is above freezing     
+                                                                      ! this should normally not happen, but sometimes, heat diffusion leads to this
+               zfmdt          = - zdeltah(ji,jk) * rhoic              ! Mass flux x time step > 0
+                         
+               dh_i_surf(ji)  = dh_i_surf(ji) + zdeltah(ji,jk)        ! Cumulate surface melt
+               
+               zfmdt          = - rhoic * zdeltah(ji,jk)              ! Recompute mass flux [kg/m2, >0]
+
+               ! Contribution to heat flux to the ocean [W.m-2], <0 (ice enthalpy zEi is "sent" to the ocean) 
+               hfx_res_1d(ji) = hfx_res_1d(ji) + zfmdt * a_i_1d(ji) * zEi * r1_rdtice
+               
+               ! Contribution to salt flux (clem: using sm_i_1d and not s_i_1d(jk) is ok)
+               sfx_res_1d(ji) = sfx_res_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * sm_i_1d(ji) * r1_rdtice
+               
+               ! Contribution to mass flux
+               wfx_res_1d(ji) =  wfx_res_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
+
+            ELSE                                !!! Surface melting
+               
+               zEi            = - e_i_1d(ji,jk) * r1_rhoic            ! Specific enthalpy of layer k [J/kg, <0]
+               zEw            =    rcp * ( ztmelts - rt0 )            ! Specific enthalpy of resulting meltwater [J/kg, <0]
+               zdE            =    zEi - zEw                          ! Specific enthalpy difference < 0
+               
+               zfmdt          = - zq_su(ji) / zdE                     ! Mass flux to the ocean [kg/m2, >0]
+               
+               zdeltah(ji,jk) = - zfmdt * r1_rhoic                    ! Melt of layer jk [m, <0]
+               
+               zdeltah(ji,jk) = MIN( 0._wp , MAX( zdeltah(ji,jk) , - zh_i(ji,jk) ) )    ! Melt of layer jk cannot exceed the layer thickness [m, <0]
+               
+               zq_su(ji)      = MAX( 0._wp , zq_su(ji) - zdeltah(ji,jk) * rhoic * zdE ) ! update available heat
+               
+               dh_i_surf(ji)  = dh_i_surf(ji) + zdeltah(ji,jk)        ! Cumulate surface melt
+               
+               zfmdt          = - rhoic * zdeltah(ji,jk)              ! Recompute mass flux [kg/m2, >0]
+               
+               zQm            = zfmdt * zEw                           ! Energy of the melt water sent to the ocean [J/m2, <0]
+               
+               ! Contribution to salt flux >0 (clem: using sm_i_1d and not s_i_1d(jk) is ok)
+               sfx_sum_1d(ji) = sfx_sum_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * sm_i_1d(ji) * r1_rdtice
+               
+               ! Contribution to heat flux [W.m-2], < 0
+               hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice
+               
+               ! Total heat flux used in this process [W.m-2], > 0  
+               hfx_sum_1d(ji) = hfx_sum_1d(ji) - zfmdt * a_i_1d(ji) * zdE * r1_rdtice
+               
+               ! Contribution to mass flux
+               wfx_sum_1d(ji) =  wfx_sum_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
+               
+            END IF
+            ! ----------------------
+            ! Sublimation part2: ice
+            ! ----------------------
+            zdum      = MAX( - ( zh_i(ji,jk) + zdeltah(ji,jk) ) , - zevap_rema(ji) * r1_rhoic )
+            zdeltah(ji,jk) = zdeltah(ji,jk) + zdum
+            dh_i_sub(ji)  = dh_i_sub(ji) + zdum
+            ! Salt flux > 0 (clem2016: flux is sent to the ocean for simplicity but salt should remain in the ice except if all ice is melted.
+            !                          It must be corrected at some point)
+            sfx_sub_1d(ji) = sfx_sub_1d(ji) - rhoic * a_i_1d(ji) * zdum * sm_i_1d(ji) * r1_rdtice
+            ! Heat flux [W.m-2], < 0
+            hfx_sub_1d(ji) = hfx_sub_1d(ji) + zdum * e_i_1d(ji,jk) * a_i_1d(ji) * r1_rdtice
+            ! Mass flux > 0
+            wfx_ice_sub_1d(ji) =  wfx_ice_sub_1d(ji) - rhoic * a_i_1d(ji) * zdum * r1_rdtice
+
+            ! update remaining mass flux
+            zevap_rema(ji)  = zevap_rema(ji) + zdum * rhoic
+            
+            ! record which layers have disappeared (for bottom melting) 
+            !    => icount=0 : no layer has vanished
+            !    => icount=5 : 5 layers have vanished
+            rswitch       = MAX( 0._wp , SIGN( 1._wp , - ( zh_i(ji,jk) + zdeltah(ji,jk) ) ) ) 
+            icount(ji,jk) = NINT( rswitch )
+            zh_i(ji,jk)   = MAX( 0._wp , zh_i(ji,jk) + zdeltah(ji,jk) )
+                        
+            ! update heat content (J.m-2) and layer thickness
+            eh_i_old(ji,jk) = eh_i_old(ji,jk) + zdeltah(ji,jk) * e_i_1d(ji,jk)
+            h_i_old (ji,jk) = h_i_old (ji,jk) + zdeltah(ji,jk)
+         END DO
+      END DO
+      ! update ice thickness
+      DO ji = 1, nidx
+         ht_i_1d(ji) =  MAX( 0._wp , ht_i_1d(ji) + dh_i_surf(ji) + dh_i_sub(ji) )
+      END DO
+
+      ! remaining "potential" evap is sent to ocean
+      DO ji = 1, nidx
+         wfx_err_sub_1d(ji) = wfx_err_sub_1d(ji) - zevap_rema(ji) * a_i_1d(ji) * r1_rdtice  ! <=0 (net evap for the ocean in kg.m-2.s-1)
+      END DO
+
+      !
+      !------------------------------------------------------------------------------!
+      ! 4) Basal growth / melt                                                       !
+      !------------------------------------------------------------------------------!
+      !
+      !------------------
+      ! 4.1 Basal growth 
+      !------------------
+      ! Basal growth is driven by heat imbalance at the ice-ocean interface,
+      ! between the inner conductive flux  (fc_bo_i), from the open water heat flux 
+      ! (fhld) and the turbulent ocean flux (fhtur). 
+      ! fc_bo_i is positive downwards. fhtur and fhld are positive to the ice 
+
+      ! If salinity varies in time, an iterative procedure is required, because
+      ! the involved quantities are inter-dependent.
+      ! Basal growth (dh_i_bott) depends upon new ice specific enthalpy (zEi),
+      ! which depends on forming ice salinity (s_i_new), which depends on dh/dt (dh_i_bott)
+      ! -> need for an iterative procedure, which converges quickly
+
+      num_iter_max = 1
+      IF( nn_icesal == 2 ) num_iter_max = 5
+
+      ! Iterative procedure
+      DO ji = 1, nidx
+         IF(  zf_tt(ji) < 0._wp  ) THEN
+            DO iter = 1, num_iter_max
+
+               ! New bottom ice salinity (Cox & Weeks, JGR88 )
+               !--- zswi1  if dh/dt < 2.0e-8
+               !--- zswi12 if 2.0e-8 < dh/dt < 3.6e-7 
+               !--- zswi2  if dh/dt > 3.6e-7
+               zgrr               = MIN( 1.0e-3, MAX ( dh_i_bott(ji) * r1_rdtice , epsi10 ) )
+               zswi2              = MAX( 0._wp , SIGN( 1._wp , zgrr - 3.6e-7 ) )
+               zswi12             = MAX( 0._wp , SIGN( 1._wp , zgrr - 2.0e-8 ) ) * ( 1.0 - zswi2 )
+               zswi1              = 1. - zswi2 * zswi12
+               zfracs             = MIN ( zswi1  * 0.12 + zswi12 * ( 0.8925 + 0.0568 * LOG( 100.0 * zgrr ) )   &
+                  &               + zswi2  * 0.26 / ( 0.26 + 0.74 * EXP ( - 724300.0 * zgrr ) )  , 0.5 )
+
+               s_i_new(ji)        = zswitch_sal * zfracs * sss_1d(ji)  &  ! New ice salinity
+                                  + ( 1. - zswitch_sal ) * sm_i_1d(ji) 
+               ! New ice growth
+               ztmelts            = - tmut * s_i_new(ji) + rt0          ! New ice melting point (K)
+
+               zt_i_new           = zswitch_sal * t_bo_1d(ji) + ( 1. - zswitch_sal) * t_i_1d(ji, nlay_i)
+               
+               zEi                = cpic * ( zt_i_new - ztmelts ) &     ! Specific enthalpy of forming ice (J/kg, <0)      
+                  &               - lfus * ( 1.0 - ( ztmelts - rt0 ) / ( zt_i_new - rt0 ) )   &
+                  &               + rcp  * ( ztmelts-rt0 )          
+
+               zEw                = rcp  * ( t_bo_1d(ji) - rt0 )         ! Specific enthalpy of seawater (J/kg, < 0)
+
+               zdE                = zEi - zEw                           ! Specific enthalpy difference (J/kg, <0)
+
+               dh_i_bott(ji)      = rdt_ice * MAX( 0._wp , zf_tt(ji) / ( zdE * rhoic ) )
+
+               e_i_1d(ji,nlay_i+1) = -zEi * rhoic                        ! New ice energy of melting (J/m3, >0)
+               
+            END DO
+            ! Contribution to Energy and Salt Fluxes                                    
+            zfmdt          = - rhoic * dh_i_bott(ji)             ! Mass flux x time step (kg/m2, < 0)
+
+            ztmelts        = - tmut * s_i_new(ji) + rt0          ! New ice melting point (K)
+            
+            zt_i_new       = zswitch_sal * t_bo_1d(ji) + ( 1. - zswitch_sal) * t_i_1d(ji, nlay_i)
+            
+            zEi            = cpic * ( zt_i_new - ztmelts ) &     ! Specific enthalpy of forming ice (J/kg, <0)      
+               &               - lfus * ( 1.0 - ( ztmelts - rt0 ) / ( zt_i_new - rt0 ) )   &
+               &               + rcp  * ( ztmelts-rt0 )          
+            
+            zEw            = rcp  * ( t_bo_1d(ji) - rt0 )         ! Specific enthalpy of seawater (J/kg, < 0)
+            
+            zdE            = zEi - zEw                           ! Specific enthalpy difference (J/kg, <0)
+            
+            ! Contribution to heat flux to the ocean [W.m-2], >0  
+            hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice
+
+            ! Total heat flux used in this process [W.m-2], <0  
+            hfx_bog_1d(ji) = hfx_bog_1d(ji) - zfmdt * a_i_1d(ji) * zdE * r1_rdtice
+            
+            ! Contribution to salt flux, <0
+            sfx_bog_1d(ji) = sfx_bog_1d(ji) - rhoic * a_i_1d(ji) * dh_i_bott(ji) * s_i_new(ji) * r1_rdtice
+
+            ! Contribution to mass flux, <0
+            wfx_bog_1d(ji) =  wfx_bog_1d(ji) - rhoic * a_i_1d(ji) * dh_i_bott(ji) * r1_rdtice
+
+            ! update heat content (J.m-2) and layer thickness
+            eh_i_old(ji,nlay_i+1) = eh_i_old(ji,nlay_i+1) + dh_i_bott(ji) * e_i_1d(ji,nlay_i+1)
+            h_i_old (ji,nlay_i+1) = h_i_old (ji,nlay_i+1) + dh_i_bott(ji)
+
+         ENDIF
+
+      END DO
+
+      !----------------
+      ! 4.2 Basal melt
+      !----------------
+      zdeltah(1:nidx,:) = 0._wp ! important
+      DO jk = nlay_i, 1, -1
+         DO ji = 1, nidx
+            IF(  zf_tt(ji)  >  0._wp  .AND. jk > icount(ji,jk) ) THEN   ! do not calculate where layer has already disappeared by surface melting 
+
+               ztmelts = - tmut * s_i_1d(ji,jk) + rt0  ! Melting point of layer jk (K)
+
+               IF( t_i_1d(ji,jk) >= ztmelts ) THEN !!! Internal melting
+
+                  zEi               = - e_i_1d(ji,jk) * r1_rhoic    ! Specific enthalpy of melting ice (J/kg, <0)
+                  zdE               = 0._wp                         ! Specific enthalpy difference   (J/kg, <0)
+                                                                    ! set up at 0 since no energy is needed to melt water...(it is already melted)
+                  zdeltah   (ji,jk) = MIN( 0._wp , - zh_i(ji,jk) )  ! internal melting occurs when the internal temperature is above freezing     
+                                                                    ! this should normally not happen, but sometimes, heat diffusion leads to this
+
+                  dh_i_bott (ji)    = dh_i_bott(ji) + zdeltah(ji,jk)
+
+                  zfmdt             = - zdeltah(ji,jk) * rhoic      ! Mass flux x time step > 0
+
+                  ! Contribution to heat flux to the ocean [W.m-2], <0 (ice enthalpy zEi is "sent" to the ocean) 
+                  hfx_res_1d(ji) = hfx_res_1d(ji) + zfmdt * a_i_1d(ji) * zEi * r1_rdtice
+
+                  ! Contribution to salt flux (clem: using sm_i_1d and not s_i_1d(jk) is ok)
+                  sfx_res_1d(ji) = sfx_res_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * sm_i_1d(ji) * r1_rdtice
+                                    
+                  ! Contribution to mass flux
+                  wfx_res_1d(ji) =  wfx_res_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
+
+                  ! update heat content (J.m-2) and layer thickness
+                  eh_i_old(ji,jk) = eh_i_old(ji,jk) + zdeltah(ji,jk) * e_i_1d(ji,jk)
+                  h_i_old (ji,jk) = h_i_old (ji,jk) + zdeltah(ji,jk)
+
+               ELSE                               !!! Basal melting
+
+                  zEi             = - e_i_1d(ji,jk) * r1_rhoic ! Specific enthalpy of melting ice (J/kg, <0)
+                  zEw             = rcp * ( ztmelts - rt0 )    ! Specific enthalpy of meltwater (J/kg, <0)
+                  zdE             = zEi - zEw                  ! Specific enthalpy difference   (J/kg, <0)
+
+                  zfmdt           = - zq_bo(ji) / zdE          ! Mass flux x time step (kg/m2, >0)
+
+                  zdeltah(ji,jk)  = - zfmdt * r1_rhoic         ! Gross thickness change
+
+                  zdeltah(ji,jk)  = MIN( 0._wp , MAX( zdeltah(ji,jk), - zh_i(ji,jk) ) ) ! bound thickness change
+                  
+                  zq_bo(ji)       = MAX( 0._wp , zq_bo(ji) - zdeltah(ji,jk) * rhoic * zdE ) ! update available heat. MAX is necessary for roundup errors
+
+                  dh_i_bott(ji)   = dh_i_bott(ji) + zdeltah(ji,jk)    ! Update basal melt
+
+                  zfmdt           = - zdeltah(ji,jk) * rhoic          ! Mass flux x time step > 0
+
+                  zQm             = zfmdt * zEw         ! Heat exchanged with ocean
+
+                  ! Contribution to heat flux to the ocean [W.m-2], <0  
+                  hfx_thd_1d(ji)  = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice
+
+                  ! Contribution to salt flux (clem: using sm_i_1d and not s_i_1d(jk) is ok)
+                  sfx_bom_1d(ji)  = sfx_bom_1d(ji) - rhoic *  a_i_1d(ji) * zdeltah(ji,jk) * sm_i_1d(ji) * r1_rdtice
+                  
+                  ! Total heat flux used in this process [W.m-2], >0  
+                  hfx_bom_1d(ji)  = hfx_bom_1d(ji) - zfmdt * a_i_1d(ji) * zdE * r1_rdtice
+                  
+                  ! Contribution to mass flux
+                  wfx_bom_1d(ji)  =  wfx_bom_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
+
+                  ! update heat content (J.m-2) and layer thickness
+                  eh_i_old(ji,jk) = eh_i_old(ji,jk) + zdeltah(ji,jk) * e_i_1d(ji,jk)
+                  h_i_old (ji,jk) = h_i_old (ji,jk) + zdeltah(ji,jk)
+               ENDIF
+           
+            ENDIF
+         END DO
+      END DO
+
+      !-------------------------------------------
+      ! Update temperature, energy
+      !-------------------------------------------
+      DO ji = 1, nidx
+         ht_i_1d(ji) =  MAX( 0._wp , ht_i_1d(ji) + dh_i_bott(ji) )
+      END DO  
+
+      !-------------------------------------------
+      ! 5. What to do with remaining energy
+      !-------------------------------------------
+      ! If heat still available for melting and snow remains, then melt more snow
+      !-------------------------------------------
+      zdeltah(1:nidx,:) = 0._wp ! important
+      DO ji = 1, nidx
+         zq_rema(ji)     = zq_su(ji) + zq_bo(ji) 
+         rswitch         = 1._wp - MAX( 0._wp, SIGN( 1._wp, - ht_s_1d(ji) ) )   ! =1 if snow
+         rswitch         = rswitch * MAX( 0._wp, SIGN( 1._wp, e_s_1d(ji,1) - epsi20 ) )
+         zdeltah  (ji,1) = - rswitch * zq_rema(ji) / MAX( e_s_1d(ji,1), epsi20 )
+         zdeltah  (ji,1) = MIN( 0._wp , MAX( zdeltah(ji,1) , - ht_s_1d(ji) ) ) ! bound melting
+         dh_s_tot (ji)   = dh_s_tot(ji)  + zdeltah(ji,1)
+         ht_s_1d   (ji)  = ht_s_1d(ji)   + zdeltah(ji,1)
+        
+         zq_rema(ji)     = zq_rema(ji) + zdeltah(ji,1) * e_s_1d(ji,1)                ! update available heat (J.m-2)
+         ! heat used to melt snow
+         hfx_snw_1d(ji)  = hfx_snw_1d(ji) - zdeltah(ji,1) * a_i_1d(ji) * e_s_1d(ji,1) * r1_rdtice ! W.m-2 (>0)
+         ! Contribution to mass flux
+         wfx_snw_sum_1d(ji)  =  wfx_snw_sum_1d(ji) - rhosn * a_i_1d(ji) * zdeltah(ji,1) * r1_rdtice
+         !    
+         ! Remaining heat flux (W.m-2) is sent to the ocean heat budget
+         hfx_out_1d(ji)  = hfx_out_1d(ji) + ( zq_rema(ji) * a_i_1d(ji) ) * r1_rdtice
+
+         IF( ln_limctl .AND. zq_rema(ji) < 0. .AND. lwp ) WRITE(numout,*) 'ALERTE zq_rema <0 = ', zq_rema(ji)
+      END DO
+
+      !
+      !------------------------------------------------------------------------------|
+      !  6) Snow-Ice formation                                                       |
+      !------------------------------------------------------------------------------|
+      ! When snow load excesses Archimede's limit, snow-ice interface goes down under sea-level, 
+      ! flooding of seawater transforms snow into ice dh_snowice is positive for the ice
+      DO ji = 1, nidx
+         !
+         dh_snowice(ji) = MAX(  0._wp , ( rhosn * ht_s_1d(ji) + (rhoic-rau0) * ht_i_1d(ji) ) / ( rhosn+rau0-rhoic )  )
+
+         ht_i_1d(ji)    = ht_i_1d(ji) + dh_snowice(ji)
+         ht_s_1d(ji)    = ht_s_1d(ji) - dh_snowice(ji)
+
+         ! Contribution to energy flux to the ocean [J/m2], >0 (if sst<0)
+         zfmdt          = ( rhosn - rhoic ) * dh_snowice(ji)    ! <0
+         zEw            = rcp * sst_1d(ji)
+         zQm            = zfmdt * zEw 
+         
+         ! Contribution to heat flux
+         hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice 
+
+         ! Contribution to salt flux
+         sfx_sni_1d(ji) = sfx_sni_1d(ji) + sss_1d(ji) * a_i_1d(ji) * zfmdt * r1_rdtice 
+
+         ! virtual salt flux to keep salinity constant
+         IF( nn_icesal == 1 .OR. nn_icesal == 3 )  THEN
+            sfx_bri_1d(ji) = sfx_bri_1d(ji) - sss_1d (ji) * a_i_1d(ji) * zfmdt                  * r1_rdtice  & ! put back sss_m     into the ocean
+               &                            - sm_i_1d(ji) * a_i_1d(ji) * dh_snowice(ji) * rhoic * r1_rdtice    ! and get  rn_icesal from the ocean 
+         ENDIF
+
+         ! Contribution to mass flux
+         ! All snow is thrown in the ocean, and seawater is taken to replace the volume
+         wfx_sni_1d(ji)     = wfx_sni_1d(ji)     - a_i_1d(ji) * dh_snowice(ji) * rhoic * r1_rdtice
+         wfx_snw_sni_1d(ji) = wfx_snw_sni_1d(ji) + a_i_1d(ji) * dh_snowice(ji) * rhosn * r1_rdtice
+
+         ! update heat content (J.m-2) and layer thickness
+         eh_i_old(ji,0) = eh_i_old(ji,0) + dh_snowice(ji) * e_s_1d(ji,1) + zfmdt * zEw
+         h_i_old (ji,0) = h_i_old (ji,0) + dh_snowice(ji)
+         
+      END DO
+
+      !
+      !-------------------------------------------
+      ! Update temperature, energy
+      !-------------------------------------------
+      DO ji = 1, nidx
+         rswitch     =  1.0 - MAX( 0._wp , SIGN( 1._wp , - ht_i_1d(ji) ) ) 
+         t_su_1d(ji) =  rswitch * t_su_1d(ji) + ( 1.0 - rswitch ) * rt0
+      END DO
+
+      DO jk = 1, nlay_s
+         DO ji = 1,nidx
+            ! mask enthalpy
+            rswitch       = 1._wp - MAX(  0._wp , SIGN( 1._wp, - ht_s_1d(ji) )  )
+            e_s_1d(ji,jk) = rswitch * e_s_1d(ji,jk)
+            ! recalculate t_s_1d from e_s_1d
+            t_s_1d(ji,jk) = rt0 + rswitch * ( - e_s_1d(ji,jk) / ( rhosn * cpic ) + lfus / cpic )
+         END DO
+      END DO
+
+      ! --- ensure that a_i = 0 where ht_i = 0 ---
+      DO ji = 1, nidx
+         IF( ht_i_1d(ji) == 0._wp )   a_i_1d(ji) = 0._wp
+      END DO         
+      !
+   END SUBROUTINE ice_thd_dh
+
+
+   !!--------------------------------------------------------------------------
+   !! INTERFACE ice_thd_snwblow
+   !! ** Purpose :   Compute distribution of precip over the ice
+   !!--------------------------------------------------------------------------
+   SUBROUTINE ice_thd_snwblow_2d( pin, pout )
+      REAL(wp), DIMENSION(:,:), INTENT(in   ) :: pin   ! previous fraction lead ( 1. - a_i_b )
+      REAL(wp), DIMENSION(:,:), INTENT(inout) :: pout
+      pout = ( 1._wp - ( pin )**rn_betas )
+   END SUBROUTINE ice_thd_snwblow_2d
+
+   SUBROUTINE ice_thd_snwblow_1d( pin, pout )
+      REAL(wp), DIMENSION(:), INTENT(in   ) :: pin
+      REAL(wp), DIMENSION(:), INTENT(inout) :: pout
+      pout = ( 1._wp - ( pin )**rn_betas )
+   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
+
+   !!======================================================================
+END MODULE icethd_dh
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 8422)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_dif.F90	(revision 8422)
@@ -0,0 +1,837 @@
+MODULE icethd_dif
+   !!======================================================================
+   !!                       ***  MODULE icethd_dif ***
+   !!                       heat diffusion in sea ice 
+   !!                   computation of surface and inner T  
+   !!======================================================================
+   !! History :  LIM  ! 02-2003 (M. Vancoppenolle) original 1D code
+   !!                 ! 06-2005 (M. Vancoppenolle) 3d version
+   !!                 ! 11-2006 (X Fettweis) Vectorization by Xavier
+   !!                 ! 04-2007 (M. Vancoppenolle) Energy conservation
+   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!             -   ! 2012-05 (C. Rousset) add penetration solar flux
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   USE par_oce        ! ocean parameters
+   USE phycst         ! physical constants (ocean directory) 
+   USE ice            ! LIM-3 variables
+   USE ice1D          ! LIM-3: thermodynamics
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_thd_dif   ! called by ice_thd
+
+   !!----------------------------------------------------------------------
+   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! $Id: icethd_dif.F90 8420 2017-08-08 12:18:46Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_thd_dif
+      !!------------------------------------------------------------------
+      !!                ***  ROUTINE ice_thd_dif  ***
+      !! ** Purpose :
+      !!           This routine determines the time evolution of snow and sea-ice 
+      !!           temperature profiles.
+      !! ** Method  :
+      !!           This is done by solving the heat equation diffusion with
+      !!           a Neumann boundary condition at the surface and a Dirichlet one
+      !!           at the bottom. Solar radiation is partially absorbed into the ice.
+      !!           The specific heat and thermal conductivities depend on ice salinity
+      !!           and temperature to take into account brine pocket melting. The 
+      !!           numerical
+      !!           scheme is an iterative Crank-Nicolson on a non-uniform multilayer grid 
+      !!           in the ice and snow system.
+      !!
+      !!           The successive steps of this routine are
+      !!           1.  Thermal conductivity at the interfaces of the ice layers
+      !!           2.  Internal absorbed radiation
+      !!           3.  Scale factors due to non-uniform grid
+      !!           4.  Kappa factors
+      !!           Then iterative procedure begins
+      !!           5.  specific heat in the ice
+      !!           6.  eta factors
+      !!           7.  surface flux computation
+      !!           8.  tridiagonal system terms
+      !!           9.  solving the tridiagonal system with Gauss elimination
+      !!           Iterative procedure ends according to a criterion on evolution
+      !!           of temperature
+      !!
+      !!
+      !! ** Inputs / Ouputs : (global commons)
+      !!           surface temperature : t_su_1d
+      !!           ice/snow temperatures   : t_i_1d, t_s_1d
+      !!           ice salinities          : s_i_1d
+      !!           number of layers in the ice/snow: nlay_i, nlay_s
+      !!           profile of the ice/snow layers : z_i, z_s
+      !!           total ice/snow thickness : ht_i_1d, ht_s_1d
+      !!
+      !! ** External : 
+      !!
+      !! ** References :
+      !!
+      !! ** History :
+      !!           (02-2003) Martin Vancoppenolle, Louvain-la-Neuve, Belgium
+      !!           (06-2005) Martin Vancoppenolle, 3d version
+      !!           (11-2006) Vectorized by Xavier Fettweis (UCL-ASTR)
+      !!           (04-2007) Energy conservation tested by M. Vancoppenolle
+      !!------------------------------------------------------------------
+      !! * Local variables
+      INTEGER ::   ji             ! spatial loop index
+      INTEGER ::   ii, ij         ! temporary dummy loop index
+      INTEGER ::   numeq          ! current reference number of equation
+      INTEGER ::   jk             ! vertical dummy loop index 
+      INTEGER ::   minnumeqmin, maxnumeqmax
+      INTEGER ::   iconv          ! number of iterations in iterative procedure
+      INTEGER ::   iconv_max = 50 ! max number of iterations in iterative procedure
+      
+      INTEGER, DIMENSION(jpij) ::   numeqmin   ! reference number of top equation
+      INTEGER, DIMENSION(jpij) ::   numeqmax   ! reference number of bottom equation
+      
+      REAL(wp) ::   zg1s      =  2._wp        ! for the tridiagonal system
+      REAL(wp) ::   zg1       =  2._wp        !
+      REAL(wp) ::   zgamma    =  18009._wp    ! for specific heat
+      REAL(wp) ::   zbeta     =  0.117_wp     ! for thermal conductivity (could be 0.13)
+      REAL(wp) ::   zraext_s  =  10._wp       ! extinction coefficient of radiation in the snow
+      REAL(wp) ::   zkimin    =  0.10_wp      ! minimum ice thermal conductivity
+      REAL(wp) ::   ztsu_err  =  1.e-5_wp     ! range around which t_su is considered at 0C 
+      REAL(wp) ::   ztmelt_i                  ! ice melting temperature
+      REAL(wp) ::   zhsu
+      REAL(wp) ::   zdti_max                  ! current maximal error on temperature 
+      REAL(wp) ::   zdti_bnd = 1.e-4_wp       ! maximal authorized error on temperature 
+      
+      REAL(wp), DIMENSION(jpij)     ::   isnow       ! switch for presence (1) or absence (0) of snow
+      REAL(wp), DIMENSION(jpij)     ::   ztsub       ! old surface temperature (before the iterative procedure )
+      REAL(wp), DIMENSION(jpij)     ::   ztsubit     ! surface temperature at previous iteration
+      REAL(wp), DIMENSION(jpij)     ::   zh_i        ! ice layer thickness
+      REAL(wp), DIMENSION(jpij)     ::   zh_s        ! snow layer thickness
+      REAL(wp), DIMENSION(jpij)     ::   zfsw        ! solar radiation absorbed at the surface
+      REAL(wp), DIMENSION(jpij)     ::   zqns_ice_b  ! solar radiation absorbed at the surface
+      REAL(wp), DIMENSION(jpij)     ::   zf          ! surface flux function
+      REAL(wp), DIMENSION(jpij)     ::   dzf         ! derivative of the surface flux function
+      REAL(wp), DIMENSION(jpij)     ::   zdti        ! current error on temperature
+      REAL(wp), DIMENSION(jpij)     ::   zdifcase    ! case of the equation resolution (1->4)
+      REAL(wp), DIMENSION(jpij)     ::   zftrice     ! solar radiation transmitted through the ice
+      REAL(wp), DIMENSION(jpij)     ::   zihic
+      
+      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   ztcond_i    ! Ice thermal conductivity
+      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   zradtr_i    ! Radiation transmitted through the ice
+      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   zradab_i    ! Radiation absorbed in the ice
+      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   zkappa_i    ! Kappa factor in the ice
+      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   ztib        ! Old temperature in the ice
+      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   zeta_i      ! Eta factor in the ice
+      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   ztitemp     ! Temporary temperature in the ice to check the convergence
+      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   zspeche_i   ! Ice specific heat
+      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   z_i         ! Vertical cotes of the layers in the ice
+      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   zradtr_s    ! Radiation transmited through the snow
+      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   zradab_s    ! Radiation absorbed in the snow
+      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   zkappa_s    ! Kappa factor in the snow
+      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   zeta_s      ! Eta factor in the snow
+      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   ztstemp     ! Temporary temperature in the snow to check the convergence
+      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   ztsb        ! Temporary temperature in the snow
+      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   z_s         ! Vertical cotes of the layers in the snow
+      REAL(wp), DIMENSION(jpij,nlay_i+3)   ::   zindterm    ! 'Ind'ependent term
+      REAL(wp), DIMENSION(jpij,nlay_i+3)   ::   zindtbis    ! Temporary 'ind'ependent term
+      REAL(wp), DIMENSION(jpij,nlay_i+3)   ::   zdiagbis    ! Temporary 'dia'gonal term
+      REAL(wp), DIMENSION(jpij,nlay_i+3,3) ::   ztrid       ! Tridiagonal system terms
+      REAL(wp), DIMENSION(jpij)            ::   zdq, zq_ini, zhfx_err ! diag errors on heat
+      REAL(wp), DIMENSION(jpij)            ::   zghe        ! G(he), th. conduct enhancement factor, mono-cat
+      
+      ! Mono-category
+      REAL(wp) :: zepsilon      ! determines thres. above which computation of G(h) is done
+      REAL(wp) :: zratio_s      ! dummy factor
+      REAL(wp) :: zratio_i      ! dummy factor
+      REAL(wp) :: zh_thres      ! thickness thres. for G(h) computation
+      REAL(wp) :: zhe           ! dummy factor
+      REAL(wp) :: zkimean       ! mean sea ice thermal conductivity
+      REAL(wp) :: zfac          ! dummy factor
+      REAL(wp) :: zihe          ! dummy factor
+      REAL(wp) :: zheshth       ! dummy factor
+      !!------------------------------------------------------------------     
+
+      ! --- diag error on heat diffusion - PART 1 --- !
+      zdq(:) = 0._wp ; zq_ini(:) = 0._wp      
+      DO ji = 1, nidx
+         zq_ini(ji) = ( SUM( e_i_1d(ji,1:nlay_i) ) * ht_i_1d(ji) * r1_nlay_i +  &
+            &           SUM( e_s_1d(ji,1:nlay_s) ) * ht_s_1d(ji) * r1_nlay_s ) 
+      END DO
+
+      !------------------------------------------------------------------------------!
+      ! 1) Initialization                                                            !
+      !------------------------------------------------------------------------------!
+      DO ji = 1 , nidx
+         isnow(ji)= 1._wp - MAX( 0._wp , SIGN(1._wp, - ht_s_1d(ji) ) )  ! is there snow or not
+         ! layer thickness
+         zh_i(ji) = ht_i_1d(ji) * r1_nlay_i
+         zh_s(ji) = ht_s_1d(ji) * r1_nlay_s
+      END DO
+
+      !--------------------
+      ! Ice / snow layers
+      !--------------------
+
+      z_s(:,0) = 0._wp   ! vert. coord. of the up. lim. of the 1st snow layer
+      z_i(:,0) = 0._wp   ! vert. coord. of the up. lim. of the 1st ice layer
+
+      DO jk = 1, nlay_s            ! vert. coord of the up. lim. of the layer-th snow layer
+         DO ji = 1 , nidx
+            z_s(ji,jk) = z_s(ji,jk-1) + ht_s_1d(ji) * r1_nlay_s
+         END DO
+      END DO
+
+      DO jk = 1, nlay_i            ! vert. coord of the up. lim. of the layer-th ice layer
+         DO ji = 1 , nidx
+            z_i(ji,jk) = z_i(ji,jk-1) + ht_i_1d(ji) * r1_nlay_i
+         END DO
+      END DO
+      !
+      !------------------------------------------------------------------------------|
+      ! 2) Radiation								                                 |
+      !------------------------------------------------------------------------------|
+      !
+      !-------------------
+      ! Computation of i0
+      !-------------------
+      ! i0 describes the fraction of solar radiation which does not contribute
+      ! to the surface energy budget but rather penetrates inside the ice.
+      ! We assume that no radiation is transmitted through the snow
+      ! If there is no no snow
+      ! zfsw    = (1-i0).qsr_ice   is absorbed at the surface 
+      ! zftrice = io.qsr_ice       is below the surface 
+      ! ftr_ice = io.qsr_ice.exp(-k(h_i)) transmitted below the ice 
+      ! fr1_i0_1d = i0 for a thin ice cover, fr1_i0_2d = i0 for a thick ice cover
+      zhsu = 0.1_wp ! threshold for the computation of i0
+      DO ji = 1 , nidx
+         ! switches
+         isnow(ji) = 1._wp - MAX( 0._wp , SIGN( 1._wp , - ht_s_1d(ji) ) ) 
+         ! hs > 0, isnow = 1
+         zihic(ji) = MAX( 0._wp , 1._wp - ( ht_i_1d(ji) / zhsu ) )     
+
+         i0(ji)    = ( 1._wp - isnow(ji) ) * ( fr1_i0_1d(ji) + zihic(ji) * fr2_i0_1d(ji) )
+      END DO
+
+      !-------------------------------------------------------
+      ! Solar radiation absorbed / transmitted at the surface
+      ! Derivative of the non solar flux
+      !-------------------------------------------------------
+      DO ji = 1 , nidx
+         zfsw   (ji)    =  qsr_ice_1d(ji) * ( 1 - i0(ji) )   ! Shortwave radiation absorbed at surface
+         zftrice(ji)    =  qsr_ice_1d(ji) *       i0(ji)     ! Solar radiation transmitted below the surface layer
+         dzf    (ji)    = dqns_ice_1d(ji)                    ! derivative of incoming nonsolar flux 
+         zqns_ice_b(ji) = qns_ice_1d(ji)                     ! store previous qns_ice_1d value
+      END DO
+
+      !---------------------------------------------------------
+      ! Transmission - absorption of solar radiation in the ice
+      !---------------------------------------------------------
+
+      DO ji = 1, nidx           ! snow initialization
+         zradtr_s(ji,0) = zftrice(ji)     ! radiation penetrating through snow
+      END DO
+
+      DO jk = 1, nlay_s          ! Radiation through snow
+         DO ji = 1, nidx
+            !                             ! radiation transmitted below the layer-th snow layer
+            zradtr_s(ji,jk) = zradtr_s(ji,0) * EXP( - zraext_s * ( MAX ( 0._wp , z_s(ji,jk) ) ) )
+            !                             ! radiation absorbed by the layer-th snow layer
+            zradab_s(ji,jk) = zradtr_s(ji,jk-1) - zradtr_s(ji,jk)
+         END DO
+      END DO
+
+      DO ji = 1, nidx           ! ice initialization
+         zradtr_i(ji,0) = zradtr_s(ji,nlay_s) * isnow(ji) + zftrice(ji) * ( 1._wp - isnow(ji) )
+      END DO
+
+      DO jk = 1, nlay_i          ! Radiation through ice
+         DO ji = 1, nidx
+            !                             ! radiation transmitted below the layer-th ice layer
+            zradtr_i(ji,jk) = zradtr_i(ji,0) * EXP( - rn_kappa_i * ( MAX ( 0._wp , z_i(ji,jk) ) ) )
+            !                             ! radiation absorbed by the layer-th ice layer
+            zradab_i(ji,jk) = zradtr_i(ji,jk-1) - zradtr_i(ji,jk)
+         END DO
+      END DO
+
+      DO ji = 1, nidx           ! Radiation transmitted below the ice
+         ftr_ice_1d(ji) = zradtr_i(ji,nlay_i) 
+      END DO
+
+      !------------------------------------------------------------------------------|
+      !  3) Iterative procedure begins                                               |
+      !------------------------------------------------------------------------------|
+      !
+      DO ji = 1, nidx        ! Old surface temperature
+         ztsub  (ji) =  t_su_1d(ji)                              ! temperature at the beg of iter pr.
+         ztsubit(ji) =  t_su_1d(ji)                              ! temperature at the previous iter
+         t_su_1d(ji) =  MIN( t_su_1d(ji), rt0 - ztsu_err )       ! necessary
+         zdti   (ji) =  1000._wp                                 ! initial value of error
+      END DO
+
+      DO jk = 1, nlay_s       ! Old snow temperature
+         DO ji = 1 , nidx
+            ztsb(ji,jk) =  t_s_1d(ji,jk)
+         END DO
+      END DO
+
+      DO jk = 1, nlay_i       ! Old ice temperature
+         DO ji = 1 , nidx
+            ztib(ji,jk) =  t_i_1d(ji,jk)
+         END DO
+      END DO
+
+      iconv    =  0           ! number of iterations
+      zdti_max =  1000._wp    ! maximal value of error on all points
+
+      DO WHILE ( zdti_max > zdti_bnd .AND. iconv < iconv_max )
+         !
+         iconv = iconv + 1
+         !
+         !------------------------------------------------------------------------------|
+         ! 4) Sea ice thermal conductivity                                              |
+         !------------------------------------------------------------------------------|
+         !
+         IF( nn_ice_thcon == 0 ) THEN      ! Untersteiner (1964) formula
+            DO ji = 1 , nidx
+               ztcond_i(ji,0) = rcdic + zbeta * s_i_1d(ji,1) / MIN( -epsi10, t_i_1d(ji,1) - rt0 )
+               ztcond_i(ji,0) = MAX( ztcond_i(ji,0), zkimin )
+            END DO
+            DO jk = 1, nlay_i-1
+               DO ji = 1 , nidx
+                  ztcond_i(ji,jk) = rcdic + zbeta * ( s_i_1d(ji,jk) + s_i_1d(ji,jk+1) ) /  &
+                     MIN(-2.0_wp * epsi10, t_i_1d(ji,jk) + t_i_1d(ji,jk+1) - 2.0_wp * rt0)
+                  ztcond_i(ji,jk) = MAX( ztcond_i(ji,jk), zkimin )
+               END DO
+            END DO
+         ENDIF
+
+         IF( nn_ice_thcon == 1 ) THEN      ! Pringle et al formula included: 2.11 + 0.09 S/T - 0.011.T
+            DO ji = 1 , nidx
+               ztcond_i(ji,0) = rcdic + 0.090_wp * s_i_1d(ji,1) / MIN( -epsi10, t_i_1d(ji,1) - rt0 )   &
+                  &                   - 0.011_wp * ( t_i_1d(ji,1) - rt0 )  
+               ztcond_i(ji,0) = MAX( ztcond_i(ji,0), zkimin )
+            END DO
+            DO jk = 1, nlay_i-1
+               DO ji = 1 , nidx
+                  ztcond_i(ji,jk) = rcdic +                                                                       & 
+                     &                 0.09_wp * ( s_i_1d(ji,jk) + s_i_1d(ji,jk+1) )                              &
+                     &                 / MIN( -2._wp * epsi10, t_i_1d(ji,jk) + t_i_1d(ji,jk+1) - 2.0_wp * rt0 )   &
+                     &               - 0.0055_wp * ( t_i_1d(ji,jk) + t_i_1d(ji,jk+1) - 2.0 * rt0 )  
+                  ztcond_i(ji,jk) = MAX( ztcond_i(ji,jk), zkimin )
+               END DO
+            END DO
+            DO ji = 1 , nidx
+               ztcond_i(ji,nlay_i) = rcdic + 0.090_wp * s_i_1d(ji,nlay_i) / MIN( -epsi10, t_bo_1d(ji) - rt0 )   &
+                  &                        - 0.011_wp * ( t_bo_1d(ji) - rt0 )  
+               ztcond_i(ji,nlay_i) = MAX( ztcond_i(ji,nlay_i), zkimin )
+            END DO
+         ENDIF
+         
+         !
+         !------------------------------------------------------------------------------|
+         !  5) G(he) - enhancement of thermal conductivity in mono-category case        |
+         !------------------------------------------------------------------------------|
+         !
+         ! Computation of effective thermal conductivity G(h)
+         ! Used in mono-category case only to simulate an ITD implicitly
+         ! Fichefet and Morales Maqueda, JGR 1997
+
+         zghe(:) = 1._wp
+
+         SELECT CASE ( nn_monocat )
+
+         CASE (1,3) ! LIM3
+
+            zepsilon = 0.1_wp
+            zh_thres = EXP( 1._wp ) * zepsilon * 0.5_wp
+
+            DO ji = 1, nidx
+   
+               ! Mean sea ice thermal conductivity
+               zkimean  = SUM( ztcond_i(ji,0:nlay_i) ) / REAL( nlay_i+1, wp )
+
+               ! Effective thickness he (zhe)
+               zfac     = 1._wp / ( rn_cdsn + zkimean )
+               zratio_s = rn_cdsn   * zfac
+               zratio_i = zkimean * zfac
+               zhe      = zratio_s * ht_i_1d(ji) + zratio_i * ht_s_1d(ji)
+
+               ! G(he)
+               rswitch  = MAX( 0._wp , SIGN( 1._wp , zhe - zh_thres ) )  ! =0 if zhe < zh_thres, if >
+               zghe(ji) = ( 1._wp - rswitch ) + rswitch * 0.5_wp * ( 1._wp + LOG( 2._wp * zhe / zepsilon ) )
+   
+               ! Impose G(he) < 2.
+               zghe(ji) = MIN( zghe(ji), 2._wp )
+
+            END DO
+
+         END SELECT
+
+         !
+         !------------------------------------------------------------------------------|
+         !  6) kappa factors                                                            |
+         !------------------------------------------------------------------------------|
+         !
+         !--- Snow
+         DO ji = 1, nidx
+            zfac                  =  1. / MAX( epsi10 , zh_s(ji) )
+            zkappa_s(ji,0)        = zghe(ji) * rn_cdsn * zfac
+            zkappa_s(ji,nlay_s)   = zghe(ji) * rn_cdsn * zfac
+         END DO
+
+         DO jk = 1, nlay_s-1
+            DO ji = 1 , nidx
+               zkappa_s(ji,jk)    = zghe(ji) * 2.0 * rn_cdsn / MAX( epsi10, 2.0 * zh_s(ji) )
+            END DO
+         END DO
+
+         !--- Ice
+         DO jk = 1, nlay_i-1
+            DO ji = 1 , nidx
+               zkappa_i(ji,jk)    = zghe(ji) * 2.0 * ztcond_i(ji,jk) / MAX( epsi10 , 2.0 * zh_i(ji) )
+            END DO
+         END DO
+
+         !--- Snow-ice interface
+         DO ji = 1 , nidx
+            zfac                  = 1./ MAX( epsi10 , zh_i(ji) )
+            zkappa_i(ji,0)        = zghe(ji) * ztcond_i(ji,0) * zfac
+            zkappa_i(ji,nlay_i)   = zghe(ji) * ztcond_i(ji,nlay_i) * zfac
+            zkappa_s(ji,nlay_s)   = zghe(ji) * zghe(ji) * 2.0 * rn_cdsn * ztcond_i(ji,0) / & 
+           &                        MAX( epsi10, ( zghe(ji) * ztcond_i(ji,0) * zh_s(ji) + zghe(ji) * rn_cdsn * zh_i(ji) ) )
+            zkappa_i(ji,0)        = zkappa_s(ji,nlay_s) * isnow(ji) + zkappa_i(ji,0) * ( 1._wp - isnow(ji) )
+         END DO
+
+         !
+         !------------------------------------------------------------------------------|
+         ! 7) Sea ice specific heat, eta factors                                        |
+         !------------------------------------------------------------------------------|
+         !
+         DO jk = 1, nlay_i
+            DO ji = 1 , nidx
+               ztitemp(ji,jk)   = t_i_1d(ji,jk)
+               zspeche_i(ji,jk) = cpic + zgamma * s_i_1d(ji,jk) / MAX( ( t_i_1d(ji,jk) - rt0 ) * ( ztib(ji,jk) - rt0 ), epsi10 )
+               zeta_i(ji,jk)    = rdt_ice / MAX( rhoic * zspeche_i(ji,jk) * zh_i(ji), epsi10 )
+            END DO
+         END DO
+
+         DO jk = 1, nlay_s
+            DO ji = 1 , nidx
+               ztstemp(ji,jk) = t_s_1d(ji,jk)
+               zeta_s(ji,jk)  = rdt_ice / MAX( rhosn * cpic * zh_s(ji), epsi10 )
+            END DO
+         END DO
+
+         !
+         !------------------------------------------------------------------------------|
+         ! 8) surface flux computation                                                  |
+         !------------------------------------------------------------------------------|
+         !
+         IF ( ln_dqnsice ) THEN 
+            DO ji = 1 , nidx
+               ! update of the non solar flux according to the update in T_su
+               qns_ice_1d(ji) = qns_ice_1d(ji) + dqns_ice_1d(ji) * ( t_su_1d(ji) - ztsubit(ji) )
+            END DO
+         ENDIF
+
+         ! Update incoming flux
+         DO ji = 1 , nidx
+            ! update incoming flux
+            zf(ji)    =          zfsw(ji)              & ! net absorbed solar radiation
+               &         + qns_ice_1d(ji)                ! non solar total flux (LWup, LWdw, SH, LH)
+         END DO
+
+         !
+         !------------------------------------------------------------------------------|
+         ! 9) tridiagonal system terms                                                  |
+         !------------------------------------------------------------------------------|
+         !
+         !!layer denotes the number of the layer in the snow or in the ice
+         !!numeq denotes the reference number of the equation in the tridiagonal
+         !!system, terms of tridiagonal system are indexed as following :
+         !!1 is subdiagonal term, 2 is diagonal and 3 is superdiagonal one
+
+         !!ice interior terms (top equation has the same form as the others)
+
+         DO numeq=1,nlay_i+3
+            DO ji = 1 , nidx
+               ztrid(ji,numeq,1) = 0.
+               ztrid(ji,numeq,2) = 0.
+               ztrid(ji,numeq,3) = 0.
+               zindterm(ji,numeq)= 0.
+               zindtbis(ji,numeq)= 0.
+               zdiagbis(ji,numeq)= 0.
+            ENDDO
+         ENDDO
+
+         DO numeq = nlay_s + 2, nlay_s + nlay_i 
+            DO ji = 1 , nidx
+               jk                 = numeq - nlay_s - 1
+               ztrid(ji,numeq,1)  =  - zeta_i(ji,jk) * zkappa_i(ji,jk-1)
+               ztrid(ji,numeq,2)  =  1.0 + zeta_i(ji,jk) * ( zkappa_i(ji,jk-1) + zkappa_i(ji,jk) )
+               ztrid(ji,numeq,3)  =  - zeta_i(ji,jk) * zkappa_i(ji,jk)
+               zindterm(ji,numeq) =  ztib(ji,jk) + zeta_i(ji,jk) * zradab_i(ji,jk)
+            END DO
+         ENDDO
+
+         numeq =  nlay_s + nlay_i + 1
+         DO ji = 1 , nidx
+            !!ice bottom term
+            ztrid(ji,numeq,1)  =  - zeta_i(ji,nlay_i)*zkappa_i(ji,nlay_i-1)   
+            ztrid(ji,numeq,2)  =  1.0 + zeta_i(ji,nlay_i) * ( zkappa_i(ji,nlay_i) * zg1 + zkappa_i(ji,nlay_i-1) )
+            ztrid(ji,numeq,3)  =  0.0
+            zindterm(ji,numeq) =  ztib(ji,nlay_i) + zeta_i(ji,nlay_i) *  &
+               &                  ( zradab_i(ji,nlay_i) + zkappa_i(ji,nlay_i) * zg1 *  t_bo_1d(ji) ) 
+         ENDDO
+
+
+         DO ji = 1 , nidx
+            IF ( ht_s_1d(ji) > 0.0 ) THEN
+               !
+               !------------------------------------------------------------------------------|
+               !  snow-covered cells                                                          |
+               !------------------------------------------------------------------------------|
+               !
+               !!snow interior terms (bottom equation has the same form as the others)
+               DO numeq = 3, nlay_s + 1
+                  jk                  =  numeq - 1
+                  ztrid(ji,numeq,1)   =  - zeta_s(ji,jk) * zkappa_s(ji,jk-1)
+                  ztrid(ji,numeq,2)   =  1.0 + zeta_s(ji,jk) * ( zkappa_s(ji,jk-1) + zkappa_s(ji,jk) )
+                  ztrid(ji,numeq,3)   =  - zeta_s(ji,jk)*zkappa_s(ji,jk)
+                  zindterm(ji,numeq)  =  ztsb(ji,jk) + zeta_s(ji,jk) * zradab_s(ji,jk)
+               END DO
+
+               !!case of only one layer in the ice (ice equation is altered)
+               IF ( nlay_i.eq.1 ) THEN
+                  ztrid(ji,nlay_s+2,3)    =  0.0
+                  zindterm(ji,nlay_s+2)   =  zindterm(ji,nlay_s+2) + zkappa_i(ji,1) * t_bo_1d(ji) 
+               ENDIF
+
+               IF ( t_su_1d(ji) < rt0 ) THEN
+
+                  !------------------------------------------------------------------------------|
+                  !  case 1 : no surface melting - snow present                                  |
+                  !------------------------------------------------------------------------------|
+                  zdifcase(ji)    =  1.0
+                  numeqmin(ji)    =  1
+                  numeqmax(ji)    =  nlay_i + nlay_s + 1
+
+                  !!surface equation
+                  ztrid(ji,1,1)  = 0.0
+                  ztrid(ji,1,2)  = dzf(ji) - zg1s * zkappa_s(ji,0)
+                  ztrid(ji,1,3)  = zg1s * zkappa_s(ji,0)
+                  zindterm(ji,1) = dzf(ji) * t_su_1d(ji) - zf(ji)
+
+                  !!first layer of snow equation
+                  ztrid(ji,2,1)  =  - zkappa_s(ji,0) * zg1s * zeta_s(ji,1)
+                  ztrid(ji,2,2)  =  1.0 + zeta_s(ji,1) * ( zkappa_s(ji,1) + zkappa_s(ji,0) * zg1s )
+                  ztrid(ji,2,3)  =  - zeta_s(ji,1)* zkappa_s(ji,1)
+                  zindterm(ji,2) =  ztsb(ji,1) + zeta_s(ji,1) * zradab_s(ji,1)
+
+               ELSE 
+                  !
+                  !------------------------------------------------------------------------------|
+                  !  case 2 : surface is melting - snow present                                  |
+                  !------------------------------------------------------------------------------|
+                  !
+                  zdifcase(ji)    =  2.0
+                  numeqmin(ji)    =  2
+                  numeqmax(ji)    =  nlay_i + nlay_s + 1
+
+                  !!first layer of snow equation
+                  ztrid(ji,2,1)  =  0.0
+                  ztrid(ji,2,2)  =  1.0 + zeta_s(ji,1) * ( zkappa_s(ji,1) + zkappa_s(ji,0) * zg1s )
+                  ztrid(ji,2,3)  =  - zeta_s(ji,1)*zkappa_s(ji,1) 
+                  zindterm(ji,2) = ztsb(ji,1) + zeta_s(ji,1) *  &
+                     &             ( zradab_s(ji,1) + zkappa_s(ji,0) * zg1s * t_su_1d(ji) ) 
+               ENDIF
+            ELSE
+               !
+               !------------------------------------------------------------------------------|
+               !  cells without snow                                                          |
+               !------------------------------------------------------------------------------|
+               !
+               IF ( t_su_1d(ji) < rt0 ) THEN
+                  !
+                  !------------------------------------------------------------------------------|
+                  !  case 3 : no surface melting - no snow                                       |
+                  !------------------------------------------------------------------------------|
+                  !
+                  zdifcase(ji)      =  3.0
+                  numeqmin(ji)      =  nlay_s + 1
+                  numeqmax(ji)      =  nlay_i + nlay_s + 1
+
+                  !!surface equation	
+                  ztrid(ji,numeqmin(ji),1)   =  0.0
+                  ztrid(ji,numeqmin(ji),2)   =  dzf(ji) - zkappa_i(ji,0)*zg1    
+                  ztrid(ji,numeqmin(ji),3)   =  zkappa_i(ji,0)*zg1
+                  zindterm(ji,numeqmin(ji))  =  dzf(ji)*t_su_1d(ji) - zf(ji)
+
+                  !!first layer of ice equation
+                  ztrid(ji,numeqmin(ji)+1,1) =  - zkappa_i(ji,0) * zg1 * zeta_i(ji,1)
+                  ztrid(ji,numeqmin(ji)+1,2) =  1.0 + zeta_i(ji,1) * ( zkappa_i(ji,1) + zkappa_i(ji,0) * zg1 )
+                  ztrid(ji,numeqmin(ji)+1,3) =  - zeta_i(ji,1) * zkappa_i(ji,1)  
+                  zindterm(ji,numeqmin(ji)+1)=  ztib(ji,1) + zeta_i(ji,1) * zradab_i(ji,1)  
+
+                  !!case of only one layer in the ice (surface & ice equations are altered)
+
+                  IF ( nlay_i == 1 ) THEN
+                     ztrid(ji,numeqmin(ji),1)    =  0.0
+                     ztrid(ji,numeqmin(ji),2)    =  dzf(ji) - zkappa_i(ji,0) * 2.0
+                     ztrid(ji,numeqmin(ji),3)    =  zkappa_i(ji,0) * 2.0
+                     ztrid(ji,numeqmin(ji)+1,1)  =  -zkappa_i(ji,0) * 2.0 * zeta_i(ji,1)
+                     ztrid(ji,numeqmin(ji)+1,2)  =  1.0 + zeta_i(ji,1) * ( zkappa_i(ji,0) * 2.0 + zkappa_i(ji,1) )
+                     ztrid(ji,numeqmin(ji)+1,3)  =  0.0
+
+                     zindterm(ji,numeqmin(ji)+1) =  ztib(ji,1) + zeta_i(ji,1) *  &
+                        &                          ( zradab_i(ji,1) + zkappa_i(ji,1) * t_bo_1d(ji) )
+                  ENDIF
+
+               ELSE
+
+                  !
+                  !------------------------------------------------------------------------------|
+                  ! case 4 : surface is melting - no snow                                        |
+                  !------------------------------------------------------------------------------|
+                  !
+                  zdifcase(ji)    =  4.0
+                  numeqmin(ji)    =  nlay_s + 2
+                  numeqmax(ji)    =  nlay_i + nlay_s + 1
+
+                  !!first layer of ice equation
+                  ztrid(ji,numeqmin(ji),1)      =  0.0
+                  ztrid(ji,numeqmin(ji),2)      =  1.0 + zeta_i(ji,1) * ( zkappa_i(ji,1) + zkappa_i(ji,0) * zg1 )  
+                  ztrid(ji,numeqmin(ji),3)      =  - zeta_i(ji,1) * zkappa_i(ji,1)
+                  zindterm(ji,numeqmin(ji))     =  ztib(ji,1) + zeta_i(ji,1) *  &
+                     &                             ( zradab_i(ji,1) + zkappa_i(ji,0) * zg1 * t_su_1d(ji) ) 
+
+                  !!case of only one layer in the ice (surface & ice equations are altered)
+                  IF ( nlay_i == 1 ) THEN
+                     ztrid(ji,numeqmin(ji),1)  =  0.0
+                     ztrid(ji,numeqmin(ji),2)  =  1.0 + zeta_i(ji,1) * ( zkappa_i(ji,0) * 2.0 + zkappa_i(ji,1) )
+                     ztrid(ji,numeqmin(ji),3)  =  0.0
+                     zindterm(ji,numeqmin(ji)) =  ztib(ji,1) + zeta_i(ji,1) * ( zradab_i(ji,1) + zkappa_i(ji,1) * t_bo_1d(ji) )  &
+                        &                       + t_su_1d(ji) * zeta_i(ji,1) * zkappa_i(ji,0) * 2.0
+                  ENDIF
+
+               ENDIF
+            ENDIF
+
+         END DO
+
+         !
+         !------------------------------------------------------------------------------|
+         ! 10) tridiagonal system solving                                               |
+         !------------------------------------------------------------------------------|
+         !
+
+         ! Solve the tridiagonal system with Gauss elimination method.
+         ! Thomas algorithm, from Computational fluid Dynamics, J.D. ANDERSON, 
+         ! McGraw-Hill 1984.	
+
+         maxnumeqmax = 0
+         minnumeqmin = nlay_i+5
+
+         DO ji = 1 , nidx
+            zindtbis(ji,numeqmin(ji)) =  zindterm(ji,numeqmin(ji))
+            zdiagbis(ji,numeqmin(ji)) =  ztrid(ji,numeqmin(ji),2)
+            minnumeqmin               =  MIN(numeqmin(ji),minnumeqmin)
+            maxnumeqmax               =  MAX(numeqmax(ji),maxnumeqmax)
+         END DO
+
+         DO jk = minnumeqmin+1, maxnumeqmax
+            DO ji = 1 , nidx
+               numeq               =  min(max(numeqmin(ji)+1,jk),numeqmax(ji))
+               zdiagbis(ji,numeq)  =  ztrid(ji,numeq,2)  - ztrid(ji,numeq,1) * ztrid(ji,numeq-1,3)  / zdiagbis(ji,numeq-1)
+               zindtbis(ji,numeq)  =  zindterm(ji,numeq) - ztrid(ji,numeq,1) * zindtbis(ji,numeq-1) / zdiagbis(ji,numeq-1)
+            END DO
+         END DO
+
+         DO ji = 1 , nidx
+            ! ice temperatures
+            t_i_1d(ji,nlay_i)    =  zindtbis(ji,numeqmax(ji)) / zdiagbis(ji,numeqmax(ji))
+         END DO
+
+         DO numeq = nlay_i + nlay_s, nlay_s + 2, -1
+            DO ji = 1 , nidx
+               jk    =  numeq - nlay_s - 1
+               t_i_1d(ji,jk)  =  ( zindtbis(ji,numeq) - ztrid(ji,numeq,3) * t_i_1d(ji,jk+1) ) / zdiagbis(ji,numeq)
+            END DO
+         END DO
+
+         DO ji = 1 , nidx
+            ! snow temperatures      
+            IF (ht_s_1d(ji) > 0._wp) &
+               t_s_1d(ji,nlay_s)     =  ( zindtbis(ji,nlay_s+1) - ztrid(ji,nlay_s+1,3) * t_i_1d(ji,1) )  &
+               &                        / zdiagbis(ji,nlay_s+1) * MAX( 0.0, SIGN( 1.0, ht_s_1d(ji) ) ) 
+
+            ! surface temperature
+            isnow(ji)   = 1._wp - MAX( 0._wp , SIGN( 1._wp , -ht_s_1d(ji) ) )
+            ztsubit(ji) = t_su_1d(ji)
+            IF( t_su_1d(ji) < rt0 ) &
+               t_su_1d(ji) = ( zindtbis(ji,numeqmin(ji)) - ztrid(ji,numeqmin(ji),3) *  &
+               &             ( isnow(ji) * t_s_1d(ji,1) + ( 1._wp - isnow(ji) ) * t_i_1d(ji,1) ) ) / zdiagbis(ji,numeqmin(ji))  
+         END DO
+         !
+         !--------------------------------------------------------------------------
+         !  11) Has the scheme converged ?, end of the iterative procedure         |
+         !--------------------------------------------------------------------------
+         !
+         ! check that nowhere it has started to melt
+         ! zdti(ji) is a measure of error, it has to be under zdti_bnd
+         DO ji = 1 , nidx
+            t_su_1d(ji) =  MAX(  MIN( t_su_1d(ji) , rt0 ) , 190._wp  )
+            zdti   (ji) =  ABS( t_su_1d(ji) - ztsubit(ji) )     
+         END DO
+
+         DO jk  =  1, nlay_s
+            DO ji = 1 , nidx
+               t_s_1d(ji,jk) = MAX(  MIN( t_s_1d(ji,jk), rt0 ), 190._wp  )
+               zdti  (ji)    = MAX( zdti(ji), ABS( t_s_1d(ji,jk) - ztstemp(ji,jk) ) )
+            END DO
+         END DO
+
+         DO jk  =  1, nlay_i
+            DO ji = 1 , nidx
+               ztmelt_i      = -tmut * s_i_1d(ji,jk) + rt0 
+               t_i_1d(ji,jk) =  MAX( MIN( t_i_1d(ji,jk), ztmelt_i ), 190._wp )
+               zdti  (ji)    =  MAX( zdti(ji), ABS( t_i_1d(ji,jk) - ztitemp(ji,jk) ) )
+            END DO
+         END DO
+
+         ! Compute spatial maximum over all errors
+         ! note that this could be optimized substantially by iterating only the non-converging points
+         zdti_max = 0._wp
+         DO ji = 1, nidx
+            zdti_max = MAX( zdti_max, zdti(ji) )   
+         END DO
+         IF( lk_mpp ) CALL mpp_max( zdti_max, kcom=ncomm_ice )
+
+      END DO  ! End of the do while iterative procedure
+
+      ! MV SIMIP 2016
+      !--- Snow-ice interfacial temperature (diagnostic SIMIP)
+      DO ji = 1, nidx
+         zfac        = 1. / MAX( epsi10 , rn_cdsn * zh_i(ji) + ztcond_i(ji,1) * zh_s(ji) )
+         IF( zh_s(ji) >= 1.e-3 ) THEN
+            t_si_1d(ji) = ( rn_cdsn        * zh_i(ji) * t_s_1d(ji,1) + &
+               &            ztcond_i(ji,1) * zh_s(ji) * t_i_1d(ji,1) ) * zfac
+         ELSE
+            t_si_1d(ji) = t_su_1d(ji)
+         ENDIF
+      END DO
+      ! END MV SIMIP 2016
+
+      IF( ln_limctl .AND. lwp ) THEN
+         WRITE(numout,*) ' zdti_max : ', zdti_max
+         WRITE(numout,*) ' iconv    : ', iconv
+      ENDIF
+
+      !
+      !-------------------------------------------------------------------------!
+      !   12) Fluxes at the interfaces                                          !
+      !-------------------------------------------------------------------------!
+      DO ji = 1, nidx
+         !                                ! surface ice conduction flux
+         isnow(ji)       = 1._wp - MAX( 0._wp, SIGN( 1._wp, -ht_s_1d(ji) ) )
+         fc_su(ji)       =  -           isnow(ji)   * zkappa_s(ji,0) * zg1s * (t_s_1d(ji,1) - t_su_1d(ji))   &
+            &               - ( 1._wp - isnow(ji) ) * zkappa_i(ji,0) * zg1  * (t_i_1d(ji,1) - t_su_1d(ji))
+         !                                ! bottom ice conduction flux
+         fc_bo_i(ji)     =  - zkappa_i(ji,nlay_i) * ( zg1*(t_bo_1d(ji) - t_i_1d(ji,nlay_i)) )
+      END DO
+
+      ! MV SIMIP 2016
+      !--- Conduction fluxes (positive downwards)
+      diag_fc_bo_1d(:)   = diag_fc_bo_1d(:) + fc_bo_i(:) * a_i_1d(:) / at_i_1d(:)
+      diag_fc_su_1d(:)   = diag_fc_su_1d(:) + fc_su(:)   * a_i_1d(:) / at_i_1d(:)
+      ! END MV SIMIP 2016
+
+      ! --- computes sea ice energy of melting compulsory for icethd_dh --- !
+      CALL ice_thd_enmelt
+
+      ! --- diagnose the change in non-solar flux due to surface temperature change --- !
+      IF ( ln_dqnsice ) THEN
+         DO ji = 1, nidx
+            hfx_err_dif_1d(ji) = hfx_err_dif_1d(ji) - ( qns_ice_1d(ji)  - zqns_ice_b(ji) ) * a_i_1d(ji) 
+         END DO
+      END IF
+
+      ! --- diag conservation imbalance on heat diffusion - PART 2 --- !
+      DO ji = 1, nidx
+         zdq(ji)        = - zq_ini(ji) + ( SUM( e_i_1d(ji,1:nlay_i) ) * ht_i_1d(ji) * r1_nlay_i +  &
+            &                              SUM( e_s_1d(ji,1:nlay_s) ) * ht_s_1d(ji) * r1_nlay_s )
+         IF( t_su_1d(ji) < rt0 ) THEN  ! case T_su < 0degC
+            zhfx_err(ji) = qns_ice_1d(ji) + qsr_ice_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) + zdq(ji) * r1_rdtice 
+         ELSE                          ! case T_su = 0degC
+            zhfx_err(ji) = fc_su(ji) + i0(ji) * qsr_ice_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) + zdq(ji) * r1_rdtice 
+         ENDIF
+         hfx_err_1d(ji) = hfx_err_1d(ji) + zhfx_err(ji) * a_i_1d(ji)
+
+         ! total heat that is sent to the ocean (i.e. not used in the heat diffusion equation)
+         hfx_err_dif_1d(ji) = hfx_err_dif_1d(ji) + zhfx_err(ji) * a_i_1d(ji)
+      END DO 
+
+      !-----------------------------------------
+      ! Heat flux used to warm/cool ice in W.m-2
+      !-----------------------------------------
+      DO ji = 1, nidx
+         IF( t_su_1d(ji) < rt0 ) THEN  ! case T_su < 0degC
+            hfx_dif_1d(ji) = hfx_dif_1d(ji)  +   &
+               &            ( qns_ice_1d(ji) + qsr_ice_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) ) * a_i_1d(ji)
+         ELSE                          ! case T_su = 0degC
+            hfx_dif_1d(ji) = hfx_dif_1d(ji) +    &
+               &             ( fc_su(ji) + i0(ji) * qsr_ice_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) ) * a_i_1d(ji)
+         ENDIF
+         ! correction on the diagnosed heat flux due to non-convergence of the algorithm used to solve heat equation
+         hfx_dif_1d(ji) = hfx_dif_1d(ji) - zhfx_err(ji) * a_i_1d(ji)
+      END DO   
+      !
+   END SUBROUTINE ice_thd_dif
+
+   SUBROUTINE ice_thd_enmelt
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_thd_enmelt *** 
+      !!                 
+      !! ** Purpose :   Computes sea ice energy of melting q_i (J.m-3) from temperature
+      !!
+      !! ** Method  :   Formula (Bitz and Lipscomb, 1999)
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ji, jk   ! dummy loop indices
+      REAL(wp) ::   ztmelts  ! local scalar 
+      !!-------------------------------------------------------------------
+      !
+      DO jk = 1, nlay_i             ! Sea ice energy of melting
+         DO ji = 1, nidx
+            ztmelts      = - tmut  * s_i_1d(ji,jk) + rt0
+            t_i_1d(ji,jk) = MIN( t_i_1d(ji,jk), ztmelts ) ! Force t_i_1d to be lower than melting point
+                                                          !   (sometimes dif scheme produces abnormally high temperatures)   
+            e_i_1d(ji,jk) = rhoic * ( cpic * ( ztmelts - t_i_1d(ji,jk) )                           &
+               &                    + lfus * ( 1.0 - ( ztmelts-rt0 ) / ( t_i_1d(ji,jk) - rt0 ) )   &
+               &                    - rcp  *         ( ztmelts-rt0 )  ) 
+         END DO
+      END DO
+      DO jk = 1, nlay_s             ! Snow energy of melting
+         DO ji = 1, nidx
+            e_s_1d(ji,jk) = rhosn * ( cpic * ( rt0 - t_s_1d(ji,jk) ) + lfus )
+         END DO
+      END DO
+      !
+   END SUBROUTINE ice_thd_enmelt
+
+#else
+   !!----------------------------------------------------------------------
+   !!                   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 8422)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_ent.F90	(revision 8422)
@@ -0,0 +1,152 @@
+MODULE icethd_ent
+   !!======================================================================
+   !!                       ***  MODULE icethd_ent   ***
+   !!                  Redistribution of Enthalpy in the ice
+   !!                        on the new vertical grid
+   !!                       after vertical growth/decay
+   !!======================================================================
+   !! History :  LIM  ! 2003-05 (M. Vancoppenolle) Original code in 1D
+   !!                 ! 2005-07 (M. Vancoppenolle) 3D version 
+   !!                 ! 2006-11 (X. Fettweis) Vectorized 
+   !!            3.0  ! 2008-03 (M. Vancoppenolle) Energy conservation and clean code
+   !!            3.4  ! 2011-02 (G. Madec) dynamical allocation
+   !!             -   ! 2014-05 (C. Rousset) complete rewriting
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_thd_ent   : ice redistribution of enthalpy
+   !!----------------------------------------------------------------------
+   USE par_oce        ! ocean parameters
+   USE dom_oce        ! domain variables
+   USE domain         !
+   USE phycst         ! physical constants
+   USE ice            ! LIM variables
+   USE ice1D          ! LIM thermodynamics
+   USE limvar         ! LIM variables
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_thd_ent         ! called by icethd and icethd_lac
+
+   !!----------------------------------------------------------------------
+   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! $Id: icethd_ent.F90 8420 2017-08-08 12:18:46Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+ 
+   SUBROUTINE ice_thd_ent( qnew )
+      !!-------------------------------------------------------------------
+      !!               ***   ROUTINE ice_thd_ent  ***
+      !!
+      !! ** Purpose :
+      !!           This routine computes new vertical grids in the ice, 
+      !!           and consistently redistributes temperatures. 
+      !!           Redistribution is made so as to ensure to energy conservation
+      !!
+      !!
+      !! ** Method  : linear conservative remapping
+      !!           
+      !! ** Steps : 1) cumulative integrals of old enthalpies/thicknesses
+      !!            2) linear remapping on the new layers
+      !!
+      !! ------------ cum0(0)                        ------------- cum1(0)
+      !!                                    NEW      -------------
+      !! ------------ cum0(1)               ==>      -------------
+      !!     ...                                     -------------
+      !! ------------                                -------------
+      !! ------------ cum0(nlay_i+2)                 ------------- cum1(nlay_i)
+      !!
+      !!
+      !! References : Bitz & Lipscomb, JGR 99; Vancoppenolle et al., GRL, 2005
+      !!-------------------------------------------------------------------
+      REAL(wp), INTENT(inout), DIMENSION(:,:) :: qnew          ! new enthlapies (J.m-3, remapped)
+
+      INTEGER  :: ji         !  dummy loop indices
+      INTEGER  :: jk0, jk1   !  old/new layer indices
+      !
+      REAL(wp), DIMENSION(jpij,0:nlay_i+2) :: zeh_cum0, zh_cum0   ! old cumulative enthlapies and layers interfaces
+      REAL(wp), DIMENSION(jpij,0:nlay_i)   :: zeh_cum1, zh_cum1   ! new cumulative enthlapies and layers interfaces
+      REAL(wp), DIMENSION(jpij)            :: zhnew               ! new layers thicknesses
+      !!-------------------------------------------------------------------
+
+      !--------------------------------------------------------------------------
+      !  1) Cumulative integral of old enthalpy * thickness and layers interfaces
+      !--------------------------------------------------------------------------
+      zeh_cum0(:,0:nlay_i+2) = 0._wp 
+      zh_cum0 (:,0:nlay_i+2) = 0._wp
+      DO jk0 = 1, nlay_i+2
+         DO ji = 1, nidx
+            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
+
+      !------------------------------------
+      !  2) Interpolation on the new layers
+      !------------------------------------
+      ! new layer thickesses
+      DO ji = 1, nidx
+         zhnew(ji) = SUM( h_i_old(ji,0:nlay_i+1) ) * r1_nlay_i  
+      ENDDO
+
+      ! new layers interfaces
+      zh_cum1(:,0:nlay_i) = 0._wp
+      DO jk1 = 1, nlay_i
+         DO ji = 1, nidx
+            zh_cum1(ji,jk1) = zh_cum1(ji,jk1-1) + zhnew(ji)
+         ENDDO
+      ENDDO
+
+      zeh_cum1(:,0:nlay_i) = 0._wp 
+      ! new cumulative q*h => linear interpolation
+      DO jk0 = 1, nlay_i+1
+         DO jk1 = 1, nlay_i-1
+            DO ji = 1, nidx
+               IF( zh_cum1(ji,jk1) <= zh_cum0(ji,jk0) .AND. zh_cum1(ji,jk1) > zh_cum0(ji,jk0-1) ) THEN
+                  zeh_cum1(ji,jk1) = ( zeh_cum0(ji,jk0-1) * ( zh_cum0(ji,jk0) - zh_cum1(ji,jk1  ) ) +  &
+                     &                 zeh_cum0(ji,jk0  ) * ( zh_cum1(ji,jk1) - zh_cum0(ji,jk0-1) ) )  &
+                     &             / ( zh_cum0(ji,jk0) - zh_cum0(ji,jk0-1) )
+               ENDIF
+            ENDDO
+         ENDDO
+      ENDDO
+      ! to ensure that total heat content is strictly conserved, set:
+      zeh_cum1(:,nlay_i) = zeh_cum0(:,nlay_i+2) 
+
+      ! new enthalpies
+      DO jk1 = 1, nlay_i
+         DO ji = 1, nidx
+            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
+
+      ! --- diag error on heat remapping --- !
+      ! comment: if input h_i_old and eh_i_old are already multiplied by a_i (as in icethd_lac), 
+      ! then we should not (* a_i) again but not important since this is just to check that remap error is ~0
+      DO ji = 1, nidx
+         hfx_err_rem_1d(ji) = hfx_err_rem_1d(ji) + a_i_1d(ji) * r1_rdtice *  &
+            &               ( SUM( qnew(ji,1:nlay_i) ) * zhnew(ji) - SUM( eh_i_old(ji,0:nlay_i+1) ) ) 
+      END DO
+      
+   END SUBROUTINE ice_thd_ent
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                               NO  LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE ice_thd_ent          ! Empty routine
+   END SUBROUTINE ice_thd_ent
+#endif
+
+   !!======================================================================
+END MODULE icethd_ent
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 8422)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_lac.F90	(revision 8422)
@@ -0,0 +1,494 @@
+MODULE icethd_lac
+   !!======================================================================
+   !!                       ***  MODULE icethd_lac   ***
+   !!                lateral thermodynamic growth of the ice 
+   !!======================================================================
+   !! History :  LIM  ! 2005-12 (M. Vancoppenolle)  Original code
+   !!             -   ! 2006-01 (M. Vancoppenolle)  add ITD
+   !!            3.0  ! 2007-07 (M. Vancoppenolle)  Mass and energy conservation tested
+   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   lim_lat_acr   : lateral accretion of ice
+   !!----------------------------------------------------------------------
+   USE par_oce        ! ocean parameters
+   USE dom_oce        ! domain variables
+   USE phycst         ! physical constants
+   USE sbc_oce , 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 icecons        ! LIM conservation
+   USE icethd_ent
+   USE limvar
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC ice_thd_lac     ! called by ice_thd
+
+   !!----------------------------------------------------------------------
+   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! $Id: icethd_lac.F90 8420 2017-08-08 12:18:46Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_thd_lac
+      !!-------------------------------------------------------------------
+      !!               ***   ROUTINE ice_thd_lac  ***
+      !!  
+      !! ** Purpose : Computation of the evolution of the ice thickness and 
+      !!      concentration as a function of the heat balance in the leads.
+      !!      It is only used for lateral accretion
+      !!       
+      !! ** Method  : Ice is formed in the open water when ocean lose heat
+      !!      (heat budget of open water Bl is negative) .
+      !!      Computation of the increase of 1-A (ice concentration) fol-
+      !!      lowing the law :
+      !!      (dA/dt)acc = F[ (1-A)/(1-a) ] * [ Bl / (Li*h0) ]
+      !!       where - h0 is the thickness of ice created in the lead
+      !!             - a is a minimum fraction for leads
+      !!             - F is a monotonic non-increasing function defined as:
+      !!                  F(X)=( 1 - X**exld )**(1.0/exld)
+      !!             - exld is the exponent closure rate (=2 default val.)
+      !! 
+      !! ** Action : - Adjustment of snow and ice thicknesses and heat
+      !!                content in brine pockets
+      !!             - Updating ice internal temperature
+      !!             - Computation of variation of ice volume and mass
+      !!             - Computation of a_i after lateral accretion and 
+      !!               update ht_s_1d, ht_i_1d and tbif_1d(:,:)      
+      !!------------------------------------------------------------------------
+      INTEGER  ::   ji,jj,jk,jl      ! dummy loop indices
+      INTEGER  ::   iter     !   -       -
+      REAL(wp) ::   ztmelts, zdv, zfrazb, zweight, zde                          ! local scalars
+      REAL(wp) ::   zgamafr, zvfrx, zvgx, ztaux, ztwogp, zf                     !   -      -
+      REAL(wp) ::   ztenagm, zvfry, zvgy, ztauy, zvrel2, zfp, zsqcd , zhicrit   !   -      -
+
+      REAL(wp) ::   zQm          ! enthalpy exchanged with the ocean (J/m2, >0 towards ocean)
+      REAL(wp) ::   zEi          ! sea ice specific enthalpy (J/kg)
+      REAL(wp) ::   zEw          ! seawater specific enthalpy (J/kg)
+      REAL(wp) ::   zfmdt        ! mass flux x time step (kg/m2, >0 towards ocean)
+     
+      REAL(wp) ::   zv_newfra
+      REAL(wp) ::   zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b ! conservation check
+  
+      INTEGER , DIMENSION(jpij) ::   jcat        ! indexes of categories where new ice grows
+      REAL(wp), DIMENSION(jpij) ::   zswinew     ! switch for new ice or not
+
+      REAL(wp), DIMENSION(jpij) ::   zv_newice   ! volume of accreted ice
+      REAL(wp), DIMENSION(jpij) ::   za_newice   ! fractional area of accreted ice
+      REAL(wp), DIMENSION(jpij) ::   zh_newice   ! thickness of accreted ice
+      REAL(wp), DIMENSION(jpij) ::   ze_newice   ! heat content of accreted ice
+      REAL(wp), DIMENSION(jpij) ::   zs_newice   ! salinity of accreted ice
+      REAL(wp), DIMENSION(jpij) ::   zo_newice   ! age of accreted ice
+      REAL(wp), DIMENSION(jpij) ::   zdv_res     ! residual volume in case of excessive heat budget
+      REAL(wp), DIMENSION(jpij) ::   zda_res     ! residual area in case of excessive heat budget
+      REAL(wp), DIMENSION(jpij) ::   zat_i_1d    ! total ice fraction    
+      REAL(wp), DIMENSION(jpij) ::   zv_frazb    ! accretion of frazil ice at the ice bottom
+      REAL(wp), DIMENSION(jpij) ::   zvrel_1d    ! relative ice / frazil velocity (1D vector)
+
+      REAL(wp), DIMENSION(jpij,jpl) ::   zv_b      ! old volume of ice in category jl
+      REAL(wp), DIMENSION(jpij,jpl) ::   za_b      ! old area of ice in category jl
+      REAL(wp), DIMENSION(jpij,jpl) ::   za_i_1d   ! 1-D version of a_i
+      REAL(wp), DIMENSION(jpij,jpl) ::   zv_i_1d   ! 1-D version of v_i
+      REAL(wp), DIMENSION(jpij,jpl) ::   zsmv_i_1d ! 1-D version of smv_i
+
+      REAL(wp), DIMENSION(jpij,nlay_i,jpl) ::   ze_i_1d !: 1-D version of e_i
+
+      REAL(wp), DIMENSION(jpi,jpj) ::   zvrel     ! relative ice / frazil velocity
+
+      REAL(wp) :: zcai = 1.4e-3_wp                     ! ice-air drag (clem: should be dependent on coupling/forcing used)
+      !!-----------------------------------------------------------------------!
+
+      IF( ln_limdiachk ) CALL ice_cons_hsm(0, 'icethd_lac', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+
+      CALL lim_var_agg(1)
+      CALL lim_var_glo2eqv
+
+      !------------------------------------------------------------------------------!
+      ! 3) Collection thickness of ice formed in leads and polynyas
+      !------------------------------------------------------------------------------!    
+      ! hicol is the thickness of new ice formed in open water
+      ! hicol can be either prescribed (frazswi = 0) or computed (frazswi = 1)
+      ! Frazil ice forms in open water, is transported by wind
+      ! accumulates at the edge of the consolidated ice edge
+      ! where it forms aggregates of a specific thickness called
+      ! collection thickness.
+
+      ! Note : the following algorithm currently breaks vectorization
+      ! 
+
+      zvrel(:,:) = 0._wp
+
+      ! Default new ice thickness
+      WHERE( qlead(:,:) < 0._wp ) ; hicol(:,:) = rn_hnewice
+      ELSEWHERE                   ; hicol(:,:) = 0._wp
+      END WHERE
+
+      IF( ln_frazil ) THEN
+
+         !--------------------
+         ! Physical constants
+         !--------------------
+         hicol(:,:) = 0._wp
+
+         zhicrit = 0.04 ! frazil ice thickness
+         ztwogp  = 2. * rau0 / ( grav * 0.3 * ( rau0 - rhoic ) ) ! reduced grav
+         zsqcd   = 1.0 / SQRT( 1.3 * zcai ) ! 1/SQRT(airdensity*drag)
+         zgamafr = 0.03
+
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               IF ( qlead(ji,jj) < 0._wp .AND. tau_icebfr(ji,jj) == 0._wp ) THEN ! activated if cooling and no landfast
+                  !-------------
+                  ! Wind stress
+                  !-------------
+                  ! C-grid wind stress components
+                  ztaux         = ( utau_ice(ji-1,jj  ) * umask(ji-1,jj  ,1)   &
+                     &          +   utau_ice(ji  ,jj  ) * umask(ji  ,jj  ,1) ) * 0.5_wp
+                  ztauy         = ( vtau_ice(ji  ,jj-1) * vmask(ji  ,jj-1,1)   &
+                     &          +   vtau_ice(ji  ,jj  ) * vmask(ji  ,jj  ,1) ) * 0.5_wp
+                  ! Square root of wind stress
+                  ztenagm       =  SQRT( SQRT( ztaux * ztaux + ztauy * ztauy ) )
+
+                  !---------------------
+                  ! Frazil ice velocity
+                  !---------------------
+                  rswitch = MAX( 0._wp, SIGN( 1._wp , ztenagm - epsi10 ) )
+                  zvfrx   = rswitch * zgamafr * zsqcd * ztaux / MAX( ztenagm, epsi10 )
+                  zvfry   = rswitch * zgamafr * zsqcd * ztauy / MAX( ztenagm, epsi10 )
+
+                  !-------------------
+                  ! Pack ice velocity
+                  !-------------------
+                  ! C-grid ice velocity
+                  zvgx    = ( u_ice(ji-1,jj  ) * umask(ji-1,jj  ,1)  + u_ice(ji,jj) * umask(ji,jj,1) ) * 0.5_wp
+                  zvgy    = ( v_ice(ji  ,jj-1) * vmask(ji  ,jj-1,1)  + v_ice(ji,jj) * vmask(ji,jj,1) ) * 0.5_wp
+
+                  !-----------------------------------
+                  ! Relative frazil/pack ice velocity
+                  !-----------------------------------
+                  ! absolute relative velocity
+                  rswitch      = MAX( 0._wp, SIGN( 1._wp , at_i(ji,jj) - epsi10 ) )
+                  zvrel2       = MAX(  ( zvfrx - zvgx ) * ( zvfrx - zvgx )   &
+                     &               + ( zvfry - zvgy ) * ( zvfry - zvgy ) , 0.15 * 0.15 ) * rswitch
+                  zvrel(ji,jj) = SQRT( zvrel2 )
+
+                  !---------------------
+                  ! Iterative procedure
+                  !---------------------
+                  hicol(ji,jj) = zhicrit +   ( zhicrit + 0.1 )    &
+                     &                   / ( ( zhicrit + 0.1 ) * ( zhicrit + 0.1 ) -  zhicrit * zhicrit ) * ztwogp * zvrel2
+
+                  iter = 1
+                  DO WHILE ( iter < 20 ) 
+                     zf  = ( hicol(ji,jj) - zhicrit ) * ( hicol(ji,jj) * hicol(ji,jj) - zhicrit * zhicrit ) -   &
+                        &    hicol(ji,jj) * zhicrit * ztwogp * zvrel2
+                     zfp = ( hicol(ji,jj) - zhicrit ) * ( 3.0 * hicol(ji,jj) + zhicrit ) - zhicrit * ztwogp * zvrel2
+
+                     hicol(ji,jj) = hicol(ji,jj) - zf / MAX( zfp, epsi20 )
+                     iter = iter + 1
+                  END DO
+
+               ENDIF ! end of selection of pixels where ice forms
+
+            END DO 
+         END DO 
+         ! 
+         CALL lbc_lnk_multi( zvrel, 'T', 1., hicol, 'T', 1.  )
+
+      ENDIF ! End of computation of frazil ice collection thickness
+
+      !------------------------------------------------------------------------------!
+      ! 4) Identify grid points where new ice forms
+      !------------------------------------------------------------------------------!
+
+      !-------------------------------------
+      ! Select points for new ice formation
+      !-------------------------------------
+      ! This occurs if open water energy budget is negative (cooling) and there is no landfast ice
+      nidx = 0 ; idxice(:) = 0
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF ( qlead(ji,jj)  <  0._wp .AND. tau_icebfr(ji,jj) == 0._wp ) THEN
+               nidx = nidx + 1
+               idxice( nidx ) = (jj - 1) * jpi + ji
+            ENDIF
+         END DO
+      END DO
+
+      !------------------------------
+      ! Move from 2-D to 1-D vectors
+      !------------------------------
+      ! If ocean gains heat do nothing. Otherwise compute new ice formation
+
+      IF ( nidx > 0 ) THEN
+
+         CALL tab_2d_1d( nidx, idxice(1:nidx), zat_i_1d  (1:nidx)     , at_i           )
+         DO jl = 1, jpl
+            CALL tab_2d_1d( nidx, idxice(1:nidx), za_i_1d  (1:nidx,jl), a_i  (:,:,jl)  )
+            CALL tab_2d_1d( nidx, idxice(1:nidx), zv_i_1d  (1:nidx,jl), v_i  (:,:,jl)  )
+            CALL tab_2d_1d( nidx, idxice(1:nidx), zsmv_i_1d(1:nidx,jl), smv_i(:,:,jl)  )
+            DO jk = 1, nlay_i
+               CALL tab_2d_1d( nidx, idxice(1:nidx), ze_i_1d(1:nidx,jk,jl), e_i(:,:,jk,jl)   )
+            END DO
+         END DO
+
+         CALL tab_2d_1d( nidx, idxice(1:nidx), qlead_1d  (1:nidx)     , qlead       )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), t_bo_1d   (1:nidx)     , t_bo        )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_opw_1d(1:nidx)     , sfx_opw     )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_opw_1d(1:nidx)     , wfx_opw     )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), hicol_1d  (1:nidx)     , hicol       )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), zvrel_1d  (1:nidx)     , zvrel       )
+
+         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_thd_1d(1:nidx)     , hfx_thd     )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_opw_1d(1:nidx)     , hfx_opw     )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), rn_amax_1d(1:nidx)     , rn_amax_2d  )
+         CALL tab_2d_1d( nidx, idxice(1:nidx), sss_1d    (1:nidx)     , sss_m       )
+
+         !------------------------------------------------------------------------------|
+         ! 2) Convert units for ice internal energy
+         !------------------------------------------------------------------------------|
+         DO jl = 1, jpl
+            DO jk = 1, nlay_i
+               DO ji = 1, nidx
+                  IF( zv_i_1d(ji,jl) > 0._wp )   ze_i_1d(ji,jk,jl) = ze_i_1d(ji,jk,jl) / zv_i_1d(ji,jl) * REAL( nlay_i )
+               END DO
+            END DO
+         END DO
+         !------------------------------------------------------------------------------!
+         ! 5) Compute thickness, salinity, enthalpy, age, area and volume of new ice
+         !------------------------------------------------------------------------------!
+
+         !-----------------------------------------
+         ! Keep old ice areas and volume in memory
+         !-----------------------------------------
+         zv_b(1:nidx,:) = zv_i_1d(1:nidx,:) 
+         za_b(1:nidx,:) = za_i_1d(1:nidx,:)
+
+         !----------------------
+         ! Thickness of new ice
+         !----------------------
+         zh_newice(1:nidx) = hicol_1d(1:nidx)
+
+         !----------------------
+         ! Salinity of new ice 
+         !----------------------
+         SELECT CASE ( nn_icesal )
+         CASE ( 1 )                    ! Sice = constant 
+            zs_newice(1:nidx) = rn_icesal
+         CASE ( 2 )                    ! Sice = F(z,t) [Vancoppenolle et al (2005)]
+            DO ji = 1, nidx
+               zs_newice(ji) = MIN(  4.606 + 0.91 / zh_newice(ji) , rn_simax , 0.5 * sss_1d(ji) )
+            END DO
+         CASE ( 3 )                    ! Sice = F(z) [multiyear ice]
+            zs_newice(1:nidx) =   2.3
+         END SELECT
+
+         !-------------------------
+         ! Heat content of new ice
+         !-------------------------
+         ! We assume that new ice is formed at the seawater freezing point
+         DO ji = 1, nidx
+            ztmelts       = - tmut * zs_newice(ji) + rt0                  ! Melting point (K)
+            ze_newice(ji) =   rhoic * (  cpic * ( ztmelts - t_bo_1d(ji) )                                         &
+               &                       + lfus * ( 1.0 - ( ztmelts - rt0 ) / MIN( t_bo_1d(ji) - rt0, -epsi10 ) )   &
+               &                       - rcp  *         ( ztmelts - rt0 )  )
+         END DO
+
+         !----------------
+         ! Age of new ice
+         !----------------
+         DO ji = 1, nidx
+            zo_newice(ji) = 0._wp
+         END DO
+
+         !-------------------
+         ! Volume of new ice
+         !-------------------
+         DO ji = 1, nidx
+
+            zEi           = - ze_newice(ji) * r1_rhoic             ! specific enthalpy of forming ice [J/kg]
+
+            zEw           = rcp * ( t_bo_1d(ji) - rt0 )            ! specific enthalpy of seawater at t_bo_1d [J/kg]
+                                                                   ! clem: we suppose we are already at the freezing point (condition qlead<0 is satisfyied) 
+                                                                   
+            zdE           = zEi - zEw                              ! specific enthalpy difference [J/kg]
+                                              
+            zfmdt         = - qlead_1d(ji) / zdE                   ! Fm.dt [kg/m2] (<0) 
+                                                                   ! clem: we use qlead instead of zqld (icethd) because we suppose we are at the freezing point   
+            zv_newice(ji) = - zfmdt * r1_rhoic
+
+            zQm           = zfmdt * zEw                            ! heat to the ocean >0 associated with mass flux  
+
+            ! Contribution to heat flux to the ocean [W.m-2], >0  
+            hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * zEw * r1_rdtice
+            ! Total heat flux used in this process [W.m-2]  
+            hfx_opw_1d(ji) = hfx_opw_1d(ji) - zfmdt * zdE * r1_rdtice
+            ! mass flux
+            wfx_opw_1d(ji) = wfx_opw_1d(ji) - zv_newice(ji) * rhoic * r1_rdtice
+            ! salt flux
+            sfx_opw_1d(ji) = sfx_opw_1d(ji) - zv_newice(ji) * rhoic * zs_newice(ji) * r1_rdtice
+         END DO
+         
+         zv_frazb(:) = 0._wp
+         IF( ln_frazil ) THEN
+            ! A fraction zfrazb of frazil ice is accreted at the ice bottom
+            DO ji = 1, nidx
+               rswitch       = 1._wp - MAX( 0._wp, SIGN( 1._wp , - zat_i_1d(ji) ) )
+               zfrazb        = rswitch * ( TANH( rn_Cfrazb * ( zvrel_1d(ji) - rn_vfrazb ) ) + 1.0 ) * 0.5 * rn_maxfrazb
+               zv_frazb(ji)  =         zfrazb   * zv_newice(ji)
+               zv_newice(ji) = ( 1.0 - zfrazb ) * zv_newice(ji)
+            END DO
+         END IF
+         
+         !-----------------
+         ! Area of new ice
+         !-----------------
+         DO ji = 1, nidx
+            za_newice(ji) = zv_newice(ji) / zh_newice(ji)
+         END DO
+
+         !------------------------------------------------------------------------------!
+         ! 6) Redistribute new ice area and volume into ice categories                  !
+         !------------------------------------------------------------------------------!
+
+         !------------------------
+         ! 6.1) lateral ice growth
+         !------------------------
+         ! If lateral ice growth gives an ice concentration gt 1, then
+         ! we keep the excessive volume in memory and attribute it later to bottom accretion
+         DO ji = 1, nidx
+            IF ( za_newice(ji) >  ( rn_amax_1d(ji) - zat_i_1d(ji) ) ) THEN
+               zda_res(ji)   = za_newice(ji) - ( rn_amax_1d(ji) - zat_i_1d(ji) )
+               zdv_res(ji)   = zda_res  (ji) * zh_newice(ji) 
+               za_newice(ji) = za_newice(ji) - zda_res  (ji)
+               zv_newice(ji) = zv_newice(ji) - zdv_res  (ji)
+            ELSE
+               zda_res(ji) = 0._wp
+               zdv_res(ji) = 0._wp
+            ENDIF
+         END DO
+
+         ! find which category to fill
+         zat_i_1d(:) = 0._wp
+         DO jl = 1, jpl
+            DO ji = 1, nidx
+               IF( zh_newice(ji) > hi_max(jl-1) .AND. zh_newice(ji) <= hi_max(jl) ) THEN
+                  za_i_1d (ji,jl) = za_i_1d (ji,jl) + za_newice(ji)
+                  zv_i_1d (ji,jl) = zv_i_1d (ji,jl) + zv_newice(ji)
+                  jcat    (ji)    = jl
+               ENDIF
+               zat_i_1d(ji) = zat_i_1d(ji) + za_i_1d  (ji,jl)
+            END DO
+         END DO
+
+         ! Heat content
+         DO ji = 1, nidx
+            jl = jcat(ji)                                                    ! categroy in which new ice is put
+            zswinew  (ji) = MAX( 0._wp , SIGN( 1._wp , - za_b(ji,jl) ) )   ! 0 if old ice
+         END DO
+
+         DO jk = 1, nlay_i
+            DO ji = 1, nidx
+               jl = jcat(ji)
+               rswitch = MAX( 0._wp, SIGN( 1._wp , zv_i_1d(ji,jl) - epsi20 ) )
+               ze_i_1d(ji,jk,jl) = zswinew(ji)   *   ze_newice(ji) +                                                    &
+                  &        ( 1.0 - zswinew(ji) ) * ( ze_newice(ji) * zv_newice(ji) + ze_i_1d(ji,jk,jl) * zv_b(ji,jl) )  &
+                  &        * rswitch / MAX( zv_i_1d(ji,jl), epsi20 )
+            END DO
+         END DO
+
+         !------------------------------------------------
+         ! 6.2) bottom ice growth + ice enthalpy remapping
+         !------------------------------------------------
+         DO jl = 1, jpl
+
+            ! for remapping
+            h_i_old (1:nidx,0:nlay_i+1) = 0._wp
+            eh_i_old(1:nidx,0:nlay_i+1) = 0._wp
+            DO jk = 1, nlay_i
+               DO ji = 1, nidx
+                  h_i_old (ji,jk) = zv_i_1d(ji,jl) * r1_nlay_i
+                  eh_i_old(ji,jk) = ze_i_1d(ji,jk,jl) * h_i_old(ji,jk)
+               END DO
+            END DO
+
+            ! new volumes including lateral/bottom accretion + residual
+            DO ji = 1, nidx
+               rswitch        = MAX( 0._wp, SIGN( 1._wp , zat_i_1d(ji) - epsi20 ) )
+               zv_newfra      = rswitch * ( zdv_res(ji) + zv_frazb(ji) ) * za_i_1d(ji,jl) / MAX( zat_i_1d(ji) , epsi20 )
+               za_i_1d(ji,jl) = rswitch * za_i_1d(ji,jl)               
+               zv_i_1d(ji,jl) = zv_i_1d(ji,jl) + zv_newfra
+               ! for remapping
+               h_i_old (ji,nlay_i+1) = zv_newfra
+               eh_i_old(ji,nlay_i+1) = ze_newice(ji) * zv_newfra
+            ENDDO
+            ! --- Ice enthalpy remapping --- !
+            CALL ice_thd_ent( ze_i_1d(1:nidx,:,jl) ) 
+         ENDDO
+
+         !-----------------
+         ! Update salinity
+         !-----------------
+         DO jl = 1, jpl
+            DO ji = 1, nidx
+               zdv   = zv_i_1d(ji,jl) - zv_b(ji,jl)
+               zsmv_i_1d(ji,jl) = zsmv_i_1d(ji,jl) + zdv * zs_newice(ji)
+            END DO
+         END DO
+
+         !------------------------------------------------------------------------------!
+         ! 8) Change units for e_i
+         !------------------------------------------------------------------------------!    
+         DO jl = 1, jpl
+            DO jk = 1, nlay_i
+               DO ji = 1, nidx
+                  ze_i_1d(ji,jk,jl) = ze_i_1d(ji,jk,jl) * zv_i_1d(ji,jl) * r1_nlay_i 
+               END DO
+            END DO
+         END DO
+         !------------------------------------------------------------------------------!
+         ! 7) Change 2D vectors to 1D vectors 
+         !------------------------------------------------------------------------------!
+         DO jl = 1, jpl
+            CALL tab_1d_2d( nidx, idxice(1:nidx), za_i_1d (1:nidx,jl), a_i (:,:,jl)  )
+            CALL tab_1d_2d( nidx, idxice(1:nidx), zv_i_1d (1:nidx,jl), v_i (:,:,jl)  )
+            CALL tab_1d_2d( nidx, idxice(1:nidx), zsmv_i_1d(1:nidx,jl), smv_i (:,:,jl)   )
+            DO jk = 1, nlay_i
+               CALL tab_1d_2d( nidx, idxice(1:nidx), ze_i_1d(1:nidx,jk,jl), e_i(:,:,jk,jl)  )
+            END DO
+         END DO
+         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_opw_1d(1:nidx), sfx_opw  )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_opw_1d(1:nidx), wfx_opw  )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_thd_1d(1:nidx), hfx_thd  )
+         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_opw_1d(1:nidx), hfx_opw  )
+         !
+      ENDIF ! nidx > 0
+      !
+      IF( ln_limdiachk ) CALL ice_cons_hsm(1, 'icethd_lac', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+      !
+   END SUBROUTINE ice_thd_lac
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                               NO  LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE ice_thd_lac           ! Empty routine
+   END SUBROUTINE ice_thd_lac
+#endif
+
+   !!======================================================================
+END MODULE icethd_lac
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 8422)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icethd_sal.F90	(revision 8422)
@@ -0,0 +1,157 @@
+MODULE icethd_sal
+   !!======================================================================
+   !!                       ***  MODULE icethd_sal ***
+   !! LIM-3 sea-ice :  computation of salinity variations in the ice
+   !!======================================================================
+   !! History :   -   ! 2003-05 (M. Vancoppenolle) UCL-ASTR first coding for LIM3-1D
+   !!            3.0  ! 2005-12 (M. Vancoppenolle) adapted to the 3-D version
+   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!---------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM-3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!   ice_thd_sal   : salinity variations in the ice
+   !!----------------------------------------------------------------------
+   USE par_oce        ! ocean parameters
+   USE phycst         ! physical constants (ocean directory)
+   USE ice            ! LIM variables
+   USE ice1D          ! LIM thermodynamics
+   USE limvar         ! LIM variables
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_thd_sal        ! called by icethd module
+   PUBLIC   ice_thd_sal_init   ! called by ice_init
+
+   !!----------------------------------------------------------------------
+   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! $Id: icethd_sal.F90 8420 2017-08-08 12:18:46Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_thd_sal
+      !!-------------------------------------------------------------------
+      !!                ***  ROUTINE ice_thd_sal  ***    
+      !!   
+      !! ** Purpose :   computes new salinities in the ice
+      !!
+      !! ** Method  :  3 possibilities
+      !!               -> nn_icesal = 1 -> Sice = cst    [ice salinity constant in both time & space] 
+      !!               -> nn_icesal = 2 -> Sice = S(z,t) [Vancoppenolle et al. 2005]
+      !!               -> nn_icesal = 3 -> Sice = S(z)   [multiyear ice]
+      !!---------------------------------------------------------------------
+      INTEGER  ::   ji, jk                       ! dummy loop indices 
+      REAL(wp) ::   iflush, igravdr              ! local scalars
+      REAL(wp) ::   zs_sni, zsm_i_gd, zsm_i_fl, zsm_i_si, zsm_i_bg   ! local scalars
+      !!---------------------------------------------------------------------
+
+      !--------------------------------------------------------------------|
+      ! 1) salinity constant in time                                       |
+      !--------------------------------------------------------------------|
+      ! do nothing
+
+      !----------------------------------------------------------------------|
+      !  2) salinity varying in time                                         |
+      !----------------------------------------------------------------------|
+      IF(  nn_icesal == 2  ) THEN
+
+         DO ji = 1, nidx
+
+            !---------------------------------------------------------
+            !  Update ice salinity from snow-ice and bottom growth
+            !---------------------------------------------------------
+            zs_sni   = sss_1d(ji) * ( rhoic - rhosn ) * r1_rhoic   ! Salinity of snow ice
+            rswitch  = MAX( 0._wp , SIGN( 1._wp , ht_i_1d(ji) - epsi20 ) )
+            zsm_i_si = ( zs_sni      - sm_i_1d(ji) ) *             dh_snowice(ji)  / MAX( ht_i_1d(ji), epsi20 ) * rswitch ! snow-ice    
+            zsm_i_bg = ( s_i_new(ji) - sm_i_1d(ji) ) * MAX( 0._wp, dh_i_bott(ji) ) / MAX( ht_i_1d(ji), epsi20 ) * rswitch ! bottom growth
+
+            ! Update salinity (nb: salt flux already included in icethd_dh)
+            sm_i_1d(ji) = sm_i_1d(ji) + zsm_i_bg + zsm_i_si
+
+            IF( ln_limdS ) THEN
+               !---------------------------------------------------------
+               !  Update ice salinity from brine drainage and flushing
+               !---------------------------------------------------------
+               iflush   = MAX( 0._wp , SIGN( 1._wp , t_su_1d(ji) - rt0         ) )  ! =1 if summer 
+               igravdr  = MAX( 0._wp , SIGN( 1._wp , t_bo_1d(ji) - t_su_1d(ji) ) )  ! =1 if t_su < t_bo
+               zsm_i_gd = - igravdr * MAX( sm_i_1d(ji) - rn_sal_gd , 0._wp ) / rn_time_gd * rdt_ice  ! gravity drainage 
+               zsm_i_fl = - iflush  * MAX( sm_i_1d(ji) - rn_sal_fl , 0._wp ) / rn_time_fl * rdt_ice  ! flushing
+               
+               ! Update salinity   
+               sm_i_1d(ji) = sm_i_1d(ji) + zsm_i_fl + zsm_i_gd
+               
+               ! Salt flux
+               sfx_bri_1d(ji) = sfx_bri_1d(ji) - rhoic * a_i_1d(ji) * ht_i_1d(ji) * ( zsm_i_fl + zsm_i_gd ) * r1_rdtice
+            ENDIF
+         END DO
+
+         ! Salinity profile
+         CALL lim_var_salprof1d
+         !
+      ENDIF 
+
+      !------------------------------------------------------------------------------|
+      !  3) vertical profile of salinity, constant in time                           |
+      !------------------------------------------------------------------------------|
+      IF(  nn_icesal == 3  )   CALL lim_var_salprof1d
+
+      !
+   END SUBROUTINE ice_thd_sal
+
+
+   SUBROUTINE ice_thd_sal_init
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE ice_thd_sal_init  ***
+      !!
+      !! ** Purpose :   initialization of ice salinity parameters
+      !!
+      !! ** Method  :   Read the namicesal namelist and check the parameter
+      !!              values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namicesal
+      !!-------------------------------------------------------------------
+      INTEGER  ::   ios                 ! Local integer output status for namelist read
+      NAMELIST/namicesal/ ln_limdS, nn_icesal, rn_icesal, rn_sal_gd, rn_time_gd,   &
+         &                rn_sal_fl, rn_time_fl, rn_simax, rn_simin 
+      !!-------------------------------------------------------------------
+      !
+      REWIND( numnam_ice_ref )              ! Namelist namicesal in reference namelist : Ice salinity
+      READ  ( numnam_ice_ref, namicesal, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicesal in reference namelist', lwp )
+
+      REWIND( numnam_ice_cfg )              ! Namelist namicesal in configuration namelist : Ice salinity
+      READ  ( numnam_ice_cfg, namicesal, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicesal in configuration namelist', lwp )
+      IF(lwm) WRITE ( numoni, namicesal )
+      !
+      IF(lwp) THEN                           ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'ice_thd_sal_init : Ice parameters for salinity '
+         WRITE(numout,*) '~~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '   activate gravity drainage and flushing (T) or not (F)   ln_limdS   = ', ln_limdS
+         WRITE(numout,*) '   switch for salinity                                     nn_icesal  = ', nn_icesal
+         WRITE(numout,*) '   bulk salinity value if nn_icesal = 1                    rn_icesal  = ', rn_icesal
+         WRITE(numout,*) '   restoring salinity for gravity drainage                 rn_sal_gd  = ', rn_sal_gd
+         WRITE(numout,*) '   restoring time for for gravity drainage                 rn_time_gd = ', rn_time_gd
+         WRITE(numout,*) '   restoring salinity for flushing                         rn_sal_fl  = ', rn_sal_fl
+         WRITE(numout,*) '   restoring time for flushing                             rn_time_fl = ', rn_time_fl
+         WRITE(numout,*) '   Maximum tolerated ice salinity                          rn_simax   = ', rn_simax
+         WRITE(numout,*) '   Minimum tolerated ice salinity                          rn_simin   = ', rn_simin
+      ENDIF
+      !
+   END SUBROUTINE ice_thd_sal_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Dummy Module          No LIM-3 sea-ice model
+   !!----------------------------------------------------------------------
+#endif
+   !!======================================================================
+END MODULE icethd_sal
Index: anches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limitd_th.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limitd_th.F90	(revision 8421)
+++ 	(revision )
@@ -1,663 +1,0 @@
-MODULE limitd_th
-   !!======================================================================
-   !!                       ***  MODULE limitd_th ***
-   !!   LIM3 ice model : ice thickness distribution: Thermodynamics
-   !!======================================================================
-   !! History :   -   !          (W. H. Lipscomb and E.C. Hunke) CICE (c) original code
-   !!            3.0  ! 2005-12  (M. Vancoppenolle) adaptation to LIM-3
-   !!             -   ! 2006-06  (M. Vancoppenolle) adaptation to include salt, age
-   !!             -   ! 2007-04  (M. Vancoppenolle) Mass conservation checked
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3' :                                   LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_itd_th_rem   :
-   !!   lim_itd_th_reb   :
-   !!   lim_itd_glinear  :
-   !!   lim_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 limvar           ! LIM-3 variables
-   USE icecons          ! conservation tests
-   USE icetab
-   !
-   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
-   PRIVATE
-
-   PUBLIC   lim_itd_th_rem   ! called in limthd
-   PUBLIC   lim_itd_th_reb   ! called in iceerr
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_itd_th_rem( kt )
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_th_rem ***
-      !!
-      !! ** Purpose :   computes the redistribution of ice thickness
-      !!              after thermodynamic growth of ice thickness
-      !!
-      !! ** Method  : Linear remapping 
-      !!
-      !! References : W.H. Lipscomb, JGR 2001
-      !!------------------------------------------------------------------
-      INTEGER , INTENT (in) ::   kt      ! Ocean time step 
-      !
-      INTEGER  ::   ji, jj, jl, jcat     ! dummy loop index
-      INTEGER  ::   nidx2                ! local integer
-      REAL(wp) ::   zx1, zwk1, zdh0, zetamin, zdamax   ! local scalars
-      REAL(wp) ::   zx2, zwk2, zda0, zetamax           !   -      -
-      REAL(wp) ::   zx3        
-      REAL(wp) ::   zslope          ! used to compute local thermodynamic "speeds"
-      REAL(wp) ::   zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b ! conservation check
-
-      INTEGER , DIMENSION(jpij)       ::   idxice2         ! compute remapping or not
-      INTEGER , DIMENSION(jpij,jpl-1) ::   jdonor          ! donor category index
-      REAL(wp), DIMENSION(jpij,jpl)   ::   zdhice          ! ice thickness increment
-      REAL(wp), DIMENSION(jpij,jpl)   ::   g0, g1          ! coefficients for fitting the line of the ITD
-      REAL(wp), DIMENSION(jpij,jpl)   ::   hL, hR          ! left and right boundary for the ITD for each thickness
-      REAL(wp), DIMENSION(jpij,jpl-1) ::   zdaice, zdvice  ! local increment of ice area and volume
-      REAL(wp), DIMENSION(jpij)       ::   zhb0, zhb1      ! category boundaries for thinnes categories
-      REAL(wp), DIMENSION(jpij,0:jpl) ::   zhbnew          ! new boundaries of ice categories
-      !!------------------------------------------------------------------
-
-      IF( kt == nit000 .AND. lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_itd_th_rem  : Remapping the ice thickness distribution'
-         WRITE(numout,*) '~~~~~~~~~~~~~~~'
-      ENDIF
-
-      IF( ln_limdiachk ) CALL ice_cons_hsm(0, 'limitd_th_rem', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      !-----------------------------------------------------------------------------------------------
-      !  1) Identify grid cells with ice
-      !-----------------------------------------------------------------------------------------------
-      nidx = 0 ; idxice(:) = 0
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF ( at_i(ji,jj) > epsi10 ) THEN
-               nidx         = nidx + 1
-               idxice( nidx ) = (jj - 1) * jpi + ji
-            ENDIF
-         END DO
-      END DO
-      
-      !-----------------------------------------------------------------------------------------------
-      !  2) Compute new category boundaries
-      !-----------------------------------------------------------------------------------------------
-      IF( nidx > 0 ) THEN
-
-         zdhice(:,:) = 0._wp
-         zhbnew(:,:) = 0._wp
-
-         CALL tab_3d_2d( nidx, idxice(1:nidx), ht_i_2d (1:nidx,1:jpl), ht_i   )
-         CALL tab_3d_2d( nidx, idxice(1:nidx), ht_ib_2d(1:nidx,1:jpl), ht_i_b )
-         CALL tab_3d_2d( nidx, idxice(1:nidx), a_i_2d  (1:nidx,1:jpl), a_i    )
-         CALL tab_3d_2d( nidx, idxice(1:nidx), a_ib_2d (1:nidx,1:jpl), a_i_b  )
-
-         DO jl = 1, jpl
-            ! Compute thickness change in each ice category
-            DO ji = 1, nidx
-               zdhice(ji,jl) = ht_i_2d(ji,jl) - ht_ib_2d(ji,jl)
-            END DO
-         END DO
-         
-         ! --- New boundaries for category 1:jpl-1 --- !
-         DO jl = 1, jpl - 1
-
-            DO ji = 1, nidx
-               !
-               ! --- New boundary: Hn* = Hn + Fn*dt --- !
-               !     Fn*dt = ( fn + (fn+1 - fn)/(hn+1 - hn) * (Hn - hn) ) * dt = zdhice + zslope * (Hmax - ht_i_b)
-               !
-               IF    ( a_ib_2d(ji,jl) >  epsi10 .AND. a_ib_2d(ji,jl+1) >  epsi10 ) THEN   ! a(jl+1) & a(jl) /= 0
-                  zslope           = ( zdhice(ji,jl+1) - zdhice(ji,jl) ) / ( ht_ib_2d(ji,jl+1) - ht_ib_2d(ji,jl) )
-                  zhbnew(ji,jl) = hi_max(jl) + zdhice(ji,jl) + zslope * ( hi_max(jl) - ht_ib_2d(ji,jl) )
-               ELSEIF( a_ib_2d(ji,jl) >  epsi10 .AND. a_ib_2d(ji,jl+1) <= epsi10 ) THEN   ! a(jl+1)=0 => Hn* = Hn + fn*dt
-                  zhbnew(ji,jl) = hi_max(jl) + zdhice(ji,jl)
-               ELSEIF( a_ib_2d(ji,jl) <= epsi10 .AND. a_ib_2d(ji,jl+1) >  epsi10 ) THEN   ! a(jl)=0 => Hn* = Hn + fn+1*dt
-                  zhbnew(ji,jl) = hi_max(jl) + zdhice(ji,jl+1)
-               ELSE                                                                       ! a(jl+1) & a(jl) = 0 
-                  zhbnew(ji,jl) = hi_max(jl)
-               ENDIF
-            
-               ! --- 2 conditions for remapping --- !
-               ! 1) hn(t+1)+espi < Hn* < hn+1(t+1)-epsi               
-               !    Note: hn(t+1) must not be too close to either HR or HL otherwise a division by nearly 0 is possible 
-               !          in lim_itd_glinear in the case (HR-HL) = 3(Hice - HL) or = 3(HR - Hice)
-               IF( a_i_2d(ji,jl  ) > epsi10 .AND. ht_i_2d(ji,jl  ) > ( zhbnew(ji,jl) - epsi10 ) )   idxice(ji) = 0
-               IF( a_i_2d(ji,jl+1) > epsi10 .AND. ht_i_2d(ji,jl+1) < ( zhbnew(ji,jl) + epsi10 ) )   idxice(ji) = 0
-               
-               ! 2) Hn-1 < Hn* < Hn+1  
-               IF( zhbnew(ji,jl) < hi_max(jl-1) )   idxice(ji) = 0
-               IF( zhbnew(ji,jl) > hi_max(jl+1) )   idxice(ji) = 0
-               
-            END DO
-         END DO
-         
-         ! --- New boundaries for category jpl --- !
-         DO ji = 1, nidx
-            IF( a_i_2d(ji,jpl) > epsi10 ) THEN
-               zhbnew(ji,jpl) = MAX( hi_max(jpl-1), 3._wp * ht_i_2d(ji,jpl) - 2._wp * zhbnew(ji,jpl-1) )
-            ELSE
-               zhbnew(ji,jpl) = hi_max(jpl)  
-            ENDIF
-            
-            ! --- 1 additional condition for remapping (1st category) --- !
-            ! H0+epsi < h1(t) < H1-epsi 
-            !    h1(t) must not be too close to either HR or HL otherwise a division by nearly 0 is possible 
-            !    in lim_itd_glinear in the case (HR-HL) = 3(Hice - HL) or = 3(HR - Hice)
-            IF( ht_ib_2d(ji,1) < ( hi_max(0) + epsi10 ) )   idxice(ji) = 0
-            IF( ht_ib_2d(ji,1) > ( hi_max(1) - epsi10 ) )   idxice(ji) = 0
-         END DO
-
-         !-----------------------------------------------------------------------------------------------
-         !  3) Identify cells where remapping
-         !-----------------------------------------------------------------------------------------------
-         nidx2 = 0 ; idxice2(:) = 0
-         DO ji = 1, nidx
-            IF( idxice(ji) /= 0 ) THEN
-               nidx2 = nidx2 + 1
-               idxice2(nidx2) = idxice(ji)
-               zhbnew(nidx2,:) = zhbnew(ji,:)  ! adjust zhbnew to new indices
-            ENDIF
-         END DO
-         idxice(:) = idxice2(:)
-         nidx      = nidx2
-         
-      ENDIF
-   
-
-      !-----------------------------------------------------------------------------------------------
-      !  4) Compute g(h) 
-      !-----------------------------------------------------------------------------------------------
-      IF( nidx > 0 ) THEN
-
-         zhb0(:) = hi_max(0) ; zhb1(:) = hi_max(1)
-         g0(:,:) = 0._wp     ; g1(:,:) = 0._wp 
-         hL(:,:) = 0._wp     ; hR(:,:) = 0._wp 
-         
-         DO jl = 1, jpl
-
-            CALL tab_2d_1d( 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 lim_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
-                        zdh0 = MIN( -zdh0, hi_max(1) )
-                        !Integrate g(1) from 0 to dh0 to estimate area melted
-                        zetamax = MIN( zdh0, hR(ji,1) ) - hL(ji,1)
-                        
-                        IF( zetamax > 0.0 ) THEN
-                           zx1    = zetamax
-                           zx2    = 0.5 * zetamax * zetamax 
-                           zda0   = g1(ji,1) * zx2 + g0(ji,1) * zx1                        ! ice area removed
-                           zdamax = a_i_1d(ji) * (1.0 - ht_i_1d(ji) / ht_ib_1d(ji) ) ! Constrain new thickness <= ht_i                
-                           zda0   = MIN( zda0, zdamax )                                                  ! ice area lost due to melting 
-                           !     of thin ice (zdamax > 0)
-                           ! Remove area, conserving volume
-                           ht_i_1d(ji) = ht_i_1d(ji) * a_i_1d(ji) / ( a_i_1d(ji) - zda0 )
-                           a_i_1d(ji)  = a_i_1d(ji) - zda0
-                           v_i_1d(ji)  = a_i_1d(ji) * 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 lim_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
-         
-         !-----------------------------------------------------------------------------------------------
-         !  5) Compute area and volume to be shifted across each boundary (Eq. 18)
-         !-----------------------------------------------------------------------------------------------
-         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
-                  zetamin = MAX( hi_max(jl)   , hL(ji,jl) ) - hL(ji,jl)   ! hi_max(jl) - hL 
-                  zetamax = MIN( zhbnew(ji,jl), hR(ji,jl) ) - hL(ji,jl)   ! hR - hL
-                  jdonor(ji,jl) = jl
-               ELSE                                 ! Hn* <= Hn => transfer from jl+1 to jl
-                  zetamin = 0.0
-                  zetamax = MIN( hi_max(jl), hR(ji,jl+1) ) - hL(ji,jl+1)  ! hi_max(jl) - hL
-                  jdonor(ji,jl) = jl + 1
-               ENDIF
-               zetamax = MAX( zetamax, zetamin ) ! no transfer if etamax < etamin
-               
-               zx1  = zetamax - zetamin
-               zwk1 = zetamin * zetamin
-               zwk2 = zetamax * zetamax
-               zx2  = 0.5 * ( zwk2 - zwk1 )
-               zwk1 = zwk1 * zetamin
-               zwk2 = zwk2 * zetamax
-               zx3  = 1.0 / 3.0 * ( zwk2 - zwk1 )
-               jcat = jdonor(ji,jl)
-               zdaice(ji,jl) = g1(ji,jcat)*zx2 + g0(ji,jcat)*zx1
-               zdvice(ji,jl) = g1(ji,jcat)*zx3 + g0(ji,jcat)*zx2 + zdaice(ji,jl)*hL(ji,jcat)
-               
-            END DO
-         END DO
-         
-         !----------------------------------------------------------------------------------------------
-         ! 6) Shift ice between categories
-         !----------------------------------------------------------------------------------------------
-         CALL lim_itd_shiftice ( jdonor(1:nidx,:), zdaice(1:nidx,:), zdvice(1:nidx,:) )
-         
-         !----------------------------------------------------------------------------------------------
-         ! 7) Make sure ht_i >= minimum ice thickness hi_min
-         !----------------------------------------------------------------------------------------------
-         CALL tab_2d_1d( nidx, idxice(1:nidx), ht_i_1d (1:nidx), ht_i(:,:,1)   )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), a_i_1d  (1:nidx), a_i(:,:,1)    )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), a_ip_1d (1:nidx), a_ip(:,:,1)    )
-         
-         DO ji = 1, nidx
-            IF ( a_i_1d(ji) > epsi10 .AND. ht_i_1d(ji) < rn_himin ) THEN
-               a_i_1d (ji) = a_i_1d(ji) * ht_i_1d(ji) / rn_himin 
-               ! MV MP 2016
-               IF ( nn_pnd_scheme > 0 ) THEN
-                  a_ip_1d(ji) = a_ip_1d(ji) * ht_i_1d(ji) / rn_himin
-               ENDIF
-               ! END MV MP 2016
-               ht_i_1d(ji) = rn_himin
-            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, 'limitd_th_rem', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-   END SUBROUTINE lim_itd_th_rem
-
-
-   SUBROUTINE lim_itd_glinear( HbL, Hbr, phice, paice, pg0, pg1, phL, phR )
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_glinear ***
-      !!
-      !! ** Purpose :   build g(h) satisfying area and volume constraints (Eq. 6 and 9)
-      !!
-      !! ** Method  :   g(h) is linear and written as: g(eta) = g1(eta) + g0
-      !!                with eta = h - HL
-      !!                
-      !!------------------------------------------------------------------
-      REAL(wp), DIMENSION(:), INTENT(in   ) ::   HbL, HbR      ! left and right category boundaries
-      REAL(wp), DIMENSION(:), INTENT(in   ) ::   phice, paice  ! ice thickness and concentration
-      REAL(wp), DIMENSION(:), INTENT(inout) ::   pg0, pg1      ! coefficients in linear equation for g(eta)
-      REAL(wp), DIMENSION(:), INTENT(inout) ::   phL, phR      ! min and max value of range over which g(h) > 0
-      !
-      INTEGER  ::   ji           ! horizontal indices
-      REAL(wp) ::   zh13         ! HbL + 1/3 * (HbR - HbL)
-      REAL(wp) ::   zh23         ! HbL + 2/3 * (HbR - HbL)
-      REAL(wp) ::   zdhr         ! 1 / (hR - hL)
-      REAL(wp) ::   zwk1, zwk2   ! temporary variables
-      !!------------------------------------------------------------------
-      !
-         DO 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
-      !
-   END SUBROUTINE lim_itd_glinear
-
-
-   SUBROUTINE lim_itd_shiftice( kdonor, pdaice, pdvice )
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_shiftice ***
-      !!
-      !! ** 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
-
-      REAL(wp) ::   ztrans             ! ice/snow transferred
-      !!------------------------------------------------------------------
-         
-      CALL tab_3d_2d( nidx, idxice(1:nidx), ht_i_2d (1:nidx,1:jpl), ht_i   )
-      CALL tab_3d_2d( nidx, idxice(1:nidx), a_i_2d  (1:nidx,1:jpl), a_i    )
-      CALL tab_3d_2d( nidx, idxice(1:nidx), v_i_2d  (1:nidx,1:jpl), v_i    )
-      CALL tab_3d_2d( nidx, idxice(1:nidx), v_s_2d  (1:nidx,1:jpl), v_s    )
-      CALL tab_3d_2d( nidx, idxice(1:nidx), oa_i_2d (1:nidx,1:jpl), oa_i   )
-      CALL tab_3d_2d( nidx, idxice(1:nidx), smv_i_2d(1:nidx,1:jpl), smv_i  )
-      CALL tab_3d_2d( nidx, idxice(1:nidx), a_ip_2d (1:nidx,1:jpl), a_ip   )
-      CALL tab_3d_2d( nidx, idxice(1:nidx), v_ip_2d (1:nidx,1:jpl), v_ip   )
-      CALL tab_3d_2d( nidx, idxice(1:nidx), t_su_2d (1:nidx,1:jpl), t_su   )
-
-      !----------------------------------------------------------------------------------------------
-      ! 1) Define a variable equal to a_i*T_su
-      !----------------------------------------------------------------------------------------------
-      DO jl = 1, jpl
-         DO ji = 1, nidx
-            zaTsfn(ji,jl) = a_i_2d(ji,jl) * t_su_2d(ji,jl)
-         END DO
-      END DO
-      
-      !-------------------------------------------------------------------------------
-      ! 2) Transfer volume and energy between categories
-      !-------------------------------------------------------------------------------
-      DO jl = 1, jpl - 1
-         DO ji = 1, 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)
-            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,jl2) = v_i_2d(ji,jl2) + pdvice(ji,jl)
-            
-            ! Snow volumes
-            ztrans         = v_s_2d(ji,jl1) * zworkv(ji)
-            v_s_2d(ji,jl1) = v_s_2d(ji,jl1) - ztrans
-            v_s_2d(ji,jl2) = v_s_2d(ji,jl2) + ztrans 
-                       
-            ! Ice age 
-            ztrans             = oa_i_2d(ji,jl1) * pdaice(ji,jl) !!clem: should be * zworka(ji) but it does not work
-            oa_i_2d(ji,jl1)    = oa_i_2d(ji,jl1) - ztrans
-            oa_i_2d(ji,jl2)    = oa_i_2d(ji,jl2) + ztrans
-            
-            ! Ice salinity
-            ztrans             = smv_i_2d(ji,jl1) * zworkv(ji)
-            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
-            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
-               ztrans          = a_ip_2d(ji,jl1) * pdaice(ji,jl) !!clem: should be * zworka(ji) but it does not work
-               a_ip_2d(ji,jl1) = a_ip_2d(ji,jl1) - ztrans
-               a_ip_2d(ji,jl2) = a_ip_2d(ji,jl2) + ztrans
-               
-               ! Pond volume (also proportional to da/a)
-               ztrans          = v_ip_2d(ji,jl1) * pdaice(ji,jl) !!clem: should be * zworka(ji) but it does not work
-               v_ip_2d(ji,jl1) = v_ip_2d(ji,jl1) - ztrans
-               v_ip_2d(ji,jl2) = v_ip_2d(ji,jl2) + ztrans
-            ENDIF
-            ! END MV MP 2016 
-               
-         END DO
-
-         ! Snow heat content
-         DO jk = 1, nlay_s
-
-            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
-               e_s(ii,ij,jk,jl2) = e_s(ii,ij,jk,jl2) + ztrans 
-            END DO
-         END DO
-
-         
-         ! Ice heat content
-         DO jk = 1, nlay_i
-            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
-               e_i(ii,ij,jk,jl2) = e_i(ii,ij,jk,jl2) + ztrans 
-            END DO
-         END DO
-         
-      END DO                   ! boundaries, 1 to jpl-1
-      
-      !-------------------------------------------------------------------------------
-      ! 3) Update ice thickness and temperature
-      !-------------------------------------------------------------------------------
-      DO jl = 1, jpl
-         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) 
-               t_su_2d(ji,jl)  =  zaTsfn(ji,jl) / a_i_2d(ji,jl) 
-            ELSE
-               ht_i_2d(ji,jl)  = 0._wp
-               t_su_2d(ji,jl)  = rt0
-            ENDIF
-         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   )
-
-      !
-   END SUBROUTINE lim_itd_shiftice
-   
-
-   SUBROUTINE lim_itd_th_reb
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_th_reb ***
-      !!
-      !! ** Purpose : rebin - rebins thicknesses into defined categories
-      !!
-      !! ** Method  : If a category thickness is out of bounds, shift part (for down to top)
-      !!              or entire (for top to down) area, volume, and energy
-      !!              to the neighboring category
-      !!------------------------------------------------------------------
-      INTEGER ::   ji, jj, jl   ! dummy loop indices
-      !
-      INTEGER , DIMENSION(jpij,jpl-1) ::   jdonor           ! donor category index
-      REAL(wp), DIMENSION(jpij,jpl-1) ::   zdaice, zdvice   ! ice area and volume transferred
-      !!------------------------------------------------------------------
-      
-      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
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( a_i(ji,jj,jl) > epsi10 .AND. v_i(ji,jj,jl) > (a_i(ji,jj,jl) * hi_max(jl)) ) THEN
-                  nidx = nidx + 1
-                  idxice( nidx ) = (jj - 1) * jpi + ji                  
-               ENDIF
-            ENDDO
-         ENDDO
-         
-!!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 
-            ! how much of a_i you send in cat sup is somewhat arbitrary
-!!clem: these do not work properly after a restart (I do not know why)
-!!          zdaice(ji,jl)  = a_i_1d(ji) * ( ht_i_1d(ji) - hi_max(jl) + epsi10 ) / ht_i_1d(ji)  
-!!          zdvice(ji,jl)  = v_i_1d(ji) - ( a_i_1d(ji) - zdaice(ji,jl) ) * ( hi_max(jl) - epsi10 )
-!!clem: these do not work properly after a restart (I do not know why)
-!!            zdaice(ji,jl)  = a_i_1d(ji)
-!!            zdvice(ji,jl)  = v_i_1d(ji)
-!!clem: these are from UCL and work ok
-            zdaice(ji,jl)  = a_i_1d(ji) * 0.5_wp
-            zdvice(ji,jl)  = v_i_1d(ji) - zdaice(ji,jl) * ( hi_max(jl) + hi_max(jl-1) ) * 0.5_wp
-            
-         END DO
-
-         IF( nidx > 0 ) THEN
-            CALL lim_itd_shiftice( jdonor(1:nidx,:), zdaice(1:nidx,:), zdvice(1:nidx,:) )  ! Shift jl=>jl+1
-            ! Reset shift parameters
-            jdonor(1:nidx,jl) = 0
-            zdaice(1:nidx,jl) = 0._wp
-            zdvice(1:nidx,jl) = 0._wp
-         ENDIF
-         !
-      END DO
-
-      !-----------------------------------------
-      ! Identify thicknesses that are too small
-      !-----------------------------------------
-      DO jl = jpl - 1, 1, -1
-
-         nidx = 0 ; idxice(:) = 0
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( a_i(ji,jj,jl+1) > epsi10 .AND. v_i(ji,jj,jl+1) <= (a_i(ji,jj,jl+1) * hi_max(jl)) ) THEN
-                  nidx = nidx + 1
-                  idxice( nidx ) = (jj - 1) * jpi + ji                  
-               ENDIF
-            ENDDO
-         ENDDO
-
-         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
-         DO ji = 1, nidx
-            jdonor(ji,jl) = jl + 1
-            zdaice(ji,jl) = a_i_1d(ji) 
-            zdvice(ji,jl) = v_i_1d(ji)
-         END DO
-         
-         IF( nidx > 0 ) THEN
-            CALL lim_itd_shiftice( jdonor(1:nidx,:), zdaice(1:nidx,:), zdvice(1:nidx,:) )  ! Shift jl+1=>jl
-            ! Reset shift parameters
-            jdonor(1:nidx,jl) = 0
-            zdaice(1:nidx,jl) = 0._wp
-            zdvice(1:nidx,jl) = 0._wp
-         ENDIF
-
-      END DO
-      !
-   END SUBROUTINE lim_itd_th_reb
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option            Dummy module         NO LIM sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_itd_th_rem
-   END SUBROUTINE lim_itd_th_rem
-   SUBROUTINE lim_itd_glinear
-   END SUBROUTINE lim_itd_glinear
-   SUBROUTINE lim_itd_shiftice
-   END SUBROUTINE lim_itd_shiftice
-   SUBROUTINE lim_itd_th_reb
-   END SUBROUTINE lim_itd_th_reb
-#endif
-   !!======================================================================
-END MODULE limitd_th
Index: anches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90	(revision 8421)
+++ 	(revision )
@@ -1,613 +1,0 @@
-MODULE limthd
-   !!======================================================================
-   !!                  ***  MODULE limthd   ***
-   !!  LIM-3 :   ice thermodynamic
-   !!======================================================================
-   !! History :  LIM  ! 2000-01 (M.A. Morales Maqueda, H. Goosse, T. Fichefet) LIM-1
-   !!            2.0  ! 2002-07 (C. Ethe, G. Madec)  LIM-2 (F90 rewriting)
-   !!            3.0  ! 2005-11 (M. Vancoppenolle)  LIM-3 : Multi-layer thermodynamics + salinity variations
-   !!             -   ! 2007-04 (M. Vancoppenolle) add lim_thd_glohec, lim_thd_con_dh and lim_thd_con_dif
-   !!            3.2  ! 2009-07 (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in wfx_snw
-   !!            3.3  ! 2010-11 (G. Madec) corrected snow melting heat (due to factor betas)
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!             -   ! 2012-05 (C. Rousset) add penetration solar flux
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_thd       : thermodynamic of sea ice
-   !!   lim_thd_init  : initialisation of sea-ice thermodynamic
-   !!----------------------------------------------------------------------
-   USE phycst         ! physical constants
-   USE dom_oce        ! ocean space and time domain variables
-   USE ice            ! sea-ice variables
-   USE sbc_oce , ONLY : sss_m, sst_m, e3t_m, utau, vtau, ssu_m, ssv_m, frq_m, qns_tot, qsr_tot, sprecip, ln_cpl
-   USE sbc_ice , ONLY : qsr_oce, qns_oce, qemp_oce, qsr_ice, qns_ice, dqns_ice, evap_ice, qprec_ice, qevap_ice, &
-      &                 fr1_i0, fr2_i0, nn_limflx
-   USE ice1D          ! thermodynamic sea-ice variables
-   USE limthd_dif     ! vertical diffusion
-   USE limthd_dh      ! ice-snow growth and melt
-   USE limthd_da      ! lateral melting
-   USE limthd_sal     ! ice salinity
-   USE limthd_ent     ! ice enthalpy redistribution
-   USE limthd_lac     ! lateral accretion
-   USE limitd_th      ! remapping thickness distribution
-   USE icetab         ! 1D <==> 2D transformation
-   USE limvar         !
-   USE icecons        ! conservation tests
-   USE icectl         ! control print
-   !
-   USE in_out_manager ! I/O manager
-   USE lbclnk         ! lateral boundary condition - MPP links
-   USE lib_mpp        ! MPP library
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE timing         ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_thd         ! called by limstp module
-   PUBLIC   lim_thd_init    ! called by ice_init
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_thd( kt )
-      !!-------------------------------------------------------------------
-      !!                ***  ROUTINE lim_thd  ***       
-      !!  
-      !! ** Purpose : This routine manages ice thermodynamics
-      !!         
-      !! ** Action : - Initialisation of some variables
-      !!             - Some preliminary computation (oceanic heat flux
-      !!               at the ice base, snow acc.,heat budget of the leads)
-      !!             - selection of the icy points and put them in an array
-      !!             - call lim_thd_dif  for vertical heat diffusion
-      !!             - call lim_thd_dh   for vertical ice growth and melt
-      !!             - call lim_thd_ent  for enthalpy remapping
-      !!             - call lim_thd_sal  for ice desalination
-      !!             - call lim_thd_temp to  retrieve temperature from ice enthalpy
-      !!             - back to the geographic grid
-      !!     
-      !! ** References : 
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) :: kt    ! number of iteration
-      !
-      INTEGER  :: ji, jj, jk, jl   ! dummy loop indices
-      REAL(wp) :: zfric_u, zqld, zqfr, zqfr_neg
-      REAL(wp) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b ! conservation check
-      REAL(wp), PARAMETER :: zfric_umin = 0._wp           ! lower bound for the friction velocity (cice value=5.e-04)
-      REAL(wp), PARAMETER :: zch        = 0.0057_wp       ! heat transfer coefficient
-      REAL(wp), DIMENSION(jpi,jpj) ::   zu_io, zv_io, zfric   ! ice-ocean velocity (m/s) and frictional velocity (m2/s2)
-      !
-      !!-------------------------------------------------------------------
-
-      IF( nn_timing == 1 )   CALL timing_start('limthd')
-
-      IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*)'' 
-         WRITE(numout,*)' lim_thd '
-         WRITE(numout,*)' ~~~~~~~~'
-      ENDIF
-      
-      ! conservation test
-      IF( ln_limdiachk ) CALL ice_cons_hsm(0, 'limthd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      CALL lim_var_glo2eqv
-
-      !---------------------------------------------!
-      ! computation of friction velocity at T points
-      !---------------------------------------------!
-      IF( ln_limdyn ) THEN
-         zu_io(:,:) = u_ice(:,:) - ssu_m(:,:)
-         zv_io(:,:) = v_ice(:,:) - ssv_m(:,:)
-         DO jj = 2, jpjm1 
-            DO ji = fs_2, fs_jpim1
-               zfric(ji,jj) = rn_cio * ( 0.5_wp *  &
-                  &                    (  zu_io(ji,jj) * zu_io(ji,jj) + zu_io(ji-1,jj) * zu_io(ji-1,jj)   &
-                  &                     + zv_io(ji,jj) * zv_io(ji,jj) + zv_io(ji,jj-1) * zv_io(ji,jj-1) ) ) * tmask(ji,jj,1)
-            END DO
-         END DO
-      ELSE      !  if no ice dynamics => transmit directly the atmospheric stress to the ocean
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1
-               zfric(ji,jj) = r1_rau0 * SQRT( 0.5_wp *  &
-                  &                         (  utau(ji,jj) * utau(ji,jj) + utau(ji-1,jj) * utau(ji-1,jj)   &
-                  &                          + vtau(ji,jj) * vtau(ji,jj) + vtau(ji,jj-1) * vtau(ji,jj-1) ) ) * tmask(ji,jj,1)
-            END DO
-         END DO
-      ENDIF
-      CALL lbc_lnk( zfric, 'T',  1. )
-      !
-      ftr_ice(:,:,:) = 0._wp  ! initialization (part of solar radiation transmitted through the ice)
-
-      !--------------------------------------------------------------------!
-      ! Partial computation of forcing for the thermodynamic sea ice model
-      !--------------------------------------------------------------------!
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            rswitch  = tmask(ji,jj,1) * MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi10 ) ) ! 0 if no ice
-            !
-            !           !  solar irradiance transmission at the mixed layer bottom and used in the lead heat budget
-            !           !  practically no "direct lateral ablation"
-            !           
-            !           !  net downward heat flux from the ice to the ocean, expressed as a function of ocean 
-            !           !  temperature and turbulent mixing (McPhee, 1992)
-            !
-            ! --- Energy received in the lead, zqld is defined everywhere (J.m-2) --- !
-            zqld =  tmask(ji,jj,1) * rdt_ice *  &
-               &    ( ( 1._wp - at_i_b(ji,jj) ) * qsr_oce(ji,jj) * frq_m(ji,jj) +  &
-               &      ( 1._wp - at_i_b(ji,jj) ) * qns_oce(ji,jj) + qemp_oce(ji,jj) )
-
-            ! --- Energy needed to bring ocean surface layer until its freezing (<0, J.m-2) --- !
-            ! includes supercooling potential energy (>0) or "above-freezing" energy (<0)
-            zqfr = tmask(ji,jj,1) * rau0 * rcp * e3t_m(ji,jj) * ( t_bo(ji,jj) - ( sst_m(ji,jj) + rt0 ) )
-
-            ! --- Above-freezing sensible heat content (J/m2 grid)
-            zqfr_neg = tmask(ji,jj,1) * rau0 * rcp * e3t_m(ji,jj) * MIN( ( t_bo(ji,jj) - ( sst_m(ji,jj) + rt0 ) ), 0._wp )
-
-            ! --- Sensible ocean-to-ice heat flux (W/m2)
-            zfric_u      = MAX( SQRT( zfric(ji,jj) ), zfric_umin ) 
-            fhtur(ji,jj) = rswitch * rau0 * rcp * zch  * zfric_u * ( ( sst_m(ji,jj) + rt0 ) - t_bo(ji,jj) ) ! W.m-2
-
-            fhtur(ji,jj) = rswitch * MIN( fhtur(ji,jj), - zqfr_neg * r1_rdtice / MAX( at_i(ji,jj), epsi10 ) )
-            ! upper bound for fhtur: the heat retrieved from the ocean must be smaller than the heat necessary to reach 
-            !                        the freezing point, so that we do not have SST < T_freeze
-            !                        This implies: - ( fhtur(ji,jj) * at_i(ji,jj) * rtdice ) - zqfr >= 0
-
-            !-- Energy Budget of the leads (J.m-2), source of lateral accretion. Must be < 0 to form ice
-            qlead(ji,jj) = MIN( 0._wp , zqld - ( fhtur(ji,jj) * at_i(ji,jj) * rdt_ice ) - zqfr )
-
-            ! If there is ice and leads are warming, then transfer energy from the lead budget and use it for bottom melting 
-            IF( zqld > 0._wp ) THEN
-               fhld (ji,jj) = rswitch * zqld * r1_rdtice / MAX( at_i(ji,jj), epsi10 ) ! divided by at_i since this is (re)multiplied by a_i in limthd_dh.F90
-               qlead(ji,jj) = 0._wp
-            ELSE
-               fhld (ji,jj) = 0._wp
-            ENDIF
-            !
-            ! Net heat flux on top of the ice-ocean [W.m-2]
-            ! ---------------------------------------------
-            hfx_in(ji,jj) = qns_tot(ji,jj) + qsr_tot(ji,jj) 
-         END DO
-      END DO
-      
-      ! In case we bypass open-water ice formation
-      IF( .NOT. ln_limdO )  qlead(:,:) = 0._wp
-      ! In case we bypass growing/melting from top and bottom: we suppose ice is impermeable => ocean is isolated from atmosphere
-      IF( .NOT. ln_limdH )  hfx_in(:,:) = ( 1._wp - at_i_b(:,:) ) * ( qns_oce(:,:) + qsr_oce(:,:) ) + qemp_oce(:,:)
-      IF( .NOT. ln_limdH )  fhtur (:,:) = 0._wp  ;  fhld  (:,:) = 0._wp
-
-      ! ---------------------------------------------------------------------
-      ! Net heat flux on top of the ocean after ice thermo (1st step) [W.m-2]
-      ! ---------------------------------------------------------------------
-      !     First  step here              :  non solar + precip - qlead - qturb
-      !     Second step in limthd_dh      :  heat remaining if total melt (zq_rema) 
-      !     Third  step in iceupdate.F90  :  heat from ice-ocean mass exchange (zf_mass) + solar
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            hfx_out(ji,jj) = ( 1._wp - at_i_b(ji,jj) ) * qns_oce(ji,jj) + qemp_oce(ji,jj)  &  ! Non solar heat flux received by the ocean               
-               &             - qlead(ji,jj) * r1_rdtice                                    &  ! heat flux taken from the ocean where there is open water ice formation
-               &             - at_i(ji,jj) * fhtur(ji,jj)                                  &  ! heat flux taken by turbulence
-               &             - at_i(ji,jj) *  fhld(ji,jj)                                     ! heat flux taken during bottom growth/melt 
-                                                                                              !    (fhld should be 0 while bott growth)
-         END DO
-      END DO
-
-      !-------------------------------------------------------------------------------------------!
-      ! Thermodynamic computation (only on grid points covered by ice) => loop over ice categories
-      !-------------------------------------------------------------------------------------------!
-      DO jl = 1, jpl
-
-         ! select ice covered grid points
-         nidx = 0 ; idxice(:) = 0
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF ( a_i(ji,jj,jl) > epsi10 ) THEN     
-                  nidx         = nidx  + 1
-                  idxice(nidx) = (jj - 1) * jpi + ji
-               ENDIF
-            END DO
-         END DO
-
-         IF( lk_mpp )         CALL mpp_ini_ice( nidx , numout )
-
-         IF( nidx > 0 ) THEN  ! If there is no ice, do nothing.
-            !                                                                
-                              CALL lim_thd_1d2d( jl, 1 )            ! --- Move to 1D arrays --- !
-            !                                                       ! --- & Change units of e_i, e_s from J/m2 to J/m3 --- !
-            !
-            s_i_new   (1:nidx) = 0._wp ; dh_s_tot (1:nidx) = 0._wp  ! --- some init --- !  (important to have them here) 
-            dh_i_surf (1:nidx) = 0._wp ; dh_i_bott(1:nidx) = 0._wp
-            dh_snowice(1:nidx) = 0._wp ; dh_i_sub (1:nidx) = 0._wp
-            !
-            IF( ln_limdH )    CALL lim_thd_dif                      ! --- Ice/Snow Temperature profile --- !
-            !
-            IF( ln_limdH )    CALL lim_thd_dh                       ! --- Ice/Snow thickness --- !    
-            !
-            IF( ln_limdH )    CALL lim_thd_ent( e_i_1d(1:nidx,:) )  ! --- Ice enthalpy remapping --- !
-            !
-                              CALL lim_thd_sal                      ! --- Ice salinity --- !    
-            !
-                              CALL lim_thd_temp                     ! --- temperature update --- !
-            !
-            IF( ln_limdH ) THEN
-               IF ( ( nn_monocat == 1 .OR. nn_monocat == 4 ) .AND. jpl == 1 ) THEN
-                              CALL lim_thd_lam                      ! --- extra lateral melting if monocat --- !
-               END IF
-            END IF
-            !
-            IF( ln_limdA )    CALL lim_thd_da                       ! --- lateral melting --- !
-            !
-                              CALL lim_thd_1d2d( jl, 2 )            ! --- Change units of e_i, e_s from J/m3 to J/m2 --- !
-            !                                                       ! --- & Move to 2D arrays --- !
-            !
-            IF( lk_mpp )      CALL mpp_comm_free( ncomm_ice ) !RB necessary ??
-         ENDIF
-         !
-      END DO
-      ! update ice age (in case a_i changed, i.e. becomes 0 or lateral melting)
-      oa_i(:,:,:) = o_i(:,:,:) * a_i(:,:,:)
-
-      IF( ln_limdiachk ) CALL ice_cons_hsm(1, 'limthd', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-      !
-                         CALL lim_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 lim_itd_th_rem( kt )       ! --- Transport ice between thickness categories --- !
-      !
-      IF( ln_limdO )     CALL lim_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( 'limthd' )      ! Control print
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('limthd')
-
-   END SUBROUTINE lim_thd 
-
- 
-   SUBROUTINE lim_thd_temp
-      !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_thd_temp *** 
-      !!                 
-      !! ** Purpose :   Computes sea ice temperature (Kelvin) from enthalpy
-      !!
-      !! ** Method  :   Formula (Bitz and Lipscomb, 1999)
-      !!-------------------------------------------------------------------
-      INTEGER  ::   ji, jk   ! dummy loop indices
-      REAL(wp) ::   ztmelts, zaaa, zbbb, zccc, zdiscrim  ! local scalar 
-      !!-------------------------------------------------------------------
-      ! Recover ice temperature
-      DO jk = 1, nlay_i
-         DO ji = 1, nidx
-            ztmelts       =  -tmut * s_i_1d(ji,jk) + rt0
-            ! Conversion q(S,T) -> T (second order equation)
-            zaaa          =  cpic
-            zbbb          =  ( rcp - cpic ) * ( ztmelts - rt0 ) + e_i_1d(ji,jk) * r1_rhoic - lfus
-            zccc          =  lfus * ( ztmelts - rt0 )
-            zdiscrim      =  SQRT( MAX( zbbb * zbbb - 4._wp * zaaa * zccc, 0._wp ) )
-            t_i_1d(ji,jk) =  rt0 - ( zbbb + zdiscrim ) / ( 2._wp * zaaa )
-            
-            ! mask temperature
-            rswitch       =  1._wp - MAX( 0._wp , SIGN( 1._wp , - ht_i_1d(ji) ) ) 
-            t_i_1d(ji,jk) =  rswitch * t_i_1d(ji,jk) + ( 1._wp - rswitch ) * rt0
-         END DO 
-      END DO 
-      !
-   END SUBROUTINE lim_thd_temp
-
-
-   SUBROUTINE lim_thd_lam
-      !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_thd_lam *** 
-      !!                 
-      !! ** Purpose :   Lateral melting in case monocategory
-      !!                          ( dA = A/2h dh )
-      !!-----------------------------------------------------------------------
-      INTEGER  ::   ji                 ! dummy loop indices
-      REAL(wp) ::   zhi_bef            ! ice thickness before thermo
-      REAL(wp) ::   zdh_mel, zda_mel   ! net melting
-      REAL(wp) ::   zvi, zvs           ! ice/snow volumes 
-      !!-----------------------------------------------------------------------
-      !
-      DO ji = 1, nidx
-         zdh_mel = MIN( 0._wp, dh_i_surf(ji) + dh_i_bott(ji) + dh_snowice(ji) + dh_i_sub(ji) )
-         IF( zdh_mel < 0._wp .AND. a_i_1d(ji) > 0._wp )  THEN
-            zvi          = a_i_1d(ji) * ht_i_1d(ji)
-            zvs          = a_i_1d(ji) * ht_s_1d(ji)
-            ! lateral melting = concentration change
-            zhi_bef     = ht_i_1d(ji) - zdh_mel
-            rswitch     = MAX( 0._wp , SIGN( 1._wp , zhi_bef - epsi20 ) )
-            zda_mel     = rswitch * a_i_1d(ji) * zdh_mel / ( 2._wp * MAX( zhi_bef, epsi20 ) )
-            a_i_1d(ji)  = MAX( epsi20, a_i_1d(ji) + zda_mel ) 
-            ! adjust thickness
-            ht_i_1d(ji) = zvi / a_i_1d(ji)            
-            ht_s_1d(ji) = zvs / a_i_1d(ji)            
-            ! retrieve total concentration
-            at_i_1d(ji) = a_i_1d(ji)
-         END IF
-      END DO
-      !
-   END SUBROUTINE lim_thd_lam
-
-
-   SUBROUTINE lim_thd_1d2d( jl, kn )
-      !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_thd_1d2d *** 
-      !!                 
-      !! ** 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
-      !!-----------------------------------------------------------------------
-      !
-      SELECT CASE( kn )
-      !
-      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)     )
-         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)   )
-         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)   )
-         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), 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), t_bo_1d     (1:nidx), t_bo             )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), sprecip_1d  (1:nidx), sprecip          ) 
-         CALL tab_2d_1d( nidx, idxice(1:nidx), fhtur_1d    (1:nidx), fhtur            )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), fhld_1d     (1:nidx), fhld             )
-         !
-         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_snw_sni_1d(1:nidx), wfx_snw_sni   )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_snw_sum_1d(1:nidx), wfx_snw_sum   )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_sub_1d    (1:nidx), wfx_sub       )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_snw_sub_1d(1:nidx), wfx_snw_sub   )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_ice_sub_1d(1:nidx), wfx_ice_sub   )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_err_sub_1d(1:nidx), wfx_err_sub   )
-         !
-         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_bog_1d (1:nidx), wfx_bog          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_bom_1d (1:nidx), wfx_bom          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_sum_1d (1:nidx), wfx_sum          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_sni_1d (1:nidx), wfx_sni          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_res_1d (1:nidx), wfx_res          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_spr_1d (1:nidx), wfx_spr          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_lam_1d (1:nidx), wfx_lam          )
-         !
-         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_bog_1d (1:nidx), sfx_bog          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_bom_1d (1:nidx), sfx_bom          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_sum_1d (1:nidx), sfx_sum          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_sni_1d (1:nidx), sfx_sni          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_bri_1d (1:nidx), sfx_bri          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_res_1d (1:nidx), sfx_res          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_sub_1d (1:nidx), sfx_sub          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_lam_1d (1:nidx), sfx_lam          )
-         !
-         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_thd_1d (1:nidx), hfx_thd          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_spr_1d (1:nidx), hfx_spr          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_sum_1d (1:nidx), hfx_sum          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_bom_1d (1:nidx), hfx_bom          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_bog_1d (1:nidx), hfx_bog          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_dif_1d (1:nidx), hfx_dif          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_opw_1d (1:nidx), hfx_opw          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_snw_1d (1:nidx), hfx_snw          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_sub_1d (1:nidx), hfx_sub          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_err_1d (1:nidx), hfx_err          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_res_1d (1:nidx), hfx_res          )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_err_dif_1d(1:nidx), hfx_err_dif   )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_err_rem_1d(1:nidx), hfx_err_rem   )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_out_1d (1:nidx), hfx_out          )
-         !
-         ! SIMIP diagnostics
-         CALL tab_2d_1d( nidx, idxice(1:nidx), diag_fc_bo_1d(1:nidx), diag_fc_bo   )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), diag_fc_su_1d(1:nidx), diag_fc_su   )
-         ! ocean surface fields
-         CALL tab_2d_1d( nidx, idxice(1:nidx), sst_1d(1:nidx), sst_m )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), sss_1d(1:nidx), sss_m )
-
-         ! --- Change units of e_i, e_s from J/m2 to J/m3 --- !
-         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
-         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
-         !
-         ! --- 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
-         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
-         !
-         ! Change thickness to volume
-         v_i_1d(1:nidx)   = ht_i_1d(1:nidx) * a_i_1d(1:nidx)
-         v_s_1d(1:nidx)   = ht_s_1d(1:nidx) * a_i_1d(1:nidx)
-         smv_i_1d(1:nidx) = sm_i_1d(1:nidx) * v_i_1d(1:nidx)
-         
-         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)     )
-         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)   )
-         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)  )
-         !
-         ! 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        )
-         ! 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) )
-      END SELECT
-      !
-   END SUBROUTINE lim_thd_1d2d
-
-
-   SUBROUTINE lim_thd_init
-      !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_thd_init *** 
-      !!                 
-      !! ** Purpose :   Physical constants and parameters linked to the ice 
-      !!              thermodynamics
-      !!
-      !! ** Method  :   Read the namicethd namelist and check the ice-thermo
-      !!              parameter values called at the first timestep (nit000)
-      !!
-      !! ** input   :   Namelist namicether
-      !!-------------------------------------------------------------------
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namicethd/ rn_kappa_i, nn_ice_thcon, ln_dqnsice, rn_cdsn,                                  &
-         &                ln_limdH, rn_betas,                                                             &
-         &                ln_limdA, rn_beta, rn_dmin,                                                     &
-         &                ln_limdO, rn_hnewice, ln_frazil, rn_maxfrazb, rn_vfrazb, rn_Cfrazb, rn_himin,   &
-         &                nn_limflx
-      !!-------------------------------------------------------------------
-      !
-      REWIND( numnam_ice_ref )              ! Namelist namicethd in reference namelist : Ice thermodynamics
-      READ  ( numnam_ice_ref, namicethd, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicethd in reference namelist', lwp )
-
-      REWIND( numnam_ice_cfg )              ! Namelist namicethd in configuration namelist : Ice thermodynamics
-      READ  ( numnam_ice_cfg, namicethd, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicethd in configuration namelist', lwp )
-      IF(lwm) WRITE ( numoni, namicethd )
-      !
-      !
-      IF(lwp) THEN                          ! control print
-         WRITE(numout,*) 'lim_thd_init : Ice Thermodynamics'
-         WRITE(numout,*) '~~~~~~~~~~~~~'
-         WRITE(numout,*)'   -- limthd_dif --'
-         WRITE(numout,*)'      extinction radiation parameter in sea ice               rn_kappa_i   = ', rn_kappa_i
-         WRITE(numout,*)'      switch for comp. of thermal conductivity in the ice     nn_ice_thcon = ', nn_ice_thcon
-         WRITE(numout,*)'      change the surface non-solar flux with Tsu or not       ln_dqnsice   = ', ln_dqnsice
-         WRITE(numout,*)'      thermal conductivity of the snow                        rn_cdsn      = ', rn_cdsn
-         WRITE(numout,*)'   -- limthd_dh --'
-         WRITE(numout,*)'      activate ice thick change from top/bot (T) or not (F)   ln_limdH     = ', ln_limdH
-         WRITE(numout,*)'      coefficient for ice-lead partition of snowfall          rn_betas     = ', rn_betas
-         WRITE(numout,*)'   -- limthd_da --'
-         WRITE(numout,*)'      activate lateral melting (T) or not (F)                 ln_limdA     = ', ln_limdA
-         WRITE(numout,*)'      Coef. beta for lateral melting param.                   rn_beta      = ', rn_beta
-         WRITE(numout,*)'      Minimum floe diameter for lateral melting param.        rn_dmin      = ', rn_dmin
-         WRITE(numout,*)'   -- limthd_lac --'
-         WRITE(numout,*)'      activate ice growth in open-water (T) or not (F)        ln_limdO     = ', ln_limdO
-         WRITE(numout,*)'      ice thick. for lateral accretion                        rn_hnewice   = ', rn_hnewice
-         WRITE(numout,*)'      Frazil ice thickness as a function of wind or not       ln_frazil    = ', ln_frazil
-         WRITE(numout,*)'      Maximum proportion of frazil ice collecting at bottom   rn_maxfrazb  = ', rn_maxfrazb
-         WRITE(numout,*)'      Thresold relative drift speed for collection of frazil  rn_vfrazb    = ', rn_vfrazb
-         WRITE(numout,*)'      Squeezing coefficient for collection of frazil          rn_Cfrazb    = ', rn_Cfrazb
-         WRITE(numout,*)'   -- limitd_th --'
-         WRITE(numout,*)'      minimum ice thickness                                   rn_himin     = ', rn_himin 
-         WRITE(numout,*)'      check heat conservation in the ice/snow                 con_i        = ', con_i
-         WRITE(numout,*)'   -- icestp --'
-         WRITE(numout,*)'      Multicategory heat flux formulation                     nn_limflx    = ', nn_limflx
-      ENDIF
-      !
-      IF ( rn_hnewice < rn_himin )   CALL ctl_stop( 'STOP', 'lim_thd_init : rn_hnewice should be >= rn_himin' )
-      !
-      IF(lwp) WRITE(numout,*)
-      SELECT CASE( nn_limflx )         ! LIM3 Multi-category heat flux formulation
-      CASE ( -1 )
-         IF(lwp) WRITE(numout,*) '   LIM3: use per-category fluxes (nn_limflx = -1) '
-         IF( ln_cpl )   CALL ctl_stop( 'sbc_init : the chosen nn_limflx for LIM3 in coupled mode must be 0 or 2' )
-      CASE ( 0  )
-         IF(lwp) WRITE(numout,*) '   LIM3: use average per-category fluxes (nn_limflx = 0) '
-      CASE ( 1  )
-         IF(lwp) WRITE(numout,*) '   LIM3: use average then redistribute per-category fluxes (nn_limflx = 1) '
-         IF( ln_cpl )   CALL ctl_stop( 'sbc_init : the chosen nn_limflx for LIM3 in coupled mode must be 0 or 2' )
-      CASE ( 2  )
-         IF(lwp) WRITE(numout,*) '   LIM3: Redistribute a single flux over categories (nn_limflx = 2) '
-         IF( .NOT. ln_cpl )   CALL ctl_stop( 'sbc_init : the chosen nn_limflx for LIM3 in forced mode cannot be 2' )
-      CASE DEFAULT
-         CALL ctl_stop( 'sbcmod: LIM3 option, nn_limflx, should be between -1 and 2' )
-      END SELECT
-      !
-   END SUBROUTINE lim_thd_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Dummy module          NO  LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-
-   !!======================================================================
-END MODULE limthd
Index: anches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limthd_da.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limthd_da.F90	(revision 8421)
+++ 	(revision )
@@ -1,158 +1,0 @@
-MODULE limthd_da
-   !!======================================================================
-   !!                       ***  MODULE limthd_da ***
-   !! LIM-3 sea-ice :  computation of lateral melting in the ice
-   !!======================================================================
-   !! History :   4.0   ! 2016-03 (C. Rousset) original code
-   !!---------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_thd_da   : sea ice lateral melting
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-   USE phycst         ! physical constants (ocean directory)
-   USE ice            ! LIM variables
-   USE ice1D          ! thermodynamic sea-ice variables
-   !
-   USE lib_mpp        ! MPP library
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_thd_da        ! called by limthd module
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: limthd_da.F90 5123 2015-03-04 16:06:03Z clem $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_thd_da
-      !!-------------------------------------------------------------------
-      !!                ***  ROUTINE lim_thd_da  ***    
-      !!   
-      !! ** Purpose :   computes sea ice lateral melting
-      !!
-      !! ** Method  :   dA/dt = - P * W   [s-1]
-      !!                   W = melting velocity [m.s-1]
-      !!                   P = perimeter of ice-ocean lateral interface normalized by grid cell area [m.m-2]
-      !!
-      !!                   W = m1 * (Tw -Tf)**m2                    --- originally from Josberger 1979 ---
-      !!                      (Tw - Tf) = elevation of water temp above freezing
-      !!                      m1 and m2 = (1.6e-6 , 1.36) best fit from field experiment near the coast of Prince Patrick Island (Perovich 1983) => static ice
-      !!                      m1 and m2 = (3.0e-6 , 1.36) best fit from MIZEX 84 experiment (Maykut and Perovich 1987) => moving ice
-      !!
-      !!                   P = N * pi * D                           --- from Rothrock and Thorndike 1984 ---
-      !!                      D = mean floe caliper diameter
-      !!                      N = number of floes = ice area / floe area(average) = A / (Cs * D**2)
-      !!                         A = ice concentration
-      !!                         Cs = deviation from a square (square:Cs=1 ; circle:Cs=pi/4 ; floe:Cs=0.66)
-      !!
-      !!                   D = Dmin * ( Astar / (Astar-A) )**beta   --- from Lupkes et al., 2012 (eq. 26-27) ---
-      !!                                                             
-      !!                      Astar = 1 / ( 1 - (Dmin/Dmax)**(1/beta) )
-      !!                      Dmin = minimum floe diameter (recommended to be 8m +- 20%)
-      !!                      Dmax = maximum floe diameter (recommended to be 300m, but it does not impact melting much except for Dmax<100m)
-      !!                      beta = 1.0 +-20% (recommended value)
-      !!                           = 0.3 best fit for western Fram Strait and Antarctica
-      !!                           = 1.4 best fit for eastern Fram Strait
-      !!
-      !! ** Tunable parameters  :   We propose to tune the lateral melting via 2 parameters
-      !!                               Dmin [6-10m]   => 6  vs 8m = +40% melting at the peak (A~0.5)
-      !!                                                 10 vs 8m = -20% melting
-      !!                               beta [0.8-1.2] => decrease = more melt and melt peaks toward higher concentration
-      !!                                                                  (A~0.5 for beta=1 ; A~0.8 for beta=0.2)
-      !!                                                 0.3 = best fit for western Fram Strait and Antarctica
-      !!                                                 1.4 = best fit for eastern Fram Strait
-      !!
-      !! ** Note   :   Former and more simple formulations for floe diameters can be found in Mai (1995), 
-      !!               Birnbaum and Lupkes (2002), Lupkes and Birnbaum (2005). They are reviewed in Lupkes et al 2012
-      !!               A simpler implementation for CICE can be found in Bitz et al (2001) and Tsamados et al (2015)
-      !!
-      !! ** References
-      !!    Bitz, C. M., Holland, M. M., Weaver, A. J., & Eby, M. (2001).
-      !!              Simulating the ice‐thickness distribution in a coupled climate model.
-      !!              Journal of Geophysical Research: Oceans, 106(C2), 2441-2463.
-      !!    Josberger, E. G. (1979).
-      !!              Laminar and turbulent boundary layers adjacent to melting vertical ice walls in salt water
-      !!              (No. SCIENTIFIC-16). WASHINGTON UNIV SEATTLE DEPT OF ATMOSPHERIC SCIENCES.
-      !!    Lüpkes, C., Gryanik, V. M., Hartmann, J., & Andreas, E. L. (2012).
-      !!              A parametrization, based on sea ice morphology, of the neutral atmospheric drag coefficients
-      !!              for weather prediction and climate models.
-      !!              Journal of Geophysical Research: Atmospheres, 117(D13).
-      !!    Maykut, G. A., & Perovich, D. K. (1987).
-      !!              The role of shortwave radiation in the summer decay of a sea ice cover.
-      !!              Journal of Geophysical Research: Oceans, 92(C7), 7032-7044.
-      !!    Perovich, D. K. (1983).
-      !!              On the summer decay of a sea ice cover. (Doctoral dissertation, University of Washington).
-      !!    Rothrock, D. A., & Thorndike, A. S. (1984).
-      !!              Measuring the sea ice floe size distribution.
-      !!              Journal of Geophysical Research: Oceans, 89(C4), 6477-6486.
-      !!    Tsamados, M., Feltham, D., Petty, A., Schroeder, D., & Flocco, D. (2015).
-      !!              Processes controlling surface, bottom and lateral melt of Arctic sea ice in a state of the art sea ice model.
-      !!              Phil. Trans. R. Soc. A, 373(2052), 20140167.
-      !!---------------------------------------------------------------------
-      INTEGER  ::   ji     ! dummy loop indices
-      REAL(wp)            ::   zastar, zdfloe, zperi, zwlat, zda
-      REAL(wp), PARAMETER ::   zdmax = 300._wp
-      REAL(wp), PARAMETER ::   zcs   = 0.66_wp
-      REAL(wp), PARAMETER ::   zm1   = 3.e-6_wp
-      REAL(wp), PARAMETER ::   zm2   = 1.36_wp
-      !
-      REAL(wp), DIMENSION(jpij) ::   zda_tot
-      !!---------------------------------------------------------------------
-
-      !------------------------------------------------------------!
-      !------------------------------------------------------------!
-      zastar = 1._wp / ( 1._wp - (rn_dmin / zdmax)**(1._wp/rn_beta) )
-      DO ji = 1, nidx   
-         ! --- Calculate reduction of total sea ice concentration --- !
-         zdfloe = rn_dmin * ( zastar / ( zastar - at_i_1d(ji) ) )**rn_beta         ! Mean floe caliper diameter [m]
-         zperi  = at_i_1d(ji) * rpi / ( zcs * zdfloe )                             ! Mean perimeter of the floe = N*pi*D = (A/cs*D^2)*pi*D [m.m-2]
-         zwlat  = zm1 * ( MAX( 0._wp, sst_1d(ji) - ( t_bo_1d(ji) - rt0 ) ) )**zm2  ! Melt speed rate [m/s]
-         
-         zda_tot(ji) = MIN( zwlat * zperi * rdt_ice, at_i_1d(ji) )                 ! sea ice concentration decrease (>0)
-      
-         ! --- Distribute reduction among ice categories and calculate associated ice-ocean fluxes --- !
-         IF( a_i_1d(ji) > 0._wp ) THEN
-            ! decrease of concentration for the category jl
-            !    each category contributes to melting in proportion to its concentration
-            zda = MIN( a_i_1d(ji), zda_tot(ji) * a_i_1d(ji) / at_i_1d(ji) )
-            
-            ! Contribution to salt flux
-            sfx_lam_1d(ji) = sfx_lam_1d(ji) + rhoic *  ht_i_1d(ji) * zda * sm_i_1d(ji) * r1_rdtice
-            
-            ! Contribution to heat flux into the ocean [W.m-2], (<0)  
-            hfx_thd_1d(ji) = hfx_thd_1d(ji) - zda * r1_rdtice * ( ht_i_1d(ji) * r1_nlay_i * SUM( e_i_1d(ji,1:nlay_i) )  &
-                                                                + ht_s_1d(ji) * r1_nlay_s * SUM( e_s_1d(ji,1:nlay_s) ) ) 
-            
-            ! Contribution to mass flux
-            wfx_lam_1d(ji) =  wfx_lam_1d(ji) + zda * r1_rdtice * ( rhoic * ht_i_1d(ji) + rhosn * ht_s_1d(ji) )
-            
-            ! 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
-               ht_i_1d(ji) = 0._wp
-               ht_s_1d(ji) = 0._wp
-            ENDIF
-         ENDIF
-      END DO
-      !
-   END SUBROUTINE lim_thd_da
-   
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Dummy Module          No LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_thd_da          ! Empty routine
-   END SUBROUTINE lim_thd_da
-#endif
-   !!======================================================================
-END MODULE limthd_da
Index: anches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90	(revision 8421)
+++ 	(revision )
@@ -1,689 +1,0 @@
-MODULE limthd_dh
-   !!======================================================================
-   !!                       ***  MODULE limthd_dh ***
-   !!  LIM-3 :   thermodynamic growth and decay of the ice 
-   !!======================================================================
-   !! History :  LIM  ! 2003-05 (M. Vancoppenolle) Original code in 1D
-   !!                 ! 2005-06 (M. Vancoppenolle) 3D version 
-   !!            3.2  ! 2009-07 (M. Vancoppenolle, Y. Aksenov, G. Madec) bug correction in wfx_snw & wfx_ice
-   !!            3.4  ! 2011-02 (G. Madec) dynamical allocation
-   !!            3.5  ! 2012-10 (G. Madec & co) salt flux + bug fixes 
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_thd_dh    : vertical accr./abl. and lateral ablation of sea ice
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-   USE phycst         ! physical constants (OCE directory) 
-   USE ice            ! LIM variables
-   USE ice1D          ! LIM thermodynamics
-   !
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_thd_dh      ! called by lim_thd
-   PUBLIC   lim_thd_snwblow ! called in sbcblk/sbcclio/sbccpl and here
-
-   INTERFACE lim_thd_snwblow
-      MODULE PROCEDURE lim_thd_snwblow_1d, lim_thd_snwblow_2d
-   END INTERFACE
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_thd_dh
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_thd_dh  ***
-      !!
-      !! ** Purpose :   determines variations of ice and snow thicknesses.
-      !!
-      !! ** Method  :   Ice/Snow surface melting arises from imbalance in surface fluxes
-      !!              Bottom accretion/ablation arises from flux budget
-      !!              Snow thickness can increase by precipitation and decrease by sublimation
-      !!              If snow load excesses Archmiede limit, snow-ice is formed by
-      !!              the flooding of sea-water in the snow
-      !!
-      !!                 1) Compute available flux of heat for surface ablation
-      !!                 2) Compute snow and sea ice enthalpies
-      !!                 3) Surface ablation and sublimation
-      !!                 4) Bottom accretion/ablation
-      !!                 5) Case of Total ablation
-      !!                 6) Snow ice formation
-      !!
-      !! References : Bitz and Lipscomb, 1999, J. Geophys. Res.
-      !!              Fichefet T. and M. Maqueda 1997, J. Geophys. Res., 102(C6), 12609-12646   
-      !!              Vancoppenolle, Fichefet and Bitz, 2005, Geophys. Res. Let. 
-      !!              Vancoppenolle et al.,2009, Ocean Modelling
-      !!------------------------------------------------------------------
-      INTEGER  ::   ji , jk        ! dummy loop indices
-      INTEGER  ::   iter
-
-      REAL(wp) ::   ztmelts             ! local scalar
-      REAL(wp) ::   zdum       
-      REAL(wp) ::   zfracs       ! fractionation coefficient for bottom salt entrapment
-      REAL(wp) ::   zswi1        ! switch for computation of bottom salinity
-      REAL(wp) ::   zswi12       ! switch for computation of bottom salinity
-      REAL(wp) ::   zswi2        ! switch for computation of bottom salinity
-      REAL(wp) ::   zgrr         ! bottom growth rate
-      REAL(wp) ::   zt_i_new     ! bottom formation temperature
-
-      REAL(wp) ::   zQm          ! enthalpy exchanged with the ocean (J/m2), >0 towards the ocean
-      REAL(wp) ::   zEi          ! specific enthalpy of sea ice (J/kg)
-      REAL(wp) ::   zEw          ! specific enthalpy of exchanged water (J/kg)
-      REAL(wp) ::   zdE          ! specific enthalpy difference (J/kg)
-      REAL(wp) ::   zfmdt        ! exchange mass flux x time step (J/m2), >0 towards the ocean
-
-      REAL(wp), DIMENSION(jpij) ::   zqprec      ! energy of fallen snow                       (J.m-3)
-      REAL(wp), DIMENSION(jpij) ::   zq_su       ! heat for surface ablation                   (J.m-2)
-      REAL(wp), DIMENSION(jpij) ::   zq_bo       ! heat for bottom ablation                    (J.m-2)
-      REAL(wp), DIMENSION(jpij) ::   zq_rema     ! remaining heat at the end of the routine    (J.m-2)
-      REAL(wp), DIMENSION(jpij) ::   zf_tt       ! Heat budget to determine melting or freezing(W.m-2)
-      REAL(wp), DIMENSION(jpij) ::   zevap_rema  ! remaining mass flux from sublimation        (kg.m-2)
-
-      REAL(wp), DIMENSION(jpij) ::   zdh_s_mel   ! snow melt 
-      REAL(wp), DIMENSION(jpij) ::   zdh_s_pre   ! snow precipitation 
-      REAL(wp), DIMENSION(jpij) ::   zdh_s_sub   ! snow sublimation
-
-      REAL(wp), DIMENSION(jpij,nlay_i) ::   zdeltah
-      REAL(wp), DIMENSION(jpij,nlay_i) ::   zh_i      ! ice layer thickness
-      INTEGER , DIMENSION(jpij,nlay_i) ::   icount    ! number of layers vanished by melting 
-
-      REAL(wp), DIMENSION(jpij) ::   zeh_i       ! total ice heat content  (J.m-2)
-      REAL(wp), DIMENSION(jpij) ::   zsnw        ! distribution of snow after wind blowing
-
-      REAL(wp) :: zswitch_sal
-
-      ! Heat conservation 
-      INTEGER  ::   num_iter_max
-      !!------------------------------------------------------------------
-
-      ! Discriminate between varying salinity (nn_icesal=2) and prescribed cases (other values)
-      SELECT CASE( nn_icesal )                  ! varying salinity or not
-         CASE( 1, 3 ) ;   zswitch_sal = 0._wp   ! prescribed salinity profile
-         CASE( 2 )    ;   zswitch_sal = 1._wp   ! varying salinity profile
-      END SELECT
-
-      DO ji = 1, nidx
-         icount (ji,:) = 0
-         zdh_s_mel(ji) = 0._wp
-         e_i_1d(ji,nlay_i+1) = 0._wp ! Initialize enthalpy at nlay_i+1
-      END DO
-
-      ! initialize layer thicknesses and enthalpies
-      h_i_old (1:nidx,0:nlay_i+1) = 0._wp
-      eh_i_old(1:nidx,0:nlay_i+1) = 0._wp
-      DO jk = 1, nlay_i
-         DO ji = 1, nidx
-            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
-      !
-      !------------------------------------------------------------------------------!
-      !  1) Calculate available heat for surface and bottom ablation                 !
-      !------------------------------------------------------------------------------!
-      !
-      DO ji = 1, nidx
-         zdum       = qns_ice_1d(ji) + ( 1._wp - i0(ji) ) * qsr_ice_1d(ji) - fc_su(ji) 
-         zf_tt(ji)  = fc_bo_i(ji) + fhtur_1d(ji) + fhld_1d(ji) 
-
-         zq_su (ji) = MAX( 0._wp, zdum      * rdt_ice ) * MAX( 0._wp , SIGN( 1._wp, t_su_1d(ji) - rt0 ) )
-         zq_bo (ji) = MAX( 0._wp, zf_tt(ji) * rdt_ice )
-      END DO
-
-      !
-      !------------------------------------------------------------------------------!
-      ! If snow temperature is above freezing point, then snow melts 
-      ! (should not happen but sometimes it does)
-      !------------------------------------------------------------------------------!
-      DO ji = 1, nidx
-         IF( t_s_1d(ji,1) > rt0 ) THEN !!! Internal melting
-            ! Contribution to heat flux to the ocean [W.m-2], < 0  
-            hfx_res_1d(ji) = hfx_res_1d(ji) + e_s_1d(ji,1) * ht_s_1d(ji) * a_i_1d(ji) * r1_rdtice
-            ! Contribution to mass flux
-            wfx_snw_sum_1d(ji) = wfx_snw_sum_1d(ji) + rhosn * ht_s_1d(ji) * a_i_1d(ji) * r1_rdtice
-            ! updates
-            ht_s_1d(ji)   = 0._wp
-            e_s_1d (ji,1) = 0._wp
-            t_s_1d (ji,1) = rt0
-         END IF
-      END DO
-
-      !------------------------------------------------------------!
-      !  2) Computing layer thicknesses and enthalpies.            !
-      !------------------------------------------------------------!
-      !
-      DO jk = 1, nlay_i
-         DO ji = 1, nidx
-            zh_i(ji,jk) = ht_i_1d(ji) * r1_nlay_i
-            zeh_i(ji)   = zeh_i(ji) + e_i_1d(ji,jk) * zh_i(ji,jk)
-         END DO
-      END DO
-      !
-      !------------------------------------------------------------------------------|
-      !  3) Surface ablation and sublimation                                         |
-      !------------------------------------------------------------------------------|
-      !
-      !-------------------------
-      ! 3.1 Snow precips / melt
-      !-------------------------
-      ! Snow accumulation in one thermodynamic time step
-      ! snowfall is partitionned between leads and ice
-      ! if snow fall was uniform, a fraction (1-at_i) would fall into leads
-      ! but because of the winds, more snow falls on leads than on sea ice
-      ! and a greater fraction (1-at_i)^beta of the total mass of snow 
-      ! (beta < 1) falls in leads.
-      ! In reality, beta depends on wind speed, 
-      ! and should decrease with increasing wind speed but here, it is 
-      ! considered as a constant. an average value is 0.66
-      ! Martin Vancoppenolle, December 2006
-
-      CALL lim_thd_snwblow( 1. - at_i_1d(1:nidx), zsnw(1:nidx) ) ! snow distribution over ice after wind blowing
-
-      zdeltah(1:nidx,:) = 0._wp
-      DO ji = 1, nidx
-         !-----------
-         ! Snow fall
-         !-----------
-         ! thickness change
-         zdh_s_pre(ji) = zsnw(ji) * sprecip_1d(ji) * rdt_ice * r1_rhosn / at_i_1d(ji)
-         ! enthalpy of the precip (>0, J.m-3)
-         zqprec   (ji) = - qprec_ice_1d(ji)   
-         IF( sprecip_1d(ji) == 0._wp ) zqprec(ji) = 0._wp
-         ! heat flux from snow precip (>0, W.m-2)
-         hfx_spr_1d(ji) = hfx_spr_1d(ji) + zdh_s_pre(ji) * a_i_1d(ji) * zqprec(ji) * r1_rdtice
-         ! mass flux, <0
-         wfx_spr_1d(ji) = wfx_spr_1d(ji) - rhosn * a_i_1d(ji) * zdh_s_pre(ji) * r1_rdtice
-
-         !---------------------
-         ! Melt of falling snow
-         !---------------------
-         ! thickness change
-         rswitch        = MAX( 0._wp , SIGN( 1._wp , zqprec(ji) - epsi20 ) )
-         zdeltah (ji,1) = - rswitch * zq_su(ji) / MAX( zqprec(ji) , epsi20 )
-         zdeltah (ji,1) = MAX( - zdh_s_pre(ji), zdeltah(ji,1) ) ! bound melting 
-         ! heat used to melt snow (W.m-2, >0)
-         hfx_snw_1d(ji) = hfx_snw_1d(ji) - zdeltah(ji,1) * a_i_1d(ji) * zqprec(ji) * r1_rdtice
-         ! snow melting only = water into the ocean (then without snow precip), >0
-         wfx_snw_sum_1d(ji) = wfx_snw_sum_1d(ji) - rhosn * a_i_1d(ji) * zdeltah(ji,1) * r1_rdtice
-         ! updates available heat + precipitations after melting
-         zq_su     (ji) = MAX( 0._wp , zq_su (ji) + zdeltah(ji,1) * zqprec(ji) )      
-         zdh_s_pre (ji) = zdh_s_pre(ji) + zdeltah(ji,1)
-
-         ! update thickness
-         ht_s_1d(ji) = MAX( 0._wp , ht_s_1d(ji) + zdh_s_pre(ji) )
-      END DO
-
-      ! If heat still available (zq_su > 0), then melt more snow
-      zdeltah(1:nidx,:) = 0._wp
-      DO jk = 1, nlay_s
-         DO ji = 1, nidx
-            ! thickness change
-            rswitch          = 1._wp - MAX( 0._wp, SIGN( 1._wp, - ht_s_1d(ji) ) ) 
-            rswitch          = rswitch * ( MAX( 0._wp, SIGN( 1._wp, e_s_1d(ji,jk) - epsi20 ) ) ) 
-            zdeltah  (ji,jk) = - rswitch * zq_su(ji) / MAX( e_s_1d(ji,jk), epsi20 )
-            zdeltah  (ji,jk) = MAX( zdeltah(ji,jk) , - ht_s_1d(ji) ) ! bound melting
-            zdh_s_mel(ji)    = zdh_s_mel(ji) + zdeltah(ji,jk)    
-            ! heat used to melt snow(W.m-2, >0)
-            hfx_snw_1d(ji)   = hfx_snw_1d(ji) - zdeltah(ji,jk) * a_i_1d(ji) * e_s_1d(ji,jk) * r1_rdtice 
-            ! snow melting only = water into the ocean (then without snow precip)
-            wfx_snw_sum_1d(ji)   = wfx_snw_sum_1d(ji) - rhosn * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
-            ! updates available heat + thickness
-            zq_su (ji)  = MAX( 0._wp , zq_su (ji) + zdeltah(ji,jk) * e_s_1d(ji,jk) )
-            ht_s_1d(ji) = MAX( 0._wp , ht_s_1d(ji) + zdeltah(ji,jk) )
-         END DO
-      END DO
-
-      !------------------------------
-      ! 3.2 Sublimation (part1: snow) 
-      !------------------------------
-      ! qla_ice is always >=0 (upwards), heat goes to the atmosphere, therefore snow sublimates
-      ! clem comment: not counted in mass/heat exchange in iceupdate.F90 since this is an exchange with atm. (not ocean)
-      zdeltah(1:nidx,:) = 0._wp
-      DO ji = 1, nidx
-         zdh_s_sub(ji)  = MAX( - ht_s_1d(ji) , - evap_ice_1d(ji) * r1_rhosn * rdt_ice )
-         ! remaining evap in kg.m-2 (used for ice melting later on)
-         zevap_rema(ji)  = evap_ice_1d(ji) * rdt_ice + zdh_s_sub(ji) * rhosn
-         ! Heat flux by sublimation [W.m-2], < 0 (sublimate first snow that had fallen, then pre-existing snow)
-         zdeltah(ji,1)  = MAX( zdh_s_sub(ji), - zdh_s_pre(ji) )
-         hfx_sub_1d(ji) = hfx_sub_1d(ji) + ( zdeltah(ji,1) * zqprec(ji) + ( zdh_s_sub(ji) - zdeltah(ji,1) ) * e_s_1d(ji,1)  &
-            &                              ) * a_i_1d(ji) * r1_rdtice
-         ! Mass flux by sublimation
-         wfx_snw_sub_1d(ji) = wfx_snw_sub_1d(ji) - rhosn * a_i_1d(ji) * zdh_s_sub(ji) * r1_rdtice
-
-         ! new snow thickness
-         ht_s_1d(ji)    =  MAX( 0._wp , ht_s_1d(ji) + zdh_s_sub(ji) )
-         ! update precipitations after sublimation and correct sublimation
-         zdh_s_pre(ji) = zdh_s_pre(ji) + zdeltah(ji,1)
-         zdh_s_sub(ji) = zdh_s_sub(ji) - zdeltah(ji,1)
-      END DO
-      
-      ! --- Update snow diags --- !
-      DO ji = 1, nidx
-         dh_s_tot(ji) = zdh_s_mel(ji) + zdh_s_pre(ji) + zdh_s_sub(ji)
-      END DO
-
-      !-------------------------------------------
-      ! 3.3 Update temperature, energy
-      !-------------------------------------------
-      ! new temp and enthalpy of the snow (remaining snow precip + remaining pre-existing snow)
-      DO jk = 1, nlay_s
-         DO ji = 1,nidx
-            rswitch       = MAX( 0._wp , SIGN( 1._wp, ht_s_1d(ji) - epsi20 ) )
-            e_s_1d(ji,jk) = rswitch / MAX( ht_s_1d(ji), epsi20 ) *           &
-              &            ( ( zdh_s_pre(ji)               ) * zqprec(ji) +  &
-              &              ( ht_s_1d(ji) - zdh_s_pre(ji) ) * rhosn * ( cpic * ( rt0 - t_s_1d(ji,jk) ) + lfus ) )
-         END DO
-      END DO
-
-      !--------------------------
-      ! 3.4 Surface ice ablation 
-      !--------------------------
-      zdeltah(1:nidx,:) = 0._wp ! important
-      DO jk = 1, nlay_i
-         DO ji = 1, nidx
-            ztmelts           = - tmut * s_i_1d(ji,jk) + rt0          ! Melting point of layer k [K]
-            
-            IF( t_i_1d(ji,jk) >= ztmelts ) THEN !!! Internal melting
-
-               zEi            = - e_i_1d(ji,jk) * r1_rhoic            ! Specific enthalpy of layer k [J/kg, <0]       
-               zdE            = 0._wp                                 ! Specific enthalpy difference   (J/kg, <0)
-                                                                      ! set up at 0 since no energy is needed to melt water...(it is already melted)
-               zdeltah(ji,jk) = MIN( 0._wp , - zh_i(ji,jk) )          ! internal melting occurs when the internal temperature is above freezing     
-                                                                      ! this should normally not happen, but sometimes, heat diffusion leads to this
-               zfmdt          = - zdeltah(ji,jk) * rhoic              ! Mass flux x time step > 0
-                         
-               dh_i_surf(ji)  = dh_i_surf(ji) + zdeltah(ji,jk)        ! Cumulate surface melt
-               
-               zfmdt          = - rhoic * zdeltah(ji,jk)              ! Recompute mass flux [kg/m2, >0]
-
-               ! Contribution to heat flux to the ocean [W.m-2], <0 (ice enthalpy zEi is "sent" to the ocean) 
-               hfx_res_1d(ji) = hfx_res_1d(ji) + zfmdt * a_i_1d(ji) * zEi * r1_rdtice
-               
-               ! Contribution to salt flux (clem: using sm_i_1d and not s_i_1d(jk) is ok)
-               sfx_res_1d(ji) = sfx_res_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * sm_i_1d(ji) * r1_rdtice
-               
-               ! Contribution to mass flux
-               wfx_res_1d(ji) =  wfx_res_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
-
-            ELSE                                !!! Surface melting
-               
-               zEi            = - e_i_1d(ji,jk) * r1_rhoic            ! Specific enthalpy of layer k [J/kg, <0]
-               zEw            =    rcp * ( ztmelts - rt0 )            ! Specific enthalpy of resulting meltwater [J/kg, <0]
-               zdE            =    zEi - zEw                          ! Specific enthalpy difference < 0
-               
-               zfmdt          = - zq_su(ji) / zdE                     ! Mass flux to the ocean [kg/m2, >0]
-               
-               zdeltah(ji,jk) = - zfmdt * r1_rhoic                    ! Melt of layer jk [m, <0]
-               
-               zdeltah(ji,jk) = MIN( 0._wp , MAX( zdeltah(ji,jk) , - zh_i(ji,jk) ) )    ! Melt of layer jk cannot exceed the layer thickness [m, <0]
-               
-               zq_su(ji)      = MAX( 0._wp , zq_su(ji) - zdeltah(ji,jk) * rhoic * zdE ) ! update available heat
-               
-               dh_i_surf(ji)  = dh_i_surf(ji) + zdeltah(ji,jk)        ! Cumulate surface melt
-               
-               zfmdt          = - rhoic * zdeltah(ji,jk)              ! Recompute mass flux [kg/m2, >0]
-               
-               zQm            = zfmdt * zEw                           ! Energy of the melt water sent to the ocean [J/m2, <0]
-               
-               ! Contribution to salt flux >0 (clem: using sm_i_1d and not s_i_1d(jk) is ok)
-               sfx_sum_1d(ji) = sfx_sum_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * sm_i_1d(ji) * r1_rdtice
-               
-               ! Contribution to heat flux [W.m-2], < 0
-               hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice
-               
-               ! Total heat flux used in this process [W.m-2], > 0  
-               hfx_sum_1d(ji) = hfx_sum_1d(ji) - zfmdt * a_i_1d(ji) * zdE * r1_rdtice
-               
-               ! Contribution to mass flux
-               wfx_sum_1d(ji) =  wfx_sum_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
-               
-            END IF
-            ! ----------------------
-            ! Sublimation part2: ice
-            ! ----------------------
-            zdum      = MAX( - ( zh_i(ji,jk) + zdeltah(ji,jk) ) , - zevap_rema(ji) * r1_rhoic )
-            zdeltah(ji,jk) = zdeltah(ji,jk) + zdum
-            dh_i_sub(ji)  = dh_i_sub(ji) + zdum
-            ! Salt flux > 0 (clem2016: flux is sent to the ocean for simplicity but salt should remain in the ice except if all ice is melted.
-            !                          It must be corrected at some point)
-            sfx_sub_1d(ji) = sfx_sub_1d(ji) - rhoic * a_i_1d(ji) * zdum * sm_i_1d(ji) * r1_rdtice
-            ! Heat flux [W.m-2], < 0
-            hfx_sub_1d(ji) = hfx_sub_1d(ji) + zdum * e_i_1d(ji,jk) * a_i_1d(ji) * r1_rdtice
-            ! Mass flux > 0
-            wfx_ice_sub_1d(ji) =  wfx_ice_sub_1d(ji) - rhoic * a_i_1d(ji) * zdum * r1_rdtice
-
-            ! update remaining mass flux
-            zevap_rema(ji)  = zevap_rema(ji) + zdum * rhoic
-            
-            ! record which layers have disappeared (for bottom melting) 
-            !    => icount=0 : no layer has vanished
-            !    => icount=5 : 5 layers have vanished
-            rswitch       = MAX( 0._wp , SIGN( 1._wp , - ( zh_i(ji,jk) + zdeltah(ji,jk) ) ) ) 
-            icount(ji,jk) = NINT( rswitch )
-            zh_i(ji,jk)   = MAX( 0._wp , zh_i(ji,jk) + zdeltah(ji,jk) )
-                        
-            ! update heat content (J.m-2) and layer thickness
-            eh_i_old(ji,jk) = eh_i_old(ji,jk) + zdeltah(ji,jk) * e_i_1d(ji,jk)
-            h_i_old (ji,jk) = h_i_old (ji,jk) + zdeltah(ji,jk)
-         END DO
-      END DO
-      ! update ice thickness
-      DO ji = 1, nidx
-         ht_i_1d(ji) =  MAX( 0._wp , ht_i_1d(ji) + dh_i_surf(ji) + dh_i_sub(ji) )
-      END DO
-
-      ! remaining "potential" evap is sent to ocean
-      DO ji = 1, nidx
-         wfx_err_sub_1d(ji) = wfx_err_sub_1d(ji) - zevap_rema(ji) * a_i_1d(ji) * r1_rdtice  ! <=0 (net evap for the ocean in kg.m-2.s-1)
-      END DO
-
-      !
-      !------------------------------------------------------------------------------!
-      ! 4) Basal growth / melt                                                       !
-      !------------------------------------------------------------------------------!
-      !
-      !------------------
-      ! 4.1 Basal growth 
-      !------------------
-      ! Basal growth is driven by heat imbalance at the ice-ocean interface,
-      ! between the inner conductive flux  (fc_bo_i), from the open water heat flux 
-      ! (fhld) and the turbulent ocean flux (fhtur). 
-      ! fc_bo_i is positive downwards. fhtur and fhld are positive to the ice 
-
-      ! If salinity varies in time, an iterative procedure is required, because
-      ! the involved quantities are inter-dependent.
-      ! Basal growth (dh_i_bott) depends upon new ice specific enthalpy (zEi),
-      ! which depends on forming ice salinity (s_i_new), which depends on dh/dt (dh_i_bott)
-      ! -> need for an iterative procedure, which converges quickly
-
-      num_iter_max = 1
-      IF( nn_icesal == 2 ) num_iter_max = 5
-
-      ! Iterative procedure
-      DO ji = 1, nidx
-         IF(  zf_tt(ji) < 0._wp  ) THEN
-            DO iter = 1, num_iter_max
-
-               ! New bottom ice salinity (Cox & Weeks, JGR88 )
-               !--- zswi1  if dh/dt < 2.0e-8
-               !--- zswi12 if 2.0e-8 < dh/dt < 3.6e-7 
-               !--- zswi2  if dh/dt > 3.6e-7
-               zgrr               = MIN( 1.0e-3, MAX ( dh_i_bott(ji) * r1_rdtice , epsi10 ) )
-               zswi2              = MAX( 0._wp , SIGN( 1._wp , zgrr - 3.6e-7 ) )
-               zswi12             = MAX( 0._wp , SIGN( 1._wp , zgrr - 2.0e-8 ) ) * ( 1.0 - zswi2 )
-               zswi1              = 1. - zswi2 * zswi12
-               zfracs             = MIN ( zswi1  * 0.12 + zswi12 * ( 0.8925 + 0.0568 * LOG( 100.0 * zgrr ) )   &
-                  &               + zswi2  * 0.26 / ( 0.26 + 0.74 * EXP ( - 724300.0 * zgrr ) )  , 0.5 )
-
-               s_i_new(ji)        = zswitch_sal * zfracs * sss_1d(ji)  &  ! New ice salinity
-                                  + ( 1. - zswitch_sal ) * sm_i_1d(ji) 
-               ! New ice growth
-               ztmelts            = - tmut * s_i_new(ji) + rt0          ! New ice melting point (K)
-
-               zt_i_new           = zswitch_sal * t_bo_1d(ji) + ( 1. - zswitch_sal) * t_i_1d(ji, nlay_i)
-               
-               zEi                = cpic * ( zt_i_new - ztmelts ) &     ! Specific enthalpy of forming ice (J/kg, <0)      
-                  &               - lfus * ( 1.0 - ( ztmelts - rt0 ) / ( zt_i_new - rt0 ) )   &
-                  &               + rcp  * ( ztmelts-rt0 )          
-
-               zEw                = rcp  * ( t_bo_1d(ji) - rt0 )         ! Specific enthalpy of seawater (J/kg, < 0)
-
-               zdE                = zEi - zEw                           ! Specific enthalpy difference (J/kg, <0)
-
-               dh_i_bott(ji)      = rdt_ice * MAX( 0._wp , zf_tt(ji) / ( zdE * rhoic ) )
-
-               e_i_1d(ji,nlay_i+1) = -zEi * rhoic                        ! New ice energy of melting (J/m3, >0)
-               
-            END DO
-            ! Contribution to Energy and Salt Fluxes                                    
-            zfmdt          = - rhoic * dh_i_bott(ji)             ! Mass flux x time step (kg/m2, < 0)
-
-            ztmelts        = - tmut * s_i_new(ji) + rt0          ! New ice melting point (K)
-            
-            zt_i_new       = zswitch_sal * t_bo_1d(ji) + ( 1. - zswitch_sal) * t_i_1d(ji, nlay_i)
-            
-            zEi            = cpic * ( zt_i_new - ztmelts ) &     ! Specific enthalpy of forming ice (J/kg, <0)      
-               &               - lfus * ( 1.0 - ( ztmelts - rt0 ) / ( zt_i_new - rt0 ) )   &
-               &               + rcp  * ( ztmelts-rt0 )          
-            
-            zEw            = rcp  * ( t_bo_1d(ji) - rt0 )         ! Specific enthalpy of seawater (J/kg, < 0)
-            
-            zdE            = zEi - zEw                           ! Specific enthalpy difference (J/kg, <0)
-            
-            ! Contribution to heat flux to the ocean [W.m-2], >0  
-            hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice
-
-            ! Total heat flux used in this process [W.m-2], <0  
-            hfx_bog_1d(ji) = hfx_bog_1d(ji) - zfmdt * a_i_1d(ji) * zdE * r1_rdtice
-            
-            ! Contribution to salt flux, <0
-            sfx_bog_1d(ji) = sfx_bog_1d(ji) - rhoic * a_i_1d(ji) * dh_i_bott(ji) * s_i_new(ji) * r1_rdtice
-
-            ! Contribution to mass flux, <0
-            wfx_bog_1d(ji) =  wfx_bog_1d(ji) - rhoic * a_i_1d(ji) * dh_i_bott(ji) * r1_rdtice
-
-            ! update heat content (J.m-2) and layer thickness
-            eh_i_old(ji,nlay_i+1) = eh_i_old(ji,nlay_i+1) + dh_i_bott(ji) * e_i_1d(ji,nlay_i+1)
-            h_i_old (ji,nlay_i+1) = h_i_old (ji,nlay_i+1) + dh_i_bott(ji)
-
-         ENDIF
-
-      END DO
-
-      !----------------
-      ! 4.2 Basal melt
-      !----------------
-      zdeltah(1:nidx,:) = 0._wp ! important
-      DO jk = nlay_i, 1, -1
-         DO ji = 1, nidx
-            IF(  zf_tt(ji)  >  0._wp  .AND. jk > icount(ji,jk) ) THEN   ! do not calculate where layer has already disappeared by surface melting 
-
-               ztmelts = - tmut * s_i_1d(ji,jk) + rt0  ! Melting point of layer jk (K)
-
-               IF( t_i_1d(ji,jk) >= ztmelts ) THEN !!! Internal melting
-
-                  zEi               = - e_i_1d(ji,jk) * r1_rhoic    ! Specific enthalpy of melting ice (J/kg, <0)
-                  zdE               = 0._wp                         ! Specific enthalpy difference   (J/kg, <0)
-                                                                    ! set up at 0 since no energy is needed to melt water...(it is already melted)
-                  zdeltah   (ji,jk) = MIN( 0._wp , - zh_i(ji,jk) )  ! internal melting occurs when the internal temperature is above freezing     
-                                                                    ! this should normally not happen, but sometimes, heat diffusion leads to this
-
-                  dh_i_bott (ji)    = dh_i_bott(ji) + zdeltah(ji,jk)
-
-                  zfmdt             = - zdeltah(ji,jk) * rhoic      ! Mass flux x time step > 0
-
-                  ! Contribution to heat flux to the ocean [W.m-2], <0 (ice enthalpy zEi is "sent" to the ocean) 
-                  hfx_res_1d(ji) = hfx_res_1d(ji) + zfmdt * a_i_1d(ji) * zEi * r1_rdtice
-
-                  ! Contribution to salt flux (clem: using sm_i_1d and not s_i_1d(jk) is ok)
-                  sfx_res_1d(ji) = sfx_res_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * sm_i_1d(ji) * r1_rdtice
-                                    
-                  ! Contribution to mass flux
-                  wfx_res_1d(ji) =  wfx_res_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
-
-                  ! update heat content (J.m-2) and layer thickness
-                  eh_i_old(ji,jk) = eh_i_old(ji,jk) + zdeltah(ji,jk) * e_i_1d(ji,jk)
-                  h_i_old (ji,jk) = h_i_old (ji,jk) + zdeltah(ji,jk)
-
-               ELSE                               !!! Basal melting
-
-                  zEi             = - e_i_1d(ji,jk) * r1_rhoic ! Specific enthalpy of melting ice (J/kg, <0)
-                  zEw             = rcp * ( ztmelts - rt0 )    ! Specific enthalpy of meltwater (J/kg, <0)
-                  zdE             = zEi - zEw                  ! Specific enthalpy difference   (J/kg, <0)
-
-                  zfmdt           = - zq_bo(ji) / zdE          ! Mass flux x time step (kg/m2, >0)
-
-                  zdeltah(ji,jk)  = - zfmdt * r1_rhoic         ! Gross thickness change
-
-                  zdeltah(ji,jk)  = MIN( 0._wp , MAX( zdeltah(ji,jk), - zh_i(ji,jk) ) ) ! bound thickness change
-                  
-                  zq_bo(ji)       = MAX( 0._wp , zq_bo(ji) - zdeltah(ji,jk) * rhoic * zdE ) ! update available heat. MAX is necessary for roundup errors
-
-                  dh_i_bott(ji)   = dh_i_bott(ji) + zdeltah(ji,jk)    ! Update basal melt
-
-                  zfmdt           = - zdeltah(ji,jk) * rhoic          ! Mass flux x time step > 0
-
-                  zQm             = zfmdt * zEw         ! Heat exchanged with ocean
-
-                  ! Contribution to heat flux to the ocean [W.m-2], <0  
-                  hfx_thd_1d(ji)  = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice
-
-                  ! Contribution to salt flux (clem: using sm_i_1d and not s_i_1d(jk) is ok)
-                  sfx_bom_1d(ji)  = sfx_bom_1d(ji) - rhoic *  a_i_1d(ji) * zdeltah(ji,jk) * sm_i_1d(ji) * r1_rdtice
-                  
-                  ! Total heat flux used in this process [W.m-2], >0  
-                  hfx_bom_1d(ji)  = hfx_bom_1d(ji) - zfmdt * a_i_1d(ji) * zdE * r1_rdtice
-                  
-                  ! Contribution to mass flux
-                  wfx_bom_1d(ji)  =  wfx_bom_1d(ji) - rhoic * a_i_1d(ji) * zdeltah(ji,jk) * r1_rdtice
-
-                  ! update heat content (J.m-2) and layer thickness
-                  eh_i_old(ji,jk) = eh_i_old(ji,jk) + zdeltah(ji,jk) * e_i_1d(ji,jk)
-                  h_i_old (ji,jk) = h_i_old (ji,jk) + zdeltah(ji,jk)
-               ENDIF
-           
-            ENDIF
-         END DO
-      END DO
-
-      !-------------------------------------------
-      ! Update temperature, energy
-      !-------------------------------------------
-      DO ji = 1, nidx
-         ht_i_1d(ji) =  MAX( 0._wp , ht_i_1d(ji) + dh_i_bott(ji) )
-      END DO  
-
-      !-------------------------------------------
-      ! 5. What to do with remaining energy
-      !-------------------------------------------
-      ! If heat still available for melting and snow remains, then melt more snow
-      !-------------------------------------------
-      zdeltah(1:nidx,:) = 0._wp ! important
-      DO ji = 1, nidx
-         zq_rema(ji)     = zq_su(ji) + zq_bo(ji) 
-         rswitch         = 1._wp - MAX( 0._wp, SIGN( 1._wp, - ht_s_1d(ji) ) )   ! =1 if snow
-         rswitch         = rswitch * MAX( 0._wp, SIGN( 1._wp, e_s_1d(ji,1) - epsi20 ) )
-         zdeltah  (ji,1) = - rswitch * zq_rema(ji) / MAX( e_s_1d(ji,1), epsi20 )
-         zdeltah  (ji,1) = MIN( 0._wp , MAX( zdeltah(ji,1) , - ht_s_1d(ji) ) ) ! bound melting
-         dh_s_tot (ji)   = dh_s_tot(ji)  + zdeltah(ji,1)
-         ht_s_1d   (ji)  = ht_s_1d(ji)   + zdeltah(ji,1)
-        
-         zq_rema(ji)     = zq_rema(ji) + zdeltah(ji,1) * e_s_1d(ji,1)                ! update available heat (J.m-2)
-         ! heat used to melt snow
-         hfx_snw_1d(ji)  = hfx_snw_1d(ji) - zdeltah(ji,1) * a_i_1d(ji) * e_s_1d(ji,1) * r1_rdtice ! W.m-2 (>0)
-         ! Contribution to mass flux
-         wfx_snw_sum_1d(ji)  =  wfx_snw_sum_1d(ji) - rhosn * a_i_1d(ji) * zdeltah(ji,1) * r1_rdtice
-         !    
-         ! Remaining heat flux (W.m-2) is sent to the ocean heat budget
-         hfx_out_1d(ji)  = hfx_out_1d(ji) + ( zq_rema(ji) * a_i_1d(ji) ) * r1_rdtice
-
-         IF( ln_limctl .AND. zq_rema(ji) < 0. .AND. lwp ) WRITE(numout,*) 'ALERTE zq_rema <0 = ', zq_rema(ji)
-      END DO
-
-      !
-      !------------------------------------------------------------------------------|
-      !  6) Snow-Ice formation                                                       |
-      !------------------------------------------------------------------------------|
-      ! When snow load excesses Archimede's limit, snow-ice interface goes down under sea-level, 
-      ! flooding of seawater transforms snow into ice dh_snowice is positive for the ice
-      DO ji = 1, nidx
-         !
-         dh_snowice(ji) = MAX(  0._wp , ( rhosn * ht_s_1d(ji) + (rhoic-rau0) * ht_i_1d(ji) ) / ( rhosn+rau0-rhoic )  )
-
-         ht_i_1d(ji)    = ht_i_1d(ji) + dh_snowice(ji)
-         ht_s_1d(ji)    = ht_s_1d(ji) - dh_snowice(ji)
-
-         ! Contribution to energy flux to the ocean [J/m2], >0 (if sst<0)
-         zfmdt          = ( rhosn - rhoic ) * dh_snowice(ji)    ! <0
-         zEw            = rcp * sst_1d(ji)
-         zQm            = zfmdt * zEw 
-         
-         ! Contribution to heat flux
-         hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * a_i_1d(ji) * zEw * r1_rdtice 
-
-         ! Contribution to salt flux
-         sfx_sni_1d(ji) = sfx_sni_1d(ji) + sss_1d(ji) * a_i_1d(ji) * zfmdt * r1_rdtice 
-
-         ! virtual salt flux to keep salinity constant
-         IF( nn_icesal == 1 .OR. nn_icesal == 3 )  THEN
-            sfx_bri_1d(ji) = sfx_bri_1d(ji) - sss_1d (ji) * a_i_1d(ji) * zfmdt                  * r1_rdtice  & ! put back sss_m     into the ocean
-               &                            - sm_i_1d(ji) * a_i_1d(ji) * dh_snowice(ji) * rhoic * r1_rdtice    ! and get  rn_icesal from the ocean 
-         ENDIF
-
-         ! Contribution to mass flux
-         ! All snow is thrown in the ocean, and seawater is taken to replace the volume
-         wfx_sni_1d(ji)     = wfx_sni_1d(ji)     - a_i_1d(ji) * dh_snowice(ji) * rhoic * r1_rdtice
-         wfx_snw_sni_1d(ji) = wfx_snw_sni_1d(ji) + a_i_1d(ji) * dh_snowice(ji) * rhosn * r1_rdtice
-
-         ! update heat content (J.m-2) and layer thickness
-         eh_i_old(ji,0) = eh_i_old(ji,0) + dh_snowice(ji) * e_s_1d(ji,1) + zfmdt * zEw
-         h_i_old (ji,0) = h_i_old (ji,0) + dh_snowice(ji)
-         
-      END DO
-
-      !
-      !-------------------------------------------
-      ! Update temperature, energy
-      !-------------------------------------------
-      DO ji = 1, nidx
-         rswitch     =  1.0 - MAX( 0._wp , SIGN( 1._wp , - ht_i_1d(ji) ) ) 
-         t_su_1d(ji) =  rswitch * t_su_1d(ji) + ( 1.0 - rswitch ) * rt0
-      END DO
-
-      DO jk = 1, nlay_s
-         DO ji = 1,nidx
-            ! mask enthalpy
-            rswitch       = 1._wp - MAX(  0._wp , SIGN( 1._wp, - ht_s_1d(ji) )  )
-            e_s_1d(ji,jk) = rswitch * e_s_1d(ji,jk)
-            ! recalculate t_s_1d from e_s_1d
-            t_s_1d(ji,jk) = rt0 + rswitch * ( - e_s_1d(ji,jk) / ( rhosn * cpic ) + lfus / cpic )
-         END DO
-      END DO
-
-      ! --- ensure that a_i = 0 where ht_i = 0 ---
-      DO ji = 1, nidx
-         IF( ht_i_1d(ji) == 0._wp )   a_i_1d(ji) = 0._wp
-      END DO         
-      !
-   END SUBROUTINE lim_thd_dh
-
-
-   !!--------------------------------------------------------------------------
-   !! INTERFACE lim_thd_snwblow
-   !! ** Purpose :   Compute distribution of precip over the ice
-   !!--------------------------------------------------------------------------
-   SUBROUTINE lim_thd_snwblow_2d( pin, pout )
-      REAL(wp), DIMENSION(:,:), INTENT(in   ) :: pin   ! previous fraction lead ( 1. - a_i_b )
-      REAL(wp), DIMENSION(:,:), INTENT(inout) :: pout
-      pout = ( 1._wp - ( pin )**rn_betas )
-   END SUBROUTINE lim_thd_snwblow_2d
-
-   SUBROUTINE lim_thd_snwblow_1d( pin, pout )
-      REAL(wp), DIMENSION(:), INTENT(in   ) :: pin
-      REAL(wp), DIMENSION(:), INTENT(inout) :: pout
-      pout = ( 1._wp - ( pin )**rn_betas )
-   END SUBROUTINE lim_thd_snwblow_1d
-
-   
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                               NO  LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_thd_dh          ! Empty routine
-   END SUBROUTINE lim_thd_dh
-#endif
-
-   !!======================================================================
-END MODULE limthd_dh
Index: anches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limthd_dif.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limthd_dif.F90	(revision 8421)
+++ 	(revision )
@@ -1,837 +1,0 @@
-MODULE limthd_dif
-   !!======================================================================
-   !!                       ***  MODULE limthd_dif ***
-   !!                       heat diffusion in sea ice 
-   !!                   computation of surface and inner T  
-   !!======================================================================
-   !! History :  LIM  ! 02-2003 (M. Vancoppenolle) original 1D code
-   !!                 ! 06-2005 (M. Vancoppenolle) 3d version
-   !!                 ! 11-2006 (X Fettweis) Vectorization by Xavier
-   !!                 ! 04-2007 (M. Vancoppenolle) Energy conservation
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!             -   ! 2012-05 (C. Rousset) add penetration solar flux
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-   USE phycst         ! physical constants (ocean directory) 
-   USE ice            ! LIM-3 variables
-   USE ice1D          ! LIM-3: thermodynamics
-   !
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_thd_dif   ! called by lim_thd
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_thd_dif
-      !!------------------------------------------------------------------
-      !!                ***  ROUTINE lim_thd_dif  ***
-      !! ** Purpose :
-      !!           This routine determines the time evolution of snow and sea-ice 
-      !!           temperature profiles.
-      !! ** Method  :
-      !!           This is done by solving the heat equation diffusion with
-      !!           a Neumann boundary condition at the surface and a Dirichlet one
-      !!           at the bottom. Solar radiation is partially absorbed into the ice.
-      !!           The specific heat and thermal conductivities depend on ice salinity
-      !!           and temperature to take into account brine pocket melting. The 
-      !!           numerical
-      !!           scheme is an iterative Crank-Nicolson on a non-uniform multilayer grid 
-      !!           in the ice and snow system.
-      !!
-      !!           The successive steps of this routine are
-      !!           1.  Thermal conductivity at the interfaces of the ice layers
-      !!           2.  Internal absorbed radiation
-      !!           3.  Scale factors due to non-uniform grid
-      !!           4.  Kappa factors
-      !!           Then iterative procedure begins
-      !!           5.  specific heat in the ice
-      !!           6.  eta factors
-      !!           7.  surface flux computation
-      !!           8.  tridiagonal system terms
-      !!           9.  solving the tridiagonal system with Gauss elimination
-      !!           Iterative procedure ends according to a criterion on evolution
-      !!           of temperature
-      !!
-      !!
-      !! ** Inputs / Ouputs : (global commons)
-      !!           surface temperature : t_su_1d
-      !!           ice/snow temperatures   : t_i_1d, t_s_1d
-      !!           ice salinities          : s_i_1d
-      !!           number of layers in the ice/snow: nlay_i, nlay_s
-      !!           profile of the ice/snow layers : z_i, z_s
-      !!           total ice/snow thickness : ht_i_1d, ht_s_1d
-      !!
-      !! ** External : 
-      !!
-      !! ** References :
-      !!
-      !! ** History :
-      !!           (02-2003) Martin Vancoppenolle, Louvain-la-Neuve, Belgium
-      !!           (06-2005) Martin Vancoppenolle, 3d version
-      !!           (11-2006) Vectorized by Xavier Fettweis (UCL-ASTR)
-      !!           (04-2007) Energy conservation tested by M. Vancoppenolle
-      !!------------------------------------------------------------------
-      !! * Local variables
-      INTEGER ::   ji             ! spatial loop index
-      INTEGER ::   ii, ij         ! temporary dummy loop index
-      INTEGER ::   numeq          ! current reference number of equation
-      INTEGER ::   jk             ! vertical dummy loop index 
-      INTEGER ::   minnumeqmin, maxnumeqmax
-      INTEGER ::   iconv          ! number of iterations in iterative procedure
-      INTEGER ::   iconv_max = 50 ! max number of iterations in iterative procedure
-      
-      INTEGER, DIMENSION(jpij) ::   numeqmin   ! reference number of top equation
-      INTEGER, DIMENSION(jpij) ::   numeqmax   ! reference number of bottom equation
-      
-      REAL(wp) ::   zg1s      =  2._wp        ! for the tridiagonal system
-      REAL(wp) ::   zg1       =  2._wp        !
-      REAL(wp) ::   zgamma    =  18009._wp    ! for specific heat
-      REAL(wp) ::   zbeta     =  0.117_wp     ! for thermal conductivity (could be 0.13)
-      REAL(wp) ::   zraext_s  =  10._wp       ! extinction coefficient of radiation in the snow
-      REAL(wp) ::   zkimin    =  0.10_wp      ! minimum ice thermal conductivity
-      REAL(wp) ::   ztsu_err  =  1.e-5_wp     ! range around which t_su is considered at 0C 
-      REAL(wp) ::   ztmelt_i                  ! ice melting temperature
-      REAL(wp) ::   zhsu
-      REAL(wp) ::   zdti_max                  ! current maximal error on temperature 
-      REAL(wp) ::   zdti_bnd = 1.e-4_wp       ! maximal authorized error on temperature 
-      
-      REAL(wp), DIMENSION(jpij)     ::   isnow       ! switch for presence (1) or absence (0) of snow
-      REAL(wp), DIMENSION(jpij)     ::   ztsub       ! old surface temperature (before the iterative procedure )
-      REAL(wp), DIMENSION(jpij)     ::   ztsubit     ! surface temperature at previous iteration
-      REAL(wp), DIMENSION(jpij)     ::   zh_i        ! ice layer thickness
-      REAL(wp), DIMENSION(jpij)     ::   zh_s        ! snow layer thickness
-      REAL(wp), DIMENSION(jpij)     ::   zfsw        ! solar radiation absorbed at the surface
-      REAL(wp), DIMENSION(jpij)     ::   zqns_ice_b  ! solar radiation absorbed at the surface
-      REAL(wp), DIMENSION(jpij)     ::   zf          ! surface flux function
-      REAL(wp), DIMENSION(jpij)     ::   dzf         ! derivative of the surface flux function
-      REAL(wp), DIMENSION(jpij)     ::   zdti        ! current error on temperature
-      REAL(wp), DIMENSION(jpij)     ::   zdifcase    ! case of the equation resolution (1->4)
-      REAL(wp), DIMENSION(jpij)     ::   zftrice     ! solar radiation transmitted through the ice
-      REAL(wp), DIMENSION(jpij)     ::   zihic
-      
-      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   ztcond_i    ! Ice thermal conductivity
-      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   zradtr_i    ! Radiation transmitted through the ice
-      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   zradab_i    ! Radiation absorbed in the ice
-      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   zkappa_i    ! Kappa factor in the ice
-      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   ztib        ! Old temperature in the ice
-      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   zeta_i      ! Eta factor in the ice
-      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   ztitemp     ! Temporary temperature in the ice to check the convergence
-      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   zspeche_i   ! Ice specific heat
-      REAL(wp), DIMENSION(jpij,0:nlay_i)   ::   z_i         ! Vertical cotes of the layers in the ice
-      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   zradtr_s    ! Radiation transmited through the snow
-      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   zradab_s    ! Radiation absorbed in the snow
-      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   zkappa_s    ! Kappa factor in the snow
-      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   zeta_s      ! Eta factor in the snow
-      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   ztstemp     ! Temporary temperature in the snow to check the convergence
-      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   ztsb        ! Temporary temperature in the snow
-      REAL(wp), DIMENSION(jpij,0:nlay_s)   ::   z_s         ! Vertical cotes of the layers in the snow
-      REAL(wp), DIMENSION(jpij,nlay_i+3)   ::   zindterm    ! 'Ind'ependent term
-      REAL(wp), DIMENSION(jpij,nlay_i+3)   ::   zindtbis    ! Temporary 'ind'ependent term
-      REAL(wp), DIMENSION(jpij,nlay_i+3)   ::   zdiagbis    ! Temporary 'dia'gonal term
-      REAL(wp), DIMENSION(jpij,nlay_i+3,3) ::   ztrid       ! Tridiagonal system terms
-      REAL(wp), DIMENSION(jpij)            ::   zdq, zq_ini, zhfx_err ! diag errors on heat
-      REAL(wp), DIMENSION(jpij)            ::   zghe        ! G(he), th. conduct enhancement factor, mono-cat
-      
-      ! Mono-category
-      REAL(wp) :: zepsilon      ! determines thres. above which computation of G(h) is done
-      REAL(wp) :: zratio_s      ! dummy factor
-      REAL(wp) :: zratio_i      ! dummy factor
-      REAL(wp) :: zh_thres      ! thickness thres. for G(h) computation
-      REAL(wp) :: zhe           ! dummy factor
-      REAL(wp) :: zkimean       ! mean sea ice thermal conductivity
-      REAL(wp) :: zfac          ! dummy factor
-      REAL(wp) :: zihe          ! dummy factor
-      REAL(wp) :: zheshth       ! dummy factor
-      !!------------------------------------------------------------------     
-
-      ! --- diag error on heat diffusion - PART 1 --- !
-      zdq(:) = 0._wp ; zq_ini(:) = 0._wp      
-      DO ji = 1, nidx
-         zq_ini(ji) = ( SUM( e_i_1d(ji,1:nlay_i) ) * ht_i_1d(ji) * r1_nlay_i +  &
-            &           SUM( e_s_1d(ji,1:nlay_s) ) * ht_s_1d(ji) * r1_nlay_s ) 
-      END DO
-
-      !------------------------------------------------------------------------------!
-      ! 1) Initialization                                                            !
-      !------------------------------------------------------------------------------!
-      DO ji = 1 , nidx
-         isnow(ji)= 1._wp - MAX( 0._wp , SIGN(1._wp, - ht_s_1d(ji) ) )  ! is there snow or not
-         ! layer thickness
-         zh_i(ji) = ht_i_1d(ji) * r1_nlay_i
-         zh_s(ji) = ht_s_1d(ji) * r1_nlay_s
-      END DO
-
-      !--------------------
-      ! Ice / snow layers
-      !--------------------
-
-      z_s(:,0) = 0._wp   ! vert. coord. of the up. lim. of the 1st snow layer
-      z_i(:,0) = 0._wp   ! vert. coord. of the up. lim. of the 1st ice layer
-
-      DO jk = 1, nlay_s            ! vert. coord of the up. lim. of the layer-th snow layer
-         DO ji = 1 , nidx
-            z_s(ji,jk) = z_s(ji,jk-1) + ht_s_1d(ji) * r1_nlay_s
-         END DO
-      END DO
-
-      DO jk = 1, nlay_i            ! vert. coord of the up. lim. of the layer-th ice layer
-         DO ji = 1 , nidx
-            z_i(ji,jk) = z_i(ji,jk-1) + ht_i_1d(ji) * r1_nlay_i
-         END DO
-      END DO
-      !
-      !------------------------------------------------------------------------------|
-      ! 2) Radiation								                                 |
-      !------------------------------------------------------------------------------|
-      !
-      !-------------------
-      ! Computation of i0
-      !-------------------
-      ! i0 describes the fraction of solar radiation which does not contribute
-      ! to the surface energy budget but rather penetrates inside the ice.
-      ! We assume that no radiation is transmitted through the snow
-      ! If there is no no snow
-      ! zfsw    = (1-i0).qsr_ice   is absorbed at the surface 
-      ! zftrice = io.qsr_ice       is below the surface 
-      ! ftr_ice = io.qsr_ice.exp(-k(h_i)) transmitted below the ice 
-      ! fr1_i0_1d = i0 for a thin ice cover, fr1_i0_2d = i0 for a thick ice cover
-      zhsu = 0.1_wp ! threshold for the computation of i0
-      DO ji = 1 , nidx
-         ! switches
-         isnow(ji) = 1._wp - MAX( 0._wp , SIGN( 1._wp , - ht_s_1d(ji) ) ) 
-         ! hs > 0, isnow = 1
-         zihic(ji) = MAX( 0._wp , 1._wp - ( ht_i_1d(ji) / zhsu ) )     
-
-         i0(ji)    = ( 1._wp - isnow(ji) ) * ( fr1_i0_1d(ji) + zihic(ji) * fr2_i0_1d(ji) )
-      END DO
-
-      !-------------------------------------------------------
-      ! Solar radiation absorbed / transmitted at the surface
-      ! Derivative of the non solar flux
-      !-------------------------------------------------------
-      DO ji = 1 , nidx
-         zfsw   (ji)    =  qsr_ice_1d(ji) * ( 1 - i0(ji) )   ! Shortwave radiation absorbed at surface
-         zftrice(ji)    =  qsr_ice_1d(ji) *       i0(ji)     ! Solar radiation transmitted below the surface layer
-         dzf    (ji)    = dqns_ice_1d(ji)                    ! derivative of incoming nonsolar flux 
-         zqns_ice_b(ji) = qns_ice_1d(ji)                     ! store previous qns_ice_1d value
-      END DO
-
-      !---------------------------------------------------------
-      ! Transmission - absorption of solar radiation in the ice
-      !---------------------------------------------------------
-
-      DO ji = 1, nidx           ! snow initialization
-         zradtr_s(ji,0) = zftrice(ji)     ! radiation penetrating through snow
-      END DO
-
-      DO jk = 1, nlay_s          ! Radiation through snow
-         DO ji = 1, nidx
-            !                             ! radiation transmitted below the layer-th snow layer
-            zradtr_s(ji,jk) = zradtr_s(ji,0) * EXP( - zraext_s * ( MAX ( 0._wp , z_s(ji,jk) ) ) )
-            !                             ! radiation absorbed by the layer-th snow layer
-            zradab_s(ji,jk) = zradtr_s(ji,jk-1) - zradtr_s(ji,jk)
-         END DO
-      END DO
-
-      DO ji = 1, nidx           ! ice initialization
-         zradtr_i(ji,0) = zradtr_s(ji,nlay_s) * isnow(ji) + zftrice(ji) * ( 1._wp - isnow(ji) )
-      END DO
-
-      DO jk = 1, nlay_i          ! Radiation through ice
-         DO ji = 1, nidx
-            !                             ! radiation transmitted below the layer-th ice layer
-            zradtr_i(ji,jk) = zradtr_i(ji,0) * EXP( - rn_kappa_i * ( MAX ( 0._wp , z_i(ji,jk) ) ) )
-            !                             ! radiation absorbed by the layer-th ice layer
-            zradab_i(ji,jk) = zradtr_i(ji,jk-1) - zradtr_i(ji,jk)
-         END DO
-      END DO
-
-      DO ji = 1, nidx           ! Radiation transmitted below the ice
-         ftr_ice_1d(ji) = zradtr_i(ji,nlay_i) 
-      END DO
-
-      !------------------------------------------------------------------------------|
-      !  3) Iterative procedure begins                                               |
-      !------------------------------------------------------------------------------|
-      !
-      DO ji = 1, nidx        ! Old surface temperature
-         ztsub  (ji) =  t_su_1d(ji)                              ! temperature at the beg of iter pr.
-         ztsubit(ji) =  t_su_1d(ji)                              ! temperature at the previous iter
-         t_su_1d(ji) =  MIN( t_su_1d(ji), rt0 - ztsu_err )       ! necessary
-         zdti   (ji) =  1000._wp                                 ! initial value of error
-      END DO
-
-      DO jk = 1, nlay_s       ! Old snow temperature
-         DO ji = 1 , nidx
-            ztsb(ji,jk) =  t_s_1d(ji,jk)
-         END DO
-      END DO
-
-      DO jk = 1, nlay_i       ! Old ice temperature
-         DO ji = 1 , nidx
-            ztib(ji,jk) =  t_i_1d(ji,jk)
-         END DO
-      END DO
-
-      iconv    =  0           ! number of iterations
-      zdti_max =  1000._wp    ! maximal value of error on all points
-
-      DO WHILE ( zdti_max > zdti_bnd .AND. iconv < iconv_max )
-         !
-         iconv = iconv + 1
-         !
-         !------------------------------------------------------------------------------|
-         ! 4) Sea ice thermal conductivity                                              |
-         !------------------------------------------------------------------------------|
-         !
-         IF( nn_ice_thcon == 0 ) THEN      ! Untersteiner (1964) formula
-            DO ji = 1 , nidx
-               ztcond_i(ji,0) = rcdic + zbeta * s_i_1d(ji,1) / MIN( -epsi10, t_i_1d(ji,1) - rt0 )
-               ztcond_i(ji,0) = MAX( ztcond_i(ji,0), zkimin )
-            END DO
-            DO jk = 1, nlay_i-1
-               DO ji = 1 , nidx
-                  ztcond_i(ji,jk) = rcdic + zbeta * ( s_i_1d(ji,jk) + s_i_1d(ji,jk+1) ) /  &
-                     MIN(-2.0_wp * epsi10, t_i_1d(ji,jk) + t_i_1d(ji,jk+1) - 2.0_wp * rt0)
-                  ztcond_i(ji,jk) = MAX( ztcond_i(ji,jk), zkimin )
-               END DO
-            END DO
-         ENDIF
-
-         IF( nn_ice_thcon == 1 ) THEN      ! Pringle et al formula included: 2.11 + 0.09 S/T - 0.011.T
-            DO ji = 1 , nidx
-               ztcond_i(ji,0) = rcdic + 0.090_wp * s_i_1d(ji,1) / MIN( -epsi10, t_i_1d(ji,1) - rt0 )   &
-                  &                   - 0.011_wp * ( t_i_1d(ji,1) - rt0 )  
-               ztcond_i(ji,0) = MAX( ztcond_i(ji,0), zkimin )
-            END DO
-            DO jk = 1, nlay_i-1
-               DO ji = 1 , nidx
-                  ztcond_i(ji,jk) = rcdic +                                                                       & 
-                     &                 0.09_wp * ( s_i_1d(ji,jk) + s_i_1d(ji,jk+1) )                              &
-                     &                 / MIN( -2._wp * epsi10, t_i_1d(ji,jk) + t_i_1d(ji,jk+1) - 2.0_wp * rt0 )   &
-                     &               - 0.0055_wp * ( t_i_1d(ji,jk) + t_i_1d(ji,jk+1) - 2.0 * rt0 )  
-                  ztcond_i(ji,jk) = MAX( ztcond_i(ji,jk), zkimin )
-               END DO
-            END DO
-            DO ji = 1 , nidx
-               ztcond_i(ji,nlay_i) = rcdic + 0.090_wp * s_i_1d(ji,nlay_i) / MIN( -epsi10, t_bo_1d(ji) - rt0 )   &
-                  &                        - 0.011_wp * ( t_bo_1d(ji) - rt0 )  
-               ztcond_i(ji,nlay_i) = MAX( ztcond_i(ji,nlay_i), zkimin )
-            END DO
-         ENDIF
-         
-         !
-         !------------------------------------------------------------------------------|
-         !  5) G(he) - enhancement of thermal conductivity in mono-category case        |
-         !------------------------------------------------------------------------------|
-         !
-         ! Computation of effective thermal conductivity G(h)
-         ! Used in mono-category case only to simulate an ITD implicitly
-         ! Fichefet and Morales Maqueda, JGR 1997
-
-         zghe(:) = 1._wp
-
-         SELECT CASE ( nn_monocat )
-
-         CASE (1,3) ! LIM3
-
-            zepsilon = 0.1_wp
-            zh_thres = EXP( 1._wp ) * zepsilon * 0.5_wp
-
-            DO ji = 1, nidx
-   
-               ! Mean sea ice thermal conductivity
-               zkimean  = SUM( ztcond_i(ji,0:nlay_i) ) / REAL( nlay_i+1, wp )
-
-               ! Effective thickness he (zhe)
-               zfac     = 1._wp / ( rn_cdsn + zkimean )
-               zratio_s = rn_cdsn   * zfac
-               zratio_i = zkimean * zfac
-               zhe      = zratio_s * ht_i_1d(ji) + zratio_i * ht_s_1d(ji)
-
-               ! G(he)
-               rswitch  = MAX( 0._wp , SIGN( 1._wp , zhe - zh_thres ) )  ! =0 if zhe < zh_thres, if >
-               zghe(ji) = ( 1._wp - rswitch ) + rswitch * 0.5_wp * ( 1._wp + LOG( 2._wp * zhe / zepsilon ) )
-   
-               ! Impose G(he) < 2.
-               zghe(ji) = MIN( zghe(ji), 2._wp )
-
-            END DO
-
-         END SELECT
-
-         !
-         !------------------------------------------------------------------------------|
-         !  6) kappa factors                                                            |
-         !------------------------------------------------------------------------------|
-         !
-         !--- Snow
-         DO ji = 1, nidx
-            zfac                  =  1. / MAX( epsi10 , zh_s(ji) )
-            zkappa_s(ji,0)        = zghe(ji) * rn_cdsn * zfac
-            zkappa_s(ji,nlay_s)   = zghe(ji) * rn_cdsn * zfac
-         END DO
-
-         DO jk = 1, nlay_s-1
-            DO ji = 1 , nidx
-               zkappa_s(ji,jk)    = zghe(ji) * 2.0 * rn_cdsn / MAX( epsi10, 2.0 * zh_s(ji) )
-            END DO
-         END DO
-
-         !--- Ice
-         DO jk = 1, nlay_i-1
-            DO ji = 1 , nidx
-               zkappa_i(ji,jk)    = zghe(ji) * 2.0 * ztcond_i(ji,jk) / MAX( epsi10 , 2.0 * zh_i(ji) )
-            END DO
-         END DO
-
-         !--- Snow-ice interface
-         DO ji = 1 , nidx
-            zfac                  = 1./ MAX( epsi10 , zh_i(ji) )
-            zkappa_i(ji,0)        = zghe(ji) * ztcond_i(ji,0) * zfac
-            zkappa_i(ji,nlay_i)   = zghe(ji) * ztcond_i(ji,nlay_i) * zfac
-            zkappa_s(ji,nlay_s)   = zghe(ji) * zghe(ji) * 2.0 * rn_cdsn * ztcond_i(ji,0) / & 
-           &                        MAX( epsi10, ( zghe(ji) * ztcond_i(ji,0) * zh_s(ji) + zghe(ji) * rn_cdsn * zh_i(ji) ) )
-            zkappa_i(ji,0)        = zkappa_s(ji,nlay_s) * isnow(ji) + zkappa_i(ji,0) * ( 1._wp - isnow(ji) )
-         END DO
-
-         !
-         !------------------------------------------------------------------------------|
-         ! 7) Sea ice specific heat, eta factors                                        |
-         !------------------------------------------------------------------------------|
-         !
-         DO jk = 1, nlay_i
-            DO ji = 1 , nidx
-               ztitemp(ji,jk)   = t_i_1d(ji,jk)
-               zspeche_i(ji,jk) = cpic + zgamma * s_i_1d(ji,jk) / MAX( ( t_i_1d(ji,jk) - rt0 ) * ( ztib(ji,jk) - rt0 ), epsi10 )
-               zeta_i(ji,jk)    = rdt_ice / MAX( rhoic * zspeche_i(ji,jk) * zh_i(ji), epsi10 )
-            END DO
-         END DO
-
-         DO jk = 1, nlay_s
-            DO ji = 1 , nidx
-               ztstemp(ji,jk) = t_s_1d(ji,jk)
-               zeta_s(ji,jk)  = rdt_ice / MAX( rhosn * cpic * zh_s(ji), epsi10 )
-            END DO
-         END DO
-
-         !
-         !------------------------------------------------------------------------------|
-         ! 8) surface flux computation                                                  |
-         !------------------------------------------------------------------------------|
-         !
-         IF ( ln_dqnsice ) THEN 
-            DO ji = 1 , nidx
-               ! update of the non solar flux according to the update in T_su
-               qns_ice_1d(ji) = qns_ice_1d(ji) + dqns_ice_1d(ji) * ( t_su_1d(ji) - ztsubit(ji) )
-            END DO
-         ENDIF
-
-         ! Update incoming flux
-         DO ji = 1 , nidx
-            ! update incoming flux
-            zf(ji)    =          zfsw(ji)              & ! net absorbed solar radiation
-               &         + qns_ice_1d(ji)                ! non solar total flux (LWup, LWdw, SH, LH)
-         END DO
-
-         !
-         !------------------------------------------------------------------------------|
-         ! 9) tridiagonal system terms                                                  |
-         !------------------------------------------------------------------------------|
-         !
-         !!layer denotes the number of the layer in the snow or in the ice
-         !!numeq denotes the reference number of the equation in the tridiagonal
-         !!system, terms of tridiagonal system are indexed as following :
-         !!1 is subdiagonal term, 2 is diagonal and 3 is superdiagonal one
-
-         !!ice interior terms (top equation has the same form as the others)
-
-         DO numeq=1,nlay_i+3
-            DO ji = 1 , nidx
-               ztrid(ji,numeq,1) = 0.
-               ztrid(ji,numeq,2) = 0.
-               ztrid(ji,numeq,3) = 0.
-               zindterm(ji,numeq)= 0.
-               zindtbis(ji,numeq)= 0.
-               zdiagbis(ji,numeq)= 0.
-            ENDDO
-         ENDDO
-
-         DO numeq = nlay_s + 2, nlay_s + nlay_i 
-            DO ji = 1 , nidx
-               jk                 = numeq - nlay_s - 1
-               ztrid(ji,numeq,1)  =  - zeta_i(ji,jk) * zkappa_i(ji,jk-1)
-               ztrid(ji,numeq,2)  =  1.0 + zeta_i(ji,jk) * ( zkappa_i(ji,jk-1) + zkappa_i(ji,jk) )
-               ztrid(ji,numeq,3)  =  - zeta_i(ji,jk) * zkappa_i(ji,jk)
-               zindterm(ji,numeq) =  ztib(ji,jk) + zeta_i(ji,jk) * zradab_i(ji,jk)
-            END DO
-         ENDDO
-
-         numeq =  nlay_s + nlay_i + 1
-         DO ji = 1 , nidx
-            !!ice bottom term
-            ztrid(ji,numeq,1)  =  - zeta_i(ji,nlay_i)*zkappa_i(ji,nlay_i-1)   
-            ztrid(ji,numeq,2)  =  1.0 + zeta_i(ji,nlay_i) * ( zkappa_i(ji,nlay_i) * zg1 + zkappa_i(ji,nlay_i-1) )
-            ztrid(ji,numeq,3)  =  0.0
-            zindterm(ji,numeq) =  ztib(ji,nlay_i) + zeta_i(ji,nlay_i) *  &
-               &                  ( zradab_i(ji,nlay_i) + zkappa_i(ji,nlay_i) * zg1 *  t_bo_1d(ji) ) 
-         ENDDO
-
-
-         DO ji = 1 , nidx
-            IF ( ht_s_1d(ji) > 0.0 ) THEN
-               !
-               !------------------------------------------------------------------------------|
-               !  snow-covered cells                                                          |
-               !------------------------------------------------------------------------------|
-               !
-               !!snow interior terms (bottom equation has the same form as the others)
-               DO numeq = 3, nlay_s + 1
-                  jk                  =  numeq - 1
-                  ztrid(ji,numeq,1)   =  - zeta_s(ji,jk) * zkappa_s(ji,jk-1)
-                  ztrid(ji,numeq,2)   =  1.0 + zeta_s(ji,jk) * ( zkappa_s(ji,jk-1) + zkappa_s(ji,jk) )
-                  ztrid(ji,numeq,3)   =  - zeta_s(ji,jk)*zkappa_s(ji,jk)
-                  zindterm(ji,numeq)  =  ztsb(ji,jk) + zeta_s(ji,jk) * zradab_s(ji,jk)
-               END DO
-
-               !!case of only one layer in the ice (ice equation is altered)
-               IF ( nlay_i.eq.1 ) THEN
-                  ztrid(ji,nlay_s+2,3)    =  0.0
-                  zindterm(ji,nlay_s+2)   =  zindterm(ji,nlay_s+2) + zkappa_i(ji,1) * t_bo_1d(ji) 
-               ENDIF
-
-               IF ( t_su_1d(ji) < rt0 ) THEN
-
-                  !------------------------------------------------------------------------------|
-                  !  case 1 : no surface melting - snow present                                  |
-                  !------------------------------------------------------------------------------|
-                  zdifcase(ji)    =  1.0
-                  numeqmin(ji)    =  1
-                  numeqmax(ji)    =  nlay_i + nlay_s + 1
-
-                  !!surface equation
-                  ztrid(ji,1,1)  = 0.0
-                  ztrid(ji,1,2)  = dzf(ji) - zg1s * zkappa_s(ji,0)
-                  ztrid(ji,1,3)  = zg1s * zkappa_s(ji,0)
-                  zindterm(ji,1) = dzf(ji) * t_su_1d(ji) - zf(ji)
-
-                  !!first layer of snow equation
-                  ztrid(ji,2,1)  =  - zkappa_s(ji,0) * zg1s * zeta_s(ji,1)
-                  ztrid(ji,2,2)  =  1.0 + zeta_s(ji,1) * ( zkappa_s(ji,1) + zkappa_s(ji,0) * zg1s )
-                  ztrid(ji,2,3)  =  - zeta_s(ji,1)* zkappa_s(ji,1)
-                  zindterm(ji,2) =  ztsb(ji,1) + zeta_s(ji,1) * zradab_s(ji,1)
-
-               ELSE 
-                  !
-                  !------------------------------------------------------------------------------|
-                  !  case 2 : surface is melting - snow present                                  |
-                  !------------------------------------------------------------------------------|
-                  !
-                  zdifcase(ji)    =  2.0
-                  numeqmin(ji)    =  2
-                  numeqmax(ji)    =  nlay_i + nlay_s + 1
-
-                  !!first layer of snow equation
-                  ztrid(ji,2,1)  =  0.0
-                  ztrid(ji,2,2)  =  1.0 + zeta_s(ji,1) * ( zkappa_s(ji,1) + zkappa_s(ji,0) * zg1s )
-                  ztrid(ji,2,3)  =  - zeta_s(ji,1)*zkappa_s(ji,1) 
-                  zindterm(ji,2) = ztsb(ji,1) + zeta_s(ji,1) *  &
-                     &             ( zradab_s(ji,1) + zkappa_s(ji,0) * zg1s * t_su_1d(ji) ) 
-               ENDIF
-            ELSE
-               !
-               !------------------------------------------------------------------------------|
-               !  cells without snow                                                          |
-               !------------------------------------------------------------------------------|
-               !
-               IF ( t_su_1d(ji) < rt0 ) THEN
-                  !
-                  !------------------------------------------------------------------------------|
-                  !  case 3 : no surface melting - no snow                                       |
-                  !------------------------------------------------------------------------------|
-                  !
-                  zdifcase(ji)      =  3.0
-                  numeqmin(ji)      =  nlay_s + 1
-                  numeqmax(ji)      =  nlay_i + nlay_s + 1
-
-                  !!surface equation	
-                  ztrid(ji,numeqmin(ji),1)   =  0.0
-                  ztrid(ji,numeqmin(ji),2)   =  dzf(ji) - zkappa_i(ji,0)*zg1    
-                  ztrid(ji,numeqmin(ji),3)   =  zkappa_i(ji,0)*zg1
-                  zindterm(ji,numeqmin(ji))  =  dzf(ji)*t_su_1d(ji) - zf(ji)
-
-                  !!first layer of ice equation
-                  ztrid(ji,numeqmin(ji)+1,1) =  - zkappa_i(ji,0) * zg1 * zeta_i(ji,1)
-                  ztrid(ji,numeqmin(ji)+1,2) =  1.0 + zeta_i(ji,1) * ( zkappa_i(ji,1) + zkappa_i(ji,0) * zg1 )
-                  ztrid(ji,numeqmin(ji)+1,3) =  - zeta_i(ji,1) * zkappa_i(ji,1)  
-                  zindterm(ji,numeqmin(ji)+1)=  ztib(ji,1) + zeta_i(ji,1) * zradab_i(ji,1)  
-
-                  !!case of only one layer in the ice (surface & ice equations are altered)
-
-                  IF ( nlay_i == 1 ) THEN
-                     ztrid(ji,numeqmin(ji),1)    =  0.0
-                     ztrid(ji,numeqmin(ji),2)    =  dzf(ji) - zkappa_i(ji,0) * 2.0
-                     ztrid(ji,numeqmin(ji),3)    =  zkappa_i(ji,0) * 2.0
-                     ztrid(ji,numeqmin(ji)+1,1)  =  -zkappa_i(ji,0) * 2.0 * zeta_i(ji,1)
-                     ztrid(ji,numeqmin(ji)+1,2)  =  1.0 + zeta_i(ji,1) * ( zkappa_i(ji,0) * 2.0 + zkappa_i(ji,1) )
-                     ztrid(ji,numeqmin(ji)+1,3)  =  0.0
-
-                     zindterm(ji,numeqmin(ji)+1) =  ztib(ji,1) + zeta_i(ji,1) *  &
-                        &                          ( zradab_i(ji,1) + zkappa_i(ji,1) * t_bo_1d(ji) )
-                  ENDIF
-
-               ELSE
-
-                  !
-                  !------------------------------------------------------------------------------|
-                  ! case 4 : surface is melting - no snow                                        |
-                  !------------------------------------------------------------------------------|
-                  !
-                  zdifcase(ji)    =  4.0
-                  numeqmin(ji)    =  nlay_s + 2
-                  numeqmax(ji)    =  nlay_i + nlay_s + 1
-
-                  !!first layer of ice equation
-                  ztrid(ji,numeqmin(ji),1)      =  0.0
-                  ztrid(ji,numeqmin(ji),2)      =  1.0 + zeta_i(ji,1) * ( zkappa_i(ji,1) + zkappa_i(ji,0) * zg1 )  
-                  ztrid(ji,numeqmin(ji),3)      =  - zeta_i(ji,1) * zkappa_i(ji,1)
-                  zindterm(ji,numeqmin(ji))     =  ztib(ji,1) + zeta_i(ji,1) *  &
-                     &                             ( zradab_i(ji,1) + zkappa_i(ji,0) * zg1 * t_su_1d(ji) ) 
-
-                  !!case of only one layer in the ice (surface & ice equations are altered)
-                  IF ( nlay_i == 1 ) THEN
-                     ztrid(ji,numeqmin(ji),1)  =  0.0
-                     ztrid(ji,numeqmin(ji),2)  =  1.0 + zeta_i(ji,1) * ( zkappa_i(ji,0) * 2.0 + zkappa_i(ji,1) )
-                     ztrid(ji,numeqmin(ji),3)  =  0.0
-                     zindterm(ji,numeqmin(ji)) =  ztib(ji,1) + zeta_i(ji,1) * ( zradab_i(ji,1) + zkappa_i(ji,1) * t_bo_1d(ji) )  &
-                        &                       + t_su_1d(ji) * zeta_i(ji,1) * zkappa_i(ji,0) * 2.0
-                  ENDIF
-
-               ENDIF
-            ENDIF
-
-         END DO
-
-         !
-         !------------------------------------------------------------------------------|
-         ! 10) tridiagonal system solving                                               |
-         !------------------------------------------------------------------------------|
-         !
-
-         ! Solve the tridiagonal system with Gauss elimination method.
-         ! Thomas algorithm, from Computational fluid Dynamics, J.D. ANDERSON, 
-         ! McGraw-Hill 1984.	
-
-         maxnumeqmax = 0
-         minnumeqmin = nlay_i+5
-
-         DO ji = 1 , nidx
-            zindtbis(ji,numeqmin(ji)) =  zindterm(ji,numeqmin(ji))
-            zdiagbis(ji,numeqmin(ji)) =  ztrid(ji,numeqmin(ji),2)
-            minnumeqmin               =  MIN(numeqmin(ji),minnumeqmin)
-            maxnumeqmax               =  MAX(numeqmax(ji),maxnumeqmax)
-         END DO
-
-         DO jk = minnumeqmin+1, maxnumeqmax
-            DO ji = 1 , nidx
-               numeq               =  min(max(numeqmin(ji)+1,jk),numeqmax(ji))
-               zdiagbis(ji,numeq)  =  ztrid(ji,numeq,2)  - ztrid(ji,numeq,1) * ztrid(ji,numeq-1,3)  / zdiagbis(ji,numeq-1)
-               zindtbis(ji,numeq)  =  zindterm(ji,numeq) - ztrid(ji,numeq,1) * zindtbis(ji,numeq-1) / zdiagbis(ji,numeq-1)
-            END DO
-         END DO
-
-         DO ji = 1 , nidx
-            ! ice temperatures
-            t_i_1d(ji,nlay_i)    =  zindtbis(ji,numeqmax(ji)) / zdiagbis(ji,numeqmax(ji))
-         END DO
-
-         DO numeq = nlay_i + nlay_s, nlay_s + 2, -1
-            DO ji = 1 , nidx
-               jk    =  numeq - nlay_s - 1
-               t_i_1d(ji,jk)  =  ( zindtbis(ji,numeq) - ztrid(ji,numeq,3) * t_i_1d(ji,jk+1) ) / zdiagbis(ji,numeq)
-            END DO
-         END DO
-
-         DO ji = 1 , nidx
-            ! snow temperatures      
-            IF (ht_s_1d(ji) > 0._wp) &
-               t_s_1d(ji,nlay_s)     =  ( zindtbis(ji,nlay_s+1) - ztrid(ji,nlay_s+1,3) * t_i_1d(ji,1) )  &
-               &                        / zdiagbis(ji,nlay_s+1) * MAX( 0.0, SIGN( 1.0, ht_s_1d(ji) ) ) 
-
-            ! surface temperature
-            isnow(ji)   = 1._wp - MAX( 0._wp , SIGN( 1._wp , -ht_s_1d(ji) ) )
-            ztsubit(ji) = t_su_1d(ji)
-            IF( t_su_1d(ji) < rt0 ) &
-               t_su_1d(ji) = ( zindtbis(ji,numeqmin(ji)) - ztrid(ji,numeqmin(ji),3) *  &
-               &             ( isnow(ji) * t_s_1d(ji,1) + ( 1._wp - isnow(ji) ) * t_i_1d(ji,1) ) ) / zdiagbis(ji,numeqmin(ji))  
-         END DO
-         !
-         !--------------------------------------------------------------------------
-         !  11) Has the scheme converged ?, end of the iterative procedure         |
-         !--------------------------------------------------------------------------
-         !
-         ! check that nowhere it has started to melt
-         ! zdti(ji) is a measure of error, it has to be under zdti_bnd
-         DO ji = 1 , nidx
-            t_su_1d(ji) =  MAX(  MIN( t_su_1d(ji) , rt0 ) , 190._wp  )
-            zdti   (ji) =  ABS( t_su_1d(ji) - ztsubit(ji) )     
-         END DO
-
-         DO jk  =  1, nlay_s
-            DO ji = 1 , nidx
-               t_s_1d(ji,jk) = MAX(  MIN( t_s_1d(ji,jk), rt0 ), 190._wp  )
-               zdti  (ji)    = MAX( zdti(ji), ABS( t_s_1d(ji,jk) - ztstemp(ji,jk) ) )
-            END DO
-         END DO
-
-         DO jk  =  1, nlay_i
-            DO ji = 1 , nidx
-               ztmelt_i      = -tmut * s_i_1d(ji,jk) + rt0 
-               t_i_1d(ji,jk) =  MAX( MIN( t_i_1d(ji,jk), ztmelt_i ), 190._wp )
-               zdti  (ji)    =  MAX( zdti(ji), ABS( t_i_1d(ji,jk) - ztitemp(ji,jk) ) )
-            END DO
-         END DO
-
-         ! Compute spatial maximum over all errors
-         ! note that this could be optimized substantially by iterating only the non-converging points
-         zdti_max = 0._wp
-         DO ji = 1, nidx
-            zdti_max = MAX( zdti_max, zdti(ji) )   
-         END DO
-         IF( lk_mpp ) CALL mpp_max( zdti_max, kcom=ncomm_ice )
-
-      END DO  ! End of the do while iterative procedure
-
-      ! MV SIMIP 2016
-      !--- Snow-ice interfacial temperature (diagnostic SIMIP)
-      DO ji = 1, nidx
-         zfac        = 1. / MAX( epsi10 , rn_cdsn * zh_i(ji) + ztcond_i(ji,1) * zh_s(ji) )
-         IF( zh_s(ji) >= 1.e-3 ) THEN
-            t_si_1d(ji) = ( rn_cdsn        * zh_i(ji) * t_s_1d(ji,1) + &
-               &            ztcond_i(ji,1) * zh_s(ji) * t_i_1d(ji,1) ) * zfac
-         ELSE
-            t_si_1d(ji) = t_su_1d(ji)
-         ENDIF
-      END DO
-      ! END MV SIMIP 2016
-
-      IF( ln_limctl .AND. lwp ) THEN
-         WRITE(numout,*) ' zdti_max : ', zdti_max
-         WRITE(numout,*) ' iconv    : ', iconv
-      ENDIF
-
-      !
-      !-------------------------------------------------------------------------!
-      !   12) Fluxes at the interfaces                                          !
-      !-------------------------------------------------------------------------!
-      DO ji = 1, nidx
-         !                                ! surface ice conduction flux
-         isnow(ji)       = 1._wp - MAX( 0._wp, SIGN( 1._wp, -ht_s_1d(ji) ) )
-         fc_su(ji)       =  -           isnow(ji)   * zkappa_s(ji,0) * zg1s * (t_s_1d(ji,1) - t_su_1d(ji))   &
-            &               - ( 1._wp - isnow(ji) ) * zkappa_i(ji,0) * zg1  * (t_i_1d(ji,1) - t_su_1d(ji))
-         !                                ! bottom ice conduction flux
-         fc_bo_i(ji)     =  - zkappa_i(ji,nlay_i) * ( zg1*(t_bo_1d(ji) - t_i_1d(ji,nlay_i)) )
-      END DO
-
-      ! MV SIMIP 2016
-      !--- Conduction fluxes (positive downwards)
-      diag_fc_bo_1d(:)   = diag_fc_bo_1d(:) + fc_bo_i(:) * a_i_1d(:) / at_i_1d(:)
-      diag_fc_su_1d(:)   = diag_fc_su_1d(:) + fc_su(:)   * a_i_1d(:) / at_i_1d(:)
-      ! END MV SIMIP 2016
-
-      ! --- computes sea ice energy of melting compulsory for limthd_dh --- !
-      CALL lim_thd_enmelt
-
-      ! --- diagnose the change in non-solar flux due to surface temperature change --- !
-      IF ( ln_dqnsice ) THEN
-         DO ji = 1, nidx
-            hfx_err_dif_1d(ji) = hfx_err_dif_1d(ji) - ( qns_ice_1d(ji)  - zqns_ice_b(ji) ) * a_i_1d(ji) 
-         END DO
-      END IF
-
-      ! --- diag conservation imbalance on heat diffusion - PART 2 --- !
-      DO ji = 1, nidx
-         zdq(ji)        = - zq_ini(ji) + ( SUM( e_i_1d(ji,1:nlay_i) ) * ht_i_1d(ji) * r1_nlay_i +  &
-            &                              SUM( e_s_1d(ji,1:nlay_s) ) * ht_s_1d(ji) * r1_nlay_s )
-         IF( t_su_1d(ji) < rt0 ) THEN  ! case T_su < 0degC
-            zhfx_err(ji) = qns_ice_1d(ji) + qsr_ice_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) + zdq(ji) * r1_rdtice 
-         ELSE                          ! case T_su = 0degC
-            zhfx_err(ji) = fc_su(ji) + i0(ji) * qsr_ice_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) + zdq(ji) * r1_rdtice 
-         ENDIF
-         hfx_err_1d(ji) = hfx_err_1d(ji) + zhfx_err(ji) * a_i_1d(ji)
-
-         ! total heat that is sent to the ocean (i.e. not used in the heat diffusion equation)
-         hfx_err_dif_1d(ji) = hfx_err_dif_1d(ji) + zhfx_err(ji) * a_i_1d(ji)
-      END DO 
-
-      !-----------------------------------------
-      ! Heat flux used to warm/cool ice in W.m-2
-      !-----------------------------------------
-      DO ji = 1, nidx
-         IF( t_su_1d(ji) < rt0 ) THEN  ! case T_su < 0degC
-            hfx_dif_1d(ji) = hfx_dif_1d(ji)  +   &
-               &            ( qns_ice_1d(ji) + qsr_ice_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) ) * a_i_1d(ji)
-         ELSE                          ! case T_su = 0degC
-            hfx_dif_1d(ji) = hfx_dif_1d(ji) +    &
-               &             ( fc_su(ji) + i0(ji) * qsr_ice_1d(ji) - zradtr_i(ji,nlay_i) - fc_bo_i(ji) ) * a_i_1d(ji)
-         ENDIF
-         ! correction on the diagnosed heat flux due to non-convergence of the algorithm used to solve heat equation
-         hfx_dif_1d(ji) = hfx_dif_1d(ji) - zhfx_err(ji) * a_i_1d(ji)
-      END DO   
-      !
-   END SUBROUTINE lim_thd_dif
-
-   SUBROUTINE lim_thd_enmelt
-      !!-----------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_thd_enmelt *** 
-      !!                 
-      !! ** Purpose :   Computes sea ice energy of melting q_i (J.m-3) from temperature
-      !!
-      !! ** Method  :   Formula (Bitz and Lipscomb, 1999)
-      !!-------------------------------------------------------------------
-      INTEGER  ::   ji, jk   ! dummy loop indices
-      REAL(wp) ::   ztmelts  ! local scalar 
-      !!-------------------------------------------------------------------
-      !
-      DO jk = 1, nlay_i             ! Sea ice energy of melting
-         DO ji = 1, nidx
-            ztmelts      = - tmut  * s_i_1d(ji,jk) + rt0
-            t_i_1d(ji,jk) = MIN( t_i_1d(ji,jk), ztmelts ) ! Force t_i_1d to be lower than melting point
-                                                          !   (sometimes dif scheme produces abnormally high temperatures)   
-            e_i_1d(ji,jk) = rhoic * ( cpic * ( ztmelts - t_i_1d(ji,jk) )                           &
-               &                    + lfus * ( 1.0 - ( ztmelts-rt0 ) / ( t_i_1d(ji,jk) - rt0 ) )   &
-               &                    - rcp  *         ( ztmelts-rt0 )  ) 
-         END DO
-      END DO
-      DO jk = 1, nlay_s             ! Snow energy of melting
-         DO ji = 1, nidx
-            e_s_1d(ji,jk) = rhosn * ( cpic * ( rt0 - t_s_1d(ji,jk) ) + lfus )
-         END DO
-      END DO
-      !
-   END SUBROUTINE lim_thd_enmelt
-
-#else
-   !!----------------------------------------------------------------------
-   !!                   Dummy Module                 No LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_thd_dif          ! Empty routine
-   END SUBROUTINE lim_thd_dif
-#endif
-   !!======================================================================
-END MODULE limthd_dif
Index: anches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limthd_ent.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limthd_ent.F90	(revision 8421)
+++ 	(revision )
@@ -1,152 +1,0 @@
-MODULE limthd_ent
-   !!======================================================================
-   !!                       ***  MODULE limthd_ent   ***
-   !!                  Redistribution of Enthalpy in the ice
-   !!                        on the new vertical grid
-   !!                       after vertical growth/decay
-   !!======================================================================
-   !! History :  LIM  ! 2003-05 (M. Vancoppenolle) Original code in 1D
-   !!                 ! 2005-07 (M. Vancoppenolle) 3D version 
-   !!                 ! 2006-11 (X. Fettweis) Vectorized 
-   !!            3.0  ! 2008-03 (M. Vancoppenolle) Energy conservation and clean code
-   !!            3.4  ! 2011-02 (G. Madec) dynamical allocation
-   !!             -   ! 2014-05 (C. Rousset) complete rewriting
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_thd_ent   : ice redistribution of enthalpy
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-   USE dom_oce        ! domain variables
-   USE domain         !
-   USE phycst         ! physical constants
-   USE ice            ! LIM variables
-   USE ice1D          ! LIM thermodynamics
-   USE limvar         ! LIM variables
-   !
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_thd_ent         ! called by limthd and limthd_lac
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
- 
-   SUBROUTINE lim_thd_ent( qnew )
-      !!-------------------------------------------------------------------
-      !!               ***   ROUTINE lim_thd_ent  ***
-      !!
-      !! ** Purpose :
-      !!           This routine computes new vertical grids in the ice, 
-      !!           and consistently redistributes temperatures. 
-      !!           Redistribution is made so as to ensure to energy conservation
-      !!
-      !!
-      !! ** Method  : linear conservative remapping
-      !!           
-      !! ** Steps : 1) cumulative integrals of old enthalpies/thicknesses
-      !!            2) linear remapping on the new layers
-      !!
-      !! ------------ cum0(0)                        ------------- cum1(0)
-      !!                                    NEW      -------------
-      !! ------------ cum0(1)               ==>      -------------
-      !!     ...                                     -------------
-      !! ------------                                -------------
-      !! ------------ cum0(nlay_i+2)                 ------------- cum1(nlay_i)
-      !!
-      !!
-      !! References : Bitz & Lipscomb, JGR 99; Vancoppenolle et al., GRL, 2005
-      !!-------------------------------------------------------------------
-      REAL(wp), INTENT(inout), DIMENSION(:,:) :: qnew          ! new enthlapies (J.m-3, remapped)
-
-      INTEGER  :: ji         !  dummy loop indices
-      INTEGER  :: jk0, jk1   !  old/new layer indices
-      !
-      REAL(wp), DIMENSION(jpij,0:nlay_i+2) :: zeh_cum0, zh_cum0   ! old cumulative enthlapies and layers interfaces
-      REAL(wp), DIMENSION(jpij,0:nlay_i)   :: zeh_cum1, zh_cum1   ! new cumulative enthlapies and layers interfaces
-      REAL(wp), DIMENSION(jpij)            :: zhnew               ! new layers thicknesses
-      !!-------------------------------------------------------------------
-
-      !--------------------------------------------------------------------------
-      !  1) Cumulative integral of old enthalpy * thickness and layers interfaces
-      !--------------------------------------------------------------------------
-      zeh_cum0(:,0:nlay_i+2) = 0._wp 
-      zh_cum0 (:,0:nlay_i+2) = 0._wp
-      DO jk0 = 1, nlay_i+2
-         DO ji = 1, nidx
-            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
-
-      !------------------------------------
-      !  2) Interpolation on the new layers
-      !------------------------------------
-      ! new layer thickesses
-      DO ji = 1, nidx
-         zhnew(ji) = SUM( h_i_old(ji,0:nlay_i+1) ) * r1_nlay_i  
-      ENDDO
-
-      ! new layers interfaces
-      zh_cum1(:,0:nlay_i) = 0._wp
-      DO jk1 = 1, nlay_i
-         DO ji = 1, nidx
-            zh_cum1(ji,jk1) = zh_cum1(ji,jk1-1) + zhnew(ji)
-         ENDDO
-      ENDDO
-
-      zeh_cum1(:,0:nlay_i) = 0._wp 
-      ! new cumulative q*h => linear interpolation
-      DO jk0 = 1, nlay_i+1
-         DO jk1 = 1, nlay_i-1
-            DO ji = 1, nidx
-               IF( zh_cum1(ji,jk1) <= zh_cum0(ji,jk0) .AND. zh_cum1(ji,jk1) > zh_cum0(ji,jk0-1) ) THEN
-                  zeh_cum1(ji,jk1) = ( zeh_cum0(ji,jk0-1) * ( zh_cum0(ji,jk0) - zh_cum1(ji,jk1  ) ) +  &
-                     &                 zeh_cum0(ji,jk0  ) * ( zh_cum1(ji,jk1) - zh_cum0(ji,jk0-1) ) )  &
-                     &             / ( zh_cum0(ji,jk0) - zh_cum0(ji,jk0-1) )
-               ENDIF
-            ENDDO
-         ENDDO
-      ENDDO
-      ! to ensure that total heat content is strictly conserved, set:
-      zeh_cum1(:,nlay_i) = zeh_cum0(:,nlay_i+2) 
-
-      ! new enthalpies
-      DO jk1 = 1, nlay_i
-         DO ji = 1, nidx
-            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
-
-      ! --- diag error on heat remapping --- !
-      ! comment: if input h_i_old and eh_i_old are already multiplied by a_i (as in limthd_lac), 
-      ! then we should not (* a_i) again but not important since this is just to check that remap error is ~0
-      DO ji = 1, nidx
-         hfx_err_rem_1d(ji) = hfx_err_rem_1d(ji) + a_i_1d(ji) * r1_rdtice *  &
-            &               ( SUM( qnew(ji,1:nlay_i) ) * zhnew(ji) - SUM( eh_i_old(ji,0:nlay_i+1) ) ) 
-      END DO
-      
-   END SUBROUTINE lim_thd_ent
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                               NO  LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_thd_ent          ! Empty routine
-   END SUBROUTINE lim_thd_ent
-#endif
-
-   !!======================================================================
-END MODULE limthd_ent
Index: anches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limthd_lac.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limthd_lac.F90	(revision 8421)
+++ 	(revision )
@@ -1,494 +1,0 @@
-MODULE limthd_lac
-   !!======================================================================
-   !!                       ***  MODULE limthd_lac   ***
-   !!                lateral thermodynamic growth of the ice 
-   !!======================================================================
-   !! History :  LIM  ! 2005-12 (M. Vancoppenolle)  Original code
-   !!             -   ! 2006-01 (M. Vancoppenolle)  add ITD
-   !!            3.0  ! 2007-07 (M. Vancoppenolle)  Mass and energy conservation tested
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_lat_acr   : lateral accretion of ice
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-   USE dom_oce        ! domain variables
-   USE phycst         ! physical constants
-   USE sbc_oce , 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 icecons        ! LIM conservation
-   USE limthd_ent
-   USE limvar
-   !
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC lim_thd_lac     ! called by lim_thd
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_thd_lac
-      !!-------------------------------------------------------------------
-      !!               ***   ROUTINE lim_thd_lac  ***
-      !!  
-      !! ** Purpose : Computation of the evolution of the ice thickness and 
-      !!      concentration as a function of the heat balance in the leads.
-      !!      It is only used for lateral accretion
-      !!       
-      !! ** Method  : Ice is formed in the open water when ocean lose heat
-      !!      (heat budget of open water Bl is negative) .
-      !!      Computation of the increase of 1-A (ice concentration) fol-
-      !!      lowing the law :
-      !!      (dA/dt)acc = F[ (1-A)/(1-a) ] * [ Bl / (Li*h0) ]
-      !!       where - h0 is the thickness of ice created in the lead
-      !!             - a is a minimum fraction for leads
-      !!             - F is a monotonic non-increasing function defined as:
-      !!                  F(X)=( 1 - X**exld )**(1.0/exld)
-      !!             - exld is the exponent closure rate (=2 default val.)
-      !! 
-      !! ** Action : - Adjustment of snow and ice thicknesses and heat
-      !!                content in brine pockets
-      !!             - Updating ice internal temperature
-      !!             - Computation of variation of ice volume and mass
-      !!             - Computation of a_i after lateral accretion and 
-      !!               update ht_s_1d, ht_i_1d and tbif_1d(:,:)      
-      !!------------------------------------------------------------------------
-      INTEGER  ::   ji,jj,jk,jl      ! dummy loop indices
-      INTEGER  ::   iter     !   -       -
-      REAL(wp) ::   ztmelts, zdv, zfrazb, zweight, zde                          ! local scalars
-      REAL(wp) ::   zgamafr, zvfrx, zvgx, ztaux, ztwogp, zf                     !   -      -
-      REAL(wp) ::   ztenagm, zvfry, zvgy, ztauy, zvrel2, zfp, zsqcd , zhicrit   !   -      -
-
-      REAL(wp) ::   zQm          ! enthalpy exchanged with the ocean (J/m2, >0 towards ocean)
-      REAL(wp) ::   zEi          ! sea ice specific enthalpy (J/kg)
-      REAL(wp) ::   zEw          ! seawater specific enthalpy (J/kg)
-      REAL(wp) ::   zfmdt        ! mass flux x time step (kg/m2, >0 towards ocean)
-     
-      REAL(wp) ::   zv_newfra
-      REAL(wp) ::   zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b ! conservation check
-  
-      INTEGER , DIMENSION(jpij) ::   jcat        ! indexes of categories where new ice grows
-      REAL(wp), DIMENSION(jpij) ::   zswinew     ! switch for new ice or not
-
-      REAL(wp), DIMENSION(jpij) ::   zv_newice   ! volume of accreted ice
-      REAL(wp), DIMENSION(jpij) ::   za_newice   ! fractional area of accreted ice
-      REAL(wp), DIMENSION(jpij) ::   zh_newice   ! thickness of accreted ice
-      REAL(wp), DIMENSION(jpij) ::   ze_newice   ! heat content of accreted ice
-      REAL(wp), DIMENSION(jpij) ::   zs_newice   ! salinity of accreted ice
-      REAL(wp), DIMENSION(jpij) ::   zo_newice   ! age of accreted ice
-      REAL(wp), DIMENSION(jpij) ::   zdv_res     ! residual volume in case of excessive heat budget
-      REAL(wp), DIMENSION(jpij) ::   zda_res     ! residual area in case of excessive heat budget
-      REAL(wp), DIMENSION(jpij) ::   zat_i_1d    ! total ice fraction    
-      REAL(wp), DIMENSION(jpij) ::   zv_frazb    ! accretion of frazil ice at the ice bottom
-      REAL(wp), DIMENSION(jpij) ::   zvrel_1d    ! relative ice / frazil velocity (1D vector)
-
-      REAL(wp), DIMENSION(jpij,jpl) ::   zv_b      ! old volume of ice in category jl
-      REAL(wp), DIMENSION(jpij,jpl) ::   za_b      ! old area of ice in category jl
-      REAL(wp), DIMENSION(jpij,jpl) ::   za_i_1d   ! 1-D version of a_i
-      REAL(wp), DIMENSION(jpij,jpl) ::   zv_i_1d   ! 1-D version of v_i
-      REAL(wp), DIMENSION(jpij,jpl) ::   zsmv_i_1d ! 1-D version of smv_i
-
-      REAL(wp), DIMENSION(jpij,nlay_i,jpl) ::   ze_i_1d !: 1-D version of e_i
-
-      REAL(wp), DIMENSION(jpi,jpj) ::   zvrel     ! relative ice / frazil velocity
-
-      REAL(wp) :: zcai = 1.4e-3_wp                     ! ice-air drag (clem: should be dependent on coupling/forcing used)
-      !!-----------------------------------------------------------------------!
-
-      IF( ln_limdiachk ) CALL ice_cons_hsm(0, 'limthd_lac', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      CALL lim_var_agg(1)
-      CALL lim_var_glo2eqv
-
-      !------------------------------------------------------------------------------!
-      ! 3) Collection thickness of ice formed in leads and polynyas
-      !------------------------------------------------------------------------------!    
-      ! hicol is the thickness of new ice formed in open water
-      ! hicol can be either prescribed (frazswi = 0) or computed (frazswi = 1)
-      ! Frazil ice forms in open water, is transported by wind
-      ! accumulates at the edge of the consolidated ice edge
-      ! where it forms aggregates of a specific thickness called
-      ! collection thickness.
-
-      ! Note : the following algorithm currently breaks vectorization
-      ! 
-
-      zvrel(:,:) = 0._wp
-
-      ! Default new ice thickness
-      WHERE( qlead(:,:) < 0._wp ) ; hicol(:,:) = rn_hnewice
-      ELSEWHERE                   ; hicol(:,:) = 0._wp
-      END WHERE
-
-      IF( ln_frazil ) THEN
-
-         !--------------------
-         ! Physical constants
-         !--------------------
-         hicol(:,:) = 0._wp
-
-         zhicrit = 0.04 ! frazil ice thickness
-         ztwogp  = 2. * rau0 / ( grav * 0.3 * ( rau0 - rhoic ) ) ! reduced grav
-         zsqcd   = 1.0 / SQRT( 1.3 * zcai ) ! 1/SQRT(airdensity*drag)
-         zgamafr = 0.03
-
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1
-               IF ( qlead(ji,jj) < 0._wp .AND. tau_icebfr(ji,jj) == 0._wp ) THEN ! activated if cooling and no landfast
-                  !-------------
-                  ! Wind stress
-                  !-------------
-                  ! C-grid wind stress components
-                  ztaux         = ( utau_ice(ji-1,jj  ) * umask(ji-1,jj  ,1)   &
-                     &          +   utau_ice(ji  ,jj  ) * umask(ji  ,jj  ,1) ) * 0.5_wp
-                  ztauy         = ( vtau_ice(ji  ,jj-1) * vmask(ji  ,jj-1,1)   &
-                     &          +   vtau_ice(ji  ,jj  ) * vmask(ji  ,jj  ,1) ) * 0.5_wp
-                  ! Square root of wind stress
-                  ztenagm       =  SQRT( SQRT( ztaux * ztaux + ztauy * ztauy ) )
-
-                  !---------------------
-                  ! Frazil ice velocity
-                  !---------------------
-                  rswitch = MAX( 0._wp, SIGN( 1._wp , ztenagm - epsi10 ) )
-                  zvfrx   = rswitch * zgamafr * zsqcd * ztaux / MAX( ztenagm, epsi10 )
-                  zvfry   = rswitch * zgamafr * zsqcd * ztauy / MAX( ztenagm, epsi10 )
-
-                  !-------------------
-                  ! Pack ice velocity
-                  !-------------------
-                  ! C-grid ice velocity
-                  zvgx    = ( u_ice(ji-1,jj  ) * umask(ji-1,jj  ,1)  + u_ice(ji,jj) * umask(ji,jj,1) ) * 0.5_wp
-                  zvgy    = ( v_ice(ji  ,jj-1) * vmask(ji  ,jj-1,1)  + v_ice(ji,jj) * vmask(ji,jj,1) ) * 0.5_wp
-
-                  !-----------------------------------
-                  ! Relative frazil/pack ice velocity
-                  !-----------------------------------
-                  ! absolute relative velocity
-                  rswitch      = MAX( 0._wp, SIGN( 1._wp , at_i(ji,jj) - epsi10 ) )
-                  zvrel2       = MAX(  ( zvfrx - zvgx ) * ( zvfrx - zvgx )   &
-                     &               + ( zvfry - zvgy ) * ( zvfry - zvgy ) , 0.15 * 0.15 ) * rswitch
-                  zvrel(ji,jj) = SQRT( zvrel2 )
-
-                  !---------------------
-                  ! Iterative procedure
-                  !---------------------
-                  hicol(ji,jj) = zhicrit +   ( zhicrit + 0.1 )    &
-                     &                   / ( ( zhicrit + 0.1 ) * ( zhicrit + 0.1 ) -  zhicrit * zhicrit ) * ztwogp * zvrel2
-
-                  iter = 1
-                  DO WHILE ( iter < 20 ) 
-                     zf  = ( hicol(ji,jj) - zhicrit ) * ( hicol(ji,jj) * hicol(ji,jj) - zhicrit * zhicrit ) -   &
-                        &    hicol(ji,jj) * zhicrit * ztwogp * zvrel2
-                     zfp = ( hicol(ji,jj) - zhicrit ) * ( 3.0 * hicol(ji,jj) + zhicrit ) - zhicrit * ztwogp * zvrel2
-
-                     hicol(ji,jj) = hicol(ji,jj) - zf / MAX( zfp, epsi20 )
-                     iter = iter + 1
-                  END DO
-
-               ENDIF ! end of selection of pixels where ice forms
-
-            END DO 
-         END DO 
-         ! 
-         CALL lbc_lnk_multi( zvrel, 'T', 1., hicol, 'T', 1.  )
-
-      ENDIF ! End of computation of frazil ice collection thickness
-
-      !------------------------------------------------------------------------------!
-      ! 4) Identify grid points where new ice forms
-      !------------------------------------------------------------------------------!
-
-      !-------------------------------------
-      ! Select points for new ice formation
-      !-------------------------------------
-      ! This occurs if open water energy budget is negative (cooling) and there is no landfast ice
-      nidx = 0 ; idxice(:) = 0
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF ( qlead(ji,jj)  <  0._wp .AND. tau_icebfr(ji,jj) == 0._wp ) THEN
-               nidx = nidx + 1
-               idxice( nidx ) = (jj - 1) * jpi + ji
-            ENDIF
-         END DO
-      END DO
-
-      !------------------------------
-      ! Move from 2-D to 1-D vectors
-      !------------------------------
-      ! If ocean gains heat do nothing. Otherwise compute new ice formation
-
-      IF ( nidx > 0 ) THEN
-
-         CALL tab_2d_1d( nidx, idxice(1:nidx), zat_i_1d  (1:nidx)     , at_i           )
-         DO jl = 1, jpl
-            CALL tab_2d_1d( nidx, idxice(1:nidx), za_i_1d  (1:nidx,jl), a_i  (:,:,jl)  )
-            CALL tab_2d_1d( nidx, idxice(1:nidx), zv_i_1d  (1:nidx,jl), v_i  (:,:,jl)  )
-            CALL tab_2d_1d( nidx, idxice(1:nidx), zsmv_i_1d(1:nidx,jl), smv_i(:,:,jl)  )
-            DO jk = 1, nlay_i
-               CALL tab_2d_1d( nidx, idxice(1:nidx), ze_i_1d(1:nidx,jk,jl), e_i(:,:,jk,jl)   )
-            END DO
-         END DO
-
-         CALL tab_2d_1d( nidx, idxice(1:nidx), qlead_1d  (1:nidx)     , qlead       )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), t_bo_1d   (1:nidx)     , t_bo        )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), sfx_opw_1d(1:nidx)     , sfx_opw     )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), wfx_opw_1d(1:nidx)     , wfx_opw     )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), hicol_1d  (1:nidx)     , hicol       )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), zvrel_1d  (1:nidx)     , zvrel       )
-
-         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_thd_1d(1:nidx)     , hfx_thd     )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), hfx_opw_1d(1:nidx)     , hfx_opw     )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), rn_amax_1d(1:nidx)     , rn_amax_2d  )
-         CALL tab_2d_1d( nidx, idxice(1:nidx), sss_1d    (1:nidx)     , sss_m       )
-
-         !------------------------------------------------------------------------------|
-         ! 2) Convert units for ice internal energy
-         !------------------------------------------------------------------------------|
-         DO jl = 1, jpl
-            DO jk = 1, nlay_i
-               DO ji = 1, nidx
-                  IF( zv_i_1d(ji,jl) > 0._wp )   ze_i_1d(ji,jk,jl) = ze_i_1d(ji,jk,jl) / zv_i_1d(ji,jl) * REAL( nlay_i )
-               END DO
-            END DO
-         END DO
-         !------------------------------------------------------------------------------!
-         ! 5) Compute thickness, salinity, enthalpy, age, area and volume of new ice
-         !------------------------------------------------------------------------------!
-
-         !-----------------------------------------
-         ! Keep old ice areas and volume in memory
-         !-----------------------------------------
-         zv_b(1:nidx,:) = zv_i_1d(1:nidx,:) 
-         za_b(1:nidx,:) = za_i_1d(1:nidx,:)
-
-         !----------------------
-         ! Thickness of new ice
-         !----------------------
-         zh_newice(1:nidx) = hicol_1d(1:nidx)
-
-         !----------------------
-         ! Salinity of new ice 
-         !----------------------
-         SELECT CASE ( nn_icesal )
-         CASE ( 1 )                    ! Sice = constant 
-            zs_newice(1:nidx) = rn_icesal
-         CASE ( 2 )                    ! Sice = F(z,t) [Vancoppenolle et al (2005)]
-            DO ji = 1, nidx
-               zs_newice(ji) = MIN(  4.606 + 0.91 / zh_newice(ji) , rn_simax , 0.5 * sss_1d(ji) )
-            END DO
-         CASE ( 3 )                    ! Sice = F(z) [multiyear ice]
-            zs_newice(1:nidx) =   2.3
-         END SELECT
-
-         !-------------------------
-         ! Heat content of new ice
-         !-------------------------
-         ! We assume that new ice is formed at the seawater freezing point
-         DO ji = 1, nidx
-            ztmelts       = - tmut * zs_newice(ji) + rt0                  ! Melting point (K)
-            ze_newice(ji) =   rhoic * (  cpic * ( ztmelts - t_bo_1d(ji) )                                         &
-               &                       + lfus * ( 1.0 - ( ztmelts - rt0 ) / MIN( t_bo_1d(ji) - rt0, -epsi10 ) )   &
-               &                       - rcp  *         ( ztmelts - rt0 )  )
-         END DO
-
-         !----------------
-         ! Age of new ice
-         !----------------
-         DO ji = 1, nidx
-            zo_newice(ji) = 0._wp
-         END DO
-
-         !-------------------
-         ! Volume of new ice
-         !-------------------
-         DO ji = 1, nidx
-
-            zEi           = - ze_newice(ji) * r1_rhoic             ! specific enthalpy of forming ice [J/kg]
-
-            zEw           = rcp * ( t_bo_1d(ji) - rt0 )            ! specific enthalpy of seawater at t_bo_1d [J/kg]
-                                                                   ! clem: we suppose we are already at the freezing point (condition qlead<0 is satisfyied) 
-                                                                   
-            zdE           = zEi - zEw                              ! specific enthalpy difference [J/kg]
-                                              
-            zfmdt         = - qlead_1d(ji) / zdE                   ! Fm.dt [kg/m2] (<0) 
-                                                                   ! clem: we use qlead instead of zqld (limthd) because we suppose we are at the freezing point   
-            zv_newice(ji) = - zfmdt * r1_rhoic
-
-            zQm           = zfmdt * zEw                            ! heat to the ocean >0 associated with mass flux  
-
-            ! Contribution to heat flux to the ocean [W.m-2], >0  
-            hfx_thd_1d(ji) = hfx_thd_1d(ji) + zfmdt * zEw * r1_rdtice
-            ! Total heat flux used in this process [W.m-2]  
-            hfx_opw_1d(ji) = hfx_opw_1d(ji) - zfmdt * zdE * r1_rdtice
-            ! mass flux
-            wfx_opw_1d(ji) = wfx_opw_1d(ji) - zv_newice(ji) * rhoic * r1_rdtice
-            ! salt flux
-            sfx_opw_1d(ji) = sfx_opw_1d(ji) - zv_newice(ji) * rhoic * zs_newice(ji) * r1_rdtice
-         END DO
-         
-         zv_frazb(:) = 0._wp
-         IF( ln_frazil ) THEN
-            ! A fraction zfrazb of frazil ice is accreted at the ice bottom
-            DO ji = 1, nidx
-               rswitch       = 1._wp - MAX( 0._wp, SIGN( 1._wp , - zat_i_1d(ji) ) )
-               zfrazb        = rswitch * ( TANH( rn_Cfrazb * ( zvrel_1d(ji) - rn_vfrazb ) ) + 1.0 ) * 0.5 * rn_maxfrazb
-               zv_frazb(ji)  =         zfrazb   * zv_newice(ji)
-               zv_newice(ji) = ( 1.0 - zfrazb ) * zv_newice(ji)
-            END DO
-         END IF
-         
-         !-----------------
-         ! Area of new ice
-         !-----------------
-         DO ji = 1, nidx
-            za_newice(ji) = zv_newice(ji) / zh_newice(ji)
-         END DO
-
-         !------------------------------------------------------------------------------!
-         ! 6) Redistribute new ice area and volume into ice categories                  !
-         !------------------------------------------------------------------------------!
-
-         !------------------------
-         ! 6.1) lateral ice growth
-         !------------------------
-         ! If lateral ice growth gives an ice concentration gt 1, then
-         ! we keep the excessive volume in memory and attribute it later to bottom accretion
-         DO ji = 1, nidx
-            IF ( za_newice(ji) >  ( rn_amax_1d(ji) - zat_i_1d(ji) ) ) THEN
-               zda_res(ji)   = za_newice(ji) - ( rn_amax_1d(ji) - zat_i_1d(ji) )
-               zdv_res(ji)   = zda_res  (ji) * zh_newice(ji) 
-               za_newice(ji) = za_newice(ji) - zda_res  (ji)
-               zv_newice(ji) = zv_newice(ji) - zdv_res  (ji)
-            ELSE
-               zda_res(ji) = 0._wp
-               zdv_res(ji) = 0._wp
-            ENDIF
-         END DO
-
-         ! find which category to fill
-         zat_i_1d(:) = 0._wp
-         DO jl = 1, jpl
-            DO ji = 1, nidx
-               IF( zh_newice(ji) > hi_max(jl-1) .AND. zh_newice(ji) <= hi_max(jl) ) THEN
-                  za_i_1d (ji,jl) = za_i_1d (ji,jl) + za_newice(ji)
-                  zv_i_1d (ji,jl) = zv_i_1d (ji,jl) + zv_newice(ji)
-                  jcat    (ji)    = jl
-               ENDIF
-               zat_i_1d(ji) = zat_i_1d(ji) + za_i_1d  (ji,jl)
-            END DO
-         END DO
-
-         ! Heat content
-         DO ji = 1, nidx
-            jl = jcat(ji)                                                    ! categroy in which new ice is put
-            zswinew  (ji) = MAX( 0._wp , SIGN( 1._wp , - za_b(ji,jl) ) )   ! 0 if old ice
-         END DO
-
-         DO jk = 1, nlay_i
-            DO ji = 1, nidx
-               jl = jcat(ji)
-               rswitch = MAX( 0._wp, SIGN( 1._wp , zv_i_1d(ji,jl) - epsi20 ) )
-               ze_i_1d(ji,jk,jl) = zswinew(ji)   *   ze_newice(ji) +                                                    &
-                  &        ( 1.0 - zswinew(ji) ) * ( ze_newice(ji) * zv_newice(ji) + ze_i_1d(ji,jk,jl) * zv_b(ji,jl) )  &
-                  &        * rswitch / MAX( zv_i_1d(ji,jl), epsi20 )
-            END DO
-         END DO
-
-         !------------------------------------------------
-         ! 6.2) bottom ice growth + ice enthalpy remapping
-         !------------------------------------------------
-         DO jl = 1, jpl
-
-            ! for remapping
-            h_i_old (1:nidx,0:nlay_i+1) = 0._wp
-            eh_i_old(1:nidx,0:nlay_i+1) = 0._wp
-            DO jk = 1, nlay_i
-               DO ji = 1, nidx
-                  h_i_old (ji,jk) = zv_i_1d(ji,jl) * r1_nlay_i
-                  eh_i_old(ji,jk) = ze_i_1d(ji,jk,jl) * h_i_old(ji,jk)
-               END DO
-            END DO
-
-            ! new volumes including lateral/bottom accretion + residual
-            DO ji = 1, nidx
-               rswitch        = MAX( 0._wp, SIGN( 1._wp , zat_i_1d(ji) - epsi20 ) )
-               zv_newfra      = rswitch * ( zdv_res(ji) + zv_frazb(ji) ) * za_i_1d(ji,jl) / MAX( zat_i_1d(ji) , epsi20 )
-               za_i_1d(ji,jl) = rswitch * za_i_1d(ji,jl)               
-               zv_i_1d(ji,jl) = zv_i_1d(ji,jl) + zv_newfra
-               ! for remapping
-               h_i_old (ji,nlay_i+1) = zv_newfra
-               eh_i_old(ji,nlay_i+1) = ze_newice(ji) * zv_newfra
-            ENDDO
-            ! --- Ice enthalpy remapping --- !
-            CALL lim_thd_ent( ze_i_1d(1:nidx,:,jl) ) 
-         ENDDO
-
-         !-----------------
-         ! Update salinity
-         !-----------------
-         DO jl = 1, jpl
-            DO ji = 1, nidx
-               zdv   = zv_i_1d(ji,jl) - zv_b(ji,jl)
-               zsmv_i_1d(ji,jl) = zsmv_i_1d(ji,jl) + zdv * zs_newice(ji)
-            END DO
-         END DO
-
-         !------------------------------------------------------------------------------!
-         ! 8) Change units for e_i
-         !------------------------------------------------------------------------------!    
-         DO jl = 1, jpl
-            DO jk = 1, nlay_i
-               DO ji = 1, nidx
-                  ze_i_1d(ji,jk,jl) = ze_i_1d(ji,jk,jl) * zv_i_1d(ji,jl) * r1_nlay_i 
-               END DO
-            END DO
-         END DO
-         !------------------------------------------------------------------------------!
-         ! 7) Change 2D vectors to 1D vectors 
-         !------------------------------------------------------------------------------!
-         DO jl = 1, jpl
-            CALL tab_1d_2d( nidx, idxice(1:nidx), za_i_1d (1:nidx,jl), a_i (:,:,jl)  )
-            CALL tab_1d_2d( nidx, idxice(1:nidx), zv_i_1d (1:nidx,jl), v_i (:,:,jl)  )
-            CALL tab_1d_2d( nidx, idxice(1:nidx), zsmv_i_1d(1:nidx,jl), smv_i (:,:,jl)   )
-            DO jk = 1, nlay_i
-               CALL tab_1d_2d( nidx, idxice(1:nidx), ze_i_1d(1:nidx,jk,jl), e_i(:,:,jk,jl)  )
-            END DO
-         END DO
-         CALL tab_1d_2d( nidx, idxice(1:nidx), sfx_opw_1d(1:nidx), sfx_opw  )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), wfx_opw_1d(1:nidx), wfx_opw  )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_thd_1d(1:nidx), hfx_thd  )
-         CALL tab_1d_2d( nidx, idxice(1:nidx), hfx_opw_1d(1:nidx), hfx_opw  )
-         !
-      ENDIF ! nidx > 0
-      !
-      IF( ln_limdiachk ) CALL ice_cons_hsm(1, 'limthd_lac', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-      !
-   END SUBROUTINE lim_thd_lac
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                               NO  LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE lim_thd_lac           ! Empty routine
-   END SUBROUTINE lim_thd_lac
-#endif
-
-   !!======================================================================
-END MODULE limthd_lac
Index: anches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limthd_sal.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limthd_sal.F90	(revision 8421)
+++ 	(revision )
@@ -1,157 +1,0 @@
-MODULE limthd_sal
-   !!======================================================================
-   !!                       ***  MODULE limthd_sal ***
-   !! LIM-3 sea-ice :  computation of salinity variations in the ice
-   !!======================================================================
-   !! History :   -   ! 2003-05 (M. Vancoppenolle) UCL-ASTR first coding for LIM3-1D
-   !!            3.0  ! 2005-12 (M. Vancoppenolle) adapted to the 3-D version
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
-   !!---------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!   lim_thd_sal   : salinity variations in the ice
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-   USE phycst         ! physical constants (ocean directory)
-   USE ice            ! LIM variables
-   USE ice1D          ! LIM thermodynamics
-   USE limvar         ! LIM variables
-   !
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   lim_thd_sal        ! called by limthd module
-   PUBLIC   lim_thd_sal_init   ! called by ice_init
-
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id$
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE lim_thd_sal
-      !!-------------------------------------------------------------------
-      !!                ***  ROUTINE lim_thd_sal  ***    
-      !!   
-      !! ** Purpose :   computes new salinities in the ice
-      !!
-      !! ** Method  :  3 possibilities
-      !!               -> nn_icesal = 1 -> Sice = cst    [ice salinity constant in both time & space] 
-      !!               -> nn_icesal = 2 -> Sice = S(z,t) [Vancoppenolle et al. 2005]
-      !!               -> nn_icesal = 3 -> Sice = S(z)   [multiyear ice]
-      !!---------------------------------------------------------------------
-      INTEGER  ::   ji, jk                       ! dummy loop indices 
-      REAL(wp) ::   iflush, igravdr              ! local scalars
-      REAL(wp) ::   zs_sni, zsm_i_gd, zsm_i_fl, zsm_i_si, zsm_i_bg   ! local scalars
-      !!---------------------------------------------------------------------
-
-      !--------------------------------------------------------------------|
-      ! 1) salinity constant in time                                       |
-      !--------------------------------------------------------------------|
-      ! do nothing
-
-      !----------------------------------------------------------------------|
-      !  2) salinity varying in time                                         |
-      !----------------------------------------------------------------------|
-      IF(  nn_icesal == 2  ) THEN
-
-         DO ji = 1, nidx
-
-            !---------------------------------------------------------
-            !  Update ice salinity from snow-ice and bottom growth
-            !---------------------------------------------------------
-            zs_sni   = sss_1d(ji) * ( rhoic - rhosn ) * r1_rhoic   ! Salinity of snow ice
-            rswitch  = MAX( 0._wp , SIGN( 1._wp , ht_i_1d(ji) - epsi20 ) )
-            zsm_i_si = ( zs_sni      - sm_i_1d(ji) ) *             dh_snowice(ji)  / MAX( ht_i_1d(ji), epsi20 ) * rswitch ! snow-ice    
-            zsm_i_bg = ( s_i_new(ji) - sm_i_1d(ji) ) * MAX( 0._wp, dh_i_bott(ji) ) / MAX( ht_i_1d(ji), epsi20 ) * rswitch ! bottom growth
-
-            ! Update salinity (nb: salt flux already included in limthd_dh)
-            sm_i_1d(ji) = sm_i_1d(ji) + zsm_i_bg + zsm_i_si
-
-            IF( ln_limdS ) THEN
-               !---------------------------------------------------------
-               !  Update ice salinity from brine drainage and flushing
-               !---------------------------------------------------------
-               iflush   = MAX( 0._wp , SIGN( 1._wp , t_su_1d(ji) - rt0         ) )  ! =1 if summer 
-               igravdr  = MAX( 0._wp , SIGN( 1._wp , t_bo_1d(ji) - t_su_1d(ji) ) )  ! =1 if t_su < t_bo
-               zsm_i_gd = - igravdr * MAX( sm_i_1d(ji) - rn_sal_gd , 0._wp ) / rn_time_gd * rdt_ice  ! gravity drainage 
-               zsm_i_fl = - iflush  * MAX( sm_i_1d(ji) - rn_sal_fl , 0._wp ) / rn_time_fl * rdt_ice  ! flushing
-               
-               ! Update salinity   
-               sm_i_1d(ji) = sm_i_1d(ji) + zsm_i_fl + zsm_i_gd
-               
-               ! Salt flux
-               sfx_bri_1d(ji) = sfx_bri_1d(ji) - rhoic * a_i_1d(ji) * ht_i_1d(ji) * ( zsm_i_fl + zsm_i_gd ) * r1_rdtice
-            ENDIF
-         END DO
-
-         ! Salinity profile
-         CALL lim_var_salprof1d
-         !
-      ENDIF 
-
-      !------------------------------------------------------------------------------|
-      !  3) vertical profile of salinity, constant in time                           |
-      !------------------------------------------------------------------------------|
-      IF(  nn_icesal == 3  )   CALL lim_var_salprof1d
-
-      !
-   END SUBROUTINE lim_thd_sal
-
-
-   SUBROUTINE lim_thd_sal_init
-      !!-------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_thd_sal_init  ***
-      !!
-      !! ** Purpose :   initialization of ice salinity parameters
-      !!
-      !! ** Method  :   Read the namicesal namelist and check the parameter
-      !!              values called at the first timestep (nit000)
-      !!
-      !! ** input   :   Namelist namicesal
-      !!-------------------------------------------------------------------
-      INTEGER  ::   ios                 ! Local integer output status for namelist read
-      NAMELIST/namicesal/ ln_limdS, nn_icesal, rn_icesal, rn_sal_gd, rn_time_gd,   &
-         &                rn_sal_fl, rn_time_fl, rn_simax, rn_simin 
-      !!-------------------------------------------------------------------
-      !
-      REWIND( numnam_ice_ref )              ! Namelist namicesal in reference namelist : Ice salinity
-      READ  ( numnam_ice_ref, namicesal, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicesal in reference namelist', lwp )
-
-      REWIND( numnam_ice_cfg )              ! Namelist namicesal in configuration namelist : Ice salinity
-      READ  ( numnam_ice_cfg, namicesal, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicesal in configuration namelist', lwp )
-      IF(lwm) WRITE ( numoni, namicesal )
-      !
-      IF(lwp) THEN                           ! control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'lim_thd_sal_init : Ice parameters for salinity '
-         WRITE(numout,*) '~~~~~~~~~~~~~~~~'
-         WRITE(numout,*) '   activate gravity drainage and flushing (T) or not (F)   ln_limdS   = ', ln_limdS
-         WRITE(numout,*) '   switch for salinity                                     nn_icesal  = ', nn_icesal
-         WRITE(numout,*) '   bulk salinity value if nn_icesal = 1                    rn_icesal  = ', rn_icesal
-         WRITE(numout,*) '   restoring salinity for gravity drainage                 rn_sal_gd  = ', rn_sal_gd
-         WRITE(numout,*) '   restoring time for for gravity drainage                 rn_time_gd = ', rn_time_gd
-         WRITE(numout,*) '   restoring salinity for flushing                         rn_sal_fl  = ', rn_sal_fl
-         WRITE(numout,*) '   restoring time for flushing                             rn_time_fl = ', rn_time_fl
-         WRITE(numout,*) '   Maximum tolerated ice salinity                          rn_simax   = ', rn_simax
-         WRITE(numout,*) '   Minimum tolerated ice salinity                          rn_simin   = ', rn_simin
-      ENDIF
-      !
-   END SUBROUTINE lim_thd_sal_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Dummy Module          No LIM-3 sea-ice model
-   !!----------------------------------------------------------------------
-#endif
-   !!======================================================================
-END MODULE limthd_sal
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limvar.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limvar.F90	(revision 8421)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limvar.F90	(revision 8422)
@@ -431,5 +431,5 @@
    SUBROUTINE lim_var_salprof1d
       !!-------------------------------------------------------------------
-      !!                  ***  ROUTINE lim_thd_salprof1d  ***
+      !!                  ***  ROUTINE lim_var_salprof1d  ***
       !!
       !! ** Purpose :   1d computation of the sea ice salinity profile
@@ -760,5 +760,5 @@
                zht_s(ji,jl) = zht_i(ji,jl) * ( zhts(ji) / zhti(ji) )
                ! In case snow load is in excess that would lead to transformation from snow to ice
-               ! Then, transfer the snow excess into the ice (different from limthd_dh)
+               ! Then, transfer the snow excess into the ice (different from icethd_dh)
                zdh = MAX( 0._wp, ( rhosn * zht_s(ji,jl) + ( rhoic - rau0 ) * zht_i(ji,jl) ) * r1_rau0 ) 
                ! recompute ht_i, ht_s avoiding out of bounds values
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice.F90	(revision 8421)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice.F90	(revision 8422)
@@ -119,7 +119,7 @@
             ! -----------------
             ! In case a) snow load would be in excess or b) ice is coming into a warmer environment that would lead to 
-            ! very large transformation from snow to ice (see limthd_dh.F90)
-
-            ! Then, a) transfer the snow excess into the ice (different from limthd_dh)
+            ! very large transformation from snow to ice (see icethd_dh.F90)
+
+            ! Then, a) transfer the snow excess into the ice (different from icethd_dh)
             zdh = MAX( 0._wp, ( rhosn * ht_s(ji,jj,jl) + ( rhoic - rau0 ) * ht_i(ji,jj,jl) ) * r1_rau0 )
             ! Or, b) transfer all the snow into ice (if incoming ice is likely to melt as it comes into a warmer environment)
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 8421)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/OPA_SRC/LBC/lib_mpp.F90	(revision 8422)
@@ -145,5 +145,5 @@
 
    ! variables used in case of sea-ice
-   INTEGER, PUBLIC ::   ncomm_ice       !: communicator made by the processors with sea-ice (public so that it can be freed in limthd)
+   INTEGER, PUBLIC ::   ncomm_ice       !: communicator made by the processors with sea-ice (public so that it can be freed in icethd)
    INTEGER         ::   ngrp_iworld     !  group ID for the world processors (for rheology)
    INTEGER         ::   ngrp_ice        !  group ID for the ice processors (for rheology)
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk.F90	(revision 8421)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk.F90	(revision 8422)
@@ -41,5 +41,5 @@
 #if defined key_lim3
    USE ice     , ONLY :   u_ice, v_ice, jpl, a_i_b, at_i_b
-   USE limthd_dh      ! for CALL lim_thd_snwblow
+   USE icethd_dh      ! for CALL ice_thd_snwblow
 #endif
    USE sbcblk_algo_ncar     ! => turb_ncar     : NCAR - CORE (Large & Yeager, 2009) 
@@ -789,5 +789,5 @@
       ! --- evaporation minus precipitation --- !
       zsnw(:,:) = 0._wp
-      CALL lim_thd_snwblow( (1.-at_i_b(:,:)), zsnw )  ! snow distribution over ice after wind blowing
+      CALL ice_thd_snwblow( (1.-at_i_b(:,:)), zsnw )  ! snow distribution over ice after wind blowing
       emp_oce(:,:) = ( 1._wp - at_i_b(:,:) ) * zevap(:,:) - ( tprecip(:,:) - sprecip(:,:) ) - sprecip(:,:) * (1._wp - zsnw )
       emp_ice(:,:) = SUM( a_i_b(:,:,:) * evap_ice(:,:,:), dim=3 ) - sprecip(:,:) * zsnw
Index: /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 8421)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 8422)
@@ -40,5 +40,5 @@
 #endif
 #if defined key_lim3
-   USE limthd_dh      ! for CALL lim_thd_snwblow
+   USE icethd_dh      ! for CALL ice_thd_snwblow
 #endif
    !
@@ -1621,5 +1621,5 @@
 #if defined key_lim3
       ! zsnw = snow fraction over ice after wind blowing (=picefr if no blowing)
-      zsnw(:,:) = 0._wp  ;  CALL lim_thd_snwblow( ziceld, zsnw )
+      zsnw(:,:) = 0._wp  ;  CALL ice_thd_snwblow( ziceld, zsnw )
       
       ! --- evaporation minus precipitation corrected (because of wind blowing on snow) --- !
