Index: branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceadv.F90
===================================================================
--- branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceadv.F90	(revision 8486)
+++ branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceadv.F90	(revision 8500)
@@ -29,4 +29,5 @@
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
    USE timing         ! Timing
+   USE iom            !
 
    IMPLICIT NONE
@@ -68,5 +69,5 @@
       !
       REAL(wp) ::    zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b
-      REAL(wp) ::    zdv, zda
+      REAL(wp) ::    zdv
       REAL(wp), DIMENSION(jpi,jpj)           ::   zatold, zeiold, zesold, zsmvold 
       REAL(wp), DIMENSION(jpi,jpj,jpl)       ::   zhimax, zviold, zvsold
@@ -80,5 +81,4 @@
       ! MV MP 2016
       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   ::   z0ap , z0vp
-      REAL(wp) ::   za_old
       ! END MV MP 2016
       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) ::   z0ei
@@ -111,13 +111,12 @@
       !--- Thickness correction init. --- !
       zatold(:,:) = at_i
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               rswitch          = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi20 ) )
-               ht_i  (ji,jj,jl) = v_i (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-               ht_s  (ji,jj,jl) = v_s (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-            END DO
-         END DO
-      END DO
+      WHERE( a_i(:,:,:) >= epsi20 )
+         ht_i(:,:,:) = v_i(:,:,:) / a_i(:,:,:)
+         ht_s(:,:,:) = v_s(:,:,:) / a_i(:,:,:)
+      ELSEWHERE
+         ht_i(:,:,:) = 0._wp
+         ht_s(:,:,:) = 0._wp         
+      END WHERE
+         
       ! --- Record max of the surrounding ice thicknesses for correction in case advection creates ice too thick --- !
       zhimax(:,:,:) = ht_i(:,:,:) + ht_s(:,:,:)
@@ -126,5 +125,5 @@
             DO ji = 2, jpim1
 !!gm use of MAXVAL here is very probably less efficient than expending the 9 values
-               zhimax(ji,jj,jl) = MAXVAL( ht_i(ji-1:ji+1,jj-1:jj+1,jl) + ht_s(ji-1:ji+1,jj-1:jj+1,jl) )
+               zhimax(ji,jj,jl) = MAX( epsi20, MAXVAL( ht_i(ji-1:ji+1,jj-1:jj+1,jl) + ht_s(ji-1:ji+1,jj-1:jj+1,jl) ) )
             END DO
          END DO
@@ -399,6 +398,11 @@
          END DO
       END DO
-      
-      IF( nn_limdyn == 2) THEN
+      IF( iom_use('icetrp') )   CALL iom_put( "icetrp" , diag_trp_vi * rday  )         ! ice volume transport
+      IF( iom_use('snwtrp') )   CALL iom_put( "snwtrp" , diag_trp_vs * rday  )         ! snw volume transport
+      IF( iom_use('saltrp') )   CALL iom_put( "saltrp" , diag_trp_smv * rday * rhoic ) ! salt content transport
+      IF( iom_use('deitrp') )   CALL iom_put( "deitrp" , diag_trp_ei         )         ! advected ice enthalpy (W/m2)
+      IF( iom_use('destrp') )   CALL iom_put( "destrp" , diag_trp_es         )         ! advected snw enthalpy (W/m2)
+      
+      IF( nn_limdyn == 2 ) THEN
          !
          CALL ice_var_zapsmall      !--- zap small areas ---!
@@ -407,57 +411,29 @@
             DO jj = 1, jpj
                DO ji = 1, jpi
-                  ! 
                   IF ( v_i(ji,jj,jl) > 0._wp ) THEN
                      !
-                     rswitch          = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,jl) - epsi20 ) )
-                     ht_i  (ji,jj,jl) = v_i (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-                     ht_s  (ji,jj,jl) = v_s (ji,jj,jl) / MAX( a_i(ji,jj,jl) , epsi20 ) * rswitch
-                     !
-                     zdv  = v_i(ji,jj,jl) + v_s(ji,jj,jl) - zviold(ji,jj,jl) - zvsold(ji,jj,jl)  
+                     ht_i  (ji,jj,jl) = v_i (ji,jj,jl) / a_i(ji,jj,jl)
+                     ht_s  (ji,jj,jl) = v_s (ji,jj,jl) / a_i(ji,jj,jl)
+                     zdv = v_i(ji,jj,jl) + v_s(ji,jj,jl) - zviold(ji,jj,jl) - zvsold(ji,jj,jl)  
                      !
                      IF ( ( zdv >  0.0 .AND. (ht_i(ji,jj,jl)+ht_s(ji,jj,jl)) > zhimax(ji,jj,jl) .AND. zatold(ji,jj) < 0.80 ) .OR. &
                         & ( zdv <= 0.0 .AND. (ht_i(ji,jj,jl)+ht_s(ji,jj,jl)) > zhimax(ji,jj,jl) ) ) THEN
-                        !
-                        rswitch        = MAX( 0._wp, SIGN( 1._wp, zhimax(ji,jj,jl) - epsi20 ) )
-                        a_i(ji,jj,jl)  = rswitch * ( v_i(ji,jj,jl) + v_s(ji,jj,jl) ) / MAX( zhimax(ji,jj,jl), epsi20 )
-                        !
-                        ! small correction due to *rswitch for a_i
-                        v_i  (ji,jj,jl)        = rswitch * v_i  (ji,jj,jl)
-                        v_s  (ji,jj,jl)        = rswitch * v_s  (ji,jj,jl)
-                        smv_i(ji,jj,jl)        = rswitch * smv_i(ji,jj,jl)
-                        e_s(ji,jj,1,jl)        = rswitch * e_s(ji,jj,1,jl)
-                        e_i(ji,jj,1:nlay_i,jl) = rswitch * e_i(ji,jj,1:nlay_i,jl)
-
-                        ! MV MP 2016
-                        IF ( nn_pnd_scheme > 0 ) THEN
-                           a_ip (ji,jj,jl)        = rswitch * a_ip (ji,jj,jl)
-                           v_ip (ji,jj,jl)        = rswitch * v_ip (ji,jj,jl)
-                        ENDIF
-                        ! END MV MP 2016
-                        !
+                        a_i (ji,jj,jl) = ( v_i(ji,jj,jl) + v_s(ji,jj,jl) ) / zhimax(ji,jj,jl)
+                        ht_i(ji,jj,jl) =   v_i(ji,jj,jl) / a_i(ji,jj,jl)
                      ENDIF
                      !
                   ENDIF
-                  !
                END DO
             END DO
          END DO
-         
-         DO jj = 1, jpj             !--- bound ht_i to hi_max (99 m).
-            DO ji = 1, jpi
-               ! MV MP 2016
-               za_old = a_i(ji,jj,jpl)
-               ! END MV MP 2016
-               rswitch         = MAX( 0._wp , SIGN( 1._wp, ht_i(ji,jj,jpl) - epsi20 ) )
-               ht_i(ji,jj,jpl) = MIN( ht_i(ji,jj,jpl) , hi_max(jpl) )
-               a_i (ji,jj,jpl) = v_i(ji,jj,jpl) / MAX( ht_i(ji,jj,jpl) , epsi20 ) * rswitch
-               ! MV MP 2016
-               IF ( nn_pnd_scheme > 0 ) THEN
-                  ! correct pond fraction to avoid a_ip > a_i
-                  a_ip(ji,jj,jpl) = a_ip(ji,jj,jpl) * a_i(ji,jj,jpl) / MAX( za_old , epsi20 ) * rswitch
-               ENDIF
-               ! END MP 2016
-            END DO
-         END DO
+                  
+         WHERE( ht_i(:,:,jpl) > hi_max(jpl) )             !--- bound ht_i to hi_max (99 m)
+            ht_i(:,:,jpl) = hi_max(jpl)
+            a_i (:,:,jpl) = v_i(:,:,jpl) / hi_max(jpl)
+         END WHERE
+
+         IF ( nn_pnd_scheme > 0 ) THEN                    !--- correct pond fraction to avoid a_ip > a_i
+            WHERE( a_ip(:,:,:) > a_i(:,:,:) )   a_ip(:,:,:) = a_i(:,:,:)
+         ENDIF
          !
       ENDIF
@@ -467,24 +443,11 @@
       !------------------------------------------------------------
       !
-!!gm remplace the test by, l_piling a logical compute one for all in icestp.F90 (and its declaration in ice.F90
-!!gm      IF ( nn_limdyn == 1 .OR. ( ( nn_monocat == 2 ) .AND. ( jpl == 1 ) ) ) THEN ! simple conservative piling, comparable with LIM2
-      IF( l_piling ) THEN
+      IF( l_piling ) THEN ! simple conservative piling, comparable with 1-cat models
          at_i(:,:) = SUM( a_i(:,:,:), dim=3 )
          DO jl = 1, jpl
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  rswitch = MAX( 0._wp, SIGN( 1._wp, at_i(ji,jj) - epsi20 ) )
-                  zda     = rswitch * MIN( rn_amax_2d(ji,jj) - at_i(ji,jj), 0._wp ) * a_i(ji,jj,jl) / MAX( at_i(ji,jj), epsi20 )
-                  a_i(ji,jj,jl) = a_i(ji,jj,jl) + zda
-               END DO
-            END DO
-         END DO
-!!gm better and faster coding?
-!         DO jl = 1, jpl
-!            WHERE( at_i(:,:) > epsi20 )
-!               a_i(:,:,jl) = a_i(:,:,jl) * (  1._wp + MIN( rn_amax_2d(:,:) - at_i(:,:) , 0._wp ) / at_i(:,:)  )
-!            END WHERE
-!         END DO
-!!gm end
+            WHERE( at_i(:,:) > epsi20 )
+               a_i(:,:,jl) = a_i(:,:,jl) * (  1._wp + MIN( rn_amax_2d(:,:) - at_i(:,:) , 0._wp ) / at_i(:,:)  )
+            END WHERE
+         END DO
       ENDIF
       
