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 4785)
+++ branches/2014/dev_r4765_CNRS_agrif/NEMOGCM/NEMO/NST_SRC/agrif_opa_interp.F90	(revision 4789)
@@ -7,4 +7,5 @@
    !!             -   !  2005-11  (XXX) 
    !!            3.2  !  2009-04  (R. Benshila) 
+   !!            3.6  !  2014-09  (R. Benshila) 
    !!----------------------------------------------------------------------
 #if defined key_agrif && ! defined key_offline
@@ -29,25 +30,30 @@
    USE wrk_nemo
    USE dynspg_oce
-
+   USE zdf_oce
+ 
    IMPLICIT NONE
    PRIVATE
 
    INTEGER :: bdy_tinterp = 0
-       
+
    PUBLIC   Agrif_tra, Agrif_dyn, Agrif_ssh, Agrif_dyn_ts, Agrif_ssh_ts, Agrif_dta_ts
    PUBLIC   interpun, interpvn, interpun2d, interpvn2d 
    PUBLIC   interptsn,  interpsshn
    PUBLIC   interpunb, interpvnb, interpub2b, interpvb2b
+   PUBLIC   interpe3t
+# if defined key_zdftke
+   PUBLIC   Agrif_tke, interpavt, interpavm, interpavmu, interpavmv
+# endif
 
 #  include "domzgr_substitute.h90"  
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/NST 3.3 , NEMO Consortium (2010)
+   !! NEMO/NST 3.6 , NEMO Consortium (2010)
    !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
-   CONTAINS
-   
+CONTAINS
+
    SUBROUTINE Agrif_tra
       !!----------------------------------------------------------------------
@@ -199,9 +205,9 @@
          END DO
          spgu(nlci-2,:)=0.
-         do jk=1,jpkm1
-            do jj=1,jpj
+         DO jk=1,jpkm1
+            DO jj=1,jpj
                spgu(nlci-2,jj)=spgu(nlci-2,jj)+fse3u(nlci-2,jj,jk)*ua(nlci-2,jj,jk)
-            enddo
-         enddo
+            ENDDO
+         ENDDO
          DO jj=1,jpj
             IF (umask(nlci-2,jj,1).NE.0.) THEN
@@ -429,9 +435,9 @@
          DO jj=1,jpj
             va_e(2,jj) = vbdy_w(jj) * hvr_e(2,jj)
-! Specified fluxes:
+            ! Specified fluxes:
             ua_e(2,jj) = ubdy_w(jj) * hur_e(2,jj)
-! Characteristics method:
-!alt            ua_e(2,jj) = 0.5_wp * ( ubdy_w(jj) * hur_e(2,jj) + ua_e(3,jj) &
-!alt                       &           - sqrt(grav * hur_e(2,jj)) * (sshn_e(3,jj) - hbdy_w(jj)) )
+            ! Characteristics method:
+            !alt            ua_e(2,jj) = 0.5_wp * ( ubdy_w(jj) * hur_e(2,jj) + ua_e(3,jj) &
+            !alt                       &           - sqrt(grav * hur_e(2,jj)) * (sshn_e(3,jj) - hbdy_w(jj)) )
          END DO
       ENDIF
@@ -440,9 +446,9 @@
          DO jj=1,jpj
             va_e(nlci-1,jj) = vbdy_e(jj) * hvr_e(nlci-1,jj)
-! Specified fluxes:
+            ! Specified fluxes:
             ua_e(nlci-2,jj) = ubdy_e(jj) * hur_e(nlci-2,jj)
-! Characteristics method:
-!alt            ua_e(nlci-2,jj) = 0.5_wp * ( ubdy_e(jj) * hur_e(nlci-2,jj) + ua_e(nlci-3,jj) &
-!alt                            &           + sqrt(grav * hur_e(nlci-2,jj)) * (sshn_e(nlci-2,jj) - hbdy_e(jj)) )
+            ! Characteristics method:
+            !alt            ua_e(nlci-2,jj) = 0.5_wp * ( ubdy_e(jj) * hur_e(nlci-2,jj) + ua_e(nlci-3,jj) &
+            !alt                            &           + sqrt(grav * hur_e(nlci-2,jj)) * (sshn_e(nlci-2,jj) - hbdy_e(jj)) )
          END DO
       ENDIF
@@ -451,9 +457,9 @@
          DO ji=1,jpi
             ua_e(ji,2) = ubdy_s(ji) * hur_e(ji,2)
-! Specified fluxes:
+            ! Specified fluxes:
             va_e(ji,2) = vbdy_s(ji) * hvr_e(ji,2)
-! Characteristics method:
-!alt            va_e(ji,2) = 0.5_wp * ( vbdy_s(ji) * hvr_e(ji,2) + va_e(ji,3) &
-!alt                       &           - sqrt(grav * hvr_e(ji,2)) * (sshn_e(ji,3) - hbdy_s(ji)) )
+            ! Characteristics method:
+            !alt            va_e(ji,2) = 0.5_wp * ( vbdy_s(ji) * hvr_e(ji,2) + va_e(ji,3) &
+            !alt                       &           - sqrt(grav * hvr_e(ji,2)) * (sshn_e(ji,3) - hbdy_s(ji)) )
          END DO
       ENDIF
@@ -462,9 +468,9 @@
          DO ji=1,jpi
             ua_e(ji,nlcj-1) = ubdy_n(ji) * hur_e(ji,nlcj-1)
-! Specified fluxes:
+            ! Specified fluxes:
             va_e(ji,nlcj-2) = vbdy_n(ji) * hvr_e(ji,nlcj-2)
-! Characteristics method:
-!alt            va_e(ji,nlcj-2) = 0.5_wp * ( vbdy_n(ji) * hvr_e(ji,nlcj-2)  + va_e(ji,nlcj-3) &
-!alt                            &           + sqrt(grav * hvr_e(ji,nlcj-2)) * (sshn_e(ji,nlcj-2) - hbdy_n(ji)) )
+            ! Characteristics method:
+            !alt            va_e(ji,nlcj-2) = 0.5_wp * ( vbdy_n(ji) * hvr_e(ji,nlcj-2)  + va_e(ji,nlcj-3) &
+            !alt                            &           + sqrt(grav * hvr_e(ji,nlcj-2)) * (sshn_e(ji,nlcj-2) - hbdy_n(ji)) )
          END DO
       ENDIF
@@ -487,5 +493,5 @@
 
       ll_int_cons = ln_bt_fw ! Assume conservative temporal integration in
-                             ! the forward case only
+      ! the forward case only
 
       zrhot = Agrif_rhot()
@@ -598,4 +604,26 @@
    END SUBROUTINE Agrif_ssh_ts
 
+# if defined key_zdftke
+   SUBROUTINE Agrif_tke
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE Agrif_tke  ***
+      !!----------------------------------------------------------------------  
+      !
+      IF( Agrif_Root() )   RETURN
+
+      
+      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)
+              
+      Agrif_UseSpecialValue = .FALSE.
+      !
+   END SUBROUTINE Agrif_tke
+# endif
+
    SUBROUTINE interptsn(ptab,i1,i2,j1,j2,k1,k2,n1,n2,before,nb,ndir)
       !!---------------------------------------------
@@ -612,5 +640,5 @@
       REAL(wp) ::   zalpha4, zalpha5, zalpha6, zalpha7
       LOGICAL :: western_side, eastern_side,northern_side,southern_side
-       
+
       IF (before) THEN         
          ptab(i1:i2,j1:j2,k1:k2,n1:n2) = tsn(i1:i2,j1:j2,k1:k2,n1:n2)
@@ -656,5 +684,5 @@
                         IF( un(nlci-2,jj,jk) > 0.e0 ) THEN
                            tsa(nlci-1,jj,jk,jn)=( zalpha6*tsa(nlci-2,jj,jk,jn)+zalpha5*tsa(nlci,jj,jk,jn) & 
-                                                + zalpha7*tsa(nlci-3,jj,jk,jn) ) * tmask(nlci-1,jj,jk)
+                                 + zalpha7*tsa(nlci-3,jj,jk,jn) ) * tmask(nlci-1,jj,jk)
                         ENDIF
                      ENDIF
@@ -675,10 +703,10 @@
                         IF (vn(ji,nlcj-2,jk) > 0.e0 ) THEN
                            tsa(ji,nlcj-1,jk,jn)=( zalpha6*tsa(ji,nlcj-2,jk,jn)+zalpha5*tsa(ji,nlcj,jk,jn)  &
-                                                + zalpha7*tsa(ji,nlcj-3,jk,jn) ) * tmask(ji,nlcj-1,jk)
+                                 + zalpha7*tsa(ji,nlcj-3,jk,jn) ) * tmask(ji,nlcj-1,jk)
                         ENDIF
                      ENDIF
                   END DO
                END DO
-            ENDDO 
+            ENDDO
          ENDIF
          !
@@ -723,17 +751,17 @@
          ! East south
          IF ((eastern_side).AND.((nbondj == -1).OR.(nbondj == 2))) THEN
-           tsa(nlci-1,2,:,:) = ptab(nlci-1,2,:,:)
+            tsa(nlci-1,2,:,:) = ptab(nlci-1,2,:,:)
          ENDIF
          ! East north
          IF ((eastern_side).AND.((nbondj == 1).OR.(nbondj == 2))) THEN
-           tsa(nlci-1,nlcj-1,:,:) = ptab(nlci-1,nlcj-1,:,:)
-         ENDIF         
+            tsa(nlci-1,nlcj-1,:,:) = ptab(nlci-1,nlcj-1,:,:)
+         ENDIF
          ! West south
          IF ((western_side).AND.((nbondj == -1).OR.(nbondj == 2))) THEN
-           tsa(2,2,:,:) = ptab(2,2,:,:)
+            tsa(2,2,:,:) = ptab(2,2,:,:)
          ENDIF
          ! West north
          IF ((western_side).AND.((nbondj == 1).OR.(nbondj == 2))) THEN
-           tsa(2,nlcj-1,:,:) = ptab(2,nlcj-1,:,:)
+            tsa(2,nlcj-1,:,:) = ptab(2,nlcj-1,:,:)
          ENDIF
          !
@@ -818,8 +846,8 @@
       !
       ztref = 1.
-      
+
       IF (before) THEN 
          DO jj=j1,j2
-            DO ji=i1,min(i2,nlci-1)
+            DO ji=i1,MIN(i2,nlci-1)
                ptab(ji,jj) = e2u(ji,jj) * ((gcx(ji+1,jj) - gcx(ji,jj))/e1u(ji,jj)) 
             END DO
@@ -855,5 +883,5 @@
                   ptab(ji,jj,jk) = e1v(ji,jj) * vn(ji,jj,jk)
                   ptab(ji,jj,jk) = ptab(ji,jj,jk) * fse3v(ji,jj,jk)
-               END DO	
+               END DO
             END DO
          END DO
@@ -866,8 +894,8 @@
             END DO
          END DO
-       ENDIF
-       !        
+      ENDIF
+      !        
    END SUBROUTINE interpvn
-   
+
    SUBROUTINE interpvn2d(ptab,i1,i2,j1,j2,before)
       !!---------------------------------------------
@@ -887,16 +915,16 @@
       IF (before) THEN 
          !interpv entre 1 et k2 et interpv2d en jpkp1
-         DO jj=j1,min(j2,nlcj-1)
+         DO jj=j1,MIN(j2,nlcj-1)
             DO ji=i1,i2
                ptab(ji,jj) = e1v(ji,jj) * ((gcx(ji,jj+1) - gcx(ji,jj))/e2v(ji,jj)) * vmask(ji,jj,1)
             END DO
          END DO
-       ELSE           
-          zrhox = Agrif_Rhox()
-          DO ji=i1,i2
-             laplacv(ji,j1:j2) = ztref * (ptab(ji,j1:j2)/(zrhox*e1v(ji,j1:j2)))
-           END DO
-         ENDIF
-         !      
+      ELSE           
+         zrhox = Agrif_Rhox()
+         DO ji=i1,i2
+            laplacv(ji,j1:j2) = ztref * (ptab(ji,j1:j2)/(zrhox*e1v(ji,j1:j2)))
+         END DO
+      ENDIF
+      !      
    END SUBROUTINE interpvn2d
 
@@ -934,9 +962,9 @@
          IF( bdy_tinterp == 1 ) THEN
             ztcoeff = zrhot * (  zt1**2._wp * (       zt1 - 1._wp)        &
-                        &      - zt0**2._wp * (       zt0 - 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 ) 
-                     
+                  &      - zt0        * (       zt0 - 1._wp)**2._wp ) 
+
          ELSE
             ztcoeff = 1
@@ -945,11 +973,11 @@
          IF(western_side) THEN
             ubdy_w(j1:j2) = ubdy_w(j1:j2) + ztcoeff * ptab(i1,j1:j2)  
-         ENDIF   
+         ENDIF
          IF(eastern_side) THEN
             ubdy_e(j1:j2) = ubdy_e(j1:j2) + ztcoeff * ptab(i1,j1:j2)  
-         ENDIF   
+         ENDIF
          IF(southern_side) THEN
             ubdy_s(i1:i2) = ubdy_s(i1:i2) + ztcoeff * ptab(i1:i2,j1) 
-         ENDIF   
+         ENDIF
          IF(northern_side) THEN
             ubdy_n(i1:i2) = ubdy_n(i1:i2) + ztcoeff * ptab(i1:i2,j1) 
@@ -957,22 +985,22 @@
          !            
          IF( bdy_tinterp == 0 .OR. bdy_tinterp == 2) THEN
-           IF(western_side) THEN
-              ubdy_w(j1:j2) = ubdy_w(j1:j2) / (zrhoy*e2u(i1,j1:j2))   &
-              &                                  * umask(i1,j1:j2,1)
-           ENDIF   
-           IF(eastern_side) THEN
-              ubdy_e(j1:j2) = ubdy_e(j1:j2) / (zrhoy*e2u(i1,j1:j2))   &
-              &                                  * umask(i1,j1:j2,1)
-           ENDIF
-           IF(southern_side) THEN
-              ubdy_s(i1:i2) = ubdy_s(i1:i2) / (zrhoy*e2u(i1:i2,j1))   &
-              &                                  * umask(i1:i2,j1,1)
-           ENDIF  
-           IF(northern_side) THEN
-              ubdy_n(i1:i2) = ubdy_n(i1:i2) / (zrhoy*e2u(i1:i2,j1))   &
-              &                                  * umask(i1:i2,j1,1)
-           ENDIF 
-        ENDIF    
-      ENDIF   
+            IF(western_side) THEN
+               ubdy_w(j1:j2) = ubdy_w(j1:j2) / (zrhoy*e2u(i1,j1:j2))   &
+                     &                                  * umask(i1,j1:j2,1)
+            ENDIF
+            IF(eastern_side) THEN
+               ubdy_e(j1:j2) = ubdy_e(j1:j2) / (zrhoy*e2u(i1,j1:j2))   &
+                     &                                  * umask(i1,j1:j2,1)
+            ENDIF
+            IF(southern_side) THEN
+               ubdy_s(i1:i2) = ubdy_s(i1:i2) / (zrhoy*e2u(i1:i2,j1))   &
+                     &                                  * umask(i1:i2,j1,1)
+            ENDIF
+            IF(northern_side) THEN
+               ubdy_n(i1:i2) = ubdy_n(i1:i2) / (zrhoy*e2u(i1:i2,j1))   &
+                     &                                  * umask(i1:i2,j1,1)
+            ENDIF
+         ENDIF
+      ENDIF
       ! 
    END SUBROUTINE interpunb
@@ -1010,9 +1038,9 @@
          IF( bdy_tinterp == 1 ) THEN
             ztcoeff = zrhot * (  zt1**2._wp * (       zt1 - 1._wp)        &
-                        &      - zt0**2._wp * (       zt0 - 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 ) 
-                     
+                  &      - zt0        * (       zt0 - 1._wp)**2._wp ) 
+
          ELSE
             ztcoeff = 1
@@ -1021,11 +1049,11 @@
          IF(western_side) THEN
             vbdy_w(j1:j2) = vbdy_w(j1:j2) + ztcoeff * ptab(i1,j1:j2)  
-         ENDIF   
+         ENDIF
          IF(eastern_side) THEN
             vbdy_e(j1:j2) = vbdy_e(j1:j2) + ztcoeff * ptab(i1,j1:j2)  
-         ENDIF   
+         ENDIF
          IF(southern_side) THEN
             vbdy_s(i1:i2) = vbdy_s(i1:i2) + ztcoeff * ptab(i1:i2,j1)
-         ENDIF   
+         ENDIF
          IF(northern_side) THEN
             vbdy_n(i1:i2) = vbdy_n(i1:i2) + ztcoeff * ptab(i1:i2,j1) 
@@ -1033,23 +1061,23 @@
          !            
          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)
-           ENDIF 
-        ENDIF    
-     ENDIF   
-     !
+            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)
+            ENDIF
+         ENDIF
+      ENDIF
+      !
    END SUBROUTINE interpvnb
 
@@ -1084,5 +1112,5 @@
          ! Polynomial interpolation coefficients:
          zat = zrhot * (  zt1**2._wp * (-2._wp*zt1 + 3._wp)        &
-                 &      - zt0**2._wp * (-2._wp*zt0 + 3._wp)        ) 
+               &      - zt0**2._wp * (-2._wp*zt0 + 3._wp)        ) 
          ! 
          IF(western_side ) ubdy_w(j1:j2) = zat * ptab(i1,j1:j2)  
@@ -1090,5 +1118,5 @@
          IF(southern_side) ubdy_s(i1:i2) = zat * ptab(i1:i2,j1) 
          IF(northern_side) ubdy_n(i1:i2) = zat * ptab(i1:i2,j1) 
-      ENDIF   
+      ENDIF
       ! 
    END SUBROUTINE interpub2b
@@ -1125,5 +1153,5 @@
          ! Polynomial interpolation coefficients:
          zat = zrhot * (  zt1**2._wp * (-2._wp*zt1 + 3._wp)        &
-                 &      - zt0**2._wp * (-2._wp*zt0 + 3._wp)        ) 
+               &      - zt0**2._wp * (-2._wp*zt0 + 3._wp)        ) 
          !
          IF(western_side ) vbdy_w(j1:j2) = zat * ptab(i1,j1:j2)  
@@ -1147,15 +1175,15 @@
       INTEGER :: ji, jj, jk
       INTEGER :: icnt
-      logical :: western_side, eastern_side,northern_side,southern_side      
+      LOGICAL :: western_side, eastern_side,northern_side,southern_side      
       !!----------------------------------------------------------------------  
       !    
       IF (before) THEN
-      DO jk=k1,k2
-         DO jj=j1,j2
-            DO ji=i1,i2
-               ptab(ji,jj,jk) = tmask(ji,jj,jk) * fse3t(ji,jj,jk)
-            END DO
-         END DO
-      END DO
+         DO jk=k1,k2
+            DO jj=j1,j2
+               DO ji=i1,i2
+                  ptab(ji,jj,jk) = tmask(ji,jj,jk) * fse3t(ji,jj,jk)
+               END DO
+            END DO
+         END DO
       ELSE
          western_side  = (nb == 1).AND.(ndir == 1)
@@ -1163,33 +1191,107 @@
          southern_side = (nb == 2).AND.(ndir == 1)
          northern_side = (nb == 2).AND.(ndir == 2)
-         
-      icnt = 0
-      DO jk=k1,k2
-         DO jj=j1,j2
-            DO ji=i1,i2
-               IF (ABS(ptab(ji,jj,jk) - tmask(ji,jj,jk) * fse3t(ji,jj,jk)) > 1.D-2) THEN
-                  IF (western_side) THEN
-                  WRITE(numout,*) 'ERROR bathymetry merge at the western border ji,jj,jk ', ji,jj,jk
-                  ELSEIF (eastern_side) THEN
-                  WRITE(numout,*) 'ERROR bathymetry merge at the eastern border ji,jj,jk ', ji,jj,jk
-                  ELSEIF (southern_side) THEN
-                  WRITE(numout,*) 'ERROR bathymetry merge at the southern border ji,jj,jk', ji,jj,jk
-                  ELSEIF (northern_side) THEN
-                  WRITE(numout,*) 'ERROR bathymetry merge at the northen border ji,jj,jk', ji,jj,jk
+
+         icnt = 0
+         DO jk=k1,k2
+            DO jj=j1,j2
+               DO ji=i1,i2
+                  IF (ABS(ptab(ji,jj,jk) - tmask(ji,jj,jk) * fse3t(ji,jj,jk)) > 1.D-2) THEN
+                     IF (western_side) THEN
+                        WRITE(numout,*) 'ERROR bathymetry merge at the western border ji,jj,jk ', ji,jj,jk
+                     ELSEIF (eastern_side) THEN
+                        WRITE(numout,*) 'ERROR bathymetry merge at the eastern border ji,jj,jk ', ji,jj,jk
+                     ELSEIF (southern_side) THEN
+                        WRITE(numout,*) 'ERROR bathymetry merge at the southern border ji,jj,jk', ji,jj,jk
+                     ELSEIF (northern_side) THEN
+                        WRITE(numout,*) 'ERROR bathymetry merge at the northen border ji,jj,jk', ji,jj,jk
+                     ENDIF
+                     WRITE(numout,*) '      ptab(ji,jj,jk), fse3t(ji,jj,jk) ', ptab(ji,jj,jk), fse3t(ji,jj,jk)
+                     icnt = icnt + 1
                   ENDIF
-                  WRITE(numout,*) '      ptab(ji,jj,jk), fse3t(ji,jj,jk) ', ptab(ji,jj,jk), fse3t(ji,jj,jk)
-                  icnt = icnt + 1
-               ENDIF
-            END DO
-         END DO
-      END DO
-      IF(icnt /= 0) THEN 
-         CALL ctl_stop('ERROR in bathymetry merge between parent and child grids...')
-      ELSE
-         IF(lwp) WRITE(numout,*) 'interp e3t ok...'
-      END IF
+               END DO
+            END DO
+         END DO
+         IF(icnt /= 0) THEN 
+            CALL ctl_stop('ERROR in bathymetry merge between parent and child grids...')
+         ELSE
+            IF(lwp) WRITE(numout,*) 'interp e3t ok...'
+         END IF
       ENDIF
       ! 
    END SUBROUTINE interpe3t
+
+# 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)
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE interavm  ***
+      !!----------------------------------------------------------------------  
+      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 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 */
 
 #else
