Index: branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/CONFIG/SHARED/1_namelist_ref
===================================================================
--- branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/CONFIG/SHARED/1_namelist_ref	(revision 5075)
+++ branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/CONFIG/SHARED/1_namelist_ref	(revision 5081)
@@ -524,5 +524,4 @@
    rn_sponge_dyn = 2880.   !  coefficient for dynamics sponge layer [m2/s]
    ln_chk_bathy  = .FALSE. !
-   ln_agrif_tke  = .FALSE.
 /
 !-----------------------------------------------------------------------
Index: branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90
===================================================================
--- branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90	(revision 5075)
+++ branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/NST_SRC/agrif_oce.F90	(revision 5081)
@@ -25,5 +25,4 @@
    REAL(wp), PUBLIC ::   rn_sponge_dyn = 2800.     !: sponge coeff. for dynamics
    LOGICAL , PUBLIC ::   ln_chk_bathy  = .FALSE.   !: check of parent bathymetry 
-   LOGICAL , PUBLIC ::   ln_agrif_tke  = .FALSE.   !: interp/extrap for TKE
 
    !                                              !!! OLD namelist names
@@ -66,5 +65,7 @@
    INTEGER :: e3t_id, e1u_id, e2v_id, sshn_id
    INTEGER :: scales_t_id
-   INTEGER :: avt_id, avm_id, avmu_id, avmv_id
+# if defined key_zdftke
+   INTEGER :: avt_id, avm_id, en_id
+# endif  
    INTEGER :: umsk_id, vmsk_id
    INTEGER :: kindic_agr
Index: branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90
===================================================================
--- branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 5075)
+++ branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 5081)
@@ -43,5 +43,5 @@
    PUBLIC   interpe3t, interpumsk, interpvmsk
 # if defined key_zdftke
-   PUBLIC   Agrif_tke, interpavt, interpavm, interpavmu, interpavmv
+   PUBLIC   Agrif_tke, interpavm
 # endif
 
@@ -609,15 +609,13 @@
       !!                  ***  ROUTINE Agrif_tke  ***
       !!----------------------------------------------------------------------  
-      !
-      IF( Agrif_Root() )   RETURN
-
+      REAL(wp) ::   zalpha
+      !
+      zalpha = REAL( Agrif_NbStepint() + Agrif_IRhot() - 1, wp ) / REAL( Agrif_IRhot(), wp )
+      IF( zalpha > 1. )   zalpha = 1.
       
       Agrif_SpecialValue    = 0.e0
       Agrif_UseSpecialValue = .TRUE.
       
-      CALL Agrif_Bc_variable(avt_id , procname=interpavt)       
-      CALL Agrif_Bc_variable(avm_id , procname=interpavm)       
-      CALL Agrif_Bc_variable(avmu_id, procname=interpavmu)
-      CALL Agrif_Bc_variable(avmv_id, procname=interpavmv)
+      CALL Agrif_Bc_variable(avm_id ,calledweight=zalpha, procname=interpavm)       
               
       Agrif_UseSpecialValue = .FALSE.
@@ -1321,22 +1319,4 @@
 
 # if defined key_zdftke
-   SUBROUTINE interpavt(ptab,i1,i2,j1,j2,k1,k2,before)
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE interavt  ***
-      !!----------------------------------------------------------------------  
-      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
-      !
-      
-   END SUBROUTINE interpavt
-
 
    SUBROUTINE interpavm(ptab,i1,i2,j1,j2,k1,k2,before)
@@ -1357,39 +1337,4 @@
    END SUBROUTINE interpavm
 
-
-   SUBROUTINE interpavmu(ptab,i1,i2,j1,j2,k1,k2,before)
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE interavmu  ***
-      !!----------------------------------------------------------------------  
-      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) = avmu_k(i1:i2,j1:j2,k1:k2)
-      ELSE
-         avmu_k(i1:i2,j1:j2,k1:k2) = ptab   (i1:i2,j1:j2,k1:k2)
-      ENDIF
-      !      
-   END SUBROUTINE interpavmu
-
-
-   SUBROUTINE interpavmv(ptab,i1,i2,j1,j2,k1,k2,before)
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE interavmv  ***
-      !!----------------------------------------------------------------------  
-      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) = avmv_k(i1:i2,j1:j2,k1:k2)
-      ELSE
-         avmv_k(i1:i2,j1:j2,k1:k2) = ptab  (i1:i2,j1:j2,k1:k2)
-      ENDIF
-      !
-   END SUBROUTINE interpavmv
 # endif /* key_zdftke */
 
Index: branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90
===================================================================
--- branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 5075)
+++ branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/NST_SRC/agrif_opa_update.F90	(revision 5081)
@@ -160,5 +160,5 @@
       INTEGER, INTENT(in) :: kt
       !       
-      IF((Agrif_NbStepint() .NE. (Agrif_irhot()-1)).AND.(kt /= 0)) RETURN
+      IF( ( Agrif_NbStepint() .NE. 0 ) .AND. (kt /= 0) ) RETURN
 #  if defined TWO_WAY
 
@@ -166,8 +166,7 @@
       Agrif_SpecialValueFineGrid = 0.
 
-      CALL Agrif_Update_Variable(avt_id ,locupdate=(/0,0/), procname=updateAVT )
-      CALL Agrif_Update_Variable(avm_id ,locupdate=(/0,0/), procname=updateAVM )
-      CALL Agrif_Update_Variable(avmu_id,locupdate=(/0,0/), procname=updateAVMu)
-      CALL Agrif_Update_Variable(avmv_id,locupdate=(/0,0/), procname=updateAVMv)
+      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.
@@ -601,7 +600,7 @@
 
 # if defined key_zdftke
-   SUBROUTINE updateAVT( ptab, i1, i2, j1, j2, k1, k2, before )
-      !!---------------------------------------------
-      !!           *** ROUTINE updateavt ***
+   SUBROUTINE updateEN( ptab, i1, i2, j1, j2, k1, k2, before )
+      !!---------------------------------------------
+      !!           *** ROUTINE updateen ***
       !!---------------------------------------------
       INTEGER, INTENT(in) :: i1, i2, j1, j2, k1, k2
@@ -611,15 +610,15 @@
       !
       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
-      !
-   END SUBROUTINE updateAVT
-
-
-   SUBROUTINE updateAVM( ptab, i1, i2, j1, j2, k1, k2, before )
-      !!---------------------------------------------
-      !!           *** ROUTINE updateavm ***
+         ptab (i1:i2,j1:j2,k1:k2) = en(i1:i2,j1:j2,k1:k2)
+      ELSE
+         en(i1:i2,j1:j2,k1:k2) = ptab (i1:i2,j1:j2,k1:k2) 
+      ENDIF
+      !
+   END SUBROUTINE updateEN
+
+
+   SUBROUTINE updateAVT( ptab, i1, i2, j1, j2, k1, k2, before )
+      !!---------------------------------------------
+      !!           *** ROUTINE updateavt ***
       !!---------------------------------------------
       INTEGER, INTENT(in) :: i1, i2, j1, j2, k1, k2
@@ -629,15 +628,15 @@
       !
       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
-
-
-   SUBROUTINE updateAVMu( ptab, i1, i2, j1, j2, k1, k2, before )
-      !!---------------------------------------------
-      !!           *** ROUTINE updateavmu ***
+         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
+      !
+   END SUBROUTINE updateAVT
+
+
+   SUBROUTINE updateAVM( ptab, i1, i2, j1, j2, k1, k2, before )
+      !!---------------------------------------------
+      !!           *** ROUTINE updateavm ***
       !!---------------------------------------------
       INTEGER, INTENT(in) :: i1, i2, j1, j2, k1, k2
@@ -647,28 +646,10 @@
       !
       IF (before) THEN
-         ptab  (i1:i2,j1:j2,k1:k2) = avmu_k(i1:i2,j1:j2,k1:k2)
-      ELSE
-         avmu_k(i1:i2,j1:j2,k1:k2) = ptab  (i1:i2,j1:j2,k1:k2) 
-      ENDIF
-      !
-   END SUBROUTINE updateAVMu
-
-
-   SUBROUTINE updateAVMv( ptab, i1, i2, j1, j2, k1, k2, before )
-      !!---------------------------------------------
-      !!           *** ROUTINE updateavmv ***
-      !!---------------------------------------------
-      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) = avmv_k(i1:i2,j1:j2,k1:k2)
-      ELSE
-         avmv_k(i1:i2,j1:j2,k1:k2) = ptab  (i1:i2,j1:j2,k1:k2) 
-      ENDIF
-      !
-   END SUBROUTINE updateAVMv
+         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 */ 
Index: branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/NST_SRC/agrif_user.F90
===================================================================
--- branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 5075)
+++ branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/NST_SRC/agrif_user.F90	(revision 5081)
@@ -316,7 +316,5 @@
    !
 # if defined key_zdftke
-   IF( ln_agrif_tke ) THEN
    CALL Agrif_Update_tke(0)
-   ENDIF    
 # endif
    !
@@ -369,8 +367,7 @@
 
 # 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)
-   CALL agrif_declare_variable((/1,2,0/),(/2,3,0/),(/'x','y','N'/),(/1,1,1/),(/jpi,jpj,jpk/),avmu_id)
-   CALL agrif_declare_variable((/2,1,0/),(/3,2,0/),(/'x','y','N'/),(/1,1,1/),(/jpi,jpj,jpk/),avmv_id)
 # endif
 
@@ -399,8 +396,5 @@
 
 # if defined key_zdftke
-   CALL Agrif_Set_bcinterp(avt_id ,interp=AGRIF_linear)
    CALL Agrif_Set_bcinterp(avm_id ,interp=AGRIF_linear)
-   CALL Agrif_Set_bcinterp(avmu_id,interp=AGRIF_linear)
-   CALL Agrif_Set_bcinterp(avmv_id,interp=AGRIF_linear)
 # endif
 
@@ -430,8 +424,5 @@
 
 # if defined key_zdftke
-   CALL Agrif_Set_bc(avt_id ,(/0,1/))
    CALL Agrif_Set_bc(avm_id ,(/0,1/))
-   CALL Agrif_Set_bc(avmu_id,(/0,1/))
-   CALL Agrif_Set_bc(avmv_id,(/0,1/))
 # endif
 
@@ -451,8 +442,7 @@
 
 # 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)
-   CALL Agrif_Set_Updatetype(avmu_id, update = AGRIF_Update_Average)
-   CALL Agrif_Set_Updatetype(avmv_id, update = AGRIF_Update_Average)
 # endif
 
@@ -740,6 +730,5 @@
    INTEGER  ::   ios                 ! Local integer output status for namelist read
    INTEGER  ::   iminspon
-   NAMELIST/namagrif/ nn_cln_update, rn_sponge_tra, rn_sponge_dyn, ln_spc_dyn, ln_chk_bathy,   &
-                 &    ln_agrif_tke
+   NAMELIST/namagrif/ nn_cln_update, rn_sponge_tra, rn_sponge_dyn, ln_spc_dyn, ln_chk_bathy
    !!--------------------------------------------------------------------------------------
    !
@@ -763,5 +752,4 @@
       WRITE(numout,*) '      use special values for dynamics   ln_spc_dyn    = ', ln_spc_dyn
       WRITE(numout,*) '      check bathymetry                  ln_chk_bathy  = ', ln_chk_bathy
-      WRITE(numout,*) '      use TKE interpolation/update      ln_agrif_tke  = ', ln_agrif_tke
       WRITE(numout,*) 
    ENDIF
Index: branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90
===================================================================
--- branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 5075)
+++ branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 5081)
@@ -114,8 +114,8 @@
    INTEGER ::   numnam_ref      =   -1      !: logical unit for reference namelist
    INTEGER ::   numnam_cfg      =   -1      !: logical unit for configuration specific namelist
-   INTEGER ::   numond          =    7      !: logical unit for Output Namelist Dynamics
+   INTEGER ::   numond          =   -1      !: logical unit for Output Namelist Dynamics
    INTEGER ::   numnam_ice_ref  =   -1      !: logical unit for ice reference namelist
    INTEGER ::   numnam_ice_cfg  =   -1      !: logical unit for ice reference namelist
-   INTEGER ::   numoni          =    8      !: logical unit for Output Namelist Ice
+   INTEGER ::   numoni          =   -1      !: logical unit for Output Namelist Ice
    INTEGER ::   numevo_ice      =   -1      !: logical unit for ice variables (temp. evolution)
    INTEGER ::   numsol          =   -1      !: logical unit for solver statistics
Index: branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 5075)
+++ branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 5081)
@@ -1438,4 +1438,5 @@
             END DO
 
+            IF( jn == 1 .AND. TRIM(Agrif_CFixed()) /= '0' )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname)
             IF( jn == 1 )   CALL iom_set_file_attr( cdid, name        = clname )
             IF( jn == 2 )   CALL iom_set_file_attr( cdid, name_suffix = clname )
Index: branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/OPA_SRC/ZDF/zdf_oce.F90
===================================================================
--- branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/OPA_SRC/ZDF/zdf_oce.F90	(revision 5075)
+++ branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/OPA_SRC/ZDF/zdf_oce.F90	(revision 5081)
@@ -44,4 +44,5 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   avt_k , avm_k  ! not enhanced Kz
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   avmu_k, avmv_k ! not enhanced Kz
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   en             !: now turbulent kinetic energy   [m2/s2]
 
    !!----------------------------------------------------------------------
@@ -62,5 +63,6 @@
          &     avmv  (jpi,jpj,jpk), avt   (jpi,jpj,jpk),            &
          &     avt_k (jpi,jpj,jpk), avm_k (jpi,jpj,jpk),            & 
-         &     avmu_k(jpi,jpj,jpk), avmv_k(jpi,jpj,jpk), STAT = zdf_oce_alloc )
+         &     avmu_k(jpi,jpj,jpk), avmv_k(jpi,jpj,jpk),            & 
+         &     en    (jpi,jpj,jpk), STAT = zdf_oce_alloc )
          !
       IF( zdf_oce_alloc /= 0 )   CALL ctl_warn('zdf_oce_alloc: failed to allocate arrays')
Index: branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90
===================================================================
--- branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90	(revision 5075)
+++ branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90	(revision 5081)
@@ -41,5 +41,4 @@
    LOGICAL , PUBLIC, PARAMETER ::   lk_zdfgls = .TRUE.   !: TKE vertical mixing flag
    !
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   en      !: now turbulent kinetic energy
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   mxln    !: now mixing length
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   zwall   !: wall function
@@ -118,5 +117,5 @@
       !!                ***  FUNCTION zdf_gls_alloc  ***
       !!----------------------------------------------------------------------
-      ALLOCATE( en(jpi,jpj,jpk),  mxln(jpi,jpj,jpk), zwall(jpi,jpj,jpk) ,     &
+      ALLOCATE( mxln(jpi,jpj,jpk), zwall(jpi,jpj,jpk) ,     &
          &      ustars2(jpi,jpj), ustarb2(jpi,jpj)                      , STAT= zdf_gls_alloc )
          !
Index: branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90
===================================================================
--- branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 5075)
+++ branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftke.F90	(revision 5081)
@@ -88,7 +88,7 @@
    REAL(wp) ::   rhftau_scl = 1.0_wp       ! scale factor applied to HF part of taum  (nn_etau=3)
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   en             !: now turbulent kinetic energy   [m2/s2]
    REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   htau           ! depth of tke penetration (nn_htau)
    REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dissl          ! now mixing lenght of dissipation
+   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   apdlr          ! now mixing lenght of dissipation
 #if defined key_c1d
    !                                                                        !!** 1D cfg only  **   ('key_c1d')
@@ -96,6 +96,4 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   e_pdl, e_ric   !: prandl and local Richardson numbers
 #endif
-   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   wei3d          ! 
-   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:  ) ::   wmix           ! 
 
    !! * Substitutions
@@ -118,15 +116,9 @@
          &      e_pdl(jpi,jpj,jpk) , e_ric(jpi,jpj,jpk) ,                          &
 #endif
-         &      en    (jpi,jpj,jpk) , htau  (jpi,jpj)    , dissl(jpi,jpj,jpk) ,    & 
+         &      apdlr(jpi,jpj,jpk) , htau  (jpi,jpj)    , dissl(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')
-      !
-      IF(.NOT. Agrif_Root()) THEN
-         ALLOCATE( wei3d(jpi,jpj,jpk), wmix(jpi,jpj), STAT= zdf_tke_alloc )
-         IF( lk_mpp             )   CALL mpp_sum ( zdf_tke_alloc )
-         IF( zdf_tke_alloc /= 0 )   CALL ctl_warn('zdf_tke_alloc2: failed to allocate arrays')
-      ENDIF
       !
    END FUNCTION zdf_tke_alloc
@@ -181,10 +173,10 @@
       !!----------------------------------------------------------------------
       !
+#if defined key_agrif 
+      ! interpolation parent grid => child grid for avm_k ( ex : at west border: update column 1 and 2)
+      IF( .NOT.Agrif_Root() )   CALL Agrif_Tke
+#endif
+      !
       IF( kt /= nit000 ) THEN   ! restore before value to compute tke
-#if defined key_agrif 
-         ! interpolation parent grid => child grid for avt_k, avm_k, avmu_k, avmv_k 
-         !( ex : at west border: update column 1 and 2)
-         IF(ln_agrif_tke) CALL Agrif_Tke   
-#endif
          avt (:,:,:) = avt_k (:,:,:) 
          avm (:,:,:) = avm_k (:,:,:) 
@@ -204,5 +196,6 @@
 #if defined key_agrif
       ! Update child grid f => parent grid 
-      IF( .NOT.Agrif_Root() .AND. ln_agrif_tke)    CALL Agrif_Update_Tke( kt )      ! children only
+      IF(lwp) WRITE(numout,*)  'sebseb', Agrif_Root(), kt, Agrif_NbStepint()
+      IF( .NOT.Agrif_Root() )   CALL Agrif_Update_Tke( kt )      ! children only
 #endif      
      ! 
@@ -241,5 +234,6 @@
       INTEGER , POINTER, DIMENSION(:,:  ) :: imlc
       REAL(wp), POINTER, DIMENSION(:,:  ) :: zhlc
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zpelc, zdiag, zd_up, zd_lw
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zpelc, zdiag, zd_up, zd_lw, z3du, z3dv
+      REAL(wp)                            ::   zri  !   local Richardson number
       !!--------------------------------------------------------------------
       !
@@ -248,5 +242,5 @@
       CALL wrk_alloc( jpi,jpj, imlc )    ! integer
       CALL wrk_alloc( jpi,jpj, zhlc ) 
-      CALL wrk_alloc( jpi,jpj,jpk, zpelc, zdiag, zd_up, zd_lw ) 
+      CALL wrk_alloc( jpi,jpj,jpk, zpelc, zdiag, zd_up, zd_lw, z3du, z3dv ) 
       !
       zbbrau = rn_ebb / rau0       ! Local constant initialisation
@@ -347,18 +341,35 @@
       !
       DO jk = 2, jpkm1           !* Shear production at uw- and vw-points (energy conserving form)
-         DO jj = 1, jpj                 ! here avmu, avmv used as workspace
-            DO ji = 1, jpi
-               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)  )
-            END DO
-         END DO
-      END DO
-      !
+         DO jj = 1, jpjm1
+            DO ji = 1, fs_jpim1   ! vector opt.
+               z3du(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) )
+               z3dv(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) )
+            END DO
+         END DO
+      END DO
+      !
+      IF( nn_pdl == 1 ) THEN      !* Prandtl number case: compute apdlr
+         ! Note that zesh2 is also computed in the next loop.
+         ! We decided to compute it twice to keep code readability and avoid an IF case in the DO loops
+         DO jk = 2, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  !                                          ! shear prod. at w-point weightened by mask
+                  zesh2  =  ( z3du(ji-1,jj,jk) + z3du(ji,jj,jk) ) / MAX( 1._wp , umask(ji-1,jj,jk) + umask(ji,jj,jk) )   &
+                     &    + ( z3dv(ji,jj-1,jk) + z3dv(ji,jj,jk) ) / MAX( 1._wp , vmask(ji,jj-1,jk) + vmask(ji,jj,jk) )    
+                  !                                          ! local Richardson number
+                  zri   = MAX( rn2b(ji,jj,jk), 0._wp ) * avm(ji,jj,jk) / ( zesh2 + rn_bshear )
+                  apdlr(ji,jj,jk) = MAX(  0.1_wp,  ri_cri / MAX( ri_cri , zri )  )
+                  
+               END DO
+            END DO
+         END DO
+         !
+      ENDIF
+         !         
       DO jk = 2, jpkm1           !* Matrix and right hand side in en
          DO jj = 2, jpjm1
@@ -369,8 +380,8 @@
                zzd_lw = zcof * ( avm  (ji,jj,jk  ) + avm  (ji,jj,jk-1) )   &  ! lower diagonal
                   &          / ( fse3t(ji,jj,jk-1) * fse3w(ji,jj,jk  ) )
-                  !                                                           ! shear prod. at w-point weightened by mask
-               zesh2  =  ( avmu(ji-1,jj,jk) + avmu(ji,jj,jk) ) / MAX( 1._wp , umask(ji-1,jj,jk) + umask(ji,jj,jk) )   &
-                  &    + ( avmv(ji,jj-1,jk) + avmv(ji,jj,jk) ) / MAX( 1._wp , vmask(ji,jj-1,jk) + vmask(ji,jj,jk) )    
-                  !
+               !                                   ! shear prod. at w-point weightened by mask
+               zesh2  =  ( z3du(ji-1,jj,jk) + z3du(ji,jj,jk) ) / MAX( 1._wp , umask(ji-1,jj,jk) + umask(ji,jj,jk) )   &
+                  &    + ( z3dv(ji,jj-1,jk) + z3dv(ji,jj,jk) ) / MAX( 1._wp , vmask(ji,jj-1,jk) + vmask(ji,jj,jk) )    
+               !
                zd_up(ji,jj,jk) = zzd_up            ! Matrix (zdiag, zd_up, zd_lw)
                zd_lw(ji,jj,jk) = zzd_lw
@@ -465,5 +476,5 @@
       CALL wrk_dealloc( jpi,jpj, imlc )    ! integer
       CALL wrk_dealloc( jpi,jpj, zhlc ) 
-      CALL wrk_dealloc( jpi,jpj,jpk, zpelc, zdiag, zd_up, zd_lw ) 
+      CALL wrk_dealloc( jpi,jpj,jpk, zpelc, zdiag, zd_up, zd_lw, z3du, z3dv ) 
       !
       IF( nn_timing == 1 )  CALL timing_stop('tke_tke')
@@ -509,7 +520,6 @@
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
       REAL(wp) ::   zrn2, zraug, zcoef, zav     ! local scalars
-      REAL(wp) ::   zdku, zpdlr, zri, zsqen     !   -      -
+      REAL(wp) ::   zdku, zri, zsqen     !   -      -
       REAL(wp) ::   zdkv, zemxl, zemlm, zemlp   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:  ) :: ztmp2d
       REAL(wp), POINTER, DIMENSION(:,:,:) :: zmpdl, zmxlm, zmxld
       !!--------------------------------------------------------------------
@@ -517,5 +527,4 @@
       IF( nn_timing == 1 )  CALL timing_start('tke_avn')
 
-      CALL wrk_alloc( jpi,jpj, ztmp2d ) 
       CALL wrk_alloc( jpi,jpj,jpk, zmpdl, zmxlm, zmxld ) 
 
@@ -649,60 +658,4 @@
       CALL lbc_lnk( avm, 'W', 1. )      ! Lateral boundary conditions (sign unchanged)
       !
-# if defined key_agrif
-      IF( .NOT. AGRIF_Root() ) THEN
-         IF( ln_agrif_tke ) THEN
-            DO jk = 1, jpkm1
-               DO jj = 2, jpjm1
-                  DO ji = 2, jpim1
-                     ztmp2d(ji,jj) = 1. * avm(ji-1,jj-1,jk) * tmask(ji-1,jj-1,jk)   &
-                           &          + 2. * avm(ji  ,jj-1,jk) * tmask(ji  ,jj-1,jk)   &
-                           &          + 1. * avm(ji+1,jj-1,jk) * tmask(ji+1,jj-1,jk)   &
-                           &          + 2. * avm(ji-1,jj  ,jk) * tmask(ji-1,jj  ,jk)   &
-                           &          + 4. * avm(ji  ,jj  ,jk) * tmask(ji  ,jj  ,jk)   &
-                           &          + 2. * avm(ji+1,jj  ,jk) * tmask(ji+1,jj  ,jk)   &
-                           &          + 1. * avm(ji-1,jj+1,jk) * tmask(ji-1,jj+1,jk)   &
-                           &          + 2. * avm(ji  ,jj+1,jk) * tmask(ji  ,jj+1,jk)   &
-                           &          + 1. * avm(ji+1,jj+1,jk) * tmask(ji+1,jj+1,jk)
-                  END DO
-               END DO
-               DO jj = 2, jpjm1
-                  DO ji = 2, jpim1
-                     avm(ji,jj,jk) = ztmp2d(ji,jj) * wei3d(ji,jj,jk) * wmix(ji,jj) + avm(ji,jj,jk) * ( 1. - wmix(ji,jj) )
-                  END DO
-               END DO
-            END DO
-            CALL lbc_lnk( avm, 'W', 1. )      ! Lateral boundary conditions (sign unchanged)
-            DO jk = 1, jpkm1
-               DO jj = 2, jpjm1
-                  DO ji = 2, jpim1
-                     ztmp2d(ji,jj) = 1. * avt(ji-1,jj-1,jk) * tmask(ji-1,jj-1,jk)   &
-                           &          + 2. * avt(ji  ,jj-1,jk) * tmask(ji  ,jj-1,jk)   &
-                           &          + 1. * avt(ji+1,jj-1,jk) * tmask(ji+1,jj-1,jk)   &
-                           &          + 2. * avt(ji-1,jj  ,jk) * tmask(ji-1,jj  ,jk)   &
-                           &          + 4. * avt(ji  ,jj  ,jk) * tmask(ji  ,jj  ,jk)   &
-                           &          + 2. * avt(ji+1,jj  ,jk) * tmask(ji+1,jj  ,jk)   &
-                           &          + 1. * avt(ji-1,jj+1,jk) * tmask(ji-1,jj+1,jk)   &
-                           &          + 2. * avt(ji  ,jj+1,jk) * tmask(ji  ,jj+1,jk)   &
-                           &          + 1. * avt(ji+1,jj+1,jk) * tmask(ji+1,jj+1,jk)
-                  END DO
-               END DO
-               DO jj = 2, jpjm1
-                  DO ji = 2, jpim1
-                     avt(ji,jj,jk) = ztmp2d(ji,jj) * wei3d(ji,jj,jk) * wmix(ji,jj) + avt(ji,jj,jk) * ( 1. - wmix(ji,jj) )
-                  END DO
-               END DO
-            END DO
-            CALL lbc_lnk( avt, 'W', 1. )      ! Lateral boundary conditions (sign unchanged)
-         ELSE   
-            DO jk = 1, jpkm1
-               IF ((nbondi ==  1).OR.(nbondi == 2)) avmu(nlci-1 , :     ,jk) = avmu(nlci-2 , :     ,jk)     !   east
-               IF ((nbondi == -1).OR.(nbondi == 2)) avmu(1      , :     ,jk) = avmu(2      , :     ,jk)     !   west
-               IF ((nbondj ==  1).OR.(nbondj == 2)) avmv(:      ,nlcj-1 ,jk) = avmv(:      ,nlcj-2 ,jk)     !   north
-               IF ((nbondj == -1).OR.(nbondj == 2)) avmv(:      ,1      ,jk) = avmv(:      ,2      ,jk)     !   south
-            END DO
-         ENDIF
-      ENDIF
-# endif /* key_Agrif */
-      !
       DO jk = 2, jpkm1            !* vertical eddy viscosity at u- and v-points
          DO jj = 2, jpjm1
@@ -719,18 +672,7 @@
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zcoef = avm(ji,jj,jk) * 2._wp * fse3w(ji,jj,jk) * fse3w(ji,jj,jk)
-                  !                                          ! shear
-                  zdku = avmu(ji-1,jj,jk) * ( un(ji-1,jj,jk-1) - un(ji-1,jj,jk) ) * ( ub(ji-1,jj,jk-1) - ub(ji-1,jj,jk) )   &
-                    &  + avmu(ji  ,jj,jk) * ( un(ji  ,jj,jk-1) - un(ji  ,jj,jk) ) * ( ub(ji  ,jj,jk-1) - ub(ji  ,jj,jk) )
-                  zdkv = avmv(ji,jj-1,jk) * ( vn(ji,jj-1,jk-1) - vn(ji,jj-1,jk) ) * ( vb(ji,jj-1,jk-1) - vb(ji,jj-1,jk) )   &
-                    &  + avmv(ji,jj  ,jk) * ( vn(ji,jj  ,jk-1) - vn(ji,jj  ,jk) ) * ( vb(ji,jj  ,jk-1) - vb(ji,jj  ,jk) )
-                  !                                          ! local Richardson number
-                  zri   = MAX( rn2b(ji,jj,jk), 0._wp ) * zcoef / (zdku + zdkv + rn_bshear )
-                  zpdlr = MAX(  0.1_wp,  0.2 / MAX( 0.2 , zri )  )
-!!gm and even better with the use of the "true" ri_crit=0.22222...  (this change the results!)
-!!gm              zpdlr = MAX(  0.1_wp,  ri_crit / MAX( ri_crit , zri )  )
-                  avt(ji,jj,jk)   = MAX( zpdlr * avt(ji,jj,jk), avtb_2d(ji,jj) * avtb(jk) ) * tmask(ji,jj,jk)
+                  avt(ji,jj,jk)   = MAX( apdlr(ji,jj,jk) * avt(ji,jj,jk), avtb_2d(ji,jj) * avtb(jk) ) * tmask(ji,jj,jk)
 # if defined key_c1d
-                  e_pdl(ji,jj,jk) = zpdlr * tmask(ji,jj,jk)    ! c1d configuration : save masked Prandlt number
+                  e_pdl(ji,jj,jk) = apdlr(ji,jj,jk) * tmask(ji,jj,jk)    ! c1d configuration : save masked Prandlt number
                   e_ric(ji,jj,jk) = zri * tmask(ji,jj,jk)                            ! c1d config. : save Ri
 # endif
@@ -747,5 +689,4 @@
       ENDIF
       !
-      CALL wrk_dealloc( jpi,jpj, ztmp2d ) 
       CALL wrk_dealloc( jpi,jpj,jpk, zmpdl, zmxlm, zmxld ) 
       !
@@ -852,27 +793,4 @@
       CALL tke_rst( nit000, 'READ' )  !* read or initialize all required files
       !
-      IF(.NOT. Agrif_Root()) THEN
-         wei3d(:,:,:) = 1.
-         DO jk = 1, jpkm1
-            DO jj = 2, jpjm1
-               DO ji = 2, jpim1
-                  wei3d(ji,jj,jk) =   &
-                     &   1.*tmask(ji-1,jj-1,jk) + 2.*tmask(ji,jj-1,jk) + 1.*tmask(ji+1,jj-1,jk)&
-                     & + 2.*tmask(ji-1,jj  ,jk) + 4.*tmask(ji,jj  ,jk) + 2.*tmask(ji+1,jj  ,jk)&
-                     & + 1.*tmask(ji-1,jj+1,jk) + 2.*tmask(ji,jj+1,jk) + 1.*tmask(ji+1,jj+1,jk)
-                  wei3d(ji,jj,jk) = tmask(ji,jj,jk) / MAX( 1., wei3d(ji,jj,jk) )
-               END DO
-            END DO
-         END DO
-         CALL lbc_lnk( wei3d, 'T', 1. )
-
-         wmix(:,:) = 0.
-         wmix(mi0(2):mi1(jpiglo-1),mj0(2):mj1(jpjglo-1)) = 1.
-         wmix(mi0(6):mi1(jpiglo-5),mj0(6):mj1(jpjglo-5)) = 0.75
-         wmix(mi0(7):mi1(jpiglo-6),mj0(7):mj1(jpjglo-6)) = 0.5
-         wmix(mi0(8):mi1(jpiglo-7),mj0(8):mj1(jpjglo-7)) = 0.25
-         wmix(mi0(9):mi1(jpiglo-8),mj0(9):mj1(jpjglo-8)) = 0.
-      END IF
-      !  
    END SUBROUTINE zdf_tke_init
 
