Index: trunk/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90
===================================================================
--- trunk/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90	(revision 4873)
+++ trunk/NEMOGCM/NEMO/LIM_SRC_3/limthd_dh.F90	(revision 4990)
@@ -26,5 +26,4 @@
    USE wrk_nemo       ! work arrays
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE cpl_oasis3, ONLY : lk_cpl
    
    IMPLICIT NONE
@@ -32,7 +31,4 @@
 
    PUBLIC   lim_thd_dh   ! called by lim_thd
-
-   REAL(wp) ::   epsi20 = 1.e-20   ! constant values
-   REAL(wp) ::   epsi10 = 1.e-10   !
 
    !!----------------------------------------------------------------------
@@ -112,10 +108,8 @@
 
       ! mass and salt flux (clem)
-      REAL(wp) :: zdvres, zswitch_sal, zswitch
+      REAL(wp) :: zdvres, zswitch_sal
 
       ! Heat conservation 
       INTEGER  ::   num_iter_max
-      REAL(wp) ::   zinda, zindq, zindh 
-      REAL(wp), POINTER, DIMENSION(:) ::   zintermelt   ! debug
 
       !!------------------------------------------------------------------
@@ -129,5 +123,4 @@
       CALL wrk_alloc( jpij, zh_s, zqprec, zq_su, zq_bo, zf_tt, zq_1cat, zq_rema )
       CALL wrk_alloc( jpij, zdh_s_mel, zdh_s_pre, zdh_s_sub, zqh_i, zqh_s, zq_s )
-      CALL wrk_alloc( jpij, zintermelt )
       CALL wrk_alloc( jpij, nlay_i+1, zdeltah, zh_i )
       CALL wrk_alloc( jpij, icount )
@@ -148,5 +141,4 @@
       zh_i      (:,:) = 0._wp       
       zdeltah   (:,:) = 0._wp       
-      zintermelt(:)   = 0._wp
       icount    (:)   = 0
 
@@ -166,9 +158,9 @@
       !
       DO ji = kideb, kiut
-         zinda         = 1._wp - MAX(  0._wp , SIGN( 1._wp , - ht_s_1d(ji) ) )
-         ztmelts       = zinda * rtt + ( 1._wp - zinda ) * rtt
-
-         zfdum     = 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) 
+         rswitch       = 1._wp - MAX(  0._wp , SIGN( 1._wp , - ht_s_1d(ji) ) )
+         ztmelts       = rswitch * rtt + ( 1._wp - rswitch ) * rtt
+
+         zfdum      = 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, zfdum     * rdt_ice ) * MAX( 0._wp , SIGN( 1._wp, t_su_1d(ji) - ztmelts ) )
@@ -255,6 +247,6 @@
          ! thickness change
          IF( zdh_s_pre(ji) > 0._wp ) THEN
-         zindq          = 1._wp - MAX( 0._wp , SIGN( 1._wp , - zqprec(ji) + epsi20 ) )
-         zdh_s_mel (ji) = - zindq * zq_su(ji) / MAX( zqprec(ji) , epsi20 )
+         rswitch        = 1._wp - MAX( 0._wp , SIGN( 1._wp , - zqprec(ji) + epsi20 ) )
+         zdh_s_mel (ji) = - rswitch * zq_su(ji) / MAX( zqprec(ji) , epsi20 )
          zdh_s_mel (ji) = MAX( - zdh_s_pre(ji), zdh_s_mel(ji) ) ! bound melting 
          ! heat used to melt snow (W.m-2, >0)
@@ -276,7 +268,7 @@
          DO ji = kideb, kiut
             ! thickness change
-            zindh            = 1._wp - MAX( 0._wp, SIGN( 1._wp, - ht_s_1d(ji) ) ) 
-            zindq            = 1._wp - MAX( 0._wp, SIGN( 1._wp, - q_s_1d(ji,jk) + epsi20 ) ) 
-            zdeltah  (ji,jk) = - zindh * zindq * zq_su(ji) / MAX( q_s_1d(ji,jk), epsi20 )
+            rswitch          = 1._wp - MAX( 0._wp, SIGN( 1._wp, - ht_s_1d(ji) ) ) 
+            rswitch          = rswitch * ( 1._wp - MAX( 0._wp, SIGN( 1._wp, - q_s_1d(ji,jk) + epsi20 ) ) ) 
+            zdeltah  (ji,jk) = - rswitch * zq_su(ji) / MAX( q_s_1d(ji,jk), epsi20 )
             zdeltah  (ji,jk) = MAX( zdeltah(ji,jk) , - zh_s(ji) ) ! bound melting
             zdh_s_mel(ji)    = zdh_s_mel(ji) + zdeltah(ji,jk)    
@@ -332,6 +324,6 @@
       DO jk = 1, nlay_s
          DO ji = kideb,kiut
-            zindh  =  MAX(  0._wp , SIGN( 1._wp, - ht_s_1d(ji) + epsi20 )  )
-            q_s_1d(ji,jk) = ( 1._wp - zindh ) / MAX( ht_s_1d(ji), epsi20 ) *             &
+            rswitch       =  MAX(  0._wp , SIGN( 1._wp, - ht_s_1d(ji) + epsi20 )  )
+            q_s_1d(ji,jk) = ( 1._wp - rswitch ) / MAX( ht_s_1d(ji), epsi20 ) *             &
               &            ( (   MAX( 0._wp, dh_s_tot(ji) )              ) * zqprec(ji) +  &
               &              ( - MAX( 0._wp, dh_s_tot(ji) ) + ht_s_1d(ji) ) * rhosn * ( cpic * ( rtt - t_s_1d(ji,jk) ) + lfus ) )
@@ -383,6 +375,6 @@
             !    => icount=0 : no layer has vanished
             !    => icount=5 : 5 layers have vanished
-            zindh       = NINT( MAX( 0._wp , SIGN( 1._wp , - ( zh_i(ji,jk) + zdeltah(ji,jk) ) ) ) ) 
-            icount(ji)  = icount(ji) + zindh
+            rswitch     = MAX( 0._wp , SIGN( 1._wp , - ( zh_i(ji,jk) + zdeltah(ji,jk) ) ) ) 
+            icount(ji)  = icount(ji) + NINT( rswitch )
             zh_i(ji,jk) = MAX( 0._wp , zh_i(ji,jk) + zdeltah(ji,jk) )
 
@@ -516,5 +508,4 @@
 
                IF( t_i_1d(ji,jk) >= ztmelts ) THEN !!! Internal melting
-                  zintermelt(ji)    = 1._wp
 
                   zEi               = - q_i_1d(ji,jk) / rhoic        ! Specific enthalpy of melting ice (J/kg, <0)
@@ -603,6 +594,6 @@
 !
 !               ! excessive energy is sent to lateral ablation
-!               zinda = MAX( 0._wp, SIGN( 1._wp , 1._wp - at_i_1d(ji) - epsi20 ) )
-!               zq_1cat(ji) =  zinda * rhoic * lfus * at_i_1d(ji) / MAX( 1._wp - at_i_1d(ji) , epsi20 ) * zdvres ! J.m-2 >=0
+!               rswitch = MAX( 0._wp, SIGN( 1._wp , 1._wp - at_i_1d(ji) - epsi20 ) )
+!               zq_1cat(ji) =  rswitch * rhoic * lfus * at_i_1d(ji) / MAX( 1._wp - at_i_1d(ji) , epsi20 ) * zdvres ! J.m-2 >=0
 !
 !               ! correct salt and mass fluxes
@@ -669,10 +660,10 @@
          ! new salinity difference stored (to be used in limthd_ent.F90)
          IF (  num_sal == 2  ) THEN
-            zswitch = MAX( 0._wp , SIGN( 1._wp , ht_i_1d(ji) - epsi10 ) )
+            rswitch = MAX( 0._wp , SIGN( 1._wp , ht_i_1d(ji) - epsi10 ) )
             ! salinity dif due to snow-ice formation
-            dsm_i_si_1d(ji) = ( zs_snic - sm_i_1d(ji) ) * dh_snowice(ji) / MAX( ht_i_1d(ji), epsi10 ) * zswitch     
+            dsm_i_si_1d(ji) = ( zs_snic - sm_i_1d(ji) ) * dh_snowice(ji) / MAX( ht_i_1d(ji), epsi10 ) * rswitch     
             ! salinity dif due to bottom growth 
             IF (  zf_tt(ji)  < 0._wp ) THEN
-               dsm_i_se_1d(ji) = ( s_i_new(ji) - sm_i_1d(ji) ) * dh_i_bott(ji) / MAX( ht_i_1d(ji), epsi10 ) * zswitch
+               dsm_i_se_1d(ji) = ( s_i_new(ji) - sm_i_1d(ji) ) * dh_i_bott(ji) / MAX( ht_i_1d(ji), epsi10 ) * rswitch
             ENDIF
          ENDIF
@@ -711,6 +702,6 @@
       !clem bug: we should take snow into account here
       DO ji = kideb, kiut
-         zindh    =  1.0 - MAX( 0._wp , SIGN( 1._wp , - ht_i_1d(ji) ) ) 
-         t_su_1d(ji) =  zindh * t_su_1d(ji) + ( 1.0 - zindh ) * rtt
+         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 ) * rtt
       END DO  ! ji
 
@@ -718,8 +709,8 @@
          DO ji = kideb,kiut
             ! mask enthalpy
-            zinda        =  MAX(  0._wp , SIGN( 1._wp, - ht_s_1d(ji) )  )
-            q_s_1d(ji,jk) = ( 1.0 - zinda ) * q_s_1d(ji,jk)
+            rswitch       =  MAX(  0._wp , SIGN( 1._wp, - ht_s_1d(ji) )  )
+            q_s_1d(ji,jk) = ( 1.0 - rswitch ) * q_s_1d(ji,jk)
             ! recalculate t_s_1d from q_s_1d
-            t_s_1d(ji,jk) = rtt + ( 1._wp - zinda ) * ( - q_s_1d(ji,jk) / ( rhosn * cpic ) + lfus / cpic )
+            t_s_1d(ji,jk) = rtt + ( 1._wp - rswitch ) * ( - q_s_1d(ji,jk) / ( rhosn * cpic ) + lfus / cpic )
          END DO
       END DO
@@ -727,5 +718,4 @@
       CALL wrk_dealloc( jpij, zh_s, zqprec, zq_su, zq_bo, zf_tt, zq_1cat, zq_rema )
       CALL wrk_dealloc( jpij, zdh_s_mel, zdh_s_pre, zdh_s_sub, zqh_i, zqh_s, zq_s )
-      CALL wrk_dealloc( jpij, zintermelt )
       CALL wrk_dealloc( jpij, nlay_i+1, zdeltah, zh_i )
       CALL wrk_dealloc( jpij, icount )
