Index: branches/2014/dev_r4621_NOC4_BDY_VERT_INTERP/NEMOGCM/NEMO/LIM_SRC_3/limitd_me.F90
===================================================================
--- branches/2014/dev_r4621_NOC4_BDY_VERT_INTERP/NEMOGCM/NEMO/LIM_SRC_3/limitd_me.F90	(revision 5038)
+++ branches/2014/dev_r4621_NOC4_BDY_VERT_INTERP/NEMOGCM/NEMO/LIM_SRC_3/limitd_me.F90	(revision 5901)
@@ -18,14 +18,12 @@
    USE thd_ice          ! LIM thermodynamics
    USE ice              ! LIM variables
-   USE par_ice          ! LIM parameters
    USE dom_ice          ! LIM domain
-   USE limthd_lac       ! LIM
    USE limvar           ! LIM
-   USE in_out_manager   ! I/O manager
    USE lbclnk           ! lateral boundary condition - MPP exchanges
    USE lib_mpp          ! MPP library
    USE wrk_nemo         ! work arrays
    USE prtctl           ! Print control
-  ! Check budget (Rousset)
+
+   USE in_out_manager   ! I/O manager
    USE iom              ! I/O manager
    USE lib_fortran      ! glob_sum
@@ -40,6 +38,5 @@
    PUBLIC   lim_itd_me_icestrength
    PUBLIC   lim_itd_me_init
-   PUBLIC   lim_itd_me_zapsmall
-   PUBLIC   lim_itd_me_alloc        ! called by iceini.F90
+   PUBLIC   lim_itd_me_alloc        ! called by sbc_lim_init 
 
    !-----------------------------------------------------------------------
@@ -125,18 +122,19 @@
       !!  and Elizabeth C. Hunke, LANL are gratefully acknowledged
       !!--------------------------------------------------------------------!
-      INTEGER ::   ji, jj, jk, jl   ! dummy loop index
-      INTEGER ::   niter, nitermax = 20   ! local integer 
-      LOGICAL  ::   asum_error            ! flag for asum .ne. 1
+      INTEGER  ::   ji, jj, jk, jl        ! dummy loop index
+      INTEGER  ::   niter                 ! local integer 
       INTEGER  ::   iterate_ridging       ! if true, repeat the ridging
-      REAL(wp) ::   w1, tmpfac            ! local scalar
+      REAL(wp) ::   za, zfac              ! local scalar
       CHARACTER (len = 15) ::   fieldid
-      REAL(wp), POINTER, DIMENSION(:,:) ::   closing_net     ! net rate at which area is removed    (1/s)
-                                                             ! (ridging ice area - area of new ridges) / dt
-      REAL(wp), POINTER, DIMENSION(:,:) ::   divu_adv        ! divu as implied by transport scheme  (1/s)
-      REAL(wp), POINTER, DIMENSION(:,:) ::   opning          ! rate of opening due to divergence/shear
-      REAL(wp), POINTER, DIMENSION(:,:) ::   closing_gross   ! rate at which area removed, not counting area of new ridges
-      REAL(wp), POINTER, DIMENSION(:,:) ::   msnow_mlt       ! mass of snow added to ocean (kg m-2)
-      REAL(wp), POINTER, DIMENSION(:,:) ::   esnow_mlt       ! energy needed to melt snow in ocean (J m-2)
-      REAL(wp), POINTER, DIMENSION(:,:) ::   vt_i_init, vt_i_final  !  ice volume summed over categories
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   closing_net     ! net rate at which area is removed    (1/s)
+                                                               ! (ridging ice area - area of new ridges) / dt
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   divu_adv        ! divu as implied by transport scheme  (1/s)
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   opning          ! rate of opening due to divergence/shear
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   closing_gross   ! rate at which area removed, not counting area of new ridges
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   msnow_mlt       ! mass of snow added to ocean (kg m-2)
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   esnow_mlt       ! energy needed to melt snow in ocean (J m-2)
+      REAL(wp), POINTER, DIMENSION(:,:)   ::   vt_i_init, vt_i_final  !  ice volume summed over categories
+      !
+      INTEGER, PARAMETER ::   nitermax = 20    
       !
       REAL(wp) :: zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
@@ -144,5 +142,5 @@
       IF( nn_timing == 1 )  CALL timing_start('limitd_me')
 
-      CALL wrk_alloc( jpi, jpj, closing_net, divu_adv, opning, closing_gross, msnow_mlt, esnow_mlt, vt_i_init, vt_i_final )
+      CALL wrk_alloc( jpi,jpj, closing_net, divu_adv, opning, closing_gross, msnow_mlt, esnow_mlt, vt_i_init, vt_i_final )
 
       IF(ln_ctl) THEN
@@ -156,8 +154,11 @@
       IF( ln_limdiahsb ) CALL lim_cons_hsm(0, 'limitd_me', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
 
+      CALL lim_var_zapsmall
+      CALL lim_var_glo2eqv            ! equivalent variables, requested for rafting
+
       !-----------------------------------------------------------------------------!
       ! 1) Thickness categories boundaries, ice / o.w. concentrations, init_ons
       !-----------------------------------------------------------------------------!
-      Cp = 0.5 * grav * (rau0-rhoic) * rhoic / rau0                ! proport const for PE
+      Cp = 0.5 * grav * (rau0-rhoic) * rhoic * r1_rau0             ! proport const for PE
       !
       CALL lim_itd_me_ridgeprep                                    ! prepare ridging
@@ -193,5 +194,5 @@
             !  (thick, newly ridged ice).
 
-            closing_net(ji,jj) = Cs * 0.5 * ( Delta_i(ji,jj) - ABS( divu_i(ji,jj) ) ) - MIN( divu_i(ji,jj), 0._wp )
+            closing_net(ji,jj) = rn_cs * 0.5 * ( delta_i(ji,jj) - ABS( divu_i(ji,jj) ) ) - MIN( divu_i(ji,jj), 0._wp )
 
             ! 2.2 divu_adv
@@ -237,15 +238,13 @@
                ! Reduce the closing rate if more than 100% of the open water 
                ! would be removed.  Reduce the opening rate proportionately.
-               IF ( ato_i(ji,jj) .GT. epsi10 .AND. athorn(ji,jj,0) .GT. 0.0 ) THEN
-                  w1 = athorn(ji,jj,0) * closing_gross(ji,jj) * rdt_ice
-                  IF ( w1 .GT. ato_i(ji,jj)) THEN
-                     tmpfac = ato_i(ji,jj) / w1
-                     closing_gross(ji,jj) = closing_gross(ji,jj) * tmpfac
-                     opning(ji,jj) = opning(ji,jj) * tmpfac
-                  ENDIF !w1
-               ENDIF !at0i and athorn
-
-            END DO ! ji
-         END DO ! jj
+               za   = athorn(ji,jj,0) * closing_gross(ji,jj) * rdt_ice
+               IF( za > epsi20 ) THEN
+                  zfac = MIN( 1._wp, ato_i(ji,jj) / za )
+                  closing_gross(ji,jj) = closing_gross(ji,jj) * zfac
+                  opning       (ji,jj) = opning       (ji,jj) * zfac
+               ENDIF
+
+            END DO
+         END DO
 
          ! correction to closing rate / opening if excessive ice removal
@@ -253,19 +252,16 @@
          ! Reduce the closing rate if more than 100% of any ice category 
          ! would be removed.  Reduce the opening rate proportionately.
-
          DO jl = 1, jpl
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  IF ( a_i(ji,jj,jl) > epsi10 .AND. athorn(ji,jj,jl) > 0._wp )THEN
-                     w1 = athorn(ji,jj,jl) * closing_gross(ji,jj) * rdt_ice
-                     IF ( w1  >  a_i(ji,jj,jl) ) THEN
-                        tmpfac = a_i(ji,jj,jl) / w1
-                        closing_gross(ji,jj) = closing_gross(ji,jj) * tmpfac
-                        opning       (ji,jj) = opning       (ji,jj) * tmpfac
-                     ENDIF
+                  za = athorn(ji,jj,jl) * closing_gross(ji,jj) * rdt_ice
+                  IF( za  >  epsi20 ) THEN
+                     zfac = MIN( 1._wp, a_i(ji,jj,jl) / za )
+                     closing_gross(ji,jj) = closing_gross(ji,jj) * zfac
+                     opning       (ji,jj) = opning       (ji,jj) * zfac
                   ENDIF
-               END DO !ji
-            END DO ! jj
-         END DO !jl
+               END DO
+            END DO
+         END DO
 
          ! 3.3 Redistribute area, volume, and energy.
@@ -276,6 +272,9 @@
          ! 3.4 Compute total area of ice plus open water after ridging.
          !-----------------------------------------------------------------------------!
-
-         CALL lim_itd_me_asumr
+         ! This is in general not equal to one because of divergence during transport
+         asum(:,:) = ato_i(:,:)
+         DO jl = 1, jpl
+            asum(:,:) = asum(:,:) + a_i(:,:,jl)
+         END DO
 
          ! 3.5 Do we keep on iterating ???
@@ -288,5 +287,5 @@
          DO jj = 1, jpj
             DO ji = 1, jpi
-               IF (ABS(asum(ji,jj) - kamax ) .LT. epsi10) THEN
+               IF (ABS(asum(ji,jj) - kamax ) < epsi10) THEN
                   closing_net(ji,jj) = 0._wp
                   opning     (ji,jj) = 0._wp
@@ -324,11 +323,6 @@
       ! Convert ridging rate diagnostics to correct units.
       ! Update fresh water and heat fluxes due to snow melt.
-
-      asum_error = .false. 
-
       DO jj = 1, jpj
          DO ji = 1, jpi
-
-            IF(ABS(asum(ji,jj) - kamax) > epsi10 ) asum_error = .true.
 
             dardg1dt(ji,jj) = dardg1dt(ji,jj) * r1_rdtice
@@ -341,5 +335,5 @@
             !-----------------------------------------------------------------------------!
             wfx_snw(ji,jj) = wfx_snw(ji,jj) + msnow_mlt(ji,jj) * r1_rdtice     ! fresh water source for ocean
-            hfx_dyn(ji,jj) = hfx_dyn(ji,jj) + esnow_mlt(ji,jj) * unit_fac / area(ji,jj) * r1_rdtice  ! heat sink for ocean (<0, W.m-2)
+            hfx_dyn(ji,jj) = hfx_dyn(ji,jj) + esnow_mlt(ji,jj) * r1_rdtice     ! heat sink for ocean (<0, W.m-2)
 
          END DO
@@ -347,20 +341,21 @@
 
       ! Check if there is a ridging error
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( ABS( asum(ji,jj) - kamax)  >  epsi10 ) THEN   ! there is a bug
-               WRITE(numout,*) ' '
-               WRITE(numout,*) ' ALERTE : Ridging error: total area = ', asum(ji,jj)
-               WRITE(numout,*) ' limitd_me '
-               WRITE(numout,*) ' POINT : ', ji, jj
-               WRITE(numout,*) ' jpl, a_i, athorn '
-               WRITE(numout,*) 0, ato_i(ji,jj), athorn(ji,jj,0)
-               DO jl = 1, jpl
-                  WRITE(numout,*) jl, a_i(ji,jj,jl), athorn(ji,jj,jl)
-               END DO
-            ENDIF  ! asum
-
-         END DO !ji
-      END DO !jj
+      IF( lwp ) THEN
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( ABS( asum(ji,jj) - kamax)  >  epsi10 ) THEN   ! there is a bug
+                  WRITE(numout,*) ' '
+                  WRITE(numout,*) ' ALERTE : Ridging error: total area = ', asum(ji,jj)
+                  WRITE(numout,*) ' limitd_me '
+                  WRITE(numout,*) ' POINT : ', ji, jj
+                  WRITE(numout,*) ' jpl, a_i, athorn '
+                  WRITE(numout,*) 0, ato_i(ji,jj), athorn(ji,jj,0)
+                  DO jl = 1, jpl
+                     WRITE(numout,*) jl, a_i(ji,jj,jl), athorn(ji,jj,jl)
+                  END DO
+               ENDIF
+            END DO
+         END DO
+      END IF
 
       ! Conservation check
@@ -371,16 +366,16 @@
       ENDIF
 
+      CALL lim_var_agg( 1 ) 
+
       !-----------------------------------------------------------------------------!
-      ! 6) Updating state variables and trend terms (done in limupdate)
+      ! control prints
       !-----------------------------------------------------------------------------!
-      CALL lim_var_glo2eqv
-      CALL lim_itd_me_zapsmall
-
-
-      IF(ln_ctl) THEN     ! Control print
+      IF(ln_ctl) THEN 
+         CALL lim_var_glo2eqv
+
          CALL prt_ctl_info(' ')
          CALL prt_ctl_info(' - Cell values : ')
          CALL prt_ctl_info('   ~~~~~~~~~~~~~ ')
-         CALL prt_ctl(tab2d_1=area , clinfo1=' lim_itd_me  : cell area :')
+         CALL prt_ctl(tab2d_1=e1e2t, clinfo1=' lim_itd_me  : cell area :')
          CALL prt_ctl(tab2d_1=at_i , clinfo1=' lim_itd_me  : at_i      :')
          CALL prt_ctl(tab2d_1=vt_i , clinfo1=' lim_itd_me  : vt_i      :')
@@ -436,9 +431,8 @@
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kstrngth    ! = 1 for Rothrock formulation, 0 for Hibler (1979)
-
-      INTEGER ::   ji,jj, jl   ! dummy loop indices
-      INTEGER ::   ksmooth     ! smoothing the resistance to deformation
-      INTEGER ::   numts_rm    ! number of time steps for the P smoothing
-      REAL(wp) ::   hi, zw1, zp, zdummy, zzc, z1_3   ! local scalars
+      INTEGER             ::   ji,jj, jl   ! dummy loop indices
+      INTEGER             ::   ksmooth     ! smoothing the resistance to deformation
+      INTEGER             ::   numts_rm    ! number of time steps for the P smoothing
+      REAL(wp)            ::   zhi, zp, z1_3  ! local scalars
       REAL(wp), POINTER, DIMENSION(:,:) ::   zworka   ! temporary array used here
       !!----------------------------------------------------------------------
@@ -466,30 +460,29 @@
                   !
                   IF( a_i(ji,jj,jl) > epsi10 .AND. athorn(ji,jj,jl) > 0._wp ) THEN
-                     hi = v_i(ji,jj,jl) / a_i(ji,jj,jl)
+                     zhi = v_i(ji,jj,jl) / a_i(ji,jj,jl)
                      !----------------------------
                      ! PE loss from deforming ice
                      !----------------------------
-                     strength(ji,jj) = strength(ji,jj) - athorn(ji,jj,jl) * hi * hi
+                     strength(ji,jj) = strength(ji,jj) - athorn(ji,jj,jl) * zhi * zhi
 
                      !--------------------------
                      ! PE gain from rafting ice
                      !--------------------------
-                     strength(ji,jj) = strength(ji,jj) + 2._wp * araft(ji,jj,jl) * hi * hi
+                     strength(ji,jj) = strength(ji,jj) + 2._wp * araft(ji,jj,jl) * zhi * zhi
 
                      !----------------------------
                      ! PE gain from ridging ice
                      !----------------------------
-                     strength(ji,jj) = strength(ji,jj) + aridge(ji,jj,jl)/krdg(ji,jj,jl)     &
-                        * z1_3 * (hrmax(ji,jj,jl)**3 - hrmin(ji,jj,jl)**3) / ( hrmax(ji,jj,jl)-hrmin(ji,jj,jl) )   
-!!gm Optimization:  (a**3-b**3)/(a-b) = a*a+ab+b*b   ==> less costly operations even if a**3 is replaced by a*a*a...                    
-                  ENDIF            ! aicen > epsi10
+                     strength(ji,jj) = strength(ji,jj) + aridge(ji,jj,jl) / krdg(ji,jj,jl)     &
+                        * z1_3 * ( hrmax(ji,jj,jl)**2 + hrmin(ji,jj,jl)**2 +  hrmax(ji,jj,jl) * hrmin(ji,jj,jl) )  
+                        !!(a**3-b**3)/(a-b) = a*a+ab+b*b                      
+                  ENDIF
                   !
-               END DO ! ji
-            END DO !jj
-         END DO !jl
-
-         zzc = Cf * Cp     ! where Cp = (g/2)*(rhow-rhoi)*(rhoi/rhow) and Cf accounts for frictional dissipation
-         strength(:,:) = zzc * strength(:,:) / aksum(:,:)
-
+               END DO
+            END DO
+         END DO
+   
+         strength(:,:) = rn_pe_rdg * Cp * strength(:,:) / aksum(:,:)
+                         ! where Cp = (g/2)*(rhow-rhoi)*(rhoi/rhow) and rn_pe_rdg accounts for frictional dissipation
          ksmooth = 1
 
@@ -499,5 +492,5 @@
       ELSE                      ! kstrngth ne 1:  Hibler (1979) form
          !
-         strength(:,:) = Pstar * vt_i(:,:) * EXP( - C_rhg * ( 1._wp - at_i(:,:) )  )
+         strength(:,:) = rn_pstar * vt_i(:,:) * EXP( - rn_crhg * ( 1._wp - at_i(:,:) )  )
          !
          ksmooth = 1
@@ -511,16 +504,11 @@
       ! CAN BE REMOVED
       !
-      IF ( brinstren_swi == 1 ) THEN
+      IF( ln_icestr_bvf ) THEN
 
          DO jj = 1, jpj
             DO ji = 1, jpi
-               IF ( bv_i(ji,jj) .GT. 0.0 ) THEN
-                  zdummy = MIN ( bv_i(ji,jj), 0.10 ) * MIN( bv_i(ji,jj), 0.10 )
-               ELSE
-                  zdummy = 0.0
-               ENDIF
                strength(ji,jj) = strength(ji,jj) * exp(-5.88*SQRT(MAX(bv_i(ji,jj),0.0)))
-            END DO              ! j
-         END DO                 ! i
+            END DO
+         END DO
 
       ENDIF
@@ -538,16 +526,11 @@
          CALL lbc_lnk( strength, 'T', 1. )
 
-         DO jj = 2, jpj - 1
-            DO ji = 2, jpi - 1
-               IF ( ( asum(ji,jj) - ato_i(ji,jj) ) .GT. epsi10) THEN ! ice is
-                  ! present
-                  zworka(ji,jj) = 4.0 * strength(ji,jj)              &
-                     &          + strength(ji-1,jj) * tms(ji-1,jj) &  
-                     &          + strength(ji+1,jj) * tms(ji+1,jj) &  
-                     &          + strength(ji,jj-1) * tms(ji,jj-1) &  
-                     &          + strength(ji,jj+1) * tms(ji,jj+1)    
-
-                  zw1 = 4.0 + tms(ji-1,jj) + tms(ji+1,jj) + tms(ji,jj-1) + tms(ji,jj+1)
-                  zworka(ji,jj) = zworka(ji,jj) / zw1
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               IF ( ( asum(ji,jj) - ato_i(ji,jj) ) > 0._wp) THEN 
+                  zworka(ji,jj) = ( 4.0 * strength(ji,jj)              &
+                     &                  + strength(ji-1,jj) * tmask(ji-1,jj,1) + strength(ji+1,jj) * tmask(ji+1,jj,1) &  
+                     &                  + strength(ji,jj-1) * tmask(ji,jj-1,1) + strength(ji,jj+1) * tmask(ji,jj+1,1) &
+                     &            ) / ( 4.0 + tmask(ji-1,jj,1) + tmask(ji+1,jj,1) + tmask(ji,jj-1,1) + tmask(ji,jj+1,1) )
                ELSE
                   zworka(ji,jj) = 0._wp
@@ -556,6 +539,6 @@
          END DO
 
-         DO jj = 2, jpj - 1
-            DO ji = 2, jpi - 1
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
                strength(ji,jj) = zworka(ji,jj)
             END DO
@@ -563,5 +546,5 @@
          CALL lbc_lnk( strength, 'T', 1. )
 
-      ENDIF ! ksmooth
+      ENDIF
 
       !--------------------
@@ -580,8 +563,8 @@
          DO jj = 1, jpj - 1
             DO ji = 1, jpi - 1
-               IF ( ( asum(ji,jj) - ato_i(ji,jj) ) .GT. epsi10) THEN       ! ice is present
+               IF ( ( asum(ji,jj) - ato_i(ji,jj) ) > 0._wp) THEN 
                   numts_rm = 1 ! number of time steps for the running mean
-                  IF ( strp1(ji,jj) .GT. 0.0 ) numts_rm = numts_rm + 1
-                  IF ( strp2(ji,jj) .GT. 0.0 ) numts_rm = numts_rm + 1
+                  IF ( strp1(ji,jj) > 0.0 ) numts_rm = numts_rm + 1
+                  IF ( strp2(ji,jj) > 0.0 ) numts_rm = numts_rm + 1
                   zp = ( strength(ji,jj) + strp1(ji,jj) + strp2(ji,jj) ) / numts_rm
                   strp2(ji,jj) = strp1(ji,jj)
@@ -612,5 +595,5 @@
       !!---------------------------------------------------------------------!
       INTEGER ::   ji,jj, jl    ! dummy loop indices
-      REAL(wp) ::   Gstari, astari, hi, hrmean, zdummy   ! local scalar
+      REAL(wp) ::   Gstari, astari, zhi, hrmean, zdummy   ! local scalar
       REAL(wp), POINTER, DIMENSION(:,:)   ::   zworka    ! temporary array used here
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   Gsum      ! Gsum(n) = sum of areas in categories 0 to n
@@ -620,6 +603,6 @@
       CALL wrk_alloc( jpi,jpj,jpl+2, Gsum, kkstart = -1 )
 
-      Gstari     = 1.0/Gstar    
-      astari     = 1.0/astar    
+      Gstari     = 1.0/rn_gstar    
+      astari     = 1.0/rn_astar    
       aksum(:,:)    = 0.0
       athorn(:,:,:) = 0.0
@@ -632,5 +615,5 @@
 
       !     ! Zero out categories with very small areas
-      CALL lim_itd_me_zapsmall
+      CALL lim_var_zapsmall
 
       !------------------------------------------------------------------------------!
@@ -639,7 +622,9 @@
 
       ! Compute total area of ice plus open water.
-      CALL lim_itd_me_asumr
-      ! This is in general not equal to one 
-      ! because of divergence during transport
+      ! This is in general not equal to one because of divergence during transport
+      asum(:,:) = ato_i(:,:)
+      DO jl = 1, jpl
+         asum(:,:) = asum(:,:) + a_i(:,:,jl)
+      END DO
 
       ! Compute cumulative thickness distribution function
@@ -649,22 +634,9 @@
 
       Gsum(:,:,-1) = 0._wp
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( ato_i(ji,jj) > epsi10 ) THEN   ;   Gsum(ji,jj,0) = ato_i(ji,jj)
-            ELSE                               ;   Gsum(ji,jj,0) = 0._wp
-            ENDIF
-         END DO
-      END DO
+      Gsum(:,:,0 ) = ato_i(:,:)
 
       ! for each value of h, you have to add ice concentration then
       DO jl = 1, jpl
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               IF( a_i(ji,jj,jl) .GT. epsi10 ) THEN   ;   Gsum(ji,jj,jl) = Gsum(ji,jj,jl-1) + a_i(ji,jj,jl)
-               ELSE                                   ;   Gsum(ji,jj,jl) = Gsum(ji,jj,jl-1)
-               ENDIF
-            END DO
-         END DO
+         Gsum(:,:,jl) = Gsum(:,:,jl-1) + a_i(:,:,jl)
       END DO
 
@@ -687,51 +659,50 @@
       !-----------------------------------------------------------------
 
-      IF( partfun_swi == 0 ) THEN       !--- Linear formulation (Thorndike et al., 1975)
+      IF( nn_partfun == 0 ) THEN       !--- Linear formulation (Thorndike et al., 1975)
          DO jl = 0, jpl    
             DO jj = 1, jpj 
                DO ji = 1, jpi
-                  IF( Gsum(ji,jj,jl) < Gstar) THEN
-                     athorn(ji,jj,jl) = Gstari * (Gsum(ji,jj,jl)-Gsum(ji,jj,jl-1)) * &
-                        (2.0 - (Gsum(ji,jj,jl-1)+Gsum(ji,jj,jl))*Gstari)
-                  ELSEIF (Gsum(ji,jj,jl-1) < Gstar) THEN
-                     athorn(ji,jj,jl) = Gstari * (Gstar-Gsum(ji,jj,jl-1)) *  &
-                        (2.0 - (Gsum(ji,jj,jl-1)+Gstar)*Gstari)
+                  IF( Gsum(ji,jj,jl) < rn_gstar) THEN
+                     athorn(ji,jj,jl) = Gstari * ( Gsum(ji,jj,jl) - Gsum(ji,jj,jl-1) ) * &
+                        &                        ( 2.0 - (Gsum(ji,jj,jl-1) + Gsum(ji,jj,jl) ) * Gstari )
+                  ELSEIF (Gsum(ji,jj,jl-1) < rn_gstar) THEN
+                     athorn(ji,jj,jl) = Gstari * ( rn_gstar - Gsum(ji,jj,jl-1) ) *  &
+                        &                        ( 2.0 - ( Gsum(ji,jj,jl-1) + rn_gstar ) * Gstari )
                   ELSE
                      athorn(ji,jj,jl) = 0.0
                   ENDIF
-               END DO ! ji
-            END DO ! jj
-         END DO ! jl 
+               END DO
+            END DO
+         END DO
 
       ELSE                             !--- Exponential, more stable formulation (Lipscomb et al, 2007)
          !                        
          zdummy = 1._wp / ( 1._wp - EXP(-astari) )        ! precompute exponential terms using Gsum as a work array
-
          DO jl = -1, jpl
             Gsum(:,:,jl) = EXP( -Gsum(:,:,jl) * astari ) * zdummy
-         END DO !jl
+         END DO
          DO jl = 0, jpl
              athorn(:,:,jl) = Gsum(:,:,jl-1) - Gsum(:,:,jl)
          END DO
          !
-      ENDIF ! partfun_swi
-
-      IF( raft_swi == 1 ) THEN      ! Ridging and rafting ice participation functions
+      ENDIF
+
+      IF( ln_rafting ) THEN      ! Ridging and rafting ice participation functions
          !
          DO jl = 1, jpl
             DO jj = 1, jpj 
                DO ji = 1, jpi
-                  IF ( athorn(ji,jj,jl) .GT. 0._wp ) THEN
+                  IF ( athorn(ji,jj,jl) > 0._wp ) THEN
 !!gm  TANH( -X ) = - TANH( X )  so can be computed only 1 time....
-                     aridge(ji,jj,jl) = ( TANH (  Craft * ( ht_i(ji,jj,jl) - hparmeter ) ) + 1.0 ) * 0.5 * athorn(ji,jj,jl)
-                     araft (ji,jj,jl) = ( TANH ( -Craft * ( ht_i(ji,jj,jl) - hparmeter ) ) + 1.0 ) * 0.5 * athorn(ji,jj,jl)
+                     aridge(ji,jj,jl) = ( TANH (  rn_craft * ( ht_i(ji,jj,jl) - rn_hraft ) ) + 1.0 ) * 0.5 * athorn(ji,jj,jl)
+                     araft (ji,jj,jl) = ( TANH ( -rn_craft * ( ht_i(ji,jj,jl) - rn_hraft ) ) + 1.0 ) * 0.5 * athorn(ji,jj,jl)
                      IF ( araft(ji,jj,jl) < epsi06 )   araft(ji,jj,jl)  = 0._wp
                      aridge(ji,jj,jl) = MAX( athorn(ji,jj,jl) - araft(ji,jj,jl), 0.0 )
-                  ENDIF ! athorn
-               END DO ! ji
-            END DO ! jj
-         END DO ! jl
-
-      ELSE  ! raft_swi = 0
+                  ENDIF
+               END DO
+            END DO
+         END DO
+
+      ELSE
          !
          DO jl = 1, jpl
@@ -741,11 +712,11 @@
       ENDIF
 
-      IF ( raft_swi == 1 ) THEN
-
-         IF( MAXVAL(aridge + araft - athorn(:,:,1:jpl)) .GT. epsi10 ) THEN
+      IF( ln_rafting ) THEN
+
+         IF( MAXVAL(aridge + araft - athorn(:,:,1:jpl)) > epsi10 .AND. lwp ) THEN
             DO jl = 1, jpl
                DO jj = 1, jpj
                   DO ji = 1, jpi
-                     IF ( aridge(ji,jj,jl) + araft(ji,jj,jl) - athorn(ji,jj,jl) .GT. epsi10 ) THEN
+                     IF ( aridge(ji,jj,jl) + araft(ji,jj,jl) - athorn(ji,jj,jl) > epsi10 ) THEN
                         WRITE(numout,*) ' ALERTE 96 : wrong participation function ... '
                         WRITE(numout,*) ' ji, jj, jl : ', ji, jj, jl
@@ -793,11 +764,11 @@
             DO ji = 1, jpi
 
-               IF (a_i(ji,jj,jl) .GT. epsi10 .AND. athorn(ji,jj,jl) .GT. 0.0 ) THEN
-                  hi = v_i(ji,jj,jl) / a_i(ji,jj,jl)
-                  hrmean          = MAX(SQRT(Hstar*hi), hi*krdgmin)
-                  hrmin(ji,jj,jl) = MIN(2.0*hi, 0.5*(hrmean + hi))
+               IF (a_i(ji,jj,jl) > epsi10 .AND. athorn(ji,jj,jl) > 0.0 ) THEN
+                  zhi = v_i(ji,jj,jl) / a_i(ji,jj,jl)
+                  hrmean          = MAX(SQRT(rn_hstar*zhi), zhi*krdgmin)
+                  hrmin(ji,jj,jl) = MIN(2.0*zhi, 0.5*(hrmean + zhi))
                   hrmax(ji,jj,jl) = 2.0*hrmean - hrmin(ji,jj,jl)
-                  hraft(ji,jj,jl) = kraft*hi
-                  krdg(ji,jj,jl)  = hrmean / hi
+                  hraft(ji,jj,jl) = kraft*zhi
+                  krdg(ji,jj,jl)  = hrmean / zhi
                ELSE
                   hraft(ji,jj,jl) = 0.0
@@ -807,7 +778,7 @@
                ENDIF
 
-            END DO ! ji
-         END DO ! jj
-      END DO ! jl
+            END DO
+         END DO
+      END DO
 
       ! Normalization factor : aksum, ensures mass conservation
@@ -841,12 +812,8 @@
       LOGICAL, PARAMETER ::   l_conservation_check = .true.  ! if true, check conservation (useful for debugging)
       !
-      LOGICAL ::   neg_ato_i      ! flag for ato_i(i,j) < -puny
-      LOGICAL ::   large_afrac    ! flag for afrac > 1
-      LOGICAL ::   large_afrft    ! flag for afrac > 1
       INTEGER ::   ji, jj, jl, jl1, jl2, jk   ! dummy loop indices
       INTEGER ::   ij                ! horizontal index, combines i and j loops
       INTEGER ::   icells            ! number of cells with aicen > puny
-      REAL(wp) ::   hL, hR, farea, zdummy, zdummy0, ztmelts    ! left and right limits of integration
-      REAL(wp) ::   zsstK            ! SST in Kelvin
+      REAL(wp) ::   hL, hR, farea, ztmelts    ! left and right limits of integration
 
       INTEGER , POINTER, DIMENSION(:) ::   indxi, indxj   ! compressed indices
@@ -864,5 +831,4 @@
       REAL(wp), POINTER, DIMENSION(:,:) ::   ardg1 , ardg2    ! area of ice ridged & new ridges
       REAL(wp), POINTER, DIMENSION(:,:) ::   vsrdg , esrdg    ! snow volume & energy of ridging ice
-      REAL(wp), POINTER, DIMENSION(:,:) ::   oirdg1, oirdg2   ! areal age content of ridged & rifging ice
       REAL(wp), POINTER, DIMENSION(:,:) ::   dhr   , dhr2     ! hrmax - hrmin  &  hrmax^2 - hrmin^2
 
@@ -873,4 +839,5 @@
       REAL(wp), POINTER, DIMENSION(:,:) ::   srdg2   ! sal*volume of new ridges
       REAL(wp), POINTER, DIMENSION(:,:) ::   smsw    ! sal*volume of water trapped into ridges
+      REAL(wp), POINTER, DIMENSION(:,:) ::   oirdg1, oirdg2   ! ice age of ice ridged
 
       REAL(wp), POINTER, DIMENSION(:,:) ::   afrft            ! fraction of category area rafted
@@ -878,5 +845,5 @@
       REAL(wp), POINTER, DIMENSION(:,:) ::   virft , vsrft    ! ice & snow volume of rafting ice
       REAL(wp), POINTER, DIMENSION(:,:) ::   esrft , smrft    ! snow energy & salinity of rafting ice
-      REAL(wp), POINTER, DIMENSION(:,:) ::   oirft1, oirft2   ! areal age content of rafted ice & rafting ice
+      REAL(wp), POINTER, DIMENSION(:,:) ::   oirft1, oirft2   ! ice age of ice rafted
 
       REAL(wp), POINTER, DIMENSION(:,:,:) ::   eirft      ! ice energy of rafting ice
@@ -886,12 +853,12 @@
       !!----------------------------------------------------------------------
 
-      CALL wrk_alloc( (jpi+1)*(jpj+1),      indxi, indxj )
-      CALL wrk_alloc( jpi, jpj,             vice_init, vice_final, eice_init, eice_final )
-      CALL wrk_alloc( jpi, jpj,             afrac, fvol , ardg1, ardg2, vsrdg, esrdg, oirdg1, oirdg2, dhr, dhr2 )
-      CALL wrk_alloc( jpi, jpj,             vrdg1, vrdg2, vsw  , srdg1, srdg2, smsw )
-      CALL wrk_alloc( jpi, jpj,             afrft, arft1, arft2, virft, vsrft, esrft, smrft, oirft1, oirft2 )
-      CALL wrk_alloc( jpi, jpj, jpl,        aicen_init, vicen_init, vsnwn_init, esnwn_init, smv_i_init, oa_i_init )
-      CALL wrk_alloc( jpi, jpj, nlay_i+1,      eirft, erdg1, erdg2, ersw )
-      CALL wrk_alloc( jpi, jpj, nlay_i+1, jpl, eicen_init )
+      CALL wrk_alloc( (jpi+1)*(jpj+1),       indxi, indxj )
+      CALL wrk_alloc( jpi, jpj,              vice_init, vice_final, eice_init, eice_final )
+      CALL wrk_alloc( jpi, jpj,              afrac, fvol , ardg1, ardg2, vsrdg, esrdg, dhr, dhr2 )
+      CALL wrk_alloc( jpi, jpj,              vrdg1, vrdg2, vsw  , srdg1, srdg2, smsw, oirdg1, oirdg2 )
+      CALL wrk_alloc( jpi, jpj,              afrft, arft1, arft2, virft, vsrft, esrft, smrft, oirft1, oirft2 )
+      CALL wrk_alloc( jpi, jpj, jpl,         aicen_init, vicen_init, vsnwn_init, esnwn_init, smv_i_init, oa_i_init )
+      CALL wrk_alloc( jpi, jpj, nlay_i,      eirft, erdg1, erdg2, ersw )
+      CALL wrk_alloc( jpi, jpj, nlay_i, jpl, eicen_init )
 
       ! Conservation check
@@ -901,6 +868,6 @@
          CALL lim_column_sum        (jpl,    v_i,       vice_init )
          CALL lim_column_sum_energy (jpl, nlay_i,  e_i, eice_init )
-         DO ji = mi0(jiindx), mi1(jiindx)
-            DO jj = mj0(jjindx), mj1(jjindx)
+         DO ji = mi0(iiceprt), mi1(iiceprt)
+            DO jj = mj0(jiceprt), mj1(jiceprt)
                WRITE(numout,*) ' vice_init  : ', vice_init(ji,jj)
                WRITE(numout,*) ' eice_init  : ', eice_init(ji,jj)
@@ -912,52 +879,26 @@
       ! 1) Compute change in open water area due to closing and opening.
       !-------------------------------------------------------------------------------
-
-      neg_ato_i = .false.
-
       DO jj = 1, jpj
          DO ji = 1, jpi
             ato_i(ji,jj) = ato_i(ji,jj) - athorn(ji,jj,0) * closing_gross(ji,jj) * rdt_ice        &
                &                        + opning(ji,jj)                          * rdt_ice
-            IF( ato_i(ji,jj) < -epsi10 ) THEN
-               neg_ato_i = .TRUE.
-            ELSEIF( ato_i(ji,jj) < 0._wp ) THEN    ! roundoff error
+            IF    ( ato_i(ji,jj) < -epsi10 ) THEN    ! there is a bug
+               IF(lwp)   WRITE(numout,*) 'Ridging error: ato_i < 0 -- ato_i : ',ato_i(ji,jj)
+            ELSEIF( ato_i(ji,jj) < 0._wp   ) THEN    ! roundoff error
                ato_i(ji,jj) = 0._wp
             ENDIF
-         END DO !jj
-      END DO !ji
-
-      ! if negative open water area alert it
-      IF( neg_ato_i ) THEN       ! there is a bug
-         DO jj = 1, jpj 
-            DO ji = 1, jpi
-               IF( ato_i(ji,jj) < -epsi10 ) THEN 
-                  WRITE(numout,*) ''  
-                  WRITE(numout,*) 'Ridging error: ato_i < 0'
-                  WRITE(numout,*) 'ato_i : ', ato_i(ji,jj)
-               ENDIF               ! ato_i < -epsi10
-            END DO
-         END DO
-      ENDIF
+         END DO
+      END DO
 
       !-----------------------------------------------------------------
       ! 2) Save initial state variables
       !-----------------------------------------------------------------
-
-      DO jl = 1, jpl
-         aicen_init(:,:,jl) = a_i(:,:,jl)
-         vicen_init(:,:,jl) = v_i(:,:,jl)
-         vsnwn_init(:,:,jl) = v_s(:,:,jl)
-         !
-         smv_i_init(:,:,jl) = smv_i(:,:,jl)
-         oa_i_init (:,:,jl) = oa_i (:,:,jl)
-      END DO !jl
-
-      esnwn_init(:,:,:) = e_s(:,:,1,:)
-
-      DO jl = 1, jpl  
-         DO jk = 1, nlay_i
-            eicen_init(:,:,jk,jl) = e_i(:,:,jk,jl)
-         END DO
-      END DO
+      aicen_init(:,:,:)   = a_i  (:,:,:)
+      vicen_init(:,:,:)   = v_i  (:,:,:)
+      vsnwn_init(:,:,:)   = v_s  (:,:,:)
+      smv_i_init(:,:,:)   = smv_i(:,:,:)
+      esnwn_init(:,:,:)   = e_s  (:,:,1,:)
+      eicen_init(:,:,:,:) = e_i  (:,:,:,:)
+      oa_i_init (:,:,:)   = oa_i (:,:,:)
 
       !
@@ -982,12 +923,8 @@
                   indxi(icells) = ji
                   indxj(icells) = jj
-               ENDIF ! test on a_icen_init 
-            END DO ! ji
-         END DO ! jj
-
-         large_afrac = .false.
-         large_afrft = .false.
-
-!CDIR NODEP
+               ENDIF
+            END DO
+         END DO
+
          DO ij = 1, icells
             ji = indxi(ij)
@@ -1003,9 +940,4 @@
             arft2(ji,jj) = arft1(ji,jj) / kraft
 
-            oirdg1(ji,jj)= aridge(ji,jj,jl1)*closing_gross(ji,jj)*rdt_ice
-            oirft1(ji,jj)= araft (ji,jj,jl1)*closing_gross(ji,jj)*rdt_ice
-            oirdg2(ji,jj)= oirdg1(ji,jj) / krdg(ji,jj,jl1)
-            oirft2(ji,jj)= oirft1(ji,jj) / kraft
-
             !---------------------------------------------------------------
             ! 3.3) Compute ridging /rafting fractions, make sure afrac <=1 
@@ -1015,12 +947,13 @@
             afrft(ji,jj) = arft1(ji,jj) / aicen_init(ji,jj,jl1) !rafting
 
-            IF (afrac(ji,jj) > kamax + epsi10) THEN  !riging
-               large_afrac = .true.
-            ELSEIF (afrac(ji,jj) > kamax) THEN  ! roundoff error
+            IF( afrac(ji,jj) > kamax + epsi10 ) THEN  ! there is a bug
+               IF(lwp)   WRITE(numout,*) ' ardg > a_i -- ardg, aicen_init : ', ardg1(ji,jj), aicen_init(ji,jj,jl1)
+            ELSEIF( afrac(ji,jj) > kamax ) THEN       ! roundoff error
                afrac(ji,jj) = kamax
             ENDIF
-            IF (afrft(ji,jj) > kamax + epsi10) THEN !rafting
-               large_afrft = .true.
-            ELSEIF (afrft(ji,jj) > kamax) THEN  ! roundoff error
+
+            IF( afrft(ji,jj) > kamax + epsi10 ) THEN ! there is a bug
+               IF(lwp)   WRITE(numout,*) ' arft > a_i -- arft, aicen_init : ', arft1(ji,jj), aicen_init(ji,jj,jl1) 
+            ELSEIF( afrft(ji,jj) > kamax) THEN       ! roundoff error
                afrft(ji,jj) = kamax
             ENDIF
@@ -1031,39 +964,42 @@
             !--------------------------------------------------------------------------
             vrdg1(ji,jj) = vicen_init(ji,jj,jl1) * afrac(ji,jj)
-            vrdg2(ji,jj) = vrdg1(ji,jj) * ( 1. + ridge_por )
-            vsw  (ji,jj) = vrdg1(ji,jj) * ridge_por
-
-            vsrdg(ji,jj) = vsnwn_init(ji,jj,jl1) * afrac(ji,jj)
-            esrdg(ji,jj) = esnwn_init(ji,jj,jl1) * afrac(ji,jj)
-            srdg1(ji,jj) = smv_i_init(ji,jj,jl1) * afrac(ji,jj)
-            srdg2(ji,jj) = smv_i_init(ji,jj,jl1) * afrac(ji,jj) !! MV HC 2014 this line seems useless
+            vrdg2(ji,jj) = vrdg1(ji,jj) * ( 1. + rn_por_rdg )
+            vsw  (ji,jj) = vrdg1(ji,jj) * rn_por_rdg
+
+            vsrdg (ji,jj) = vsnwn_init(ji,jj,jl1) * afrac(ji,jj)
+            esrdg (ji,jj) = esnwn_init(ji,jj,jl1) * afrac(ji,jj)
+            srdg1 (ji,jj) = smv_i_init(ji,jj,jl1) * afrac(ji,jj)
+            oirdg1(ji,jj) = oa_i_init (ji,jj,jl1) * afrac(ji,jj)
+            oirdg2(ji,jj) = oa_i_init (ji,jj,jl1) * afrac(ji,jj) / krdg(ji,jj,jl1) 
 
             ! rafting volumes, heat contents ...
-            virft(ji,jj) = vicen_init(ji,jj,jl1) * afrft(ji,jj)
-            vsrft(ji,jj) = vsnwn_init(ji,jj,jl1) * afrft(ji,jj)
-            esrft(ji,jj) = esnwn_init(ji,jj,jl1) * afrft(ji,jj)
-            smrft(ji,jj) = smv_i_init(ji,jj,jl1) * afrft(ji,jj) 
+            virft (ji,jj) = vicen_init(ji,jj,jl1) * afrft(ji,jj)
+            vsrft (ji,jj) = vsnwn_init(ji,jj,jl1) * afrft(ji,jj)
+            esrft (ji,jj) = esnwn_init(ji,jj,jl1) * afrft(ji,jj)
+            smrft (ji,jj) = smv_i_init(ji,jj,jl1) * afrft(ji,jj) 
+            oirft1(ji,jj) = oa_i_init (ji,jj,jl1) * afrft(ji,jj) 
+            oirft2(ji,jj) = oa_i_init (ji,jj,jl1) * afrft(ji,jj) / kraft 
 
             ! substract everything
-            a_i(ji,jj,jl1)   = a_i(ji,jj,jl1)   - ardg1(ji,jj)  - arft1(ji,jj)
-            v_i(ji,jj,jl1)   = v_i(ji,jj,jl1)   - vrdg1(ji,jj)  - virft(ji,jj)
-            v_s(ji,jj,jl1)   = v_s(ji,jj,jl1)   - vsrdg(ji,jj)  - vsrft(ji,jj)
-            e_s(ji,jj,1,jl1) = e_s(ji,jj,1,jl1) - esrdg(ji,jj)  - esrft(ji,jj)
+            a_i(ji,jj,jl1)   = a_i(ji,jj,jl1)   - ardg1 (ji,jj) - arft1 (ji,jj)
+            v_i(ji,jj,jl1)   = v_i(ji,jj,jl1)   - vrdg1 (ji,jj) - virft (ji,jj)
+            v_s(ji,jj,jl1)   = v_s(ji,jj,jl1)   - vsrdg (ji,jj) - vsrft (ji,jj)
+            e_s(ji,jj,1,jl1) = e_s(ji,jj,1,jl1) - esrdg (ji,jj) - esrft (ji,jj)
+            smv_i(ji,jj,jl1) = smv_i(ji,jj,jl1) - srdg1 (ji,jj) - smrft (ji,jj)
             oa_i(ji,jj,jl1)  = oa_i(ji,jj,jl1)  - oirdg1(ji,jj) - oirft1(ji,jj)
-            smv_i(ji,jj,jl1) = smv_i(ji,jj,jl1) - srdg1(ji,jj)  - smrft(ji,jj)
 
             !-----------------------------------------------------------------
             ! 3.5) Compute properties of new ridges
             !-----------------------------------------------------------------
-            !-------------
+            !---------
             ! Salinity
-            !-------------
+            !---------
             smsw(ji,jj)  = vsw(ji,jj) * sss_m(ji,jj)                      ! salt content of seawater frozen in voids !! MV HC2014
             srdg2(ji,jj) = srdg1(ji,jj) + smsw(ji,jj)                     ! salt content of new ridge
 
-            !srdg2(ji,jj) = MIN( s_i_max * vrdg2(ji,jj) , zsrdg2 )         ! impose a maximum salinity
+            !srdg2(ji,jj) = MIN( rn_simax * vrdg2(ji,jj) , zsrdg2 )         ! impose a maximum salinity
             
             sfx_dyn(ji,jj) = sfx_dyn(ji,jj) - smsw(ji,jj) * rhoic * r1_rdtice
-            wfx_dyn(ji,jj) = wfx_dyn(ji,jj) - vsw (ji,jj) * rhoic * r1_rdtice   ! gurvan: increase in ice volume du to seawater frozen in voids             
+            wfx_dyn(ji,jj) = wfx_dyn(ji,jj) - vsw (ji,jj) * rhoic * r1_rdtice   ! increase in ice volume du to seawater frozen in voids             
 
             !------------------------------------            
@@ -1091,10 +1027,10 @@
             !           ij looping 1-icells
 
-            msnow_mlt(ji,jj) = msnow_mlt(ji,jj) + rhosn*vsrdg(ji,jj)*(1.0-fsnowrdg)   &   ! rafting included
-               &                                + rhosn*vsrft(ji,jj)*(1.0-fsnowrft)
-
-            ! in 1e-9 Joules (same as e_s)
-            esnow_mlt(ji,jj) = esnow_mlt(ji,jj) - esrdg(ji,jj)*(1.0-fsnowrdg)         &   !rafting included
-               &                                - esrft(ji,jj)*(1.0-fsnowrft)          
+            msnow_mlt(ji,jj) = msnow_mlt(ji,jj) + rhosn*vsrdg(ji,jj)*(1.0-rn_fsnowrdg)   &   ! rafting included
+               &                                + rhosn*vsrft(ji,jj)*(1.0-rn_fsnowrft)
+
+            ! in J/m2 (same as e_s)
+            esnow_mlt(ji,jj) = esnow_mlt(ji,jj) - esrdg(ji,jj)*(1.0-rn_fsnowrdg)         &   !rafting included
+               &                                - esrft(ji,jj)*(1.0-rn_fsnowrft)          
 
             !-----------------------------------------------------------------
@@ -1109,5 +1045,5 @@
             dhr2(ji,jj) = hrmax(ji,jj,jl1) * hrmax(ji,jj,jl1) - hrmin(ji,jj,jl1) * hrmin(ji,jj,jl1)
 
-         END DO                 ! ij
+         END DO
 
          !--------------------------------------------------------------------
@@ -1116,5 +1052,4 @@
          !--------------------------------------------------------------------
          DO jk = 1, nlay_i
-!CDIR NODEP
             DO ij = 1, icells
                ji = indxi(ij)
@@ -1128,57 +1063,23 @@
                ! enthalpy of the trapped seawater (J/m2, >0)
                ! clem: if sst>0, then ersw <0 (is that possible?)
-               zsstK  = sst_m(ji,jj) + rt0
-               ersw(ji,jj,jk)   = - rhoic * vsw(ji,jj) * rcp * ( zsstK - rt0 ) / REAL( nlay_i )
+               ersw(ji,jj,jk)   = - rhoic * vsw(ji,jj) * rcp * sst_m(ji,jj) * r1_nlay_i
 
                ! heat flux to the ocean
                hfx_dyn(ji,jj) = hfx_dyn(ji,jj) + ersw(ji,jj,jk) * r1_rdtice  ! > 0 [W.m-2] ocean->ice flux 
 
-               ! Correct dimensions to avoid big values
-               ersw(ji,jj,jk)   = ersw(ji,jj,jk) / unit_fac
-
-               ! Mutliply by ice volume, and divide by number of layers to get heat content in 1.e9 J
-               ! it is added to sea ice because the sign convention is the opposite of the sign convention for the ocean 
-               !! MV HC 2014
-               ersw (ji,jj,jk)  = ersw(ji,jj,jk) * area(ji,jj)
-
+               ! it is added to sea ice because the sign convention is the opposite of the sign convention for the ocean
                erdg2(ji,jj,jk)  = erdg1(ji,jj,jk) + ersw(ji,jj,jk)
 
-            END DO ! ij
-         END DO !jk
+            END DO
+         END DO
 
 
          IF( con_i ) THEN
             DO jk = 1, nlay_i
-!CDIR NODEP
                DO ij = 1, icells
                   ji = indxi(ij)
                   jj = indxj(ij)
                   eice_init(ji,jj) = eice_init(ji,jj) + erdg2(ji,jj,jk) - erdg1(ji,jj,jk)
-               END DO ! ij
-            END DO !jk
-         ENDIF
-
-         IF( large_afrac ) THEN   ! there is a bug
-!CDIR NODEP
-            DO ij = 1, icells
-               ji = indxi(ij)
-               jj = indxj(ij)
-               IF( afrac(ji,jj) > kamax + epsi10 ) THEN 
-                  WRITE(numout,*) ''
-                  WRITE(numout,*) ' ardg > a_i'
-                  WRITE(numout,*) ' ardg, aicen_init : ', ardg1(ji,jj), aicen_init(ji,jj,jl1)
-               ENDIF
-            END DO
-         ENDIF
-         IF( large_afrft ) THEN  ! there is a bug
-!CDIR NODEP
-            DO ij = 1, icells
-               ji = indxi(ij)
-               jj = indxj(ij)
-               IF( afrft(ji,jj) > kamax + epsi10 ) THEN 
-                  WRITE(numout,*) ''
-                  WRITE(numout,*) ' arft > a_i'
-                  WRITE(numout,*) ' arft, aicen_init : ', arft1(ji,jj), aicen_init(ji,jj,jl1)
-               ENDIF
+               END DO
             END DO
          ENDIF
@@ -1190,5 +1091,4 @@
          DO jl2  = 1, jpl 
             ! over categories to which ridged ice is transferred
-!CDIR NODEP
             DO ij = 1, icells
                ji = indxi(ij)
@@ -1199,6 +1099,5 @@
                ! Transfer area, volume, and energy accordingly.
 
-               IF( hrmin(ji,jj,jl1) >= hi_max(jl2)  .OR.        &
-                   hrmax(ji,jj,jl1) <= hi_max(jl2-1) ) THEN
+               IF( hrmin(ji,jj,jl1) >= hi_max(jl2) .OR. hrmax(ji,jj,jl1) <= hi_max(jl2-1) ) THEN
                   hL = 0._wp
                   hR = 0._wp
@@ -1214,18 +1113,17 @@
                a_i  (ji,jj  ,jl2) = a_i  (ji,jj  ,jl2) + ardg2 (ji,jj) * farea
                v_i  (ji,jj  ,jl2) = v_i  (ji,jj  ,jl2) + vrdg2 (ji,jj) * fvol(ji,jj)
-               v_s  (ji,jj  ,jl2) = v_s  (ji,jj  ,jl2) + vsrdg (ji,jj) * fvol(ji,jj) * fsnowrdg
-               e_s  (ji,jj,1,jl2) = e_s  (ji,jj,1,jl2) + esrdg (ji,jj) * fvol(ji,jj) * fsnowrdg
+               v_s  (ji,jj  ,jl2) = v_s  (ji,jj  ,jl2) + vsrdg (ji,jj) * fvol(ji,jj) * rn_fsnowrdg
+               e_s  (ji,jj,1,jl2) = e_s  (ji,jj,1,jl2) + esrdg (ji,jj) * fvol(ji,jj) * rn_fsnowrdg
                smv_i(ji,jj  ,jl2) = smv_i(ji,jj  ,jl2) + srdg2 (ji,jj) * fvol(ji,jj)
                oa_i (ji,jj  ,jl2) = oa_i (ji,jj  ,jl2) + oirdg2(ji,jj) * farea
 
-            END DO ! ij
+            END DO
 
             ! Transfer ice energy to category jl2 by ridging
             DO jk = 1, nlay_i
-!CDIR NODEP
                DO ij = 1, icells
                   ji = indxi(ij)
                   jj = indxj(ij)
-                  e_i(ji,jj,jk,jl2) = e_i(ji,jj,jk,jl2) + fvol(ji,jj)*erdg2(ji,jj,jk)
+                  e_i(ji,jj,jk,jl2) = e_i(ji,jj,jk,jl2) + fvol(ji,jj) * erdg2(ji,jj,jk)
                END DO
             END DO
@@ -1235,5 +1133,4 @@
          DO jl2 = 1, jpl 
 
-!CDIR NODEP
             DO ij = 1, icells
                ji = indxi(ij)
@@ -1242,30 +1139,27 @@
                ! thickness category jl2, transfer area, volume, and energy accordingly.
                !
-               IF( hraft(ji,jj,jl1) <= hi_max(jl2)  .AND.        &
-                   hraft(ji,jj,jl1) >  hi_max(jl2-1) ) THEN
+               IF( hraft(ji,jj,jl1) <= hi_max(jl2) .AND. hraft(ji,jj,jl1) >  hi_max(jl2-1) ) THEN
                   a_i  (ji,jj  ,jl2) = a_i  (ji,jj  ,jl2) + arft2 (ji,jj)
                   v_i  (ji,jj  ,jl2) = v_i  (ji,jj  ,jl2) + virft (ji,jj)
-                  v_s  (ji,jj  ,jl2) = v_s  (ji,jj  ,jl2) + vsrft (ji,jj) * fsnowrft
-                  e_s  (ji,jj,1,jl2) = e_s  (ji,jj,1,jl2) + esrft (ji,jj) * fsnowrft
+                  v_s  (ji,jj  ,jl2) = v_s  (ji,jj  ,jl2) + vsrft (ji,jj) * rn_fsnowrft
+                  e_s  (ji,jj,1,jl2) = e_s  (ji,jj,1,jl2) + esrft (ji,jj) * rn_fsnowrft
                   smv_i(ji,jj  ,jl2) = smv_i(ji,jj  ,jl2) + smrft (ji,jj)    
-                  oa_i (ji,jj  ,jl2) = oa_i (ji,jj  ,jl2) + oirft2(ji,jj)    
-               ENDIF ! hraft
+                  oa_i (ji,jj  ,jl2) = oa_i (ji,jj  ,jl2) + oirft2(ji,jj)
+               ENDIF
                !
-            END DO ! ij
+            END DO
 
             ! Transfer rafted ice energy to category jl2 
             DO jk = 1, nlay_i
-!CDIR NODEP
                DO ij = 1, icells
                   ji = indxi(ij)
                   jj = indxj(ij)
-                  IF(  hraft(ji,jj,jl1)  <=  hi_max(jl2)   .AND.        &
-                       hraft(ji,jj,jl1)  >   hi_max(jl2-1)  ) THEN
+                  IF( hraft(ji,jj,jl1) <= hi_max(jl2) .AND. hraft(ji,jj,jl1) > hi_max(jl2-1)  ) THEN
                      e_i(ji,jj,jk,jl2) = e_i(ji,jj,jk,jl2) + eirft(ji,jj,jk)
                   ENDIF
-               END DO           ! ij
-            END DO !jk
-
-         END DO ! jl2
+               END DO
+            END DO
+
+         END DO
 
       END DO ! jl1 (deforming categories)
@@ -1281,6 +1175,6 @@
          CALL lim_cons_check (eice_init, eice_final, 1.0e-2, fieldid) 
 
-         DO ji = mi0(jiindx), mi1(jiindx)
-            DO jj = mj0(jjindx), mj1(jjindx)
+         DO ji = mi0(iiceprt), mi1(iiceprt)
+            DO jj = mj0(jiceprt), mj1(jiceprt)
                WRITE(numout,*) ' vice_init  : ', vice_init (ji,jj)
                WRITE(numout,*) ' vice_final : ', vice_final(ji,jj)
@@ -1291,37 +1185,14 @@
       ENDIF
       !
-      CALL wrk_dealloc( (jpi+1)*(jpj+1),      indxi, indxj )
-      CALL wrk_dealloc( jpi, jpj,             vice_init, vice_final, eice_init, eice_final )
-      CALL wrk_dealloc( jpi, jpj,             afrac, fvol , ardg1, ardg2, vsrdg, esrdg, oirdg1, oirdg2, dhr, dhr2 )
-      CALL wrk_dealloc( jpi, jpj,             vrdg1, vrdg2, vsw  , srdg1, srdg2, smsw )
-      CALL wrk_dealloc( jpi, jpj,             afrft, arft1, arft2, virft, vsrft, esrft, smrft, oirft1, oirft2 )
-      CALL wrk_dealloc( jpi, jpj, jpl,        aicen_init, vicen_init, vsnwn_init, esnwn_init, smv_i_init, oa_i_init )
-      CALL wrk_dealloc( jpi, jpj, nlay_i+1,      eirft, erdg1, erdg2, ersw )
-      CALL wrk_dealloc( jpi, jpj, nlay_i+1, jpl, eicen_init )
+      CALL wrk_dealloc( (jpi+1)*(jpj+1),        indxi, indxj )
+      CALL wrk_dealloc( jpi, jpj,               vice_init, vice_final, eice_init, eice_final )
+      CALL wrk_dealloc( jpi, jpj,               afrac, fvol , ardg1, ardg2, vsrdg, esrdg, dhr, dhr2 )
+      CALL wrk_dealloc( jpi, jpj,               vrdg1, vrdg2, vsw  , srdg1, srdg2, smsw, oirdg1, oirdg2 )
+      CALL wrk_dealloc( jpi, jpj,               afrft, arft1, arft2, virft, vsrft, esrft, smrft, oirft1, oirft2 )
+      CALL wrk_dealloc( jpi, jpj, jpl,          aicen_init, vicen_init, vsnwn_init, esnwn_init, smv_i_init, oa_i_init )
+      CALL wrk_dealloc( jpi, jpj, nlay_i,       eirft, erdg1, erdg2, ersw )
+      CALL wrk_dealloc( jpi, jpj, nlay_i, jpl,  eicen_init )
       !
    END SUBROUTINE lim_itd_me_ridgeshift
-
-
-   SUBROUTINE lim_itd_me_asumr
-      !!-----------------------------------------------------------------------------
-      !!                ***  ROUTINE lim_itd_me_asumr ***
-      !!
-      !! ** Purpose :   finds total fractional area
-      !!
-      !! ** Method  :   Find the total area of ice plus open water in each grid cell.
-      !!              This is similar to the aggregate_area subroutine except that the
-      !!              total area can be greater than 1, so the open water area is 
-      !!              included in the sum instead of being computed as a residual. 
-      !!-----------------------------------------------------------------------------
-      INTEGER ::   jl   ! dummy loop index
-      !!-----------------------------------------------------------------------------
-      !
-      asum(:,:) = ato_i(:,:)                    ! open water
-      DO jl = 1, jpl                            ! ice categories
-         asum(:,:) = asum(:,:) + a_i(:,:,jl)
-      END DO
-      !
-   END SUBROUTINE lim_itd_me_asumr
-
 
    SUBROUTINE lim_itd_me_init
@@ -1339,7 +1210,7 @@
       !!-------------------------------------------------------------------
       INTEGER :: ios                 ! Local integer output status for namelist read
-      NAMELIST/namiceitdme/ ridge_scheme_swi, Cs, Cf, fsnowrdg, fsnowrft,              & 
-        &                   Gstar, astar, Hstar, raft_swi, hparmeter, Craft, ridge_por, &
-        &                   partfun_swi, brinstren_swi
+      NAMELIST/namiceitdme/ rn_cs, rn_fsnowrdg, rn_fsnowrft,              & 
+        &                   rn_gstar, rn_astar, rn_hstar, ln_rafting, rn_hraft, rn_craft, rn_por_rdg, &
+        &                   nn_partfun
       !!-------------------------------------------------------------------
       !
@@ -1357,130 +1228,18 @@
          WRITE(numout,*)' lim_itd_me_init : ice parameters for mechanical ice redistribution '
          WRITE(numout,*)' ~~~~~~~~~~~~~~~'
-         WRITE(numout,*)'   Switch choosing the ice redistribution scheme           ridge_scheme_swi', ridge_scheme_swi 
-         WRITE(numout,*)'   Fraction of shear energy contributing to ridging        Cs              ', Cs 
-         WRITE(numout,*)'   Ratio of ridging work to PotEner change in ridging      Cf              ', Cf 
-         WRITE(numout,*)'   Fraction of snow volume conserved during ridging        fsnowrdg        ', fsnowrdg 
-         WRITE(numout,*)'   Fraction of snow volume conserved during ridging        fsnowrft        ', fsnowrft 
-         WRITE(numout,*)'   Fraction of total ice coverage contributing to ridging  Gstar           ', Gstar
-         WRITE(numout,*)'   Equivalent to G* for an exponential part function       astar           ', astar
-         WRITE(numout,*)'   Quantity playing a role in max ridged ice thickness     Hstar           ', Hstar
-         WRITE(numout,*)'   Rafting of ice sheets or not                            raft_swi        ', raft_swi
-         WRITE(numout,*)'   Parmeter thickness (threshold between ridge-raft)       hparmeter       ', hparmeter
-         WRITE(numout,*)'   Rafting hyperbolic tangent coefficient                  Craft           ', Craft  
-         WRITE(numout,*)'   Initial porosity of ridges                              ridge_por       ', ridge_por
-         WRITE(numout,*)'   Switch for part. function (0) linear (1) exponential    partfun_swi     ', partfun_swi
-         WRITE(numout,*)'   Switch for including brine volume in ice strength comp. brinstren_swi   ', brinstren_swi
+         WRITE(numout,*)'   Fraction of shear energy contributing to ridging        rn_cs       = ', rn_cs 
+         WRITE(numout,*)'   Fraction of snow volume conserved during ridging        rn_fsnowrdg = ', rn_fsnowrdg 
+         WRITE(numout,*)'   Fraction of snow volume conserved during ridging        rn_fsnowrft = ', rn_fsnowrft 
+         WRITE(numout,*)'   Fraction of total ice coverage contributing to ridging  rn_gstar    = ', rn_gstar
+         WRITE(numout,*)'   Equivalent to G* for an exponential part function       rn_astar    = ', rn_astar
+         WRITE(numout,*)'   Quantity playing a role in max ridged ice thickness     rn_hstar    = ', rn_hstar
+         WRITE(numout,*)'   Rafting of ice sheets or not                            ln_rafting  = ', ln_rafting
+         WRITE(numout,*)'   Parmeter thickness (threshold between ridge-raft)       rn_hraft    = ', rn_hraft
+         WRITE(numout,*)'   Rafting hyperbolic tangent coefficient                  rn_craft    = ', rn_craft  
+         WRITE(numout,*)'   Initial porosity of ridges                              rn_por_rdg  = ', rn_por_rdg
+         WRITE(numout,*)'   Switch for part. function (0) linear (1) exponential    nn_partfun  = ', nn_partfun
       ENDIF
       !
    END SUBROUTINE lim_itd_me_init
-
-
-   SUBROUTINE lim_itd_me_zapsmall
-      !!-------------------------------------------------------------------
-      !!                   ***  ROUTINE lim_itd_me_zapsmall ***
-      !!
-      !! ** Purpose :   Remove too small sea ice areas and correct salt fluxes
-      !!
-      !! history :
-      !! author: William H. Lipscomb, LANL
-      !! Nov 2003:  Modified by Julie Schramm to conserve volume and energy
-      !! Sept 2004: Modified by William Lipscomb; replaced normalize_state with
-      !!            additions to local freshwater, salt, and heat fluxes
-      !!  9.0, LIM3.0 - 02-2006 (M. Vancoppenolle) original code
-      !!-------------------------------------------------------------------
-      INTEGER ::   ji, jj, jl, jk   ! dummy loop indices
-      INTEGER ::   icells           ! number of cells with ice to zap
-
-      REAL(wp), POINTER, DIMENSION(:,:) ::   zmask   ! 2D workspace
-      REAL(wp)                          ::   zmask_glo, zsal, zvi, zvs, zei, zes
-!!gm      REAL(wp) ::   xtmp      ! temporary variable
-      !!-------------------------------------------------------------------
-
-      CALL wrk_alloc( jpi, jpj, zmask )
-
-      ! to be sure that at_i is the sum of a_i(jl)
-      at_i(:,:) = SUM( a_i(:,:,:), dim=3 )
-
-      DO jl = 1, jpl
-         !-----------------------------------------------------------------
-         ! Count categories to be zapped.
-         !-----------------------------------------------------------------
-         icells = 0
-         zmask(:,:)  = 0._wp
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( a_i(ji,jj,jl) <= epsi10 .OR. v_i(ji,jj,jl) <= epsi10 .OR. at_i(ji,jj) <= epsi10 ) THEN
-                  zmask(ji,jj) = 1._wp
-               ENDIF
-            END DO
-         END DO
-         !zmask_glo = glob_sum(zmask)
-         !IF( ln_nicep .AND. lwp ) WRITE(numout,*) zmask_glo, ' cells of ice zapped in the ocean '
-
-         !-----------------------------------------------------------------
-         ! Zap ice energy and use ocean heat to melt ice
-         !-----------------------------------------------------------------
-
-         DO jk = 1, nlay_i
-            DO jj = 1 , jpj
-               DO ji = 1 , jpi
-                  zei  = e_i(ji,jj,jk,jl)
-                  e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * ( 1._wp - zmask(ji,jj) )
-                  t_i(ji,jj,jk,jl) = t_i(ji,jj,jk,jl) * ( 1._wp - zmask(ji,jj) ) + rtt * zmask(ji,jj)
-                  ! update exchanges with ocean
-                  hfx_res(ji,jj)   = hfx_res(ji,jj) + ( e_i(ji,jj,jk,jl) - zei ) * unit_fac / area(ji,jj) * r1_rdtice ! W.m-2 <0
-               END DO
-            END DO
-         END DO
-
-         DO jj = 1 , jpj
-            DO ji = 1 , jpi
-               
-               zsal = smv_i(ji,jj,jl)
-               zvi  = v_i(ji,jj,jl)
-               zvs  = v_s(ji,jj,jl)
-               zes  = e_s(ji,jj,1,jl)
-               !-----------------------------------------------------------------
-               ! Zap snow energy and use ocean heat to melt snow
-               !-----------------------------------------------------------------
-               !           xtmp = esnon(i,j,n) / dt ! < 0
-               !           fhnet(i,j)      = fhnet(i,j)      + xtmp
-               !           fhnet_hist(i,j) = fhnet_hist(i,j) + xtmp
-               ! xtmp is greater than 0
-               ! fluxes are positive to the ocean
-               ! here the flux has to be negative for the ocean
-               t_s(ji,jj,1,jl) = rtt * zmask(ji,jj) + t_s(ji,jj,1,jl) * ( 1._wp - zmask(ji,jj) )
-
-               !-----------------------------------------------------------------
-               ! zap ice and snow volume, add water and salt to ocean
-               !-----------------------------------------------------------------
-               ato_i(ji,jj)    = a_i  (ji,jj,jl) *           zmask(ji,jj)   + ato_i(ji,jj)
-               a_i  (ji,jj,jl) = a_i  (ji,jj,jl) * ( 1._wp - zmask(ji,jj) )
-               v_i  (ji,jj,jl) = v_i  (ji,jj,jl) * ( 1._wp - zmask(ji,jj) )
-               v_s  (ji,jj,jl) = v_s  (ji,jj,jl) * ( 1._wp - zmask(ji,jj) )
-               t_su (ji,jj,jl) = t_su (ji,jj,jl) * ( 1._wp - zmask(ji,jj) ) + t_bo(ji,jj) * zmask(ji,jj)
-               oa_i (ji,jj,jl) = oa_i (ji,jj,jl) * ( 1._wp - zmask(ji,jj) )
-               smv_i(ji,jj,jl) = smv_i(ji,jj,jl) * ( 1._wp - zmask(ji,jj) )
-               e_s(ji,jj,1,jl) = e_s(ji,jj,1,jl) * ( 1._wp - zmask(ji,jj) )
-               ! additional condition
-               IF( v_s(ji,jj,jl) <= epsi10 ) THEN
-                  v_s(ji,jj,jl)   = 0._wp
-                  e_s(ji,jj,1,jl) = 0._wp
-               ENDIF
-               ! update exchanges with ocean
-               sfx_res(ji,jj)  = sfx_res(ji,jj) - ( smv_i(ji,jj,jl) - zsal ) * rhoic * r1_rdtice
-               wfx_res(ji,jj)  = wfx_res(ji,jj) - ( v_i(ji,jj,jl)   - zvi  ) * rhoic * r1_rdtice
-               wfx_snw(ji,jj)  = wfx_snw(ji,jj) - ( v_s(ji,jj,jl)   - zvs  ) * rhosn * r1_rdtice
-               hfx_res(ji,jj)  = hfx_res(ji,jj) + ( e_s(ji,jj,1,jl) - zes ) * unit_fac / area(ji,jj) * r1_rdtice ! W.m-2 <0
-            END DO
-         END DO
-      END DO ! jl 
-
-      ! to be sure that at_i is the sum of a_i(jl)
-      at_i(:,:) = SUM( a_i(:,:,:), dim=3 )
-      !
-      CALL wrk_dealloc( jpi, jpj, zmask )
-      !
-   END SUBROUTINE lim_itd_me_zapsmall
 
 #else
@@ -1493,10 +1252,6 @@
    SUBROUTINE lim_itd_me_icestrength
    END SUBROUTINE lim_itd_me_icestrength
-   SUBROUTINE lim_itd_me_sort
-   END SUBROUTINE lim_itd_me_sort
    SUBROUTINE lim_itd_me_init
    END SUBROUTINE lim_itd_me_init
-   SUBROUTINE lim_itd_me_zapsmall
-   END SUBROUTINE lim_itd_me_zapsmall
 #endif
    !!======================================================================
