Index: NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/NST/agrif_oce.F90
===================================================================
--- NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/NST/agrif_oce.F90	(revision 13564)
+++ NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/NST/agrif_oce.F90	(revision 13565)
@@ -70,4 +70,5 @@
    INTEGER, PUBLIC :: mbkt_id, ht0_id
    INTEGER, PUBLIC :: glamt_id, gphit_id
+   INTEGER, PUBLIC :: batupd_id
    INTEGER, PUBLIC :: kindic_agr
 
Index: NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/NST/agrif_oce_sponge.F90
===================================================================
--- NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/NST/agrif_oce_sponge.F90	(revision 13564)
+++ NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/NST/agrif_oce_sponge.F90	(revision 13565)
@@ -137,8 +137,4 @@
          
          ztabramp(:,:) = 0._wp
-
-         ! Trick to remove sponge in 2DV domains:
-         IF ( nbcellsx <= 3 ) ispongearea = -1
-         IF ( nbcellsy <= 3 ) jspongearea = -1
 
          IF( lk_west ) THEN                             ! --- West --- !
Index: NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/NST/agrif_oce_update.F90
===================================================================
--- NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/NST/agrif_oce_update.F90	(revision 13564)
+++ NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/NST/agrif_oce_update.F90	(revision 13565)
@@ -21,4 +21,5 @@
    USE zdf_oce        ! vertical physics: ocean variables 
    USE agrif_oce
+   USE dom_oce
    !
    USE in_out_manager ! I/O manager
@@ -32,5 +33,5 @@
 
    PUBLIC   Agrif_Update_Tra, Agrif_Update_Dyn, Agrif_Update_vvl, Agrif_Update_ssh
-   PUBLIC   Update_Scales
+   PUBLIC   Update_Scales, Agrif_Check_parent_bat
 
    !!----------------------------------------------------------------------
@@ -50,5 +51,5 @@
       IF (lwp.AND.lk_agrif_debug) Write(*,*) 'Update tracers  from grid Number',Agrif_Fixed()
 
-      Agrif_UseSpecialValueInUpdate = .NOT.l_vremap
+      Agrif_UseSpecialValueInUpdate = .NOT.ln_vert_remap
       Agrif_SpecialValueFineGrid    = 0._wp
       l_vremap                      = ln_vert_remap
@@ -343,5 +344,5 @@
                   N_in = 0
                   DO jk=k1,k2 !k2 = jpk of child grid
-                     IF (tabres(ji,jj,jk,n2) == 0._wp  ) EXIT
+                     IF (tabres(ji,jj,jk,n2) <= 1.e-6_wp  ) EXIT
                      N_in = N_in + 1
                      tabin(jk,:) = tabres(ji,jj,jk,n1:n2-1)/tabres(ji,jj,jk,n2)
@@ -448,6 +449,6 @@
       REAL(wp) :: h_in(k1:k2)
       REAL(wp) :: h_out(1:jpk)
-      INTEGER  :: N_in, N_out
-      REAL(wp) :: h_diff, excess, thick
+      INTEGER  :: N_in, N_out, N_in_save, N_out_save
+      REAL(wp) :: zhmin, zd
       REAL(wp) :: tabin(k1:k2)
 ! VERTICAL REFINEMENT END
@@ -470,5 +471,4 @@
 
          tabres_child(:,:,:) = 0._wp
-         AGRIF_SpecialValue = 0._wp
 
          IF ( l_vremap ) THEN
@@ -480,5 +480,5 @@
                   tabin(:) = 0._wp
                   DO jk=k1,k2 !k2=jpk of child grid
-                     IF( tabres(ji,jj,jk,2) == 0.) EXIT
+                     IF( tabres(ji,jj,jk,2)*r1_e2u(ji,jj) <= 1.e-6_wp ) EXIT
                      N_in = N_in + 1
                      tabin(jk) = tabres(ji,jj,jk,1)/tabres(ji,jj,jk,2)
@@ -487,26 +487,35 @@
                   N_out = 0
                   DO jk=1,jpk
-                     IF (umask(ji,jj,jk) == 0) EXIT
+                     IF (umask(ji,jj,jk) == 0._wp) EXIT
                      N_out = N_out + 1
                      h_out(N_out) = e3u(ji,jj,jk,Kmm_a)
                   ENDDO
                   IF (N_in * N_out > 0) THEN
-                     h_diff = sum(h_out(1:N_out))-sum(h_in(1:N_in))
-                     excess = 0._wp
-                     IF (h_diff < -1.e-4) THEN
-                        DO jk=N_in,1,-1
-                           thick = MIN(-1*h_diff, h_in(jk))
-                           excess = excess + tabin(jk)*thick*e2u(ji,jj)
-                           tabin(jk) = tabin(jk)*(1. - thick/h_in(jk))
-                           h_diff = h_diff + thick
-                           IF ( h_diff == 0) THEN
+                     ! Deal with potentially different depths at velocity points:
+                     N_in_save  = N_in
+                     N_out_save = N_out
+                     IF ( ABS(sum(h_out(1:N_out))-sum(h_in(1:N_in))) > 1.e-6_wp ) THEN
+                        zhmin = MIN(sum(h_out(1:N_out)), sum(h_in(1:N_in)))
+                        zd = 0._wp
+                        DO jk=1, N_in_save
+                           IF ( (zd +  h_in(jk)) > zhmin-1.e-6) THEN
                               N_in = jk
-                              h_in(jk) = h_in(jk) - thick
-                              EXIT
+                              h_in(jk) = zhmin - zd
+                              EXIT 
                            ENDIF
-                        ENDDO
-                     ENDIF
+                           zd = zd + h_in(jk)
+                        END DO
+                        zd = 0._wp
+                        DO jk=1, N_out_save
+                           IF ( (zd +  h_out(jk)) > zhmin-1.e-6) THEN
+                              N_out = jk
+                              h_out(jk) = zhmin - zd
+                              EXIT 
+                           ENDIF
+                           zd = zd + h_out(jk)
+                        END DO
+                     END IF
                      CALL reconstructandremap(tabin(1:N_in),h_in(1:N_in),tabres_child(ji,jj,1:N_out),h_out(1:N_out),N_in,N_out,1)
-                     tabres_child(ji,jj,N_out) = tabres_child(ji,jj,N_out) + excess/(e2u(ji,jj)*h_out(N_out))
+                     IF (N_out < N_out_save) tabres_child(ji,jj,N_out+1:N_out_save) = tabres_child(ji,jj,N_out)
                   ENDIF
                ENDDO
@@ -606,6 +615,6 @@
       REAL(wp) :: h_in(k1:k2)
       REAL(wp) :: h_out(1:jpk)
-      INTEGER :: N_in, N_out
-      REAL(wp) :: h_diff, excess, thick
+      INTEGER  :: N_in, N_out, N_in_save, N_out_save
+      REAL(wp) :: zhmin, zd
       REAL(wp) :: tabin(k1:k2)
 ! VERTICAL REFINEMENT END
@@ -628,5 +637,4 @@
 
          tabres_child(:,:,:) = 0._wp
-         AGRIF_SpecialValue = 0._wp
 
          IF ( l_vremap ) THEN
@@ -636,5 +644,5 @@
                   N_in = 0
                   DO jk=k1,k2
-                     IF (tabres(ji,jj,jk,2) == 0) EXIT
+                     IF (tabres(ji,jj,jk,2)* r1_e1v(ji,jj) <= 1.e-6_wp) EXIT
                      N_in = N_in + 1
                      tabin(jk) = tabres(ji,jj,jk,1)/tabres(ji,jj,jk,2)
@@ -648,23 +656,30 @@
                   ENDDO
                   IF (N_in * N_out > 0) THEN
-                     h_diff = sum(h_out(1:N_out))-sum(h_in(1:N_in))
-                     excess = 0._wp
-                     IF (h_diff < -1.e-4) then
-!Even if bathy at T points match it's possible for the V points to be deeper in the child grid. 
-!In this case we need to move transport from the child grid cells below bed of parent grid into the bottom cell.
-                        DO jk=N_in,1,-1
-                           thick = MIN(-1*h_diff, h_in(jk))
-                           excess = excess + tabin(jk)*thick*e2u(ji,jj)
-                           tabin(jk) = tabin(jk)*(1. - thick/h_in(jk))
-                           h_diff = h_diff + thick
-                           IF ( h_diff == 0) THEN
+                     ! Deal with potentially different depths at velocity points:
+                     N_in_save  = N_in
+                     N_out_save = N_out
+                     IF ( ABS(sum(h_out(1:N_out))-sum(h_in(1:N_in))) > 1.e-6_wp ) THEN
+                        zhmin = MIN(sum(h_out(1:N_out)), sum(h_in(1:N_in)))
+                        zd = 0._wp
+                        DO jk=1, N_in_save
+                           IF ( (zd +  h_in(jk)) > zhmin-1.e-6) THEN
                               N_in = jk
-                              h_in(jk) = h_in(jk) - thick
-                              EXIT
+                              h_in(jk) = zhmin - zd
+                              EXIT 
                            ENDIF
-                        ENDDO
-                     ENDIF
+                           zd = zd + h_in(jk)
+                        END DO
+                        zd = 0._wp
+                        DO jk=1, N_out_save
+                           IF ( (zd +  h_out(jk)) > zhmin-1.e-6) THEN
+                              N_out = jk
+                              h_out(jk) = zhmin - zd
+                              EXIT 
+                           ENDIF
+                           zd = zd + h_out(jk)
+                        END DO
+                     END IF
                      CALL reconstructandremap(tabin(1:N_in),h_in(1:N_in),tabres_child(ji,jj,1:N_out),h_out(1:N_out),N_in,N_out,1)
-                     tabres_child(ji,jj,N_out) = tabres_child(ji,jj,N_out) + excess/(e1v(ji,jj)*h_out(N_out))
+                     IF (N_out < N_out_save) tabres_child(ji,jj,N_out+1:N_out_save) = tabres_child(ji,jj,N_out)
                   ENDIF
                ENDDO
@@ -1316,4 +1331,63 @@
    END SUBROUTINE updatee3t
 
+   SUBROUTINE Agrif_Check_parent_bat( )
+      !!----------------------------------------------------------------------
+      !!                   *** ROUTINE Agrif_Check_parent_bat ***
+      !!----------------------------------------------------------------------
+      ! 
+      IF (( .NOT.ln_agrif_2way ).OR.(.NOT.ln_chk_bathy).OR.(Agrif_Root())) RETURN
+      !
+      Agrif_UseSpecialValueInUpdate = .FALSE.
+      !
+      IF(lwp) WRITE(numout,*) ' '
+      IF(lwp) WRITE(numout,*) 'AGRIF: Check parent volume at Level:', Agrif_Level()
+      !
+# if ! defined DECAL_FEEDBACK && ! defined DECAL_FEEDBACK_2D
+      CALL Agrif_Update_Variable(batupd_id,procname = update_bat)
+# else
+      CALL Agrif_Update_Variable(batupd_id,locupdate=(/1,0/),procname = update_bat)
+# endif
+      !
+      kindic_agr = Agrif_Parent(kindic_agr)
+      CALL mpp_sum( 'Agrif_Check_parent_bat', kindic_agr )
+
+      IF( kindic_agr /= 0 ) THEN
+         CALL ctl_stop('==> Averaged Bathymetry does not match parent volume') 
+      ELSE
+         IF(lwp) WRITE(numout,*) '==> Averaged Bathymetry matches parent ' 
+         IF(lwp) WRITE(numout,*) ''
+      ENDIF
+      !
+   END SUBROUTINE Agrif_Check_parent_bat
+
+   SUBROUTINE update_bat(ptab, i1, i2, j1, j2, before )
+      !!---------------------------------------------
+      !!           *** ROUTINE update_bat ***
+      !!---------------------------------------------
+      REAL(wp), DIMENSION(i1:i2,j1:j2) :: ptab
+      INTEGER, INTENT(in) :: i1, i2, j1, j2
+      LOGICAL, INTENT(in) :: before
+      INTEGER :: ji, jj
+      !
+      !!---------------------------------------------
+      !
+      IF( before ) THEN
+         ptab(i1:i2,j1:j2) = ht_0(i1:i2,j1:j2) * tmask(i1:i2,j1:j2,1)
+      ELSE
+         kindic_agr = 0
+         !
+         DO jj=j1,j2
+            DO ji=i1,i2
+               IF ( (ssmask(ji,jj).NE.0._wp).AND.&
+               & (ABS(ptab(ji,jj)-ht_0(ji,jj)).GE.1.e-6) ) THEN 
+                  kindic_agr = kindic_agr + 1 
+               ENDIF
+            END DO
+         END DO
+         !
+      ENDIF
+      !
+   END SUBROUTINE update_bat
+
 #else
    !!----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/NST/agrif_user.F90
===================================================================
--- NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/NST/agrif_user.F90	(revision 13564)
+++ NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/NST/agrif_user.F90	(revision 13565)
@@ -91,4 +91,6 @@
       CALL agrif_declare_variable((/2,2    /),(/ind2  ,ind3      /),(/'x','y'        /),(/1,1    /),(/jpi,jpj        /),sshini_id)
       ! 
+      ! Update location
+      CALL agrif_declare_variable((/2,2/),(/ind2  ,ind3  /),(/'x','y'/),(/1,1/),(/jpi,jpj/), batupd_id)
      
       ! 2. Type of interpolation
@@ -138,9 +140,11 @@
       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(batupd_id, update = Agrif_Update_Full_Weighting)
 #else
       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          )
-#endif
-      
+      CALL Agrif_Set_Updatetype(batupd_id, update = Agrif_Update_Average)
+#endif      
+
    !   CALL Agrif_Set_ExternalMapping(nemo_mapping)
       !
@@ -199,6 +203,6 @@
       IF ( ln_sco.AND.Agrif_Parent(ln_sco) ) THEN 
          DO_2D( 1, 0, 1, 0 )
-            hu0_parent(ji,jj) = 0.5_wp * ( ht0_parent(ji,jj)+ht0_parent(ji+1,jj) )
-            hv0_parent(ji,jj) = 0.5_wp * ( ht0_parent(ji,jj)+ht0_parent(ji,jj+1) )
+            hu0_parent(ji,jj) = 0.5_wp * ( ht0_parent(ji,jj)+ht0_parent(ji+1,jj) ) * ssumask(ji,jj)
+            hv0_parent(ji,jj) = 0.5_wp * ( ht0_parent(ji,jj)+ht0_parent(ji,jj+1) ) * ssvmask(ji,jj)
          END_2D
       ELSE
@@ -432,4 +436,12 @@
 !
 ! > Divergence conserving alternative:
+!      CALL Agrif_Set_bcinterp( ts_interp_id,interp =AGRIF_constant)
+!      CALL Agrif_Set_bcinterp( un_interp_id,interp1=Agrif_linear,interp2=AGRIF_constant   )
+!      CALL Agrif_Set_bcinterp( vn_interp_id,interp1=AGRIF_constant   ,interp2=Agrif_linear)
+!
+!      CALL Agrif_Set_bcinterp(  ts_sponge_id,interp =AGRIF_constant)
+!      CALL Agrif_Set_bcinterp(  un_sponge_id,interp1=Agrif_linear,interp2=AGRIF_constant   )
+!      CALL Agrif_Set_bcinterp(  vn_sponge_id,interp1=AGRIF_constant   ,interp2=Agrif_linear)
+!
 !      CALL Agrif_Set_bcinterp(sshn_id,interp=AGRIF_constant)
 !      CALL Agrif_Set_bcinterp(unb_id,interp1=Agrif_linear,interp2=AGRIF_constant)
@@ -785,9 +797,9 @@
       ENDIF
 
+! JC => side effects of lines below to be checked:
       lk_west  = .NOT. ( Agrif_Ix() == 1 )
       lk_east  = .NOT. ( Agrif_Ix() + nbcellsx/AGRIF_Irhox() == Agrif_Parent(jpiglo) -1 )
       lk_south = .NOT. ( Agrif_Iy() == 1 )
       lk_north = .NOT. ( Agrif_Iy() + nbcellsy/AGRIF_Irhoy() == Agrif_Parent(jpjglo) -1 )
-
       !
       ! Set the number of ghost cells according to periodicity
@@ -798,4 +810,12 @@
       IF(   jperio == 1  )   nbghostcells_x   = 0
       IF( .NOT. lk_south )   nbghostcells_y_s = 0
+      ! For 2DV domains:
+      IF (( nbcellsy <= 3 ).AND.(AGRIF_Irhoy()==1)) THEN
+         lk_north  = .FALSE. ; lk_south = .FALSE.
+         nbghostcells_y_s = nbghostcells
+      ENDIF
+      IF (( nbcellsx <= 3 ).AND.(AGRIF_Irhox()==1)) THEN
+         lk_east  = .FALSE. ; lk_north = .FALSE.
+      ENDIF
       ! Some checks
       IF( jpiglo /= nbcellsx + 2 + 2*nn_hls + nbghostcells_x   + nbghostcells_x   )   CALL ctl_stop( 'STOP',    &
Index: NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/OCE/BDY/bdyini.F90
===================================================================
--- NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/OCE/BDY/bdyini.F90	(revision 13564)
+++ NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/OCE/BDY/bdyini.F90	(revision 13565)
@@ -397,4 +397,5 @@
       IF( nbdysege > 0 .OR. nbdysegw > 0 .OR. nbdysegn > 0 .OR. nbdysegs > 0)   CALL bdy_ctl_seg
       
+
       ! Allocate arrays
       !---------------
@@ -786,5 +787,5 @@
                   ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
                   ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-                  IF(  mig(ii) > 2 .AND. mig(ii) < jpiglo-2 .AND. mjg(ij) > 2 .AND. mjg(ij) < jpjglo-2  ) THEN
+                  IF(  mig0(ii) > 2 .AND. mig0(ii) < Ni0glo-2 .AND. mjg0(ij) > 2 .AND. mjg0(ij) < Nj0glo-2  ) THEN
                      WRITE(ctmp1,*) ' Orlanski is not safe when the open boundaries are on the interior of the computational domain'
                      CALL ctl_stop( ctmp1 )
@@ -1111,11 +1112,11 @@
       CASE( 'N' )
          IF( nbdyind == -1 ) THEN  ! Automatic boundary definition: if nbdysegX = -1
-            nbdyind  = jpjglo - 2  ! set boundary to whole side of model domain.
+            nbdyind  = Nj0glo - 2  ! set boundary to whole side of model domain.
             nbdybeg  = 2
-            nbdyend  = jpiglo - 1
+            nbdyend  = Ni0glo - 1
          ENDIF
          nbdysegn = nbdysegn + 1
          npckgn(nbdysegn) = kb_bdy ! Save bdy package number
-         jpjnob(nbdysegn) = nbdyind
+         jpjnob(nbdysegn) = nbdyind 
          jpindt(nbdysegn) = nbdybeg
          jpinft(nbdysegn) = nbdyend
@@ -1125,5 +1126,5 @@
             nbdyind  = 2           ! set boundary to whole side of model domain.
             nbdybeg  = 2
-            nbdyend  = jpiglo - 1
+            nbdyend  = Ni0glo - 1
          ENDIF
          nbdysegs = nbdysegs + 1
@@ -1135,7 +1136,7 @@
       CASE( 'E' )
          IF( nbdyind == -1 ) THEN  ! Automatic boundary definition: if nbdysegX = -1
-            nbdyind  = jpiglo - 2  ! set boundary to whole side of model domain.
+            nbdyind  = Ni0glo - 2  ! set boundary to whole side of model domain.
             nbdybeg  = 2
-            nbdyend  = jpjglo - 1
+            nbdyend  = Nj0glo - 1 
          ENDIF
          nbdysege = nbdysege + 1 
@@ -1149,5 +1150,5 @@
             nbdyind  = 2           ! set boundary to whole side of model domain.
             nbdybeg  = 2
-            nbdyend  = jpjglo - 1
+            nbdyend  = Nj0glo - 1
          ENDIF
          nbdysegw = nbdysegw + 1
@@ -1196,36 +1197,36 @@
       DO ib = 1, nbdysegn
          IF (lwp) WRITE(numout,*) '**check north seg bounds pckg: ', npckgn(ib)
-         IF ((jpjnob(ib).ge.jpjglo-1).or.& 
+         IF ((jpjnob(ib).ge.Nj0glo-1).or.& 
             &(jpjnob(ib).le.1))        CALL ctl_stop( 'nbdyind out of domain' )
          IF (jpindt(ib).ge.jpinft(ib)) CALL ctl_stop( 'Bdy start index is greater than end index' )
          IF (jpindt(ib).lt.1     )     CALL ctl_stop( 'Start index out of domain' )
-         IF (jpinft(ib).gt.jpiglo)     CALL ctl_stop( 'End index out of domain' )
+         IF (jpinft(ib).gt.Ni0glo)     CALL ctl_stop( 'End index out of domain' )
       END DO
       !
       DO ib = 1, nbdysegs
          IF (lwp) WRITE(numout,*) '**check south seg bounds pckg: ', npckgs(ib)
-         IF ((jpjsob(ib).ge.jpjglo-1).or.& 
+         IF ((jpjsob(ib).ge.Nj0glo-1).or.& 
             &(jpjsob(ib).le.1))        CALL ctl_stop( 'nbdyind out of domain' )
          IF (jpisdt(ib).ge.jpisft(ib)) CALL ctl_stop( 'Bdy start index is greater than end index' )
          IF (jpisdt(ib).lt.1     )     CALL ctl_stop( 'Start index out of domain' )
-         IF (jpisft(ib).gt.jpiglo)     CALL ctl_stop( 'End index out of domain' )
+         IF (jpisft(ib).gt.Ni0glo)     CALL ctl_stop( 'End index out of domain' )
       END DO
       !
       DO ib = 1, nbdysege
          IF (lwp) WRITE(numout,*) '**check east  seg bounds pckg: ', npckge(ib)
-         IF ((jpieob(ib).ge.jpiglo-1).or.& 
+         IF ((jpieob(ib).ge.Ni0glo-1).or.& 
             &(jpieob(ib).le.1))        CALL ctl_stop( 'nbdyind out of domain' )
          IF (jpjedt(ib).ge.jpjeft(ib)) CALL ctl_stop( 'Bdy start index is greater than end index' )
          IF (jpjedt(ib).lt.1     )     CALL ctl_stop( 'Start index out of domain' )
-         IF (jpjeft(ib).gt.jpjglo)     CALL ctl_stop( 'End index out of domain' )
+         IF (jpjeft(ib).gt.Nj0glo)     CALL ctl_stop( 'End index out of domain' )
       END DO
       !
       DO ib = 1, nbdysegw
          IF (lwp) WRITE(numout,*) '**check west  seg bounds pckg: ', npckgw(ib)
-         IF ((jpiwob(ib).ge.jpiglo-1).or.& 
+         IF ((jpiwob(ib).ge.Ni0glo-1).or.& 
             &(jpiwob(ib).le.1))        CALL ctl_stop( 'nbdyind out of domain' )
          IF (jpjwdt(ib).ge.jpjwft(ib)) CALL ctl_stop( 'Bdy start index is greater than end index' )
          IF (jpjwdt(ib).lt.1     )     CALL ctl_stop( 'Start index out of domain' )
-         IF (jpjwft(ib).gt.jpjglo)     CALL ctl_stop( 'End index out of domain' )
+         IF (jpjwft(ib).gt.Nj0glo)     CALL ctl_stop( 'End index out of domain' )
       ENDDO
       !
@@ -1378,6 +1379,6 @@
          DO ji = 1, jpi
             DO jj = 1, jpj             
-              IF( mig(ji) == jpiwob(ib) .AND. mjg(jj) == jpjwdt(ib) )   ztestmask(1) = tmask(ji,jj,1)
-              IF( mig(ji) == jpiwob(ib) .AND. mjg(jj) == jpjwft(ib) )   ztestmask(2) = tmask(ji,jj,1)  
+              IF( mig0(ji) == jpiwob(ib) .AND. mjg0(jj) == jpjwdt(ib) )   ztestmask(1) = tmask(ji,jj,1)
+              IF( mig0(ji) == jpiwob(ib) .AND. mjg0(jj) == jpjwft(ib) )   ztestmask(2) = tmask(ji,jj,1)  
             END DO
          END DO
@@ -1414,6 +1415,6 @@
          DO ji = 1, jpi
             DO jj = 1, jpj             
-              IF( mig(ji) == jpieob(ib)+1 .AND. mjg(jj) == jpjedt(ib) )   ztestmask(1) = tmask(ji,jj,1)
-              IF( mig(ji) == jpieob(ib)+1 .AND. mjg(jj) == jpjeft(ib) )   ztestmask(2) = tmask(ji,jj,1)  
+              IF( mig0(ji) == jpieob(ib)+1 .AND. mjg0(jj) == jpjedt(ib) )   ztestmask(1) = tmask(ji,jj,1)
+              IF( mig0(ji) == jpieob(ib)+1 .AND. mjg0(jj) == jpjeft(ib) )   ztestmask(2) = tmask(ji,jj,1)  
             END DO
          END DO
@@ -1450,6 +1451,6 @@
          DO ji = 1, jpi
             DO jj = 1, jpj             
-              IF( mjg(jj) == jpjsob(ib) .AND. mig(ji) == jpisdt(ib) )   ztestmask(1) = tmask(ji,jj,1)
-              IF( mjg(jj) == jpjsob(ib) .AND. mig(ji) == jpisft(ib) )   ztestmask(2) = tmask(ji,jj,1)  
+              IF( mjg0(jj) == jpjsob(ib) .AND. mig0(ji) == jpisdt(ib) )   ztestmask(1) = tmask(ji,jj,1)
+              IF( mjg0(jj) == jpjsob(ib) .AND. mig0(ji) == jpisft(ib) )   ztestmask(2) = tmask(ji,jj,1)  
             END DO
          END DO
@@ -1472,6 +1473,6 @@
          DO ji = 1, jpi
             DO jj = 1, jpj             
-               IF( mjg(jj) == jpjnob(ib)+1 .AND. mig(ji) == jpindt(ib) )   ztestmask(1) = tmask(ji,jj,1)
-               IF( mjg(jj) == jpjnob(ib)+1 .AND. mig(ji) == jpinft(ib) )   ztestmask(2) = tmask(ji,jj,1)  
+               IF( mjg0(jj) == jpjnob(ib)+1 .AND. mig0(ji) == jpindt(ib) )   ztestmask(1) = tmask(ji,jj,1)
+               IF( mjg0(jj) == jpjnob(ib)+1 .AND. mig0(ji) == jpinft(ib) )   ztestmask(2) = tmask(ji,jj,1)  
             END DO
          END DO
@@ -1526,6 +1527,6 @@
             DO ij = jpjedt(iseg), jpjeft(iseg)
                icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpieob(iseg) + 2 - ir
-               nbjdta(icount, igrd, ib_bdy) = ij
+               nbidta(icount, igrd, ib_bdy) = jpieob(iseg) + 2 - ir + nn_hls
+               nbjdta(icount, igrd, ib_bdy) = ij + nn_hls
                nbrdta(icount, igrd, ib_bdy) = ir
             ENDDO
@@ -1538,6 +1539,6 @@
             DO ij = jpjedt(iseg), jpjeft(iseg)
                icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpieob(iseg) + 1 - ir
-               nbjdta(icount, igrd, ib_bdy) = ij
+               nbidta(icount, igrd, ib_bdy) = jpieob(iseg) + 1 - ir + nn_hls
+               nbjdta(icount, igrd, ib_bdy) = ij + nn_hls
                nbrdta(icount, igrd, ib_bdy) = ir
             ENDDO
@@ -1551,6 +1552,6 @@
             DO ij = jpjedt(iseg), jpjeft(iseg)
                icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpieob(iseg) + 2 - ir
-               nbjdta(icount, igrd, ib_bdy) = ij
+               nbidta(icount, igrd, ib_bdy) = jpieob(iseg) + 2 - ir + nn_hls
+               nbjdta(icount, igrd, ib_bdy) = ij + nn_hls
                nbrdta(icount, igrd, ib_bdy) = ir
             ENDDO
@@ -1571,6 +1572,6 @@
             DO ij = jpjwdt(iseg), jpjwft(iseg)
                icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpiwob(iseg) + ir - 1
-               nbjdta(icount, igrd, ib_bdy) = ij
+               nbidta(icount, igrd, ib_bdy) = jpiwob(iseg) + ir - 1 + nn_hls
+               nbjdta(icount, igrd, ib_bdy) = ij + nn_hls
                nbrdta(icount, igrd, ib_bdy) = ir
             ENDDO
@@ -1583,6 +1584,6 @@
             DO ij = jpjwdt(iseg), jpjwft(iseg)
                icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpiwob(iseg) + ir - 1
-               nbjdta(icount, igrd, ib_bdy) = ij
+               nbidta(icount, igrd, ib_bdy) = jpiwob(iseg) + ir - 1 + nn_hls
+               nbjdta(icount, igrd, ib_bdy) = ij + nn_hls
                nbrdta(icount, igrd, ib_bdy) = ir
             ENDDO
@@ -1596,6 +1597,6 @@
             DO ij = jpjwdt(iseg), jpjwft(iseg)
                icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = jpiwob(iseg) + ir - 1
-               nbjdta(icount, igrd, ib_bdy) = ij
+               nbidta(icount, igrd, ib_bdy) = jpiwob(iseg) + ir - 1 + nn_hls
+               nbjdta(icount, igrd, ib_bdy) = ij + nn_hls
                nbrdta(icount, igrd, ib_bdy) = ir
             ENDDO
@@ -1616,6 +1617,6 @@
             DO ii = jpindt(iseg), jpinft(iseg)
                icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjnob(iseg) + 2 - ir 
+               nbidta(icount, igrd, ib_bdy) = ii + nn_hls
+               nbjdta(icount, igrd, ib_bdy) = jpjnob(iseg) + 2 - ir + nn_hls 
                nbrdta(icount, igrd, ib_bdy) = ir
             ENDDO
@@ -1629,6 +1630,6 @@
             DO ii = jpindt(iseg), jpinft(iseg)
                icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjnob(iseg) + 2 - ir
+               nbidta(icount, igrd, ib_bdy) = ii + nn_hls
+               nbjdta(icount, igrd, ib_bdy) = jpjnob(iseg) + 2 - ir + nn_hls
                nbrdta(icount, igrd, ib_bdy) = ir
             ENDDO
@@ -1643,6 +1644,6 @@
             DO ii = jpindt(iseg), jpinft(iseg)
                icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjnob(iseg) + 1 - ir
+               nbidta(icount, igrd, ib_bdy) = ii + nn_hls
+               nbjdta(icount, igrd, ib_bdy) = jpjnob(iseg) + 1 - ir + nn_hls
                nbrdta(icount, igrd, ib_bdy) = ir
             ENDDO
@@ -1661,6 +1662,6 @@
             DO ii = jpisdt(iseg), jpisft(iseg)
                icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjsob(iseg) + ir - 1
+               nbidta(icount, igrd, ib_bdy) = ii + nn_hls
+               nbjdta(icount, igrd, ib_bdy) = jpjsob(iseg) + ir - 1 + nn_hls
                nbrdta(icount, igrd, ib_bdy) = ir
             ENDDO
@@ -1674,6 +1675,6 @@
             DO ii = jpisdt(iseg), jpisft(iseg)
                icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjsob(iseg) + ir - 1
+               nbidta(icount, igrd, ib_bdy) = ii + nn_hls
+               nbjdta(icount, igrd, ib_bdy) = jpjsob(iseg) + ir - 1 + nn_hls
                nbrdta(icount, igrd, ib_bdy) = ir
             ENDDO
@@ -1688,6 +1689,6 @@
             DO ii = jpisdt(iseg), jpisft(iseg)
                icount = icount + 1
-               nbidta(icount, igrd, ib_bdy) = ii
-               nbjdta(icount, igrd, ib_bdy) = jpjsob(iseg) + ir - 1
+               nbidta(icount, igrd, ib_bdy) = ii + nn_hls
+               nbjdta(icount, igrd, ib_bdy) = jpjsob(iseg) + ir - 1 + nn_hls
                nbrdta(icount, igrd, ib_bdy) = ir
             ENDDO
Index: NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/OCE/DIA/diawri.F90
===================================================================
--- NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/OCE/DIA/diawri.F90	(revision 13564)
+++ NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/OCE/DIA/diawri.F90	(revision 13565)
@@ -137,4 +137,11 @@
       CALL iom_put("e3v_0", e3v_0(:,:,:) )
       !
+      IF ( iom_use("tpt_dep") ) THEN
+         DO jk = 1, jpk
+            z3d(:,:,jk) = gdept(:,:,jk,Kmm)
+         END DO
+         CALL iom_put( "tpt_dep",     z3d(:,:,:) )
+      ENDIF
+
       IF ( iom_use("e3t") .OR. iom_use("e3tdef") ) THEN  ! time-varying e3t
          DO jk = 1, jpk
Index: NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/OCE/nemogcm.F90
===================================================================
--- NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/OCE/nemogcm.F90	(revision 13564)
+++ NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/src/OCE/nemogcm.F90	(revision 13565)
@@ -98,4 +98,5 @@
 #if defined key_agrif
    USE agrif_all_update   ! Master Agrif update
+   USE agrif_oce_update
 #endif
    USE halo_mng
@@ -181,4 +182,5 @@
       Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
       CALL Agrif_step_child_adj(Agrif_Update_All)
+      CALL Agrif_step_child_adj(Agrif_Check_parent_bat)
       !
       DO WHILE( istp <= nitend .AND. nstop == 0 )
