Index: /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90
===================================================================
--- /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90	(revision 7059)
+++ /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/LIM_SRC_3/limistate.F90	(revision 7060)
@@ -108,37 +108,22 @@
       ! 1) Read namelist
       !--------------------------------------------------------------------
-
-      CALL lim_istate_init     !  reading the initials parameters of the ice
-
-      ! surface temperature
-      DO jl = 1, jpl ! loop over categories
+      CALL lim_istate_init
+
+      ! init surface temperature
+      DO jl = 1, jpl
          t_su  (:,:,jl) = rt0 * tmask(:,:,1)
          tn_ice(:,:,jl) = rt0 * tmask(:,:,1)
       END DO
 
-      ! basal temperature (considered at freezing point)
+      ! init basal temperature (considered at freezing point)
       CALL eos_fzp( sss_m(:,:), t_bo(:,:) )
       t_bo(:,:) = ( t_bo(:,:) + rt0 ) * tmask(:,:,1) 
 
 
+      !--------------------------------------------------------------------
+      ! 2) Initialization of sea ice state variables
+      !--------------------------------------------------------------------
       IF( ln_limini ) THEN
 
-         !--------------------------------------------------------------------
-         ! 2) Basal temperature, ice mask and hemispheric index
-         !--------------------------------------------------------------------
-
-         DO jj = 1, jpj                                       ! ice if sst <= t-freez + ttest
-            DO ji = 1, jpi
-               IF( ( sst_m(ji,jj)  - ( t_bo(ji,jj) - rt0 ) ) * tmask(ji,jj,1) >= rn_thres_sst * tmask(ji,jj,1) ) THEN
-                  zswitch(ji,jj) = 0._wp                     ! no ice
-               ELSE                                                                                   
-                  zswitch(ji,jj) = 1._wp * tmask(ji,jj,1)    !    ice
-               ENDIF
-            END DO
-         END DO
-
-         !--------------------------------------------------------------------
-         ! 3) Initialization of sea ice state variables
-         !--------------------------------------------------------------------
          IF( ln_limini_file )THEN
 
@@ -150,5 +135,17 @@
             zsm_i_ini(:,:)  = si(jp_smi)%fnow(:,:,1)
 
+            WHERE( zat_i_ini(:,:) > 0._wp ) ; zswitch(:,:) = tmask(:,:,1) 
+            ELSEWHERE                       ; zswitch(:,:) = 0._wp
+            END WHERE
+
          ELSE ! ln_limini_file = F
+
+            !--------------------------------------------------------------------
+            ! 3) Basal temperature, ice mask
+            !--------------------------------------------------------------------
+            ! no ice if sst <= t-freez + ttest
+            WHERE( ( sst_m(:,:) - (t_bo(:,:) - rt0) ) * tmask(:,:,1) >= rn_thres_sst ) ; zswitch(:,:) = 0._wp 
+            ELSEWHERE                                                                  ; zswitch(:,:) = tmask(:,:,1)
+            END WHERE
 
             !-----------------------------
@@ -457,6 +454,6 @@
 !!      ! Output the initial state and forcings
 !!      CALL dia_wri_state( 'output.init', nit000 )
-!!!
-      
+!!!      
+
       CALL wrk_dealloc( jpi, jpj, jpl, zh_i_ini,  za_i_ini )
       CALL wrk_dealloc( jpi, jpj,      zht_i_ini, zat_i_ini, zvt_i_ini, zts_u_ini, zht_s_ini, zsm_i_ini, ztm_i_ini )
Index: /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_ice.F90
===================================================================
--- /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_ice.F90	(revision 7059)
+++ /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_ice.F90	(revision 7060)
@@ -60,7 +60,5 @@
    END FUNCTION agrif_ice_alloc
 
-#endif
-
-#if defined key_agrif && defined key_lim3
+#elif defined key_agrif && defined key_lim3
    !!----------------------------------------------------------------------
    !!   'key_agrif'                                              AGRIF zoom
Index: /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_lim3_interp.F90
===================================================================
--- /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_lim3_interp.F90	(revision 7059)
+++ /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_lim3_interp.F90	(revision 7060)
@@ -134,6 +134,6 @@
       !! put -9999 WHERE the parent grid is masked. The child solution will be found in the 9(?) points around
       !!-----------------------------------------------------------------------
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab
       INTEGER , INTENT(in) :: i1, i2, j1, j2, k1, k2
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab
       LOGICAL , INTENT(in) :: before
       !!
@@ -142,4 +142,5 @@
       ! clem: pkoi on n'utilise pas les quantités intégrées ici => before: * e12t ; after: * r1_e12t / rhox / rhoy
       ! a priori c'est ok comme ca (cf ce qui est fait dans l'ocean). Je ne sais pas pkoi ceci dit
+      
       IF( before ) THEN  ! parent grid
          jm = 1
Index: /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90
===================================================================
--- /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 7059)
+++ /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 7060)
@@ -638,5 +638,5 @@
       REAL(wp) ::   zalpha4, zalpha5, zalpha6, zalpha7
       LOGICAL :: western_side, eastern_side,northern_side,southern_side
-
+      
       IF (before) THEN         
          ptab(i1:i2,j1:j2,k1:k2,n1:n2) = tsn(i1:i2,j1:j2,k1:k2,n1:n2)
Index: /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_user.F90
===================================================================
--- /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 7059)
+++ /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 7060)
@@ -306,4 +306,5 @@
    ! Note that update below is recursive (with lk_agrif_doupd=T):
    ! 
+!!#if ! defined key_sas2D
 ! JC: I am not sure if Agrif_MaxLevel() is the "relative"
 !     or the absolute maximum nesting level...TBC                        
@@ -313,4 +314,5 @@
       CALL Agrif_Update_dyn()
    ENDIF
+!!#endif   
    !
 # if defined key_zdftke
@@ -321,4 +323,5 @@
    nbcline = 0
    lk_agrif_doupd = .FALSE.
+
    !
 END SUBROUTINE Agrif_InitValues_cont
@@ -454,5 +457,5 @@
 !   CALL Agrif_Set_Updatetype(vb2b_update_id,update1 = Agrif_Update_Full_Weighting, update2 = Agrif_Update_Average)
 !   CALL Agrif_Set_Updatetype(sshn_id, update = Agrif_Update_Full_Weighting)
- 
+
    !
 END SUBROUTINE agrif_declare_var
@@ -609,5 +612,6 @@
    !! ** Purpose :: Declaration of variables to be interpolated for LIM3
    !!----------------------------------------------------------------------
-   USE agrif_util
+   USE Agrif_Util
+   USE Agrif_ice  !clem useless ?
    USE ice
 
@@ -618,8 +622,7 @@
    !       agrif_declare_variable(position,1st point index,--,--,dimensions,name)
    !-------------------------------------------------------------------------------------
-   CALL agrif_declare_variable((/2,2,0,0/),(/3,3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/), &
-      &                        (/jpi,jpj,jpl,jpl*(5+nlay_s+nlay_i)/), tra_ice_id )
-   CALL agrif_declare_variable((/1,2/)    ,(/2,3/)    ,(/'x','y'/)        ,(/1,1/)    ,(/jpi,jpj/)      ,u_ice_id  )
-   CALL agrif_declare_variable((/2,1/)    ,(/3,2/)    ,(/'x','y'/)        ,(/1,1/)    ,(/jpi,jpj/)      ,v_ice_id  )
+   CALL agrif_declare_variable((/2,2,0/),(/3,3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpl*(5+nlay_s+nlay_i)/),tra_ice_id )
+   CALL agrif_declare_variable((/1,2/)    ,(/2,3/),(/'x','y'/)    ,(/1,1/)  ,(/nlci,nlcj/)                      ,u_ice_id   )
+   CALL agrif_declare_variable((/2,1/)    ,(/3,2/),(/'x','y'/)    ,(/1,1/)  ,(/nlci,nlcj/)                      ,v_ice_id   )
 
    ! 2. Set interpolations (normal & tangent to the grid cell for velocities)
Index: /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90
===================================================================
--- /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 7059)
+++ /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 7060)
@@ -118,4 +118,11 @@
       IF( nn_timing == 1 )  CALL timing_start('sbc_ice_lim')
 
+      ! clem: it is important to initialize agrif_lim3 variables here and not in sbc_lim_init
+# if defined key_agrif
+      IF( kt == nit000 ) THEN
+         IF( .NOT. Agrif_Root() )   CALL Agrif_InitValues_cont_lim3
+      ENDIF
+# endif
+
       !-----------------------!
       ! --- Ice time step --- !
@@ -189,4 +196,5 @@
             !
          ENDIF
+
          ! ---
 #if defined key_agrif
@@ -314,10 +322,4 @@
       IF( ierr /= 0 )   CALL ctl_stop('STOP', 'sbc_lim_init : unable to allocate ice arrays')
       !
-      !                                ! adequation jpk versus ice/snow layers/categories
-      IF( jpl > jpk .OR. (nlay_i+1) > jpk .OR. nlay_s > jpk )   &
-         &      CALL ctl_stop( 'STOP',                          &
-         &     'sbc_lim_init: the 3rd dimension of workspace arrays is too small.',   &
-         &     'use more ocean levels or less ice/snow layers/categories.' )
-      !
       CALL lim_dyn_init                ! set ice dynamics parameters
       !
@@ -364,7 +366,4 @@
       IF( nstock == 0 )   nstock = nlast + 1
       !
-# if defined key_agrif
-      IF( .NOT. Agrif_Root() )   CALL Agrif_InitValues_cont_lim3
-# endif
       !
    END SUBROUTINE sbc_lim_init
Index: /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90
===================================================================
--- /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 7059)
+++ /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 7060)
@@ -111,14 +111,18 @@
 
       !                          ! overwrite namelist parameter using CPP key information
-      IF( Agrif_Root() ) THEN                ! AGRIF zoom
-        IF( lk_lim2 )   nn_ice      = 2
-        IF( lk_lim3 )   nn_ice      = 3
-        IF( lk_cice )   nn_ice      = 4
-      ENDIF
-      IF( cp_cfg == 'gyre' ) THEN            ! GYRE configuration
-          ln_ana      = .TRUE.   
-          nn_ice      =   0
-      ENDIF
-
+#if defined key_agrif
+      IF( Agrif_Root() ) THEN                ! AGRIF zoom (cf r1242: possibility to run without ice in fine grid)
+         IF( lk_lim2 )   nn_ice      = 2
+         IF( lk_lim3 )   nn_ice      = 3
+         IF( lk_cice )   nn_ice      = 4
+      ENDIF
+#else
+      IF( lk_lim2 )   nn_ice      = 2
+      IF( lk_lim3 )   nn_ice      = 3
+      IF( lk_cice )   nn_ice      = 4     
+#endif
+
+      IF( cp_cfg == 'gyre' )   ln_ana = .TRUE.          ! GYRE configuration
+             
       IF(lwp) THEN               ! Control print
          WRITE(numout,*) '        Namelist namsbc (partly overwritten with CPP key setting)'
@@ -195,6 +199,4 @@
 
       !                                            ! restartability   
-      IF( ( nn_ice == 2 .OR. nn_ice ==3 ) .AND. .NOT.( ln_blk_clio .OR. ln_blk_core .OR. ln_cpl ) )   &
-         &   CALL ctl_stop( 'LIM sea-ice model requires a bulk formulation or coupled configuration' )
       IF( nn_ice == 4 .AND. .NOT.( ln_blk_core .OR. ln_cpl ) )   &
          &   CALL ctl_stop( 'CICE sea-ice model requires ln_blk_core or ln_cpl' )
@@ -303,5 +305,5 @@
       !
       IF( nn_ice == 3      )   CALL sbc_lim_init               ! LIM3 initialisation
-
+      !
       IF( nn_ice == 4      )   CALL cice_sbc_init( nsbc )      ! CICE initialisation
       
Index: /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90
===================================================================
--- /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90	(revision 7059)
+++ /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90	(revision 7060)
@@ -111,8 +111,5 @@
 # endif
 # if defined key_lim2
-      CALL Agrif_Declare_Var_lim2  !  "      "   "   "      "  LIM2
-# endif
-# if defined key_lim3
-      CALL Agrif_Declare_Var_lim3  !  "      "   "   "      "  LIM3
+      CALL Agrif_Declare_Var_lim2  !  "      "   "   "      "  LIM
 # endif
 #endif
Index: /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/SAS_SRC/step.F90
===================================================================
--- /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/SAS_SRC/step.F90	(revision 7059)
+++ /branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/SAS_SRC/step.F90	(revision 7060)
@@ -43,4 +43,8 @@
 #endif
 
+#if defined key_agrif
+   USE agrif_oce, ONLY: lk_agrif_debug  !clem
+#endif
+   
    IMPLICIT NONE
    PRIVATE
@@ -78,8 +82,17 @@
 #if defined key_agrif
       kstp = nit000 + Agrif_Nb_Step()
+      IF ( lk_agrif_debug ) THEN
+         IF ( Agrif_Root() .and. lwp) Write(*,*) '---'
+         IF (lwp) Write(*,*) 'Grid Number',Agrif_Fixed(),' time step ',kstp, 'int tstep',Agrif_NbStepint()
+      ENDIF
+
+      IF ( kstp == (nit000 + 1) ) lk_agrif_fstep = .FALSE.
+
 # if defined key_iomput
       IF( Agrif_Nbstepint() == 0 )   CALL iom_swap( cxios_context )
 # endif   
 #endif   
+                             indic = 0                    ! although indic is not changed in stp_ctl
+                                                          ! need to keep the same interface 
       IF( kstp == nit000 )   CALL iom_init( cxios_context ) ! iom_put initialization (must be done after nemo_init for AGRIF+XIOS+OASIS)
       IF( kstp /= nit000 )   CALL day( kstp )             ! Calendar (day was already called at nit000 in day_init)
@@ -98,7 +111,21 @@
                              CALL dia_wri( kstp )         ! ocean model: outputs
 
-                             indic = 0                    ! although indic is not changed in stp_ctl
-                                                          ! need to keep the same interface 
+#if defined key_agrif
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! AGRIF
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<      
+                             CALL Agrif_Integrate_ChildGrids( stp )  
+#endif
+                             
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Control
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                              CALL stp_ctl( kstp, indic )
+      IF( indic < 0  )  THEN
+                             CALL ctl_stop( 'step: indic < 0' )
+                             CALL dia_wri_state( 'output.abort', kstp )
+      ENDIF
+      IF( kstp == nit000   ) CALL iom_close( numror )     ! close input  ocean restart file (clem: not sure...)
+      
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ! Coupled mode
