Index: /branches/2017/dev_r7881_ENHANCE09_RK3/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90
===================================================================
--- /branches/2017/dev_r7881_ENHANCE09_RK3/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 8865)
+++ /branches/2017/dev_r7881_ENHANCE09_RK3/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 8866)
@@ -4,6 +4,5 @@
    !! AGRIF: interpolation package for the ocean dynamics (OPA)
    !!======================================================================
-   !! History :  2.0  !  2002-06  (XXX)  Original cade
-   !!             -   !  2005-11  (XXX) 
+   !! History :  2.0  !  2002-06  (L. Debreu)  Original cade
    !!            3.2  !  2009-04  (R. Benshila) 
    !!            3.6  !  2014-09  (R. Benshila) 
@@ -15,4 +14,9 @@
    !!   Agrif_tra     :
    !!   Agrif_dyn     : 
+   !!   Agrif_ssh     :
+   !!   Agrif_dyn_ts  :
+   !!   Agrif_dta_ts  :
+   !!   Agrif_ssh_ts  :
+   !!   Agrif_avm     : 
    !!   interpu       :
    !!   interpv       :
@@ -37,5 +41,5 @@
    PUBLIC   interpunb, interpvnb , interpub2b, interpvb2b
    PUBLIC   interpe3t, interpumsk, interpvmsk
-   PUBLIC   Agrif_tke, interpavm
+   PUBLIC   Agrif_avm, interpavm
 
    INTEGER ::   bdy_tinterp = 0
@@ -595,22 +599,21 @@
 
 
-   SUBROUTINE Agrif_tke
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE Agrif_tke  ***
+   SUBROUTINE Agrif_avm
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE Agrif_avm  ***
       !!----------------------------------------------------------------------  
       REAL(wp) ::   zalpha
       !!----------------------------------------------------------------------  
       !
-      zalpha = 1._wp ! JC: proper time interpolation impossible 
-                     ! => use last available value from parent 
-      !
-      Agrif_SpecialValue    = 0.e0
+      zalpha = 1._wp   ! proper time interpolation impossible  ==> use last available value from parent 
+      !
+      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
+   END SUBROUTINE Agrif_avm
    
 
@@ -630,10 +633,10 @@
       !!----------------------------------------------------------------------
       !
-      IF (before) THEN         
+      IF( before ) THEN         
          ptab(i1:i2,j1:j2,k1:k2,n1:n2) = tsn(i1:i2,j1:j2,k1:k2,n1:n2)
       ELSE
          !
-         western_side  = (nb == 1).AND.(ndir == 1)  ;  eastern_side  = (nb == 1).AND.(ndir == 2)
-         southern_side = (nb == 2).AND.(ndir == 1)  ;  northern_side = (nb == 2).AND.(ndir == 2)
+         western_side  = (nb == 1).AND.(ndir == 1)   ;   eastern_side  = (nb == 1).AND.(ndir == 2)
+         southern_side = (nb == 2).AND.(ndir == 1)   ;   northern_side = (nb == 2).AND.(ndir == 2)
          !
          IF( nbghostcells > 1 ) THEN  ! no smoothing
Index: /branches/2017/dev_r7881_ENHANCE09_RK3/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90
===================================================================
--- /branches/2017/dev_r7881_ENHANCE09_RK3/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 8865)
+++ /branches/2017/dev_r7881_ENHANCE09_RK3/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 8866)
@@ -7,6 +7,5 @@
    !! AGRIF: update package for the ocean dynamics (OPA)
    !!======================================================================
-   !! History :  2.0  !  2002-06  (XXX)  Original cade
-   !!             -   !  2005-11  (XXX) 
+   !! History :  2.0  !  2002-06  (L. Debreu)  Original code
    !!            3.2  !  2009-04  (R. Benshila) 
    !!            3.6  !  2014-09  (R. Benshila) 
@@ -29,5 +28,4 @@
 
    PUBLIC   Agrif_Update_Tra, Agrif_Update_Dyn, Update_Scales
-   PUBLIC   Agrif_Update_Tke
 
    !!----------------------------------------------------------------------
@@ -160,30 +158,4 @@
    END SUBROUTINE Agrif_Update_Dyn
 
-!!gm Missing GLS case !!!!!
-
-   SUBROUTINE Agrif_Update_Tke( kt )
-      !!----------------------------------------------------------------------
-      !!                   *** ROUTINE Agrif_Update_Tke ***
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! timestep index
-      !!----------------------------------------------------------------------
-      !
-!!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._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
-   
 
    SUBROUTINE updateTS( tabres, i1, i2, j1, j2, k1, k2, n1, n2, before )
@@ -215,5 +187,5 @@
                   DO jj = j1, j2
                      DO ji = i1, i2
-                        IF( tabres(ji,jj,jk,jn) .NE. 0. ) THEN
+                        IF( tabres(ji,jj,jk,jn) /= 0._wp ) THEN
                            tsb(ji,jj,jk,jn) = tsb(ji,jj,jk,jn) & 
                               &             + atfp * ( tabres(ji,jj,jk,jn) - tsn(ji,jj,jk,jn) ) * tmask(ji,jj,jk)
@@ -228,5 +200,5 @@
                DO jj=j1,j2
                   DO ji=i1,i2
-                     IF( tabres(ji,jj,jk,jn) .NE. 0. ) THEN 
+                     IF( tabres(ji,jj,jk,jn) /= 0._wp ) THEN 
                         tsn(ji,jj,jk,jn) = tabres(ji,jj,jk,jn) * tmask(ji,jj,jk)
                      END IF
Index: /branches/2017/dev_r7881_ENHANCE09_RK3/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfphy.F90
===================================================================
--- /branches/2017/dev_r7881_ENHANCE09_RK3/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfphy.F90	(revision 8865)
+++ /branches/2017/dev_r7881_ENHANCE09_RK3/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfphy.F90	(revision 8866)
@@ -28,5 +28,5 @@
    USE sbcrnf         ! surface boundary condition: runoff variables
 #if defined key_agrif
-   USE agrif_opa_interp
+   USE agrif_opa_interp   ! interpavm
 #endif
    !
@@ -279,15 +279,16 @@
 
 #if defined key_agrif 
-      ! interpolation parent grid => child grid for avm_k ( ex : at west border:
-      ! update column 1 and 2)
-      CALL Agrif_tke
+      ! interpolation parent grid => child grid for avm_k ( ex : at west border: update column 1 and 2)
+      IF( l_zdfsh2 )   CALL Agrif_avm
 #endif
 
       !                                         !* Lateral boundary conditions (sign unchanged)
-      CALL lbc_lnk( avm_k, 'W', 1. )                  ! needed to compute the shear production term
-      CALL lbc_lnk( avt_k, 'W', 1. )                  !!gm a priori useless ==>> to be tested
+      IF( l_zdfsh2 ) THEN
+         CALL lbc_lnk( avm_k, 'W', 1. )               ! needed to compute the shear production term
+         CALL lbc_lnk( avt_k, 'W', 1. )               !!gm a priori useless ==>> to be tested
+      ENDIF
       CALL lbc_lnk( avm  , 'W', 1. )                  ! needed to compute avm at u- and v-points
       CALL lbc_lnk( avt  , 'W', 1. )                  !!gm  a priori only avm_k and avm are required
-      CALL lbc_lnk( avs  , 'W', 1. )                  !!gm  To be tested
+      CALL lbc_lnk( avs  , 'W', 1. )                  !!gm  for calculation, keeped here for output only
       !
       IF( l_zdfdrg ) THEN     ! drag  have been updated (non-linear cases)
@@ -297,5 +298,5 @@
       !
       CALL zdf_mxl( kt )                        !* mixed layer depth, and level
-
+      !
       IF( lrst_oce ) THEN                       !* write TKE, GLS or RIC fields in the restart file
          IF( ln_zdftke )   CALL tke_rst( kt, 'WRITE' )
Index: /branches/2017/dev_r7881_ENHANCE09_RK3/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90
===================================================================
--- /branches/2017/dev_r7881_ENHANCE09_RK3/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 8865)
+++ /branches/2017/dev_r7881_ENHANCE09_RK3/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 8866)
@@ -46,8 +46,4 @@
    USE zdfdrg         ! vertical physics: top/bottom drag coef.
    USE zdfmxl         ! vertical physics: mixed layer
-#if defined key_agrif
-   USE agrif_opa_interp
-   USE agrif_opa_update
-#endif
    !
    USE in_out_manager ! I/O manager
@@ -107,5 +103,5 @@
       !!----------------------------------------------------------------------
       ALLOCATE( htau(jpi,jpj) , dissl(jpi,jpj,jpk) , apdlr(jpi,jpj,jpk) ,   STAT= zdf_tke_alloc )
-         !
+      !
       IF( lk_mpp             )   CALL mpp_sum ( zdf_tke_alloc )
       IF( zdf_tke_alloc /= 0 )   CALL ctl_warn('zdf_tke_alloc: failed to allocate arrays')
@@ -171,6 +167,5 @@
 
 
-   SUBROUTINE tke_tke( pdepw, p_e3t, p_e3w, p_sh2    &
-      &                            , p_avm, p_avt )
+   SUBROUTINE tke_tke( pdepw, p_e3t, p_e3w, p_sh2, p_avm, p_avt )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE tke_tke  ***
@@ -217,5 +212,4 @@
       zfact3 = 0.5_wp       * rn_ediss
       !
-      !
       !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       !                     !  Surface/top/bottom boundary condition on tke
@@ -234,5 +228,5 @@
          END DO
       ENDIF
-      
+      !
       !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       !                     !  Bottom boundary condition on tke
@@ -395,5 +389,5 @@
          END DO
       END DO
-
+      !
       !                            !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       !                            !  TKE due to surface and internal wave breaking
@@ -483,9 +477,9 @@
       REAL(wp) ::   zdku,   zdkv, zsqen       !   -      -
       REAL(wp) ::   zemxl, zemlm, zemlp       !   -      -
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zmxlm, zmxld
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zmxlm, zmxld   ! 3D workspace
       !!--------------------------------------------------------------------
       !
       IF( ln_timing )   CALL timing_start('tke_avn')
-
+      !
       !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       !                     !  Mixing length
@@ -597,5 +591,4 @@
       END SELECT
       !
-
       !                     !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       !                     !  Vertical eddy viscosity and diffusivity  (avm and avt)
@@ -623,5 +616,5 @@
          END DO
       ENDIF
-
+      !
       IF(ln_ctl) THEN
          CALL prt_ctl( tab3d_1=en , clinfo1=' tke  - e: ', tab3d_2=avt, clinfo2=' t: ', ovlap=1, kdim=jpk)
