Index: NEMO/trunk/src/ICE/icectl.F90
===================================================================
--- NEMO/trunk/src/ICE/icectl.F90	(revision 13295)
+++ NEMO/trunk/src/ICE/icectl.F90	(revision 13472)
@@ -350,138 +350,136 @@
       !!                   ***  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_2D( 1, 1, 1, 1 )
-            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_2D
       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_2D( 1, 1, 1, 1 )
-         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_2D
-
-      ! 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_2D( 1, 1, 1, 1 )
-         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_2D
-
-      ! Alert on salt flux
-      ialert_id = 5 ! reference number of this alert
-      cl_alname(ialert_id) = ' High salt flux               ' ! name of the alert
-      DO_2D( 1, 1, 1, 1 )
-         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_2D
-
-      ! 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_2D( 1, 1, 1, 1 )
-         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_2D
-
-!
-!     ! 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_2D( 1, 1, 1, 1 )
-            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_2D
       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_2D( 1, 1, 1, 1 )
-         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_2D
-      !+++++
-
-!     ! 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_2D( 1, 1, 1, 1 )
-            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_2D
-      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_3D( 1, 1, 1, 1, 1, nlay_i )
             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
          END_3D
       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_3D( 1, 1, 1, 1, 1, nlay_i )
+            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_3D
+      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_2D( 1, 1, 1, 1 )
+         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_2D
+
+      ! 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_2D( 1, 1, 1, 1 )
+         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_2D
+
+      ! 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_2D( 1, 1, 1, 1 )
+         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_2D
+
+      ! 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_2D( 1, 1, 1, 1 )
+         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_2D
+
+      ! 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_2D( 1, 1, 1, 1 )
+         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_2D
 
       ! 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
@@ -489,10 +487,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
@@ -543,5 +539,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,*) '   ~~~~~~~~~~~ '
@@ -552,4 +547,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)
@@ -588,5 +584,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,*)
                
@@ -605,5 +600,4 @@
                   WRITE(numout,*) ' e_snow     : ', e_s(ji,jj,1,jl)            , ' e_snow_b   : ', e_s_b(ji,jj,1,jl) 
                   WRITE(numout,*) ' sv_i       : ', sv_i(ji,jj,jl)             , ' sv_i_b     : ', sv_i_b(ji,jj,jl)   
-                  WRITE(numout,*) ' oa_i       : ', oa_i(ji,jj,jl)             , ' oa_i_b     : ', oa_i_b(ji,jj,jl)
                END DO !jl
                
@@ -713,5 +707,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        : ')
@@ -721,4 +714,5 @@
             CALL prt_ctl_info(' - Layer : ', ivar=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
