Index: NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/ICE/icectl.F90
===================================================================
--- NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/ICE/icectl.F90	(revision 13148)
+++ NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/ICE/icectl.F90	(revision 13168)
@@ -350,27 +350,28 @@
       !!                   ***  ROUTINE ice_ctl *** 
       !!                 
-      !! ** Purpose :   Alerts in case of model crash
+      !! ** Purpose :   control checks
       !!-------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt      ! ocean time step
-      INTEGER  ::   ji, jj, jk,  jl   ! dummy loop indices
-      INTEGER  ::   inb_altests       ! number of alert tests (max 20)
-      INTEGER  ::   ialert_id         ! number of the current alert
-      REAL(wp) ::   ztmelts           ! ice layer melting point
+      INTEGER  ::   ja, ji, jj, jk, jl ! dummy loop indices
+      INTEGER  ::   ialert_id          ! number of the current alert
+      REAL(wp) ::   ztmelts            ! ice layer melting point
       CHARACTER (len=30), DIMENSION(20) ::   cl_alname   ! name of alert
       INTEGER           , DIMENSION(20) ::   inb_alp     ! number of alerts positive
       !!-------------------------------------------------------------------
-
-      inb_altests = 10
-      inb_alp(:)  =  0
-
-      ! Alert if incompatible volume and concentration
-      ialert_id = 2 ! reference number of this alert
-      cl_alname(ialert_id) = ' Incompat vol and con         '    ! name of the alert
+      inb_alp(:) = 0
+      ialert_id = 0
+      
+      ! Alert if very high salinity
+      ialert_id = ialert_id + 1 ! reference number of this alert
+      cl_alname(ialert_id) = ' Very high salinity ' ! name of the alert
       DO jl = 1, jpl
          DO jj = 1, jpj
             DO ji = 1, jpi
-               IF(  v_i(ji,jj,jl) /= 0._wp   .AND.   a_i(ji,jj,jl) == 0._wp   ) THEN
-                  WRITE(numout,*) ' ALERTE 2 :   Incompatible volume and concentration '
-                  inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+               IF( v_i(ji,jj,jl) > epsi10  ) THEN
+                  IF( sv_i(ji,jj,jl) / v_i(ji,jj,jl) > rn_simax ) THEN
+                     WRITE(numout,*) ' ALERTE :   Very high salinity ',sv_i(ji,jj,jl)/v_i(ji,jj,jl)
+                     WRITE(numout,*) ' at i,j,l = ',ji,jj,jl
+                     inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+                  ENDIF
                ENDIF
             END DO
@@ -378,111 +379,24 @@
       END DO
 
-      ! Alerte if very thick ice
-      ialert_id = 3 ! reference number of this alert
-      cl_alname(ialert_id) = ' Very thick ice               ' ! name of the alert
-      jl = jpl 
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF(   h_i(ji,jj,jl)  >  50._wp   ) THEN
-               WRITE(numout,*) ' ALERTE 3 :   Very thick ice'
-               !CALL ice_prt( kt, ji, jj, 2, ' ALERTE 3 :   Very thick ice ' )
-               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-            ENDIF
-         END DO
-      END DO
-
-      ! Alert if very fast ice
-      ialert_id = 4 ! reference number of this alert
-      cl_alname(ialert_id) = ' Very fast ice               ' ! name of the alert
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF(   MAX( ABS( u_ice(ji,jj) ), ABS( v_ice(ji,jj) ) ) > 2.  .AND.  &
-               &  at_i(ji,jj) > 0._wp   ) THEN
-               WRITE(numout,*) ' ALERTE 4 :   Very fast ice'
-               !CALL ice_prt( kt, ji, jj, 1, ' ALERTE 4 :   Very fast ice ' )
-               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-            ENDIF
-         END DO
-      END DO
-
-      ! Alert on salt flux
-      ialert_id = 5 ! reference number of this alert
-      cl_alname(ialert_id) = ' High salt flux               ' ! name of the alert
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( ABS( sfx (ji,jj) ) > 1.0e-2 ) THEN  ! = 1 psu/day for 1m ocean depth
-               WRITE(numout,*) ' ALERTE 5 :   High salt flux'
-               !CALL ice_prt( kt, ji, jj, 3, ' ALERTE 5 :   High salt flux ' )
-               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-            ENDIF
-         END DO
-      END DO
-
-      ! Alert if there is ice on continents
-      ialert_id = 6 ! reference number of this alert
-      cl_alname(ialert_id) = ' Ice on continents           ' ! name of the alert
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF(   tmask(ji,jj,1) <= 0._wp   .AND.   at_i(ji,jj) > 0._wp   ) THEN 
-               WRITE(numout,*) ' ALERTE 6 :   Ice on continents'
-               !CALL ice_prt( kt, ji, jj, 1, ' ALERTE 6 :   Ice on continents ' )
-               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-            ENDIF
-         END DO
-      END DO
-
-!
-!     ! Alert if very fresh ice
-      ialert_id = 7 ! reference number of this alert
-      cl_alname(ialert_id) = ' Very fresh ice               ' ! name of the alert
+      ! Alert if very low salinity
+      ialert_id = ialert_id + 1 ! reference number of this alert
+      cl_alname(ialert_id) = ' Very low salinity ' ! name of the alert
       DO jl = 1, jpl
          DO jj = 1, jpj
             DO ji = 1, jpi
-               IF( s_i(ji,jj,jl) < 0.1 .AND. a_i(ji,jj,jl) > 0._wp ) THEN
-                  WRITE(numout,*) ' ALERTE 7 :   Very fresh ice'
-!                 CALL ice_prt(kt,ji,jj,1, ' ALERTE 7 :   Very fresh ice ' )
-                  inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+               IF( v_i(ji,jj,jl) > epsi10  ) THEN
+                  IF( sv_i(ji,jj,jl) / v_i(ji,jj,jl) < rn_simin ) THEN
+                     WRITE(numout,*) ' ALERTE :   Very low salinity ',sv_i(ji,jj,jl),v_i(ji,jj,jl)
+                     WRITE(numout,*) ' at i,j,l = ',ji,jj,jl
+                     inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+                  ENDIF
                ENDIF
             END DO
          END DO
       END DO
-!
-      ! Alert if qns very big
-      ialert_id = 8 ! reference number of this alert
-      cl_alname(ialert_id) = ' fnsolar very big             ' ! name of the alert
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( ABS( qns(ji,jj) ) > 1500._wp .AND. at_i(ji,jj) > 0._wp ) THEN
-               !
-               WRITE(numout,*) ' ALERTE 8 :   Very high non-solar heat flux'
-               !CALL ice_prt( kt, ji, jj, 2, '   ')
-               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-               !
-            ENDIF
-         END DO
-      END DO
-      !+++++
-
-!     ! Alert if too old ice
-      ialert_id = 9 ! reference number of this alert
-      cl_alname(ialert_id) = ' Very old   ice               ' ! name of the alert
-      DO jl = 1, jpl
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               IF ( ( ( ABS( o_i(ji,jj,jl) ) > rdt_ice ) .OR. &
-                      ( ABS( o_i(ji,jj,jl) ) < 0._wp) ) .AND. &
-                             ( a_i(ji,jj,jl) > 0._wp ) ) THEN
-                  WRITE(numout,*) ' ALERTE 9 :   Wrong ice age'
-                  !CALL ice_prt( kt, ji, jj, 1, ' ALERTE 9 :   Wrong ice age ')
-                  inb_alp(ialert_id) = inb_alp(ialert_id) + 1
-               ENDIF
-            END DO
-         END DO
-      END DO
-  
-      ! Alert if very warm ice
-      ialert_id = 10 ! reference number of this alert
-      cl_alname(ialert_id) = ' Very warm ice                ' ! name of the alert
-      inb_alp(ialert_id) = 0
+
+      ! Alert if very cold ice
+      ialert_id = ialert_id + 1 ! reference number of this alert
+      cl_alname(ialert_id) = ' Very cold ice ' ! name of the alert
       DO jl = 1, jpl
          DO jk = 1, nlay_i
@@ -490,7 +404,7 @@
                DO ji = 1, jpi
                   ztmelts    =  -rTmlt * sz_i(ji,jj,jk,jl) + rt0
-                  IF( t_i(ji,jj,jk,jl) > ztmelts  .AND.  v_i(ji,jj,jl) > 1.e-10   &
-                     &                            .AND.  a_i(ji,jj,jl) > 0._wp   ) THEN
-                     WRITE(numout,*) ' ALERTE 10 :   Very warm ice'
+                  IF( t_i(ji,jj,jk,jl) < -50.+rt0  .AND.  v_i(ji,jj,jl) > epsi10 ) THEN
+                     WRITE(numout,*) ' ALERTE :   Very cold ice ',(t_i(ji,jj,jk,jl)-rt0)
+                     WRITE(numout,*) ' at i,j,k,l = ',ji,jj,jk,jl
                     inb_alp(ialert_id) = inb_alp(ialert_id) + 1
                   ENDIF
@@ -499,9 +413,95 @@
          END DO
       END DO
+  
+      ! Alert if very warm ice
+      ialert_id = ialert_id + 1 ! reference number of this alert
+      cl_alname(ialert_id) = ' Very warm ice ' ! name of the alert
+      DO jl = 1, jpl
+         DO jk = 1, nlay_i
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ztmelts    =  -rTmlt * sz_i(ji,jj,jk,jl) + rt0
+                  IF( t_i(ji,jj,jk,jl) > ztmelts  .AND.  v_i(ji,jj,jl) > epsi10 ) THEN
+                     WRITE(numout,*) ' ALERTE :   Very warm ice',(t_i(ji,jj,jk,jl)-rt0)
+                     WRITE(numout,*) ' at i,j,k,l = ',ji,jj,jk,jl
+                    inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+                  ENDIF
+               END DO
+            END DO
+         END DO
+      END DO
+      
+      ! Alerte if very thick ice
+      ialert_id = ialert_id + 1 ! reference number of this alert
+      cl_alname(ialert_id) = ' Very thick ice ' ! name of the alert
+      jl = jpl 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( h_i(ji,jj,jl) > 50._wp ) THEN
+               WRITE(numout,*) ' ALERTE :   Very thick ice ',h_i(ji,jj,jl)
+               WRITE(numout,*) ' at i,j,l = ',ji,jj,jl
+               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+            ENDIF
+         END DO
+      END DO
+
+      ! Alerte if very thin ice
+      ialert_id = ialert_id + 1 ! reference number of this alert
+      cl_alname(ialert_id) = ' Very thin ice ' ! name of the alert
+      jl = 1 
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( h_i(ji,jj,jl) < rn_himin ) THEN
+               WRITE(numout,*) ' ALERTE :   Very thin ice ',h_i(ji,jj,jl)
+               WRITE(numout,*) ' at i,j,l = ',ji,jj,jl
+               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+            ENDIF
+         END DO
+      END DO
+
+      ! Alert if very fast ice
+      ialert_id = ialert_id + 1 ! reference number of this alert
+      cl_alname(ialert_id) = ' Very fast ice ' ! name of the alert
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( MAX( ABS( u_ice(ji,jj) ), ABS( v_ice(ji,jj) ) ) > 2. ) THEN
+               WRITE(numout,*) ' ALERTE :   Very fast ice ',MAX( ABS( u_ice(ji,jj) ), ABS( v_ice(ji,jj) ) )
+               WRITE(numout,*) ' at i,j = ',ji,jj
+               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+            ENDIF
+         END DO
+      END DO
+
+      ! Alert if there is ice on continents
+      ialert_id = ialert_id + 1 ! reference number of this alert
+      cl_alname(ialert_id) = ' Ice on continents ' ! name of the alert
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( tmask(ji,jj,1) == 0._wp .AND. ( at_i(ji,jj) > 0._wp .OR. vt_i(ji,jj) > 0._wp ) ) THEN 
+               WRITE(numout,*) ' ALERTE :   Ice on continents ',at_i(ji,jj),vt_i(ji,jj)
+               WRITE(numout,*) ' at i,j = ',ji,jj
+               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+            ENDIF
+         END DO
+      END DO
+
+      ! Alert if incompatible ice concentration and volume
+      ialert_id = ialert_id + 1 ! reference number of this alert
+      cl_alname(ialert_id) = ' Incompatible ice conc and vol ' ! name of the alert
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF(  ( vt_i(ji,jj) == 0._wp .AND. at_i(ji,jj) >  0._wp ) .OR. &
+               & ( vt_i(ji,jj) >  0._wp .AND. at_i(ji,jj) == 0._wp ) ) THEN 
+               WRITE(numout,*) ' ALERTE :   Incompatible ice conc and vol ',at_i(ji,jj),vt_i(ji,jj)
+               WRITE(numout,*) ' at i,j = ',ji,jj
+               inb_alp(ialert_id) = inb_alp(ialert_id) + 1
+            ENDIF
+         END DO
+      END DO
 
       ! sum of the alerts on all processors
       IF( lk_mpp ) THEN
-         DO ialert_id = 1, inb_altests
-            CALL mpp_sum('icectl', inb_alp(ialert_id))
+         DO ja = 1, ialert_id
+            CALL mpp_sum('icectl', inb_alp(ja))
          END DO
       ENDIF
@@ -509,10 +509,8 @@
       ! print alerts
       IF( lwp ) THEN
-         ialert_id = 1                                 ! reference number of this alert
-         cl_alname(ialert_id) = ' NO alerte 1      '   ! name of the alert
          WRITE(numout,*) ' time step ',kt
          WRITE(numout,*) ' All alerts at the end of ice model '
-         DO ialert_id = 1, inb_altests
-            WRITE(numout,*) ialert_id, cl_alname(ialert_id)//' : ', inb_alp(ialert_id), ' times ! '
+         DO ja = 1, ialert_id
+            WRITE(numout,*) ja, cl_alname(ja)//' : ', inb_alp(ja), ' times ! '
          END DO
       ENDIF
@@ -563,5 +561,4 @@
                WRITE(numout,*) ' v_ice(i  ,j)  : ', v_ice(ji,jj)
                WRITE(numout,*) ' strength      : ', strength(ji,jj)
-               WRITE(numout,*)
                WRITE(numout,*) ' - Cell values '
                WRITE(numout,*) '   ~~~~~~~~~~~ '
@@ -572,4 +569,5 @@
                DO jl = 1, jpl
                   WRITE(numout,*) ' - Category (', jl,')'
+                  WRITE(numout,*) '   ~~~~~~~~~~~ '
                   WRITE(numout,*) ' a_i           : ', a_i(ji,jj,jl)
                   WRITE(numout,*) ' h_i           : ', h_i(ji,jj,jl)
@@ -608,5 +606,4 @@
                WRITE(numout,*) ' v_ice(i  ,j)  : ', v_ice(ji,jj)
                WRITE(numout,*) ' strength      : ', strength(ji,jj)
-               WRITE(numout,*) ' u_ice_b       : ', u_ice_b(ji,jj)    , ' v_ice_b       : ', v_ice_b(ji,jj)  
                WRITE(numout,*)
                
@@ -732,5 +729,4 @@
          CALL prt_ctl(tab2d_1=v_i        (:,:,jl)        , clinfo1= ' v_i         : ')
          CALL prt_ctl(tab2d_1=v_s        (:,:,jl)        , clinfo1= ' v_s         : ')
-         CALL prt_ctl(tab2d_1=e_i        (:,:,1,jl)      , clinfo1= ' e_i1        : ')
          CALL prt_ctl(tab2d_1=e_s        (:,:,1,jl)      , clinfo1= ' e_snow      : ')
          CALL prt_ctl(tab2d_1=sv_i       (:,:,jl)        , clinfo1= ' sv_i        : ')
@@ -740,4 +736,5 @@
             CALL prt_ctl_info(' - Layer : ', ivar1=jk)
             CALL prt_ctl(tab2d_1=t_i(:,:,jk,jl) , clinfo1= ' t_i       : ')
+            CALL prt_ctl(tab2d_1=e_i(:,:,jk,jl) , clinfo1= ' e_i       : ')
          END DO
       END DO
