Index: branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_ice.F90
===================================================================
--- branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_ice.F90	(revision 7899)
+++ branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_ice.F90	(revision 7953)
@@ -18,20 +18,19 @@
    PUBLIC agrif_ice_alloc ! routine called by nemo_init in nemogcm.F90
 
-   INTEGER, PUBLIC :: u_ice_id, v_ice_id, adv_ice_id
-   REAL(wp), PUBLIC :: lim_nbstep = 0.    ! child time position in sea-ice model
+   INTEGER , PUBLIC ::   u_ice_id, v_ice_id, adv_ice_id
+   REAL(wp), PUBLIC ::   lim_nbstep = 0.    ! child time position in sea-ice model
 #if defined key_lim2_vp
    REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:)     :: u_ice_nst, v_ice_nst   
 #else
    REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:)   :: u_ice_oe, u_ice_sn     !: boundaries arrays
-   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:)   :: v_ice_oe, v_ice_sn     !:  "          " 
+   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:)   :: v_ice_oe, v_ice_sn     !:     -        - 
 #endif
-   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:,:) :: adv_ice_oe, adv_ice_sn !:  "          "
+   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:,:) :: adv_ice_oe, adv_ice_sn !:     -        -
 
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.3.4 , NEMO Consortium (2012)
+   !! NEMO/NST 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS 
 
@@ -50,11 +49,11 @@
 
 #if ! defined key_lim2_vp
-      u_ice_oe(:,:,:) =  0.e0
-      v_ice_oe(:,:,:) =  0.e0
-      u_ice_sn(:,:,:) =  0.e0
-      v_ice_sn(:,:,:) =  0.e0
+      u_ice_oe(:,:,:) =  0._wp
+      v_ice_oe(:,:,:) =  0._wp
+      u_ice_sn(:,:,:) =  0._wp
+      v_ice_sn(:,:,:) =  0._wp
 #endif
-      adv_ice_oe (:,:,:,:) = 0.e0 
-      adv_ice_sn (:,:,:,:) = 0.e0 
+      adv_ice_oe (:,:,:,:) = 0._wp 
+      adv_ice_sn (:,:,:,:) = 0._wp
       !
    END FUNCTION agrif_ice_alloc
@@ -71,5 +70,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.6 , NEMO Consortium (2016)
+   !! NEMO/NST 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
Index: branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_lim3_interp.F90
===================================================================
--- branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_lim3_interp.F90	(revision 7899)
+++ branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_lim3_interp.F90	(revision 7953)
@@ -28,5 +28,5 @@
    PRIVATE
 
-   PUBLIC agrif_interp_lim3
+   PUBLIC   agrif_interp_lim3   ! called by ???
 
    !!----------------------------------------------------------------------
@@ -46,13 +46,13 @@
       !!  computing factor for time interpolation
       !!-----------------------------------------------------------------------
-      CHARACTER(len=1), INTENT( in )           :: cd_type
-      INTEGER         , INTENT( in ), OPTIONAL :: kiter, kitermax
-      !!
-      REAL(wp) :: zbeta
+      CHARACTER(len=1), INTENT(in   )           ::   cd_type
+      INTEGER         , INTENT(in   ), OPTIONAL ::   kiter, kitermax
+      !!
+      REAL(wp) ::   zbeta   ! local scalar
       !!-----------------------------------------------------------------------
       !
       IF( Agrif_Root() )  RETURN
       !
-      SELECT CASE(cd_type)
+      SELECT CASE( cd_type )
       CASE('U','V')
          IF( PRESENT( kiter ) ) THEN  ! interpolation at the child sub-time step (only for ice rheology)
@@ -66,22 +66,17 @@
       END SELECT
       !
-      Agrif_SpecialValue=-9999.
+      Agrif_SpecialValue    = -9999.
       Agrif_UseSpecialValue = .TRUE.
-      SELECT CASE(cd_type)
-      CASE('U')
-         CALL Agrif_Bc_variable( u_ice_id  , procname=interp_u_ice  , calledweight=zbeta )
-      CASE('V')
-         CALL Agrif_Bc_variable( v_ice_id  , procname=interp_v_ice  , calledweight=zbeta )
-      CASE('T')
-         CALL Agrif_Bc_variable( tra_ice_id, procname=interp_tra_ice, calledweight=zbeta )
+      SELECT CASE( cd_type )
+      CASE('U')   ;   CALL Agrif_Bc_variable( u_ice_id  , procname=interp_u_ice  , calledweight=zbeta )
+      CASE('V')   ;   CALL Agrif_Bc_variable( v_ice_id  , procname=interp_v_ice  , calledweight=zbeta )
+      CASE('T')   ;   CALL Agrif_Bc_variable( tra_ice_id, procname=interp_tra_ice, calledweight=zbeta )
       END SELECT
-      Agrif_SpecialValue=0.
+      Agrif_SpecialValue    = 0._wp
       Agrif_UseSpecialValue = .FALSE.
       !
    END SUBROUTINE agrif_interp_lim3
 
-   !!------------------
-   !! Local subroutines
-   !!------------------
+
    SUBROUTINE interp_u_ice( ptab, i1, i2, j1, j2, before )
       !!-----------------------------------------------------------------------
@@ -92,9 +87,9 @@
       !! put -9999 WHERE the parent grid is masked. The child solution will be found in the 9(?) points around
       !!-----------------------------------------------------------------------
-      INTEGER , INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: ptab
-      LOGICAL , INTENT(in) :: before
-      !!
-      REAL(wp) :: zrhoy
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
+      LOGICAL                         , INTENT(in   ) ::   before
+      !!
+      REAL(wp) ::   zrhoy   ! local scalar
       !!-----------------------------------------------------------------------
       !
@@ -118,9 +113,9 @@
       !! put -9999 WHERE the parent grid is masked. The child solution will be found in the 9(?) points around
       !!-----------------------------------------------------------------------      
-      INTEGER , INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: ptab
-      LOGICAL , INTENT(in) :: before
-      !!
-      REAL(wp) :: zrhox
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
+      LOGICAL                         , INTENT(in   ) ::   before
+      !!
+      REAL(wp) ::   zrhox   ! local scalar
       !!-----------------------------------------------------------------------
       !
@@ -144,17 +139,16 @@
       !! 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
-      LOGICAL , INTENT(in) :: before
-      INTEGER , INTENT(in) :: nb, ndir
-      !!
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: ztab
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) ::   ptab
+      INTEGER                               , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
+      LOGICAL                               , INTENT(in   ) ::   before
+      INTEGER                               , INTENT(in   ) ::   nb, ndir
+      !!
       INTEGER  ::   ji, jj, jk, jl, jm
       INTEGER  ::   imin, imax, jmin, jmax
+      LOGICAL  ::   western_side, eastern_side, northern_side, southern_side
       REAL(wp) ::   zrhox, z1, z2, z3, z4, z5, z6, z7
-      LOGICAL  ::   western_side, eastern_side, northern_side, southern_side
-
-      !!-----------------------------------------------------------------------
-      ! tracers are not multiplied by grid cell here => before: * e12t ; after: * r1_e12t / rhox / rhoy
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ztab
+      !!-----------------------------------------------------------------------
+      ! tracers are not multiplied by grid cell here => before: * e1e2t ; after: * r1_e1e2t / rhox / rhoy
       ! and it is ok since we conserve tracers (same as in the ocean).
       ALLOCATE( ztab(SIZE(a_i_b,1),SIZE(a_i_b,2),SIZE(ptab,3)) )
@@ -163,20 +157,20 @@
          jm = 1
          DO jl = 1, jpl
-            ptab(i1:i2,j1:j2,jm) = a_i_b  (i1:i2,j1:j2,jl) ; jm = jm + 1
-            ptab(i1:i2,j1:j2,jm) = v_i_b  (i1:i2,j1:j2,jl) ; jm = jm + 1
-            ptab(i1:i2,j1:j2,jm) = v_s_b  (i1:i2,j1:j2,jl) ; jm = jm + 1
-            ptab(i1:i2,j1:j2,jm) = smv_i_b(i1:i2,j1:j2,jl) ; jm = jm + 1
-            ptab(i1:i2,j1:j2,jm) = oa_i_b (i1:i2,j1:j2,jl) ; jm = jm + 1
+            ptab(i1:i2,j1:j2,jm) = a_i_b  (i1:i2,j1:j2,jl)   ;   jm = jm + 1
+            ptab(i1:i2,j1:j2,jm) = v_i_b  (i1:i2,j1:j2,jl)   ;   jm = jm + 1
+            ptab(i1:i2,j1:j2,jm) = v_s_b  (i1:i2,j1:j2,jl)   ;   jm = jm + 1
+            ptab(i1:i2,j1:j2,jm) = smv_i_b(i1:i2,j1:j2,jl)   ;   jm = jm + 1
+            ptab(i1:i2,j1:j2,jm) = oa_i_b (i1:i2,j1:j2,jl)   ;   jm = jm + 1
             DO jk = 1, nlay_s
-               ptab(i1:i2,j1:j2,jm) = e_s_b(i1:i2,j1:j2,jk,jl) ; jm = jm + 1
-            ENDDO
+               ptab(i1:i2,j1:j2,jm) = e_s_b(i1:i2,j1:j2,jk,jl)   ;   jm = jm + 1
+            END DO
             DO jk = 1, nlay_i
-               ptab(i1:i2,j1:j2,jm) = e_i_b(i1:i2,j1:j2,jk,jl) ; jm = jm + 1
-            ENDDO
-         ENDDO
+               ptab(i1:i2,j1:j2,jm) = e_i_b(i1:i2,j1:j2,jk,jl)   ;   jm = jm + 1
+            END DO
+         END DO
          
          DO jk = k1, k2
-            WHERE( tmask(i1:i2,j1:j2,1) == 0. )  ptab(i1:i2,j1:j2,jk) = -9999.
-         ENDDO
+            WHERE( tmask(i1:i2,j1:j2,1) == 0._wp )   ptab(i1:i2,j1:j2,jk) = -9999.
+         END DO
          
       ELSE               ! child grid
@@ -184,16 +178,16 @@
          jm = 1
          DO jl = 1, jpl
-            a_i  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            v_i  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            v_s  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            smv_i(i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            oa_i (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            a_i  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1)   ;   jm = jm + 1
+            v_i  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1)   ;   jm = jm + 1
+            v_s  (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1)   ;   jm = jm + 1
+            smv_i(i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1)   ;   jm = jm + 1
+            oa_i (i1:i2,j1:j2,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1)   ;   jm = jm + 1
             DO jk = 1, nlay_s
-               e_s(i1:i2,j1:j2,jk,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            ENDDO
+               e_s(i1:i2,j1:j2,jk,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1)   ;   jm = jm + 1
+            END DO
             DO jk = 1, nlay_i
-               e_i(i1:i2,j1:j2,jk,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            ENDDO
-         ENDDO
+               e_i(i1:i2,j1:j2,jk,jl) = ptab(i1:i2,j1:j2,jm) * tmask(i1:i2,j1:j2,1)   ;   jm = jm + 1
+            END DO
+         END DO
 
 !! ==> this is a more complex interpolation since we mix solutions over a couple of grid points
@@ -319,5 +313,5 @@
          et_s(i1:i2,j1:j2)  = SUM( SUM( e_s(i1:i2,j1:j2,:,:), dim=4 ), dim=3 )
          et_i(i1:i2,j1:j2)  = SUM( SUM( e_i(i1:i2,j1:j2,:,:), dim=4 ), dim=3 )
-
+         !
       ENDIF
       
@@ -327,11 +321,13 @@
 
 #else
+   !!----------------------------------------------------------------------
+   !!   Empty module                                             no sea-ice
+   !!----------------------------------------------------------------------
 CONTAINS
    SUBROUTINE agrif_lim3_interp_empty
-      !!---------------------------------------------
-      !!   *** ROUTINE agrif_lim3_interp_empty ***
-      !!---------------------------------------------
       WRITE(*,*)  'agrif_lim3_interp : You should not have seen this print! error?'
    END SUBROUTINE agrif_lim3_interp_empty
 #endif
+
+   !!======================================================================
 END MODULE agrif_lim3_interp
Index: branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_lim3_update.F90
===================================================================
--- branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_lim3_update.F90	(revision 7899)
+++ branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_lim3_update.F90	(revision 7953)
@@ -31,12 +31,11 @@
    PRIVATE
 
-   PUBLIC agrif_update_lim3
+   PUBLIC   agrif_update_lim3   ! called by ????
 
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.6 , LOCEAN-IPSL (2016)
+   !! NEMO/NST 4.0 , LOCEAN-IPSL (2017)
    !! $Id: agrif_lim3_update.F90 6204 2016-01-04 13:47:06Z cetlod $
    !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 CONTAINS
 
@@ -49,5 +48,4 @@
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) :: kt
-      !!
       !!----------------------------------------------------------------------
       !
@@ -57,5 +55,5 @@
                                                                                                                            ! i.e. update only at the parent time step
       Agrif_UseSpecialValueInUpdate = .TRUE.
-      Agrif_SpecialValueFineGrid = -9999.
+      Agrif_SpecialValueFineGrid    = -9999.
 # if defined TWO_WAY
       IF( MOD(nbcline,nbclineupdate) == 0) THEN ! update the whole basin at each nbclineupdate (=nn_cln_update) baroclinic parent time steps
@@ -75,7 +73,4 @@
 
 
-   !!------------------
-   !! Local subroutines
-   !!------------------
    SUBROUTINE update_tra_ice( ptab, i1, i2, j1, j2, k1, k2, before )
       !!-----------------------------------------------------------------------
@@ -84,7 +79,7 @@
       !!              the properties per mass on the coarse grid
       !!-----------------------------------------------------------------------
-      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
+      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
       !!
       INTEGER  :: jk, jl, jm
@@ -94,36 +89,36 @@
          jm = 1
          DO jl = 1, jpl
-            ptab(:,:,jm) = a_i  (i1:i2,j1:j2,jl) ; jm = jm + 1
-            ptab(:,:,jm) = v_i  (i1:i2,j1:j2,jl) ; jm = jm + 1
-            ptab(:,:,jm) = v_s  (i1:i2,j1:j2,jl) ; jm = jm + 1
-            ptab(:,:,jm) = smv_i(i1:i2,j1:j2,jl) ; jm = jm + 1
-            ptab(:,:,jm) = oa_i (i1:i2,j1:j2,jl) ; jm = jm + 1
+            ptab(:,:,jm) = a_i  (i1:i2,j1:j2,jl)   ;   jm = jm + 1
+            ptab(:,:,jm) = v_i  (i1:i2,j1:j2,jl)   ;   jm = jm + 1
+            ptab(:,:,jm) = v_s  (i1:i2,j1:j2,jl)   ;   jm = jm + 1
+            ptab(:,:,jm) = smv_i(i1:i2,j1:j2,jl)   ;   jm = jm + 1
+            ptab(:,:,jm) = oa_i (i1:i2,j1:j2,jl)   ;   jm = jm + 1
             DO jk = 1, nlay_s
-               ptab(:,:,jm) = e_s(i1:i2,j1:j2,jk,jl) ; jm = jm + 1
-            ENDDO
+               ptab(:,:,jm) = e_s(i1:i2,j1:j2,jk,jl)   ;   jm = jm + 1
+            END DO
             DO jk = 1, nlay_i
-               ptab(:,:,jm) = e_i(i1:i2,j1:j2,jk,jl) ; jm = jm + 1
-            ENDDO
-         ENDDO
+               ptab(:,:,jm) = e_i(i1:i2,j1:j2,jk,jl)   ;   jm = jm + 1
+            END DO
+         END DO
 
          DO jk = k1, k2
             WHERE( tmask(i1:i2,j1:j2,1) == 0. )  ptab(:,:,jk) = -9999.
-         ENDDO
-                  
+         END DO
+         !       
       ELSE
          jm = 1
          DO jl = 1, jpl
-            a_i  (i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            v_i  (i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            v_s  (i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            smv_i(i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            oa_i (i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+            a_i  (i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1)   ;   jm = jm + 1
+            v_i  (i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1)   ;   jm = jm + 1
+            v_s  (i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1)   ;   jm = jm + 1
+            smv_i(i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1)   ;   jm = jm + 1
+            oa_i (i1:i2,j1:j2,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1)   ;   jm = jm + 1
             DO jk = 1, nlay_s
-               e_s(i1:i2,j1:j2,jk,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
+               e_s(i1:i2,j1:j2,jk,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1)   ;   jm = jm + 1
             ENDDO
             DO jk = 1, nlay_i
-               e_i(i1:i2,j1:j2,jk,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1) ; jm = jm + 1
-            ENDDO
-         ENDDO
+               e_i(i1:i2,j1:j2,jk,jl) = ptab(:,:,jm) * tmask(i1:i2,j1:j2,1)   ;   jm = jm + 1
+            END DO
+         END DO
 
          ! integrated values
@@ -144,9 +139,9 @@
       !! ** Method  : Update the fluxes and recover the properties (C-grid)
       !!-----------------------------------------------------------------------
-      INTEGER , INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: ptab
-      LOGICAL , INTENT(in) :: before
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
+      LOGICAL                         , INTENT(in   ) ::   before
       !!
-      REAL(wp) :: zrhoy
+      REAL(wp) ::   zrhoy   ! local scalar
       !!-----------------------------------------------------------------------
       !
@@ -154,5 +149,5 @@
          zrhoy = Agrif_Rhoy()
          ptab(:,:) = e2u(i1:i2,j1:j2) * u_ice(i1:i2,j1:j2) * zrhoy
-         WHERE( umask(i1:i2,j1:j2,1) == 0. )  ptab(:,:) = -9999.
+         WHERE( umask(i1:i2,j1:j2,1) == 0. )   ptab(:,:) = -9999.
       ELSE
          u_ice(i1:i2,j1:j2) = ptab(:,:) / e2u(i1:i2,j1:j2) * umask(i1:i2,j1:j2,1)
@@ -167,9 +162,9 @@
       !! ** Method  : Update the fluxes and recover the properties (C-grid)
       !!-----------------------------------------------------------------------
-      INTEGER , INTENT(in) :: i1,i2,j1,j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2),  INTENT(inout) :: ptab
-      LOGICAL , INTENT(in) :: before
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   ptab
+      LOGICAL                         , INTENT(in   ) ::   before
       !!
-      REAL(wp) :: zrhox
+      REAL(wp) ::   zrhox   ! local scalar
       !!-----------------------------------------------------------------------
       !
@@ -177,5 +172,5 @@
          zrhox = Agrif_Rhox()
          ptab(:,:) = e1v(i1:i2,j1:j2) * v_ice(i1:i2,j1:j2) * zrhox
-         WHERE( vmask(i1:i2,j1:j2,1) == 0. )  ptab(:,:) = -9999.
+         WHERE( vmask(i1:i2,j1:j2,1) == 0. )   ptab(:,:) = -9999.
       ELSE
          v_ice(i1:i2,j1:j2) = ptab(:,:) / e1v(i1:i2,j1:j2) * vmask(i1:i2,j1:j2,1)
@@ -185,11 +180,13 @@
 
 #else
+   !!----------------------------------------------------------------------
+   !!   Empty module                                             no sea-ice
+   !!----------------------------------------------------------------------
 CONTAINS
    SUBROUTINE agrif_lim3_update_empty
-      !!---------------------------------------------
-      !!   *** ROUTINE agrif_lim3_update_empty ***
-      !!---------------------------------------------
       WRITE(*,*)  'agrif_lim3_update : You should not have seen this print! error?'
    END SUBROUTINE agrif_lim3_update_empty
 #endif
+
+   !!======================================================================
 END MODULE agrif_lim3_update
Index: branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90
===================================================================
--- branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90	(revision 7899)
+++ branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90	(revision 7953)
@@ -47,6 +47,5 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE,  DIMENSION(:,:) :: fsahm_spt, fsahm_spf !: sponge viscosities
 
-   ! Barotropic arrays used to store open boundary data during
-   ! time-splitting loop:
+   ! Barotropic arrays used to store open boundary data during time-splitting loop:
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::  ubdy_w, vbdy_w, hbdy_w
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::  ubdy_e, vbdy_e, hbdy_e
@@ -54,20 +53,22 @@
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::  ubdy_s, vbdy_s, hbdy_s
 
-   INTEGER :: tsn_id                                                  ! AGRIF profile for tracers interpolation and update
-   INTEGER :: un_interp_id, vn_interp_id                              ! AGRIF profiles for interpolations
-   INTEGER :: un_update_id, vn_update_id                              ! AGRIF profiles for udpates
-   INTEGER :: tsn_sponge_id, un_sponge_id, vn_sponge_id               ! AGRIF profiles for sponge layers
+!!gm   add PUBLIC in all variable below:
+
+   INTEGER, PUBLIC :: tsn_id                                                  ! AGRIF profile for tracers interpolation and update
+   INTEGER, PUBLIC :: un_interp_id, vn_interp_id                              ! AGRIF profiles for interpolations
+   INTEGER, PUBLIC :: un_update_id, vn_update_id                              ! AGRIF profiles for udpates
+   INTEGER, PUBLIC :: tsn_sponge_id, un_sponge_id, vn_sponge_id               ! AGRIF profiles for sponge layers
 # if defined key_top
-   INTEGER :: trn_id, trn_sponge_id
+   INTEGER, PUBLIC :: trn_id, trn_sponge_id
 # endif  
-   INTEGER :: unb_id, vnb_id, ub2b_interp_id, vb2b_interp_id
-   INTEGER :: ub2b_update_id, vb2b_update_id
-   INTEGER :: e3t_id, e1u_id, e2v_id, sshn_id
-   INTEGER :: scales_t_id
-# if defined key_zdftke
-   INTEGER :: avt_id, avm_id, en_id
-# endif  
-   INTEGER :: umsk_id, vmsk_id
-   INTEGER :: kindic_agr
+   INTEGER, PUBLIC :: unb_id, vnb_id, ub2b_interp_id, vb2b_interp_id
+   INTEGER, PUBLIC :: ub2b_update_id, vb2b_update_id
+   INTEGER, PUBLIC :: e3t_id, e1u_id, e2v_id, sshn_id
+   INTEGER, PUBLIC :: scales_t_id
+   INTEGER, PUBLIC :: avt_id, avm_id, en_id                ! TKE related identificators
+   INTEGER, PUBLIC :: umsk_id, vmsk_id
+   INTEGER, PUBLIC :: kindic_agr
+   
+!!gm end public addition
 
    !!----------------------------------------------------------------------
Index: branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90
===================================================================
--- branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 7899)
+++ branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 7953)
@@ -21,5 +21,5 @@
    USE oce
    USE dom_oce      
-   USE zdf_oce
+   USE zdf_oce          ! vertical physics
    USE agrif_oce
    USE phycst
@@ -34,11 +34,9 @@
 
    PUBLIC   Agrif_tra, Agrif_dyn, Agrif_ssh, Agrif_dyn_ts, Agrif_ssh_ts, Agrif_dta_ts
-   PUBLIC   interpun, interpvn
-   PUBLIC   interptsn,  interpsshn
-   PUBLIC   interpunb, interpvnb, interpub2b, interpvb2b
+   PUBLIC   interpun , interpvn
+   PUBLIC   interptsn, interpsshn
+   PUBLIC   interpunb, interpvnb , interpub2b, interpvb2b
    PUBLIC   interpe3t, interpumsk, interpvmsk
-# if defined key_zdftke
    PUBLIC   Agrif_tke, interpavm
-# endif
 
    INTEGER ::   bdy_tinterp = 0
@@ -46,5 +44,5 @@
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.7 , NEMO Consortium (2015)
+   !! NEMO/NST 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -385,5 +383,4 @@
       !!                  ***  ROUTINE Agrif_dyn_ts  ***
       !!----------------------------------------------------------------------  
-      !! 
       INTEGER, INTENT(in) ::   jn
       !!
@@ -444,5 +441,4 @@
       !!                  ***  ROUTINE Agrif_dta_ts  ***
       !!----------------------------------------------------------------------  
-      !! 
       INTEGER, INTENT(in) ::   kt
       !!
@@ -504,5 +500,4 @@
       !!----------------------------------------------------------------------  
       INTEGER, INTENT(in) ::   kt
-      !!
       !!----------------------------------------------------------------------  
       !
@@ -541,5 +536,5 @@
       !!----------------------------------------------------------------------  
       !
-      IF((nbondi == -1).OR.(nbondi == 2)) THEN
+      IF( nbondi == -1 .OR. nbondi == 2 ) THEN
          DO jj = 1, jpj
             ssha_e(2,jj) = hbdy_w(jj)
@@ -547,5 +542,5 @@
       ENDIF
       !
-      IF((nbondi == 1).OR.(nbondi == 2)) THEN
+      IF( nbondi == 1 .OR. nbondi == 2 ) THEN
          DO jj = 1, jpj
             ssha_e(nlci-1,jj) = hbdy_e(jj)
@@ -553,5 +548,5 @@
       ENDIF
       !
-      IF((nbondj == -1).OR.(nbondj == 2)) THEN
+      IF( nbondj == -1 .OR.(nbondj == 2 ) THEN
          DO ji = 1, jpi
             ssha_e(ji,2) = hbdy_s(ji)
@@ -559,5 +554,5 @@
       ENDIF
       !
-      IF((nbondj == 1).OR.(nbondj == 2)) THEN
+      IF( nbondj == 1 .OR. nbondj == 2 ) THEN
          DO ji = 1, jpi
             ssha_e(ji,nlcj-1) = hbdy_n(ji)
@@ -567,5 +562,4 @@
    END SUBROUTINE Agrif_ssh_ts
 
-# if defined key_zdftke
 
    SUBROUTINE Agrif_tke
@@ -579,18 +573,17 @@
       IF( zalpha > 1. )   zalpha = 1.
       !
-      Agrif_SpecialValue    = 0.e0
+      Agrif_SpecialValue    = 0._wp
       Agrif_UseSpecialValue = .TRUE.
       !
-      CALL Agrif_Bc_variable(avm_id ,calledweight=zalpha, procname=interpavm)       
+      CALL Agrif_Bc_variable( avm_id , calledweight=zalpha, procname=interpavm )       
       !
       Agrif_UseSpecialValue = .FALSE.
       !
    END SUBROUTINE Agrif_tke
-   
-# endif
+
 
    SUBROUTINE interptsn( ptab, i1, i2, j1, j2, k1, k2, n1, n2, before, nb, ndir )
       !!----------------------------------------------------------------------
-      !!   *** ROUTINE interptsn ***
+      !!                  *** ROUTINE interptsn ***
       !!----------------------------------------------------------------------
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) ::   ptab
@@ -599,9 +592,9 @@
       INTEGER                                     , INTENT(in   ) ::   nb , ndir
       !
-      INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
-      INTEGER  ::   imin, imax, jmin, jmax
-      REAL(wp) ::   zrhox , zalpha1, zalpha2, zalpha3
-      REAL(wp) ::   zalpha4, zalpha5, zalpha6, zalpha7
-      LOGICAL  ::   western_side, eastern_side,northern_side,southern_side
+      INTEGER ::   ji, jj, jk, jn   ! dummy loop indices
+      INTEGER ::   imin, imax, jmin, jmax
+      REAL(wp)::   zrhox , zalpha1, zalpha2, zalpha3
+      REAL(wp)::   zalpha4, zalpha5, zalpha6, zalpha7
+      LOGICAL ::   western_side, eastern_side,northern_side,southern_side
       !!----------------------------------------------------------------------
       !
@@ -770,5 +763,5 @@
    SUBROUTINE interpun( ptab, i1, i2, j1, j2, k1, k2, before )
       !!----------------------------------------------------------------------
-      !!   *** ROUTINE interpun ***
+      !!                         *** ROUTINE interpun ***
       !!----------------------------------------------------------------------
       INTEGER                               , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
@@ -776,6 +769,6 @@
       LOGICAL                               , INTENT(in   ) ::   before
       !
-      INTEGER  ::   ji, jj, jk
-      REAL(wp) ::   zrhoy	
+      INTEGER ::   ji, jj, jk
+      REAL(wp)::   zrhoy	
       !!----------------------------------------------------------------------
       !
@@ -798,5 +791,5 @@
    SUBROUTINE interpvn( ptab, i1, i2, j1, j2, k1, k2, before )
       !!----------------------------------------------------------------------
-      !!   *** ROUTINE interpvn ***
+      !!                      *** ROUTINE interpvn ***
       !!----------------------------------------------------------------------
       INTEGER                               , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
@@ -804,6 +797,6 @@
       LOGICAL                               , INTENT(in   ) ::   before
       !
-      INTEGER  ::   ji, jj, jk
-      REAL(wp) ::   zrhox	
+      INTEGER ::   ji, jj, jk
+      REAL(wp)::   zrhox	
       !!----------------------------------------------------------------------
       !      
@@ -831,7 +824,7 @@
       INTEGER                         , INTENT(in   ) ::   nb , ndir
       !
-      INTEGER  ::   ji, jj
-      REAL(wp) ::   zrhoy, zrhot, zt0, zt1, ztcoeff
-      LOGICAL  ::   western_side, eastern_side,northern_side,southern_side
+      INTEGER ::   ji, jj
+      REAL(wp)::   zrhoy, zrhot, zt0, zt1, ztcoeff
+      LOGICAL ::   western_side, eastern_side,northern_side,southern_side
       !!----------------------------------------------------------------------  
       !
@@ -901,7 +894,7 @@
       INTEGER                         , INTENT(in   ) ::   nb , ndir
       !
-      INTEGER  ::   ji,jj
-      REAL(wp) ::   zrhox, zrhot, zt0, zt1, ztcoeff   
-      LOGICAL  ::   western_side, eastern_side,northern_side,southern_side
+      INTEGER ::   ji,jj
+      REAL(wp)::   zrhox, zrhot, zt0, zt1, ztcoeff   
+      LOGICAL ::   western_side, eastern_side,northern_side,southern_side
       !!----------------------------------------------------------------------  
       ! 
@@ -919,9 +912,9 @@
          zt1 = REAL(Agrif_NbStepint()+1, wp) / zrhot      
          IF( bdy_tinterp == 1 ) THEN
-            ztcoeff = zrhot * (  zt1**2._wp * (       zt1 - 1._wp)        &
-               &               - zt0**2._wp * (       zt0 - 1._wp)        )
+            ztcoeff = zrhot * (  zt1**2._wp * ( zt1 - 1._wp)        &
+               &               - zt0**2._wp * ( zt0 - 1._wp)        )
          ELSEIF( bdy_tinterp == 2 ) THEN
-            ztcoeff = zrhot * (  zt1        * (       zt1 - 1._wp)**2._wp &
-               &               - zt0        * (       zt0 - 1._wp)**2._wp ) 
+            ztcoeff = zrhot * (  zt1        * ( zt1 - 1._wp)**2._wp &
+               &               - zt0        * ( zt0 - 1._wp)**2._wp ) 
          ELSE
             ztcoeff = 1
@@ -942,19 +935,8 @@
          !            
          IF( bdy_tinterp == 0 .OR. bdy_tinterp == 2) THEN
-            IF(western_side) THEN
-               vbdy_w(j1:j2) = vbdy_w(j1:j2) / (zrhox*e1v(i1,j1:j2))   &
-                     &                                  * vmask(i1,j1:j2,1)
-            ENDIF
-            IF(eastern_side) THEN
-               vbdy_e(j1:j2) = vbdy_e(j1:j2) / (zrhox*e1v(i1,j1:j2))   &
-                     &                                  * vmask(i1,j1:j2,1)
-            ENDIF
-            IF(southern_side) THEN
-               vbdy_s(i1:i2) = vbdy_s(i1:i2) / (zrhox*e1v(i1:i2,j1))   &
-                     &                                  * vmask(i1:i2,j1,1)
-            ENDIF
-            IF(northern_side) THEN
-               vbdy_n(i1:i2) = vbdy_n(i1:i2) / (zrhox*e1v(i1:i2,j1))   &
-                     &                                  * vmask(i1:i2,j1,1)
+            IF( western_side  )   vbdy_w(j1:j2) = vbdy_w(j1:j2) / (zrhox*e1v(i1,j1:j2)) * vmask(i1,j1:j2,1)
+            IF( eastern_side  )   vbdy_e(j1:j2) = vbdy_e(j1:j2) / (zrhox*e1v(i1,j1:j2)) * vmask(i1,j1:j2,1)
+            IF( southern_side )   vbdy_s(i1:i2) = vbdy_s(i1:i2) / (zrhox*e1v(i1:i2,j1)) * vmask(i1:i2,j1,1)
+            IF( northern_side )   vbdy_n(i1:i2) = vbdy_n(i1:i2) / (zrhox*e1v(i1:i2,j1)) * vmask(i1:i2,j1,1)
             ENDIF
          ENDIF
@@ -973,7 +955,7 @@
       INTEGER                         , INTENT(in   ) ::   nb , ndir
       !
-      INTEGER  ::   ji,jj
-      REAL(wp) ::   zrhot, zt0, zt1,zat
-      LOGICAL  ::   western_side, eastern_side,northern_side,southern_side
+      INTEGER ::   ji,jj
+      REAL(wp)::   zrhot, zt0, zt1,zat
+      LOGICAL ::   western_side, eastern_side,northern_side,southern_side
       !!----------------------------------------------------------------------  
       IF( before ) THEN
@@ -1030,8 +1012,8 @@
             &           - zt0**2._wp * (-2._wp*zt0 + 3._wp)    ) 
          !
-         IF(western_side )   vbdy_w(j1:j2) = zat * ptab(i1,j1:j2)  
-         IF(eastern_side )   vbdy_e(j1:j2) = zat * ptab(i1,j1:j2)  
-         IF(southern_side)   vbdy_s(i1:i2) = zat * ptab(i1:i2,j1) 
-         IF(northern_side)   vbdy_n(i1:i2) = zat * ptab(i1:i2,j1) 
+         IF( western_side  )   vbdy_w(j1:j2) = zat * ptab(i1,j1:j2)  
+         IF( eastern_side  )   vbdy_e(j1:j2) = zat * ptab(i1,j1:j2)  
+         IF( southern_side )   vbdy_s(i1:i2) = zat * ptab(i1:i2,j1) 
+         IF( northern_side )   vbdy_n(i1:i2) = zat * ptab(i1:i2,j1) 
       ENDIF
       !      
@@ -1048,7 +1030,7 @@
       INTEGER                              , INTENT(in   ) :: nb , ndir
       !
-      INTEGER :: ji, jj, jk
-      LOGICAL :: western_side, eastern_side, northern_side, southern_side
-      REAL(wp) :: ztmpmsk      
+      INTEGER ::   ji, jj, jk
+      LOGICAL ::   western_side, eastern_side, northern_side, southern_side
+      REAL(wp)::   ztmpmsk      
       !!----------------------------------------------------------------------  
       !    
@@ -1065,8 +1047,8 @@
                DO ji = i1, i2
                   ! Get velocity mask at boundary edge points:
-                  IF( western_side )   ztmpmsk = umask(ji    ,jj    ,1)
-                  IF( eastern_side )   ztmpmsk = umask(nlci-2,jj    ,1)
-                  IF( northern_side)   ztmpmsk = vmask(ji    ,nlcj-2,1)
-                  IF( southern_side)   ztmpmsk = vmask(ji    ,2     ,1)
+                  IF( western_side  )   ztmpmsk = umask(ji    ,jj    ,1)
+                  IF( eastern_side  )   ztmpmsk = umask(nlci-2,jj    ,1)
+                  IF( northern_side )   ztmpmsk = vmask(ji    ,nlcj-2,1)
+                  IF( southern_side )   ztmpmsk = vmask(ji    ,2     ,1)
                   !
                   IF( ABS( ptab(ji,jj,jk) - tmask(ji,jj,jk) * e3t_0(ji,jj,jk) )*ztmpmsk > 1.D-2) THEN
@@ -1141,5 +1123,5 @@
       REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) ::   ptab
       LOGICAL                              , INTENT(in   ) ::   before
-      INTEGER                              , INTENT(in   ) :: nb , ndir
+      INTEGER                              , INTENT(in   ) ::   nb , ndir
       !
       INTEGER ::   ji, jj, jk
@@ -1175,5 +1157,4 @@
    END SUBROUTINE interpvmsk
 
-# if defined key_zdftke
 
    SUBROUTINE interpavm( ptab, i1, i2, j1, j2, k1, k2, before )
@@ -1186,13 +1167,9 @@
       !!----------------------------------------------------------------------  
       !      
-      IF( before ) THEN
-         ptab (i1:i2,j1:j2,k1:k2) = avm_k(i1:i2,j1:j2,k1:k2)
-      ELSE
-         avm_k(i1:i2,j1:j2,k1:k2) = ptab (i1:i2,j1:j2,k1:k2)
+      IF( before ) THEN   ;   ptab (i1:i2,j1:j2,k1:k2) = avm_k(i1:i2,j1:j2,k1:k2)
+      ELSE                ;   avm_k(i1:i2,j1:j2,k1:k2) = ptab (i1:i2,j1:j2,k1:k2)
       ENDIF
       !
    END SUBROUTINE interpavm
-
-# endif /* key_zdftke */
 
 #else
Index: branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90
===================================================================
--- branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90	(revision 7899)
+++ branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_opa_sponge.F90	(revision 7953)
@@ -3,13 +3,20 @@
 MODULE agrif_opa_sponge
    !!======================================================================
-   !!                ***  MODULE agrif_opa_update  ***
-   !! AGRIF :   
+   !!                   ***  MODULE  agrif_opa_interp  ***
+   !! AGRIF: interpolation package
    !!======================================================================
-   !! History :  
+   !! History :  2.0  !  2002-06  (XXX)  Original cade
+   !!             -   !  2005-11  (XXX) 
+   !!            3.2  !  2009-04  (R. Benshila) 
+   !!            3.6  !  2014-09  (R. Benshila) 
    !!----------------------------------------------------------------------
 #if defined key_agrif
+   !!----------------------------------------------------------------------
+   !!   'key_agrif'                                              AGRIF zoom
+   !!----------------------------------------------------------------------
    USE par_oce
    USE oce
    USE dom_oce
+   !
    USE in_out_manager
    USE agrif_oce
@@ -24,5 +31,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.7 , NEMO Consortium (2015)
+   !! NEMO/NST 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -31,20 +38,20 @@
 
    SUBROUTINE Agrif_Sponge_Tra
-      !!---------------------------------------------
-      !!   *** ROUTINE Agrif_Sponge_Tra ***
-      !!---------------------------------------------
-      REAL(wp) :: timecoeff
-      !!---------------------------------------------
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE Agrif_Sponge_Tra ***
+      !!----------------------------------------------------------------------
+      REAL(wp) ::   timecoeff   ! local scalar
+      !!----------------------------------------------------------------------
       !
 #if defined SPONGE
       timecoeff = REAL(Agrif_NbStepint(),wp)/Agrif_rhot()
-
+      !
       CALL Agrif_Sponge
-      Agrif_SpecialValue=0.
+      Agrif_SpecialValue    = 0._wp
       Agrif_UseSpecialValue = .TRUE.
-      tabspongedone_tsn = .FALSE.
-
+      tabspongedone_tsn     = .FALSE.
+      !
       CALL Agrif_Bc_Variable(tsn_sponge_id,calledweight=timecoeff,procname=interptsn_sponge)
-
+      !
       Agrif_UseSpecialValue = .FALSE.
 #endif
@@ -54,24 +61,24 @@
 
    SUBROUTINE Agrif_Sponge_dyn
-      !!---------------------------------------------
-      !!   *** ROUTINE Agrif_Sponge_dyn ***
-      !!---------------------------------------------
-      REAL(wp) :: timecoeff
-      !!---------------------------------------------
-
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE Agrif_Sponge_dyn ***
+      !!----------------------------------------------------------------------
+      REAL(wp) ::   timecoeff   ! local scalar
+      !!----------------------------------------------------------------------
+      !
 #if defined SPONGE
       timecoeff = REAL(Agrif_NbStepint(),wp)/Agrif_rhot()
-
-      Agrif_SpecialValue=0.
+      !
+      Agrif_SpecialValue    = 0._wp
       Agrif_UseSpecialValue = ln_spc_dyn
-
+      !
       tabspongedone_u = .FALSE.
       tabspongedone_v = .FALSE.         
       CALL Agrif_Bc_Variable(un_sponge_id,calledweight=timecoeff,procname=interpun_sponge)
-
+      !
       tabspongedone_u = .FALSE.
       tabspongedone_v = .FALSE.
       CALL Agrif_Bc_Variable(vn_sponge_id,calledweight=timecoeff,procname=interpvn_sponge)
-
+      !
       Agrif_UseSpecialValue = .FALSE.
 #endif
@@ -81,7 +88,7 @@
 
    SUBROUTINE Agrif_Sponge
-      !!---------------------------------------------
-      !!   *** ROUTINE  Agrif_Sponge ***
-      !!---------------------------------------------
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE  Agrif_Sponge ***
+      !!----------------------------------------------------------------------
       INTEGER  :: ji,jj,jk
       INTEGER  :: ispongearea, ilci, ilcj
@@ -89,5 +96,6 @@
       REAL(wp) :: z1spongearea, zramp
       REAL(wp), POINTER, DIMENSION(:,:) :: ztabramp
-
+      !!----------------------------------------------------------------------
+      !
 #if defined SPONGE || defined SPONGE_TOP
       ll_spdone=.TRUE.
@@ -176,8 +184,8 @@
                fsahm_spt(ji,jj) = visc_dyn * ztabramp(ji,jj)
                fsahm_spf(ji,jj) = 0.25_wp * visc_dyn * ( ztabramp(ji,jj) + ztabramp(ji  ,jj+1) &
-                                                     &  +ztabramp(ji,jj) + ztabramp(ji+1,jj  ) )
-            END DO
-         END DO
-
+                  &                                     +ztabramp(ji,jj) + ztabramp(ji+1,jj  ) )
+            END DO
+         END DO
+         !
          CALL lbc_lnk( fsahm_spt, 'T', 1. )   ! Lateral boundary conditions
          CALL lbc_lnk( fsahm_spf, 'F', 1. )
@@ -192,11 +200,11 @@
 
 
-   SUBROUTINE interptsn_sponge(tabres,i1,i2,j1,j2,k1,k2,n1,n2,before)
-      !!---------------------------------------------
-      !!   *** ROUTINE interptsn_sponge ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2,n1,n2
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
+   SUBROUTINE interptsn_sponge( tabres, i1, i2, j1, j2, k1, k2, n1, n2, before )
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE interptsn_sponge ***
+      !!----------------------------------------------------------------------
+      INTEGER                                     , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2, n1, n2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) ::   tabres
+      LOGICAL                                     , INTENT(in   ) ::   before
       !
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
@@ -205,4 +213,5 @@
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: ztu, ztv
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2) ::tsbdiff
+      !!----------------------------------------------------------------------
       !
       IF( before ) THEN
@@ -258,20 +267,18 @@
 
 
-   SUBROUTINE interpun_sponge(tabres,i1,i2,j1,j2,k1,k2, before)
-      !!---------------------------------------------
-      !!   *** ROUTINE interpun_sponge ***
-      !!---------------------------------------------    
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-
+   SUBROUTINE interpun_sponge( tabres, i1, i2, j1, j2, k1, k2, before )
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE interpun_sponge ***
+      !!----------------------------------------------------------------------
+      INTEGER                               , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) ::   tabres
+      LOGICAL                               , INTENT(in   ) ::   before
+      !!
       INTEGER :: ji,jj,jk
-
-      ! sponge parameters 
+      INTEGER :: jmax
       REAL(wp) :: ze2u, ze1v, zua, zva, zbtr
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: ubdiff
       REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: rotdiff, hdivdiff
-      INTEGER :: jmax
-      !!---------------------------------------------    
+      !!----------------------------------------------------------------------
       !
       IF( before ) THEN
@@ -356,19 +363,18 @@
 
 
-   SUBROUTINE interpvn_sponge(tabres,i1,i2,j1,j2,k1,k2, before,nb,ndir)
-      !!---------------------------------------------
-      !!   *** ROUTINE interpvn_sponge ***
-      !!--------------------------------------------- 
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-      INTEGER, INTENT(in) :: nb , ndir
-      !
-      INTEGER  ::   ji, jj, jk
-      REAL(wp) ::   ze2u, ze1v, zua, zva, zbtr
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: vbdiff
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: rotdiff, hdivdiff
-      INTEGER :: imax
-      !!--------------------------------------------- 
+   SUBROUTINE interpvn_sponge( tabres, i1, i2, j1, j2, k1, k2, before, nb, ndir )
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE interpvn_sponge ***
+      !!----------------------------------------------------------------------
+      INTEGER                               , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) ::   tabres
+      LOGICAL                               , INTENT(in   ) ::   before
+      INTEGER                               , INTENT(in   ) ::   nb , ndir
+      !
+      INTEGER ::   ji, jj, jk
+      INTEGER ::   imax
+      REAL(wp)::   ze2u, ze1v, zua, zva, zbtr
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) ::   vbdiff, rotdiff, hdivdiff
+      !!----------------------------------------------------------------------
 
       IF( before ) THEN 
@@ -403,5 +409,5 @@
          !                                                
 
-         imax = i2-1
+         imax = i2 - 1
          IF ((nbondi == 1).OR.(nbondi == 2))   imax = MIN(imax,nlci-3)
 
@@ -437,9 +443,12 @@
 
 #else
+   !!----------------------------------------------------------------------
+   !!   Empty module                                          no AGRIF zoom
+   !!----------------------------------------------------------------------
 CONTAINS
    SUBROUTINE agrif_opa_sponge_empty
-      !!---------------------------------------------
-      !!   *** ROUTINE agrif_OPA_sponge_empty ***
-      !!---------------------------------------------
+      !!----------------------------------------------------------------------
+      !!                 *** ROUTINE agrif_OPA_sponge_empty ***
+      !!----------------------------------------------------------------------
       WRITE(*,*)  'agrif_opa_sponge : You should not have seen this print! error?'
    END SUBROUTINE agrif_opa_sponge_empty
Index: branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90
===================================================================
--- branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 7899)
+++ branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 7953)
@@ -3,23 +3,35 @@
  
 MODULE agrif_opa_update
+   !!======================================================================
+   !!                   ***  MODULE  agrif_opa_interp  ***
+   !! AGRIF: interpolation package
+   !!======================================================================
+   !! History :  2.0  !  2002-06  (XXX)  Original cade
+   !!             -   !  2005-11  (XXX) 
+   !!            3.2  !  2009-04  (R. Benshila) 
+   !!            3.6  !  2014-09  (R. Benshila) 
+   !!----------------------------------------------------------------------
 #if defined key_agrif 
+   !!----------------------------------------------------------------------
+   !!   'key_agrif'                                              AGRIF zoom
+   !!----------------------------------------------------------------------
    USE par_oce
    USE oce
    USE dom_oce
+   USE zdf_oce        ! vertical physics: ocean variables 
    USE agrif_oce
-   USE in_out_manager  ! I/O manager
+   !
+   USE in_out_manager ! I/O manager
    USE lib_mpp
    USE wrk_nemo  
-   USE zdf_oce        ! vertical physics: ocean variables 
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC Agrif_Update_Tra, Agrif_Update_Dyn,Update_Scales
-# if defined key_zdftke
-   PUBLIC Agrif_Update_Tke
-# endif
+   PUBLIC   Agrif_Update_Tra, Agrif_Update_Dyn, Update_Scales
+   PUBLIC   Agrif_Update_Tke
+
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.6 , NEMO Consortium (2010)
+   !! NEMO/NST 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -28,7 +40,7 @@
 
    RECURSIVE SUBROUTINE Agrif_Update_Tra( )
-      !!---------------------------------------------
-      !!   *** ROUTINE Agrif_Update_Tra ***
-      !!---------------------------------------------
+      !!----------------------------------------------------------------------
+      !!                   *** ROUTINE Agrif_Update_Tra ***
+      !!----------------------------------------------------------------------
       ! 
       IF (Agrif_Root()) RETURN
@@ -38,5 +50,5 @@
 
       Agrif_UseSpecialValueInUpdate = .TRUE.
-      Agrif_SpecialValueFineGrid = 0.
+      Agrif_SpecialValueFineGrid    = 0._wp
       ! 
       IF (MOD(nbcline,nbclineupdate) == 0) THEN
@@ -68,7 +80,7 @@
 
    RECURSIVE SUBROUTINE Agrif_Update_Dyn( )
-      !!---------------------------------------------
-      !!   *** ROUTINE Agrif_Update_Dyn ***
-      !!---------------------------------------------
+      !!----------------------------------------------------------------------
+      !!                   *** ROUTINE Agrif_Update_Dyn ***
+      !!----------------------------------------------------------------------
       ! 
       IF (Agrif_Root()) RETURN
@@ -106,5 +118,5 @@
 # endif
 
-      IF ( ln_dynspg_ts.AND.ln_bt_fw ) THEN
+      IF ( ln_dynspg_ts .AND. ln_bt_fw ) THEN
          ! Update time integrated transports
          IF (mod(nbcline,nbclineupdate) == 0) THEN
@@ -149,47 +161,47 @@
    END SUBROUTINE Agrif_Update_Dyn
 
-# if defined key_zdftke
+!!gm Missing GLS case !!!!!
 
    SUBROUTINE Agrif_Update_Tke( kt )
-      !!---------------------------------------------
-      !!   *** ROUTINE Agrif_Update_Tke ***
-      !!---------------------------------------------
-      !!
+      !!----------------------------------------------------------------------
+      !!                   *** ROUTINE Agrif_Update_Tke ***
+      !!----------------------------------------------------------------------
       INTEGER, INTENT(in) :: kt
-      !       
-      IF( ( Agrif_NbStepint() .NE. 0 ) .AND. (kt /= 0) ) RETURN
+      !!----------------------------------------------------------------------
+      !
+!!gm test on kt/=0  ????  why not nit000-1  ?  doesn't seem logic
+      IF( ( Agrif_NbStepint() /= 0 ) .AND. kt /= 0 )   RETURN
 #  if defined TWO_WAY
-
+      !
       Agrif_UseSpecialValueInUpdate = .TRUE.
-      Agrif_SpecialValueFineGrid = 0.
-
-      CALL Agrif_Update_Variable( en_id, locupdate=(/0,0/), procname=updateEN  )
-      CALL Agrif_Update_Variable(avt_id, locupdate=(/0,0/), procname=updateAVT )
-      CALL Agrif_Update_Variable(avm_id, locupdate=(/0,0/), procname=updateAVM )
-
+      Agrif_SpecialValueFineGrid    = 0._wp
+      !
+      CALL Agrif_Update_Variable(  en_id, locupdate=(/0,0/), procname=updateEN  )
+      CALL Agrif_Update_Variable( avt_id, locupdate=(/0,0/), procname=updateAVT )
+      CALL Agrif_Update_Variable( avm_id, locupdate=(/0,0/), procname=updateAVM )
+      !
       Agrif_UseSpecialValueInUpdate = .FALSE.
-
+      !
 #  endif
-      
+      !
    END SUBROUTINE Agrif_Update_Tke
    
-# endif /* key_zdftke */
 
    SUBROUTINE updateTS( tabres, i1, i2, j1, j2, k1, k2, n1, n2, before )
-      !!---------------------------------------------
+      !!----------------------------------------------------------------------
       !!           *** ROUTINE updateT ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2,n1,n2
-      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-      !!
-      INTEGER :: ji,jj,jk,jn
-      !!---------------------------------------------
-      !
-      IF (before) THEN
-         DO jn = n1,n2
-            DO jk=k1,k2
-               DO jj=j1,j2
-                  DO ji=i1,i2
+      !!----------------------------------------------------------------------
+      INTEGER                                    , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2, n1, n2
+      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) ::   tabres
+      LOGICAL                                    , INTENT(in   ) ::   before
+      !
+      INTEGER :: ji, jj, jk, jn
+      !!----------------------------------------------------------------------
+      !
+      IF( before ) THEN
+         DO jn = n1, n2
+            DO jk = k1, k2
+               DO jj = j1, j2
+                  DO ji = i1, i2
                      tabres(ji,jj,jk,jn) = tsn(ji,jj,jk,jn)
                   END DO
@@ -209,8 +221,8 @@
                                  &             - tsn(ji,jj,jk,jn) ) * tmask(ji,jj,jk)
                         ENDIF
-                     ENDDO
-                  ENDDO
-               ENDDO
-            ENDDO
+                     END DO
+                  END DO
+               END DO
+            END DO
          ENDIF
          DO jn = n1,n2
@@ -238,6 +250,6 @@
       LOGICAL                               , INTENT(in   ) :: before
       !
-      INTEGER  ::   ji, jj, jk
-      REAL(wp) ::   zrhoy
+      INTEGER ::   ji, jj, jk
+      REAL(wp)::   zrhoy
       !!---------------------------------------------
       ! 
@@ -268,16 +280,16 @@
 
    SUBROUTINE updatev( tabres, i1, i2, j1, j2, k1, k2, before )
-      !!---------------------------------------------
-      !!           *** ROUTINE updatev ***
-      !!---------------------------------------------
-      INTEGER :: i1,i2,j1,j2,k1,k2
-      INTEGER :: ji,jj,jk
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2) :: tabres
-      LOGICAL :: before
+      !!----------------------------------------------------------------------
+      !!                      *** ROUTINE updatev ***
+      !!----------------------------------------------------------------------
+      INTEGER                               , INTENT(in   ) :: i1, i2, j1, j2, k1, k2
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: tabres
+      LOGICAL                               , INTENT(in   ) :: before
       !!
-      REAL(wp) :: zrhox
-      !!---------------------------------------------      
-      !
-      IF (before) THEN
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   zrhox
+      !!----------------------------------------------------------------------
+      !
+      IF( before ) THEN
          zrhox = Agrif_Rhox()
          DO jk=k1,k2
@@ -309,17 +321,16 @@
 
    SUBROUTINE updateu2d( tabres, i1, i2, j1, j2, before )
+      !!----------------------------------------------------------------------
+      !!                      *** ROUTINE updateu2d ***
+      !!----------------------------------------------------------------------
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   tabres
+      LOGICAL                         , INTENT(in   ) ::   before
+      !! 
+      INTEGER ::   ji, jj, jk
+      REAL(wp)::   zrhoy, zcorr
       !!---------------------------------------------
-      !!          *** ROUTINE updateu2d ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-      !! 
-      INTEGER :: ji, jj, jk
-      REAL(wp) :: zrhoy
-      REAL(wp) :: zcorr
-      !!---------------------------------------------
-      !
-      IF (before) THEN
+      !
+      IF( before ) THEN
          zrhoy = Agrif_Rhoy()
          DO jj=j1,j2
@@ -374,17 +385,16 @@
 
    SUBROUTINE updatev2d( tabres, i1, i2, j1, j2, before )
-      !!---------------------------------------------
-      !!          *** ROUTINE updatev2d ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
-      !! 
+      !!----------------------------------------------------------------------
+      !!                   *** ROUTINE updatev2d ***
+      !!----------------------------------------------------------------------
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   tabres
+      LOGICAL                         , INTENT(in   ) ::   before
+      ! 
       INTEGER :: ji, jj, jk
-      REAL(wp) :: zrhox
-      REAL(wp) :: zcorr
-      !!---------------------------------------------
-      !
-      IF (before) THEN
+      REAL(wp) :: zrhox, zcorr
+      !!----------------------------------------------------------------------
+      !
+      IF( before ) THEN
          zrhox = Agrif_Rhox()
          DO jj=j1,j2
@@ -439,15 +449,15 @@
 
    SUBROUTINE updateSSH( tabres, i1, i2, j1, j2, before )
-      !!---------------------------------------------
-      !!          *** ROUTINE updateSSH ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
+      !!----------------------------------------------------------------------
+      !!                   *** ROUTINE updateSSH ***
+      !!----------------------------------------------------------------------
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   tabres
+      LOGICAL                         , INTENT(in   ) ::   before
       !!
       INTEGER :: ji, jj
-      !!---------------------------------------------
-      ! 
-      IF (before) THEN
+      !!----------------------------------------------------------------------
+      ! 
+      IF( before ) THEN
          DO jj=j1,j2
             DO ji=i1,i2
@@ -478,14 +488,14 @@
 
    SUBROUTINE updateub2b( tabres, i1, i2, j1, j2, before )
-      !!---------------------------------------------
-      !!          *** ROUTINE updateub2b ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
+      !!----------------------------------------------------------------------
+      !!                      *** ROUTINE updateub2b ***
+      !!----------------------------------------------------------------------
+      INTEGER                            , INTENT(in) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   tabres
+      LOGICAL                            , INTENT(in) ::   before
       !!
-      INTEGER :: ji, jj
-      REAL(wp) :: zrhoy
-      !!---------------------------------------------
+      INTEGER ::   ji, jj
+      REAL(wp)::   zrhoy
+      !!----------------------------------------------------------------------
       !
       IF (before) THEN
@@ -509,16 +519,16 @@
 
    SUBROUTINE updatevb2b( tabres, i1, i2, j1, j2, before )
-      !!---------------------------------------------
-      !!          *** ROUTINE updatevb2b ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1, i2, j1, j2
-      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: tabres
-      LOGICAL, INTENT(in) :: before
+      !!----------------------------------------------------------------------
+      !!                      *** ROUTINE updatevb2b ***
+      !!----------------------------------------------------------------------
+      INTEGER                         , INTENT(in   ) ::   i1, i2, j1, j2
+      REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) ::   tabres
+      LOGICAL                         , INTENT(in   ) ::   before
       !!
-      INTEGER :: ji, jj
-      REAL(wp) :: zrhox
-      !!---------------------------------------------
-      !
-      IF (before) THEN
+      INTEGER ::   ji, jj
+      REAL(wp)::   zrhox
+      !!----------------------------------------------------------------------
+      !
+      IF( before ) THEN
          zrhox = Agrif_Rhox()
          DO jj=j1,j2
@@ -540,15 +550,17 @@
 
    SUBROUTINE update_scales( tabres, i1, i2, j1, j2, k1, k2, n1,n2, before )
-      ! currently not used
-      !!---------------------------------------------
-      !!           *** ROUTINE updateT ***
-      !!---------------------------------------------
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2,n1,n2
-      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) :: tabres
-      LOGICAL, iNTENT(in) :: before
-      !
+      !
+      ! ====>>>>>>>>>>    currently not used
+      !
+      !!----------------------------------------------------------------------
+      !!                      *** ROUTINE updateT ***
+      !!----------------------------------------------------------------------
+      INTEGER                                    , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2, n1, n2
+      REAL(wp),DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) ::   tabres
+      LOGICAL                                    , INTENT(in   ) ::   before
+      !!
       INTEGER :: ji,jj,jk
       REAL(wp) :: ztemp
-      !!---------------------------------------------
+      !!----------------------------------------------------------------------
 
       IF (before) THEN
@@ -587,16 +599,15 @@
    END SUBROUTINE update_scales
 
-# if defined key_zdftke
 
    SUBROUTINE updateEN( ptab, i1, i2, j1, j2, k1, k2, before )
-      !!---------------------------------------------
-      !!           *** ROUTINE updateen ***
-      !!---------------------------------------------
-      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
-      !!---------------------------------------------
-      !
-      IF (before) THEN
+      !!----------------------------------------------------------------------
+      !!                      *** ROUTINE updateen ***
+      !!----------------------------------------------------------------------
+      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
+      !!----------------------------------------------------------------------
+      !
+      IF( before ) THEN
          ptab (i1:i2,j1:j2,k1:k2) = en(i1:i2,j1:j2,k1:k2)
       ELSE
@@ -608,16 +619,14 @@
 
    SUBROUTINE updateAVT( ptab, i1, i2, j1, j2, k1, k2, before )
-      !!---------------------------------------------
-      !!           *** ROUTINE updateavt ***
-      !!---------------------------------------------
-      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
-      !!---------------------------------------------
-      !
-      IF (before) THEN
-         ptab (i1:i2,j1:j2,k1:k2) = avt_k(i1:i2,j1:j2,k1:k2)
-      ELSE
-         avt_k(i1:i2,j1:j2,k1:k2) = ptab (i1:i2,j1:j2,k1:k2) 
+      !!----------------------------------------------------------------------
+      !!                      *** ROUTINE updateavt ***
+      !!----------------------------------------------------------------------
+      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
+      !!----------------------------------------------------------------------
+      !
+      IF( before ) THEN   ;   ptab (i1:i2,j1:j2,k1:k2) = avt_k(i1:i2,j1:j2,k1:k2)
+      ELSE                ;   avt_k(i1:i2,j1:j2,k1:k2) = ptab (i1:i2,j1:j2,k1:k2) 
       ENDIF
       !
@@ -628,29 +637,27 @@
       !!---------------------------------------------
       !!           *** ROUTINE updateavm ***
-      !!---------------------------------------------
-      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
-      !!---------------------------------------------
-      !
-      IF (before) THEN
-         ptab (i1:i2,j1:j2,k1:k2) = avm_k(i1:i2,j1:j2,k1:k2)
-      ELSE
-         avm_k(i1:i2,j1:j2,k1:k2) = ptab (i1:i2,j1:j2,k1:k2) 
+      !!----------------------------------------------------------------------
+      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
+      !!----------------------------------------------------------------------
+      !
+      IF( before ) THEN   ;   ptab (i1:i2,j1:j2,k1:k2) = avm_k(i1:i2,j1:j2,k1:k2)
+      ELSE                ;   avm_k(i1:i2,j1:j2,k1:k2) = ptab (i1:i2,j1:j2,k1:k2) 
       ENDIF
       !
    END SUBROUTINE updateAVM
 
-# endif /* key_zdftke */ 
-
 #else
+   !!----------------------------------------------------------------------
+   !!   Empty module                                          no AGRIF zoom
+   !!----------------------------------------------------------------------
 CONTAINS
    SUBROUTINE agrif_opa_update_empty
-      !!---------------------------------------------
-      !!   *** ROUTINE agrif_opa_update_empty ***
-      !!---------------------------------------------
       WRITE(*,*)  'agrif_opa_update : You should not have seen this print! error?'
    END SUBROUTINE agrif_opa_update_empty
 #endif
+
+   !!======================================================================
 END MODULE agrif_opa_update
 
Index: branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_top_interp.F90
===================================================================
--- branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_top_interp.F90	(revision 7899)
+++ branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_top_interp.F90	(revision 7953)
@@ -1,4 +1,14 @@
 MODULE agrif_top_interp
+   !!======================================================================
+   !!                   ***  MODULE  agrif_top_interp  ***
+   !! AGRIF: interpolation package
+   !!======================================================================
+   !! History :  2.0  !  ??? 
+   !!----------------------------------------------------------------------
 #if defined key_agrif && defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_agrif'                                              AGRIF zoom
+   !!   'key_top'                                           on-line tracers
+   !!----------------------------------------------------------------------
    USE par_oce
    USE oce
@@ -8,4 +18,5 @@
    USE par_trc
    USE trc
+   !
    USE lib_mpp
    USE wrk_nemo  
@@ -16,7 +27,6 @@
    PUBLIC Agrif_trc, interptrn
 
-#  include "vectopt_loop_substitute.h90"
   !!----------------------------------------------------------------------
-   !! NEMO/NST 3.6 , NEMO Consortium (2010)
+   !! NEMO/NST 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -26,12 +36,12 @@
    SUBROUTINE Agrif_trc
       !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE Agrif_trc  ***
+      !!                   ***  ROUTINE Agrif_trc  ***
       !!----------------------------------------------------------------------
       !
       IF( Agrif_Root() )   RETURN
-
-      Agrif_SpecialValue    = 0.e0
+      !
+      Agrif_SpecialValue    = 0._wp
       Agrif_UseSpecialValue = .TRUE.
-
+      !
       CALL Agrif_Bc_variable( trn_id, procname=interptrn )
       Agrif_UseSpecialValue = .FALSE.
@@ -40,20 +50,21 @@
 
 
-   SUBROUTINE interptrn(ptab,i1,i2,j1,j2,k1,k2,n1,n2,before,nb,ndir)
-      !!---------------------------------------------
-      !!   *** ROUTINE interptrn ***
-      !!---------------------------------------------
-      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) :: ptab
-      INTEGER, INTENT(in) :: i1,i2,j1,j2,k1,k2,n1,n2
-      LOGICAL, INTENT(in) :: before
-      INTEGER, INTENT(in) :: nb , ndir
-      !
-      INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
-      INTEGER :: imin, imax, jmin, jmax
-      REAL(wp) ::   zrhox , zalpha1, zalpha2, zalpha3
-      REAL(wp) ::   zalpha4, zalpha5, zalpha6, zalpha7
-      LOGICAL :: western_side, eastern_side,northern_side,southern_side
-
-      IF (before) THEN         
+   SUBROUTINE interptrn( ptab, i1, i2, j1, j2, k1, k2, n1, n2, before, nb, ndir )
+      !!----------------------------------------------------------------------
+      !!                   *** ROUTINE interptrn ***
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2,n1:n2), INTENT(inout) ::   ptab
+      INTEGER                                     , INTENT(in   ) ::   i1, i2, j1, j2, k1, k2, n1, n2
+      LOGICAL                                     , INTENT(in   ) ::   before
+      INTEGER                                     , INTENT(in   ) ::   nb , ndir
+      !!
+      INTEGER ::   ji, jj, jk, jn   ! dummy loop indices
+      INTEGER ::   imin, imax, jmin, jmax
+      LOGICAL ::   western_side, eastern_side,northern_side,southern_side
+      REAL(wp)::   zrhox , zalpha1, zalpha2, zalpha3
+      REAL(wp)::   zalpha4, zalpha5, zalpha6, zalpha7
+      !!----------------------------------------------------------------------
+      !
+      IF( before ) THEN         
          ptab(i1:i2,j1:j2,k1:k2,n1:n2) = trn(i1:i2,j1:j2,k1:k2,n1:n2)
       ELSE
@@ -185,4 +196,7 @@
 
 #else
+   !!----------------------------------------------------------------------
+   !!   Empty module                                           no TOP AGRIF
+   !!----------------------------------------------------------------------
 CONTAINS
    SUBROUTINE Agrif_TOP_Interp_empty
@@ -193,3 +207,5 @@
    END SUBROUTINE Agrif_TOP_Interp_empty
 #endif
+
+   !!======================================================================
 END MODULE agrif_top_interp
Index: branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_top_sponge.F90
===================================================================
--- branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_top_sponge.F90	(revision 7899)
+++ branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_top_sponge.F90	(revision 7953)
@@ -4,14 +4,13 @@
    !!======================================================================
    !!                ***  MODULE agrif_top_sponge  ***
-   !! AGRIF :   define in memory AGRIF variables for sea-ice
+   !! AGRIF :   TOP sponge layer
    !!======================================================================
    !! History :  2.0  ! 2006-08  (R. Benshila, L. Debreu)  Original code
    !!----------------------------------------------------------------------
-
+#if defined key_agrif && defined key_top
    !!----------------------------------------------------------------------
    !!   Agrif_Sponge_trc : 
    !!   interptrn_sponge :  
    !!----------------------------------------------------------------------
-#if defined key_agrif && defined key_top
    USE par_oce
    USE par_trc
@@ -32,5 +31,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.7 , NEMO Consortium (2015)
+   !! NEMO/NST 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -42,5 +41,5 @@
       !!                   *** ROUTINE Agrif_Sponge_Trc ***
       !!----------------------------------------------------------------------
-      REAL(wp) ::   timecoeff
+      REAL(wp) ::   timecoeff   ! local scalar
       !!----------------------------------------------------------------------
       !
@@ -107,5 +106,7 @@
 
 #else
-
+   !!----------------------------------------------------------------------
+   !!   Empty module                                           no TOP AGRIF
+   !!----------------------------------------------------------------------
 CONTAINS
    SUBROUTINE agrif_top_sponge_empty
Index: branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_top_update.F90
===================================================================
--- branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_top_update.F90	(revision 7899)
+++ branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_top_update.F90	(revision 7953)
@@ -6,15 +6,19 @@
    !!                ***  MODULE agrif_top_update  ***
    !! AGRIF :   
-   !!----------------------------------------------------------------------
+   !!======================================================================
    !! History :  
    !!----------------------------------------------------------------------
-
 #if defined key_agrif && defined key_top
+   !!----------------------------------------------------------------------
+   !!   'key_agrif'                                              AGRIF zoom
+   !!   'key_TOP'                                           on-line tracers
+   !!----------------------------------------------------------------------
    USE par_oce
    USE oce
+   USE dom_oce
+   USE agrif_oce
    USE par_trc
    USE trc
-   USE dom_oce
-   USE agrif_oce
+   !
    USE wrk_nemo  
 
@@ -27,5 +31,5 @@
 
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.7 , NEMO Consortium (2015)
+   !! NEMO/NST 4.0 , NEMO Consortium (2017)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -112,9 +116,9 @@
 
 #else
+   !!----------------------------------------------------------------------
+   !!   Empty module                                           no TOP AGRIF
+   !!----------------------------------------------------------------------
 CONTAINS
    SUBROUTINE agrif_top_update_empty
-      !!---------------------------------------------
-      !!   *** ROUTINE agrif_Top_update_empty ***
-      !!---------------------------------------------
       WRITE(*,*)  'agrif_top_update : You should not have seen this print! error?'
    END SUBROUTINE agrif_top_update_empty
Index: branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_user.F90
===================================================================
--- branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 7899)
+++ branches/2017/dev_r7881_HPC09_ZDF/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 7953)
@@ -1,5 +1,5 @@
 #if defined key_agrif
 !!----------------------------------------------------------------------
-!! NEMO/NST 3.7 , NEMO Consortium (2016)
+!! NEMO/NST 4.0 , NEMO Consortium (2017)
 !! $Id$
 !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
@@ -107,4 +107,5 @@
    !!
    IMPLICIT NONE
+   !
    !!----------------------------------------------------------------------
    !
@@ -125,5 +126,5 @@
    USE par_oce       
    USE oce
-   !!
+   !
    IMPLICIT NONE
    !!----------------------------------------------------------------------
@@ -136,20 +137,20 @@
    ! 2. Type of interpolation
    !-------------------------
-   CALL Agrif_Set_bcinterp(e1u_id,interp1=Agrif_linear,interp2=AGRIF_ppm)
-   CALL Agrif_Set_bcinterp(e2v_id,interp1=AGRIF_ppm,interp2=Agrif_linear)
+   CALL Agrif_Set_bcinterp( e1u_id, interp1=Agrif_linear, interp2=AGRIF_ppm    )
+   CALL Agrif_Set_bcinterp( e2v_id, interp1=AGRIF_ppm   , interp2=Agrif_linear )
 
    ! 3. Location of interpolation
    !-----------------------------
-   CALL Agrif_Set_bc(e1u_id,(/0,0/))
-   CALL Agrif_Set_bc(e2v_id,(/0,0/))
+   CALL Agrif_Set_bc( e1u_id, (/0,0/) )
+   CALL Agrif_Set_bc( e2v_id, (/0,0/) )
 
    ! 5. Update type
    !--------------- 
-   CALL Agrif_Set_Updatetype(e1u_id,update1 = Agrif_Update_Copy, update2=Agrif_Update_Average)
-   CALL Agrif_Set_Updatetype(e2v_id,update1 = Agrif_Update_Average, update2=Agrif_Update_Copy)
+   CALL Agrif_Set_Updatetype( e1u_id, update1=Agrif_Update_Copy   , update2=Agrif_Update_Average )
+   CALL Agrif_Set_Updatetype( e2v_id, update1=Agrif_Update_Average, update2=Agrif_Update_Copy    )
 
 ! High order updates
-!   CALL Agrif_Set_Updatetype(e1u_id,update1 = Agrif_Update_Average,            update2=Agrif_Update_Full_Weighting)
-!   CALL Agrif_Set_Updatetype(e2v_id,update1 = Agrif_Update_Full_Weighting,     update2=Agrif_Update_Average)
+!   CALL Agrif_Set_Updatetype( e1u_id, update1=Agrif_Update_Average       , update2=Agrif_Update_Full_Weighting )
+!   CALL Agrif_Set_Updatetype( e2v_id, update1=Agrif_Update_Full_Weighting, update2=Agrif_Update_Average        )
     !
 END SUBROUTINE agrif_declare_var_dom
@@ -165,5 +166,7 @@
    USE oce 
    USE dom_oce
+   USE zdf_oce
    USE nemogcm
+   !
    USE lib_mpp
    USE in_out_manager
@@ -171,5 +174,5 @@
    USE agrif_opa_interp
    USE agrif_opa_sponge
-   !!
+   !
    IMPLICIT NONE
    !
@@ -184,5 +187,5 @@
    ! 2. First interpolations of potentially non zero fields
    !-------------------------------------------------------
-   Agrif_SpecialValue=0.
+   Agrif_SpecialValue    = 0._wp
    Agrif_UseSpecialValue = .TRUE.
    CALL Agrif_Bc_variable(tsn_id,calledweight=1.,procname=interptsn)
@@ -319,7 +322,5 @@
    ENDIF
    !
-# if defined key_zdftke
-   CALL Agrif_Update_tke(0)
-# endif
+   IF( ln_zdftke )   CALL Agrif_Update_tke( 0 )
    !
    Agrif_UseSpecialValueInUpdate = .FALSE.
@@ -337,7 +338,8 @@
    !!----------------------------------------------------------------------
    USE agrif_util
-   USE par_oce       !   ONLY : jpts
+   USE agrif_oce
+   USE par_oce       ! ocean parameters
+   USE zdf_oce       ! vertical physics
    USE oce
-   USE agrif_oce
    !!
    IMPLICIT NONE
@@ -371,9 +373,9 @@
    CALL agrif_declare_variable((/2,2/),(/3,3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),sshn_id)
 
-# if defined key_zdftke
-   CALL agrif_declare_variable((/2,2,0/),(/3,3,0/),(/'x','y','N'/),(/1,1,1/),(/jpi,jpj,jpk/), en_id)
-   CALL agrif_declare_variable((/2,2,0/),(/3,3,0/),(/'x','y','N'/),(/1,1,1/),(/jpi,jpj,jpk/),avt_id)
-   CALL agrif_declare_variable((/2,2,0/),(/3,3,0/),(/'x','y','N'/),(/1,1,1/),(/jpi,jpj,jpk/),avm_id)
-# endif
+   IF( ln_zdftke ) THEN
+      CALL agrif_declare_variable((/2,2,0/),(/3,3,0/),(/'x','y','N'/),(/1,1,1/),(/jpi,jpj,jpk/), en_id)
+      CALL agrif_declare_variable((/2,2,0/),(/3,3,0/),(/'x','y','N'/),(/1,1,1/),(/jpi,jpj,jpk/),avt_id)
+      CALL agrif_declare_variable((/2,2,0/),(/3,3,0/),(/'x','y','N'/),(/1,1,1/),(/jpi,jpj,jpk/),avm_id)
+   ENDIF
 
    ! 2. Type of interpolation
@@ -400,8 +402,5 @@
    CALL Agrif_Set_bcinterp(vmsk_id,interp=AGRIF_constant)
 
-# if defined key_zdftke
-   CALL Agrif_Set_bcinterp(avm_id ,interp=AGRIF_linear)
-# endif
-
+   IF( ln_zdftke )   CALL Agrif_Set_bcinterp( avm_id, interp=AGRIF_linear )
 
    ! 3. Location of interpolation
@@ -418,9 +417,9 @@
    CALL Agrif_Set_bc(vn_sponge_id ,(/-nn_sponge_len*Agrif_irhox()-1,0/))
 
-   CALL Agrif_Set_bc(sshn_id,(/0,0/))
-   CALL Agrif_Set_bc(unb_id ,(/0,0/))
-   CALL Agrif_Set_bc(vnb_id ,(/0,0/))
-   CALL Agrif_Set_bc(ub2b_interp_id,(/0,0/))
-   CALL Agrif_Set_bc(vb2b_interp_id,(/0,0/))
+   CALL Agrif_Set_bc( sshn_id       , (/0,0/) )
+   CALL Agrif_Set_bc( unb_id        , (/0,0/) )
+   CALL Agrif_Set_bc( vnb_id        , (/0,0/) )
+   CALL Agrif_Set_bc( ub2b_interp_id, (/0,0/) )
+   CALL Agrif_Set_bc( vb2b_interp_id, (/0,0/) )
 
    CALL Agrif_Set_bc(e3t_id,(/-2*Agrif_irhox()-1,0/))   ! if west and rhox=3: column 2 to 9
@@ -428,7 +427,5 @@
    CALL Agrif_Set_bc(vmsk_id,(/0,0/))
 
-# if defined key_zdftke
-   CALL Agrif_Set_bc(avm_id ,(/0,1/))
-# endif
+   IF( ln_zdftke )   CALL Agrif_Set_bc( avm_id, (/0,1/) )
 
    ! 5. Update type
@@ -446,9 +443,9 @@
    CALL Agrif_Set_Updatetype(vb2b_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy)
 
-# if defined key_zdftke
-   CALL Agrif_Set_Updatetype( en_id, update = AGRIF_Update_Average)
-   CALL Agrif_Set_Updatetype(avt_id, update = AGRIF_Update_Average)
-   CALL Agrif_Set_Updatetype(avm_id, update = AGRIF_Update_Average)
-# endif
+   IF( ln_zdftke) THEN
+      CALL Agrif_Set_Updatetype( en_id, update = AGRIF_Update_Average)
+      CALL Agrif_Set_Updatetype(avt_id, update = AGRIF_Update_Average)
+      CALL Agrif_Set_Updatetype(avm_id, update = AGRIF_Update_Average)
+   ENDIF
 
 ! High order updates
