Index: branches/2016/dev_CNRS_2016/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90
===================================================================
--- branches/2016/dev_CNRS_2016/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90	(revision 7278)
+++ branches/2016/dev_CNRS_2016/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90	(revision 7280)
@@ -5,5 +5,5 @@
    !!======================================================================
    !! History :  2.0  ! 2004-01 (C. Ethe, G. Madec)  Original code
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!            3.0  ! 2011-02 (G. Madec) dynamical allocation
    !!             -   ! 2014    (C. Rousset) add N/S initializations
    !!----------------------------------------------------------------------
@@ -25,4 +25,5 @@
    USE dom_ice          ! sea-ice domain
    USE limvar           ! lim_var_salprof
+   !
    USE in_out_manager   ! I/O manager
    USE lib_mpp          ! MPP library
@@ -37,5 +38,5 @@
    PUBLIC   lim_istate      ! routine called by lim_init.F90
 
-   !                          !!** init namelist (namiceini) **
+   !                           !!** init namelist (namiceini) **
    REAL(wp) ::   rn_thres_sst   ! threshold water temperature for initial sea ice
    REAL(wp) ::   rn_hts_ini_n   ! initial snow thickness in the north
@@ -57,5 +58,5 @@
    INTEGER , PARAMETER ::   jp_tmi = 5           ! index of ice temp at T-point
    INTEGER , PARAMETER ::   jp_smi = 6           ! index of ice sali at T-point
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   si    ! structure of input fields (file informations, fields read)
+   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   si  ! structure of input fields (file informations, fields read)
 
    LOGICAL  ::  ln_iceini        ! initialization or not
@@ -74,12 +75,10 @@
       !! ** Purpose :   defined the sea-ice initial state
       !!
-      !! ** Method  :   
-      !!                This routine will put some ice where ocean
+      !! ** Method  :   This routine will put some ice where ocean
       !!                is at the freezing point, then fill in ice 
       !!                state variables using prescribed initial 
       !!                values in the namelist            
       !!
-      !! ** Steps   :   
-      !!                1) Read namelist
+      !! ** Steps   :   1) Read namelist
       !!                2) Basal temperature; ice and hemisphere masks
       !!                3) Fill in the ice thickness distribution using gaussian
@@ -96,9 +95,7 @@
       !!   4.0  !  09-11  (M. Vancoppenolle)   Enhanced version for ice cats
       !!--------------------------------------------------------------------
-
-      !! * Local variables
-      INTEGER    :: ji, jj, jk, jl             ! dummy loop indices
-      REAL(wp)   :: ztmelts, zdh
-      INTEGER    :: i_hemis, i_fill, jl0  
+      INTEGER  :: ji, jj, jk, jl   ! dummy loop indices
+      REAL(wp) :: ztmelts, zdh
+      INTEGER  :: i_hemis, i_fill, jl0  
       REAL(wp)   :: ztest_1, ztest_2, ztest_3, ztest_4, ztests, zsigma, zarg, zA, zV, zA_cons, zV_cons, zconv 
       REAL(wp), POINTER, DIMENSION(:,:)   :: zswitch    ! ice indicator
@@ -108,16 +105,16 @@
       !--------------------------------------------------------------------
 
-      CALL wrk_alloc( jpi, jpj, jpl, zh_i_ini,  za_i_ini,  zv_i_ini )
-      CALL wrk_alloc( jpi, jpj,      zht_i_ini, zat_i_ini, zvt_i_ini, zts_u_ini, zht_s_ini, zsm_i_ini, ztm_i_ini )
-      CALL wrk_alloc( jpi, jpj,      zswitch )
+      CALL wrk_alloc( jpi,jpj,jpl,   zh_i_ini,  za_i_ini,  zv_i_ini )
+      CALL wrk_alloc( jpi,jpj,       zht_i_ini, zat_i_ini, zvt_i_ini, zts_u_ini, zht_s_ini, zsm_i_ini, ztm_i_ini )
+      CALL wrk_alloc( jpi,jpj,       zswitch )
 
       IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'lim_istate : Ice initialization '
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
+      IF(lwp) WRITE(numout,*) 'lim_istate : sea-ice initialization '
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~ '
 
       !--------------------------------------------------------------------
       ! 1) Read namelist
       !--------------------------------------------------------------------
-
+      !
       CALL lim_istate_init     !  reading the initials parameters of the ice
 
@@ -134,9 +131,9 @@
 
       IF( ln_iceini ) THEN
-
+         !
          !--------------------------------------------------------------------
          ! 2) Basal temperature, ice mask and hemispheric index
          !--------------------------------------------------------------------
-
+         !
          DO jj = 1, jpj                                       ! ice if sst <= t-freez + ttest
             DO ji = 1, jpi
@@ -153,5 +150,5 @@
          !--------------------------------------------------------------------
          IF( ln_iceini_file )THEN
-
+            !
             zht_i_ini(:,:)  = si(jp_hti)%fnow(:,:,1)
             zht_s_ini(:,:)  = si(jp_hts)%fnow(:,:,1)
@@ -160,7 +157,7 @@
             ztm_i_ini(:,:)  = si(jp_tmi)%fnow(:,:,1)
             zsm_i_ini(:,:)  = si(jp_smi)%fnow(:,:,1)
-
+            !
          ELSE ! ln_iceini_file = F
-
+            !
             !-----------------------------
             ! 3.1) Hemisphere-dependent arrays
@@ -186,5 +183,5 @@
                END DO
             END DO
-
+            !
          ENDIF ! ln_iceini_file
 
@@ -200,17 +197,17 @@
          za_i_ini(:,:,:) = 0._wp
          zv_i_ini(:,:,:) = 0._wp
-
+         !
          DO jj = 1, jpj
             DO ji = 1, jpi
-
+               !
                IF( zat_i_ini(ji,jj) > 0._wp .AND. zht_i_ini(ji,jj) > 0._wp )THEN
-
-                  ztest_1 = 0 ; ztest_2 = 0 ; ztest_3 = 0 ; ztest_4 = 0
+                  !
+                  ztest_1 = 0   ;   ztest_2 = 0   ;   ztest_3 = 0   ;   ztest_4 = 0
 !                  ztests  = 0 
-
+                  !
                   DO i_fill = jpl, 1, -1
-
-!                     IF( ztests .NE. 4 ) THEN
-                     IF ( ( ztest_1 + ztest_2 + ztest_3 + ztest_4 ) .NE. 4 ) THEN
+                     !
+!                     IF( ztests /= 4 ) THEN
+                     IF ( ( ztest_1 + ztest_2 + ztest_3 + ztest_4 ) /= 4 ) THEN
                         !----------------------------
                         ! fill the i_fill categories
@@ -223,5 +220,5 @@
                            za_i_ini(ji,jj,2:jpl)   = 0._wp
                         ELSE
-
+                           !
                            ! *** >1 categores to fill
                            !--- Ice thicknesses in the i_fill - 1 first categories
@@ -229,5 +226,5 @@
                               zh_i_ini(ji,jj,jl) = hi_mean(jl)
                            END DO
-               
+                           !
                            !--- jl0: most likely index where cc will be maximum
                            DO jl = 1, jpl
@@ -238,9 +235,9 @@
                            END DO
                            jl0 = MIN(jl0, i_fill)
-               
+                           !
                            !--- Concentrations
                            za_i_ini(ji,jj,jl0) = zat_i_ini(ji,jj) / SQRT(REAL(jpl))
                            DO jl = 1, i_fill - 1
-                              IF( jl .NE. jl0 )THEN
+                              IF( jl /= jl0 )THEN
                                  zsigma             = 0.5 * zht_i_ini(ji,jj)
                                  zarg               = ( zh_i_ini(ji,jj,jl) - zht_i_ini(ji,jj) ) / zsigma
@@ -248,5 +245,5 @@
                               ENDIF
                            END DO
-               
+                           !
                            zA = 0. ! sum of the areas in the jpl categories 
                            DO jl = 1, i_fill - 1
@@ -254,6 +251,6 @@
                            END DO
                            za_i_ini(ji,jj,i_fill)   = zat_i_ini(ji,jj) - zA ! ice conc in the last category
-                           IF ( i_fill .LT. jpl ) za_i_ini(ji,jj,i_fill+1:jpl) = 0._wp
-         
+                           IF ( i_fill < jpl ) za_i_ini(ji,jj,i_fill+1:jpl) = 0._wp
+                           !
                            !--- Ice thickness in the last category
                            zV = 0. ! sum of the volumes of the N-1 categories
@@ -262,12 +259,12 @@
                            END DO
                            zh_i_ini(ji,jj,i_fill) = ( zvt_i_ini(ji,jj) - zV ) / za_i_ini(ji,jj,i_fill) 
-                           IF ( i_fill .LT. jpl ) zh_i_ini(ji,jj,i_fill+1:jpl) = 0._wp
-
+                           IF ( i_fill < jpl ) zh_i_ini(ji,jj,i_fill+1:jpl) = 0._wp
+                           !
                            !--- volumes
                            zv_i_ini(ji,jj,:) = za_i_ini(ji,jj,:) * zh_i_ini(ji,jj,:)
-                           IF ( i_fill .LT. jpl ) zv_i_ini(ji,jj,i_fill+1:jpl) = 0._wp
-
+                           IF ( i_fill < jpl ) zv_i_ini(ji,jj,i_fill+1:jpl) = 0._wp
+                           !
                         ENDIF ! i_fill
-
+                        !
                         !---------------------
                         ! Compatibility tests
@@ -275,59 +272,49 @@
                         ! Test 1: area conservation
                         zA_cons = SUM(za_i_ini(ji,jj,:)) ; zconv = ABS(zat_i_ini(ji,jj) - zA_cons )
-                        IF ( zconv .LT. 1.0e-6 ) THEN
-                           ztest_1 = 1
-                        ELSE 
-                          ztest_1 = 0
+                        IF( zconv < 1.0e-6 ) THEN   ;   ztest_1 = 1.
+                        ELSE                        ;   ztest_1 = 0.
                         ENDIF
-
+                        !
                         ! Test 2: volume conservation
                         zV_cons = SUM(zv_i_ini(ji,jj,:))
-                        zconv = ABS(zvt_i_ini(ji,jj) - zV_cons)
-
-                        IF( zconv .LT. 1.0e-6 ) THEN
-                           ztest_2 = 1
-                        ELSE
-                           ztest_2 = 0
+                        zconv   = ABS(zvt_i_ini(ji,jj) - zV_cons)
+                        IF( zconv < 1.0e-6 ) THEN   ;   ztest_2 = 1.
+                        ELSE                        ;   ztest_2 = 0.
                         ENDIF
-
+                        !
                         ! Test 3: thickness of the last category is in-bounds ?
-                        IF ( zh_i_ini(ji,jj,i_fill) > hi_max(i_fill-1) ) THEN
-                           ztest_3 = 1
-                        ELSE
-                           ztest_3 = 0
+                        IF( zh_i_ini(ji,jj,i_fill) > hi_max(i_fill-1) ) THEN   ;   ztest_3 = 1.
+                        ELSE                                                   ;   ztest_3 = 0.
                         ENDIF
-
+                        !
                         ! Test 4: positivity of ice concentrations
                         ztest_4 = 1
                         DO jl = 1, jpl
-                           IF ( za_i_ini(ji,jj,jl) .LT. 0._wp ) THEN 
-                              ztest_4 = 0
-                           ENDIF
+                           IF( za_i_ini(ji,jj,jl) < 0._wp )   ztest_4 = 0
                         END DO
-
+                        !
                      ENDIF ! ztest_1 + ztest_2 + ztest_3 + ztest_4
- 
+                     !
                      ztests = ztest_1 + ztest_2 + ztest_3 + ztest_4
-
+                     !
                   END DO ! i_fill
-
+                  !
                   IF(lwp) THEN 
-                     WRITE(numout,*) ' ztests : ', ztests
-                     IF( ztests .NE. 4 )THEN
+                     IF( ztests /= 4 ) THEN
                         WRITE(numout,*)
                         WRITE(numout,*) ' !!!! ALERT                  !!! '
                         WRITE(numout,*) ' !!!! Something is wrong in the LIM3 initialization procedure '
                         WRITE(numout,*)
-                        WRITE(numout,*) ' *** ztests is not equal to 4 '
+                        WRITE(numout,*) ' *** ztests is not equal to 4 :   ztests : ', ztests
                         WRITE(numout,*) ' *** ztest_i (i=1,4) = ', ztest_1, ztest_2, ztest_3, ztest_4
                         WRITE(numout,*) ' zat_i_ini : ', zat_i_ini(ji,jj)
                         WRITE(numout,*) ' zht_i_ini : ', zht_i_ini(ji,jj)
-                     ENDIF ! ztests .NE. 4
+                     ENDIF ! ztests /= 4
                   ENDIF
-      
+                  !
                ENDIF !  zat_i_ini(ji,jj) > 0._wp .AND. zhm_i_ini(ji,jj) > 0._wp
-
-            ENDDO   
-         ENDDO   
+               !
+            END DO   
+         END DO   
 
          !---------------------------------------------------------------------
