Index: anches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icecor1.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icecor1.F90	(revision 8409)
+++ 	(revision )
@@ -1,153 +1,0 @@
-MODULE icecor1
-   !!======================================================================
-   !!                     ***  MODULE  icecor1  ***
-   !!   LIM-3 : Update of sea-ice global variables at the end of the time step
-   !!======================================================================
-   !! History :  3.0  !  2006-04  (M. Vancoppenolle) Original code
-   !!            3.5  !  2014-06  (C. Rousset)       Complete rewriting/cleaning
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!    ice_cor1   : computes update of sea-ice global variables from trend terms
-   !!----------------------------------------------------------------------
-   USE dom_oce
-   USE phycst          ! physical constants
-   USE ice
-   USE thd_ice         ! LIM thermodynamic sea-ice variables
-   USE limitd_th
-   USE limvar
-   USE limcons         ! conservation tests
-   USE limctl          ! control prints
-   !
-   USE lib_mpp         ! MPP library
-   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE in_out_manager  ! I/O manager
-   USE timing          ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   ice_cor1
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: icecor1.F90 8378 2017-07-26 13:55:59Z clem $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE ice_cor1( kt )
-      !!-------------------------------------------------------------------
-      !!               ***  ROUTINE ice_cor1  ***
-      !!               
-      !! ** Purpose :  Computes update of sea-ice global variables at 
-      !!               the end of the dynamics.
-      !!                
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt    ! number of iteration
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      REAL(wp) ::   zsal
-      REAL(wp) ::   zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
-      !!-------------------------------------------------------------------
-      IF( nn_timing == 1 )  CALL timing_start('icecor1')
-
-      IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*)'' 
-         WRITE(numout,*)' ice_cor1 ' 
-         WRITE(numout,*)' ~~~~~~~~~~~ '
-      ENDIF
-
-      ! conservation test
-      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'icecor1', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      !----------------------------------------------------
-      ! ice concentration should not exceed amax 
-      !-----------------------------------------------------
-      at_i(:,:) = 0._wp
-      DO jl = 1, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-      DO jl  = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( at_i(ji,jj) > rn_amax_2d(ji,jj) .AND. a_i(ji,jj,jl) > 0._wp ) THEN
-                  a_i (ji,jj,jl) = a_i (ji,jj,jl) * ( 1._wp - ( 1._wp - rn_amax_2d(ji,jj) / at_i(ji,jj) ) )
-               ENDIF
-            END DO
-         END DO
-      END DO
-    
-      !---------------------
-      ! Ice salinity bounds
-      !---------------------
-      IF (  nn_icesal == 2  ) THEN 
-         DO jl = 1, jpl
-            DO jj = 1, jpj 
-               DO ji = 1, jpi
-                  zsal            = smv_i(ji,jj,jl)
-                  ! salinity stays in bounds
-                  rswitch         = 1._wp - MAX( 0._wp, SIGN( 1._wp, - v_i(ji,jj,jl) ) )
-                  smv_i(ji,jj,jl) = rswitch * MAX( MIN( rn_simax * v_i(ji,jj,jl), smv_i(ji,jj,jl) ), rn_simin * v_i(ji,jj,jl) )
-                  ! associated salt flux
-                  sfx_res(ji,jj) = sfx_res(ji,jj) - ( smv_i(ji,jj,jl) - zsal ) * rhoic * r1_rdtice
-               END DO
-            END DO
-         END DO
-      ENDIF
-
-      !----------------------------------------------------
-      ! Rebin categories with thickness out of bounds
-      !----------------------------------------------------
-      IF ( jpl > 1 ) CALL lim_itd_th_reb
-
-      !-----------------
-      ! zap small values
-      !-----------------
-      CALL lim_var_zapsmall
-
-      ! -------------------------------------------------
-      ! Diagnostics
-      ! -------------------------------------------------
-      DO jl  = 1, jpl
-         afx_dyn(:,:) = afx_dyn(:,:) + ( a_i(:,:,jl) - a_i_b(:,:,jl) ) * r1_rdtice
-      END DO
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi            
-            ! heat content variation (W.m-2)
-            diag_heat(ji,jj) = - ( SUM( e_i(ji,jj,1:nlay_i,:) - e_i_b(ji,jj,1:nlay_i,:) ) +  & 
-               &                   SUM( e_s(ji,jj,1:nlay_s,:) - e_s_b(ji,jj,1:nlay_s,:) )    &
-               &                 ) * r1_rdtice
-            ! salt, volume
-            diag_smvi(ji,jj) = SUM( smv_i(ji,jj,:) - smv_i_b(ji,jj,:) ) * rhoic * r1_rdtice
-            diag_vice(ji,jj) = SUM( v_i  (ji,jj,:) - v_i_b  (ji,jj,:) ) * rhoic * r1_rdtice
-            diag_vsnw(ji,jj) = SUM( v_s  (ji,jj,:) - v_s_b  (ji,jj,:) ) * rhosn * r1_rdtice
-         END DO
-      END DO
-
-      ! conservation test
-      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'icecor1', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      ! control prints
-      IF( ln_ctl )       CALL lim_prt3D( 'icecor1' )
-   
-      IF( nn_timing == 1 )  CALL timing_stop('icecor1')
-
-   END SUBROUTINE ice_cor1
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Empty Module               No sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE ice_cor1     ! Empty routine
-   END SUBROUTINE ice_cor1
-
-#endif
-
-END MODULE icecor1
Index: anches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icecor2.F90
===================================================================
--- /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icecor2.F90	(revision 8409)
+++ 	(revision )
@@ -1,192 +1,0 @@
-MODULE icecor2
-   !!======================================================================
-   !!                     ***  MODULE  icecor2  ***
-   !!   LIM-3 : Update of sea-ice global variables at the end of the time step
-   !!======================================================================
-   !! History :  3.0  !  2006-04  (M. Vancoppenolle) Original code
-   !!            3.5  !  2014-06  (C. Rousset)       Complete rewriting/cleaning
-   !!----------------------------------------------------------------------
-#if defined key_lim3
-   !!----------------------------------------------------------------------
-   !!   'key_lim3'                                      LIM3 sea-ice model
-   !!----------------------------------------------------------------------
-   !!    ice_cor2   : computes update of sea-ice global variables from trend terms
-   !!----------------------------------------------------------------------
-   USE dom_oce
-   USE phycst          ! physical constants
-   USE ice
-   USE thd_ice         ! LIM thermodynamic sea-ice variables
-   USE limitd_th
-   USE limvar
-   USE limcons         ! conservation tests
-   USE limctl
-   !
-   USE lbclnk          ! lateral boundary condition - MPP exchanges
-   USE lib_mpp         ! MPP library
-   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-   USE in_out_manager
-   USE timing          ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   ice_cor2   ! routine called by ice_step
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
-   !! $Id: icecor2.F90 8378 2017-07-26 13:55:59Z clem $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE ice_cor2( kt )
-      !!-------------------------------------------------------------------
-      !!               ***  ROUTINE ice_cor2  ***
-      !!               
-      !! ** Purpose :  Computes update of sea-ice global variables at 
-      !!               the end of the time step.
-      !!
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt    ! number of iteration
-      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
-      REAL(wp) ::   zsal
-      REAL(wp) ::   zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
-      !!-------------------------------------------------------------------
-      IF( nn_timing == 1 )  CALL timing_start('icecor2')
-
-      IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*)''
-         WRITE(numout,*)' ice_cor2 '
-         WRITE(numout,*)' ~~~~~~~~~~~ '
-      ENDIF
-
-      ! conservation test
-      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'icecor2', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      !----------------------------------------------------------------------
-      ! Constrain the thickness of the smallest category above himin
-      !----------------------------------------------------------------------
-      DO jj = 1, jpj 
-         DO ji = 1, jpi
-            rswitch = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,1) - epsi20 ) )   !0 if no ice and 1 if yes
-            ht_i(ji,jj,1) = v_i (ji,jj,1) / MAX( a_i(ji,jj,1) , epsi20 ) * rswitch
-            IF( v_i(ji,jj,1) > 0._wp .AND. ht_i(ji,jj,1) < rn_himin ) THEN
-               a_i (ji,jj,1) = a_i (ji,jj,1) * ht_i(ji,jj,1) / rn_himin
-            ENDIF
-         END DO
-      END DO
-      
-      !-----------------------------------------------------
-      ! ice concentration should not exceed amax 
-      !-----------------------------------------------------
-      at_i(:,:) = 0._wp
-      DO jl = 1, jpl
-         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
-      END DO
-
-      DO jl  = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF( at_i(ji,jj) > rn_amax_2d(ji,jj) .AND. a_i(ji,jj,jl) > 0._wp ) THEN
-                  a_i (ji,jj,jl) = a_i (ji,jj,jl) * ( 1._wp - ( 1._wp - rn_amax_2d(ji,jj) / at_i(ji,jj) ) )
-               ENDIF
-            END DO
-         END DO
-      END DO
-
-      !---------------------
-      ! Ice salinity
-      !---------------------
-      IF (  nn_icesal == 2  ) THEN 
-         DO jl = 1, jpl
-            DO jj = 1, jpj 
-               DO ji = 1, jpi
-                  zsal            = smv_i(ji,jj,jl)
-                  ! salinity stays in bounds
-                  rswitch         = 1._wp - MAX( 0._wp, SIGN( 1._wp, - v_i(ji,jj,jl) ) )
-                  smv_i(ji,jj,jl) = rswitch * MAX( MIN( rn_simax * v_i(ji,jj,jl), smv_i(ji,jj,jl) ), rn_simin * v_i(ji,jj,jl) )
-                  ! associated salt flux
-                  sfx_res(ji,jj) = sfx_res(ji,jj) - ( smv_i(ji,jj,jl) - zsal ) * rhoic * r1_rdtice
-               END DO
-            END DO
-         END DO
-      ENDIF
-
-      !----------------------------------------------------
-      ! Rebin categories with thickness out of bounds
-      !----------------------------------------------------
-      IF ( jpl > 1 ) CALL lim_itd_th_reb
-
-      !-----------------
-      ! zap small values
-      !-----------------
-      CALL lim_var_zapsmall
-
-      !------------------------------------------------------------------------------
-      ! Corrections to avoid wrong values                                        |
-      !------------------------------------------------------------------------------
-      ! Ice drift
-      !------------
-      DO jj = 2, jpjm1
-         DO ji = 2, jpim1
-            IF ( at_i(ji,jj) == 0._wp ) THEN ! what to do if there is no ice
-               IF ( at_i(ji+1,jj) == 0._wp ) u_ice(ji,jj)   = 0._wp ! right side
-               IF ( at_i(ji-1,jj) == 0._wp ) u_ice(ji-1,jj) = 0._wp ! left side
-               IF ( at_i(ji,jj+1) == 0._wp ) v_ice(ji,jj)   = 0._wp ! upper side
-               IF ( at_i(ji,jj-1) == 0._wp ) v_ice(ji,jj-1) = 0._wp ! bottom side
-            ENDIF
-         END DO
-      END DO
-      !lateral boundary conditions
-      CALL lbc_lnk_multi( u_ice(:,:), 'U', -1., v_ice(:,:), 'V', -1. )
-      !mask velocities
-      u_ice(:,:) = u_ice(:,:) * umask(:,:,1)
-      v_ice(:,:) = v_ice(:,:) * vmask(:,:,1)
- 
-      ! -------------------------------------------------
-      ! Diagnostics
-      ! -------------------------------------------------
-      DO jl  = 1, jpl
-         oa_i(:,:,jl) = oa_i(:,:,jl) + a_i(:,:,jl) * rdt_ice          ! ice natural aging
-         afx_thd(:,:) = afx_thd(:,:) + ( a_i(:,:,jl) - a_i_b(:,:,jl) ) * r1_rdtice
-      END DO
-      afx_tot = afx_thd + afx_dyn
-
-      DO jj = 1, jpj
-         DO ji = 1, jpi            
-            ! heat content variation (W.m-2)
-            diag_heat(ji,jj) = diag_heat(ji,jj) -  &
-               &               ( SUM( e_i(ji,jj,1:nlay_i,:) - e_i_b(ji,jj,1:nlay_i,:) ) +  & 
-               &                 SUM( e_s(ji,jj,1:nlay_s,:) - e_s_b(ji,jj,1:nlay_s,:) )    &
-               &               ) * r1_rdtice   
-            ! salt, volume
-            diag_smvi(ji,jj) = diag_smvi(ji,jj) + SUM( smv_i(ji,jj,:) - smv_i_b(ji,jj,:) ) * rhoic * r1_rdtice
-            diag_vice(ji,jj) = diag_vice(ji,jj) + SUM( v_i  (ji,jj,:) - v_i_b  (ji,jj,:) ) * rhoic * r1_rdtice
-            diag_vsnw(ji,jj) = diag_vsnw(ji,jj) + SUM( v_s  (ji,jj,:) - v_s_b  (ji,jj,:) ) * rhosn * r1_rdtice
-         END DO
-      END DO
-
-      ! conservation test
-      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'icecor2', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
-
-      ! control prints
-      IF( ln_limctl )    CALL lim_prt( kt, iiceprt, jiceprt, 2, ' - Final state - ' )
-      IF( ln_ctl )       CALL lim_prt3D( 'icecor2' )
-   
-      IF( nn_timing == 1 )  CALL timing_stop('icecor2')
-
-   END SUBROUTINE ice_cor2
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option         Empty Module               No sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE ice_cor2     ! Empty routine
-   END SUBROUTINE ice_cor2
-
-#endif
-
-END MODULE icecor2
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 8410)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceerr1.F90	(revision 8410)
@@ -0,0 +1,153 @@
+MODULE iceerr1
+   !!======================================================================
+   !!                     ***  MODULE  iceerr1  ***
+   !!   LIM-3 : Update of sea-ice global variables at the end of the time step
+   !!======================================================================
+   !! History :  3.0  !  2006-04  (M. Vancoppenolle) Original code
+   !!            3.5  !  2014-06  (C. Rousset)       Complete rewriting/cleaning
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!    ice_err1   : computes update of sea-ice global variables from trend terms
+   !!----------------------------------------------------------------------
+   USE dom_oce
+   USE phycst          ! physical constants
+   USE ice
+   USE thd_ice         ! LIM thermodynamic sea-ice variables
+   USE limitd_th
+   USE limvar
+   USE limcons         ! conservation tests
+   USE limctl          ! control prints
+   !
+   USE lib_mpp         ! MPP library
+   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   USE in_out_manager  ! I/O manager
+   USE timing          ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_err1
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! $Id: iceerr1.F90 8378 2017-07-26 13:55:59Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_err1( kt )
+      !!-------------------------------------------------------------------
+      !!               ***  ROUTINE ice_err1  ***
+      !!               
+      !! ** Purpose :  Computes update of sea-ice global variables at 
+      !!               the end of the dynamics.
+      !!                
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt    ! number of iteration
+      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
+      REAL(wp) ::   zsal
+      REAL(wp) ::   zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
+      !!-------------------------------------------------------------------
+      IF( nn_timing == 1 )  CALL timing_start('iceerr1')
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)'' 
+         WRITE(numout,*)' ice_err1 ' 
+         WRITE(numout,*)' ~~~~~~~~~~~ '
+      ENDIF
+
+      ! conservation test
+      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'iceerr1', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+
+      !----------------------------------------------------
+      ! ice concentration should not exceed amax 
+      !-----------------------------------------------------
+      at_i(:,:) = 0._wp
+      DO jl = 1, jpl
+         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+      END DO
+
+      DO jl  = 1, jpl
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( at_i(ji,jj) > rn_amax_2d(ji,jj) .AND. a_i(ji,jj,jl) > 0._wp ) THEN
+                  a_i (ji,jj,jl) = a_i (ji,jj,jl) * ( 1._wp - ( 1._wp - rn_amax_2d(ji,jj) / at_i(ji,jj) ) )
+               ENDIF
+            END DO
+         END DO
+      END DO
+    
+      !---------------------
+      ! Ice salinity bounds
+      !---------------------
+      IF (  nn_icesal == 2  ) THEN 
+         DO jl = 1, jpl
+            DO jj = 1, jpj 
+               DO ji = 1, jpi
+                  zsal            = smv_i(ji,jj,jl)
+                  ! salinity stays in bounds
+                  rswitch         = 1._wp - MAX( 0._wp, SIGN( 1._wp, - v_i(ji,jj,jl) ) )
+                  smv_i(ji,jj,jl) = rswitch * MAX( MIN( rn_simax * v_i(ji,jj,jl), smv_i(ji,jj,jl) ), rn_simin * v_i(ji,jj,jl) )
+                  ! associated salt flux
+                  sfx_res(ji,jj) = sfx_res(ji,jj) - ( smv_i(ji,jj,jl) - zsal ) * rhoic * r1_rdtice
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+      !----------------------------------------------------
+      ! Rebin categories with thickness out of bounds
+      !----------------------------------------------------
+      IF ( jpl > 1 ) CALL lim_itd_th_reb
+
+      !-----------------
+      ! zap small values
+      !-----------------
+      CALL lim_var_zapsmall
+
+      ! -------------------------------------------------
+      ! Diagnostics
+      ! -------------------------------------------------
+      DO jl  = 1, jpl
+         afx_dyn(:,:) = afx_dyn(:,:) + ( a_i(:,:,jl) - a_i_b(:,:,jl) ) * r1_rdtice
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi            
+            ! heat content variation (W.m-2)
+            diag_heat(ji,jj) = - ( SUM( e_i(ji,jj,1:nlay_i,:) - e_i_b(ji,jj,1:nlay_i,:) ) +  & 
+               &                   SUM( e_s(ji,jj,1:nlay_s,:) - e_s_b(ji,jj,1:nlay_s,:) )    &
+               &                 ) * r1_rdtice
+            ! salt, volume
+            diag_smvi(ji,jj) = SUM( smv_i(ji,jj,:) - smv_i_b(ji,jj,:) ) * rhoic * r1_rdtice
+            diag_vice(ji,jj) = SUM( v_i  (ji,jj,:) - v_i_b  (ji,jj,:) ) * rhoic * r1_rdtice
+            diag_vsnw(ji,jj) = SUM( v_s  (ji,jj,:) - v_s_b  (ji,jj,:) ) * rhosn * r1_rdtice
+         END DO
+      END DO
+
+      ! conservation test
+      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'iceerr1', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+
+      ! control prints
+      IF( ln_ctl )       CALL lim_prt3D( 'iceerr1' )
+   
+      IF( nn_timing == 1 )  CALL timing_stop('iceerr1')
+
+   END SUBROUTINE ice_err1
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty Module               No sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE ice_err1     ! Empty routine
+   END SUBROUTINE ice_err1
+
+#endif
+
+END MODULE iceerr1
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 8410)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceerr2.F90	(revision 8410)
@@ -0,0 +1,192 @@
+MODULE iceerr2
+   !!======================================================================
+   !!                     ***  MODULE  iceerr2  ***
+   !!   LIM-3 : Update of sea-ice global variables at the end of the time step
+   !!======================================================================
+   !! History :  3.0  !  2006-04  (M. Vancoppenolle) Original code
+   !!            3.5  !  2014-06  (C. Rousset)       Complete rewriting/cleaning
+   !!----------------------------------------------------------------------
+#if defined key_lim3
+   !!----------------------------------------------------------------------
+   !!   'key_lim3'                                      LIM3 sea-ice model
+   !!----------------------------------------------------------------------
+   !!    ice_err2   : computes update of sea-ice global variables from trend terms
+   !!----------------------------------------------------------------------
+   USE dom_oce
+   USE phycst          ! physical constants
+   USE ice
+   USE thd_ice         ! LIM thermodynamic sea-ice variables
+   USE limitd_th
+   USE limvar
+   USE limcons         ! conservation tests
+   USE limctl
+   !
+   USE lbclnk          ! lateral boundary condition - MPP exchanges
+   USE lib_mpp         ! MPP library
+   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   USE in_out_manager
+   USE timing          ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   ice_err2   ! routine called by ice_step
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
+   !! $Id: iceerr2.F90 8378 2017-07-26 13:55:59Z clem $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ice_err2( kt )
+      !!-------------------------------------------------------------------
+      !!               ***  ROUTINE ice_err2  ***
+      !!               
+      !! ** Purpose :  Computes update of sea-ice global variables at 
+      !!               the end of the time step.
+      !!
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt    ! number of iteration
+      INTEGER  ::   ji, jj, jk, jl   ! dummy loop indices
+      REAL(wp) ::   zsal
+      REAL(wp) ::   zvi_b, zsmv_b, zei_b, zfs_b, zfw_b, zft_b 
+      !!-------------------------------------------------------------------
+      IF( nn_timing == 1 )  CALL timing_start('iceerr2')
+
+      IF( kt == nit000 .AND. lwp ) THEN
+         WRITE(numout,*)''
+         WRITE(numout,*)' ice_err2 '
+         WRITE(numout,*)' ~~~~~~~~~~~ '
+      ENDIF
+
+      ! conservation test
+      IF( ln_limdiachk ) CALL lim_cons_hsm(0, 'iceerr2', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+
+      !----------------------------------------------------------------------
+      ! Constrain the thickness of the smallest category above himin
+      !----------------------------------------------------------------------
+      DO jj = 1, jpj 
+         DO ji = 1, jpi
+            rswitch = MAX( 0._wp , SIGN( 1._wp, a_i(ji,jj,1) - epsi20 ) )   !0 if no ice and 1 if yes
+            ht_i(ji,jj,1) = v_i (ji,jj,1) / MAX( a_i(ji,jj,1) , epsi20 ) * rswitch
+            IF( v_i(ji,jj,1) > 0._wp .AND. ht_i(ji,jj,1) < rn_himin ) THEN
+               a_i (ji,jj,1) = a_i (ji,jj,1) * ht_i(ji,jj,1) / rn_himin
+            ENDIF
+         END DO
+      END DO
+      
+      !-----------------------------------------------------
+      ! ice concentration should not exceed amax 
+      !-----------------------------------------------------
+      at_i(:,:) = 0._wp
+      DO jl = 1, jpl
+         at_i(:,:) = a_i(:,:,jl) + at_i(:,:)
+      END DO
+
+      DO jl  = 1, jpl
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( at_i(ji,jj) > rn_amax_2d(ji,jj) .AND. a_i(ji,jj,jl) > 0._wp ) THEN
+                  a_i (ji,jj,jl) = a_i (ji,jj,jl) * ( 1._wp - ( 1._wp - rn_amax_2d(ji,jj) / at_i(ji,jj) ) )
+               ENDIF
+            END DO
+         END DO
+      END DO
+
+      !---------------------
+      ! Ice salinity
+      !---------------------
+      IF (  nn_icesal == 2  ) THEN 
+         DO jl = 1, jpl
+            DO jj = 1, jpj 
+               DO ji = 1, jpi
+                  zsal            = smv_i(ji,jj,jl)
+                  ! salinity stays in bounds
+                  rswitch         = 1._wp - MAX( 0._wp, SIGN( 1._wp, - v_i(ji,jj,jl) ) )
+                  smv_i(ji,jj,jl) = rswitch * MAX( MIN( rn_simax * v_i(ji,jj,jl), smv_i(ji,jj,jl) ), rn_simin * v_i(ji,jj,jl) )
+                  ! associated salt flux
+                  sfx_res(ji,jj) = sfx_res(ji,jj) - ( smv_i(ji,jj,jl) - zsal ) * rhoic * r1_rdtice
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+      !----------------------------------------------------
+      ! Rebin categories with thickness out of bounds
+      !----------------------------------------------------
+      IF ( jpl > 1 ) CALL lim_itd_th_reb
+
+      !-----------------
+      ! zap small values
+      !-----------------
+      CALL lim_var_zapsmall
+
+      !------------------------------------------------------------------------------
+      ! Corrections to avoid wrong values                                        |
+      !------------------------------------------------------------------------------
+      ! Ice drift
+      !------------
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            IF ( at_i(ji,jj) == 0._wp ) THEN ! what to do if there is no ice
+               IF ( at_i(ji+1,jj) == 0._wp ) u_ice(ji,jj)   = 0._wp ! right side
+               IF ( at_i(ji-1,jj) == 0._wp ) u_ice(ji-1,jj) = 0._wp ! left side
+               IF ( at_i(ji,jj+1) == 0._wp ) v_ice(ji,jj)   = 0._wp ! upper side
+               IF ( at_i(ji,jj-1) == 0._wp ) v_ice(ji,jj-1) = 0._wp ! bottom side
+            ENDIF
+         END DO
+      END DO
+      !lateral boundary conditions
+      CALL lbc_lnk_multi( u_ice(:,:), 'U', -1., v_ice(:,:), 'V', -1. )
+      !mask velocities
+      u_ice(:,:) = u_ice(:,:) * umask(:,:,1)
+      v_ice(:,:) = v_ice(:,:) * vmask(:,:,1)
+ 
+      ! -------------------------------------------------
+      ! Diagnostics
+      ! -------------------------------------------------
+      DO jl  = 1, jpl
+         oa_i(:,:,jl) = oa_i(:,:,jl) + a_i(:,:,jl) * rdt_ice          ! ice natural aging
+         afx_thd(:,:) = afx_thd(:,:) + ( a_i(:,:,jl) - a_i_b(:,:,jl) ) * r1_rdtice
+      END DO
+      afx_tot = afx_thd + afx_dyn
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi            
+            ! heat content variation (W.m-2)
+            diag_heat(ji,jj) = diag_heat(ji,jj) -  &
+               &               ( SUM( e_i(ji,jj,1:nlay_i,:) - e_i_b(ji,jj,1:nlay_i,:) ) +  & 
+               &                 SUM( e_s(ji,jj,1:nlay_s,:) - e_s_b(ji,jj,1:nlay_s,:) )    &
+               &               ) * r1_rdtice   
+            ! salt, volume
+            diag_smvi(ji,jj) = diag_smvi(ji,jj) + SUM( smv_i(ji,jj,:) - smv_i_b(ji,jj,:) ) * rhoic * r1_rdtice
+            diag_vice(ji,jj) = diag_vice(ji,jj) + SUM( v_i  (ji,jj,:) - v_i_b  (ji,jj,:) ) * rhoic * r1_rdtice
+            diag_vsnw(ji,jj) = diag_vsnw(ji,jj) + SUM( v_s  (ji,jj,:) - v_s_b  (ji,jj,:) ) * rhosn * r1_rdtice
+         END DO
+      END DO
+
+      ! conservation test
+      IF( ln_limdiachk ) CALL lim_cons_hsm(1, 'iceerr2', zvi_b, zsmv_b, zei_b, zfw_b, zfs_b, zft_b)
+
+      ! control prints
+      IF( ln_limctl )    CALL lim_prt( kt, iiceprt, jiceprt, 2, ' - Final state - ' )
+      IF( ln_ctl )       CALL lim_prt3D( 'iceerr2' )
+   
+      IF( nn_timing == 1 )  CALL timing_stop('iceerr2')
+
+   END SUBROUTINE ice_err2
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option         Empty Module               No sea-ice model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE ice_err2     ! Empty routine
+   END SUBROUTINE ice_err2
+
+#endif
+
+END MODULE iceerr2
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 8409)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/icestp.F90	(revision 8410)
@@ -40,6 +40,6 @@
    USE limwri          ! Ice outputs
    USE limrst          ! Ice restarts
-   USE icecor1         ! Ice corrections after dynamics
-   USE icecor2         ! Ice corrections after thermo
+   USE iceerr1         ! Ice corrections after dynamics
+   USE iceerr2         ! Ice corrections after thermo
    USE limvar          ! Ice variables switch
    USE limctl          !
@@ -157,5 +157,5 @@
             IF( nn_limdyn == 2 .AND. nn_monocat /= 2 )  &      ! -- ridging/rafting
                &                      CALL ice_rdgrft         
-            IF( nn_limdyn == 2 )      CALL ice_cor1( kt )      ! -- Corrections
+            IF( nn_limdyn == 2 )      CALL ice_err1( kt )      ! -- Corrections
             !
          ENDIF
@@ -196,5 +196,5 @@
          ! END MV MP 2016
 
-         IF( ln_limthd )              CALL ice_cor2( kt )       ! -- Corrections
+         IF( ln_limthd )              CALL ice_err2( kt )       ! -- Corrections
          ! ---
 # if defined key_agrif
Index: /branches/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 8409)
+++ /branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/limitd_th.F90	(revision 8410)
@@ -36,5 +36,5 @@
 
    PUBLIC   lim_itd_th_rem   ! called in limthd
-   PUBLIC   lim_itd_th_reb   ! called in icecor
+   PUBLIC   lim_itd_th_reb   ! called in iceerr
 
    !!----------------------------------------------------------------------
