Index: branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90
===================================================================
--- branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90	(revision 7987)
+++ branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90	(revision 7988)
@@ -65,5 +65,5 @@
    INTEGER :: e3t_id, e1u_id, e2v_id, sshn_id
    INTEGER :: scales_t_id
-# if defined key_zdftke
+# if defined key_zdftke || defined key_zdfgls
    INTEGER :: avt_id, avm_id, en_id
 # endif  
Index: branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90
===================================================================
--- branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 7987)
+++ branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 7988)
@@ -42,6 +42,6 @@
    PUBLIC   interpunb, interpvnb, interpub2b, interpvb2b
    PUBLIC   interpe3t, interpumsk, interpvmsk
-# if defined key_zdftke
-   PUBLIC   Agrif_tke, interpavm
+# if defined key_zdftke || defined key_zdfgls
+   PUBLIC   Agrif_avm, interpavm
 # endif
 
@@ -415,4 +415,7 @@
 
       ENDIF
+      !
+      ua(:,:,:) = ua(:,:,:) * umask(:,:,:)
+      va(:,:,:) = va(:,:,:) * vmask(:,:,:)
       !
       CALL wrk_dealloc( jpi, jpj, spgv1, spgu1 )
@@ -576,4 +579,6 @@
       !!----------------------------------------------------------------------  
 
+      IF( Agrif_Root() )   RETURN
+
       IF((nbondi == -1).OR.(nbondi == 2)) THEN
          DO jj=1,jpj
@@ -602,13 +607,18 @@
    END SUBROUTINE Agrif_ssh_ts
 
-# if defined key_zdftke
-   SUBROUTINE Agrif_tke
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE Agrif_tke  ***
+# if defined key_zdftke || defined key_zdfgls
+   SUBROUTINE Agrif_avm
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE Agrif_avm  ***
       !!----------------------------------------------------------------------  
       REAL(wp) ::   zalpha
       !
-      zalpha = REAL( Agrif_NbStepint() + Agrif_IRhot() - 1, wp ) / REAL( Agrif_IRhot(), wp )
-      IF( zalpha > 1. )   zalpha = 1.
+
+      IF( Agrif_Root() )   RETURN
+
+!      zalpha = REAL( Agrif_NbStepint() + Agrif_IRhot() - 1, wp ) / REAL( Agrif_IRhot(), wp )
+!      IF( zalpha > 1. )   zalpha = 1.
+      zalpha = 1._wp ! JC: proper time interpolation impossible 
+                     ! => use last available value from parent
       
       Agrif_SpecialValue    = 0.e0
@@ -619,5 +629,5 @@
       Agrif_UseSpecialValue = .FALSE.
       !
-   END SUBROUTINE Agrif_tke
+   END SUBROUTINE Agrif_avm
 # endif
 
@@ -762,4 +772,8 @@
          ENDIF
          !
+         DO jn = 1, jpts
+            tsa(:,:,:,jn) = tsa(:,:,:,jn) * tmask(:,:,:)
+         ENDDO
+         !
       ENDIF
       !
@@ -1332,5 +1346,5 @@
    END SUBROUTINE interpvmsk
 
-# if defined key_zdftke
+# if defined key_zdftke || defined key_zdfgls
 
    SUBROUTINE interpavm(ptab,i1,i2,j1,j2,k1,k2,before)
@@ -1346,10 +1360,10 @@
          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)
+         avm(i1:i2,j1:j2,k1:k2) = ptab (i1:i2,j1:j2,k1:k2)
       ENDIF
       !
    END SUBROUTINE interpavm
 
-# endif /* key_zdftke */
+# endif /* key_zdftke key_zdfgls */
 
 #else
Index: branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90
===================================================================
--- branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 7987)
+++ branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 7988)
@@ -228,4 +228,14 @@
                   & Agrif_Fixed(), 'Step', Agrif_Nb_Step()
 
+      ! Save "old" scale factor (prior update) for subsequent asselin correction
+      ! of prognostic variables (needed to update initial state only)
+      fse3u_a(:,:,:) = fse3u_n(:,:,:)
+      fse3v_a(:,:,:) = fse3v_n(:,:,:)
+      hu_a(:,:) = hu(:,:)
+      hv_a(:,:) = hv(:,:)
+
+      ! Vertical scale factor interpolations
+      ! ------------------------------------
+      !
       CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3u_n(:,:,:),  'U'  )
       CALL dom_vvl_interpol( fse3t_n(:,:,:), fse3v_n(:,:,:),  'V'  )
@@ -310,8 +320,8 @@
                      DO ji=i1,i2
                         IF( tabres(ji,jj,jk,jn) .NE. 0. ) THEN
-                           tsb(ji,jj,jk,jn) = tsb(ji,jj,jk,jn) & 
-                                 & + atfp * ( tabres(ji,jj,jk,jn) &
-                                 &             - tsn(ji,jj,jk,jn)*fse3t_a(ji,jj,jk) ) & 
-                                 & * tmask(ji,jj,jk) / fse3t_b(ji,jj,jk)
+                           tsb(ji,jj,jk,jn) = ( tsb(ji,jj,jk,jn)*fse3t_b(ji,jj,jk)   & ! jc: should be fse3t_b prior update
+                                & + atfp * ( tabres(ji,jj,jk,jn)                     &
+                                &             - tsn(ji,jj,jk,jn)*fse3t_a(ji,jj,jk) ) & 
+                                & * tmask(ji,jj,jk) ) / fse3t_b(ji,jj,jk)
                         ENDIF
                      ENDDO
@@ -367,8 +377,8 @@
                   !
                   IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN ! Add asselin part
-                     ub(ji,jj,jk) = ub(ji,jj,jk) & 
-                           & + atfp * ( tabres(ji,jj,jk)                     & 
+                     ub(ji,jj,jk) = (       ub(ji,jj,jk)*fse3u_b(ji,jj,jk)   & ! jc: should be fse3u_b prior update
+                           & + atfp * ( tabres(ji,jj,jk)                     &
                            &              - un(ji,jj,jk)*fse3u_a(ji,jj,jk) ) & 
-                           & * umask(ji,jj,jk) / fse3u_b(ji,jj,jk)
+                           & * umask(ji,jj,jk) ) / fse3u_b(ji,jj,jk)
                   ENDIF
                   !
@@ -413,8 +423,8 @@
                   !
                   IF (.NOT.(lk_agrif_fstep.AND.(neuler==0))) THEN ! Add asselin part
-                     vb(ji,jj,jk) = vb(ji,jj,jk) & 
+                     vb(ji,jj,jk) = (       vb(ji,jj,jk)*fse3v_b(ji,jj,jk)   & ! jc: should be fse3v_b prior update
                            & + atfp * ( tabres(ji,jj,jk)                     & 
                            &              - vn(ji,jj,jk)*fse3v_a(ji,jj,jk) ) & 
-                           & * vmask(ji,jj,jk) / fse3v_b(ji,jj,jk)
+                           & * vmask(ji,jj,jk) ) / fse3v_b(ji,jj,jk)
                   ENDIF
                   !
@@ -809,5 +819,5 @@
             fsdept_b(i1:i2,j1:j2,1) = 0.5_wp * fse3w_b(i1:i2,j1:j2,1)
             !
-            DO jk = 2, jpkm1
+            DO jk = 2, jpk
                DO jj = j1,j2
                   DO ji = i1,i2            
@@ -823,8 +833,13 @@
                END DO
             END DO
+            !
          ENDIF        
          !
          ! 2) Updates at now time step:
          ! ----------------------------
+         !
+         ! Save "old" scale factor (prior update) for subsequent asselin correction
+         ! of prognostic variables (needed to update initial state only)
+         fse3t_a(i1:i2,j1:j2,k1:k2) = fse3t_n(i1:i2,j1:j2,k1:k2)
          !
          ! Update vertical scale factor at T-points:
@@ -843,5 +858,5 @@
          fsde3w_n(i1:i2,j1:j2,1) = fsdept_n(i1:i2,j1:j2,1) - (ht(i1:i2,j1:j2)-ht_0(i1:i2,j1:j2)) ! Last term in the rhs is ssh
          !
-         DO jk = 2, jpkm1
+         DO jk = 2, jpk
             DO jj = j1,j2
                DO ji = i1,i2            
Index: branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/NST_SRC/agrif_user.F90
===================================================================
--- branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 7987)
+++ branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 7988)
@@ -198,5 +198,5 @@
    CALL Agrif_Bc_variable(tsn_sponge_id,calledweight=1.,procname=interptsn_sponge)
    ! reset tsa to zero
-   tsa(:,:,:,:) = 0.
+   tsa(:,:,:,:) = 0. !? JC: ??
 
    Agrif_UseSpecialValue = ln_spc_dyn
@@ -212,4 +212,6 @@
    Agrif_UseSpecialValue = .TRUE.
    CALL Agrif_Bc_variable(sshn_id,calledweight=1., procname=interpsshn )
+   hbdy_w(:) = 0.e0 ; hbdy_e(:) = 0.e0 ; hbdy_n(:) = 0.e0 ; hbdy_s(:) = 0.e0
+   ssha(:,:) = 0.e0
 
 #if defined key_dynspg_ts
@@ -219,8 +221,8 @@
    CALL Agrif_Bc_variable(ub2b_interp_id,calledweight=1.,procname=interpub2b)
    CALL Agrif_Bc_variable(vb2b_interp_id,calledweight=1.,procname=interpvb2b)
-   ubdy_w(:) = 0.e0 ; vbdy_w(:) = 0.e0 ; hbdy_w(:) =0.e0
-   ubdy_e(:) = 0.e0 ; vbdy_e(:) = 0.e0 ; hbdy_e(:) =0.e0 
-   ubdy_n(:) = 0.e0 ; vbdy_n(:) = 0.e0 ; hbdy_n(:) =0.e0 
-   ubdy_s(:) = 0.e0 ; vbdy_s(:) = 0.e0 ; hbdy_s(:) =0.e0
+   ubdy_w(:) = 0.e0 ; vbdy_w(:) = 0.e0 
+   ubdy_e(:) = 0.e0 ; vbdy_e(:) = 0.e0 
+   ubdy_n(:) = 0.e0 ; vbdy_n(:) = 0.e0 
+   ubdy_s(:) = 0.e0 ; vbdy_s(:) = 0.e0 
 #endif
 
@@ -307,8 +309,9 @@
    ! 
 ! JC: I am not sure if Agrif_MaxLevel() is the "relative"
-!     or the absolute maximum nesting level...TBC                        
-   IF ( Agrif_Level().EQ.Agrif_MaxLevel() ) THEN 
+!     or the absolute maximum nesting level...TBC  
+   nbcline = 0                 
+   IF ( Agrif_Level().EQ.Agrif_MaxLevel() ) THEN       
       ! NB: Order matters below: 
-      CALL Agrif_Update_vvl() 
+      IF ( lk_vvl ) CALL Agrif_Update_vvl() 
       CALL Agrif_Update_tra()
       CALL Agrif_Update_dyn()
@@ -320,5 +323,4 @@
    !
    Agrif_UseSpecialValueInUpdate = .FALSE.
-   nbcline = 0
    lk_agrif_doupd = .FALSE.
    !
@@ -366,8 +368,8 @@
    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)
+# if defined key_zdftke || defined key_zdfgls
+   CALL agrif_declare_variable((/2,2,0/),(/3,3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/), en_id)
+   CALL agrif_declare_variable((/2,2,0/),(/3,3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),avt_id)
+   CALL agrif_declare_variable((/2,2,0/),(/3,3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),avm_id)
 # endif
 
@@ -395,5 +397,5 @@
    CALL Agrif_Set_bcinterp(vmsk_id,interp=AGRIF_constant)
 
-# if defined key_zdftke
+# if defined key_zdftke || defined key_zdfgls
    CALL Agrif_Set_bcinterp(avm_id ,interp=AGRIF_linear)
 # endif
@@ -423,5 +425,5 @@
    CALL Agrif_Set_bc(vmsk_id,(/0,0/))
 
-# if defined key_zdftke
+# if defined key_zdftke || defined key_zdfgls
    CALL Agrif_Set_bc(avm_id ,(/0,1/))
 # endif
@@ -441,5 +443,5 @@
    CALL Agrif_Set_Updatetype(vb2b_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy)
 
-# if defined key_zdftke
+# if defined key_zdftke || defined key_zdfgls
    CALL Agrif_Set_Updatetype( en_id, update = AGRIF_Update_Average)
    CALL Agrif_Set_Updatetype(avt_id, update = AGRIF_Update_Average)
@@ -457,5 +459,6 @@
 !   CALL Agrif_Set_Updatetype(vb2b_update_id,update1 = Agrif_Update_Full_Weighting, update2 = Agrif_Update_Average)
 !   CALL Agrif_Set_Updatetype(sshn_id, update = Agrif_Update_Full_Weighting)
- 
+
+!   CALL Agrif_Set_Updatetype(e3t_id, update = Agrif_Update_Full_Weighting)
    !
 END SUBROUTINE agrif_declare_var
@@ -657,9 +660,8 @@
       ENDIF
    ENDIF
-
+   nbcline_trc = 0
    CALL Agrif_Update_trc(0)
    !
    Agrif_UseSpecialValueInUpdate = .FALSE.
-   nbcline_trc = 0
    !
 END SUBROUTINE Agrif_InitValues_cont_top
@@ -766,4 +768,5 @@
    IF (lk_mpp) iminspon = MIN(iminspon,FLOOR(REAL(jpi-2)/REAL(Agrif_irhox())), FLOOR(REAL(jpj-2)/REAL(Agrif_irhox())) )
    IF (nn_sponge_len > iminspon)  CALL ctl_stop('agrif sponge length is too large')
+   IF (MOD((nitend-nit000+1), nbclineupdate).NE.0 ) CALL ctl_stop('number of time steps should be a multiple of nn_cln_update')
    !
    IF( agrif_oce_alloc()  > 0 )   CALL ctl_warn('agrif agrif_oce_alloc: allocation of arrays failed')
Index: branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90
===================================================================
--- branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90	(revision 7987)
+++ branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90	(revision 7988)
@@ -31,5 +31,8 @@
    USE iom            ! I/O manager library
    USE timing         ! Timing
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined) 
+#if defined key_agrif
+   USE agrif_opa_interp ! Set bc on avm
+#endif 
 
    IMPLICIT NONE
@@ -204,12 +207,12 @@
          DO jj = 2, jpjm1
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               avmu(ji,jj,jk) = avmu(ji,jj,jk) * ( un(ji,jj,jk-1) - un(ji,jj,jk) )   &
-                  &                            * ( ub(ji,jj,jk-1) - ub(ji,jj,jk) )   &
-                  &                            / (  fse3uw_n(ji,jj,jk)               &
-                  &                            *    fse3uw_b(ji,jj,jk) )
-               avmv(ji,jj,jk) = avmv(ji,jj,jk) * ( vn(ji,jj,jk-1) - vn(ji,jj,jk) )   &
-                  &                            * ( vb(ji,jj,jk-1) - vb(ji,jj,jk) )   &
-                  &                            / (  fse3vw_n(ji,jj,jk)               &
-                  &                            *    fse3vw_b(ji,jj,jk) )
+               avmu(ji,jj,jk) = 0.5 * ( avm(ji,jj,jk) + avm(ji+1,jj  ,jk) ) * ( un(ji,jj,jk-1) - un(ji,jj,jk) )   &
+                  &                                                         * ( ub(ji,jj,jk-1) - ub(ji,jj,jk) )   &
+                  &                                                         / (  fse3uw_n(ji,jj,jk)               &
+                  &                                                         *    fse3uw_b(ji,jj,jk) )
+               avmv(ji,jj,jk) = 0.5 * ( avm(ji,jj,jk) + avm(ji  ,jj+1,jk) ) * ( vn(ji,jj,jk-1) - vn(ji,jj,jk) )   &
+                  &                                                         * ( vb(ji,jj,jk-1) - vb(ji,jj,jk) )   &
+                  &                                                         / (  fse3vw_n(ji,jj,jk)               &
+                  &                                                         *    fse3vw_b(ji,jj,jk) )
                eps(ji,jj,jk)  = rc03 * en(ji,jj,jk) * SQRT(en(ji,jj,jk)) / mxln(ji,jj,jk)
             END DO
@@ -809,4 +812,7 @@
       !
       ! Lateral boundary conditions (sign unchanged)
+#if defined key_agrif
+      CALL Agrif_avm
+#endif
       avt(:,:,1)  = 0._wp
       CALL lbc_lnk( avm, 'W', 1. )   ;   CALL lbc_lnk( avt, 'W', 1. )
Index: branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90
===================================================================
--- branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 7987)
+++ branches/2017/dev_r7963_nemo_v3_6_AGRIF-3_AGRIFVVL/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 7988)
@@ -192,5 +192,6 @@
 #if defined key_agrif
       ! Update child grid f => parent grid 
-      IF( .NOT.Agrif_Root() )   CALL Agrif_Update_Tke( kt )      ! children only
+!!! JC: suppress update since this hampers restartability
+!!!      IF( .NOT.Agrif_Root() )   CALL Agrif_Update_Tke( kt )      ! children only
 #endif      
      ! 
@@ -659,4 +660,8 @@
          END DO
       END DO
+
+#if defined key_agrif
+      CALL Agrif_avm
+#endif
       CALL lbc_lnk( avm, 'W', 1. )      ! Lateral boundary conditions (sign unchanged)
       !
